From 09aadef83b9ec5c8f2e507f62c1eb6e9e6aea2c8 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Fri, 29 Jun 2018 13:01:08 +0200 Subject: [PATCH 01/76] Fix support for URL to account for master-slave and pooling-shard connections --- lib/Doctrine/DBAL/DriverManager.php | 22 ++++++ .../Doctrine/Tests/DBAL/DriverManagerTest.php | 71 +++++++++++++++++++ 2 files changed, 93 insertions(+) diff --git a/lib/Doctrine/DBAL/DriverManager.php b/lib/Doctrine/DBAL/DriverManager.php index 22ae8ac3264..6f7164e9e0e 100644 --- a/lib/Doctrine/DBAL/DriverManager.php +++ b/lib/Doctrine/DBAL/DriverManager.php @@ -155,6 +155,28 @@ public static function getConnection( $params = self::parseDatabaseUrl($params); + // URL support for MasterSlaveConnection + if (isset($params['master'])) { + $params['master'] = self::parseDatabaseUrl($params['master']); + } + + if (isset($params['slaves'])) { + foreach ($params['slaves'] as $key => $slaveParams) { + $params['slaves'][$key] = self::parseDatabaseUrl($slaveParams); + } + } + + // URL support for PoolingShardConnection + if (isset($params['global'])) { + $params['global'] = self::parseDatabaseUrl($params['global']); + } + + if (isset($params['shards'])) { + foreach ($params['shards'] as $key => $shardParams) { + $params['shards'][$key] = self::parseDatabaseUrl($shardParams); + } + } + // check for existing pdo object if (isset($params['pdo']) && ! $params['pdo'] instanceof \PDO) { throw DBALException::invalidPdoInstance(); diff --git a/tests/Doctrine/Tests/DBAL/DriverManagerTest.php b/tests/Doctrine/Tests/DBAL/DriverManagerTest.php index 05892a2d0ff..7e7c5b0153a 100644 --- a/tests/Doctrine/Tests/DBAL/DriverManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/DriverManagerTest.php @@ -2,12 +2,15 @@ namespace Doctrine\Tests\DBAL; +use Doctrine\DBAL\Connections\MasterSlaveConnection; use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\DrizzlePDOMySql\Driver as DrizzlePDOMySqlDriver; use Doctrine\DBAL\Driver\PDOMySql\Driver as PDOMySQLDriver; use Doctrine\DBAL\Driver\PDOSqlite\Driver as PDOSqliteDriver; use Doctrine\DBAL\Driver\SQLSrv\Driver as SQLSrvDriver; use Doctrine\DBAL\DriverManager; +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; @@ -133,6 +136,74 @@ public function testValidDriverClass() self::assertInstanceOf(PDOMySQLDriver::class, $conn->getDriver()); } + public function testDatabaseUrlMasterSlave() + { + $options = [ + 'driver' => 'pdo_mysql', + 'master' => ['url' => 'mysql://foo:bar@localhost:11211/baz'], + 'slaves' => [ + 'slave1' => ['url' => 'mysql://foo:bar@localhost:11211/baz_slave'], + ], + 'wrapperClass' => MasterSlaveConnection::class, + ]; + + $conn = DriverManager::getConnection($options); + + $params = $conn->getParams(); + self::assertInstanceOf(PDOMySQLDriver::class, $conn->getDriver()); + + $expected = [ + 'user' => 'foo', + 'password' => 'bar', + 'host' => 'localhost', + 'port' => 11211, + ]; + + foreach ($expected as $key => $value) { + self::assertEquals($value, $params['master'][$key]); + self::assertEquals($value, $params['slaves']['slave1'][$key]); + } + + self::assertEquals('baz', $params['master']['dbname']); + self::assertEquals('baz_slave', $params['slaves']['slave1']['dbname']); + } + + public function testDatabaseUrlShard() + { + $options = [ + 'driver' => 'pdo_mysql', + 'shardChoser' => MultiTenantShardChoser::class, + 'global' => ['url' => 'mysql://foo:bar@localhost:11211/baz'], + 'shards' => [ + [ + 'id' => 1, + 'url' => 'mysql://foo:bar@localhost:11211/baz_slave', + ], + ], + 'wrapperClass' => PoolingShardConnection::class, + ]; + + $conn = DriverManager::getConnection($options); + + $params = $conn->getParams(); + self::assertInstanceOf(PDOMySQLDriver::class, $conn->getDriver()); + + $expected = [ + 'user' => 'foo', + 'password' => 'bar', + 'host' => 'localhost', + 'port' => 11211, + ]; + + foreach ($expected as $key => $value) { + self::assertEquals($value, $params['global'][$key]); + self::assertEquals($value, $params['shards'][0][$key]); + } + + self::assertEquals('baz', $params['global']['dbname']); + self::assertEquals('baz_slave', $params['shards'][0]['dbname']); + } + /** * @dataProvider databaseUrls */ From 8fa2d7bce9467977e1bba9737077ce331e1faae1 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 12 Jul 2018 20:14:40 -0700 Subject: [PATCH 02/76] Bump version to 2.9.0-DEV --- 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 5f22681e56a..e82d1e8ae62 100644 --- a/lib/Doctrine/DBAL/Version.php +++ b/lib/Doctrine/DBAL/Version.php @@ -38,7 +38,7 @@ class Version /** * Current Doctrine Version. */ - public const VERSION = '2.8.0-DEV'; + public const VERSION = '2.9.0-DEV'; /** * Compares a Doctrine version with the current one. From cebb5863e81ed84f3a1c8e009b44a90d6a768b2f Mon Sep 17 00:00:00 2001 From: Gawain Lynch Date: Sun, 15 Jul 2018 21:43:38 +0200 Subject: [PATCH 03/76] GitHub template grammar/spelling fixes --- .github/ISSUE_TEMPLATE/BC_Break.md | 10 +++++----- .github/ISSUE_TEMPLATE/Bug.md | 8 ++++---- .github/ISSUE_TEMPLATE/Support_Question.md | 2 +- .github/PULL_REQUEST_TEMPLATE.md | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/BC_Break.md b/.github/ISSUE_TEMPLATE/BC_Break.md index fe2f6eac490..c372e7fefd5 100644 --- a/.github/ISSUE_TEMPLATE/BC_Break.md +++ b/.github/ISSUE_TEMPLATE/BC_Break.md @@ -1,6 +1,6 @@ --- name: 💥 BC Break -about: Have you encountered an issue during upgrade? 💣 +about: Have you encountered an issue during an upgrade? 💣 --- + -#### Previous behavior +#### Previous behaviour - + #### Current behavior - + #### How to reproduce diff --git a/.github/ISSUE_TEMPLATE/Bug.md b/.github/ISSUE_TEMPLATE/Bug.md index b0767e8c790..466769fc7a2 100644 --- a/.github/ISSUE_TEMPLATE/Bug.md +++ b/.github/ISSUE_TEMPLATE/Bug.md @@ -14,11 +14,11 @@ about: Something is broken? 🔨 #### Summary - + #### Current behavior - + #### How to reproduce @@ -28,7 +28,7 @@ If possible, also add a code snippet with relevant configuration, driver/platfor Adding a failing Unit or Functional Test would help us a lot - you can submit one in a Pull Request separately, referencing this bug report. --> -#### Expected behavior +#### Expected behaviour - + diff --git a/.github/ISSUE_TEMPLATE/Support_Question.md b/.github/ISSUE_TEMPLATE/Support_Question.md index 59a63fda112..d5bccbd15fa 100644 --- a/.github/ISSUE_TEMPLATE/Support_Question.md +++ b/.github/ISSUE_TEMPLATE/Support_Question.md @@ -10,7 +10,7 @@ about: Have a problem that you can't figure out? 🤔 | Version | x.y.z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 332d6db0bb8..d88b155d0a0 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -8,4 +8,4 @@ #### Summary - + From aa25877a75ae2a3a17368d5a4bd5a500db894650 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 27 Jul 2018 12:01:41 -0700 Subject: [PATCH 04/76] Removed NOW() from QueryBuilder usage examples --- lib/Doctrine/DBAL/Query/QueryBuilder.php | 26 ++++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/Doctrine/DBAL/Query/QueryBuilder.php b/lib/Doctrine/DBAL/Query/QueryBuilder.php index 8a69806b3a9..40c133abe20 100644 --- a/lib/Doctrine/DBAL/Query/QueryBuilder.php +++ b/lib/Doctrine/DBAL/Query/QueryBuilder.php @@ -552,9 +552,9 @@ public function delete($delete = null, $alias = null) * * * $qb = $conn->createQueryBuilder() - * ->update('users', 'u') - * ->set('u.last_login', 'NOW()') - * ->where('u.id = ?'); + * ->update('counters', 'c') + * ->set('c.value', 'c.value + 1') + * ->where('c.id = ?'); * * * @param string $update The table whose rows are subject to the update. @@ -745,9 +745,9 @@ public function rightJoin($fromAlias, $join, $alias, $condition = null) * * * $qb = $conn->createQueryBuilder() - * ->update('users', 'u') - * ->set('u.last_login', 'NOW()') - * ->where('u.id = ?'); + * ->update('counters', 'c') + * ->set('c.value', 'c.value + 1') + * ->where('c.id = ?'); * * * @param string $key The column to set. @@ -766,19 +766,19 @@ public function set($key, $value) * * * $qb = $conn->createQueryBuilder() - * ->select('u.name') - * ->from('users', 'u') - * ->where('u.id = ?'); + * ->select('c.value') + * ->from('counters', 'c') + * ->where('c.id = ?'); * * // You can optionally programatically build and/or expressions * $qb = $conn->createQueryBuilder(); * * $or = $qb->expr()->orx(); - * $or->add($qb->expr()->eq('u.id', 1)); - * $or->add($qb->expr()->eq('u.id', 2)); + * $or->add($qb->expr()->eq('c.id', 1)); + * $or->add($qb->expr()->eq('c.id', 2)); * - * $qb->update('users', 'u') - * ->set('u.last_login', 'NOW()') + * $qb->update('counters', 'c') + * ->set('c.value', 'c.value + 1') * ->where($or); * * From 8677cf1d4882467598d1b8d07d14bc145b862c52 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Thu, 2 Aug 2018 14:48:41 +0200 Subject: [PATCH 05/76] Use PSR-4 autoloader --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 163d80abba8..f631bb3a645 100644 --- a/composer.json +++ b/composer.json @@ -34,10 +34,10 @@ "sort-packages": true }, "autoload": { - "psr-0": { "Doctrine\\DBAL\\": "lib/" } + "psr-4": { "Doctrine\\DBAL\\": "lib/Doctrine/DBAL" } }, "autoload-dev": { - "psr-0": { "Doctrine\\Tests\\": "tests/" } + "psr-4": { "Doctrine\\Tests\\": "tests/Doctrine/Tests" } }, "extra": { "branch-alias": { From b7e34da751e2d9fcff40e04f98fa6081dc638c37 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Fri, 3 Aug 2018 21:51:03 +0200 Subject: [PATCH 06/76] README: Update for 2.8 release --- README.md | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index b0d2e711bca..652e938dc0b 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # Doctrine DBAL -| [Master][Master] | [2.7][2.7] | [2.6][2.6] | [Develop][develop] | +| [Master][Master] | [2.8][2.8] | [2.7][2.7] | [Develop][develop] | |:----------------:|:----------:|:----------:|:--------------:| -| [![Build status][Master image]][Master] | [![Build status][2.7 image]][2.7] | [![Build status][2.6 image]][2.6] | [![Build status][develop image]][develop] | -| [![Build Status][ContinuousPHP image]][ContinuousPHP] | [![Build Status][ContinuousPHP 2.7 image]][ContinuousPHP] | [![Build Status][ContinuousPHP 2.6 image]][ContinuousPHP] | [![Build Status][ContinuousPHP develop image]][ContinuousPHP] | -| [![Code Coverage][Coverage image]][Scrutinizer Master] | [![Code Coverage][Coverage 2.7 image]][Scrutinizer 2.7] | [![Code Coverage][Coverage 2.6 image]][Scrutinizer 2.6] | [![Code Coverage][Coverage develop image]][Scrutinizer develop] | -| [![Code Quality][Quality image]][Scrutinizer Master] | [![Code Quality][Quality 2.7 image]][Scrutinizer 2.7] | [![Code Quality][Quality 2.6 image]][Scrutinizer 2.6] | [![Code Quality][Quality develop image]][Scrutinizer develop] | -| [![AppVeyor][AppVeyor master image]][AppVeyor master] | [![AppVeyor][AppVeyor 2.7 image]][AppVeyor 2.7] | | [![AppVeyor][AppVeyor develop image]][AppVeyor develop] | +| [![Build status][Master image]][Master] | [![Build status][2.8 image]][2.8] | [![Build status][2.7 image]][2.7] | [![Build status][develop image]][develop] | +| [![Build Status][ContinuousPHP image]][ContinuousPHP] | [![Build Status][ContinuousPHP 2.8 image]][ContinuousPHP] | [![Build Status][ContinuousPHP 2.7 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 2.7 image]][Scrutinizer 2.7] | [![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 2.7 image]][Scrutinizer 2.7] | [![Code Quality][Quality develop image]][Scrutinizer develop] | +| [![AppVeyor][AppVeyor master image]][AppVeyor master] | [![AppVeyor][AppVeyor 2.8 image]][AppVeyor 2.8] | [![AppVeyor][AppVeyor 2.7 image]][AppVeyor 2.7] | [![AppVeyor][AppVeyor develop image]][AppVeyor develop] | Powerful database abstraction layer with many features for database schema introspection, schema management and PDO abstraction. @@ -26,6 +26,14 @@ 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.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 [2.7 image]: https://img.shields.io/travis/doctrine/dbal/2.7.svg?style=flat-square [Coverage 2.7 image]: https://img.shields.io/scrutinizer/coverage/g/doctrine/dbal/2.7.svg?style=flat-square [Quality 2.7 image]: https://img.shields.io/scrutinizer/g/doctrine/dbal/2.7.svg?style=flat-square @@ -34,12 +42,6 @@ Powerful database abstraction layer with many features for database schema intro [Scrutinizer 2.7]: https://scrutinizer-ci.com/g/doctrine/dbal/?branch=2.7 [AppVeyor 2.7]: https://ci.appveyor.com/project/doctrine/dbal/branch/2.7 [AppVeyor 2.7 image]: https://ci.appveyor.com/api/projects/status/i88kitq8qpbm0vie/branch/2.7?svg=true - [2.6 image]: https://img.shields.io/travis/doctrine/dbal/2.6.svg?style=flat-square - [Coverage 2.6 image]: https://img.shields.io/scrutinizer/coverage/g/doctrine/dbal/2.6.svg?style=flat-square - [Quality 2.6 image]: https://img.shields.io/scrutinizer/g/doctrine/dbal/2.6.svg?style=flat-square - [ContinuousPHP 2.6 image]: https://img.shields.io/continuousphp/git-hub/doctrine/dbal/2.6.svg?style=flat-square - [2.6]: https://github.com/doctrine/dbal/tree/2.6 - [Scrutinizer 2.6]: https://scrutinizer-ci.com/g/doctrine/dbal/?branch=2.6 [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 8e4faabbb61163246de66681932477d72903daa4 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Fri, 3 Aug 2018 21:52:07 +0200 Subject: [PATCH 07/76] Bump branch alias to 2.9.x-dev --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f631bb3a645..db678f71b62 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,7 @@ }, "extra": { "branch-alias": { - "dev-master": "2.8.x-dev", + "dev-master": "2.9.x-dev", "dev-develop": "3.0.x-dev" } }, From f242a9db3acbc2d1779bbb09982a4d6e3bf6c1e6 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 8 Aug 2018 18:47:33 -0700 Subject: [PATCH 08/76] Deprecated dbal:import CLI command --- UPGRADE.md | 11 +++++++++++ .../DBAL/Tools/Console/Command/ImportCommand.php | 1 + 2 files changed, 12 insertions(+) diff --git a/UPGRADE.md b/UPGRADE.md index 25e2747b67f..b860757156c 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,3 +1,14 @@ +# Upgrade to 2.9 + +## Deprecated dbal:import CLI command + +The `dbal:import` CLI command has been deprecated since it only works with PDO-based drivers by relying on a non-documented behavior of the extension, and it's impossible to make it work with other drivers. +Please use other database client applications for import, e.g.: + + * For MySQL and MariaDB: `mysql [dbname] < data.sql`. + * For PostgreSQL: `psql [dbname] < data.sql`. + * For SQLite: `sqlite3 /path/to/file.db < data.sql`. + # Upgrade to 2.8 ## Deprecated usage of DB-generated UUIDs diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php index 61fb07fb0d6..005cf7ed5a6 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php @@ -42,6 +42,7 @@ * @author Guilherme Blanco * @author Jonathan Wage * @author Roman Borschel + * @deprecated Use a database client application instead */ class ImportCommand extends Command { From b3d80abe4cbcd24f15f042584e363ac96f5c6043 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 15 Aug 2018 19:46:14 -0700 Subject: [PATCH 09/76] Deprecated usage of the NULL offset in LIMITed queries --- UPGRADE.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/UPGRADE.md b/UPGRADE.md index b860757156c..e6730319b00 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,9 @@ # Upgrade to 2.9 +## Deprecated `NULL` value of `$offset` in LIMIT queries + +The `NULL` value of the `$offset` argument in `AbstractPlatform::(do)?ModifyLimitQuery()` methods is deprecated. If explicitly used in the method call, the absence of the offset should be indicated with a `0`. + ## Deprecated dbal:import CLI command The `dbal:import` CLI command has been deprecated since it only works with PDO-based drivers by relying on a non-documented behavior of the extension, and it's impossible to make it work with other drivers. From 35093a4b89c9b301177b74916aae2f50a5b4f711 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 15 Aug 2018 12:58:19 -0700 Subject: [PATCH 10/76] Replaced call_user_func_array() of a fixed method with the usage of variadic arguments --- lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php | 1 - lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php | 8 +++----- .../DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php | 3 +-- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php index 6693d090e5f..68f195427dd 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php @@ -27,7 +27,6 @@ use const DB2_LONG; use const DB2_PARAM_IN; use function array_change_key_case; -use function call_user_func_array; use function db2_bind_param; use function db2_execute; use function db2_fetch_array; diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php index 6941894e009..fb4d6765ead 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php @@ -25,7 +25,6 @@ use Doctrine\DBAL\ParameterType; use function array_combine; use function array_fill; -use function call_user_func_array; use function count; use function str_repeat; @@ -172,7 +171,7 @@ public function execute($params = null) throw new MysqliException($this->_stmt->error, $this->_stmt->errno); } } else { - if (!call_user_func_array([$this->_stmt, 'bind_param'], [$this->types] + $this->_bindedValues)) { + if (! $this->_stmt->bind_param($this->types, ...$this->_bindedValues)) { throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno); } } @@ -221,7 +220,7 @@ public function execute($params = null) $refs[$key] =& $value; } - if (!call_user_func_array([$this->_stmt, 'bind_result'], $refs)) { + if (! $this->_stmt->bind_result(...$refs)) { throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno); } } @@ -242,13 +241,12 @@ private function _bindValues($values) { $params = []; $types = str_repeat('s', count($values)); - $params[0] = $types; foreach ($values as &$v) { $params[] =& $v; } - return call_user_func_array([$this->_stmt, 'bind_param'], $params); + return $this->_stmt->bind_param($types, ...$params); } /** diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php index 1584dadb115..38d7fa0fdf1 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php @@ -26,7 +26,6 @@ use IteratorAggregate; use const SASQL_BOTH; use function array_key_exists; -use function call_user_func_array; use function func_get_args; use function func_num_args; use function gettype; @@ -280,7 +279,7 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n switch ($fetchMode) { case FetchMode::CUSTOM_OBJECT: - while ($row = call_user_func_array([$this, 'fetch'], func_get_args())) { + while ($row = $this->fetch(...func_get_args())) { $rows[] = $row; } break; From 7454e68972a0a8666f5ac6146d1ed1560350cf3a Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Fri, 17 Aug 2018 22:28:10 +0200 Subject: [PATCH 11/76] Deprecate Doctrine\DBAL\Types\Type::__toString() --- UPGRADE.md | 4 ++++ lib/Doctrine/DBAL/Types/Type.php | 2 ++ 2 files changed, 6 insertions(+) diff --git a/UPGRADE.md b/UPGRADE.md index e6730319b00..e1335b1441d 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,9 @@ # Upgrade to 2.9 +## Deprecated `Doctrine\DBAL\Types\Type::__toString()` + +Relying on string representation is discouraged and will be removed in DBAL 3.0. + ## Deprecated `NULL` value of `$offset` in LIMIT queries The `NULL` value of the `$offset` argument in `AbstractPlatform::(do)?ModifyLimitQuery()` methods is deprecated. If explicitly used in the method call, the absence of the offset should be indicated with a `0`. diff --git a/lib/Doctrine/DBAL/Types/Type.php b/lib/Doctrine/DBAL/Types/Type.php index 453631e0aaa..56405dfe909 100644 --- a/lib/Doctrine/DBAL/Types/Type.php +++ b/lib/Doctrine/DBAL/Types/Type.php @@ -274,6 +274,8 @@ public static function getTypesMap() /** * @return string + * + * @deprecated Relying on string representation is discouraged and will be removed in DBAL 3.0. */ public function __toString() { From ceb261682a2ae01137b5565bfa3d45359559234c Mon Sep 17 00:00:00 2001 From: Farhad Safarov Date: Fri, 17 Aug 2018 12:48:44 +0400 Subject: [PATCH 12/76] Throw ConversionException when unserialization fail for array and object types cs fix object type conversionFailedUnserialization type hinting & finally restore error handler cs: use function type hint sort use alphabetically code quality improvements --- lib/Doctrine/DBAL/Types/ArrayType.php | 16 +++++++++++----- lib/Doctrine/DBAL/Types/ConversionException.php | 9 +++++++++ lib/Doctrine/DBAL/Types/ObjectType.php | 16 +++++++++++----- tests/Doctrine/Tests/DBAL/Types/ArrayTest.php | 11 +---------- tests/Doctrine/Tests/DBAL/Types/ObjectTest.php | 10 +--------- 5 files changed, 33 insertions(+), 29 deletions(-) diff --git a/lib/Doctrine/DBAL/Types/ArrayType.php b/lib/Doctrine/DBAL/Types/ArrayType.php index 7fc4fcc9be6..16d48aa1d7f 100644 --- a/lib/Doctrine/DBAL/Types/ArrayType.php +++ b/lib/Doctrine/DBAL/Types/ArrayType.php @@ -21,7 +21,9 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use function is_resource; +use function restore_error_handler; use function serialize; +use function set_error_handler; use function stream_get_contents; use function unserialize; @@ -59,12 +61,16 @@ public function convertToPHPValue($value, AbstractPlatform $platform) } $value = (is_resource($value)) ? stream_get_contents($value) : $value; - $val = unserialize($value); - if ($val === false && $value != 'b:0;') { - throw ConversionException::conversionFailed($value, $this->getName()); - } - return $val; + set_error_handler(function (int $code, string $message) : void { + throw ConversionException::conversionFailedUnserialization($this->getName(), $message); + }); + + try { + return unserialize($value); + } finally { + restore_error_handler(); + } } /** diff --git a/lib/Doctrine/DBAL/Types/ConversionException.php b/lib/Doctrine/DBAL/Types/ConversionException.php index df2eb74a38f..cab786de5d3 100644 --- a/lib/Doctrine/DBAL/Types/ConversionException.php +++ b/lib/Doctrine/DBAL/Types/ConversionException.php @@ -120,4 +120,13 @@ public static function conversionFailedSerialization($value, $format, $error) $error )); } + + public static function conversionFailedUnserialization(string $format, string $error) : self + { + return new self(sprintf( + "Could not convert database value to '%s' as an error was triggered by the unserialization: '%s'", + $format, + $error + )); + } } diff --git a/lib/Doctrine/DBAL/Types/ObjectType.php b/lib/Doctrine/DBAL/Types/ObjectType.php index 95fe84a5a19..0547377c9c2 100644 --- a/lib/Doctrine/DBAL/Types/ObjectType.php +++ b/lib/Doctrine/DBAL/Types/ObjectType.php @@ -21,7 +21,9 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use function is_resource; +use function restore_error_handler; use function serialize; +use function set_error_handler; use function stream_get_contents; use function unserialize; @@ -58,12 +60,16 @@ public function convertToPHPValue($value, AbstractPlatform $platform) } $value = (is_resource($value)) ? stream_get_contents($value) : $value; - $val = unserialize($value); - if ($val === false && $value !== 'b:0;') { - throw ConversionException::conversionFailed($value, $this->getName()); - } - return $val; + set_error_handler(function (int $code, string $message) : void { + throw ConversionException::conversionFailedUnserialization($this->getName(), $message); + }); + + try { + return unserialize($value); + } finally { + restore_error_handler(); + } } /** diff --git a/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php b/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php index f230491409a..c6599e66d65 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php @@ -5,9 +5,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; -use const E_ALL; -use const E_STRICT; -use function error_reporting; use function serialize; class ArrayTest extends \Doctrine\Tests\DbalTestCase @@ -28,12 +25,6 @@ protected function setUp() $this->_type = Type::getType('array'); } - protected function tearDown() - { - error_reporting(-1); // reactive all error levels - } - - public function testArrayConvertsToDatabaseValue() { self::assertInternalType( @@ -52,8 +43,8 @@ public function testArrayConvertsToPHPValue() public function testConversionFailure() { - error_reporting( (E_ALL | E_STRICT) - \E_NOTICE ); $this->expectException('Doctrine\DBAL\Types\ConversionException'); + $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); } diff --git a/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php b/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php index 63ded4ca082..bd4fcd8057d 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php @@ -4,9 +4,6 @@ use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; -use const E_ALL; -use const E_STRICT; -use function error_reporting; use function serialize; class ObjectTest extends \Doctrine\Tests\DbalTestCase @@ -27,11 +24,6 @@ protected function setUp() $this->_type = Type::getType('object'); } - protected function tearDown() - { - error_reporting(-1); // reactive all error levels - } - public function testObjectConvertsToDatabaseValue() { self::assertInternalType('string', $this->_type->convertToDatabaseValue(new \stdClass(), $this->_platform)); @@ -44,8 +36,8 @@ public function testObjectConvertsToPHPValue() public function testConversionFailure() { - error_reporting( (E_ALL | E_STRICT) - \E_NOTICE ); $this->expectException('Doctrine\DBAL\Types\ConversionException'); + $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); } From 488c5294d7e4e8dd4a6c7cb57e46e2fc5f8c4e30 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Sat, 18 Aug 2018 01:29:01 +0200 Subject: [PATCH 13/76] Update export-ignores --- .gitattributes | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/.gitattributes b/.gitattributes index d15eb35f48f..5bbaf359701 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,12 +1,15 @@ -/tests export-ignore +/.appveyor.yml export-ignore +/.gitattributes export-ignore +/.github export-ignore +/.gitignore export-ignore +/.scrutinizer.yml export-ignore +/.travis.yml export-ignore +/build.properties export-ignore +/build.xml export-ignore +/composer.lock export-ignore /docs export-ignore -.gitattributes export-ignore -.gitignore export-ignore -.appveyor.yml export-ignore -.travis.yml export-ignore -build.properties export-ignore -build.xml export-ignore -phpunit.xml.dist export-ignore -run-all.sh export-ignore /phpcs.xml.dist export-ignore -/composer.lock export-ignore +/phpstan.neon.dist export-ignore +/phpunit.xml.dist export-ignore +/run-all.sh export-ignore +/tests export-ignore From 1bfc30bd284222aeac7951a530bb54f7ce383657 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Sat, 18 Aug 2018 01:29:44 +0200 Subject: [PATCH 14/76] Drop archive.exclude section in composer.json --- composer.json | 3 --- composer.lock | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/composer.json b/composer.json index db678f71b62..01c5abc97ec 100644 --- a/composer.json +++ b/composer.json @@ -44,8 +44,5 @@ "dev-master": "2.9.x-dev", "dev-develop": "3.0.x-dev" } - }, - "archive": { - "exclude": ["!vendor", "tests", "*phpunit.xml", ".appveyor.yml", ".travis.yml", "build.xml", "build.properties", "composer.phar"] } } diff --git a/composer.lock b/composer.lock index 4d74e4eb956..8eb6bc50ee9 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": "69dd02e4a1e8f77823b3676b3f707ef6", + "content-hash": "c1b5ddb5a1259c7ac793dd9c6e6d657a", "packages": [ { "name": "doctrine/cache", From c38bbcc09cd9579338dbb4c827b4cf42d17bfa9e Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Fri, 17 Aug 2018 22:02:09 +0200 Subject: [PATCH 15/76] Deprecate Doctrine\DBAL\Types\Type::getDefaultLength() --- UPGRADE.md | 4 ++++ lib/Doctrine/DBAL/Types/Type.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/UPGRADE.md b/UPGRADE.md index e1335b1441d..31d3fd94955 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,9 @@ # Upgrade to 2.9 +## Deprecated `Doctrine\DBAL\Types\Type::getDefaultLength()` + +This method was never used by DBAL internally. It is now deprecated and will be removed in DBAL 3.0. + ## Deprecated `Doctrine\DBAL\Types\Type::__toString()` Relying on string representation is discouraged and will be removed in DBAL 3.0. diff --git a/lib/Doctrine/DBAL/Types/Type.php b/lib/Doctrine/DBAL/Types/Type.php index 56405dfe909..31f93866b9a 100644 --- a/lib/Doctrine/DBAL/Types/Type.php +++ b/lib/Doctrine/DBAL/Types/Type.php @@ -146,7 +146,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) * * @return int|null * - * @todo Needed? + * @deprecated Rely on information provided by the platform instead. */ public function getDefaultLength(AbstractPlatform $platform) { From 9427bd3d1f79497fd365c4894cb6558702a73a65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ronald=20M=C3=A1rf=C3=B6ldi?= Date: Thu, 23 Aug 2018 14:03:42 +0200 Subject: [PATCH 16/76] Fixed type hints in DockBlocks As the explanatory description says: "The name or position of the parameter." --- lib/Doctrine/DBAL/Statement.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/Doctrine/DBAL/Statement.php b/lib/Doctrine/DBAL/Statement.php index 9ee252bd7d0..fb1da7927bd 100644 --- a/lib/Doctrine/DBAL/Statement.php +++ b/lib/Doctrine/DBAL/Statement.php @@ -97,9 +97,9 @@ public function __construct($sql, Connection $conn) * type and the value undergoes the conversion routines of the mapping type before * being bound. * - * @param string $name The name or position of the parameter. - * @param mixed $value The value of the parameter. - * @param mixed $type Either a PDO binding type or a DBAL mapping type name or instance. + * @param string|int $name The name or position of the parameter. + * @param mixed $value The value of the parameter. + * @param mixed $type Either a PDO binding type or a DBAL mapping type name or instance. * * @return bool TRUE on success, FALSE on failure. */ @@ -129,11 +129,11 @@ public function bindValue($name, $value, $type = ParameterType::STRING) * * Binding a parameter by reference does not support DBAL mapping types. * - * @param string $name The name or position of the parameter. - * @param mixed $var The reference to the variable to bind. - * @param int $type The PDO binding type. - * @param int|null $length Must be specified when using an OUT bind - * so that PHP allocates enough memory to hold the returned value. + * @param string|int $name The name or position of the parameter. + * @param mixed $var The reference to the variable to bind. + * @param int $type The PDO binding type. + * @param int|null $length Must be specified when using an OUT bind + * so that PHP allocates enough memory to hold the returned value. * * @return bool TRUE on success, FALSE on failure. */ From 13b673c3697cad29a9d9cf810af59d5fcf791f49 Mon Sep 17 00:00:00 2001 From: Alexander Deider Date: Thu, 30 Aug 2018 00:14:28 +0700 Subject: [PATCH 17/76] Schema\Sequence: force prospective type in setters for correct comparision --- lib/Doctrine/DBAL/Schema/Sequence.php | 8 ++++---- tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/DBAL/Schema/Sequence.php b/lib/Doctrine/DBAL/Schema/Sequence.php index 6d304cde4b6..607b76553e7 100644 --- a/lib/Doctrine/DBAL/Schema/Sequence.php +++ b/lib/Doctrine/DBAL/Schema/Sequence.php @@ -57,8 +57,8 @@ class Sequence extends AbstractAsset public function __construct($name, $allocationSize = 1, $initialValue = 1, $cache = null) { $this->_setName($name); - $this->allocationSize = is_numeric($allocationSize) ? $allocationSize : 1; - $this->initialValue = is_numeric($initialValue) ? $initialValue : 1; + $this->setAllocationSize($allocationSize); + $this->setInitialValue($initialValue); $this->cache = $cache; } @@ -93,7 +93,7 @@ public function getCache() */ public function setAllocationSize($allocationSize) { - $this->allocationSize = is_numeric($allocationSize) ? $allocationSize : 1; + $this->allocationSize = is_numeric($allocationSize) ? (int) $allocationSize : 1; return $this; } @@ -105,7 +105,7 @@ public function setAllocationSize($allocationSize) */ public function setInitialValue($initialValue) { - $this->initialValue = is_numeric($initialValue) ? $initialValue : 1; + $this->initialValue = is_numeric($initialValue) ? (int) $initialValue : 1; return $this; } diff --git a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php index 40250020023..24d097c3006 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php @@ -435,11 +435,13 @@ public function testCompareSequences() $seq1 = new Sequence('foo', 1, 1); $seq2 = new Sequence('foo', 1, 2); $seq3 = new Sequence('foo', 2, 1); + $seq4 = new Sequence('foo', '1', '1'); $c = new Comparator(); self::assertTrue($c->diffSequence($seq1, $seq2)); self::assertTrue($c->diffSequence($seq1, $seq3)); + self::assertFalse($c->diffSequence($seq1, $seq4)); } public function testRemovedSequence() From 436780bcbee22a9d98aed2771f793f7e0bfe9a7a Mon Sep 17 00:00:00 2001 From: "Jonathan H. Wage" Date: Fri, 31 Aug 2018 20:08:47 +0100 Subject: [PATCH 18/76] Add .doctrine-project.json to root of the project. --- .doctrine-project.json | 49 ++++++++++++++++++++++++++++++++++++++++++ composer.json | 13 +++++++++-- 2 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 .doctrine-project.json diff --git a/.doctrine-project.json b/.doctrine-project.json new file mode 100644 index 00000000000..9fb3d836c74 --- /dev/null +++ b/.doctrine-project.json @@ -0,0 +1,49 @@ +{ + "active": true, + "name": "Database Abstraction Layer", + "shortName": "DBAL", + "slug": "dbal", + "docsSlug": "doctrine-dbal", + "versions": [ + { + "name": "3.0", + "branchName": "develop", + "slug": "latest", + "upcoming": true + }, + { + "name": "2.9", + "branchName": "master", + "slug": "2.9", + "upcoming": true + }, + { + "name": "2.8", + "branchName": "2.8", + "slug": "2.8", + "current": true, + "aliases": [ + "current", + "stable" + ] + }, + { + "name": "2.7", + "branchName": "2.7", + "slug": "2.7", + "maintained": false + }, + { + "name": "2.6", + "branchName": "2.6", + "slug": "2.6", + "maintained": false + }, + { + "name": "2.5", + "branchName": "2.5", + "slug": "2.5", + "maintained": false + } + ] +} diff --git a/composer.json b/composer.json index 01c5abc97ec..7eef54c0c1d 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,17 @@ { "name": "doctrine/dbal", "type": "library", - "description": "Database Abstraction Layer", - "keywords": ["dbal", "database", "persistence", "queryobject"], + "description": "Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.", + "keywords": [ + "php", + "mysql", + "pgsql", + "dbal", + "database", + "abstraction", + "persistence", + "queryobject" + ], "homepage": "http://www.doctrine-project.org", "license": "MIT", "authors": [ From d7ccc5665e9a3aaa059cb786860fad841a547589 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Fri, 31 Aug 2018 23:32:42 +0200 Subject: [PATCH 19/76] Update homepage --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7eef54c0c1d..ab00c8cddf4 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "persistence", "queryobject" ], - "homepage": "http://www.doctrine-project.org", + "homepage": "https://www.doctrine-project.org/projects/dbal.html", "license": "MIT", "authors": [ {"name": "Guilherme Blanco", "email": "guilhermeblanco@gmail.com"}, From 5682b66827e14729eebb6c44ed2b643d67b3e9c9 Mon Sep 17 00:00:00 2001 From: Bruno Vitorino Date: Mon, 23 Jul 2018 16:45:40 +0200 Subject: [PATCH 20/76] Ignore case when matching ARRAY --- lib/Doctrine/DBAL/SQLParserUtils.php | 2 +- tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/DBAL/SQLParserUtils.php b/lib/Doctrine/DBAL/SQLParserUtils.php index e635af754d9..c24607f0e83 100644 --- a/lib/Doctrine/DBAL/SQLParserUtils.php +++ b/lib/Doctrine/DBAL/SQLParserUtils.php @@ -51,7 +51,7 @@ class SQLParserUtils const ESCAPED_SINGLE_QUOTED_TEXT = "(?:'(?:\\\\\\\\)+'|'(?:[^'\\\\]|\\\\'?|'')*')"; const ESCAPED_DOUBLE_QUOTED_TEXT = '(?:"(?:\\\\\\\\)+"|"(?:[^"\\\\]|\\\\"?)*")'; const ESCAPED_BACKTICK_QUOTED_TEXT = '(?:`(?:\\\\\\\\)+`|`(?:[^`\\\\]|\\\\`?)*`)'; - const ESCAPED_BRACKET_QUOTED_TEXT = '(? :start_date AND baz > :start_date', false, array(46 => 'start_date', 68 => 'start_date')), // Ticket GH-259 array('SELECT `d.ns:col_name` FROM my_table d WHERE `d.date` >= :param1', false, array(57 => 'param1')), // Ticket DBAL-552 array('SELECT [d.ns:col_name] FROM my_table d WHERE [d.date] >= :param1', false, array(57 => 'param1')), // Ticket DBAL-552 - array('SELECT * FROM foo WHERE jsonb_exists_any(foo.bar, ARRAY[:foo])', false, array(56 => 'foo')), // Ticket GH-2295 + ['SELECT * FROM foo WHERE jsonb_exists_any(foo.bar, ARRAY[:foo])', false, [56 => 'foo']], // Ticket GH-2295 + ['SELECT * FROM foo WHERE jsonb_exists_any(foo.bar, array[:foo])', false, [56 => 'foo']], array( <<<'SQLDATA' SELECT * FROM foo WHERE From 133571c86dd6cd69cd4de07e63e680aeafeeda93 Mon Sep 17 00:00:00 2001 From: Gert de Pagter Date: Sat, 8 Sep 2018 18:19:19 +0200 Subject: [PATCH 21/76] Behavior > Behaviour Same as other templates --- .github/ISSUE_TEMPLATE/Bug.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/Bug.md b/.github/ISSUE_TEMPLATE/Bug.md index 466769fc7a2..2e7d29ca027 100644 --- a/.github/ISSUE_TEMPLATE/Bug.md +++ b/.github/ISSUE_TEMPLATE/Bug.md @@ -16,7 +16,7 @@ about: Something is broken? 🔨 -#### Current behavior +#### Current behaviour From b3f57e70da23461d48025ec30be91a4b7282bdbb Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Wed, 12 Sep 2018 13:35:03 +0200 Subject: [PATCH 22/76] Remove old comment from MysqliStatement As discussed in #3217 (see https://github.com/doctrine/dbal/pull/3217#issuecomment-419673323 in particular), there is no way in MySQL to get around the `max_allowed_packet` limitation. --- lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php index fb4d6765ead..8b4f9a58006 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php @@ -42,8 +42,6 @@ class MysqliStatement implements \IteratorAggregate, Statement ParameterType::BOOLEAN => 'i', ParameterType::NULL => 's', ParameterType::INTEGER => 'i', - - // TODO Support LOB bigger then max package size ParameterType::LARGE_OBJECT => 's', ]; From 0da0450097b54de75c8e0b7546e9284eb5ab71fc Mon Sep 17 00:00:00 2001 From: Oleg Zhulnev Date: Mon, 10 Sep 2018 23:26:18 +0300 Subject: [PATCH 23/76] MariaDB improvements, refactoring default keywords for 10.2 version and extends them for 10.3 revert back MariaDb1027Platform --- .travis.yml | 12 ++++++++++++ docs/en/reference/platforms.rst | 5 +++++ lib/Doctrine/DBAL/Platforms/MariaDb1027Platform.php | 10 +--------- .../Tests/DBAL/Platforms/MariaDb1027PlatformTest.php | 2 -- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7bf23c9c0b3..9ca1ebe5509 100644 --- a/.travis.yml +++ b/.travis.yml @@ -179,6 +179,18 @@ jobs: addons: mariadb: 10.2 + - 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.1 env: DB=pgsql POSTGRESQL_VERSION=9.2 COVERAGE=yes diff --git a/docs/en/reference/platforms.rst b/docs/en/reference/platforms.rst index 5f57fec9226..32ef74304ea 100644 --- a/docs/en/reference/platforms.rst +++ b/docs/en/reference/platforms.rst @@ -37,6 +37,11 @@ MySQL - ``MySQL57Platform`` for version 5.7 (5.7.9 GA) and above. - ``MySQL80Platform`` for version 8.0 (8.0 GA) and above. +MariaDB +^^^^^ + +- ``MariaDb1027Platform`` for version 10.2 (10.2.7 GA) and above. + Oracle ^^^^^^ diff --git a/lib/Doctrine/DBAL/Platforms/MariaDb1027Platform.php b/lib/Doctrine/DBAL/Platforms/MariaDb1027Platform.php index 1955fb05912..4c1f6b3f8b0 100644 --- a/lib/Doctrine/DBAL/Platforms/MariaDb1027Platform.php +++ b/lib/Doctrine/DBAL/Platforms/MariaDb1027Platform.php @@ -24,21 +24,13 @@ /** * Provides the behavior, features and SQL dialect of the MariaDB 10.2 (10.2.7 GA) database platform. * - * Note: Should not be used with versions prior ro 10.2.7. + * Note: Should not be used with versions prior to 10.2.7. * * @author Vanvelthem Sébastien * @link www.doctrine-project.org */ final class MariaDb1027Platform extends MySqlPlatform { - /** - * {@inheritdoc} - */ - public function hasNativeJsonType() : bool - { - return false; - } - /** * {@inheritdoc} * diff --git a/tests/Doctrine/Tests/DBAL/Platforms/MariaDb1027PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/MariaDb1027PlatformTest.php index 79d08d1a07d..138a55ef714 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/MariaDb1027PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/MariaDb1027PlatformTest.php @@ -3,8 +3,6 @@ namespace Doctrine\Tests\DBAL\Platforms; use Doctrine\DBAL\Platforms\MariaDb1027Platform; -use Doctrine\DBAL\Schema\Comparator; -use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Type; class MariaDb1027PlatformTest extends AbstractMySQLPlatformTestCase From 53406e84cb50a1657b2b57f7fa4246fad2c36a15 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sat, 22 Sep 2018 22:31:18 -0700 Subject: [PATCH 24/76] Do not generate SID or SERVICE_NAME when dbname or service name is not specified Refactored the logic of connection string generation --- .../DBAL/Driver/AbstractOracleDriver.php | 42 +----- .../EasyConnectString.php | 121 ++++++++++++++++++ .../EasyConnectStringTest.php | 61 +++++++++ 3 files changed, 184 insertions(+), 40 deletions(-) create mode 100644 lib/Doctrine/DBAL/Driver/AbstractOracleDriver/EasyConnectString.php create mode 100644 tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriver/EasyConnectStringTest.php diff --git a/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php b/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php index 26cfcd1500c..f58b564f3c5 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php @@ -20,6 +20,7 @@ namespace Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver; +use Doctrine\DBAL\Driver\AbstractOracleDriver\EasyConnectString; use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Schema\OracleSchemaManager; @@ -108,48 +109,9 @@ public function getSchemaManager(\Doctrine\DBAL\Connection $conn) * @param array $params The connection parameters to return the Easy Connect STring for. * * @return string - * - * @link https://docs.oracle.com/database/121/NETAG/naming.htm */ protected function getEasyConnectString(array $params) { - if ( ! empty($params['connectstring'])) { - return $params['connectstring']; - } - - if ( ! empty($params['host'])) { - if ( ! isset($params['port'])) { - $params['port'] = 1521; - } - - $serviceName = $params['dbname']; - - if ( ! empty($params['servicename'])) { - $serviceName = $params['servicename']; - } - - $service = 'SID=' . $serviceName; - $pooled = ''; - $instance = ''; - - if (isset($params['service']) && $params['service'] == true) { - $service = 'SERVICE_NAME=' . $serviceName; - } - - if (isset($params['instancename']) && ! empty($params['instancename'])) { - $instance = '(INSTANCE_NAME = ' . $params['instancename'] . ')'; - } - - if (isset($params['pooled']) && $params['pooled'] == true) { - $pooled = '(SERVER=POOLED)'; - } - - return '(DESCRIPTION=' . - '(ADDRESS=(PROTOCOL=TCP)(HOST=' . $params['host'] . ')(PORT=' . $params['port'] . '))' . - '(CONNECT_DATA=(' . $service . ')' . $instance . $pooled . '))'; - - } - - return $params['dbname'] ?? ''; + return (string) EasyConnectString::fromConnectionParameters($params); } } diff --git a/lib/Doctrine/DBAL/Driver/AbstractOracleDriver/EasyConnectString.php b/lib/Doctrine/DBAL/Driver/AbstractOracleDriver/EasyConnectString.php new file mode 100644 index 00000000000..01f648b3b85 --- /dev/null +++ b/lib/Doctrine/DBAL/Driver/AbstractOracleDriver/EasyConnectString.php @@ -0,0 +1,121 @@ +string = $string; + } + + public function __toString() : string + { + return $this->string; + } + + /** + * Creates the object from an array representation + * + * @param mixed[] $params + */ + public static function fromArray(array $params) : self + { + return new self(self::renderParams($params)); + } + + /** + * Creates the object from the given DBAL connection parameters. + * + * @param mixed[] $params + */ + public static function fromConnectionParameters(array $params) : self + { + if (! empty($params['connectstring'])) { + return new self($params['connectstring']); + } + + if (empty($params['host'])) { + return new self($params['dbname'] ?? ''); + } + + $connectData = []; + + if (isset($params['servicename']) || isset($params['dbname'])) { + $serviceKey = 'SID'; + + if (! empty($params['service'])) { + $serviceKey = 'SERVICE_NAME'; + } + + $serviceName = $params['servicename'] ?? $params['dbname']; + + $connectData[$serviceKey] = $serviceName; + } + + if (! empty($params['instancename'])) { + $connectData['INSTANCE_NAME'] = $params['instancename']; + } + + if (! empty($params['pooled'])) { + $connectData['SERVER'] = 'POOLED'; + } + + return self::fromArray([ + 'DESCRIPTION' => [ + 'ADDRESS' => [ + 'PROTOCOL' => 'TCP', + 'HOST' => $params['host'], + 'PORT' => $params['port'] ?? 1521, + ], + 'CONNECT_DATA' => $connectData, + ], + ]); + } + + /** + * @param mixed[] $params + */ + private static function renderParams(array $params) : string + { + $chunks = []; + + foreach ($params as $key => $value) { + $string = self::renderValue($value); + + if ($string === '') { + continue; + } + + $chunks[] = sprintf('(%s=%s)', $key, $string); + } + + return implode('', $chunks); + } + + /** + * @param mixed $value + */ + private static function renderValue($value) : string + { + if (is_array($value)) { + return self::renderParams($value); + } + + return (string) $value; + } +} diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriver/EasyConnectStringTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriver/EasyConnectStringTest.php new file mode 100644 index 00000000000..812a46b5682 --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriver/EasyConnectStringTest.php @@ -0,0 +1,61 @@ +assertSame($expected, (string) $string); + } + + /** + * @return mixed[] + */ + public static function connectionParametersProvider() : iterable + { + return [ + 'empty-params' => [[],''], + 'common-params' => [ + [ + 'host' => 'oracle.example.com', + 'port' => 1521, + 'dbname' => 'XE', + ], + '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=oracle.example.com)(PORT=1521))(CONNECT_DATA=(SID=XE)))', + ], + 'no-db-name' => [ + ['host' => 'localhost'], + '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))', + ], + 'service' => [ + [ + 'host' => 'localhost', + 'port' => 1521, + 'service' => true, + 'servicename' => 'BILLING', + ], + '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=BILLING)))', + ], + 'advanced-params' => [ + [ + 'host' => 'localhost', + 'port' => 41521, + 'dbname' => 'XE', + 'instancename' => 'SALES', + 'pooled' => true, + ], + '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=41521))(CONNECT_DATA=(SID=XE)(INSTANCE_NAME=SALES)(SERVER=POOLED)))', + ], + ]; + } +} From 72dcd04f3f5730bb8e90e1209d84a2aab9876f14 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Wed, 12 Sep 2018 13:22:31 +0200 Subject: [PATCH 25/76] Fix that MysqliStatement cannot handle streams The blob type maps BLOB (and also TEXT) columns to PHP streams. Internally, they use the ParameterType::LARGE_OBJECT (i. e. \PDO::PARAM_LOB) binding type, which suggests that efficient handling of PHP stream resources was intended. However, at least when using the mysqli driver, stream resources passed into insert() or update() are simply cast to strings. As a result, a literal string like "Resource id #126" will end up in the database. This PR fixes the issue by correctly processing streams in the MysqliStatement when they are passed with the ParameterType::LARGE_OBJECT binding type. It uses the mysqli::send_long_data() method to pass stream data in chunks to the MySQL server, thus keeping the memory footprint low. This method does not (despite claims to the contrary) allow to bypass the max_allowed_package size! The pdo_mysql driver was already capable of handling streams this way. Now this is covered by tests. Helpful documentation: - http://php.net/manual/en/mysqli-stmt.send-long-data.php - http://php.net/manual/en/mysqli-stmt.bind-param.php - see first "Note" - http://php.net/manual/en/pdo.lobs.php - https://blogs.oracle.com/oswald/phps-mysqli-extension:-storing-and-retrieving-blobs Additional notes on MySQL's max_allowed_packet: This change does not not intend to work around the max_allowed_packet setting, and quick tests show that this is not possible: When MySQL is configured to use a low max_allowed_packet value, an error will be triggered stating Parameter of prepared statement which is set through mysql_send_long_data() is longer than 'max_allowed_packet' bytes. Documentation for the underlying mysql_stmt_send_long_data() C API function suggests that max_allowed_packet is always a hard limit. References: - https://dev.mysql.com/doc/refman/8.0/en/mysql-stmt-send-long-data.html - https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_max_allowed_packet - https://bugs.mysql.com/bug.php?id=83958 What mysqli::send_long_data() seems to do is that every data chunk of data passed to it is immediately sent out to the network. I have confirmed this using tcpdump, and so the advantage might be that we can keep the memory footprint low on the PHP side while processing streams. --- .../DBAL/Driver/Mysqli/MysqliStatement.php | 68 ++++++++++++++- .../Tests/DBAL/Functional/BlobTest.php | 83 +++++++++++++++++-- 2 files changed, 144 insertions(+), 7 deletions(-) diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php index 8b4f9a58006..fe7d4c1297f 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php @@ -21,11 +21,16 @@ use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\Driver\StatementIterator; +use Doctrine\DBAL\Exception\InvalidArgumentException; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; use function array_combine; use function array_fill; use function count; +use function feof; +use function fread; +use function get_resource_type; +use function is_resource; use function str_repeat; /** @@ -42,7 +47,7 @@ class MysqliStatement implements \IteratorAggregate, Statement ParameterType::BOOLEAN => 'i', ParameterType::NULL => 's', ParameterType::INTEGER => 'i', - ParameterType::LARGE_OBJECT => 's', + ParameterType::LARGE_OBJECT => 'b', ]; /** @@ -169,9 +174,11 @@ public function execute($params = null) throw new MysqliException($this->_stmt->error, $this->_stmt->errno); } } else { - if (! $this->_stmt->bind_param($this->types, ...$this->_bindedValues)) { + list($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); } } @@ -228,6 +235,63 @@ public function execute($params = null) return true; } + /** + * 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> + */ + private function separateBoundValues() + { + $streams = $values = []; + $types = $this->types; + + foreach ($this->_bindedValues as $parameter => $value) { + if (! isset($types[$parameter - 1])) { + $types[$parameter - 1] = static::$_paramTypeMap[ParameterType::STRING]; + } + + if ($types[$parameter - 1] === static::$_paramTypeMap[ParameterType::LARGE_OBJECT]) { + if (is_resource($value)) { + if (get_resource_type($value) !== 'stream') { + throw new InvalidArgumentException('Resources passed with the LARGE_OBJECT parameter type must be stream resources.'); + } + $streams[$parameter] = $value; + $values[$parameter] = null; + continue; + } else { + $types[$parameter - 1] = static::$_paramTypeMap[ParameterType::STRING]; + } + } + + $values[$parameter] = $value; + } + + return [$types, $values, $streams]; + } + + /** + * Handle $this->_longData after regular query parameters have been bound + * + * @throws MysqliException + */ + private function sendLongData($streams) + { + foreach ($streams as $paramNr => $stream) { + while (! feof($stream)) { + $chunk = fread($stream, 8192); + + if ($chunk === false) { + throw new MysqliException("Failed reading the stream resource for parameter offset ${paramNr}."); + } + + if (! $this->_stmt->send_long_data($paramNr - 1, $chunk)) { + throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno); + } + } + } + } + /** * Binds a array of values to bound parameters. * diff --git a/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php b/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php index c8249d050ee..e409f5f5f5e 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php @@ -3,11 +3,13 @@ namespace Doctrine\Tests\DBAL\Functional; use Doctrine\DBAL\Driver\PDOSqlsrv\Driver as PDOSQLSrvDriver; +use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Type; -use const CASE_LOWER; -use function array_change_key_case; +use function fopen; +use function in_array; +use function str_repeat; use function stream_get_contents; /** @@ -49,6 +51,28 @@ public function testInsert() self::assertEquals(1, $ret); } + public function testInsertProcessesStream() + { + if (in_array($this->_conn->getDatabasePlatform()->getName(), ['oracle', 'db2'], true)) { + // https://github.com/doctrine/dbal/issues/3288 for DB2 + // https://github.com/doctrine/dbal/issues/3290 for Oracle + $this->markTestIncomplete('Platform does not support stream resources as parameters'); + } + + $longBlob = str_repeat('x', 4 * 8192); // send 4 chunks + $this->_conn->insert('blob_table', [ + 'id' => 1, + 'clobfield' => 'ignored', + 'blobfield' => fopen('data://text/plain,' . $longBlob, 'r'), + ], [ + ParameterType::INTEGER, + ParameterType::STRING, + ParameterType::LARGE_OBJECT, + ]); + + $this->assertBlobContains($longBlob); + } + public function testSelect() { $this->_conn->insert('blob_table', [ @@ -86,14 +110,63 @@ public function testUpdate() $this->assertBlobContains('test2'); } + public function testUpdateProcessesStream() + { + if (in_array($this->_conn->getDatabasePlatform()->getName(), ['oracle', 'db2'], true)) { + // https://github.com/doctrine/dbal/issues/3288 for DB2 + // https://github.com/doctrine/dbal/issues/3290 for Oracle + $this->markTestIncomplete('Platform does not support stream resources as parameters'); + } + + $this->_conn->insert('blob_table', [ + 'id' => 1, + 'clobfield' => 'ignored', + 'blobfield' => 'test', + ], [ + ParameterType::INTEGER, + ParameterType::STRING, + ParameterType::LARGE_OBJECT, + ]); + + $this->_conn->update('blob_table', [ + 'id' => 1, + 'blobfield' => fopen('data://text/plain,test2', 'r'), + ], ['id' => 1], [ + ParameterType::INTEGER, + ParameterType::LARGE_OBJECT, + ]); + + $this->assertBlobContains('test2'); + } + + public function testBindParamProcessesStream() + { + if (in_array($this->_conn->getDatabasePlatform()->getName(), ['oracle', 'db2'], true)) { + // https://github.com/doctrine/dbal/issues/3288 for DB2 + // https://github.com/doctrine/dbal/issues/3290 for Oracle + $this->markTestIncomplete('Platform does not support stream resources as parameters'); + } + + $stmt = $this->_conn->prepare("INSERT INTO blob_table(id, clobfield, blobfield) VALUES (1, 'ignored', ?)"); + + $stream = null; + $stmt->bindParam(1, $stream, ParameterType::LARGE_OBJECT); + + // Bind param does late binding (bind by reference), so create the stream only now: + $stream = fopen('data://text/plain,test', 'r'); + + $stmt->execute(); + + $this->assertBlobContains('test'); + } + private function assertBlobContains($text) { - $rows = $this->_conn->fetchAll('SELECT * FROM blob_table'); + $rows = $this->_conn->query('SELECT blobfield FROM blob_table')->fetchAll(FetchMode::COLUMN); self::assertCount(1, $rows); - $row = array_change_key_case($rows[0], CASE_LOWER); - $blobValue = Type::getType('blob')->convertToPHPValue($row['blobfield'], $this->_conn->getDatabasePlatform()); + $blobValue = Type::getType('blob')->convertToPHPValue($rows[0], $this->_conn->getDatabasePlatform()); self::assertInternalType('resource', $blobValue); self::assertEquals($text, stream_get_contents($blobValue)); From f18ced5692b15e6aba7749228e9f54c8fe590dbe Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 26 Sep 2018 23:01:23 -0700 Subject: [PATCH 26/76] Updated doctrine/coding-standard to ^5 --- .travis.yml | 2 +- composer.json | 2 +- composer.lock | 54 ++++++++++++++++++++++++++------------------------- 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9ca1ebe5509..0162cd7808d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -442,7 +442,7 @@ jobs: git fetch origin $TRAVIS_BRANCH; fi - git merge-base origin/$TRAVIS_BRANCH $TRAVIS_PULL_REQUEST_SHA || git fetch origin +refs/pull/$TRAVIS_PULL_REQUEST/merge --unshallow - - wget https://github.com/diff-sniffer/git/releases/download/0.1.0/git-phpcs.phar + - wget https://github.com/diff-sniffer/git/releases/download/0.2.0/git-phpcs.phar - php git-phpcs.phar origin/$TRAVIS_BRANCH...$TRAVIS_PULL_REQUEST_SHA - stage: Coding standard diff --git a/composer.json b/composer.json index ab00c8cddf4..c0a35f4d9cb 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "doctrine/event-manager": "^1.0" }, "require-dev": { - "doctrine/coding-standard": "^4.0", + "doctrine/coding-standard": "^5.0", "jetbrains/phpstorm-stubs": "^2018.1.2", "phpstan/phpstan": "^0.10.1", "phpunit/phpunit": "^7.1.2", diff --git a/composer.lock b/composer.lock index 8eb6bc50ee9..0ac48fe1249 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": "c1b5ddb5a1259c7ac793dd9c6e6d657a", + "content-hash": "a6e554864457c4bf9babe37f88174255", "packages": [ { "name": "doctrine/cache", @@ -270,28 +270,28 @@ }, { "name": "doctrine/coding-standard", - "version": "4.0.0", + "version": "5.0.0", "source": { "type": "git", "url": "https://github.com/doctrine/coding-standard.git", - "reference": "0469c18a1a4724c278f2879c0dd7b1fa860b52de" + "reference": "bb8de042a25c4fb59a2c55c350dc55cc00227a8c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/coding-standard/zipball/0469c18a1a4724c278f2879c0dd7b1fa860b52de", - "reference": "0469c18a1a4724c278f2879c0dd7b1fa860b52de", + "url": "https://api.github.com/repos/doctrine/coding-standard/zipball/bb8de042a25c4fb59a2c55c350dc55cc00227a8c", + "reference": "bb8de042a25c4fb59a2c55c350dc55cc00227a8c", "shasum": "" }, "require": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.4.2", + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.4", "php": "^7.1", - "slevomat/coding-standard": "^4.5.0", - "squizlabs/php_codesniffer": "^3.2.3" + "slevomat/coding-standard": "^4.8.0", + "squizlabs/php_codesniffer": "^3.3.2" }, "type": "phpcodesniffer-standard", "extra": { "branch-alias": { - "dev-master": "3.0.x-dev" + "dev-master": "5.0.x-dev" } }, "autoload": { @@ -313,18 +313,21 @@ "email": "st.mueller@dzh-online.de" } ], - "description": "Doctrine Coding Standard", - "homepage": "http://www.doctrine-project.org", + "description": "The Doctrine Coding Standard is a set of PHPCS rules applied to all Doctrine projects.", + "homepage": "https://www.doctrine-project.org/projects/coding-standard.html", "keywords": [ + "checks", "code", "coding", "cs", "doctrine", + "rules", "sniffer", + "sniffs", "standard", "style" ], - "time": "2018-03-03T23:49:15+00:00" + "time": "2018-09-24T19:08:56+00:00" }, { "name": "doctrine/instantiator", @@ -2519,30 +2522,29 @@ }, { "name": "slevomat/coding-standard", - "version": "4.5.2", + "version": "4.8.3", "source": { "type": "git", "url": "https://github.com/slevomat/coding-standard.git", - "reference": "1e609159241fa90d5a429f185b2ea9b881340a7c" + "reference": "32e1ca205fc34920f323582ed29c0602e3897ae3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/1e609159241fa90d5a429f185b2ea9b881340a7c", - "reference": "1e609159241fa90d5a429f185b2ea9b881340a7c", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/32e1ca205fc34920f323582ed29c0602e3897ae3", + "reference": "32e1ca205fc34920f323582ed29c0602e3897ae3", "shasum": "" }, "require": { "php": "^7.1", - "squizlabs/php_codesniffer": "^3.2.3" + "squizlabs/php_codesniffer": "^3.3.0" }, "require-dev": { "jakub-onderka/php-parallel-lint": "1.0.0", - "phing/phing": "2.16", + "phing/phing": "2.16.1", "phpstan/phpstan": "0.9.2", "phpstan/phpstan-phpunit": "0.9.4", "phpstan/phpstan-strict-rules": "0.9", - "phpunit/php-code-coverage": "6.0.1", - "phpunit/phpunit": "7.0.2" + "phpunit/phpunit": "7.3.5" }, "type": "phpcodesniffer-standard", "autoload": { @@ -2555,20 +2557,20 @@ "MIT" ], "description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", - "time": "2018-03-08T08:14:33+00:00" + "time": "2018-09-25T21:21:11+00:00" }, { "name": "squizlabs/php_codesniffer", - "version": "3.2.3", + "version": "3.3.2", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "4842476c434e375f9d3182ff7b89059583aa8b27" + "reference": "6ad28354c04b364c3c71a34e4a18b629cc3b231e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/4842476c434e375f9d3182ff7b89059583aa8b27", - "reference": "4842476c434e375f9d3182ff7b89059583aa8b27", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/6ad28354c04b364c3c71a34e4a18b629cc3b231e", + "reference": "6ad28354c04b364c3c71a34e4a18b629cc3b231e", "shasum": "" }, "require": { @@ -2606,7 +2608,7 @@ "phpcs", "standards" ], - "time": "2018-02-20T21:35:23+00:00" + "time": "2018-09-23T23:08:17+00:00" }, { "name": "symfony/console", From 73bd82a3d77d6414771744d346002dddc9ce4f9c Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sun, 23 Sep 2018 17:47:40 -0700 Subject: [PATCH 27/76] PHPCBF --- .../DBAL/Cache/QueryCacheProfileTest.php | 46 +- .../Doctrine/Tests/DBAL/ConfigurationTest.php | 4 +- tests/Doctrine/Tests/DBAL/ConnectionTest.php | 174 ++-- .../Doctrine/Tests/DBAL/DBALExceptionTest.php | 32 +- .../Tests/DBAL/Driver/AbstractDriverTest.php | 88 +- .../DBAL/Driver/AbstractMySQLDriverTest.php | 154 +-- .../EasyConnectStringTest.php | 1 + .../DBAL/Driver/AbstractOracleDriverTest.php | 76 +- .../Driver/AbstractPostgreSQLDriverTest.php | 100 +- .../Driver/AbstractSQLAnywhereDriverTest.php | 150 +-- .../Driver/AbstractSQLServerDriverTest.php | 56 +- .../DBAL/Driver/AbstractSQLiteDriverTest.php | 72 +- .../DBAL/Driver/IBMDB2/DB2ConnectionTest.php | 6 +- .../Driver/Mysqli/MysqliConnectionTest.php | 9 +- .../DBAL/Driver/OCI8/OCI8ConnectionTest.php | 6 +- .../DBAL/Driver/OCI8/OCI8StatementTest.php | 43 +- .../Tests/DBAL/Driver/PDOExceptionTest.php | 15 +- .../Tests/DBAL/Driver/PDOPgSql/DriverTest.php | 31 +- .../SQLAnywhere/SQLAnywhereConnectionTest.php | 6 +- .../Driver/SQLSrv/SQLSrvConnectionTest.php | 6 +- .../DBAL/Driver/StatementIteratorTest.php | 7 +- .../Doctrine/Tests/DBAL/DriverManagerTest.php | 17 +- .../DBAL/Events/MysqlSessionInitTest.php | 5 +- .../DBAL/Events/OracleSessionInitTest.php | 13 +- .../Tests/DBAL/Events/SQLSessionInitTest.php | 2 +- .../InvalidArgumentExceptionTest.php | 5 +- .../Tests/DBAL/Functional/BlobTest.php | 10 +- .../Tests/DBAL/Functional/ConnectionTest.php | 52 +- .../Tests/DBAL/Functional/DataAccessTest.php | 373 +++---- .../Functional/Driver/AbstractDriverTest.php | 7 +- .../Driver/IBMDB2/DB2DriverTest.php | 6 +- .../Driver/IBMDB2/DB2StatementTest.php | 8 +- .../Driver/Mysqli/ConnectionTest.php | 36 +- .../Functional/Driver/Mysqli/DriverTest.php | 6 +- .../Functional/Driver/OCI8/DriverTest.php | 6 +- .../Driver/OCI8/OCI8ConnectionTest.php | 11 +- .../Functional/Driver/OCI8/StatementTest.php | 70 +- .../Functional/Driver/PDOConnectionTest.php | 14 +- .../Functional/Driver/PDOMySql/DriverTest.php | 6 +- .../Driver/PDOOracle/DriverTest.php | 6 +- .../Functional/Driver/PDOPgSql/DriverTest.php | 36 +- .../Driver/PDOPgsqlConnectionTest.php | 23 +- .../Driver/PDOSqlite/DriverTest.php | 6 +- .../Driver/PDOSqlsrv/DriverTest.php | 2 +- .../Driver/SQLAnywhere/ConnectionTest.php | 13 +- .../Driver/SQLAnywhere/DriverTest.php | 6 +- .../Driver/SQLAnywhere/StatementTest.php | 22 +- .../Functional/Driver/SQLSrv/DriverTest.php | 6 +- .../Driver/SQLSrv/StatementTest.php | 8 +- .../Tests/DBAL/Functional/ExceptionTest.php | 197 ++-- .../Functional/LikeWildcardsEscapingTest.php | 1 - .../Tests/DBAL/Functional/LoggingTest.php | 14 +- .../Functional/MasterSlaveConnectionTest.php | 45 +- .../DBAL/Functional/ModifyLimitQueryTest.php | 166 +-- .../DBAL/Functional/NamedParametersTest.php | 97 +- .../Tests/DBAL/Functional/PortabilityTest.php | 66 +- .../Tests/DBAL/Functional/ResultCacheTest.php | 85 +- .../Schema/Db2SchemaManagerTest.php | 2 +- .../Schema/DrizzleSchemaManagerTest.php | 8 +- .../Schema/MySqlSchemaManagerTest.php | 116 ++- .../Schema/OracleSchemaManagerTest.php | 78 +- .../Schema/PostgreSqlSchemaManagerTest.php | 179 ++-- .../Schema/SQLAnywhereSchemaManagerTest.php | 16 +- .../Schema/SQLServerSchemaManagerTest.php | 222 ++-- .../SchemaManagerFunctionalTestCase.php | 584 +++++------ .../Schema/SqliteSchemaManagerTest.php | 81 +- .../Tests/DBAL/Functional/StatementTest.php | 93 +- .../DBAL/Functional/TableGeneratorTest.php | 39 +- .../DBAL/Functional/TemporaryTableTest.php | 71 +- .../DBAL/Functional/Ticket/DBAL168Test.php | 13 +- .../DBAL/Functional/Ticket/DBAL202Test.php | 11 +- .../DBAL/Functional/Ticket/DBAL421Test.php | 20 +- .../DBAL/Functional/Ticket/DBAL461Test.php | 12 +- .../DBAL/Functional/Ticket/DBAL510Test.php | 15 +- .../DBAL/Functional/Ticket/DBAL630Test.php | 41 +- .../DBAL/Functional/Ticket/DBAL752Test.php | 10 +- .../DBAL/Functional/TypeConversionTest.php | 124 +-- .../Tests/DBAL/Functional/WriteTest.php | 124 +-- .../Tests/DBAL/Logging/DebugStackTest.php | 15 +- .../Tests/DBAL/Mocks/MockPlatform.php | 27 +- .../TypeConversionPerformanceTest.php | 12 +- .../AbstractMySQLPlatformTestCase.php | 410 ++++---- .../Platforms/AbstractPlatformTestCase.php | 515 +++++----- .../AbstractPostgreSqlPlatformTestCase.php | 362 +++---- .../AbstractSQLServerPlatformTestCase.php | 854 ++++++++-------- .../Tests/DBAL/Platforms/DB2PlatformTest.php | 286 +++--- .../Platforms/MariaDb1027PlatformTest.php | 1 + .../DBAL/Platforms/MySQL57PlatformTest.php | 22 +- .../DBAL/Platforms/MySqlPlatformTest.php | 2 +- .../DBAL/Platforms/OraclePlatformTest.php | 299 +++--- .../Platforms/PostgreSQL92PlatformTest.php | 8 +- .../Platforms/PostgreSQL94PlatformTest.php | 4 +- .../DBAL/Platforms/PostgreSqlPlatformTest.php | 2 +- .../ReservedKeywordsValidatorTest.php | 20 +- .../Platforms/SQLAnywhere11PlatformTest.php | 6 +- .../Platforms/SQLAnywhere12PlatformTest.php | 30 +- .../Platforms/SQLAnywhere16PlatformTest.php | 18 +- .../Platforms/SQLAnywherePlatformTest.php | 286 +++--- .../DBAL/Platforms/SQLAzurePlatformTest.php | 14 +- .../Platforms/SQLServer2008PlatformTest.php | 2 +- .../Platforms/SQLServer2012PlatformTest.php | 238 ++--- .../DBAL/Platforms/SQLServerPlatformTest.php | 21 +- .../DBAL/Platforms/SqlitePlatformTest.php | 223 +++-- .../Tests/DBAL/Portability/StatementTest.php | 35 +- .../Expression/CompositeExpressionTest.php | 75 +- .../Expression/ExpressionBuilderTest.php | 155 ++- .../Tests/DBAL/Query/QueryBuilderTest.php | 88 +- .../Tests/DBAL/SQLParserUtilsTest.php | 617 ++++++------ .../Tests/DBAL/Schema/ColumnDiffTest.php | 11 +- .../Doctrine/Tests/DBAL/Schema/ColumnTest.php | 61 +- .../Tests/DBAL/Schema/ComparatorTest.php | 946 +++++++++--------- .../DBAL/Schema/DB2SchemaManagerTest.php | 40 +- .../DBAL/Schema/ForeignKeyConstraintTest.php | 38 +- .../Doctrine/Tests/DBAL/Schema/IndexTest.php | 43 +- .../DBAL/Schema/MySqlInheritCharsetTest.php | 2 +- .../DBAL/Schema/MySqlSchemaManagerTest.php | 78 +- .../DBAL/Schema/Platforms/MySQLSchemaTest.php | 45 +- .../Tests/DBAL/Schema/SchemaDiffTest.php | 32 +- .../Doctrine/Tests/DBAL/Schema/SchemaTest.php | 123 +-- .../Tests/DBAL/Schema/SequenceTest.php | 30 +- .../DBAL/Schema/SqliteSchemaManagerTest.php | 46 +- .../SingleDatabaseSynchronizerTest.php | 32 +- .../Tests/DBAL/Schema/TableDiffTest.php | 7 +- .../Doctrine/Tests/DBAL/Schema/TableTest.php | 493 ++++----- .../Visitor/CreateSchemaSqlCollectorTest.php | 52 +- .../Visitor/DropSchemaSqlCollectorTest.php | 11 +- .../Visitor/RemoveNamespacedAssetsTest.php | 45 +- .../Schema/Visitor/SchemaSqlCollectorTest.php | 41 +- .../Sharding/PoolingShardConnectionTest.php | 211 ++-- .../DBAL/Sharding/PoolingShardManagerTest.php | 59 +- .../Sharding/SQLAzure/AbstractTestCase.php | 36 +- .../DBAL/Sharding/SQLAzure/FunctionalTest.php | 39 +- .../SQLAzure/MultiTenantVisitorTest.php | 24 +- .../SQLAzureFederationsSynchronizerTest.php | 19 +- .../SQLAzure/SQLAzureShardManagerTest.php | 27 +- .../MultiTenantShardChoserTest.php | 8 +- tests/Doctrine/Tests/DBAL/StatementTest.php | 61 +- .../DBAL/Tools/Console/RunSqlCommandTest.php | 38 +- .../Doctrine/Tests/DBAL/Tools/DumperTest.php | 3 +- tests/Doctrine/Tests/DBAL/Types/ArrayTest.php | 17 +- .../Tests/DBAL/Types/BaseDateTypeTestCase.php | 33 +- .../Doctrine/Tests/DBAL/Types/BinaryTest.php | 34 +- tests/Doctrine/Tests/DBAL/Types/BlobTest.php | 14 +- .../Doctrine/Tests/DBAL/Types/BooleanTest.php | 13 +- .../DBAL/Types/ConversionExceptionTest.php | 17 +- .../DBAL/Types/DateImmutableTypeTest.php | 24 +- .../Tests/DBAL/Types/DateIntervalTest.php | 27 +- tests/Doctrine/Tests/DBAL/Types/DateTest.php | 3 +- .../DBAL/Types/DateTimeImmutableTypeTest.php | 24 +- .../Tests/DBAL/Types/DateTimeTest.php | 5 +- .../Types/DateTimeTzImmutableTypeTest.php | 24 +- .../Tests/DBAL/Types/DateTimeTzTest.php | 5 +- .../Doctrine/Tests/DBAL/Types/DecimalTest.php | 13 +- tests/Doctrine/Tests/DBAL/Types/FloatTest.php | 13 +- .../Tests/DBAL/Types/GuidTypeTest.php | 14 +- .../Doctrine/Tests/DBAL/Types/IntegerTest.php | 13 +- .../Tests/DBAL/Types/JsonArrayTest.php | 22 +- tests/Doctrine/Tests/DBAL/Types/JsonTest.php | 20 +- .../Doctrine/Tests/DBAL/Types/ObjectTest.php | 18 +- .../Tests/DBAL/Types/SmallIntTest.php | 13 +- .../Doctrine/Tests/DBAL/Types/StringTest.php | 21 +- .../DBAL/Types/TimeImmutableTypeTest.php | 24 +- .../Types/VarDateTimeImmutableTypeTest.php | 26 +- .../Tests/DBAL/Types/VarDateTimeTest.php | 20 +- tests/Doctrine/Tests/DBAL/UtilTest.php | 74 +- .../Doctrine/Tests/DbalFunctionalTestCase.php | 70 +- .../Tests/DbalPerformanceTestCase.php | 10 +- .../Tests/DbalPerformanceTestListener.php | 44 +- tests/Doctrine/Tests/DbalTestCase.php | 4 +- tests/Doctrine/Tests/Mocks/ConnectionMock.php | 32 +- .../Tests/Mocks/DatabasePlatformMock.php | 63 +- .../Tests/Mocks/DriverConnectionMock.php | 39 +- tests/Doctrine/Tests/Mocks/DriverMock.php | 47 +- .../Tests/Mocks/DriverResultStatementMock.php | 3 +- .../Tests/Mocks/DriverStatementMock.php | 3 +- .../Tests/Mocks/SchemaManagerMock.php | 13 +- tests/Doctrine/Tests/TestUtil.php | 53 +- tests/Doctrine/Tests/Types/MySqlPointType.php | 2 +- tests/continuousphp/bootstrap.php | 4 +- tests/phpstan-polyfill.php | 2 +- 180 files changed, 6406 insertions(+), 6249 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php b/tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php index 5bc77c911c3..1d500046260 100644 --- a/tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php +++ b/tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php @@ -12,36 +12,26 @@ class QueryCacheProfileTest extends DbalTestCase private const LIFETIME = 3600; private const CACHE_KEY = 'user_specified_cache_key'; - /** - * @var QueryCacheProfile - */ + /** @var QueryCacheProfile */ private $queryCacheProfile; - /** - * @var string - */ + /** @var string */ private $query = 'SELECT * FROM foo WHERE bar = ?'; - /** - * @var int[] - */ + /** @var int[] */ private $params = [666]; - /** - * @var string[] - */ + /** @var string[] */ private $types = [ParameterType::INTEGER]; - /** - * @var string[] - */ + /** @var string[] */ private $connectionParams = [ - 'dbname' => 'database_name', - 'user' => 'database_user', - 'password' => 'database_password', - 'host' => 'database_host', - 'driver' => 'database_driver', - ]; + 'dbname' => 'database_name', + 'user' => 'database_user', + 'password' => 'database_password', + 'host' => 'database_host', + 'driver' => 'database_driver', + ]; protected function setUp() { @@ -50,7 +40,7 @@ protected function setUp() public function testShouldUseTheGivenCacheKeyIfPresent() { - list($cacheKey) = $this->queryCacheProfile->generateCacheKeys( + [$cacheKey] = $this->queryCacheProfile->generateCacheKeys( $this->query, $this->params, $this->types, @@ -64,7 +54,7 @@ public function testShouldGenerateAnAutomaticKeyIfNoKeyHasBeenGiven() { $this->queryCacheProfile = $this->queryCacheProfile->setCacheKey(null); - list($cacheKey) = $this->queryCacheProfile->generateCacheKeys( + [$cacheKey] = $this->queryCacheProfile->generateCacheKeys( $this->query, $this->params, $this->types, @@ -84,7 +74,7 @@ public function testShouldGenerateDifferentKeysForSameQueryAndParamsAndDifferent { $this->queryCacheProfile = $this->queryCacheProfile->setCacheKey(null); - list($firstCacheKey) = $this->queryCacheProfile->generateCacheKeys( + [$firstCacheKey] = $this->queryCacheProfile->generateCacheKeys( $this->query, $this->params, $this->types, @@ -93,7 +83,7 @@ public function testShouldGenerateDifferentKeysForSameQueryAndParamsAndDifferent $this->connectionParams['host'] = 'a_different_host'; - list($secondCacheKey) = $this->queryCacheProfile->generateCacheKeys( + [$secondCacheKey] = $this->queryCacheProfile->generateCacheKeys( $this->query, $this->params, $this->types, @@ -107,7 +97,7 @@ public function testConnectionParamsShouldBeHashed() { $this->queryCacheProfile = $this->queryCacheProfile->setCacheKey(null); - list($cacheKey, $queryString) = $this->queryCacheProfile->generateCacheKeys( + [$cacheKey, $queryString] = $this->queryCacheProfile->generateCacheKeys( $this->query, $this->params, $this->types, @@ -128,14 +118,14 @@ public function testShouldGenerateSameKeysIfNoneOfTheParamsChanges() { $this->queryCacheProfile = $this->queryCacheProfile->setCacheKey(null); - list($firstCacheKey) = $this->queryCacheProfile->generateCacheKeys( + [$firstCacheKey] = $this->queryCacheProfile->generateCacheKeys( $this->query, $this->params, $this->types, $this->connectionParams ); - list($secondCacheKey) = $this->queryCacheProfile->generateCacheKeys( + [$secondCacheKey] = $this->queryCacheProfile->generateCacheKeys( $this->query, $this->params, $this->types, diff --git a/tests/Doctrine/Tests/DBAL/ConfigurationTest.php b/tests/Doctrine/Tests/DBAL/ConfigurationTest.php index 4379b3b35a9..851f973e66e 100644 --- a/tests/Doctrine/Tests/DBAL/ConfigurationTest.php +++ b/tests/Doctrine/Tests/DBAL/ConfigurationTest.php @@ -24,15 +24,13 @@ /** * Unit tests for the configuration container. - * - * @author Steve Müller */ class ConfigurationTest extends DbalTestCase { /** * The configuration container instance under test. * - * @var \Doctrine\DBAL\Configuration + * @var Configuration */ protected $config; diff --git a/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/ConnectionTest.php index 819dd71f487..dfb908f40f4 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -15,32 +15,36 @@ use Doctrine\DBAL\Events; use Doctrine\DBAL\Exception\InvalidArgumentException; use Doctrine\DBAL\FetchMode; +use Doctrine\DBAL\Logging\DebugStack; +use Doctrine\DBAL\Logging\EchoSQLLogger; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\Mocks\DriverMock; +use Doctrine\Tests\Mocks\ServerInfoAwareConnectionMock; use Doctrine\Tests\Mocks\VersionAwarePlatformDriverMock; +use Exception; +use PHPUnit_Framework_MockObject_MockObject; +use ReflectionObject; +use stdClass; use function call_user_func_array; /** * @requires extension pdo_mysql */ -class ConnectionTest extends \Doctrine\Tests\DbalTestCase +class ConnectionTest extends DbalTestCase { - /** - * @var \Doctrine\DBAL\Connection - */ + /** @var Connection */ protected $_conn = null; - /** - * @var string[] - */ - protected $params = array( + /** @var string[] */ + protected $params = [ 'driver' => 'pdo_mysql', 'host' => 'localhost', 'user' => 'root', 'password' => 'password', - 'port' => '1234' - ); + 'port' => '1234', + ]; protected function setUp() { @@ -49,7 +53,7 @@ protected function setUp() public function getExecuteUpdateMockConnection() { - $driverMock = $this->createMock(\Doctrine\DBAL\Driver::class); + $driverMock = $this->createMock(Driver::class); $driverMock->expects($this->any()) ->method('connect') @@ -57,12 +61,10 @@ public function getExecuteUpdateMockConnection() $this->createMock(DriverConnection::class) )); - $conn = $this->getMockBuilder(Connection::class) + return $this->getMockBuilder(Connection::class) ->setMethods(['executeUpdate']) ->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock]) ->getMock(); - - return $conn; } public function testIsConnected() @@ -139,19 +141,19 @@ public function testGetEventManager() public function testConnectDispatchEvent() { $listenerMock = $this->getMockBuilder('ConnectDispatchEventListener') - ->setMethods(array('postConnect')) + ->setMethods(['postConnect']) ->getMock(); $listenerMock->expects($this->once())->method('postConnect'); $eventManager = new EventManager(); - $eventManager->addEventListener(array(Events::postConnect), $listenerMock); + $eventManager->addEventListener([Events::postConnect], $listenerMock); $driverMock = $this->createMock('Doctrine\DBAL\Driver'); - $driverMock->expects(($this->at(0))) + $driverMock->expects($this->at(0)) ->method('connect'); $platform = new Mocks\MockPlatform(); - $conn = new Connection(array('platform' => $platform), $driverMock, new Configuration(), $eventManager); + $conn = new Connection(['platform' => $platform], $driverMock, new Configuration(), $eventManager); $conn->connect(); } @@ -183,13 +185,13 @@ public function testDriverExceptionIsWrapped($method) public function getQueryMethods() { - return array( - array('exec'), - array('query'), - array('executeQuery'), - array('executeUpdate'), - array('prepare'), - ); + return [ + ['exec'], + ['query'], + ['executeQuery'], + ['executeUpdate'], + ['prepare'], + ]; } /** @@ -199,7 +201,7 @@ public function getQueryMethods() */ public function testEchoSQLLogger() { - $logger = new \Doctrine\DBAL\Logging\EchoSQLLogger(); + $logger = new EchoSQLLogger(); $this->_conn->getConfiguration()->setSQLLogger($logger); self::assertSame($logger, $this->_conn->getConfiguration()->getSQLLogger()); } @@ -211,7 +213,7 @@ public function testEchoSQLLogger() */ public function testDebugSQLStack() { - $logger = new \Doctrine\DBAL\Logging\DebugStack(); + $logger = new DebugStack(); $this->_conn->getConfiguration()->setSQLLogger($logger); self::assertSame($logger, $this->_conn->getConfiguration()->getSQLLogger()); } @@ -246,7 +248,7 @@ public function testConnectStartsTransactionInNoAutoCommitMode() ->will($this->returnValue( $this->createMock(DriverConnection::class) )); - $conn = new Connection(array('platform' => new Mocks\MockPlatform()), $driverMock); + $conn = new Connection(['platform' => new Mocks\MockPlatform()], $driverMock); $conn->setAutoCommit(false); @@ -268,7 +270,7 @@ public function testCommitStartsTransactionInNoAutoCommitMode() ->will($this->returnValue( $this->createMock(DriverConnection::class) )); - $conn = new Connection(array('platform' => new Mocks\MockPlatform()), $driverMock); + $conn = new Connection(['platform' => new Mocks\MockPlatform()], $driverMock); $conn->setAutoCommit(false); $conn->connect(); @@ -288,7 +290,7 @@ public function testRollBackStartsTransactionInNoAutoCommitMode() ->will($this->returnValue( $this->createMock(DriverConnection::class) )); - $conn = new Connection(array('platform' => new Mocks\MockPlatform()), $driverMock); + $conn = new Connection(['platform' => new Mocks\MockPlatform()], $driverMock); $conn->setAutoCommit(false); $conn->connect(); @@ -308,7 +310,7 @@ public function testSwitchingAutoCommitModeCommitsAllCurrentTransactions() ->will($this->returnValue( $this->createMock(DriverConnection::class) )); - $conn = new Connection(array('platform' => new Mocks\MockPlatform()), $driverMock); + $conn = new Connection(['platform' => new Mocks\MockPlatform()], $driverMock); $conn->connect(); $conn->beginTransaction(); @@ -332,7 +334,7 @@ public function testEmptyInsert() ->method('executeUpdate') ->with('INSERT INTO footable () VALUES ()'); - $conn->insert('footable', array()); + $conn->insert('footable', []); } /** @@ -475,12 +477,8 @@ public function testDeleteWithIsNull() ->method('executeUpdate') ->with( 'DELETE FROM TestTable WHERE id IS NULL AND name = ?', - [ - 'foo', - ], - [ - 'string', - ] + ['foo'], + ['string'] ); $conn->delete( @@ -518,10 +516,10 @@ public function testFetchAssoc() ->with(FetchMode::ASSOCIATIVE) ->will($this->returnValue($result)); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Doctrine\DBAL\Connection $conn */ + /** @var PHPUnit_Framework_MockObject_MockObject|Connection $conn */ $conn = $this->getMockBuilder('Doctrine\DBAL\Connection') - ->setMethods(array('executeQuery')) - ->setConstructorArgs(array(array('platform' => new Mocks\MockPlatform()), $driverMock)) + ->setMethods(['executeQuery']) + ->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock]) ->getMock(); $conn->expects($this->once()) @@ -554,10 +552,10 @@ public function testFetchArray() ->with(FetchMode::NUMERIC) ->will($this->returnValue($result)); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Doctrine\DBAL\Connection $conn */ + /** @var PHPUnit_Framework_MockObject_MockObject|Connection $conn */ $conn = $this->getMockBuilder('Doctrine\DBAL\Connection') - ->setMethods(array('executeQuery')) - ->setConstructorArgs(array(array('platform' => new Mocks\MockPlatform()), $driverMock)) + ->setMethods(['executeQuery']) + ->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock]) ->getMock(); $conn->expects($this->once()) @@ -591,10 +589,10 @@ public function testFetchColumn() ->with($column) ->will($this->returnValue($result)); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Doctrine\DBAL\Connection $conn */ + /** @var PHPUnit_Framework_MockObject_MockObject|Connection $conn */ $conn = $this->getMockBuilder('Doctrine\DBAL\Connection') - ->setMethods(array('executeQuery')) - ->setConstructorArgs(array(array('platform' => new Mocks\MockPlatform()), $driverMock)) + ->setMethods(['executeQuery']) + ->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock]) ->getMock(); $conn->expects($this->once()) @@ -610,14 +608,14 @@ public function testConnectionIsClosedButNotUnset() // mock Connection, and make connect() purposefully do nothing $connection = $this->getMockBuilder('Doctrine\DBAL\Connection') ->disableOriginalConstructor() - ->setMethods(array('connect')) + ->setMethods(['connect']) ->getMock(); // artificially set the wrapped connection to non-null - $reflection = new \ReflectionObject($connection); + $reflection = new ReflectionObject($connection); $connProperty = $reflection->getProperty('_conn'); $connProperty->setAccessible(true); - $connProperty->setValue($connection, new \stdClass); + $connProperty->setValue($connection, new stdClass()); // close the connection (should nullify the wrapped connection) $connection->close(); @@ -649,10 +647,10 @@ public function testFetchAll() ->method('fetchAll') ->will($this->returnValue($result)); - /** @var \PHPUnit_Framework_MockObject_MockObject|\Doctrine\DBAL\Connection $conn */ + /** @var PHPUnit_Framework_MockObject_MockObject|Connection $conn */ $conn = $this->getMockBuilder('Doctrine\DBAL\Connection') - ->setMethods(array('executeQuery')) - ->setConstructorArgs(array(array('platform' => new Mocks\MockPlatform()), $driverMock)) + ->setMethods(['executeQuery']) + ->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock]) ->getMock(); $conn->expects($this->once()) @@ -665,29 +663,29 @@ public function testFetchAll() public function testConnectionDoesNotMaintainTwoReferencesToExternalPDO() { - $params['pdo'] = new \stdClass(); + $params['pdo'] = new stdClass(); $driverMock = $this->createMock('Doctrine\DBAL\Driver'); $conn = new Connection($params, $driverMock); - self::assertArrayNotHasKey('pdo', $conn->getParams(), "Connection is maintaining additional reference to the PDO connection"); + self::assertArrayNotHasKey('pdo', $conn->getParams(), 'Connection is maintaining additional reference to the PDO connection'); } public function testPassingExternalPDOMeansConnectionIsConnected() { - $params['pdo'] = new \stdClass(); + $params['pdo'] = new stdClass(); $driverMock = $this->createMock('Doctrine\DBAL\Driver'); $conn = new Connection($params, $driverMock); - self::assertTrue($conn->isConnected(), "Connection is not connected after passing external PDO"); + self::assertTrue($conn->isConnected(), 'Connection is not connected after passing external PDO'); } public function testCallingDeleteWithNoDeletionCriteriaResultsInInvalidArgumentException() { - /* @var $driver \Doctrine\DBAL\Driver */ + /** @var Driver $driver */ $driver = $this->createMock('Doctrine\DBAL\Driver'); $pdoMock = $this->createMock('Doctrine\DBAL\Driver\Connection'); @@ -695,21 +693,21 @@ public function testCallingDeleteWithNoDeletionCriteriaResultsInInvalidArgumentE $pdoMock->expects($this->never())->method('exec'); $pdoMock->expects($this->never())->method('prepare'); - $conn = new Connection(array('pdo' => $pdoMock), $driver); + $conn = new Connection(['pdo' => $pdoMock], $driver); $this->expectException(InvalidArgumentException::class); - $conn->delete('kittens', array()); + $conn->delete('kittens', []); } public function dataCallConnectOnce() { - return array( - array('delete', array('tbl', array('id' => 12345))), - array('insert', array('tbl', array('data' => 'foo'))), - array('update', array('tbl', array('data' => 'bar'), array('id' => 12345))), - array('prepare', array('select * from dual')), - array('executeUpdate', array('insert into tbl (id) values (?)'), array(123)), - ); + return [ + ['delete', ['tbl', ['id' => 12345]]], + ['insert', ['tbl', ['data' => 'foo']]], + ['update', ['tbl', ['data' => 'bar'], ['id' => 12345]]], + ['prepare', ['select * from dual']], + ['executeUpdate', ['insert into tbl (id) values (?)'], [123]], + ]; } /** @@ -727,13 +725,13 @@ public function testCallConnectOnce($method, $params) ->will($this->returnValue($stmtMock)); $conn = $this->getMockBuilder('Doctrine\DBAL\Connection') - ->setConstructorArgs(array(array('pdo' => $pdoMock, 'platform' => $platformMock), $driverMock)) - ->setMethods(array('connect')) + ->setConstructorArgs([['pdo' => $pdoMock, 'platform' => $platformMock], $driverMock]) + ->setMethods(['connect']) ->getMock(); $conn->expects($this->once())->method('connect'); - call_user_func_array(array($conn, $method), $params); + call_user_func_array([$conn, $method], $params); } /** @@ -741,16 +739,16 @@ public function testCallConnectOnce($method, $params) */ public function testPlatformDetectionIsTriggerOnlyOnceOnRetrievingPlatform() { - /** @var \Doctrine\Tests\Mocks\VersionAwarePlatformDriverMock|\PHPUnit_Framework_MockObject_MockObject $driverMock */ + /** @var VersionAwarePlatformDriverMock|PHPUnit_Framework_MockObject_MockObject $driverMock */ $driverMock = $this->createMock('Doctrine\Tests\Mocks\VersionAwarePlatformDriverMock'); - /** @var \Doctrine\Tests\Mocks\ServerInfoAwareConnectionMock|\PHPUnit_Framework_MockObject_MockObject $driverConnectionMock */ + /** @var ServerInfoAwareConnectionMock|PHPUnit_Framework_MockObject_MockObject $driverConnectionMock */ $driverConnectionMock = $this->createMock('Doctrine\Tests\Mocks\ServerInfoAwareConnectionMock'); - /** @var \Doctrine\DBAL\Platforms\AbstractPlatform|\PHPUnit_Framework_MockObject_MockObject $platformMock */ + /** @var AbstractPlatform|PHPUnit_Framework_MockObject_MockObject $platformMock */ $platformMock = $this->getMockForAbstractClass('Doctrine\DBAL\Platforms\AbstractPlatform'); - $connection = new Connection(array(), $driverMock); + $connection = new Connection([], $driverMock); $driverMock->expects($this->once()) ->method('connect') @@ -786,7 +784,7 @@ public function testConnectionParamsArePassedToTheQueryCacheProfileInExecuteCach $params = [666]; $types = [ParameterType::INTEGER]; - /* @var $queryCacheProfileMock QueryCacheProfile|\PHPUnit_Framework_MockObject_MockObject */ + /** @var QueryCacheProfile|PHPUnit_Framework_MockObject_MockObject $queryCacheProfileMock */ $queryCacheProfileMock = $this->createMock(QueryCacheProfile::class); $queryCacheProfileMock @@ -801,7 +799,7 @@ public function testConnectionParamsArePassedToTheQueryCacheProfileInExecuteCach ->with($query, $params, $types, $this->params) ->will($this->returnValue(['cacheKey', 'realKey'])); - /* @var $driver Driver */ + /** @var Driver $driver */ $driver = $this->createMock(Driver::class); self::assertInstanceOf( @@ -813,7 +811,7 @@ public function testConnectionParamsArePassedToTheQueryCacheProfileInExecuteCach /** * @group #2821 */ - public function testShouldNotPassPlatformInParamsToTheQueryCacheProfileInExecuteCacheQuery(): void + public function testShouldNotPassPlatformInParamsToTheQueryCacheProfileInExecuteCacheQuery() : void { $resultCacheDriverMock = $this->createMock(Cache::class); @@ -823,7 +821,7 @@ public function testShouldNotPassPlatformInParamsToTheQueryCacheProfileInExecute ->with('cacheKey') ->will($this->returnValue(['realKey' => []])); - /* @var $queryCacheProfileMock QueryCacheProfile|\PHPUnit_Framework_MockObject_MockObject */ + /** @var QueryCacheProfile|PHPUnit_Framework_MockObject_MockObject $queryCacheProfileMock */ $queryCacheProfileMock = $this->createMock(QueryCacheProfile::class); $queryCacheProfileMock @@ -831,7 +829,7 @@ public function testShouldNotPassPlatformInParamsToTheQueryCacheProfileInExecute ->method('getResultCacheDriver') ->will($this->returnValue($resultCacheDriverMock)); - $query = 'SELECT 1'; + $query = 'SELECT 1'; $connectionParams = $this->params; @@ -843,7 +841,7 @@ public function testShouldNotPassPlatformInParamsToTheQueryCacheProfileInExecute $connectionParams['platform'] = $this->createMock(AbstractPlatform::class); - /* @var $driver Driver */ + /** @var Driver $driver */ $driver = $this->createMock(Driver::class); (new Connection($connectionParams, $driver))->executeCacheQuery($query, [], [], $queryCacheProfileMock); @@ -852,12 +850,12 @@ public function testShouldNotPassPlatformInParamsToTheQueryCacheProfileInExecute /** * @group #2821 */ - public function testThrowsExceptionWhenInValidPlatformSpecified(): void + public function testThrowsExceptionWhenInValidPlatformSpecified() : void { - $connectionParams = $this->params; - $connectionParams['platform'] = new \stdClass(); + $connectionParams = $this->params; + $connectionParams['platform'] = new stdClass(); - /* @var $driver Driver */ + /** @var Driver $driver */ $driver = $this->createMock(Driver::class); $this->expectException(DBALException::class); @@ -870,12 +868,12 @@ public function testThrowsExceptionWhenInValidPlatformSpecified(): void */ public function testRethrowsOriginalExceptionOnDeterminingPlatformWhenConnectingToNonExistentDatabase() { - /** @var \Doctrine\Tests\Mocks\VersionAwarePlatformDriverMock|\PHPUnit_Framework_MockObject_MockObject $driverMock */ + /** @var VersionAwarePlatformDriverMock|PHPUnit_Framework_MockObject_MockObject $driverMock */ $driverMock = $this->createMock(VersionAwarePlatformDriverMock::class); - $connection = new Connection(array('dbname' => 'foo'), $driverMock); - $originalException = new \Exception('Original exception'); - $fallbackException = new \Exception('Fallback exception'); + $connection = new Connection(['dbname' => 'foo'], $driverMock); + $originalException = new Exception('Original exception'); + $fallbackException = new Exception('Fallback exception'); $driverMock->expects($this->at(0)) ->method('connect') diff --git a/tests/Doctrine/Tests/DBAL/DBALExceptionTest.php b/tests/Doctrine/Tests/DBAL/DBALExceptionTest.php index e83524f3c84..9c0cc18c0be 100644 --- a/tests/Doctrine/Tests/DBAL/DBALExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/DBALExceptionTest.php @@ -3,10 +3,12 @@ namespace Doctrine\Tests\DBAL; use Doctrine\DBAL\DBALException; -use Doctrine\DBAL\Exception\DriverException; +use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\DriverException as InnerDriverException; +use Doctrine\DBAL\Exception\DriverException; use Doctrine\Tests\DbalTestCase; -use Doctrine\DBAL\Driver; +use Exception; +use stdClass; use function chr; use function fopen; use function sprintf; @@ -15,25 +17,25 @@ class DBALExceptionTest extends DbalTestCase { public function testDriverExceptionDuringQueryAcceptsBinaryData() { - /* @var $driver Driver */ + /** @var Driver $driver */ $driver = $this->createMock(Driver::class); - $e = DBALException::driverExceptionDuringQuery($driver, new \Exception, '', array('ABC', chr(128))); + $e = DBALException::driverExceptionDuringQuery($driver, new Exception(), '', ['ABC', chr(128)]); self::assertContains('with params ["ABC", "\x80"]', $e->getMessage()); } - + public function testDriverExceptionDuringQueryAcceptsResource() { - /* @var $driver Driver */ + /** @var Driver $driver */ $driver = $this->createMock(Driver::class); - $e = \Doctrine\DBAL\DBALException::driverExceptionDuringQuery($driver, new \Exception, "INSERT INTO file (`content`) VALUES (?)", [1 => fopen(__FILE__, 'r')]); + $e = DBALException::driverExceptionDuringQuery($driver, new Exception(), 'INSERT INTO file (`content`) VALUES (?)', [1 => fopen(__FILE__, 'r')]); self::assertContains('Resource', $e->getMessage()); } public function testAvoidOverWrappingOnDriverException() { - /* @var $driver Driver */ + /** @var Driver $driver */ $driver = $this->createMock(Driver::class); - $inner = new class extends \Exception implements InnerDriverException + $inner = new class extends Exception implements InnerDriverException { /** * {@inheritDoc} @@ -49,14 +51,14 @@ public function getSQLState() { } }; - $ex = new DriverException('', $inner); - $e = DBALException::driverExceptionDuringQuery($driver, $ex, ''); + $ex = new DriverException('', $inner); + $e = DBALException::driverExceptionDuringQuery($driver, $ex, ''); self::assertSame($ex, $e); } public function testDriverRequiredWithUrl() { - $url = 'mysql://localhost'; + $url = 'mysql://localhost'; $exception = DBALException::driverRequired($url); self::assertInstanceOf(DBALException::class, $exception); @@ -73,9 +75,9 @@ public function testDriverRequiredWithUrl() /** * @group #2821 */ - public function testInvalidPlatformTypeObject(): void + public function testInvalidPlatformTypeObject() : void { - $exception = DBALException::invalidPlatformType(new \stdClass()); + $exception = DBALException::invalidPlatformType(new stdClass()); self::assertSame( "Option 'platform' must be a subtype of 'Doctrine\DBAL\Platforms\AbstractPlatform', instance of 'stdClass' given", @@ -86,7 +88,7 @@ public function testInvalidPlatformTypeObject(): void /** * @group #2821 */ - public function testInvalidPlatformTypeScalar(): void + public function testInvalidPlatformTypeScalar() : void { $exception = DBALException::invalidPlatformType('some string'); diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php index 7a49b3f9577..9eda7f8de77 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php @@ -3,37 +3,41 @@ namespace Doctrine\Tests\DBAL\Driver; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\DriverException; use Doctrine\DBAL\Driver\ExceptionConverterDriver; +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\VersionAwarePlatformDriver; use Doctrine\Tests\DbalTestCase; +use Exception; use function get_class; use function sprintf; abstract class AbstractDriverTest extends DbalTestCase { - const EXCEPTION_CONNECTION = 'Doctrine\DBAL\Exception\ConnectionException'; - const EXCEPTION_CONSTRAINT_VIOLATION = 'Doctrine\DBAL\Exception\ConstraintViolationException'; - const EXCEPTION_DATABASE_OBJECT_EXISTS = 'Doctrine\DBAL\Exception\DatabaseObjectExistsException'; - const EXCEPTION_DATABASE_OBJECT_NOT_FOUND = 'Doctrine\DBAL\Exception\DatabaseObjectNotFoundException'; - const EXCEPTION_DRIVER = 'Doctrine\DBAL\Exception\DriverException'; - const EXCEPTION_FOREIGN_KEY_CONSTRAINT_VIOLATION = 'Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException'; - const EXCEPTION_INVALID_FIELD_NAME = 'Doctrine\DBAL\Exception\InvalidFieldNameException'; - const EXCEPTION_NON_UNIQUE_FIELD_NAME = 'Doctrine\DBAL\Exception\NonUniqueFieldNameException'; - const EXCEPTION_NOT_NULL_CONSTRAINT_VIOLATION = 'Doctrine\DBAL\Exception\NotNullConstraintViolationException'; - const EXCEPTION_READ_ONLY = 'Doctrine\DBAL\Exception\ReadOnlyException'; - const EXCEPTION_SERVER = 'Doctrine\DBAL\Exception\ServerException'; - const EXCEPTION_SYNTAX_ERROR = 'Doctrine\DBAL\Exception\SyntaxErrorException'; - const EXCEPTION_TABLE_EXISTS = 'Doctrine\DBAL\Exception\TableExistsException'; - const EXCEPTION_TABLE_NOT_FOUND = 'Doctrine\DBAL\Exception\TableNotFoundException'; - const EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION = 'Doctrine\DBAL\Exception\UniqueConstraintViolationException'; - const EXCEPTION_DEADLOCK = 'Doctrine\DBAL\Exception\DeadlockException'; - const EXCEPTION_LOCK_WAIT_TIMEOUT = 'Doctrine\DBAL\Exception\LockWaitTimeoutException'; + public const EXCEPTION_CONNECTION = 'Doctrine\DBAL\Exception\ConnectionException'; + public const EXCEPTION_CONSTRAINT_VIOLATION = 'Doctrine\DBAL\Exception\ConstraintViolationException'; + public const EXCEPTION_DATABASE_OBJECT_EXISTS = 'Doctrine\DBAL\Exception\DatabaseObjectExistsException'; + public const EXCEPTION_DATABASE_OBJECT_NOT_FOUND = 'Doctrine\DBAL\Exception\DatabaseObjectNotFoundException'; + public const EXCEPTION_DRIVER = 'Doctrine\DBAL\Exception\DriverException'; + public const EXCEPTION_FOREIGN_KEY_CONSTRAINT_VIOLATION = 'Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException'; + public const EXCEPTION_INVALID_FIELD_NAME = 'Doctrine\DBAL\Exception\InvalidFieldNameException'; + public const EXCEPTION_NON_UNIQUE_FIELD_NAME = 'Doctrine\DBAL\Exception\NonUniqueFieldNameException'; + public const EXCEPTION_NOT_NULL_CONSTRAINT_VIOLATION = 'Doctrine\DBAL\Exception\NotNullConstraintViolationException'; + public const EXCEPTION_READ_ONLY = 'Doctrine\DBAL\Exception\ReadOnlyException'; + public const EXCEPTION_SERVER = 'Doctrine\DBAL\Exception\ServerException'; + public const EXCEPTION_SYNTAX_ERROR = 'Doctrine\DBAL\Exception\SyntaxErrorException'; + public const EXCEPTION_TABLE_EXISTS = 'Doctrine\DBAL\Exception\TableExistsException'; + public const EXCEPTION_TABLE_NOT_FOUND = 'Doctrine\DBAL\Exception\TableNotFoundException'; + public const EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION = 'Doctrine\DBAL\Exception\UniqueConstraintViolationException'; + public const EXCEPTION_DEADLOCK = 'Doctrine\DBAL\Exception\DeadlockException'; + public const EXCEPTION_LOCK_WAIT_TIMEOUT = 'Doctrine\DBAL\Exception\LockWaitTimeoutException'; /** * The driver mock under test. * - * @var \Doctrine\DBAL\Driver + * @var Driver */ protected $driver; @@ -46,7 +50,7 @@ protected function setUp() public function testConvertsException() { - if ( ! $this->driver instanceof ExceptionConverterDriver) { + if (! $this->driver instanceof ExceptionConverterDriver) { $this->markTestSkipped('This test is only intended for exception converter drivers.'); } @@ -56,13 +60,13 @@ public function testConvertsException() $this->fail( sprintf( 'No test data found for test %s. You have to return test data from %s.', - get_class($this) . '::' . __FUNCTION__, - get_class($this) . '::getExceptionConversionData' + static::class . '::' . __FUNCTION__, + static::class . '::getExceptionConversionData' ) ); } - $driverException = new class extends \Exception implements DriverException + $driverException = new class extends Exception implements DriverException { public function __construct() { @@ -86,13 +90,13 @@ public function getSQLState() } }; - $data[] = array($driverException, self::EXCEPTION_DRIVER); + $data[] = [$driverException, self::EXCEPTION_DRIVER]; $message = 'DBAL exception message'; foreach ($data as $item) { /** @var $driverException \Doctrine\DBAL\Driver\DriverException */ - list($driverException, $convertedExceptionClassName) = $item; + [$driverException, $convertedExceptionClassName] = $item; $convertedException = $this->driver->convertException($message, $driverException); @@ -106,7 +110,7 @@ public function getSQLState() public function testCreatesDatabasePlatformForVersion() { - if ( ! $this->driver instanceof VersionAwarePlatformDriver) { + if (! $this->driver instanceof VersionAwarePlatformDriver) { $this->markTestSkipped('This test is only intended for version aware platform drivers.'); } @@ -116,8 +120,8 @@ public function testCreatesDatabasePlatformForVersion() $data, sprintf( 'No test data found for test %s. You have to return test data from %s.', - get_class($this) . '::' . __FUNCTION__, - get_class($this) . '::getDatabasePlatformsForVersions' + static::class . '::' . __FUNCTION__, + static::class . '::getDatabasePlatformsForVersions' ) ); @@ -142,7 +146,7 @@ public function testCreatesDatabasePlatformForVersion() */ public function testThrowsExceptionOnCreatingDatabasePlatformsForInvalidVersion() { - if ( ! $this->driver instanceof VersionAwarePlatformDriver) { + if (! $this->driver instanceof VersionAwarePlatformDriver) { $this->markTestSkipped('This test is only intended for version aware platform drivers.'); } @@ -151,11 +155,11 @@ public function testThrowsExceptionOnCreatingDatabasePlatformsForInvalidVersion( public function testReturnsDatabaseName() { - $params = array( + $params = [ 'user' => 'foo', 'password' => 'bar', 'dbname' => 'baz', - ); + ]; $connection = $this->getConnectionMock(); @@ -183,7 +187,7 @@ public function testReturnsSchemaManager() /** * Factory method for creating the driver instance under test. * - * @return \Doctrine\DBAL\Driver + * @return Driver */ abstract protected function createDriver(); @@ -193,7 +197,7 @@ abstract protected function createDriver(); * The platform instance returned by this method must be the same as returned by * the driver's getDatabasePlatform() method. * - * @return \Doctrine\DBAL\Platforms\AbstractPlatform + * @return AbstractPlatform */ abstract protected function createPlatform(); @@ -205,7 +209,7 @@ abstract protected function createPlatform(); * * @param Connection $connection The underlying connection to use. * - * @return \Doctrine\DBAL\Schema\AbstractSchemaManager + * @return AbstractSchemaManager */ abstract protected function createSchemaManager(Connection $connection); @@ -218,32 +222,28 @@ protected function getConnectionMock() protected function getDatabasePlatformsForVersions() { - return array(); + return []; } protected function getExceptionConversionData() { - return array(); + return []; } private function getExceptionConversions() { - $data = array(); + $data = []; foreach ($this->getExceptionConversionData() as $convertedExceptionClassName => $errors) { foreach ($errors as $error) { $driverException = new class ($error[0], $error[1], $error[2]) - extends \Exception + extends Exception implements DriverException { - /** - * @var mixed - */ + /** @var mixed */ private $errorCode; - /** - * @var mixed - */ + /** @var mixed */ private $sqlState; public function __construct($errorCode, $sqlState, $message) @@ -271,7 +271,7 @@ public function getSQLState() } }; - $data[] = array($driverException, $convertedExceptionClassName); + $data[] = [$driverException, $convertedExceptionClassName]; } } diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php index 337a73c0e29..ebeb81d160f 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php @@ -16,10 +16,10 @@ public function testReturnsDatabaseName() parent::testReturnsDatabaseName(); $database = 'bloo'; - $params = array( + $params = [ 'user' => 'foo', 'password' => 'bar', - ); + ]; $statement = $this->createMock('Doctrine\Tests\Mocks\DriverResultStatementMock'); @@ -74,85 +74,85 @@ protected function getDatabasePlatformsForVersions() : array ['5.5.40-MariaDB-1~wheezy', MySqlPlatform::class], ['5.5.5-MariaDB-10.2.8+maria~xenial-log', MariaDb1027Platform::class], ['10.2.8-MariaDB-10.2.8+maria~xenial-log', MariaDb1027Platform::class], - ['10.2.8-MariaDB-1~lenny-log', MariaDb1027Platform::class] + ['10.2.8-MariaDB-1~lenny-log', MariaDb1027Platform::class], ]; } protected function getExceptionConversionData() { - return array( - self::EXCEPTION_CONNECTION => array( - array('1044', null, null), - array('1045', null, null), - array('1046', null, null), - array('1049', null, null), - array('1095', null, null), - array('1142', null, null), - array('1143', null, null), - array('1227', null, null), - array('1370', null, null), - array('2002', null, null), - array('2005', null, null), - ), - self::EXCEPTION_FOREIGN_KEY_CONSTRAINT_VIOLATION => array( - array('1216', null, null), - array('1217', null, null), - array('1451', null, null), - array('1452', null, null), - ), - self::EXCEPTION_INVALID_FIELD_NAME => array( - array('1054', null, null), - array('1166', null, null), - array('1611', null, null), - ), - self::EXCEPTION_NON_UNIQUE_FIELD_NAME => array( - array('1052', null, null), - array('1060', null, null), - array('1110', null, null), - ), - self::EXCEPTION_NOT_NULL_CONSTRAINT_VIOLATION => array( - array('1048', null, null), - array('1121', null, null), - array('1138', null, null), - array('1171', null, null), - array('1252', null, null), - array('1263', null, null), - array('1364', null, null), - array('1566', null, null), - ), - self::EXCEPTION_SYNTAX_ERROR => array( - array('1064', null, null), - array('1149', null, null), - array('1287', null, null), - array('1341', null, null), - array('1342', null, null), - array('1343', null, null), - array('1344', null, null), - array('1382', null, null), - array('1479', null, null), - array('1541', null, null), - array('1554', null, null), - array('1626', null, null), - ), - self::EXCEPTION_TABLE_EXISTS => array( - array('1050', null, null), - ), - self::EXCEPTION_TABLE_NOT_FOUND => array( - array('1051', null, null), - array('1146', null, null), - ), - self::EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION => array( - array('1062', null, null), - array('1557', null, null), - array('1569', null, null), - array('1586', null, null), - ), - self::EXCEPTION_DEADLOCK => array( - array('1213', null, null), - ), - self::EXCEPTION_LOCK_WAIT_TIMEOUT => array( - array('1205', null, null), - ), - ); + return [ + self::EXCEPTION_CONNECTION => [ + ['1044', null, null], + ['1045', null, null], + ['1046', null, null], + ['1049', null, null], + ['1095', null, null], + ['1142', null, null], + ['1143', null, null], + ['1227', null, null], + ['1370', null, null], + ['2002', null, null], + ['2005', null, null], + ], + self::EXCEPTION_FOREIGN_KEY_CONSTRAINT_VIOLATION => [ + ['1216', null, null], + ['1217', null, null], + ['1451', null, null], + ['1452', null, null], + ], + self::EXCEPTION_INVALID_FIELD_NAME => [ + ['1054', null, null], + ['1166', null, null], + ['1611', null, null], + ], + self::EXCEPTION_NON_UNIQUE_FIELD_NAME => [ + ['1052', null, null], + ['1060', null, null], + ['1110', null, null], + ], + self::EXCEPTION_NOT_NULL_CONSTRAINT_VIOLATION => [ + ['1048', null, null], + ['1121', null, null], + ['1138', null, null], + ['1171', null, null], + ['1252', null, null], + ['1263', null, null], + ['1364', null, null], + ['1566', null, null], + ], + self::EXCEPTION_SYNTAX_ERROR => [ + ['1064', null, null], + ['1149', null, null], + ['1287', null, null], + ['1341', null, null], + ['1342', null, null], + ['1343', null, null], + ['1344', null, null], + ['1382', null, null], + ['1479', null, null], + ['1541', null, null], + ['1554', null, null], + ['1626', null, null], + ], + self::EXCEPTION_TABLE_EXISTS => [ + ['1050', null, null], + ], + self::EXCEPTION_TABLE_NOT_FOUND => [ + ['1051', null, null], + ['1146', null, null], + ], + self::EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION => [ + ['1062', null, null], + ['1557', null, null], + ['1569', null, null], + ['1586', null, null], + ], + self::EXCEPTION_DEADLOCK => [ + ['1213', null, null], + ], + self::EXCEPTION_LOCK_WAIT_TIMEOUT => [ + ['1205', null, null], + ], + ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriver/EasyConnectStringTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriver/EasyConnectStringTest.php index 812a46b5682..efb250d1ac7 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriver/EasyConnectStringTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriver/EasyConnectStringTest.php @@ -9,6 +9,7 @@ class EasyConnectStringTest extends TestCase { /** * @param mixed[] $params + * * @dataProvider connectionParametersProvider */ public function testFromConnectionParameters(array $params, string $expected) : void diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriverTest.php index 59d3c20ae0b..a427f12c945 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriverTest.php @@ -10,11 +10,11 @@ class AbstractOracleDriverTest extends AbstractDriverTest { public function testReturnsDatabaseName() { - $params = array( + $params = [ 'user' => 'foo', 'password' => 'bar', 'dbname' => 'baz', - ); + ]; $connection = $this->getConnectionMock(); @@ -27,13 +27,13 @@ public function testReturnsDatabaseName() public function testReturnsDatabaseNameWithConnectDescriptor() { - $params = array( + $params = [ 'user' => 'foo', 'password' => 'bar', 'connectionstring' => '(DESCRIPTION=' . '(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))' . - '(CONNECT_DATA=(SERVICE_NAME=baz)))' - ); + '(CONNECT_DATA=(SERVICE_NAME=baz)))', + ]; $connection = $this->getConnectionMock(); @@ -61,38 +61,38 @@ protected function createSchemaManager(Connection $connection) protected function getExceptionConversionData() { - return array( - self::EXCEPTION_CONNECTION => array( - array('1017', null, null), - array('12545', null, null), - ), - self::EXCEPTION_FOREIGN_KEY_CONSTRAINT_VIOLATION => array( - array('2292', null, null), - ), - self::EXCEPTION_INVALID_FIELD_NAME => array( - array('904', null, null), - ), - self::EXCEPTION_NON_UNIQUE_FIELD_NAME => array( - array('918', null, null), - array('960', null, null), - ), - self::EXCEPTION_NOT_NULL_CONSTRAINT_VIOLATION => array( - array('1400', null, null), - ), - self::EXCEPTION_SYNTAX_ERROR => array( - array('923', null, null), - ), - self::EXCEPTION_TABLE_EXISTS => array( - array('955', null, null), - ), - self::EXCEPTION_TABLE_NOT_FOUND => array( - array('942', null, null), - ), - self::EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION => array( - array('1', null, null), - array('2299', null, null), - array('38911', null, null), - ), - ); + return [ + self::EXCEPTION_CONNECTION => [ + ['1017', null, null], + ['12545', null, null], + ], + self::EXCEPTION_FOREIGN_KEY_CONSTRAINT_VIOLATION => [ + ['2292', null, null], + ], + self::EXCEPTION_INVALID_FIELD_NAME => [ + ['904', null, null], + ], + self::EXCEPTION_NON_UNIQUE_FIELD_NAME => [ + ['918', null, null], + ['960', null, null], + ], + self::EXCEPTION_NOT_NULL_CONSTRAINT_VIOLATION => [ + ['1400', null, null], + ], + self::EXCEPTION_SYNTAX_ERROR => [ + ['923', null, null], + ], + self::EXCEPTION_TABLE_EXISTS => [ + ['955', null, null], + ], + self::EXCEPTION_TABLE_NOT_FOUND => [ + ['942', null, null], + ], + self::EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION => [ + ['1', null, null], + ['2299', null, null], + ['38911', null, null], + ], + ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractPostgreSQLDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractPostgreSQLDriverTest.php index b71e10f80ce..9c9bcd5c354 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractPostgreSQLDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractPostgreSQLDriverTest.php @@ -14,10 +14,10 @@ public function testReturnsDatabaseName() parent::testReturnsDatabaseName(); $database = 'bloo'; - $params = array( + $params = [ 'user' => 'foo', 'password' => 'bar', - ); + ]; $statement = $this->createMock('Doctrine\Tests\Mocks\DriverResultStatementMock'); @@ -55,57 +55,57 @@ protected function createSchemaManager(Connection $connection) protected function getDatabasePlatformsForVersions() { - return array( - array('9.0.9', 'Doctrine\DBAL\Platforms\PostgreSqlPlatform'), - array('9.1', 'Doctrine\DBAL\Platforms\PostgreSQL91Platform'), - array('9.1.0', 'Doctrine\DBAL\Platforms\PostgreSQL91Platform'), - array('9.1.1', 'Doctrine\DBAL\Platforms\PostgreSQL91Platform'), - array('9.1.9', 'Doctrine\DBAL\Platforms\PostgreSQL91Platform'), - array('9.2', 'Doctrine\DBAL\Platforms\PostgreSQL92Platform'), - array('9.2.0', 'Doctrine\DBAL\Platforms\PostgreSQL92Platform'), - array('9.2.1', 'Doctrine\DBAL\Platforms\PostgreSQL92Platform'), - array('9.3.6', 'Doctrine\DBAL\Platforms\PostgreSQL92Platform'), - array('9.4', 'Doctrine\DBAL\Platforms\PostgreSQL94Platform'), - array('9.4.0', 'Doctrine\DBAL\Platforms\PostgreSQL94Platform'), - array('9.4.1', 'Doctrine\DBAL\Platforms\PostgreSQL94Platform'), - array('10', PostgreSQL100Platform::class), - ); + return [ + ['9.0.9', 'Doctrine\DBAL\Platforms\PostgreSqlPlatform'], + ['9.1', 'Doctrine\DBAL\Platforms\PostgreSQL91Platform'], + ['9.1.0', 'Doctrine\DBAL\Platforms\PostgreSQL91Platform'], + ['9.1.1', 'Doctrine\DBAL\Platforms\PostgreSQL91Platform'], + ['9.1.9', 'Doctrine\DBAL\Platforms\PostgreSQL91Platform'], + ['9.2', 'Doctrine\DBAL\Platforms\PostgreSQL92Platform'], + ['9.2.0', 'Doctrine\DBAL\Platforms\PostgreSQL92Platform'], + ['9.2.1', 'Doctrine\DBAL\Platforms\PostgreSQL92Platform'], + ['9.3.6', 'Doctrine\DBAL\Platforms\PostgreSQL92Platform'], + ['9.4', 'Doctrine\DBAL\Platforms\PostgreSQL94Platform'], + ['9.4.0', 'Doctrine\DBAL\Platforms\PostgreSQL94Platform'], + ['9.4.1', 'Doctrine\DBAL\Platforms\PostgreSQL94Platform'], + ['10', PostgreSQL100Platform::class], + ]; } protected function getExceptionConversionData() { - return array( - self::EXCEPTION_CONNECTION => array( - array(null, '7', 'SQLSTATE[08006]'), - ), - self::EXCEPTION_FOREIGN_KEY_CONSTRAINT_VIOLATION => array( - array(null, '23503', null), - ), - self::EXCEPTION_INVALID_FIELD_NAME => array( - array(null, '42703', null), - ), - self::EXCEPTION_NON_UNIQUE_FIELD_NAME => array( - array(null, '42702', null), - ), - self::EXCEPTION_NOT_NULL_CONSTRAINT_VIOLATION => array( - array(null, '23502', null), - ), - self::EXCEPTION_SYNTAX_ERROR => array( - array(null, '42601', null), - ), - self::EXCEPTION_TABLE_EXISTS => array( - array(null, '42P07', null), - ), - self::EXCEPTION_TABLE_NOT_FOUND => array( - array(null, '42P01', null), - ), - self::EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION => array( - array(null, '23505', null), - ), - self::EXCEPTION_DEADLOCK => array( - array(null, '40001', null), - array(null, '40P01', null), - ), - ); + return [ + self::EXCEPTION_CONNECTION => [ + [null, '7', 'SQLSTATE[08006]'], + ], + self::EXCEPTION_FOREIGN_KEY_CONSTRAINT_VIOLATION => [ + [null, '23503', null], + ], + self::EXCEPTION_INVALID_FIELD_NAME => [ + [null, '42703', null], + ], + self::EXCEPTION_NON_UNIQUE_FIELD_NAME => [ + [null, '42702', null], + ], + self::EXCEPTION_NOT_NULL_CONSTRAINT_VIOLATION => [ + [null, '23502', null], + ], + self::EXCEPTION_SYNTAX_ERROR => [ + [null, '42601', null], + ], + self::EXCEPTION_TABLE_EXISTS => [ + [null, '42P07', null], + ], + self::EXCEPTION_TABLE_NOT_FOUND => [ + [null, '42P01', null], + ], + self::EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION => [ + [null, '23505', null], + ], + self::EXCEPTION_DEADLOCK => [ + [null, '40001', null], + [null, '40P01', null], + ], + ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLAnywhereDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLAnywhereDriverTest.php index f2b13c3c1c9..53480e7d82a 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLAnywhereDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLAnywhereDriverTest.php @@ -25,84 +25,84 @@ protected function createSchemaManager(Connection $connection) protected function getDatabasePlatformsForVersions() { - return array( - array('10', 'Doctrine\DBAL\Platforms\SQLAnywherePlatform'), - array('10.0', 'Doctrine\DBAL\Platforms\SQLAnywherePlatform'), - array('10.0.0', 'Doctrine\DBAL\Platforms\SQLAnywherePlatform'), - array('10.0.0.0', 'Doctrine\DBAL\Platforms\SQLAnywherePlatform'), - array('10.1.2.3', 'Doctrine\DBAL\Platforms\SQLAnywherePlatform'), - array('10.9.9.9', 'Doctrine\DBAL\Platforms\SQLAnywherePlatform'), - array('11', 'Doctrine\DBAL\Platforms\SQLAnywhere11Platform'), - array('11.0', 'Doctrine\DBAL\Platforms\SQLAnywhere11Platform'), - array('11.0.0', 'Doctrine\DBAL\Platforms\SQLAnywhere11Platform'), - array('11.0.0.0', 'Doctrine\DBAL\Platforms\SQLAnywhere11Platform'), - array('11.1.2.3', 'Doctrine\DBAL\Platforms\SQLAnywhere11Platform'), - array('11.9.9.9', 'Doctrine\DBAL\Platforms\SQLAnywhere11Platform'), - array('12', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'), - array('12.0', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'), - array('12.0.0', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'), - array('12.0.0.0', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'), - array('12.1.2.3', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'), - array('12.9.9.9', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'), - array('13', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'), - array('14', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'), - array('15', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'), - array('15.9.9.9', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'), - array('16', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'), - array('16.0', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'), - array('16.0.0', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'), - array('16.0.0.0', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'), - array('16.1.2.3', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'), - array('16.9.9.9', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'), - array('17', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'), - ); + return [ + ['10', 'Doctrine\DBAL\Platforms\SQLAnywherePlatform'], + ['10.0', 'Doctrine\DBAL\Platforms\SQLAnywherePlatform'], + ['10.0.0', 'Doctrine\DBAL\Platforms\SQLAnywherePlatform'], + ['10.0.0.0', 'Doctrine\DBAL\Platforms\SQLAnywherePlatform'], + ['10.1.2.3', 'Doctrine\DBAL\Platforms\SQLAnywherePlatform'], + ['10.9.9.9', 'Doctrine\DBAL\Platforms\SQLAnywherePlatform'], + ['11', 'Doctrine\DBAL\Platforms\SQLAnywhere11Platform'], + ['11.0', 'Doctrine\DBAL\Platforms\SQLAnywhere11Platform'], + ['11.0.0', 'Doctrine\DBAL\Platforms\SQLAnywhere11Platform'], + ['11.0.0.0', 'Doctrine\DBAL\Platforms\SQLAnywhere11Platform'], + ['11.1.2.3', 'Doctrine\DBAL\Platforms\SQLAnywhere11Platform'], + ['11.9.9.9', 'Doctrine\DBAL\Platforms\SQLAnywhere11Platform'], + ['12', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'], + ['12.0', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'], + ['12.0.0', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'], + ['12.0.0.0', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'], + ['12.1.2.3', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'], + ['12.9.9.9', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'], + ['13', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'], + ['14', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'], + ['15', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'], + ['15.9.9.9', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'], + ['16', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'], + ['16.0', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'], + ['16.0.0', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'], + ['16.0.0.0', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'], + ['16.1.2.3', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'], + ['16.9.9.9', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'], + ['17', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'], + ]; } protected function getExceptionConversionData() { - return array( - self::EXCEPTION_CONNECTION => array( - array('-100', null, null), - array('-103', null, null), - array('-832', null, null), - ), - self::EXCEPTION_FOREIGN_KEY_CONSTRAINT_VIOLATION => array( - array('-198', null, null), - ), - self::EXCEPTION_INVALID_FIELD_NAME => array( - array('-143', null, null), - ), - self::EXCEPTION_NON_UNIQUE_FIELD_NAME => array( - array('-144', null, null), - ), - self::EXCEPTION_NOT_NULL_CONSTRAINT_VIOLATION => array( - array('-184', null, null), - array('-195', null, null), - ), - self::EXCEPTION_SYNTAX_ERROR => array( - array('-131', null, null), - ), - self::EXCEPTION_TABLE_EXISTS => array( - array('-110', null, null), - ), - self::EXCEPTION_TABLE_NOT_FOUND => array( - array('-141', null, null), - array('-1041', null, null), - ), - self::EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION => array( - array('-193', null, null), - array('-196', null, null), - ), - self::EXCEPTION_DEADLOCK => array( - array('-306', null, null), - array('-307', null, null), - array('-684', null, null), - ), - self::EXCEPTION_LOCK_WAIT_TIMEOUT => array( - array('-210', null, null), - array('-1175', null, null), - array('-1281', null, null), - ), - ); + return [ + self::EXCEPTION_CONNECTION => [ + ['-100', null, null], + ['-103', null, null], + ['-832', null, null], + ], + self::EXCEPTION_FOREIGN_KEY_CONSTRAINT_VIOLATION => [ + ['-198', null, null], + ], + self::EXCEPTION_INVALID_FIELD_NAME => [ + ['-143', null, null], + ], + self::EXCEPTION_NON_UNIQUE_FIELD_NAME => [ + ['-144', null, null], + ], + self::EXCEPTION_NOT_NULL_CONSTRAINT_VIOLATION => [ + ['-184', null, null], + ['-195', null, null], + ], + self::EXCEPTION_SYNTAX_ERROR => [ + ['-131', null, null], + ], + self::EXCEPTION_TABLE_EXISTS => [ + ['-110', null, null], + ], + self::EXCEPTION_TABLE_NOT_FOUND => [ + ['-141', null, null], + ['-1041', null, null], + ], + self::EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION => [ + ['-193', null, null], + ['-196', null, null], + ], + self::EXCEPTION_DEADLOCK => [ + ['-306', null, null], + ['-307', null, null], + ['-684', null, null], + ], + self::EXCEPTION_LOCK_WAIT_TIMEOUT => [ + ['-210', null, null], + ['-1175', null, null], + ['-1281', null, null], + ], + ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLServerDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLServerDriverTest.php index 35d2d721a51..31e72a661af 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLServerDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLServerDriverTest.php @@ -25,33 +25,33 @@ protected function createSchemaManager(Connection $connection) protected function getDatabasePlatformsForVersions() { - return array( - array('9', 'Doctrine\DBAL\Platforms\SQLServerPlatform'), - array('9.00', 'Doctrine\DBAL\Platforms\SQLServerPlatform'), - array('9.00.0', 'Doctrine\DBAL\Platforms\SQLServerPlatform'), - array('9.00.1398', 'Doctrine\DBAL\Platforms\SQLServerPlatform'), - array('9.00.1398.99', 'Doctrine\DBAL\Platforms\SQLServerPlatform'), - array('9.00.1399', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'), - array('9.00.1399.0', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'), - array('9.00.1399.99', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'), - array('9.00.1400', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'), - array('9.10', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'), - array('9.10.9999', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'), - array('10.00.1599', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'), - array('10.00.1599.99', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'), - array('10.00.1600', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'), - array('10.00.1600.0', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'), - array('10.00.1600.99', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'), - array('10.00.1601', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'), - array('10.10', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'), - array('10.10.9999', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'), - array('11.00.2099', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'), - array('11.00.2099.99', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'), - array('11.00.2100', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'), - array('11.00.2100.0', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'), - array('11.00.2100.99', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'), - array('11.00.2101', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'), - array('12', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'), - ); + return [ + ['9', 'Doctrine\DBAL\Platforms\SQLServerPlatform'], + ['9.00', 'Doctrine\DBAL\Platforms\SQLServerPlatform'], + ['9.00.0', 'Doctrine\DBAL\Platforms\SQLServerPlatform'], + ['9.00.1398', 'Doctrine\DBAL\Platforms\SQLServerPlatform'], + ['9.00.1398.99', 'Doctrine\DBAL\Platforms\SQLServerPlatform'], + ['9.00.1399', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'], + ['9.00.1399.0', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'], + ['9.00.1399.99', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'], + ['9.00.1400', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'], + ['9.10', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'], + ['9.10.9999', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'], + ['10.00.1599', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'], + ['10.00.1599.99', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'], + ['10.00.1600', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'], + ['10.00.1600.0', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'], + ['10.00.1600.99', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'], + ['10.00.1601', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'], + ['10.10', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'], + ['10.10.9999', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'], + ['11.00.2099', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'], + ['11.00.2099.99', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'], + ['11.00.2100', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'], + ['11.00.2100.0', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'], + ['11.00.2100.99', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'], + ['11.00.2101', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'], + ['12', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'], + ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLiteDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLiteDriverTest.php index e1ce3f10127..96f3b6b9d64 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLiteDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLiteDriverTest.php @@ -10,12 +10,12 @@ class AbstractSQLiteDriverTest extends AbstractDriverTest { public function testReturnsDatabaseName() { - $params = array( + $params = [ 'user' => 'foo', 'password' => 'bar', 'dbname' => 'baz', 'path' => 'bloo', - ); + ]; $connection = $this->getConnectionMock(); @@ -43,39 +43,39 @@ protected function createSchemaManager(Connection $connection) protected function getExceptionConversionData() { - return array( - self::EXCEPTION_CONNECTION => array( - array(null, null, 'unable to open database file'), - ), - self::EXCEPTION_INVALID_FIELD_NAME => array( - array(null, null, 'has no column named'), - ), - self::EXCEPTION_NON_UNIQUE_FIELD_NAME => array( - array(null, null, 'ambiguous column name'), - ), - self::EXCEPTION_NOT_NULL_CONSTRAINT_VIOLATION => array( - array(null, null, 'may not be NULL'), - ), - self::EXCEPTION_READ_ONLY => array( - array(null, null, 'attempt to write a readonly database'), - ), - self::EXCEPTION_SYNTAX_ERROR => array( - array(null, null, 'syntax error'), - ), - self::EXCEPTION_TABLE_EXISTS => array( - array(null, null, 'already exists'), - ), - self::EXCEPTION_TABLE_NOT_FOUND => array( - array(null, null, 'no such table:'), - ), - self::EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION => array( - array(null, null, 'must be unique'), - array(null, null, 'is not unique'), - array(null, null, 'are not unique'), - ), - self::EXCEPTION_LOCK_WAIT_TIMEOUT => array( - array(null, null, 'database is locked'), - ), - ); + return [ + self::EXCEPTION_CONNECTION => [ + [null, null, 'unable to open database file'], + ], + self::EXCEPTION_INVALID_FIELD_NAME => [ + [null, null, 'has no column named'], + ], + self::EXCEPTION_NON_UNIQUE_FIELD_NAME => [ + [null, null, 'ambiguous column name'], + ], + self::EXCEPTION_NOT_NULL_CONSTRAINT_VIOLATION => [ + [null, null, 'may not be NULL'], + ], + self::EXCEPTION_READ_ONLY => [ + [null, null, 'attempt to write a readonly database'], + ], + self::EXCEPTION_SYNTAX_ERROR => [ + [null, null, 'syntax error'], + ], + self::EXCEPTION_TABLE_EXISTS => [ + [null, null, 'already exists'], + ], + self::EXCEPTION_TABLE_NOT_FOUND => [ + [null, null, 'no such table:'], + ], + self::EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION => [ + [null, null, 'must be unique'], + [null, null, 'is not unique'], + [null, null, 'are not unique'], + ], + self::EXCEPTION_LOCK_WAIT_TIMEOUT => [ + [null, null, 'database is locked'], + ], + ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2ConnectionTest.php index 114a5a108a1..eaebefb728c 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2ConnectionTest.php @@ -2,7 +2,9 @@ namespace Doctrine\Tests\DBAL\Driver\IBMDB2; +use Doctrine\DBAL\Driver\IBMDB2\DB2Connection; use Doctrine\Tests\DbalTestCase; +use PHPUnit_Framework_MockObject_MockObject; use function extension_loaded; class DB2ConnectionTest extends DbalTestCase @@ -10,13 +12,13 @@ class DB2ConnectionTest extends DbalTestCase /** * The ibm_db2 driver connection mock under test. * - * @var \Doctrine\DBAL\Driver\IBMDB2\DB2Connection|\PHPUnit_Framework_MockObject_MockObject + * @var DB2Connection|PHPUnit_Framework_MockObject_MockObject */ private $connectionMock; protected function setUp() { - if ( ! extension_loaded('ibm_db2')) { + 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 1dec0608eba..b0b34309f28 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Driver\Mysqli\MysqliException; use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\Tests\DbalFunctionalTestCase; +use PHPUnit_Framework_MockObject_MockObject; use function extension_loaded; use function restore_error_handler; use function set_error_handler; @@ -15,13 +16,13 @@ class MysqliConnectionTest extends DbalFunctionalTestCase /** * The mysqli driver connection mock under test. * - * @var \Doctrine\DBAL\Driver\Mysqli\MysqliConnection|\PHPUnit_Framework_MockObject_MockObject + * @var MysqliConnection|PHPUnit_Framework_MockObject_MockObject */ private $connectionMock; protected function setUp() { - if ( ! extension_loaded('mysqli')) { + if (! extension_loaded('mysqli')) { $this->markTestSkipped('mysqli is not installed.'); } @@ -43,7 +44,9 @@ public function testDoesNotRequireQueryForServerVersion() public function testRestoresErrorHandlerOnException() { - $handler = function () { self::fail('Never expected this to be called'); }; + $handler = static function () { + self::fail('Never expected this to be called'); + }; $default_handler = set_error_handler($handler); try { diff --git a/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8ConnectionTest.php index 864b1a643d5..b8141a84f2a 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8ConnectionTest.php @@ -2,7 +2,9 @@ namespace Doctrine\Tests\DBAL\Driver\OCI8; +use Doctrine\DBAL\Driver\OCI8\OCI8Connection; use Doctrine\Tests\DbalTestCase; +use PHPUnit_Framework_MockObject_MockObject; use function extension_loaded; class OCI8ConnectionTest extends DbalTestCase @@ -10,13 +12,13 @@ class OCI8ConnectionTest extends DbalTestCase /** * The oci8 driver connection mock under test. * - * @var \Doctrine\DBAL\Driver\OCI8\OCI8Connection|\PHPUnit_Framework_MockObject_MockObject + * @var OCI8Connection|PHPUnit_Framework_MockObject_MockObject */ private $connectionMock; protected function setUp() { - if ( ! extension_loaded('oci8')) { + 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 65a3c95ce36..103b7ab57d7 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php @@ -5,13 +5,14 @@ use Doctrine\DBAL\Driver\OCI8\OCI8Exception; use Doctrine\DBAL\Driver\OCI8\OCI8Statement; use Doctrine\Tests\DbalTestCase; +use ReflectionProperty; use function extension_loaded; class OCI8StatementTest extends DbalTestCase { protected function setUp() { - if (!extension_loaded('oci8')) { + if (! extension_loaded('oci8')) { $this->markTestSkipped('oci8 is not installed.'); } @@ -33,7 +34,7 @@ protected function setUp() public function testExecute(array $params) { $statement = $this->getMockBuilder('\Doctrine\DBAL\Driver\OCI8\OCI8Statement') - ->setMethods(array('bindValue', 'errorInfo')) + ->setMethods(['bindValue', 'errorInfo']) ->disableOriginalConstructor() ->getMock(); @@ -54,18 +55,18 @@ public function testExecute(array $params) ->with( $this->equalTo(3), $this->equalTo($params[2]) - ); + ); // 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('\Doctrine\DBAL\Driver\OCI8\OCI8Connection') - ->setMethods(array('getExecuteMode')) + ->setMethods(['getExecuteMode']) ->disableOriginalConstructor() ->getMock(); $conn->expects($this->once()) ->method('getExecuteMode'); - $reflProperty = new \ReflectionProperty($statement, '_conn'); + $reflProperty = new ReflectionProperty($statement, '_conn'); $reflProperty->setAccessible(true); $reflProperty->setValue($statement, $conn); @@ -74,16 +75,16 @@ public function testExecute(array $params) public static function executeDataProvider() { - return array( + return [ // $hasZeroIndex = isset($params[0]); == true - array( - array(0 => 'test', 1 => null, 2 => 'value') - ), + [ + [0 => 'test', 1 => null, 2 => 'value'], + ], // $hasZeroIndex = isset($params[0]); == false - array( - array(0 => null, 1 => 'test', 2 => 'value') - ) - ); + [ + [0 => null, 1 => 'test', 2 => 'value'], + ], + ]; } /** @@ -98,19 +99,19 @@ public function testConvertNonTerminatedLiteral($sql, $message) public static function nonTerminatedLiteralProvider() { - return array( - 'no-matching-quote' => array( + return [ + 'no-matching-quote' => [ "SELECT 'literal FROM DUAL", '/offset 7/', - ), - 'no-matching-double-quote' => array( + ], + 'no-matching-double-quote' => [ 'SELECT 1 "COL1 FROM DUAL', '/offset 9/', - ), - 'incorrect-escaping-syntax' => array( + ], + 'incorrect-escaping-syntax' => [ "SELECT 'quoted \\'string' FROM DUAL", '/offset 23/', - ), - ); + ], + ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Driver/PDOExceptionTest.php b/tests/Doctrine/Tests/DBAL/Driver/PDOExceptionTest.php index 96691bacd9c..593f04d203c 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/PDOExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/PDOExceptionTest.php @@ -4,33 +4,34 @@ use Doctrine\DBAL\Driver\PDOException; use Doctrine\Tests\DbalTestCase; +use PHPUnit_Framework_MockObject_MockObject; use function extension_loaded; class PDOExceptionTest extends DbalTestCase { - const ERROR_CODE = 666; + public const ERROR_CODE = 666; - const MESSAGE = 'PDO Exception'; + public const MESSAGE = 'PDO Exception'; - const SQLSTATE = 28000; + public const SQLSTATE = 28000; /** * The PDO exception wrapper under test. * - * @var \Doctrine\DBAL\Driver\PDOException + * @var PDOException */ private $exception; /** * The wrapped PDO exception mock. * - * @var \PDOException|\PHPUnit_Framework_MockObject_MockObject + * @var \PDOException|PHPUnit_Framework_MockObject_MockObject */ private $wrappedException; protected function setUp() { - if ( ! extension_loaded('PDO')) { + if (! extension_loaded('PDO')) { $this->markTestSkipped('PDO is not installed.'); } @@ -38,7 +39,7 @@ protected function setUp() $this->wrappedException = new \PDOException(self::MESSAGE, self::SQLSTATE); - $this->wrappedException->errorInfo = array(self::SQLSTATE, self::ERROR_CODE); + $this->wrappedException->errorInfo = [self::SQLSTATE, self::ERROR_CODE]; $this->exception = new PDOException($this->wrappedException); } diff --git a/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php index 6fd187e3d28..3f1c3efa1f8 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php @@ -6,6 +6,7 @@ use Doctrine\Tests\DBAL\Driver\AbstractPostgreSQLDriverTest; use PDO; use PDOException; +use PHPUnit_Framework_SkippedTestError; use function defined; class DriverTest extends AbstractPostgreSQLDriverTest @@ -23,10 +24,10 @@ public function testConnectionDisablesPreparesOnPhp56() $this->skipWhenNotUsingPhp56AndPdoPgsql(); $connection = $this->createDriver()->connect( - array( + [ 'host' => $GLOBALS['db_host'], - 'port' => $GLOBALS['db_port'] - ), + 'port' => $GLOBALS['db_port'], + ], $GLOBALS['db_username'], $GLOBALS['db_password'] ); @@ -49,13 +50,13 @@ public function testConnectionDoesNotDisablePreparesOnPhp56WhenAttributeDefined( $this->skipWhenNotUsingPhp56AndPdoPgsql(); $connection = $this->createDriver()->connect( - array( + [ 'host' => $GLOBALS['db_host'], - 'port' => $GLOBALS['db_port'] - ), + 'port' => $GLOBALS['db_port'], + ], $GLOBALS['db_username'], $GLOBALS['db_password'], - array(PDO::PGSQL_ATTR_DISABLE_PREPARES => false) + [PDO::PGSQL_ATTR_DISABLE_PREPARES => false] ); self::assertInstanceOf('Doctrine\DBAL\Driver\PDOConnection', $connection); @@ -76,13 +77,13 @@ public function testConnectionDisablePreparesOnPhp56WhenDisablePreparesIsExplici $this->skipWhenNotUsingPhp56AndPdoPgsql(); $connection = $this->createDriver()->connect( - array( + [ 'host' => $GLOBALS['db_host'], - 'port' => $GLOBALS['db_port'] - ), + 'port' => $GLOBALS['db_port'], + ], $GLOBALS['db_username'], $GLOBALS['db_password'], - array(PDO::PGSQL_ATTR_DISABLE_PREPARES => true) + [PDO::PGSQL_ATTR_DISABLE_PREPARES => true] ); self::assertInstanceOf('Doctrine\DBAL\Driver\PDOConnection', $connection); @@ -104,7 +105,7 @@ protected function createDriver() } /** - * @throws \PHPUnit_Framework_SkippedTestError + * @throws PHPUnit_Framework_SkippedTestError */ private function skipWhenNotUsingPhp56AndPdoPgsql() { @@ -112,8 +113,10 @@ private function skipWhenNotUsingPhp56AndPdoPgsql() $this->markTestSkipped('Test requires PHP 5.6+'); } - if (! (isset($GLOBALS['db_type']) && $GLOBALS['db_type'] === 'pdo_pgsql')) { - $this->markTestSkipped('Test enabled only when using pdo_pgsql specific phpunit.xml'); + if (isset($GLOBALS['db_type']) && $GLOBALS['db_type'] === 'pdo_pgsql') { + return; } + + $this->markTestSkipped('Test enabled only when using pdo_pgsql specific phpunit.xml'); } } diff --git a/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/SQLAnywhereConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/SQLAnywhereConnectionTest.php index 273c2de1b85..49bc5d05a16 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/SQLAnywhereConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/SQLAnywhereConnectionTest.php @@ -2,7 +2,9 @@ namespace Doctrine\Tests\DBAL\Driver\SQLAnywhere; +use Doctrine\DBAL\Driver\SQLAnywhere\SQLAnywhereConnection; use Doctrine\Tests\DbalTestCase; +use PHPUnit_Framework_MockObject_MockObject; use function extension_loaded; class SQLAnywhereConnectionTest extends DbalTestCase @@ -10,13 +12,13 @@ class SQLAnywhereConnectionTest extends DbalTestCase /** * The sqlanywhere driver connection mock under test. * - * @var \Doctrine\DBAL\Driver\SQLAnywhere\SQLAnywhereConnection|\PHPUnit_Framework_MockObject_MockObject + * @var SQLAnywhereConnection|PHPUnit_Framework_MockObject_MockObject */ private $connectionMock; protected function setUp() { - if ( ! extension_loaded('sqlanywhere')) { + 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 089d2b11085..9e467cca01f 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/SQLSrvConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/SQLSrvConnectionTest.php @@ -2,7 +2,9 @@ namespace Doctrine\Tests\DBAL\Driver\SQLSrv; +use Doctrine\DBAL\Driver\SQLSrv\SQLSrvConnection; use Doctrine\Tests\DbalTestCase; +use PHPUnit_Framework_MockObject_MockObject; use function extension_loaded; class SQLSrvConnectionTest extends DbalTestCase @@ -10,13 +12,13 @@ class SQLSrvConnectionTest extends DbalTestCase /** * The sqlsrv driver connection mock under test. * - * @var \Doctrine\DBAL\Driver\SQLSrv\SQLSrvConnection|\PHPUnit_Framework_MockObject_MockObject + * @var SQLSrvConnection|PHPUnit_Framework_MockObject_MockObject */ private $connectionMock; protected function setUp() { - if ( ! extension_loaded('sqlsrv')) { + if (! extension_loaded('sqlsrv')) { $this->markTestSkipped('sqlsrv is not installed.'); } diff --git a/tests/Doctrine/Tests/DBAL/Driver/StatementIteratorTest.php b/tests/Doctrine/Tests/DBAL/Driver/StatementIteratorTest.php index 95f107cf921..90244cd2ac8 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/StatementIteratorTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/StatementIteratorTest.php @@ -10,12 +10,13 @@ use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\Driver\StatementIterator; use Doctrine\DBAL\Portability\Statement as PortabilityStatement; +use Doctrine\Tests\DbalTestCase; use IteratorAggregate; use PHPUnit\Framework\MockObject\MockObject; use Traversable; use function extension_loaded; -class StatementIteratorTest extends \Doctrine\Tests\DbalTestCase +class StatementIteratorTest extends DbalTestCase { /** * @dataProvider statementProvider() @@ -58,11 +59,11 @@ public function testStatementIterationCallsFetchOncePerStep(string $class) : voi private function configureStatement(MockObject $stmt, int &$calls) : void { $values = ['foo', '', 'bar', '0', 'baz', 0, 'qux', null, 'quz', false, 'impossible']; - $calls = 0; + $calls = 0; $stmt->expects($this->exactly(10)) ->method('fetch') - ->willReturnCallback(function() use ($values, &$calls) { + ->willReturnCallback(static function () use ($values, &$calls) { $value = $values[$calls]; $calls++; diff --git a/tests/Doctrine/Tests/DBAL/DriverManagerTest.php b/tests/Doctrine/Tests/DBAL/DriverManagerTest.php index 7e7c5b0153a..e5520afcf1e 100644 --- a/tests/Doctrine/Tests/DBAL/DriverManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/DriverManagerTest.php @@ -15,6 +15,7 @@ use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\Mocks\ConnectionMock; use Doctrine\Tests\Mocks\DriverMock; +use PDO; use stdClass; use function extension_loaded; use function in_array; @@ -37,7 +38,7 @@ public function testInvalidPdoInstance() public function testValidPdoInstance() { $conn = DriverManager::getConnection([ - 'pdo' => new \PDO('sqlite::memory:'), + 'pdo' => new PDO('sqlite::memory:'), ]); self::assertEquals('sqlite', $conn->getDatabasePlatform()->getName()); @@ -49,12 +50,12 @@ public function testValidPdoInstance() */ public function testPdoInstanceSetErrorMode() { - $pdo = new \PDO('sqlite::memory:'); - $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_SILENT); + $pdo = new PDO('sqlite::memory:'); + $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); $options = ['pdo' => $pdo]; DriverManager::getConnection($options); - self::assertEquals(\PDO::ERRMODE_EXCEPTION, $pdo->getAttribute(\PDO::ATTR_ERRMODE)); + self::assertEquals(PDO::ERRMODE_EXCEPTION, $pdo->getAttribute(PDO::ATTR_ERRMODE)); } /** @@ -80,7 +81,7 @@ public function testCustomPlatform() { $mockPlatform = new MockPlatform(); $options = [ - 'pdo' => new \PDO('sqlite::memory:'), + 'pdo' => new PDO('sqlite::memory:'), 'platform' => $mockPlatform, ]; @@ -96,7 +97,7 @@ public function testCustomWrapper() $wrapperClass = ConnectionMock::class; $options = [ - 'pdo' => new \PDO('sqlite::memory:'), + 'pdo' => new PDO('sqlite::memory:'), 'wrapperClass' => $wrapperClass, ]; @@ -112,7 +113,7 @@ public function testInvalidWrapperClass() $this->expectException(DBALException::class); $options = [ - 'pdo' => new \PDO('sqlite::memory:'), + 'pdo' => new PDO('sqlite::memory:'), 'wrapperClass' => stdClass::class, ]; @@ -216,7 +217,7 @@ public function testDatabaseUrl($url, $expected) $this->markTestSkipped('PDO is not installed'); } - $options['pdo'] = $this->createMock(\PDO::class); + $options['pdo'] = $this->createMock(PDO::class); } $options = is_array($url) ? $url : ['url' => $url]; diff --git a/tests/Doctrine/Tests/DBAL/Events/MysqlSessionInitTest.php b/tests/Doctrine/Tests/DBAL/Events/MysqlSessionInitTest.php index 2a19d2c5fee..981851a6b9e 100644 --- a/tests/Doctrine/Tests/DBAL/Events/MysqlSessionInitTest.php +++ b/tests/Doctrine/Tests/DBAL/Events/MysqlSessionInitTest.php @@ -14,11 +14,10 @@ public function testPostConnect() $connectionMock = $this->createMock('Doctrine\DBAL\Connection'); $connectionMock->expects($this->once()) ->method('executeUpdate') - ->with($this->equalTo("SET NAMES foo COLLATE bar")); + ->with($this->equalTo('SET NAMES foo COLLATE bar')); $eventArgs = new ConnectionEventArgs($connectionMock); - $listener = new MysqlSessionInit('foo', 'bar'); $listener->postConnect($eventArgs); } @@ -26,6 +25,6 @@ public function testPostConnect() public function testGetSubscribedEvents() { $listener = new MysqlSessionInit(); - self::assertEquals(array(Events::postConnect), $listener->getSubscribedEvents()); + 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 4ec3545c002..b86af27fc3f 100644 --- a/tests/Doctrine/Tests/DBAL/Events/OracleSessionInitTest.php +++ b/tests/Doctrine/Tests/DBAL/Events/OracleSessionInitTest.php @@ -19,14 +19,12 @@ public function testPostConnect() $eventArgs = new ConnectionEventArgs($connectionMock); - $listener = new OracleSessionInit(); $listener->postConnect($eventArgs); } /** * @group DBAL-1824 - * * @dataProvider getPostConnectWithSessionParameterValuesData */ public function testPostConnectQuotesSessionParameterValues($name, $value) @@ -40,21 +38,20 @@ public function testPostConnectQuotesSessionParameterValues($name, $value) $eventArgs = new ConnectionEventArgs($connectionMock); - - $listener = new OracleSessionInit(array($name => $value)); + $listener = new OracleSessionInit([$name => $value]); $listener->postConnect($eventArgs); } public function getPostConnectWithSessionParameterValuesData() { - return array( - array('CURRENT_SCHEMA', 'foo'), - ); + return [ + ['CURRENT_SCHEMA', 'foo'], + ]; } public function testGetSubscribedEvents() { $listener = new OracleSessionInit(); - self::assertEquals(array(Events::postConnect), $listener->getSubscribedEvents()); + 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 2b25301da98..bf74e5180ae 100644 --- a/tests/Doctrine/Tests/DBAL/Events/SQLSessionInitTest.php +++ b/tests/Doctrine/Tests/DBAL/Events/SQLSessionInitTest.php @@ -28,6 +28,6 @@ public function testPostConnect() public function testGetSubscribedEvents() { $listener = new SQLSessionInit("SET SEARCH_PATH TO foo, public, TIMEZONE TO 'Europe/Berlin'"); - self::assertEquals(array(Events::postConnect), $listener->getSubscribedEvents()); + 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 9984e3d0223..c2e7c7ec29a 100644 --- a/tests/Doctrine/Tests/DBAL/Exception/InvalidArgumentExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Exception/InvalidArgumentExceptionTest.php @@ -20,15 +20,14 @@ namespace Doctrine\Tests\DBAL\Exception; use Doctrine\DBAL\Exception\InvalidArgumentException; +use PHPUnit\Framework\TestCase; /** * Tests for {@see \Doctrine\DBAL\Exception\InvalidArgumentException} * * @covers \Doctrine\DBAL\Exception\InvalidArgumentException - * - * @author Marco Pivetta */ -class InvalidArgumentExceptionTest extends \PHPUnit\Framework\TestCase +class InvalidArgumentExceptionTest extends TestCase { public function testFromEmptyCriteria() { diff --git a/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php b/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php index e409f5f5f5e..66332ed20ba 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php @@ -5,8 +5,10 @@ use Doctrine\DBAL\Driver\PDOSqlsrv\Driver as PDOSQLSrvDriver; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; +use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Type; +use Doctrine\Tests\DbalFunctionalTestCase; use function fopen; use function in_array; use function str_repeat; @@ -15,7 +17,7 @@ /** * @group DBAL-6 */ -class BlobTest extends \Doctrine\Tests\DbalFunctionalTestCase +class BlobTest extends DbalFunctionalTestCase { protected function setUp() { @@ -25,7 +27,7 @@ protected function setUp() $this->markTestSkipped('This test does not work on pdo_sqlsrv driver due to a bug. See: http://social.msdn.microsoft.com/Forums/sqlserver/en-US/5a755bdd-41e9-45cb-9166-c9da4475bb94/how-to-set-null-for-varbinarymax-using-bindvalue-using-pdosqlsrv?forum=sqldriverforphp'); } - /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ + /** @var AbstractSchemaManager $sm */ $table = new Table('blob_table'); $table->addColumn('id', 'integer'); $table->addColumn('clobfield', 'text'); @@ -100,9 +102,7 @@ public function testUpdate() ParameterType::LARGE_OBJECT, ]); - $this->_conn->update('blob_table', [ - 'blobfield' => 'test2', - ], ['id' => 1], [ + $this->_conn->update('blob_table', ['blobfield' => 'test2'], ['id' => 1], [ ParameterType::LARGE_OBJECT, ParameterType::INTEGER, ]); diff --git a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php index 0c9d57895aa..c6cca6d8e68 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php @@ -2,14 +2,20 @@ namespace Doctrine\Tests\DBAL\Functional; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\ConnectionException; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\Type; +use Doctrine\Tests\DbalFunctionalTestCase; +use Error; +use Exception; +use RuntimeException; +use Throwable; use function in_array; -class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase +class ConnectionTest extends DbalFunctionalTestCase { protected function setUp() { @@ -46,9 +52,9 @@ public function testTransactionNestingBehavior() try { $this->_conn->beginTransaction(); self::assertEquals(2, $this->_conn->getTransactionNestingLevel()); - throw new \Exception; + throw new Exception(); $this->_conn->commit(); // never reached - } catch (\Exception $e) { + } catch (Throwable $e) { $this->_conn->rollBack(); self::assertEquals(1, $this->_conn->getTransactionNestingLevel()); //no rethrow @@ -82,9 +88,9 @@ public function testTransactionNestingBehaviorWithSavepoints() self::assertEquals(3, $this->_conn->getTransactionNestingLevel()); $this->_conn->commit(); self::assertEquals(2, $this->_conn->getTransactionNestingLevel()); - throw new \Exception; + throw new Exception(); $this->_conn->commit(); // never reached - } catch (\Exception $e) { + } catch (Throwable $e) { $this->_conn->rollBack(); self::assertEquals(1, $this->_conn->getTransactionNestingLevel()); //no rethrow @@ -121,7 +127,7 @@ public function testSetNestedTransactionsThroughSavepointsNotSupportedThrowsExce } $this->expectException(ConnectionException::class); - $this->expectExceptionMessage("Savepoints are not supported by this driver."); + $this->expectExceptionMessage('Savepoints are not supported by this driver.'); $this->_conn->setNestTransactionsWithSavepoints(true); } @@ -133,7 +139,7 @@ public function testCreateSavepointsNotSupportedThrowsException() } $this->expectException(ConnectionException::class); - $this->expectExceptionMessage("Savepoints are not supported by this driver."); + $this->expectExceptionMessage('Savepoints are not supported by this driver.'); $this->_conn->createSavepoint('foo'); } @@ -145,7 +151,7 @@ public function testReleaseSavepointsNotSupportedThrowsException() } $this->expectException(ConnectionException::class); - $this->expectExceptionMessage("Savepoints are not supported by this driver."); + $this->expectExceptionMessage('Savepoints are not supported by this driver.'); $this->_conn->releaseSavepoint('foo'); } @@ -157,7 +163,7 @@ public function testRollbackSavepointsNotSupportedThrowsException() } $this->expectException(ConnectionException::class); - $this->expectExceptionMessage("Savepoints are not supported by this driver."); + $this->expectExceptionMessage('Savepoints are not supported by this driver.'); $this->_conn->rollbackSavepoint('foo'); } @@ -168,10 +174,10 @@ public function testTransactionBehaviorWithRollback() $this->_conn->beginTransaction(); self::assertEquals(1, $this->_conn->getTransactionNestingLevel()); - throw new \Exception; + throw new Exception(); $this->_conn->commit(); // never reached - } catch (\Exception $e) { + } catch (Throwable $e) { self::assertEquals(1, $this->_conn->getTransactionNestingLevel()); $this->_conn->rollBack(); self::assertEquals(0, $this->_conn->getTransactionNestingLevel()); @@ -184,7 +190,7 @@ public function testTransactionBehaviour() $this->_conn->beginTransaction(); self::assertEquals(1, $this->_conn->getTransactionNestingLevel()); $this->_conn->commit(); - } catch (\Exception $e) { + } catch (Throwable $e) { $this->_conn->rollBack(); self::assertEquals(0, $this->_conn->getTransactionNestingLevel()); } @@ -195,13 +201,13 @@ public function testTransactionBehaviour() public function testTransactionalWithException() { try { - $this->_conn->transactional(function($conn) { - /* @var $conn \Doctrine\DBAL\Connection */ + $this->_conn->transactional(static function($conn) { + /** @var Connection $conn */ $conn->executeQuery($conn->getDatabasePlatform()->getDummySelectSQL()); - throw new \RuntimeException("Ooops!"); + throw new RuntimeException('Ooops!'); }); $this->fail('Expected exception'); - } catch (\RuntimeException $expected) { + } catch (RuntimeException $expected) { self::assertEquals(0, $this->_conn->getTransactionNestingLevel()); } } @@ -209,21 +215,21 @@ public function testTransactionalWithException() public function testTransactionalWithThrowable() { try { - $this->_conn->transactional(function($conn) { - /* @var $conn \Doctrine\DBAL\Connection */ + $this->_conn->transactional(static function($conn) { + /** @var Connection $conn */ $conn->executeQuery($conn->getDatabasePlatform()->getDummySelectSQL()); - throw new \Error("Ooops!"); + throw new Error('Ooops!'); }); $this->fail('Expected exception'); - } catch (\Error $expected) { + } catch (Error $expected) { self::assertEquals(0, $this->_conn->getTransactionNestingLevel()); } } public function testTransactional() { - $res = $this->_conn->transactional(function($conn) { - /* @var $conn \Doctrine\DBAL\Connection */ + $res = $this->_conn->transactional(static function($conn) { + /** @var Connection $conn */ $conn->executeQuery($conn->getDatabasePlatform()->getDummySelectSQL()); }); @@ -232,7 +238,7 @@ public function testTransactional() public function testTransactionalReturnValue() { - $res = $this->_conn->transactional(function() { + $res = $this->_conn->transactional(static function() { return 42; }); diff --git a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php index f63e397c65b..e688a5f0604 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php @@ -2,13 +2,16 @@ namespace Doctrine\Tests\DBAL\Functional; +use DateTime; use Doctrine\DBAL\Connection; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Platforms\TrimMode; +use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Type; +use Doctrine\Tests\DbalFunctionalTestCase; use const CASE_LOWER; use const PHP_EOL; use function array_change_key_case; @@ -22,36 +25,36 @@ use function property_exists; use function strtotime; -class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase +class DataAccessTest extends DbalFunctionalTestCase { - /** - * @var bool - */ + /** @var bool */ static private $generated = false; protected function setUp() { parent::setUp(); - if (self::$generated === false) { - /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ - $table = new \Doctrine\DBAL\Schema\Table("fetch_table"); - $table->addColumn('test_int', 'integer'); - $table->addColumn('test_string', 'string'); - $table->addColumn('test_datetime', 'datetime', array('notnull' => false)); - $table->setPrimaryKey(array('test_int')); + if (self::$generated !== false) { + return; + } - $sm = $this->_conn->getSchemaManager(); - $sm->createTable($table); + /** @var AbstractSchemaManager $sm */ + $table = new Table('fetch_table'); + $table->addColumn('test_int', 'integer'); + $table->addColumn('test_string', 'string'); + $table->addColumn('test_datetime', 'datetime', ['notnull' => false]); + $table->setPrimaryKey(['test_int']); - $this->_conn->insert('fetch_table', array('test_int' => 1, 'test_string' => 'foo', 'test_datetime' => '2010-01-01 10:10:10')); - self::$generated = true; - } + $sm = $this->_conn->getSchemaManager(); + $sm->createTable($table); + + $this->_conn->insert('fetch_table', array('test_int' => 1, 'test_string' => 'foo', 'test_datetime' => '2010-01-01 10:10:10')); + self::$generated = true; } public function testPrepareWithBindValue() { - $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; + $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; $stmt = $this->_conn->prepare($sql); self::assertInstanceOf('Doctrine\DBAL\Statement', $stmt); @@ -60,8 +63,8 @@ public function testPrepareWithBindValue() $stmt->execute(); $row = $stmt->fetch(FetchMode::ASSOCIATIVE); - $row = array_change_key_case($row, \CASE_LOWER); - self::assertEquals(array('test_int' => 1, 'test_string' => 'foo'), $row); + $row = array_change_key_case($row, CASE_LOWER); + self::assertEquals(['test_int' => 1, 'test_string' => 'foo'], $row); } public function testPrepareWithBindParam() @@ -69,7 +72,7 @@ public function testPrepareWithBindParam() $paramInt = 1; $paramStr = 'foo'; - $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; + $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; $stmt = $this->_conn->prepare($sql); self::assertInstanceOf('Doctrine\DBAL\Statement', $stmt); @@ -78,8 +81,8 @@ public function testPrepareWithBindParam() $stmt->execute(); $row = $stmt->fetch(FetchMode::ASSOCIATIVE); - $row = array_change_key_case($row, \CASE_LOWER); - self::assertEquals(array('test_int' => 1, 'test_string' => 'foo'), $row); + $row = array_change_key_case($row, CASE_LOWER); + self::assertEquals(['test_int' => 1, 'test_string' => 'foo'], $row); } public function testPrepareWithFetchAll() @@ -87,7 +90,7 @@ public function testPrepareWithFetchAll() $paramInt = 1; $paramStr = 'foo'; - $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; + $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; $stmt = $this->_conn->prepare($sql); self::assertInstanceOf('Doctrine\DBAL\Statement', $stmt); @@ -96,8 +99,8 @@ public function testPrepareWithFetchAll() $stmt->execute(); $rows = $stmt->fetchAll(FetchMode::ASSOCIATIVE); - $rows[0] = array_change_key_case($rows[0], \CASE_LOWER); - self::assertEquals(array('test_int' => 1, 'test_string' => 'foo'), $rows[0]); + $rows[0] = array_change_key_case($rows[0], CASE_LOWER); + self::assertEquals(['test_int' => 1, 'test_string' => 'foo'], $rows[0]); } /** @@ -108,7 +111,7 @@ public function testPrepareWithFetchAllBoth() $paramInt = 1; $paramStr = 'foo'; - $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; + $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; $stmt = $this->_conn->prepare($sql); self::assertInstanceOf('Doctrine\DBAL\Statement', $stmt); @@ -117,8 +120,8 @@ public function testPrepareWithFetchAllBoth() $stmt->execute(); $rows = $stmt->fetchAll(FetchMode::MIXED); - $rows[0] = array_change_key_case($rows[0], \CASE_LOWER); - self::assertEquals(array('test_int' => 1, 'test_string' => 'foo', 0 => 1, 1 => 'foo'), $rows[0]); + $rows[0] = array_change_key_case($rows[0], CASE_LOWER); + self::assertEquals(['test_int' => 1, 'test_string' => 'foo', 0 => 1, 1 => 'foo'], $rows[0]); } public function testPrepareWithFetchColumn() @@ -126,7 +129,7 @@ public function testPrepareWithFetchColumn() $paramInt = 1; $paramStr = 'foo'; - $sql = "SELECT test_int FROM fetch_table WHERE test_int = ? AND test_string = ?"; + $sql = 'SELECT test_int FROM fetch_table WHERE test_int = ? AND test_string = ?'; $stmt = $this->_conn->prepare($sql); self::assertInstanceOf('Doctrine\DBAL\Statement', $stmt); @@ -143,7 +146,7 @@ public function testPrepareWithIterator() $paramInt = 1; $paramStr = 'foo'; - $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; + $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; $stmt = $this->_conn->prepare($sql); self::assertInstanceOf('Doctrine\DBAL\Statement', $stmt); @@ -151,18 +154,18 @@ public function testPrepareWithIterator() $stmt->bindParam(2, $paramStr); $stmt->execute(); - $rows = array(); + $rows = []; $stmt->setFetchMode(FetchMode::ASSOCIATIVE); foreach ($stmt as $row) { - $rows[] = array_change_key_case($row, \CASE_LOWER); + $rows[] = array_change_key_case($row, CASE_LOWER); } - self::assertEquals(array('test_int' => 1, 'test_string' => 'foo'), $rows[0]); + self::assertEquals(['test_int' => 1, 'test_string' => 'foo'], $rows[0]); } public function testPrepareWithQuoted() { - $table = 'fetch_table'; + $table = 'fetch_table'; $paramInt = 1; $paramStr = 'foo'; @@ -177,20 +180,20 @@ public function testPrepareWithExecuteParams() $paramInt = 1; $paramStr = 'foo'; - $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; + $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; $stmt = $this->_conn->prepare($sql); self::assertInstanceOf('Doctrine\DBAL\Statement', $stmt); - $stmt->execute(array($paramInt, $paramStr)); + $stmt->execute([$paramInt, $paramStr]); $row = $stmt->fetch(FetchMode::ASSOCIATIVE); self::assertNotFalse($row); - $row = array_change_key_case($row, \CASE_LOWER); - self::assertEquals(array('test_int' => 1, 'test_string' => 'foo'), $row); + $row = array_change_key_case($row, CASE_LOWER); + self::assertEquals(['test_int' => 1, 'test_string' => 'foo'], $row); } public function testFetchAll() { - $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; + $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; $data = $this->_conn->fetchAll($sql, array(1, 'foo')); self::assertCount(1, $data); @@ -198,7 +201,7 @@ public function testFetchAll() $row = $data[0]; self::assertCount(2, $row); - $row = array_change_key_case($row, \CASE_LOWER); + $row = array_change_key_case($row, CASE_LOWER); self::assertEquals(1, $row['test_int']); self::assertEquals('foo', $row['test_string']); } @@ -209,7 +212,7 @@ public function testFetchAll() public function testFetchAllWithTypes() { $datetimeString = '2010-01-01 10:10:10'; - $datetime = new \DateTime($datetimeString); + $datetime = new DateTime($datetimeString); $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; $data = $this->_conn->fetchAll($sql, [1, $datetime], [ParameterType::STRING, Type::DATETIME]); @@ -219,7 +222,7 @@ public function testFetchAllWithTypes() $row = $data[0]; self::assertCount(2, $row); - $row = array_change_key_case($row, \CASE_LOWER); + $row = array_change_key_case($row, CASE_LOWER); self::assertEquals(1, $row['test_int']); self::assertStringStartsWith($datetimeString, $row['test_datetime']); } @@ -236,9 +239,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 = ?"; - $data = $this->_conn->fetchAll($sql, array(1, $datetime)); + $datetime = new DateTime($datetimeString); + $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; + $data = $this->_conn->fetchAll($sql, [1, $datetime]); } public function testFetchBoth() @@ -248,7 +251,7 @@ public function testFetchBoth() self::assertNotFalse($row); - $row = array_change_key_case($row, \CASE_LOWER); + $row = array_change_key_case($row, CASE_LOWER); self::assertEquals(1, $row['test_int']); self::assertEquals('foo', $row['test_string']); @@ -265,12 +268,12 @@ public function testFetchNoResult() public function testFetchAssoc() { - $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; + $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; $row = $this->_conn->fetchAssoc($sql, array(1, 'foo')); self::assertNotFalse($row); - $row = array_change_key_case($row, \CASE_LOWER); + $row = array_change_key_case($row, CASE_LOWER); self::assertEquals(1, $row['test_int']); self::assertEquals('foo', $row['test_string']); @@ -279,14 +282,14 @@ public function testFetchAssoc() public function testFetchAssocWithTypes() { $datetimeString = '2010-01-01 10:10:10'; - $datetime = new \DateTime($datetimeString); + $datetime = new DateTime($datetimeString); $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; $row = $this->_conn->fetchAssoc($sql, [1, $datetime], [ParameterType::STRING, Type::DATETIME]); self::assertNotFalse($row); - $row = array_change_key_case($row, \CASE_LOWER); + $row = array_change_key_case($row, CASE_LOWER); self::assertEquals(1, $row['test_int']); self::assertStringStartsWith($datetimeString, $row['test_datetime']); @@ -303,14 +306,14 @@ 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 = ?"; + $datetime = new DateTime($datetimeString); + $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; $row = $this->_conn->fetchAssoc($sql, array(1, $datetime)); } public function testFetchArray() { - $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; + $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; $row = $this->_conn->fetchArray($sql, array(1, 'foo')); self::assertEquals(1, $row[0]); @@ -320,14 +323,14 @@ public function testFetchArray() public function testFetchArrayWithTypes() { $datetimeString = '2010-01-01 10:10:10'; - $datetime = new \DateTime($datetimeString); + $datetime = new DateTime($datetimeString); $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; $row = $this->_conn->fetchArray($sql, [1, $datetime], [ParameterType::STRING, Type::DATETIME]); self::assertNotFalse($row); - $row = array_change_key_case($row, \CASE_LOWER); + $row = array_change_key_case($row, CASE_LOWER); self::assertEquals(1, $row[0]); self::assertStringStartsWith($datetimeString, $row[1]); @@ -344,20 +347,20 @@ 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->_conn->fetchArray($sql, array(1, $datetime)); + $datetime = new DateTime($datetimeString); + $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; + $row = $this->_conn->fetchArray($sql, [1, $datetime]); } public function testFetchColumn() { - $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; - $testInt = $this->_conn->fetchColumn($sql, array(1, 'foo'), 0); + $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; + $testInt = $this->_conn->fetchColumn($sql, [1, 'foo'], 0); self::assertEquals(1, $testInt); - $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; - $testString = $this->_conn->fetchColumn($sql, array(1, 'foo'), 1); + $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; + $testString = $this->_conn->fetchColumn($sql, [1, 'foo'], 1); self::assertEquals('foo', $testString); } @@ -365,7 +368,7 @@ public function testFetchColumn() public function testFetchColumnWithTypes() { $datetimeString = '2010-01-01 10:10:10'; - $datetime = new \DateTime($datetimeString); + $datetime = new DateTime($datetimeString); $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; $column = $this->_conn->fetchColumn($sql, [1, $datetime], 1, [ParameterType::STRING, Type::DATETIME]); @@ -386,9 +389,9 @@ 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->_conn->fetchColumn($sql, array(1, $datetime), 1); + $datetime = new DateTime($datetimeString); + $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; + $column = $this->_conn->fetchColumn($sql, [1, $datetime], 1); } /** @@ -396,10 +399,11 @@ public function testFetchColumnWithMissingTypes() */ public function testExecuteQueryBindDateTimeType() { - $sql = 'SELECT count(*) AS c FROM fetch_table WHERE test_datetime = ?'; - $stmt = $this->_conn->executeQuery($sql, - array(1 => new \DateTime('2010-01-01 10:10:10')), - array(1 => Type::DATETIME) + $sql = 'SELECT count(*) AS c FROM fetch_table WHERE test_datetime = ?'; + $stmt = $this->_conn->executeQuery( + $sql, + [1 => new DateTime('2010-01-01 10:10:10')], + [1 => Type::DATETIME] ); self::assertEquals(1, $stmt->fetchColumn()); @@ -410,9 +414,9 @@ public function testExecuteQueryBindDateTimeType() */ public function testExecuteUpdateBindDateTimeType() { - $datetime = new \DateTime('2010-02-02 20:20:20'); + $datetime = new DateTime('2010-02-02 20:20:20'); - $sql = 'INSERT INTO fetch_table (test_int, test_string, test_datetime) VALUES (?, ?, ?)'; + $sql = 'INSERT INTO fetch_table (test_int, test_string, test_datetime) VALUES (?, ?, ?)'; $affectedRows = $this->_conn->executeUpdate($sql, [ 1 => 50, 2 => 'foo', @@ -426,8 +430,8 @@ public function testExecuteUpdateBindDateTimeType() self::assertEquals(1, $affectedRows); self::assertEquals(1, $this->_conn->executeQuery( 'SELECT count(*) AS c FROM fetch_table WHERE test_datetime = ?', - array(1 => $datetime), - array(1 => Type::DATETIME) + [1 => $datetime], + [1 => Type::DATETIME] )->fetchColumn()); } @@ -436,9 +440,9 @@ public function testExecuteUpdateBindDateTimeType() */ public function testPrepareQueryBindValueDateTimeType() { - $sql = 'SELECT count(*) AS c FROM fetch_table WHERE test_datetime = ?'; + $sql = 'SELECT count(*) AS c FROM fetch_table WHERE test_datetime = ?'; $stmt = $this->_conn->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'), Type::DATETIME); $stmt->execute(); self::assertEquals(1, $stmt->fetchColumn()); @@ -450,22 +454,28 @@ public function testPrepareQueryBindValueDateTimeType() public function testNativeArrayListSupport() { for ($i = 100; $i < 110; $i++) { - $this->_conn->insert('fetch_table', array('test_int' => $i, 'test_string' => 'foo' . $i, 'test_datetime' => '2010-01-01 10:10:10')); + $this->_conn->insert('fetch_table', ['test_int' => $i, 'test_string' => 'foo' . $i, 'test_datetime' => '2010-01-01 10:10:10']); } - $stmt = $this->_conn->executeQuery('SELECT test_int FROM fetch_table WHERE test_int IN (?)', - array(array(100, 101, 102, 103, 104)), array(Connection::PARAM_INT_ARRAY)); + $stmt = $this->_conn->executeQuery( + 'SELECT test_int FROM fetch_table WHERE test_int IN (?)', + [[100, 101, 102, 103, 104]], + [Connection::PARAM_INT_ARRAY] + ); $data = $stmt->fetchAll(FetchMode::NUMERIC); self::assertCount(5, $data); - self::assertEquals(array(array(100), array(101), array(102), array(103), array(104)), $data); + self::assertEquals([[100], [101], [102], [103], [104]], $data); - $stmt = $this->_conn->executeQuery('SELECT test_int FROM fetch_table WHERE test_string IN (?)', - array(array('foo100', 'foo101', 'foo102', 'foo103', 'foo104')), array(Connection::PARAM_STR_ARRAY)); + $stmt = $this->_conn->executeQuery( + 'SELECT test_int FROM fetch_table WHERE test_string IN (?)', + [['foo100', 'foo101', 'foo102', 'foo103', 'foo104']], + [Connection::PARAM_STR_ARRAY] + ); $data = $stmt->fetchAll(FetchMode::NUMERIC); self::assertCount(5, $data); - self::assertEquals(array(array(100), array(101), array(102), array(103), array(104)), $data); + self::assertEquals([[100], [101], [102], [103], [104]], $data); } /** @@ -485,7 +495,7 @@ public function testTrimExpression($value, $position, $char, $expectedResult) public function getTrimExpressionData() { - return array( + return [ ['test_string', TrimMode::UNSPECIFIED, false, 'foo'], ['test_string', TrimMode::LEADING, false, 'foo'], ['test_string', TrimMode::TRAILING, false, 'foo'], @@ -522,7 +532,7 @@ public function getTrimExpressionData() ["' foo '", TrimMode::BOTH, "'o'", ' foo '], ["' foo '", TrimMode::BOTH, "'.'", ' foo '], ["' foo '", TrimMode::BOTH, "' '", 'foo'], - ); + ]; } /** @@ -530,45 +540,45 @@ public function getTrimExpressionData() */ public function testDateArithmetics() { - $p = $this->_conn->getDatabasePlatform(); - $sql = 'SELECT '; - $sql .= $p->getDateAddSecondsExpression('test_datetime', 1) .' AS add_seconds, '; - $sql .= $p->getDateSubSecondsExpression('test_datetime', 1) .' AS sub_seconds, '; - $sql .= $p->getDateAddMinutesExpression('test_datetime', 5) .' AS add_minutes, '; - $sql .= $p->getDateSubMinutesExpression('test_datetime', 5) .' AS sub_minutes, '; - $sql .= $p->getDateAddHourExpression('test_datetime', 3) .' AS add_hour, '; - $sql .= $p->getDateSubHourExpression('test_datetime', 3) .' AS sub_hour, '; - $sql .= $p->getDateAddDaysExpression('test_datetime', 10) .' AS add_days, '; - $sql .= $p->getDateSubDaysExpression('test_datetime', 10) .' AS sub_days, '; - $sql .= $p->getDateAddWeeksExpression('test_datetime', 1) .' AS add_weeks, '; - $sql .= $p->getDateSubWeeksExpression('test_datetime', 1) .' AS sub_weeks, '; - $sql .= $p->getDateAddMonthExpression('test_datetime', 2) .' AS add_month, '; - $sql .= $p->getDateSubMonthExpression('test_datetime', 2) .' AS sub_month, '; - $sql .= $p->getDateAddQuartersExpression('test_datetime', 3) .' AS add_quarters, '; - $sql .= $p->getDateSubQuartersExpression('test_datetime', 3) .' AS sub_quarters, '; - $sql .= $p->getDateAddYearsExpression('test_datetime', 6) .' AS add_years, '; - $sql .= $p->getDateSubYearsExpression('test_datetime', 6) .' AS sub_years '; + $p = $this->_conn->getDatabasePlatform(); + $sql = 'SELECT '; + $sql .= $p->getDateAddSecondsExpression('test_datetime', 1) . ' AS add_seconds, '; + $sql .= $p->getDateSubSecondsExpression('test_datetime', 1) . ' AS sub_seconds, '; + $sql .= $p->getDateAddMinutesExpression('test_datetime', 5) . ' AS add_minutes, '; + $sql .= $p->getDateSubMinutesExpression('test_datetime', 5) . ' AS sub_minutes, '; + $sql .= $p->getDateAddHourExpression('test_datetime', 3) . ' AS add_hour, '; + $sql .= $p->getDateSubHourExpression('test_datetime', 3) . ' AS sub_hour, '; + $sql .= $p->getDateAddDaysExpression('test_datetime', 10) . ' AS add_days, '; + $sql .= $p->getDateSubDaysExpression('test_datetime', 10) . ' AS sub_days, '; + $sql .= $p->getDateAddWeeksExpression('test_datetime', 1) . ' AS add_weeks, '; + $sql .= $p->getDateSubWeeksExpression('test_datetime', 1) . ' AS sub_weeks, '; + $sql .= $p->getDateAddMonthExpression('test_datetime', 2) . ' AS add_month, '; + $sql .= $p->getDateSubMonthExpression('test_datetime', 2) . ' AS sub_month, '; + $sql .= $p->getDateAddQuartersExpression('test_datetime', 3) . ' AS add_quarters, '; + $sql .= $p->getDateSubQuartersExpression('test_datetime', 3) . ' AS sub_quarters, '; + $sql .= $p->getDateAddYearsExpression('test_datetime', 6) . ' AS add_years, '; + $sql .= $p->getDateSubYearsExpression('test_datetime', 6) . ' AS sub_years '; $sql .= 'FROM fetch_table'; $row = $this->_conn->fetchAssoc($sql); $row = array_change_key_case($row, CASE_LOWER); - self::assertEquals('2010-01-01 10:10:11', date('Y-m-d H:i:s', strtotime($row['add_seconds'])), "Adding second should end up on 2010-01-01 10:10:11"); - self::assertEquals('2010-01-01 10:10:09', date('Y-m-d H:i:s', strtotime($row['sub_seconds'])), "Subtracting second should end up on 2010-01-01 10:10:09"); - self::assertEquals('2010-01-01 10:15:10', date('Y-m-d H:i:s', strtotime($row['add_minutes'])), "Adding minutes should end up on 2010-01-01 10:15:10"); - self::assertEquals('2010-01-01 10:05:10', date('Y-m-d H:i:s', strtotime($row['sub_minutes'])), "Subtracting minutes should end up on 2010-01-01 10:05:10"); - self::assertEquals('2010-01-01 13:10', date('Y-m-d H:i', strtotime($row['add_hour'])), "Adding date should end up on 2010-01-01 13:10"); - self::assertEquals('2010-01-01 07:10', date('Y-m-d H:i', strtotime($row['sub_hour'])), "Subtracting date should end up on 2010-01-01 07:10"); - self::assertEquals('2010-01-11', date('Y-m-d', strtotime($row['add_days'])), "Adding date should end up on 2010-01-11"); - self::assertEquals('2009-12-22', date('Y-m-d', strtotime($row['sub_days'])), "Subtracting date should end up on 2009-12-22"); - self::assertEquals('2010-01-08', date('Y-m-d', strtotime($row['add_weeks'])), "Adding week should end up on 2010-01-08"); - self::assertEquals('2009-12-25', date('Y-m-d', strtotime($row['sub_weeks'])), "Subtracting week should end up on 2009-12-25"); - self::assertEquals('2010-03-01', date('Y-m-d', strtotime($row['add_month'])), "Adding month should end up on 2010-03-01"); - self::assertEquals('2009-11-01', date('Y-m-d', strtotime($row['sub_month'])), "Subtracting month should end up on 2009-11-01"); - self::assertEquals('2010-10-01', date('Y-m-d', strtotime($row['add_quarters'])), "Adding quarters should end up on 2010-04-01"); - self::assertEquals('2009-04-01', date('Y-m-d', strtotime($row['sub_quarters'])), "Subtracting quarters should end up on 2009-10-01"); - self::assertEquals('2016-01-01', date('Y-m-d', strtotime($row['add_years'])), "Adding years should end up on 2016-01-01"); - self::assertEquals('2004-01-01', date('Y-m-d', strtotime($row['sub_years'])), "Subtracting years should end up on 2004-01-01"); + self::assertEquals('2010-01-01 10:10:11', date('Y-m-d H:i:s', strtotime($row['add_seconds'])), 'Adding second should end up on 2010-01-01 10:10:11'); + self::assertEquals('2010-01-01 10:10:09', date('Y-m-d H:i:s', strtotime($row['sub_seconds'])), 'Subtracting second should end up on 2010-01-01 10:10:09'); + self::assertEquals('2010-01-01 10:15:10', date('Y-m-d H:i:s', strtotime($row['add_minutes'])), 'Adding minutes should end up on 2010-01-01 10:15:10'); + self::assertEquals('2010-01-01 10:05:10', date('Y-m-d H:i:s', strtotime($row['sub_minutes'])), 'Subtracting minutes should end up on 2010-01-01 10:05:10'); + self::assertEquals('2010-01-01 13:10', date('Y-m-d H:i', strtotime($row['add_hour'])), 'Adding date should end up on 2010-01-01 13:10'); + self::assertEquals('2010-01-01 07:10', date('Y-m-d H:i', strtotime($row['sub_hour'])), 'Subtracting date should end up on 2010-01-01 07:10'); + self::assertEquals('2010-01-11', date('Y-m-d', strtotime($row['add_days'])), 'Adding date should end up on 2010-01-11'); + self::assertEquals('2009-12-22', date('Y-m-d', strtotime($row['sub_days'])), 'Subtracting date should end up on 2009-12-22'); + self::assertEquals('2010-01-08', date('Y-m-d', strtotime($row['add_weeks'])), 'Adding week should end up on 2010-01-08'); + self::assertEquals('2009-12-25', date('Y-m-d', strtotime($row['sub_weeks'])), 'Subtracting week should end up on 2009-12-25'); + self::assertEquals('2010-03-01', date('Y-m-d', strtotime($row['add_month'])), 'Adding month should end up on 2010-03-01'); + self::assertEquals('2009-11-01', date('Y-m-d', strtotime($row['sub_month'])), 'Subtracting month should end up on 2009-11-01'); + self::assertEquals('2010-10-01', date('Y-m-d', strtotime($row['add_quarters'])), 'Adding quarters should end up on 2010-04-01'); + self::assertEquals('2009-04-01', date('Y-m-d', strtotime($row['sub_quarters'])), 'Subtracting quarters should end up on 2009-10-01'); + self::assertEquals('2016-01-01', date('Y-m-d', strtotime($row['add_years'])), 'Adding years should end up on 2016-01-01'); + 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() @@ -584,7 +594,7 @@ public function testSqliteDateArithmeticWithDynamicInterval() $table->addColumn('test_days', 'integer'); $table->setPrimaryKey(['test_date']); - /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ + /** @var AbstractSchemaManager $sm */ $sm = $this->_conn->getSchemaManager(); $sm->createTable($table); @@ -603,16 +613,16 @@ public function testLocateExpression() { $platform = $this->_conn->getDatabasePlatform(); - $sql = 'SELECT '; - $sql .= $platform->getLocateExpression('test_string', "'oo'") .' AS locate1, '; - $sql .= $platform->getLocateExpression('test_string', "'foo'") .' AS locate2, '; - $sql .= $platform->getLocateExpression('test_string', "'bar'") .' AS locate3, '; - $sql .= $platform->getLocateExpression('test_string', 'test_string') .' AS locate4, '; - $sql .= $platform->getLocateExpression("'foo'", 'test_string') .' AS locate5, '; - $sql .= $platform->getLocateExpression("'barfoobaz'", 'test_string') .' AS locate6, '; - $sql .= $platform->getLocateExpression("'bar'", 'test_string') .' AS locate7, '; - $sql .= $platform->getLocateExpression('test_string', "'oo'", 2) .' AS locate8, '; - $sql .= $platform->getLocateExpression('test_string', "'oo'", 3) .' AS locate9 '; + $sql = 'SELECT '; + $sql .= $platform->getLocateExpression('test_string', "'oo'") . ' AS locate1, '; + $sql .= $platform->getLocateExpression('test_string', "'foo'") . ' AS locate2, '; + $sql .= $platform->getLocateExpression('test_string', "'bar'") . ' AS locate3, '; + $sql .= $platform->getLocateExpression('test_string', 'test_string') . ' AS locate4, '; + $sql .= $platform->getLocateExpression("'foo'", 'test_string') . ' AS locate5, '; + $sql .= $platform->getLocateExpression("'barfoobaz'", 'test_string') . ' AS locate6, '; + $sql .= $platform->getLocateExpression("'bar'", 'test_string') . ' AS locate7, '; + $sql .= $platform->getLocateExpression('test_string', "'oo'", 2) . ' AS locate8, '; + $sql .= $platform->getLocateExpression('test_string', "'oo'", 3) . ' AS locate9 '; $sql .= 'FROM fetch_table'; $row = $this->_conn->fetchAssoc($sql); @@ -631,10 +641,10 @@ public function testLocateExpression() public function testQuoteSQLInjection() { - $sql = "SELECT * FROM fetch_table WHERE test_string = " . $this->_conn->quote("bar' OR '1'='1"); + $sql = 'SELECT * FROM fetch_table WHERE test_string = ' . $this->_conn->quote("bar' OR '1'='1"); $rows = $this->_conn->fetchAll($sql); - self::assertCount(0, $rows, "no result should be returned, otherwise SQL injection is possible"); + self::assertCount(0, $rows, 'no result should be returned, otherwise SQL injection is possible'); } /** @@ -644,31 +654,30 @@ public function testBitComparisonExpressionSupport() { $this->_conn->exec('DELETE FROM fetch_table'); $platform = $this->_conn->getDatabasePlatform(); - $bitmap = array(); + $bitmap = []; - for ($i = 2; $i < 9; $i = $i + 2) { - $bitmap[$i] = array( + for ($i = 2; $i < 9; $i += 2) { + $bitmap[$i] = [ 'bit_or' => ($i | 2), - 'bit_and' => ($i & 2) - ); - $this->_conn->insert('fetch_table', array( + 'bit_and' => ($i & 2), + ]; + $this->_conn->insert('fetch_table', [ 'test_int' => $i, 'test_string' => json_encode($bitmap[$i]), - 'test_datetime' => '2010-01-01 10:10:10' - )); + 'test_datetime' => '2010-01-01 10:10:10', + ]); } - $sql[] = 'SELECT '; - $sql[] = 'test_int, '; - $sql[] = 'test_string, '; - $sql[] = $platform->getBitOrComparisonExpression('test_int', 2) . ' AS bit_or, '; - $sql[] = $platform->getBitAndComparisonExpression('test_int', 2) . ' AS bit_and '; - $sql[] = 'FROM fetch_table'; + $sql[] = 'SELECT '; + $sql[] = 'test_int, '; + $sql[] = 'test_string, '; + $sql[] = $platform->getBitOrComparisonExpression('test_int', 2) . ' AS bit_or, '; + $sql[] = $platform->getBitAndComparisonExpression('test_int', 2) . ' AS bit_and '; + $sql[] = 'FROM fetch_table'; $stmt = $this->_conn->executeQuery(implode(PHP_EOL, $sql)); $data = $stmt->fetchAll(FetchMode::ASSOCIATIVE); - self::assertCount(4, $data); self::assertEquals(count($bitmap), count($data)); foreach ($data as $row) { @@ -691,11 +700,13 @@ public function testBitComparisonExpressionSupport() public function testSetDefaultFetchMode() { - $stmt = $this->_conn->query("SELECT * FROM fetch_table"); + $stmt = $this->_conn->query('SELECT * FROM fetch_table'); $stmt->setFetchMode(FetchMode::NUMERIC); $row = array_keys($stmt->fetch()); - self::assertCount(0, array_filter($row, function($v) { return ! is_numeric($v); }), "should be no non-numerical elements in the result."); + self::assertCount(0, array_filter($row, static function ($v) { + return ! is_numeric($v); + }), 'should be no non-numerical elements in the result.'); } /** @@ -705,7 +716,7 @@ public function testFetchAllStyleObject() { $this->setupFixture(); - $sql = 'SELECT test_int, test_string, test_datetime FROM fetch_table'; + $sql = 'SELECT test_int, test_string, test_datetime FROM fetch_table'; $stmt = $this->_conn->prepare($sql); $stmt->execute(); @@ -737,17 +748,17 @@ public function testFetchAllSupportFetchClass() $this->skipOci8AndMysqli(); $this->setupFixture(); - $sql = "SELECT test_int, test_string, test_datetime FROM fetch_table"; - $stmt = $this->_conn->prepare($sql); + $sql = 'SELECT test_int, test_string, test_datetime FROM fetch_table'; + $stmt = $this->_conn->prepare($sql); $stmt->execute(); $results = $stmt->fetchAll( FetchMode::CUSTOM_OBJECT, - __NAMESPACE__.'\\MyFetchClass' + __NAMESPACE__ . '\\MyFetchClass' ); self::assertCount(1, $results); - self::assertInstanceOf(__NAMESPACE__.'\\MyFetchClass', $results[0]); + self::assertInstanceOf(__NAMESPACE__ . '\\MyFetchClass', $results[0]); self::assertEquals(1, $results[0]->test_int); self::assertEquals('foo', $results[0]->test_string); @@ -759,16 +770,16 @@ public function testFetchAllSupportFetchClass() */ public function testFetchAllStyleColumn() { - $sql = "DELETE FROM fetch_table"; + $sql = 'DELETE FROM fetch_table'; $this->_conn->executeUpdate($sql); - $this->_conn->insert('fetch_table', array('test_int' => 1, 'test_string' => 'foo')); - $this->_conn->insert('fetch_table', array('test_int' => 10, 'test_string' => 'foo')); + $this->_conn->insert('fetch_table', ['test_int' => 1, 'test_string' => 'foo']); + $this->_conn->insert('fetch_table', ['test_int' => 10, 'test_string' => 'foo']); - $sql = "SELECT test_int FROM fetch_table"; + $sql = 'SELECT test_int FROM fetch_table'; $rows = $this->_conn->query($sql)->fetchAll(FetchMode::COLUMN); - self::assertEquals(array(1, 10), $rows); + self::assertEquals([1, 10], $rows); } /** @@ -779,14 +790,14 @@ public function testSetFetchModeClassFetchAll() $this->skipOci8AndMysqli(); $this->setupFixture(); - $sql = "SELECT * FROM fetch_table"; + $sql = 'SELECT * FROM fetch_table'; $stmt = $this->_conn->query($sql); $stmt->setFetchMode(FetchMode::CUSTOM_OBJECT, __NAMESPACE__ . '\\MyFetchClass'); $results = $stmt->fetchAll(); self::assertCount(1, $results); - self::assertInstanceOf(__NAMESPACE__.'\\MyFetchClass', $results[0]); + self::assertInstanceOf(__NAMESPACE__ . '\\MyFetchClass', $results[0]); self::assertEquals(1, $results[0]->test_int); self::assertEquals('foo', $results[0]->test_string); @@ -801,17 +812,17 @@ public function testSetFetchModeClassFetch() $this->skipOci8AndMysqli(); $this->setupFixture(); - $sql = "SELECT * FROM fetch_table"; + $sql = 'SELECT * FROM fetch_table'; $stmt = $this->_conn->query($sql); $stmt->setFetchMode(FetchMode::CUSTOM_OBJECT, __NAMESPACE__ . '\\MyFetchClass'); - $results = array(); + $results = []; while ($row = $stmt->fetch()) { $results[] = $row; } self::assertCount(1, $results); - self::assertInstanceOf(__NAMESPACE__.'\\MyFetchClass', $results[0]); + self::assertInstanceOf(__NAMESPACE__ . '\\MyFetchClass', $results[0]); self::assertEquals(1, $results[0]->test_int); self::assertEquals('foo', $results[0]->test_string); @@ -835,8 +846,8 @@ public function testEmptyFetchColumnReturnsFalse() */ public function testSetFetchModeOnDbalStatement() { - $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; - $stmt = $this->_conn->executeQuery($sql, array(1, "foo")); + $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; + $stmt = $this->_conn->executeQuery($sql, [1, 'foo']); $stmt->setFetchMode(FetchMode::NUMERIC); $row = $stmt->fetch(); @@ -851,11 +862,11 @@ public function testSetFetchModeOnDbalStatement() */ public function testEmptyParameters() { - $sql = "SELECT * FROM fetch_table WHERE test_int IN (?)"; - $stmt = $this->_conn->executeQuery($sql, array(array()), array(\Doctrine\DBAL\Connection::PARAM_INT_ARRAY)); + $sql = 'SELECT * FROM fetch_table WHERE test_int IN (?)'; + $stmt = $this->_conn->executeQuery($sql, [[]], [Connection::PARAM_INT_ARRAY]); $rows = $stmt->fetchAll(); - self::assertEquals(array(), $rows); + self::assertEquals([], $rows); } /** @@ -865,11 +876,11 @@ public function testFetchColumnNullValue() { $this->_conn->executeUpdate( 'INSERT INTO fetch_table (test_int, test_string) VALUES (?, ?)', - array(2, 'foo') + [2, 'foo'] ); self::assertNull( - $this->_conn->fetchColumn('SELECT test_datetime FROM fetch_table WHERE test_int = ?', array(2)) + $this->_conn->fetchColumn('SELECT test_datetime FROM fetch_table WHERE test_int = ?', [2]) ); } @@ -885,7 +896,7 @@ public function testFetchColumnNonExistingIndex() } self::assertNull( - $this->_conn->fetchColumn('SELECT test_int FROM fetch_table WHERE test_int = ?', array(1), 1) + $this->_conn->fetchColumn('SELECT test_int FROM fetch_table WHERE test_int = ?', [1], 1) ); } @@ -895,28 +906,30 @@ public function testFetchColumnNonExistingIndex() public function testFetchColumnNoResult() { self::assertFalse( - $this->_conn->fetchColumn('SELECT test_int FROM fetch_table WHERE test_int = ?', array(-1)) + $this->_conn->fetchColumn('SELECT test_int FROM fetch_table WHERE test_int = ?', [-1]) ); } private function setupFixture() { $this->_conn->exec('DELETE FROM fetch_table'); - $this->_conn->insert('fetch_table', array( + $this->_conn->insert('fetch_table', [ 'test_int' => 1, 'test_string' => 'foo', - 'test_datetime' => '2010-01-01 10:10:10' - )); + 'test_datetime' => '2010-01-01 10:10:10', + ]); } private function skipOci8AndMysqli() { - if (isset($GLOBALS['db_type']) && $GLOBALS['db_type'] == "oci8") { - $this->markTestSkipped("Not supported by OCI8"); + if (isset($GLOBALS['db_type']) && $GLOBALS['db_type'] === 'oci8') { + $this->markTestSkipped('Not supported by OCI8'); } - if ('mysqli' == $this->_conn->getDriver()->getName()) { - $this->markTestSkipped('Mysqli driver dont support this feature.'); + if ($this->_conn->getDriver()->getName() !== 'mysqli') { + return; } + + $this->markTestSkipped('Mysqli driver dont support this feature.'); } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php index 4857e81a5e1..a013a7706a8 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\DBAL\Functional\Driver; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver; use Doctrine\Tests\DbalFunctionalTestCase; abstract class AbstractDriverTest extends DbalFunctionalTestCase @@ -10,7 +11,7 @@ abstract class AbstractDriverTest extends DbalFunctionalTestCase /** * The driver instance under test. * - * @var \Doctrine\DBAL\Driver + * @var Driver */ protected $driver; @@ -29,7 +30,7 @@ public function testConnectsWithoutDatabaseNameParameter() $params = $this->_conn->getParams(); unset($params['dbname']); - $user = $params['user'] ?? null; + $user = $params['user'] ?? null; $password = $params['password'] ?? null; $connection = $this->driver->connect($params, $user, $password); @@ -59,7 +60,7 @@ public function testReturnsDatabaseNameWithoutDatabaseNameParameter() } /** - * @return \Doctrine\DBAL\Driver + * @return Driver */ abstract protected function createDriver(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2DriverTest.php index 4bcc5b6cf76..cb39d81135c 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2DriverTest.php @@ -16,9 +16,11 @@ protected function setUp() parent::setUp(); - if (! $this->_conn->getDriver() instanceof DB2Driver) { - $this->markTestSkipped('ibm_db2 only test.'); + if ($this->_conn->getDriver() instanceof DB2Driver) { + return; } + + $this->markTestSkipped('ibm_db2 only test.'); } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2StatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2StatementTest.php index 59b42a75635..13226c32613 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2StatementTest.php @@ -13,15 +13,17 @@ class DB2StatementTest extends DbalFunctionalTestCase { protected function setUp() { - if ( ! extension_loaded('ibm_db2')) { + if (! extension_loaded('ibm_db2')) { $this->markTestSkipped('ibm_db2 is not installed.'); } parent::setUp(); - if ( ! $this->_conn->getDriver() instanceof DB2Driver) { - $this->markTestSkipped('ibm_db2 only test.'); + if ($this->_conn->getDriver() instanceof DB2Driver) { + return; } + + $this->markTestSkipped('ibm_db2 only test.'); } public function testExecutionErrorsAreNotSuppressed() diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php index c20533a4700..591fff5a13e 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php @@ -1,20 +1,28 @@ markTestSkipped('mysqli is not installed.'); } parent::setUp(); - if ( !($this->_conn->getDriver() instanceof \Doctrine\DBAL\Driver\Mysqli\Driver)) { - $this->markTestSkipped('MySQLi only test.'); + if ($this->_conn->getDriver() instanceof Driver) { + return; } + + $this->markTestSkipped('MySQLi only test.'); } protected function tearDown() @@ -24,12 +32,10 @@ protected function tearDown() public function testDriverOptions() { - $driverOptions = array( - \MYSQLI_OPT_CONNECT_TIMEOUT => 1, - ); + $driverOptions = [MYSQLI_OPT_CONNECT_TIMEOUT => 1]; $connection = $this->getConnection($driverOptions); - self::assertInstanceOf("\Doctrine\DBAL\Driver\Mysqli\MysqliConnection", $connection); + self::assertInstanceOf('\Doctrine\DBAL\Driver\Mysqli\MysqliConnection', $connection); } /** @@ -37,22 +43,22 @@ public function testDriverOptions() */ public function testUnsupportedDriverOption() { - $this->getConnection(array('hello' => 'world')); // use local infile + $this->getConnection(['hello' => 'world']); // use local infile } public function testPing() { - $conn = $this->getConnection(array()); + $conn = $this->getConnection([]); self::assertTrue($conn->ping()); } private function getConnection(array $driverOptions) { - return new \Doctrine\DBAL\Driver\Mysqli\MysqliConnection( - array( - 'host' => $GLOBALS['db_host'], - 'dbname' => $GLOBALS['db_name'], - ), + return new MysqliConnection( + [ + 'host' => $GLOBALS['db_host'], + 'dbname' => $GLOBALS['db_name'], + ], $GLOBALS['db_username'], $GLOBALS['db_password'], $driverOptions diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/DriverTest.php index d88265d4aa3..da9ee0b5e5b 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/DriverTest.php @@ -16,9 +16,11 @@ protected function setUp() parent::setUp(); - if (! $this->_conn->getDriver() instanceof Driver) { - $this->markTestSkipped('MySQLi only test.'); + if ($this->_conn->getDriver() instanceof Driver) { + return; } + + $this->markTestSkipped('MySQLi only test.'); } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/DriverTest.php index 8a08d24f051..a5776b75c68 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/DriverTest.php @@ -16,9 +16,11 @@ protected function setUp() parent::setUp(); - if (! $this->_conn->getDriver() instanceof Driver) { - $this->markTestSkipped('oci8 only test.'); + if ($this->_conn->getDriver() instanceof Driver) { + return; } + + $this->markTestSkipped('oci8 only test.'); } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/OCI8ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/OCI8ConnectionTest.php index 90430e92a02..cba1041129e 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/OCI8ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/OCI8ConnectionTest.php @@ -3,15 +3,14 @@ namespace Doctrine\Tests\DBAL\Functional\Driver\OCI8; use Doctrine\DBAL\Driver\OCI8\Driver; +use Doctrine\DBAL\Driver\OCI8\OCI8Connection; use Doctrine\DBAL\Schema\Table; use Doctrine\Tests\DbalFunctionalTestCase; use function extension_loaded; class OCI8ConnectionTest extends DbalFunctionalTestCase { - /** - * @var \Doctrine\DBAL\Driver\OCI8\OCI8Connection - */ + /** @var OCI8Connection */ protected $driverConnection; protected function setUp() @@ -34,18 +33,18 @@ protected function setUp() */ public function testLastInsertIdAcceptsFqn() { - $platform = $this->_conn->getDatabasePlatform(); + $platform = $this->_conn->getDatabasePlatform(); $schemaManager = $this->_conn->getSchemaManager(); $table = new Table('DBAL2595'); - $table->addColumn('id', 'integer', array('autoincrement' => true)); + $table->addColumn('id', 'integer', ['autoincrement' => true]); $table->addColumn('foo', 'integer'); $schemaManager->dropAndCreateTable($table); $this->_conn->executeUpdate('INSERT INTO DBAL2595 (foo) VALUES (1)'); - $schema = $this->_conn->getDatabase(); + $schema = $this->_conn->getDatabase(); $sequence = $platform->getIdentitySequenceName($schema . '.DBAL2595', 'id'); self::assertSame(1, $this->driverConnection->lastInsertId($sequence)); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/StatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/StatementTest.php index 5cbaa9c137c..f9ddce6f11c 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/StatementTest.php @@ -16,9 +16,11 @@ protected function setUp() parent::setUp(); - if (! $this->_conn->getDriver() instanceof Driver) { - $this->markTestSkipped('oci8 only test.'); + if ($this->_conn->getDriver() instanceof Driver) { + return; } + + $this->markTestSkipped('oci8 only test.'); } /** @@ -34,53 +36,47 @@ public function testQueryConversion($query, array $params, array $expected) public static function queryConversionProvider() { - return array( - 'simple' => array( + return [ + 'simple' => [ 'SELECT ? COL1 FROM DUAL', - array(1), - array( - 'COL1' => 1, - ), - ), - 'literal-with-placeholder' => array( + [1], + ['COL1' => 1], + ], + 'literal-with-placeholder' => [ "SELECT '?' COL1, ? COL2 FROM DUAL", - array(2), - array( + [2], + [ 'COL1' => '?', 'COL2' => 2, - ), - ), - 'literal-with-quotes' => array( + ], + ], + 'literal-with-quotes' => [ "SELECT ? COL1, '?\"?''?' \"COL?\" FROM DUAL", - array(3), - array( + [3], + [ 'COL1' => 3, 'COL?' => '?"?\'?', - ), - ), - 'placeholder-at-the-end' => array( + ], + ], + 'placeholder-at-the-end' => [ 'SELECT ? COL1 FROM DUAL WHERE 1 = ?', - array(4, 1), - array( - 'COL1' => 4, - ), - ), - 'multi-line-literal' => array( + [4, 1], + ['COL1' => 4], + ], + 'multi-line-literal' => [ "SELECT 'Hello, World?!' COL1 FROM DUAL WHERE 1 = ?", - array(1), - array( + [1], + [ 'COL1' => 'Hello, World?!', - ), - ), - 'empty-literal' => array( + ], + ], + 'empty-literal' => [ "SELECT '' COL1 FROM DUAL", - array(), - array( - 'COL1' => '', - ), - ), - ); + [], + ['COL1' => ''], + ], + ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php index 29f18f8c78f..b5eebb92da3 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php @@ -4,6 +4,7 @@ use Doctrine\DBAL\Driver\PDOConnection; use Doctrine\Tests\DbalFunctionalTestCase; +use PDO; use function extension_loaded; use function sprintf; @@ -12,13 +13,13 @@ class PDOConnectionTest extends DbalFunctionalTestCase /** * The PDO driver connection under test. * - * @var \Doctrine\DBAL\Driver\PDOConnection + * @var PDOConnection */ protected $driverConnection; protected function setUp() { - if ( ! extension_loaded('PDO')) { + if (! extension_loaded('PDO')) { $this->markTestSkipped('PDO is not installed.'); } @@ -26,9 +27,11 @@ protected function setUp() $this->driverConnection = $this->_conn->getWrappedConnection(); - if ( ! $this->driverConnection instanceof PDOConnection) { - $this->markTestSkipped('PDO connection only test.'); + if ($this->driverConnection instanceof PDOConnection) { + return; } + + $this->markTestSkipped('PDO connection only test.'); } protected function tearDown() @@ -53,7 +56,6 @@ public function testThrowsWrappedExceptionOnConstruct() /** * @group DBAL-1022 - * * @expectedException \Doctrine\DBAL\Driver\PDOException */ public function testThrowsWrappedExceptionOnExec() @@ -72,7 +74,7 @@ public function testThrowsWrappedExceptionOnPrepare() // 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); + $this->driverConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $this->driverConnection->prepare('foo'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOMySql/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOMySql/DriverTest.php index 299fd4798e4..462f5941fa2 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOMySql/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOMySql/DriverTest.php @@ -16,9 +16,11 @@ protected function setUp() parent::setUp(); - if (! $this->_conn->getDriver() instanceof Driver) { - $this->markTestSkipped('pdo_mysql only test.'); + if ($this->_conn->getDriver() instanceof Driver) { + return; } + + $this->markTestSkipped('pdo_mysql only test.'); } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOOracle/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOOracle/DriverTest.php index afbdc08c7e8..0fcba6d6431 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOOracle/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOOracle/DriverTest.php @@ -16,9 +16,11 @@ protected function setUp() parent::setUp(); - if (! $this->_conn->getDriver() instanceof Driver) { - $this->markTestSkipped('PDO_OCI only test.'); + if ($this->_conn->getDriver() instanceof Driver) { + return; } + + $this->markTestSkipped('PDO_OCI only test.'); } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgSql/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgSql/DriverTest.php index 04be88079ec..7c595c9c7df 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgSql/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgSql/DriverTest.php @@ -21,9 +21,11 @@ protected function setUp() parent::setUp(); - if (! $this->_conn->getDriver() instanceof Driver) { - $this->markTestSkipped('pdo_pgsql only test.'); + if ($this->_conn->getDriver() instanceof Driver) { + return; } + + $this->markTestSkipped('pdo_pgsql only test.'); } /** @@ -31,8 +33,8 @@ protected function setUp() */ public function testDatabaseParameters($databaseName, $defaultDatabaseName, $expectedDatabaseName) { - $params = $this->_conn->getParams(); - $params['dbname'] = $databaseName; + $params = $this->_conn->getParams(); + $params['dbname'] = $databaseName; $params['default_dbname'] = $defaultDatabaseName; $connection = new Connection( @@ -50,17 +52,17 @@ public function testDatabaseParameters($databaseName, $defaultDatabaseName, $exp public function getDatabaseParameter() { - $params = TestUtil::getConnection()->getParams(); - $realDatabaseName = $params['dbname'] ?? ''; + $params = TestUtil::getConnection()->getParams(); + $realDatabaseName = $params['dbname'] ?? ''; $dummyDatabaseName = $realDatabaseName . 'a'; - return array( + return [ // dbname, default_dbname, expected - array($realDatabaseName, null, $realDatabaseName), - array($realDatabaseName, $dummyDatabaseName, $realDatabaseName), - array(null, $realDatabaseName, $realDatabaseName), - array(null, null, $this->getDatabaseNameForConnectionWithoutDatabaseNameParameter()), - ); + [$realDatabaseName, null, $realDatabaseName], + [$realDatabaseName, $dummyDatabaseName, $realDatabaseName], + [null, $realDatabaseName, $realDatabaseName], + [null, null, $this->getDatabaseNameForConnectionWithoutDatabaseNameParameter()], + ]; } /** @@ -68,18 +70,18 @@ public function getDatabaseParameter() */ public function testConnectsWithApplicationNameParameter() { - $parameters = $this->_conn->getParams(); + $parameters = $this->_conn->getParams(); $parameters['application_name'] = 'doctrine'; - $user = $parameters['user'] ?? null; + $user = $parameters['user'] ?? null; $password = $parameters['password'] ?? null; $connection = $this->driver->connect($parameters, $user, $password); - $hash = microtime(true); // required to identify the record in the results uniquely - $sql = sprintf('SELECT * FROM pg_stat_activity WHERE %d = %d', $hash, $hash); + $hash = microtime(true); // required to identify the record in the results uniquely + $sql = sprintf('SELECT * FROM pg_stat_activity WHERE %d = %d', $hash, $hash); $statement = $connection->query($sql); - $records = $statement->fetchAll(); + $records = $statement->fetchAll(); foreach ($records as $record) { // The query column is named "current_query" on PostgreSQL < 9.2 diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgsqlConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgsqlConnectionTest.php index 52c7cda4efa..16021c3ea24 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgsqlConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgsqlConnectionTest.php @@ -12,28 +12,29 @@ class PDOPgsqlConnectionTest extends DbalFunctionalTestCase { protected function setUp() { - if ( ! extension_loaded('pdo_pgsql')) { + if (! extension_loaded('pdo_pgsql')) { $this->markTestSkipped('pdo_pgsql is not loaded.'); } parent::setUp(); - if ( ! $this->_conn->getDatabasePlatform() instanceof PostgreSqlPlatform) { - $this->markTestSkipped('PDOPgsql only test.'); + if ($this->_conn->getDatabasePlatform() instanceof PostgreSqlPlatform) { + return; } + + $this->markTestSkipped('PDOPgsql only test.'); } /** + * @param string $charset + * * @group DBAL-1183 * @group DBAL-1189 - * * @dataProvider getValidCharsets - * - * @param string $charset */ public function testConnectsWithValidCharsetOption($charset) { - $params = $this->_conn->getParams(); + $params = $this->_conn->getParams(); $params['charset'] = $charset; $connection = DriverManager::getConnection( @@ -54,9 +55,9 @@ public function testConnectsWithValidCharsetOption($charset) */ public function getValidCharsets() { - return array( - array("UTF8"), - array("LATIN1") - ); + return [ + ['UTF8'], + ['LATIN1'], + ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlite/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlite/DriverTest.php index d292db1583c..e6ad8639552 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlite/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlite/DriverTest.php @@ -16,9 +16,11 @@ protected function setUp() parent::setUp(); - if (! $this->_conn->getDriver() instanceof Driver) { - $this->markTestSkipped('pdo_sqlite only test.'); + if ($this->_conn->getDriver() instanceof Driver) { + return; } + + $this->markTestSkipped('pdo_sqlite only test.'); } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php index 88c87d7e08b..e9d224f8e0f 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php @@ -2,7 +2,7 @@ namespace Doctrine\Tests\DBAL\Functional\Driver\PDOSqlsrv; -use Doctrine\DBAL\Driver\Connection as Connection; +use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\Driver\PDOSqlsrv\Driver; use Doctrine\Tests\DBAL\Functional\Driver\AbstractDriverTest; use PDO; diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/ConnectionTest.php index 9f62612ca3b..d94fb91df7d 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/ConnectionTest.php @@ -4,9 +4,10 @@ use Doctrine\DBAL\Driver\SQLAnywhere\Driver; use Doctrine\DBAL\DriverManager; +use Doctrine\Tests\DbalFunctionalTestCase; use function extension_loaded; -class ConnectionTest extends \Doctrine\Tests\DbalFunctionalTestCase +class ConnectionTest extends DbalFunctionalTestCase { protected function setUp() { @@ -16,14 +17,16 @@ protected function setUp() parent::setUp(); - if (! $this->_conn->getDriver() instanceof Driver) { - $this->markTestSkipped('sqlanywhere only test.'); + if ($this->_conn->getDriver() instanceof Driver) { + return; } + + $this->markTestSkipped('sqlanywhere only test.'); } public function testNonPersistentConnection() { - $params = $this->_conn->getParams(); + $params = $this->_conn->getParams(); $params['persistent'] = false; $conn = DriverManager::getConnection($params); @@ -35,7 +38,7 @@ public function testNonPersistentConnection() public function testPersistentConnection() { - $params = $this->_conn->getParams(); + $params = $this->_conn->getParams(); $params['persistent'] = true; $conn = DriverManager::getConnection($params); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/DriverTest.php index 172b6479e94..1dbe8eebee7 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/DriverTest.php @@ -17,9 +17,11 @@ protected function setUp() parent::setUp(); - if (! $this->_conn->getDriver() instanceof Driver) { - $this->markTestSkipped('sqlanywhere only test.'); + if ($this->_conn->getDriver() instanceof Driver) { + return; } + + $this->markTestSkipped('sqlanywhere only test.'); } public function testReturnsDatabaseNameWithoutDatabaseNameParameter() diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/StatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/StatementTest.php index 4fbc16acf27..1e2debe949f 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/StatementTest.php @@ -4,9 +4,10 @@ use Doctrine\DBAL\Driver\SQLAnywhere\Driver; use Doctrine\DBAL\DriverManager; +use Doctrine\Tests\DbalFunctionalTestCase; use function extension_loaded; -class StatementTest extends \Doctrine\Tests\DbalFunctionalTestCase +class StatementTest extends DbalFunctionalTestCase { protected function setUp() { @@ -16,39 +17,40 @@ protected function setUp() parent::setUp(); - if (! $this->_conn->getDriver() instanceof Driver) { - $this->markTestSkipped('sqlanywhere only test.'); + if ($this->_conn->getDriver() instanceof Driver) { + return; } + + $this->markTestSkipped('sqlanywhere only test.'); } public function testNonPersistentStatement() { - $params = $this->_conn->getParams(); + $params = $this->_conn->getParams(); $params['persistent'] = false; $conn = DriverManager::getConnection($params); $conn->connect(); - self::assertTrue($conn->isConnected(),'No SQLAnywhere-Connection established'); + self::assertTrue($conn->isConnected(), 'No SQLAnywhere-Connection established'); $prepStmt = $conn->prepare('SELECT 1'); - self::assertTrue($prepStmt->execute(),' Statement non-persistent failed'); + self::assertTrue($prepStmt->execute(), ' Statement non-persistent failed'); } public function testPersistentStatement() { - $params = $this->_conn->getParams(); + $params = $this->_conn->getParams(); $params['persistent'] = true; $conn = DriverManager::getConnection($params); $conn->connect(); - self::assertTrue($conn->isConnected(),'No SQLAnywhere-Connection established'); + self::assertTrue($conn->isConnected(), 'No SQLAnywhere-Connection established'); $prepStmt = $conn->prepare('SELECT 1'); - self::assertTrue($prepStmt->execute(),' Statement persistent failed'); + self::assertTrue($prepStmt->execute(), ' Statement persistent failed'); } - } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/DriverTest.php index aa7ed63a3e1..4ea3c9bc143 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/DriverTest.php @@ -16,9 +16,11 @@ protected function setUp() parent::setUp(); - if (! $this->_conn->getDriver() instanceof Driver) { - $this->markTestSkipped('sqlsrv only test.'); + if ($this->_conn->getDriver() instanceof Driver) { + return; } + + $this->markTestSkipped('sqlsrv only test.'); } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/StatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/StatementTest.php index 6c9ea327a62..b6b325f23b4 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/StatementTest.php @@ -11,15 +11,17 @@ class StatementTest extends DbalFunctionalTestCase { protected function setUp() { - if (!extension_loaded('sqlsrv')) { + if (! extension_loaded('sqlsrv')) { self::markTestSkipped('sqlsrv is not installed.'); } parent::setUp(); - if (!$this->_conn->getDriver() instanceof Driver) { - self::markTestSkipped('sqlsrv only test'); + if ($this->_conn->getDriver() instanceof Driver) { + return; } + + self::markTestSkipped('sqlsrv only test'); } public function testFailureToPrepareResultsInException() diff --git a/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php b/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php index a8c73ce33c5..a2e1ca901e3 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php @@ -1,9 +1,14 @@ _conn->getDriver() instanceof ExceptionConverterDriver)) { - $this->markTestSkipped('Driver does not support special exception handling.'); + if ($this->_conn->getDriver() instanceof ExceptionConverterDriver) { + return; } + + $this->markTestSkipped('Driver does not support special exception handling.'); } public function testPrimaryConstraintViolationException() { - $table = new \Doctrine\DBAL\Schema\Table("duplicatekey_table"); - $table->addColumn('id', 'integer', array()); - $table->setPrimaryKey(array('id')); + $table = new Table('duplicatekey_table'); + $table->addColumn('id', 'integer', []); + $table->setPrimaryKey(['id']); $this->_conn->getSchemaManager()->createTable($table); - $this->_conn->insert("duplicatekey_table", array('id' => 1)); + $this->_conn->insert('duplicatekey_table', ['id' => 1]); $this->expectException(Exception\UniqueConstraintViolationException::class); - $this->_conn->insert("duplicatekey_table", array('id' => 1)); + $this->_conn->insert('duplicatekey_table', ['id' => 1]); } public function testTableNotFoundException() { - $sql = "SELECT * FROM unknown_table"; + $sql = 'SELECT * FROM unknown_table'; $this->expectException(Exception\TableNotFoundException::class); $this->_conn->executeQuery($sql); @@ -49,9 +56,9 @@ public function testTableNotFoundException() public function testTableExistsException() { $schemaManager = $this->_conn->getSchemaManager(); - $table = new \Doctrine\DBAL\Schema\Table("alreadyexist_table"); - $table->addColumn('id', 'integer', array()); - $table->setPrimaryKey(array('id')); + $table = new Table('alreadyexist_table'); + $table->addColumn('id', 'integer', []); + $table->setPrimaryKey(['id']); $this->expectException(Exception\TableExistsException::class); $schemaManager->createTable($table); @@ -60,16 +67,16 @@ public function testTableExistsException() public function testForeignKeyConstraintViolationExceptionOnInsert() { - if ( ! $this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { - $this->markTestSkipped("Only fails on platforms with foreign key constraints."); + if (! $this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { + $this->markTestSkipped('Only fails on platforms with foreign key constraints.'); } $this->setUpForeignKeyConstraintViolationExceptionTest(); try { - $this->_conn->insert("constraint_error_table", array('id' => 1)); - $this->_conn->insert("owning_table", array('id' => 1, 'constraint_id' => 1)); - } catch (\Exception $exception) { + $this->_conn->insert('constraint_error_table', ['id' => 1]); + $this->_conn->insert('owning_table', ['id' => 1, 'constraint_id' => 1]); + } catch (Throwable $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); throw $exception; @@ -78,12 +85,12 @@ public function testForeignKeyConstraintViolationExceptionOnInsert() $this->expectException(Exception\ForeignKeyConstraintViolationException::class); try { - $this->_conn->insert('owning_table', array('id' => 2, 'constraint_id' => 2)); + $this->_conn->insert('owning_table', ['id' => 2, 'constraint_id' => 2]); } catch (Exception\ForeignKeyConstraintViolationException $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); throw $exception; - } catch (\Exception $exception) { + } catch (Throwable $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); throw $exception; @@ -94,16 +101,16 @@ public function testForeignKeyConstraintViolationExceptionOnInsert() public function testForeignKeyConstraintViolationExceptionOnUpdate() { - if ( ! $this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { - $this->markTestSkipped("Only fails on platforms with foreign key constraints."); + if (! $this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { + $this->markTestSkipped('Only fails on platforms with foreign key constraints.'); } $this->setUpForeignKeyConstraintViolationExceptionTest(); try { - $this->_conn->insert("constraint_error_table", array('id' => 1)); - $this->_conn->insert("owning_table", array('id' => 1, 'constraint_id' => 1)); - } catch (\Exception $exception) { + $this->_conn->insert('constraint_error_table', ['id' => 1]); + $this->_conn->insert('owning_table', ['id' => 1, 'constraint_id' => 1]); + } catch (Throwable $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); throw $exception; @@ -112,12 +119,12 @@ public function testForeignKeyConstraintViolationExceptionOnUpdate() $this->expectException(Exception\ForeignKeyConstraintViolationException::class); try { - $this->_conn->update('constraint_error_table', array('id' => 2), array('id' => 1)); + $this->_conn->update('constraint_error_table', ['id' => 2], ['id' => 1]); } catch (Exception\ForeignKeyConstraintViolationException $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); throw $exception; - } catch (\Exception $exception) { + } catch (Throwable $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); throw $exception; @@ -128,16 +135,16 @@ public function testForeignKeyConstraintViolationExceptionOnUpdate() public function testForeignKeyConstraintViolationExceptionOnDelete() { - if ( ! $this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { - $this->markTestSkipped("Only fails on platforms with foreign key constraints."); + if (! $this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { + $this->markTestSkipped('Only fails on platforms with foreign key constraints.'); } $this->setUpForeignKeyConstraintViolationExceptionTest(); try { - $this->_conn->insert("constraint_error_table", array('id' => 1)); - $this->_conn->insert("owning_table", array('id' => 1, 'constraint_id' => 1)); - } catch (\Exception $exception) { + $this->_conn->insert('constraint_error_table', ['id' => 1]); + $this->_conn->insert('owning_table', ['id' => 1, 'constraint_id' => 1]); + } catch (Throwable $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); throw $exception; @@ -146,12 +153,12 @@ public function testForeignKeyConstraintViolationExceptionOnDelete() $this->expectException(Exception\ForeignKeyConstraintViolationException::class); try { - $this->_conn->delete('constraint_error_table', array('id' => 1)); + $this->_conn->delete('constraint_error_table', ['id' => 1]); } catch (Exception\ForeignKeyConstraintViolationException $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); throw $exception; - } catch (\Exception $exception) { + } catch (Throwable $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); throw $exception; @@ -164,16 +171,16 @@ public function testForeignKeyConstraintViolationExceptionOnTruncate() { $platform = $this->_conn->getDatabasePlatform(); - if (!$platform->supportsForeignKeyConstraints()) { - $this->markTestSkipped("Only fails on platforms with foreign key constraints."); + if (! $platform->supportsForeignKeyConstraints()) { + $this->markTestSkipped('Only fails on platforms with foreign key constraints.'); } $this->setUpForeignKeyConstraintViolationExceptionTest(); try { - $this->_conn->insert("constraint_error_table", array('id' => 1)); - $this->_conn->insert("owning_table", array('id' => 1, 'constraint_id' => 1)); - } catch (\Exception $exception) { + $this->_conn->insert('constraint_error_table', ['id' => 1]); + $this->_conn->insert('owning_table', ['id' => 1, 'constraint_id' => 1]); + } catch (Throwable $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); throw $exception; @@ -187,7 +194,7 @@ public function testForeignKeyConstraintViolationExceptionOnTruncate() $this->tearDownForeignKeyConstraintViolationExceptionTest(); throw $exception; - } catch (\Exception $exception) { + } catch (Throwable $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); throw $exception; @@ -198,44 +205,44 @@ public function testForeignKeyConstraintViolationExceptionOnTruncate() public function testNotNullConstraintViolationException() { - $schema = new \Doctrine\DBAL\Schema\Schema(); + $schema = new Schema(); - $table = $schema->createTable("notnull_table"); - $table->addColumn('id', 'integer', array()); - $table->addColumn('value', 'integer', array('notnull' => true)); - $table->setPrimaryKey(array('id')); + $table = $schema->createTable('notnull_table'); + $table->addColumn('id', 'integer', []); + $table->addColumn('value', 'integer', ['notnull' => true]); + $table->setPrimaryKey(['id']); foreach ($schema->toSql($this->_conn->getDatabasePlatform()) as $sql) { $this->_conn->exec($sql); } $this->expectException(Exception\NotNullConstraintViolationException::class); - $this->_conn->insert("notnull_table", array('id' => 1, 'value' => null)); + $this->_conn->insert('notnull_table', ['id' => 1, 'value' => null]); } public function testInvalidFieldNameException() { - $schema = new \Doctrine\DBAL\Schema\Schema(); + $schema = new Schema(); - $table = $schema->createTable("bad_fieldname_table"); - $table->addColumn('id', 'integer', array()); + $table = $schema->createTable('bad_fieldname_table'); + $table->addColumn('id', 'integer', []); foreach ($schema->toSql($this->_conn->getDatabasePlatform()) as $sql) { $this->_conn->exec($sql); } $this->expectException(Exception\InvalidFieldNameException::class); - $this->_conn->insert("bad_fieldname_table", array('name' => 5)); + $this->_conn->insert('bad_fieldname_table', ['name' => 5]); } public function testNonUniqueFieldNameException() { - $schema = new \Doctrine\DBAL\Schema\Schema(); + $schema = new Schema(); - $table = $schema->createTable("ambiguous_list_table"); + $table = $schema->createTable('ambiguous_list_table'); $table->addColumn('id', 'integer'); - $table2 = $schema->createTable("ambiguous_list_table_2"); + $table2 = $schema->createTable('ambiguous_list_table_2'); $table2->addColumn('id', 'integer'); foreach ($schema->toSql($this->_conn->getDatabasePlatform()) as $sql) { @@ -249,26 +256,26 @@ public function testNonUniqueFieldNameException() public function testUniqueConstraintViolationException() { - $schema = new \Doctrine\DBAL\Schema\Schema(); + $schema = new Schema(); - $table = $schema->createTable("unique_field_table"); + $table = $schema->createTable('unique_field_table'); $table->addColumn('id', 'integer'); - $table->addUniqueIndex(array('id')); + $table->addUniqueIndex(['id']); foreach ($schema->toSql($this->_conn->getDatabasePlatform()) as $sql) { $this->_conn->exec($sql); } - $this->_conn->insert("unique_field_table", array('id' => 5)); + $this->_conn->insert('unique_field_table', ['id' => 5]); $this->expectException(Exception\UniqueConstraintViolationException::class); - $this->_conn->insert("unique_field_table", array('id' => 5)); + $this->_conn->insert('unique_field_table', ['id' => 5]); } public function testSyntaxErrorException() { - $table = new \Doctrine\DBAL\Schema\Table("syntax_error_table"); - $table->addColumn('id', 'integer', array()); - $table->setPrimaryKey(array('id')); + $table = new Table('syntax_error_table'); + $table->addColumn('id', 'integer', []); + $table->setPrimaryKey(['id']); $this->_conn->getSchemaManager()->createTable($table); @@ -282,11 +289,11 @@ public function testSyntaxErrorException() */ public function testConnectionExceptionSqLite($mode, $exceptionClass) { - if ($this->_conn->getDatabasePlatform()->getName() != 'sqlite') { - $this->markTestSkipped("Only fails this way on sqlite"); + if ($this->_conn->getDatabasePlatform()->getName() !== 'sqlite') { + $this->markTestSkipped('Only fails this way on sqlite'); } - $filename = sprintf('%s/%s', sys_get_temp_dir(), 'doctrine_failed_connection_'.$mode.'.db'); + $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 @@ -296,14 +303,14 @@ public function testConnectionExceptionSqLite($mode, $exceptionClass) touch($filename); chmod($filename, $mode); - $params = array( + $params = [ 'driver' => 'pdo_sqlite', 'path' => $filename, - ); - $conn = \Doctrine\DBAL\DriverManager::getConnection($params); + ]; + $conn = DriverManager::getConnection($params); - $schema = new \Doctrine\DBAL\Schema\Schema(); - $table = $schema->createTable("no_connection"); + $schema = new Schema(); + $table = $schema->createTable('no_connection'); $table->addColumn('id', 'integer'); $this->expectException($exceptionClass); @@ -314,11 +321,11 @@ public function testConnectionExceptionSqLite($mode, $exceptionClass) public function getSqLiteOpenConnection() { - return array( + return [ // mode 0 is considered read-only on Windows - array(0000, defined('PHP_WINDOWS_VERSION_BUILD') ? Exception\ReadOnlyException::class : Exception\ConnectionException::class), - array(0444, Exception\ReadOnlyException::class), - ); + [0000, defined('PHP_WINDOWS_VERSION_BUILD') ? Exception\ReadOnlyException::class : Exception\ConnectionException::class], + [0444, Exception\ReadOnlyException::class], + ]; } /** @@ -326,25 +333,25 @@ public function getSqLiteOpenConnection() */ public function testConnectionException($params) { - if ($this->_conn->getDatabasePlatform()->getName() == 'sqlite') { - $this->markTestSkipped("Only skipped if platform is not sqlite"); + if ($this->_conn->getDatabasePlatform()->getName() === 'sqlite') { + $this->markTestSkipped('Only skipped if platform is not sqlite'); } - if ($this->_conn->getDatabasePlatform()->getName() == 'drizzle') { - $this->markTestSkipped("Drizzle does not always support authentication"); + if ($this->_conn->getDatabasePlatform()->getName() === 'drizzle') { + $this->markTestSkipped('Drizzle does not always support authentication'); } - if ($this->_conn->getDatabasePlatform()->getName() == 'postgresql' && isset($params['password'])) { - $this->markTestSkipped("Does not work on Travis"); + if ($this->_conn->getDatabasePlatform()->getName() === 'postgresql' && isset($params['password'])) { + $this->markTestSkipped('Does not work on Travis'); } $defaultParams = $this->_conn->getParams(); - $params = array_merge($defaultParams, $params); + $params = array_merge($defaultParams, $params); - $conn = \Doctrine\DBAL\DriverManager::getConnection($params); + $conn = DriverManager::getConnection($params); - $schema = new \Doctrine\DBAL\Schema\Schema(); - $table = $schema->createTable("no_connection"); + $schema = new Schema(); + $table = $schema->createTable('no_connection'); $table->addColumn('id', 'integer'); $this->expectException(Exception\ConnectionException::class); @@ -356,26 +363,26 @@ public function testConnectionException($params) public function getConnectionParams() { - return array( - array(array('user' => 'not_existing')), - array(array('password' => 'really_not')), - array(array('host' => 'localnope')), - ); + return [ + [['user' => 'not_existing']], + [['password' => 'really_not']], + [['host' => 'localnope']], + ]; } private function setUpForeignKeyConstraintViolationExceptionTest() { $schemaManager = $this->_conn->getSchemaManager(); - $table = new Table("constraint_error_table"); - $table->addColumn('id', 'integer', array()); - $table->setPrimaryKey(array('id')); + $table = new Table('constraint_error_table'); + $table->addColumn('id', 'integer', []); + $table->setPrimaryKey(['id']); - $owningTable = new Table("owning_table"); - $owningTable->addColumn('id', 'integer', array()); - $owningTable->addColumn('constraint_id', 'integer', array()); - $owningTable->setPrimaryKey(array('id')); - $owningTable->addForeignKeyConstraint($table, array('constraint_id'), array('id')); + $owningTable = new Table('owning_table'); + $owningTable->addColumn('id', 'integer', []); + $owningTable->addColumn('constraint_id', 'integer', []); + $owningTable->setPrimaryKey(['id']); + $owningTable->addForeignKeyConstraint($table, ['constraint_id'], ['id']); $schemaManager->createTable($table); $schemaManager->createTable($owningTable); diff --git a/tests/Doctrine/Tests/DBAL/Functional/LikeWildcardsEscapingTest.php b/tests/Doctrine/Tests/DBAL/Functional/LikeWildcardsEscapingTest.php index 9f2a098d7f5..59306f153fd 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/LikeWildcardsEscapingTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/LikeWildcardsEscapingTest.php @@ -4,7 +4,6 @@ use Doctrine\Tests\DbalFunctionalTestCase; use function sprintf; -use function str_replace; final class LikeWildcardsEscapingTest extends DbalFunctionalTestCase { diff --git a/tests/Doctrine/Tests/DBAL/Functional/LoggingTest.php b/tests/Doctrine/Tests/DBAL/Functional/LoggingTest.php index f32520485ef..8ba5daa0669 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/LoggingTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/LoggingTest.php @@ -2,7 +2,9 @@ namespace Doctrine\Tests\DBAL\Functional; -class LoggingTest extends \Doctrine\Tests\DbalFunctionalTestCase +use Doctrine\Tests\DbalFunctionalTestCase; + +class LoggingTest extends DbalFunctionalTestCase { public function testLogExecuteQuery() { @@ -11,11 +13,11 @@ public function testLogExecuteQuery() $logMock = $this->createMock('Doctrine\DBAL\Logging\SQLLogger'); $logMock->expects($this->at(0)) ->method('startQuery') - ->with($this->equalTo($sql), $this->equalTo(array()), $this->equalTo(array())); + ->with($this->equalTo($sql), $this->equalTo([]), $this->equalTo([])); $logMock->expects($this->at(1)) ->method('stopQuery'); $this->_conn->getConfiguration()->setSQLLogger($logMock); - $this->_conn->executeQuery($sql, array()); + $this->_conn->executeQuery($sql, []); } public function testLogExecuteUpdate() @@ -27,11 +29,11 @@ public function testLogExecuteUpdate() $logMock = $this->createMock('Doctrine\DBAL\Logging\SQLLogger'); $logMock->expects($this->at(0)) ->method('startQuery') - ->with($this->equalTo($sql), $this->equalTo(array()), $this->equalTo(array())); + ->with($this->equalTo($sql), $this->equalTo([]), $this->equalTo([])); $logMock->expects($this->at(1)) ->method('stopQuery'); $this->_conn->getConfiguration()->setSQLLogger($logMock); - $this->_conn->executeUpdate($sql, array()); + $this->_conn->executeUpdate($sql, []); } public function testLogPrepareExecute() @@ -41,7 +43,7 @@ public function testLogPrepareExecute() $logMock = $this->createMock('Doctrine\DBAL\Logging\SQLLogger'); $logMock->expects($this->once()) ->method('startQuery') - ->with($this->equalTo($sql), $this->equalTo(array())); + ->with($this->equalTo($sql), $this->equalTo([])); $logMock->expects($this->at(1)) ->method('stopQuery'); $this->_conn->getConfiguration()->setSQLLogger($logMock); diff --git a/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php index 8b4c01e31d2..af894cf147c 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php @@ -4,7 +4,10 @@ use Doctrine\DBAL\Connections\MasterSlaveConnection; use Doctrine\DBAL\DriverManager; +use Doctrine\DBAL\Schema\AbstractSchemaManager; +use Doctrine\DBAL\Schema\Table; use Doctrine\Tests\DbalFunctionalTestCase; +use Throwable; use const CASE_LOWER; use function array_change_key_case; use function sprintf; @@ -24,25 +27,23 @@ protected function setUp() $platformName = $this->_conn->getDatabasePlatform()->getName(); // This is a MySQL specific test, skip other vendors. - if ($platformName != 'mysql') { + if ($platformName !== 'mysql') { $this->markTestSkipped(sprintf('Test does not work on %s.', $platformName)); } try { - /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ - $table = new \Doctrine\DBAL\Schema\Table("master_slave_table"); + /** @var AbstractSchemaManager $sm */ + $table = new Table('master_slave_table'); $table->addColumn('test_int', 'integer'); - $table->setPrimaryKey(array('test_int')); + $table->setPrimaryKey(['test_int']); $sm = $this->_conn->getSchemaManager(); $sm->createTable($table); - - - } catch(\Exception $e) { + } catch (Throwable $e) { } $this->_conn->executeUpdate('DELETE FROM master_slave_table'); - $this->_conn->insert('master_slave_table', array('test_int' => 1)); + $this->_conn->insert('master_slave_table', ['test_int' => 1]); } private function createMasterSlaveConnection(bool $keepSlave = false) : MasterSlaveConnection @@ -52,9 +53,9 @@ private function createMasterSlaveConnection(bool $keepSlave = false) : MasterSl private function createMasterSlaveConnectionParams(bool $keepSlave = false) : array { - $params = $this->_conn->getParams(); + $params = $this->_conn->getParams(); $params['master'] = $params; - $params['slaves'] = array($params, $params); + $params['slaves'] = [$params, $params]; $params['keepSlave'] = $keepSlave; $params['wrapperClass'] = MasterSlaveConnection::class; @@ -65,17 +66,19 @@ public function testInheritCharsetFromMaster() : void { $charsets = [ 'utf8', - 'latin1' + 'latin1', ]; foreach ($charsets as $charset) { - $params = $this->createMasterSlaveConnectionParams(); + $params = $this->createMasterSlaveConnectionParams(); $params['master']['charset'] = $charset; foreach ($params['slaves'] as $index => $slaveParams) { - if (isset($slaveParams['charset'])) { - unset($params['slaves'][$index]['charset']); + if (! isset($slaveParams['charset'])) { + continue; } + + unset($params['slaves'][$index]['charset']); } /** @var MasterSlaveConnection $conn */ @@ -108,8 +111,8 @@ public function testNoMasterOnExecuteQuery() { $conn = $this->createMasterSlaveConnection(); - $sql = "SELECT count(*) as num FROM master_slave_table"; - $data = $conn->fetchAll($sql); + $sql = 'SELECT count(*) as num FROM master_slave_table'; + $data = $conn->fetchAll($sql); $data[0] = array_change_key_case($data[0], CASE_LOWER); self::assertEquals(1, $data[0]['num']); @@ -119,12 +122,12 @@ public function testNoMasterOnExecuteQuery() public function testMasterOnWriteOperation() { $conn = $this->createMasterSlaveConnection(); - $conn->insert('master_slave_table', array('test_int' => 30)); + $conn->insert('master_slave_table', ['test_int' => 30]); self::assertTrue($conn->isConnectedToMaster()); - $sql = "SELECT count(*) as num FROM master_slave_table"; - $data = $conn->fetchAll($sql); + $sql = 'SELECT count(*) as num FROM master_slave_table'; + $data = $conn->fetchAll($sql); $data[0] = array_change_key_case($data[0], CASE_LOWER); self::assertEquals(2, $data[0]['num']); @@ -140,7 +143,7 @@ public function testKeepSlaveBeginTransactionStaysOnMaster() $conn->connect('slave'); $conn->beginTransaction(); - $conn->insert('master_slave_table', array('test_int' => 30)); + $conn->insert('master_slave_table', ['test_int' => 30]); $conn->commit(); self::assertTrue($conn->isConnectedToMaster()); @@ -160,7 +163,7 @@ public function testKeepSlaveInsertStaysOnMaster() $conn = $this->createMasterSlaveConnection($keepSlave = true); $conn->connect('slave'); - $conn->insert('master_slave_table', array('test_int' => 30)); + $conn->insert('master_slave_table', ['test_int' => 30]); self::assertTrue($conn->isConnectedToMaster()); diff --git a/tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php b/tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php index 6cd36b74e7e..b68aeaef8b3 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php @@ -1,31 +1,33 @@ addColumn('test_int', 'integer'); - $table->setPrimaryKey(array('test_int')); + $table->setPrimaryKey(['test_int']); - $table2 = new \Doctrine\DBAL\Schema\Table("modify_limit_table2"); - $table2->addColumn('id', 'integer', array('autoincrement' => true)); + $table2 = new Table('modify_limit_table2'); + $table2->addColumn('id', 'integer', ['autoincrement' => true]); $table2->addColumn('test_int', 'integer'); - $table2->setPrimaryKey(array('id')); + $table2->setPrimaryKey(['id']); $sm = $this->_conn->getSchemaManager(); $sm->createTable($table); @@ -38,104 +40,104 @@ protected function setUp() public function testModifyLimitQuerySimpleQuery() { - $this->_conn->insert('modify_limit_table', array('test_int' => 1)); - $this->_conn->insert('modify_limit_table', array('test_int' => 2)); - $this->_conn->insert('modify_limit_table', array('test_int' => 3)); - $this->_conn->insert('modify_limit_table', array('test_int' => 4)); + $this->_conn->insert('modify_limit_table', ['test_int' => 1]); + $this->_conn->insert('modify_limit_table', ['test_int' => 2]); + $this->_conn->insert('modify_limit_table', ['test_int' => 3]); + $this->_conn->insert('modify_limit_table', ['test_int' => 4]); - $sql = "SELECT * FROM modify_limit_table ORDER BY test_int ASC"; + $sql = 'SELECT * FROM modify_limit_table ORDER BY test_int ASC'; - $this->assertLimitResult(array(1, 2, 3, 4), $sql, 10, 0); - $this->assertLimitResult(array(1, 2), $sql, 2, 0); - $this->assertLimitResult(array(3, 4), $sql, 2, 2); - $this->assertLimitResult(array(2, 3, 4), $sql, null, 1); + $this->assertLimitResult([1, 2, 3, 4], $sql, 10, 0); + $this->assertLimitResult([1, 2], $sql, 2, 0); + $this->assertLimitResult([3, 4], $sql, 2, 2); + $this->assertLimitResult([2, 3, 4], $sql, null, 1); } public function testModifyLimitQueryJoinQuery() { - $this->_conn->insert('modify_limit_table', array('test_int' => 1)); - $this->_conn->insert('modify_limit_table', array('test_int' => 2)); + $this->_conn->insert('modify_limit_table', ['test_int' => 1]); + $this->_conn->insert('modify_limit_table', ['test_int' => 2]); - $this->_conn->insert('modify_limit_table2', array('test_int' => 1)); - $this->_conn->insert('modify_limit_table2', array('test_int' => 1)); - $this->_conn->insert('modify_limit_table2', array('test_int' => 1)); - $this->_conn->insert('modify_limit_table2', array('test_int' => 2)); - $this->_conn->insert('modify_limit_table2', array('test_int' => 2)); + $this->_conn->insert('modify_limit_table2', ['test_int' => 1]); + $this->_conn->insert('modify_limit_table2', ['test_int' => 1]); + $this->_conn->insert('modify_limit_table2', ['test_int' => 1]); + $this->_conn->insert('modify_limit_table2', ['test_int' => 2]); + $this->_conn->insert('modify_limit_table2', ['test_int' => 2]); - $sql = "SELECT modify_limit_table.test_int FROM modify_limit_table INNER JOIN modify_limit_table2 ON modify_limit_table.test_int = modify_limit_table2.test_int ORDER BY modify_limit_table.test_int DESC"; + $sql = 'SELECT modify_limit_table.test_int FROM modify_limit_table INNER JOIN modify_limit_table2 ON modify_limit_table.test_int = modify_limit_table2.test_int ORDER BY modify_limit_table.test_int DESC'; - $this->assertLimitResult(array(2, 2, 1, 1, 1), $sql, 10, 0); - $this->assertLimitResult(array(1, 1, 1), $sql, 3, 2); - $this->assertLimitResult(array(2, 2), $sql, 2, 0); + $this->assertLimitResult([2, 2, 1, 1, 1], $sql, 10, 0); + $this->assertLimitResult([1, 1, 1], $sql, 3, 2); + $this->assertLimitResult([2, 2], $sql, 2, 0); } public function testModifyLimitQueryNonDeterministic() { - $this->_conn->insert('modify_limit_table', array('test_int' => 1)); - $this->_conn->insert('modify_limit_table', array('test_int' => 2)); - $this->_conn->insert('modify_limit_table', array('test_int' => 3)); - $this->_conn->insert('modify_limit_table', array('test_int' => 4)); + $this->_conn->insert('modify_limit_table', ['test_int' => 1]); + $this->_conn->insert('modify_limit_table', ['test_int' => 2]); + $this->_conn->insert('modify_limit_table', ['test_int' => 3]); + $this->_conn->insert('modify_limit_table', ['test_int' => 4]); - $sql = "SELECT * FROM modify_limit_table"; + $sql = 'SELECT * FROM modify_limit_table'; - $this->assertLimitResult(array(4, 3, 2, 1), $sql, 10, 0, false); - $this->assertLimitResult(array(4, 3), $sql, 2, 0, false); - $this->assertLimitResult(array(2, 1), $sql, 2, 2, false); + $this->assertLimitResult([4, 3, 2, 1], $sql, 10, 0, false); + $this->assertLimitResult([4, 3], $sql, 2, 0, false); + $this->assertLimitResult([2, 1], $sql, 2, 2, false); } public function testModifyLimitQueryGroupBy() { - $this->_conn->insert('modify_limit_table', array('test_int' => 1)); - $this->_conn->insert('modify_limit_table', array('test_int' => 2)); - - $this->_conn->insert('modify_limit_table2', array('test_int' => 1)); - $this->_conn->insert('modify_limit_table2', array('test_int' => 1)); - $this->_conn->insert('modify_limit_table2', array('test_int' => 1)); - $this->_conn->insert('modify_limit_table2', array('test_int' => 2)); - $this->_conn->insert('modify_limit_table2', array('test_int' => 2)); - - $sql = "SELECT modify_limit_table.test_int FROM modify_limit_table " . - "INNER JOIN modify_limit_table2 ON modify_limit_table.test_int = modify_limit_table2.test_int ". - "GROUP BY modify_limit_table.test_int " . - "ORDER BY modify_limit_table.test_int ASC"; - $this->assertLimitResult(array(1, 2), $sql, 10, 0); - $this->assertLimitResult(array(1), $sql, 1, 0); - $this->assertLimitResult(array(2), $sql, 1, 1); + $this->_conn->insert('modify_limit_table', ['test_int' => 1]); + $this->_conn->insert('modify_limit_table', ['test_int' => 2]); + + $this->_conn->insert('modify_limit_table2', ['test_int' => 1]); + $this->_conn->insert('modify_limit_table2', ['test_int' => 1]); + $this->_conn->insert('modify_limit_table2', ['test_int' => 1]); + $this->_conn->insert('modify_limit_table2', ['test_int' => 2]); + $this->_conn->insert('modify_limit_table2', ['test_int' => 2]); + + $sql = 'SELECT modify_limit_table.test_int FROM modify_limit_table ' . + 'INNER JOIN modify_limit_table2 ON modify_limit_table.test_int = modify_limit_table2.test_int ' . + 'GROUP BY modify_limit_table.test_int ' . + 'ORDER BY modify_limit_table.test_int ASC'; + $this->assertLimitResult([1, 2], $sql, 10, 0); + $this->assertLimitResult([1], $sql, 1, 0); + $this->assertLimitResult([2], $sql, 1, 1); } public function testModifyLimitQuerySubSelect() { - $this->_conn->insert('modify_limit_table', array('test_int' => 1)); - $this->_conn->insert('modify_limit_table', array('test_int' => 2)); - $this->_conn->insert('modify_limit_table', array('test_int' => 3)); - $this->_conn->insert('modify_limit_table', array('test_int' => 4)); + $this->_conn->insert('modify_limit_table', ['test_int' => 1]); + $this->_conn->insert('modify_limit_table', ['test_int' => 2]); + $this->_conn->insert('modify_limit_table', ['test_int' => 3]); + $this->_conn->insert('modify_limit_table', ['test_int' => 4]); - $sql = "SELECT modify_limit_table.*, (SELECT COUNT(*) FROM modify_limit_table) AS cnt FROM modify_limit_table ORDER BY test_int DESC"; + $sql = 'SELECT modify_limit_table.*, (SELECT COUNT(*) FROM modify_limit_table) AS cnt FROM modify_limit_table ORDER BY test_int DESC'; - $this->assertLimitResult(array(4, 3, 2, 1), $sql, 10, 0); - $this->assertLimitResult(array(4, 3), $sql, 2, 0); - $this->assertLimitResult(array(2, 1), $sql, 2, 2); + $this->assertLimitResult([4, 3, 2, 1], $sql, 10, 0); + $this->assertLimitResult([4, 3], $sql, 2, 0); + $this->assertLimitResult([2, 1], $sql, 2, 2); } public function testModifyLimitQueryFromSubSelect() { - $this->_conn->insert('modify_limit_table', array('test_int' => 1)); - $this->_conn->insert('modify_limit_table', array('test_int' => 2)); - $this->_conn->insert('modify_limit_table', array('test_int' => 3)); - $this->_conn->insert('modify_limit_table', array('test_int' => 4)); + $this->_conn->insert('modify_limit_table', ['test_int' => 1]); + $this->_conn->insert('modify_limit_table', ['test_int' => 2]); + $this->_conn->insert('modify_limit_table', ['test_int' => 3]); + $this->_conn->insert('modify_limit_table', ['test_int' => 4]); - $sql = "SELECT * FROM (SELECT * FROM modify_limit_table) sub ORDER BY test_int DESC"; + $sql = 'SELECT * FROM (SELECT * FROM modify_limit_table) sub ORDER BY test_int DESC'; - $this->assertLimitResult(array(4, 3, 2, 1), $sql, 10, 0); - $this->assertLimitResult(array(4, 3), $sql, 2, 0); - $this->assertLimitResult(array(2, 1), $sql, 2, 2); + $this->assertLimitResult([4, 3, 2, 1], $sql, 10, 0); + $this->assertLimitResult([4, 3], $sql, 2, 0); + $this->assertLimitResult([2, 1], $sql, 2, 2); } public function testModifyLimitQueryLineBreaks() { - $this->_conn->insert('modify_limit_table', array('test_int' => 1)); - $this->_conn->insert('modify_limit_table', array('test_int' => 2)); - $this->_conn->insert('modify_limit_table', array('test_int' => 3)); + $this->_conn->insert('modify_limit_table', ['test_int' => 1]); + $this->_conn->insert('modify_limit_table', ['test_int' => 2]); + $this->_conn->insert('modify_limit_table', ['test_int' => 3]); $sql = <<assertLimitResult(array(2), $sql, 1, 1); + $this->assertLimitResult([2], $sql, 1, 1); } public function testModifyLimitQueryZeroOffsetNoLimit() { - $this->_conn->insert('modify_limit_table', array('test_int' => 1)); - $this->_conn->insert('modify_limit_table', array('test_int' => 2)); + $this->_conn->insert('modify_limit_table', ['test_int' => 1]); + $this->_conn->insert('modify_limit_table', ['test_int' => 2]); - $sql = "SELECT test_int FROM modify_limit_table ORDER BY test_int ASC"; + $sql = 'SELECT test_int FROM modify_limit_table ORDER BY test_int ASC'; - $this->assertLimitResult(array(1, 2), $sql, null, 0); + $this->assertLimitResult([1, 2], $sql, null, 0); } public function assertLimitResult($expectedResults, $sql, $limit, $offset, $deterministic = true) { - $p = $this->_conn->getDatabasePlatform(); - $data = array(); + $p = $this->_conn->getDatabasePlatform(); + $data = []; foreach ($this->_conn->fetchAll($p->modifyLimitQuery($sql, $limit, $offset)) as $row) { - $row = array_change_key_case($row, CASE_LOWER); + $row = array_change_key_case($row, CASE_LOWER); $data[] = $row['test_int']; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/NamedParametersTest.php b/tests/Doctrine/Tests/DBAL/Functional/NamedParametersTest.php index fd001d496e5..cbe56ef9bfc 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/NamedParametersTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/NamedParametersTest.php @@ -6,13 +6,15 @@ use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Schema\Table; +use Doctrine\Tests\DbalFunctionalTestCase; +use Throwable; use const CASE_LOWER; use function array_change_key_case; /** * @group DDC-1372 */ -class NamedParametersTest extends \Doctrine\Tests\DbalFunctionalTestCase +class NamedParametersTest extends DbalFunctionalTestCase { public function ticketProvider() { @@ -149,61 +151,64 @@ protected function setUp() { parent::setUp(); - if (! $this->_conn->getSchemaManager()->tablesExist('ddc1372_foobar')) { - try { - $table = new Table('ddc1372_foobar'); - $table->addColumn('id', 'integer'); - $table->addColumn('foo', 'string'); - $table->addColumn('bar', 'string'); - $table->setPrimaryKey(['id']); - - $sm = $this->_conn->getSchemaManager(); - $sm->createTable($table); + if ($this->_conn->getSchemaManager()->tablesExist('ddc1372_foobar')) { + return; + } - $this->_conn->insert('ddc1372_foobar', [ - 'id' => 1, - 'foo' => 1, - 'bar' => 1, - ]); - $this->_conn->insert('ddc1372_foobar', [ - 'id' => 2, - 'foo' => 1, - 'bar' => 2, - ]); - $this->_conn->insert('ddc1372_foobar', [ - 'id' => 3, - 'foo' => 1, - 'bar' => 3, - ]); - $this->_conn->insert('ddc1372_foobar', [ - 'id' => 4, - 'foo' => 1, - 'bar' => 4, - ]); - $this->_conn->insert('ddc1372_foobar', [ - 'id' => 5, - 'foo' => 2, - 'bar' => 1, - ]); - $this->_conn->insert('ddc1372_foobar', [ - 'id' => 6, - 'foo' => 2, - 'bar' => 2, - ]); - } catch(\Exception $e) { - $this->fail($e->getMessage()); - } + try { + $table = new Table('ddc1372_foobar'); + $table->addColumn('id', 'integer'); + $table->addColumn('foo', 'string'); + $table->addColumn('bar', 'string'); + $table->setPrimaryKey(['id']); + + $sm = $this->_conn->getSchemaManager(); + $sm->createTable($table); + + $this->_conn->insert('ddc1372_foobar', [ + 'id' => 1, + 'foo' => 1, + 'bar' => 1, + ]); + $this->_conn->insert('ddc1372_foobar', [ + 'id' => 2, + 'foo' => 1, + 'bar' => 2, + ]); + $this->_conn->insert('ddc1372_foobar', [ + 'id' => 3, + 'foo' => 1, + 'bar' => 3, + ]); + $this->_conn->insert('ddc1372_foobar', [ + 'id' => 4, + 'foo' => 1, + 'bar' => 4, + ]); + $this->_conn->insert('ddc1372_foobar', [ + 'id' => 5, + 'foo' => 2, + 'bar' => 1, + ]); + $this->_conn->insert('ddc1372_foobar', [ + 'id' => 6, + 'foo' => 2, + 'bar' => 2, + ]); + } catch (Throwable $e) { + $this->fail($e->getMessage()); } } /** - * @dataProvider ticketProvider * @param string $query * @param array $params * @param array $types * @param array $expected + * + * @dataProvider ticketProvider */ - public function testTicket($query,$params,$types,$expected) + public function testTicket($query, $params, $types, $expected) { $stmt = $this->_conn->executeQuery($query, $params, $types); $result = $stmt->fetchAll(FetchMode::ASSOCIATIVE); diff --git a/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php b/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php index f95f5bed47a..32a43664d6e 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php @@ -7,16 +7,18 @@ use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\Portability\Connection as ConnectionPortability; +use Doctrine\DBAL\Schema\AbstractSchemaManager; +use Doctrine\DBAL\Schema\Table; +use Doctrine\Tests\DbalFunctionalTestCase; +use Throwable; use function strlen; /** * @group DBAL-56 */ -class PortabilityTest extends \Doctrine\Tests\DbalFunctionalTestCase +class PortabilityTest extends DbalFunctionalTestCase { - /** - * @var Connection - */ + /** @var Connection */ private $portableConnection; protected function tearDown() @@ -31,13 +33,14 @@ protected function tearDown() /** * @param int $portabilityMode * @param int $case + * * @return Connection */ private function getPortableConnection( $portabilityMode = ConnectionPortability::PORTABILITY_ALL, $case = ColumnCase::LOWER ) { - if (!$this->portableConnection) { + if (! $this->portableConnection) { $params = $this->_conn->getParams(); $params['wrapperClass'] = ConnectionPortability::class; @@ -47,20 +50,19 @@ private function getPortableConnection( $this->portableConnection = DriverManager::getConnection($params, $this->_conn->getConfiguration(), $this->_conn->getEventManager()); try { - /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ - $table = new \Doctrine\DBAL\Schema\Table("portability_table"); + /** @var AbstractSchemaManager $sm */ + $table = new Table('portability_table'); $table->addColumn('Test_Int', 'integer'); - $table->addColumn('Test_String', 'string', array('fixed' => true, 'length' => 32)); - $table->addColumn('Test_Null', 'string', array('notnull' => false)); - $table->setPrimaryKey(array('Test_Int')); + $table->addColumn('Test_String', 'string', ['fixed' => true, 'length' => 32]); + $table->addColumn('Test_Null', 'string', ['notnull' => false]); + $table->setPrimaryKey(['Test_Int']); $sm = $this->portableConnection->getSchemaManager(); $sm->createTable($table); - $this->portableConnection->insert('portability_table', array('Test_Int' => 1, 'Test_String' => 'foo', 'Test_Null' => '')); - $this->portableConnection->insert('portability_table', array('Test_Int' => 2, 'Test_String' => 'foo ', 'Test_Null' => null)); - } catch(\Exception $e) { - + $this->portableConnection->insert('portability_table', ['Test_Int' => 1, 'Test_String' => 'foo', 'Test_Null' => '']); + $this->portableConnection->insert('portability_table', ['Test_Int' => 2, 'Test_String' => 'foo ', 'Test_Null' => null]); + } catch (Throwable $e) { } } @@ -103,18 +105,18 @@ public function testConnFetchMode() $stmt = $conn->query('SELECT * FROM portability_table'); foreach ($stmt as $row) { - $this->assertFetchResultRow($row); + $this->assertFetchResultRow($row); } $stmt = $conn->query('SELECT * FROM portability_table'); while (($row = $stmt->fetch())) { - $this->assertFetchResultRow($row); + $this->assertFetchResultRow($row); } $stmt = $conn->prepare('SELECT * FROM portability_table'); $stmt->execute(); while (($row = $stmt->fetch())) { - $this->assertFetchResultRow($row); + $this->assertFetchResultRow($row); } } @@ -128,9 +130,9 @@ public function assertFetchResultRows($rows) public function assertFetchResultRow($row) { - self::assertContains($row['test_int'], array(1, 2), "Primary key test_int should either be 1 or 2."); - self::assertArrayHasKey('test_string', $row, "Case should be lowered."); - self::assertEquals(3, strlen($row['test_string']), "test_string should be rtrimed to length of three for CHAR(32) column."); + 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.'); + self::assertEquals(3, strlen($row['test_string']), 'test_string should be rtrimed to length of three for CHAR(32) column.'); self::assertNull($row['test_null']); self::assertArrayNotHasKey(0, $row, 'The row should not contain numerical keys.'); } @@ -141,12 +143,10 @@ public function assertFetchResultRow($row) public function testPortabilityPdoSqlServer() { $portability = ConnectionPortability::PORTABILITY_SQLSRV; - $params = array( - 'portability' => $portability - ); + $params = ['portability' => $portability]; $driverMock = $this->getMockBuilder('Doctrine\\DBAL\\Driver\\PDOSqlsrv\\Driver') - ->setMethods(array('connect')) + ->setMethods(['connect']) ->getMock(); $driverMock->expects($this->once()) @@ -174,16 +174,16 @@ public function testFetchAllColumn($field, array $expected) public static function fetchAllColumnProvider() { - return array( - 'int' => array( + return [ + 'int' => [ 'Test_Int', - array(1, 2), - ), - 'string' => array( + [1, 2], + ], + 'string' => [ 'Test_String', - array('foo', 'foo'), - ), - ); + ['foo', 'foo'], + ], + ]; } public function testFetchAllNullColumn() @@ -192,6 +192,6 @@ public function testFetchAllNullColumn() $stmt = $conn->query('SELECT Test_Null FROM portability_table'); $column = $stmt->fetchAll(FetchMode::COLUMN); - self::assertSame(array(null, null), $column); + self::assertSame([null, null], $column); } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php b/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php index 63d82ad42c8..cb32a94252c 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php @@ -2,9 +2,12 @@ namespace Doctrine\Tests\DBAL\Functional; +use Doctrine\Common\Cache\ArrayCache; use Doctrine\DBAL\Cache\QueryCacheProfile; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\Logging\DebugStack; +use Doctrine\DBAL\Schema\Table; +use Doctrine\Tests\DbalFunctionalTestCase; use const CASE_LOWER; use function array_change_key_case; use function array_merge; @@ -15,26 +18,22 @@ /** * @group DDC-217 */ -class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase +class ResultCacheTest extends DbalFunctionalTestCase { - /** - * @var int[][]|string[][] - */ - private $expectedResult = array(array('test_int' => 100, 'test_string' => 'foo'), array('test_int' => 200, 'test_string' => 'bar'), array('test_int' => 300, 'test_string' => 'baz')); - - /** - * @var DebugStack - */ + /** @var int[][]|string[][] */ + private $expectedResult = [['test_int' => 100, 'test_string' => 'foo'], ['test_int' => 200, 'test_string' => 'bar'], ['test_int' => 300, 'test_string' => 'baz']]; + + /** @var DebugStack */ private $sqlLogger; protected function setUp() { parent::setUp(); - $table = new \Doctrine\DBAL\Schema\Table("caching"); + $table = new Table('caching'); $table->addColumn('test_int', 'integer'); - $table->addColumn('test_string', 'string', array('notnull' => false)); - $table->setPrimaryKey(array('test_int')); + $table->addColumn('test_string', 'string', ['notnull' => false]); + $table->setPrimaryKey(['test_int']); $sm = $this->_conn->getSchemaManager(); $sm->createTable($table); @@ -43,10 +42,10 @@ protected function setUp() $this->_conn->insert('caching', $row); } - $config = $this->_conn->getConfiguration(); - $config->setSQLLogger($this->sqlLogger = new DebugStack); + $config = $this->_conn->getConfiguration(); + $config->setSQLLogger($this->sqlLogger = new DebugStack()); - $cache = new \Doctrine\Common\Cache\ArrayCache; + $cache = new ArrayCache(); $config->setResultCacheImpl($cache); } @@ -67,7 +66,7 @@ public function testCacheFetchAssoc() public function testFetchNum() { - $expectedResult = array(); + $expectedResult = []; foreach ($this->expectedResult as $v) { $expectedResult[] = array_values($v); } @@ -77,7 +76,7 @@ public function testFetchNum() public function testFetchBoth() { - $expectedResult = array(); + $expectedResult = []; foreach ($this->expectedResult as $v) { $expectedResult[] = array_merge($v, array_values($v)); } @@ -87,7 +86,7 @@ public function testFetchBoth() public function testFetchColumn() { - $expectedResult = array(); + $expectedResult = []; foreach ($this->expectedResult as $v) { $expectedResult[] = array_shift($v); } @@ -97,17 +96,17 @@ public function testFetchColumn() public function testMixingFetch() { - $numExpectedResult = array(); + $numExpectedResult = []; foreach ($this->expectedResult as $v) { $numExpectedResult[] = array_values($v); } - $stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey")); + $stmt = $this->_conn->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); $data = $this->hydrateStmt($stmt, FetchMode::ASSOCIATIVE); self::assertEquals($this->expectedResult, $data); - $stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey")); + $stmt = $this->_conn->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); $data = $this->hydrateStmt($stmt, FetchMode::NUMERIC); @@ -123,10 +122,10 @@ public function testIteratorFetch() public function assertStandardAndIteratorFetchAreEqual($fetchMode) { - $stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey")); + $stmt = $this->_conn->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); $data = $this->hydrateStmt($stmt, $fetchMode); - $stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey")); + $stmt = $this->_conn->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); $data_iterator = $this->hydrateStmtIterator($stmt, $fetchMode); self::assertEquals($data, $data_iterator); @@ -134,17 +133,17 @@ public function assertStandardAndIteratorFetchAreEqual($fetchMode) public function testDontCloseNoCache() { - $stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey")); + $stmt = $this->_conn->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); - $data = array(); + $data = []; while ($row = $stmt->fetch(FetchMode::ASSOCIATIVE)) { $data[] = $row; } - $stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey")); + $stmt = $this->_conn->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); - $data = array(); + $data = []; while ($row = $stmt->fetch(FetchMode::NUMERIC)) { $data[] = $row; @@ -155,12 +154,12 @@ public function testDontCloseNoCache() public function testDontFinishNoCache() { - $stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey")); + $stmt = $this->_conn->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); $stmt->fetch(FetchMode::ASSOCIATIVE); $stmt->closeCursor(); - $stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey")); + $stmt = $this->_conn->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); $this->hydrateStmt($stmt, FetchMode::NUMERIC); @@ -169,47 +168,47 @@ public function testDontFinishNoCache() public function assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, $fetchMode) { - $stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey")); + $stmt = $this->_conn->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); self::assertEquals(2, $stmt->columnCount()); $data = $this->hydrateStmt($stmt, $fetchMode); self::assertEquals($expectedResult, $data); - $stmt = $this->_conn->executeQuery("SELECT * FROM caching ORDER BY test_int ASC", array(), array(), new QueryCacheProfile(10, "testcachekey")); + $stmt = $this->_conn->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); self::assertEquals(2, $stmt->columnCount()); $data = $this->hydrateStmt($stmt, $fetchMode); self::assertEquals($expectedResult, $data); - self::assertCount(1, $this->sqlLogger->queries, "just one dbal hit"); + self::assertCount(1, $this->sqlLogger->queries, 'just one dbal hit'); } public function testEmptyResultCache() { - $stmt = $this->_conn->executeQuery("SELECT * FROM caching WHERE test_int > 500", array(), array(), new QueryCacheProfile(10, "emptycachekey")); + $stmt = $this->_conn->executeQuery('SELECT * FROM caching WHERE test_int > 500', [], [], new QueryCacheProfile(10, 'emptycachekey')); $data = $this->hydrateStmt($stmt); - $stmt = $this->_conn->executeQuery("SELECT * FROM caching WHERE test_int > 500", array(), array(), new QueryCacheProfile(10, "emptycachekey")); + $stmt = $this->_conn->executeQuery('SELECT * FROM caching WHERE test_int > 500', [], [], new QueryCacheProfile(10, 'emptycachekey')); $data = $this->hydrateStmt($stmt); - self::assertCount(1, $this->sqlLogger->queries, "just one dbal hit"); + self::assertCount(1, $this->sqlLogger->queries, 'just one dbal hit'); } public function testChangeCacheImpl() { - $stmt = $this->_conn->executeQuery("SELECT * FROM caching WHERE test_int > 500", array(), array(), new QueryCacheProfile(10, "emptycachekey")); + $stmt = $this->_conn->executeQuery('SELECT * FROM caching WHERE test_int > 500', [], [], new QueryCacheProfile(10, 'emptycachekey')); $data = $this->hydrateStmt($stmt); - $secondCache = new \Doctrine\Common\Cache\ArrayCache; - $stmt = $this->_conn->executeQuery("SELECT * FROM caching WHERE test_int > 500", array(), array(), new QueryCacheProfile(10, "emptycachekey", $secondCache)); - $data = $this->hydrateStmt($stmt); + $secondCache = new ArrayCache(); + $stmt = $this->_conn->executeQuery('SELECT * FROM caching WHERE test_int > 500', [], [], new QueryCacheProfile(10, 'emptycachekey', $secondCache)); + $data = $this->hydrateStmt($stmt); - self::assertCount(2, $this->sqlLogger->queries, "two hits"); - self::assertCount(1, $secondCache->fetch("emptycachekey")); + self::assertCount(2, $this->sqlLogger->queries, 'two hits'); + self::assertCount(1, $secondCache->fetch('emptycachekey')); } private function hydrateStmt($stmt, $fetchMode = FetchMode::ASSOCIATIVE) { - $data = array(); + $data = []; while ($row = $stmt->fetch($fetchMode)) { $data[] = is_array($row) ? array_change_key_case($row, CASE_LOWER) : $row; } @@ -219,7 +218,7 @@ private function hydrateStmt($stmt, $fetchMode = FetchMode::ASSOCIATIVE) private function hydrateStmtIterator($stmt, $fetchMode = FetchMode::ASSOCIATIVE) { - $data = array(); + $data = []; $stmt->setFetchMode($fetchMode); foreach ($stmt as $row) { $data[] = is_array($row) ? array_change_key_case($row, CASE_LOWER) : $row; diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/Db2SchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/Db2SchemaManagerTest.php index e81cc4a3978..bb1f46d2787 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/Db2SchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/Db2SchemaManagerTest.php @@ -13,7 +13,7 @@ public function testGetBooleanColumn() { $table = new Table('boolean_column_test'); $table->addColumn('bool', 'boolean'); - $table->addColumn('bool_commented', 'boolean', array('comment' => "That's a comment")); + $table->addColumn('bool_commented', 'boolean', ['comment' => "That's a comment"]); $this->_sm->createTable($table); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/DrizzleSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/DrizzleSchemaManagerTest.php index 5b63b363a51..bbc1b5a5fdd 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/DrizzleSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/DrizzleSchemaManagerTest.php @@ -12,9 +12,9 @@ public function testListTableWithBinary() $table = new Table($tableName); $table->addColumn('id', 'integer'); - $table->addColumn('column_varbinary', 'binary', array()); - $table->addColumn('column_binary', 'binary', array('fixed' => true)); - $table->setPrimaryKey(array('id')); + $table->addColumn('column_varbinary', 'binary', []); + $table->addColumn('column_binary', 'binary', ['fixed' => true]); + $table->setPrimaryKey(['id']); $this->_sm->createTable($table); @@ -29,7 +29,7 @@ public function testListTableWithBinary() public function testColumnCollation() { - $table = new Table('test_collation'); + $table = new Table('test_collation'); $table->addOption('collate', $collation = 'utf8_unicode_ci'); $table->addColumn('id', 'integer'); $table->addColumn('text', 'text'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php index 9f246ad4119..80a89e29541 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Functional\Schema; +use DateTime; use Doctrine\DBAL\Platforms\MariaDb1027Platform; use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Schema\Comparator; @@ -17,23 +18,25 @@ protected function setUp() { parent::setUp(); - if ( ! Type::hasType('point')) { - Type::addType('point', MySqlPointType::class); + if (Type::hasType('point')) { + return; } + + Type::addType('point', MySqlPointType::class); } public function testSwitchPrimaryKeyColumns() { - $tableOld = new Table("switch_primary_key_columns"); + $tableOld = new Table('switch_primary_key_columns'); $tableOld->addColumn('foo_id', 'integer'); $tableOld->addColumn('bar_id', 'integer'); $this->_sm->createTable($tableOld); - $tableFetched = $this->_sm->listTableDetails("switch_primary_key_columns"); - $tableNew = clone $tableFetched; - $tableNew->setPrimaryKey(array('bar_id', 'foo_id')); + $tableFetched = $this->_sm->listTableDetails('switch_primary_key_columns'); + $tableNew = clone $tableFetched; + $tableNew->setPrimaryKey(['bar_id', 'foo_id']); - $comparator = new Comparator; + $comparator = new Comparator(); $this->_sm->alterTable($comparator->diffTable($tableFetched, $tableNew)); $table = $this->_sm->listTableDetails('switch_primary_key_columns'); @@ -47,31 +50,31 @@ public function testSwitchPrimaryKeyColumns() public function testDiffTableBug() { $schema = new Schema(); - $table = $schema->createTable('diffbug_routing_translations'); + $table = $schema->createTable('diffbug_routing_translations'); $table->addColumn('id', 'integer'); $table->addColumn('route', 'string'); $table->addColumn('locale', 'string'); $table->addColumn('attribute', 'string'); $table->addColumn('localized_value', 'string'); $table->addColumn('original_value', 'string'); - $table->setPrimaryKey(array('id')); - $table->addUniqueIndex(array('route', 'locale', 'attribute')); - $table->addIndex(array('localized_value')); // this is much more selective than the unique index + $table->setPrimaryKey(['id']); + $table->addUniqueIndex(['route', 'locale', 'attribute']); + $table->addIndex(['localized_value']); // this is much more selective than the unique index $this->_sm->createTable($table); - $tableFetched = $this->_sm->listTableDetails("diffbug_routing_translations"); + $tableFetched = $this->_sm->listTableDetails('diffbug_routing_translations'); - $comparator = new Comparator; - $diff = $comparator->diffTable($tableFetched, $table); + $comparator = new Comparator(); + $diff = $comparator->diffTable($tableFetched, $table); - self::assertFalse($diff, "no changes expected."); + self::assertFalse($diff, 'no changes expected.'); } public function testFulltextIndex() { $table = new Table('fulltext_index'); $table->addColumn('text', 'text'); - $table->addIndex(array('text'), 'f_index'); + $table->addIndex(['text'], 'f_index'); $table->addOption('engine', 'MyISAM'); $index = $table->getIndex('f_index'); @@ -88,7 +91,7 @@ public function testSpatialIndex() { $table = new Table('spatial_index'); $table->addColumn('point', 'point'); - $table->addIndex(array('point'), 's_index'); + $table->addIndex(['point'], 's_index'); $table->addOption('engine', 'MyISAM'); $index = $table->getIndex('s_index'); @@ -109,7 +112,7 @@ public function testAlterTableAddPrimaryKey() $table = new Table('alter_table_add_pk'); $table->addColumn('id', 'integer'); $table->addColumn('foo', 'integer'); - $table->addIndex(array('id'), 'idx_id'); + $table->addIndex(['id'], 'idx_id'); $this->_sm->createTable($table); @@ -117,11 +120,11 @@ public function testAlterTableAddPrimaryKey() $diffTable = clone $table; $diffTable->dropIndex('idx_id'); - $diffTable->setPrimaryKey(array('id')); + $diffTable->setPrimaryKey(['id']); $this->_sm->alterTable($comparator->diffTable($table, $diffTable)); - $table = $this->_sm->listTableDetails("alter_table_add_pk"); + $table = $this->_sm->listTableDetails('alter_table_add_pk'); self::assertFalse($table->hasIndex('idx_id')); self::assertTrue($table->hasPrimaryKey()); @@ -132,10 +135,10 @@ public function testAlterTableAddPrimaryKey() */ public function testDropPrimaryKeyWithAutoincrementColumn() { - $table = new Table("drop_primary_key"); - $table->addColumn('id', 'integer', array('autoincrement' => true)); + $table = new Table('drop_primary_key'); + $table->addColumn('id', 'integer', ['autoincrement' => true]); $table->addColumn('foo', 'integer'); - $table->setPrimaryKey(array('id', 'foo')); + $table->setPrimaryKey(['id', 'foo']); $this->_sm->dropAndCreateTable($table); @@ -147,7 +150,7 @@ public function testDropPrimaryKeyWithAutoincrementColumn() $this->_sm->alterTable($comparator->diffTable($table, $diffTable)); - $table = $this->_sm->listTableDetails("drop_primary_key"); + $table = $this->_sm->listTableDetails('drop_primary_key'); self::assertFalse($table->hasPrimaryKey()); self::assertFalse($table->getColumn('id')->getAutoincrement()); @@ -164,7 +167,7 @@ public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() ); } - $table = new Table("text_blob_default_value"); + $table = new Table('text_blob_default_value'); $table->addColumn('def_text', 'text', ['default' => 'def']); $table->addColumn('def_text_null', 'text', ['notnull' => false, 'default' => 'def']); $table->addColumn('def_blob', 'blob', ['default' => 'def']); @@ -172,7 +175,7 @@ public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() $this->_sm->dropAndCreateTable($table); - $onlineTable = $this->_sm->listTableDetails("text_blob_default_value"); + $onlineTable = $this->_sm->listTableDetails('text_blob_default_value'); self::assertNull($onlineTable->getColumn('def_text')->getDefault()); self::assertNull($onlineTable->getColumn('def_text_null')->getDefault()); @@ -185,7 +188,7 @@ public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() $this->_sm->alterTable($comparator->diffTable($table, $onlineTable)); - $onlineTable = $this->_sm->listTableDetails("text_blob_default_value"); + $onlineTable = $this->_sm->listTableDetails('text_blob_default_value'); self::assertNull($onlineTable->getColumn('def_text')->getDefault()); self::assertNull($onlineTable->getColumn('def_text_null')->getDefault()); @@ -197,7 +200,7 @@ public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() public function testColumnCollation() { - $table = new Table('test_collation'); + $table = new Table('test_collation'); $table->addOption('collate', $collation = 'latin1_swedish_ci'); $table->addOption('charset', 'latin1'); $table->addColumn('id', 'integer'); @@ -220,23 +223,23 @@ public function testColumnCollation() public function testListLobTypeColumns() { $tableName = 'lob_type_columns'; - $table = new Table($tableName); + $table = new Table($tableName); - $table->addColumn('col_tinytext', 'text', array('length' => MySqlPlatform::LENGTH_LIMIT_TINYTEXT)); - $table->addColumn('col_text', 'text', array('length' => MySqlPlatform::LENGTH_LIMIT_TEXT)); - $table->addColumn('col_mediumtext', 'text', array('length' => MySqlPlatform::LENGTH_LIMIT_MEDIUMTEXT)); + $table->addColumn('col_tinytext', 'text', ['length' => MySqlPlatform::LENGTH_LIMIT_TINYTEXT]); + $table->addColumn('col_text', 'text', ['length' => MySqlPlatform::LENGTH_LIMIT_TEXT]); + $table->addColumn('col_mediumtext', 'text', ['length' => MySqlPlatform::LENGTH_LIMIT_MEDIUMTEXT]); $table->addColumn('col_longtext', 'text'); - $table->addColumn('col_tinyblob', 'text', array('length' => MySqlPlatform::LENGTH_LIMIT_TINYBLOB)); - $table->addColumn('col_blob', 'blob', array('length' => MySqlPlatform::LENGTH_LIMIT_BLOB)); - $table->addColumn('col_mediumblob', 'blob', array('length' => MySqlPlatform::LENGTH_LIMIT_MEDIUMBLOB)); + $table->addColumn('col_tinyblob', 'text', ['length' => MySqlPlatform::LENGTH_LIMIT_TINYBLOB]); + $table->addColumn('col_blob', 'blob', ['length' => MySqlPlatform::LENGTH_LIMIT_BLOB]); + $table->addColumn('col_mediumblob', 'blob', ['length' => MySqlPlatform::LENGTH_LIMIT_MEDIUMBLOB]); $table->addColumn('col_longblob', 'blob'); $this->_sm->dropAndCreateTable($table); - $platform = $this->_sm->getDatabasePlatform(); + $platform = $this->_sm->getDatabasePlatform(); $offlineColumns = $table->getColumns(); - $onlineColumns = $this->_sm->listTableColumns($tableName); + $onlineColumns = $this->_sm->listTableColumns($tableName); self::assertSame( $platform->getClobTypeDeclarationSQL($offlineColumns['col_tinytext']->toArray()), @@ -289,7 +292,7 @@ public function testDiffListGuidTableColumn() self::assertFalse( $comparator->diffTable($offlineTable, $onlineTable), - "No differences should be detected with the offline vs online schema." + 'No differences should be detected with the offline vs online schema.' ); } @@ -299,10 +302,10 @@ public function testDiffListGuidTableColumn() public function testListDecimalTypeColumns() { $tableName = 'test_list_decimal_columns'; - $table = new Table($tableName); + $table = new Table($tableName); $table->addColumn('col', 'decimal'); - $table->addColumn('col_unsigned', 'decimal', array('unsigned' => true)); + $table->addColumn('col_unsigned', 'decimal', ['unsigned' => true]); $this->_sm->dropAndCreateTable($table); @@ -320,10 +323,10 @@ public function testListDecimalTypeColumns() public function testListFloatTypeColumns() { $tableName = 'test_list_float_columns'; - $table = new Table($tableName); + $table = new Table($tableName); $table->addColumn('col', 'float'); - $table->addColumn('col_unsigned', 'float', array('unsigned' => true)); + $table->addColumn('col_unsigned', 'float', ['unsigned' => true]); $this->_sm->dropAndCreateTable($table); @@ -350,7 +353,7 @@ public function testColumnDefaultCurrentTimestamp() : void { $platform = $this->_sm->getDatabasePlatform(); - $table = new Table("test_column_defaults_current_timestamp"); + $table = new Table('test_column_defaults_current_timestamp'); $currentTimeStampSql = $platform->getCurrentTimestampSQL(); @@ -359,19 +362,19 @@ public function testColumnDefaultCurrentTimestamp() : void $this->_sm->dropAndCreateTable($table); - $onlineTable = $this->_sm->listTableDetails("test_column_defaults_current_timestamp"); + $onlineTable = $this->_sm->listTableDetails('test_column_defaults_current_timestamp'); self::assertSame($currentTimeStampSql, $onlineTable->getColumn('col_datetime')->getDefault()); self::assertSame($currentTimeStampSql, $onlineTable->getColumn('col_datetime_nullable')->getDefault()); $comparator = new Comparator(); $diff = $comparator->diffTable($table, $onlineTable); - self::assertFalse($diff, "Tables should be identical with column defaults."); + self::assertFalse($diff, 'Tables should be identical with column defaults.'); } public function testColumnDefaultsAreValid() { - $table = new Table("test_column_defaults_are_valid"); + $table = new Table('test_column_defaults_are_valid'); $currentTimeStampSql = $this->_sm->getDatabasePlatform()->getCurrentTimestampSQL(); $table->addColumn('col_datetime', 'datetime', ['default' => $currentTimeStampSql]); @@ -385,14 +388,14 @@ public function testColumnDefaultsAreValid() $this->_sm->dropAndCreateTable($table); $this->_conn->executeUpdate( - "INSERT INTO test_column_defaults_are_valid () VALUES()" + 'INSERT INTO test_column_defaults_are_valid () VALUES()' ); $row = $this->_conn->fetchAssoc( 'SELECT *, DATEDIFF(CURRENT_TIMESTAMP(), col_datetime) as diff_seconds FROM test_column_defaults_are_valid' ); - self::assertInstanceOf(\DateTime::class, \DateTime::createFromFormat('Y-m-d H:i:s', $row['col_datetime'])); + self::assertInstanceOf(DateTime::class, DateTime::createFromFormat('Y-m-d H:i:s', $row['col_datetime'])); self::assertNull($row['col_datetime_null']); self::assertSame('2012-12-12', $row['col_date']); self::assertSame('A', $row['col_string']); @@ -414,13 +417,13 @@ public function testColumnDefaultsAreValid() */ public function testColumnDefaultValuesCurrentTimeAndDate() : void { - if ( ! $this->_sm->getDatabasePlatform() instanceof MariaDb1027Platform) { + if (! $this->_sm->getDatabasePlatform() instanceof MariaDb1027Platform) { $this->markTestSkipped('Only relevant for MariaDb102Platform.'); } $platform = $this->_sm->getDatabasePlatform(); - $table = new Table("test_column_defaults_current_time_and_date"); + $table = new Table('test_column_defaults_current_time_and_date'); $currentTimestampSql = $platform->getCurrentTimestampSQL(); $currentTimeSql = $platform->getCurrentTimeSQL(); @@ -432,7 +435,7 @@ public function testColumnDefaultValuesCurrentTimeAndDate() : void $this->_sm->dropAndCreateTable($table); - $onlineTable = $this->_sm->listTableDetails("test_column_defaults_current_time_and_date"); + $onlineTable = $this->_sm->listTableDetails('test_column_defaults_current_time_and_date'); self::assertSame($currentTimestampSql, $onlineTable->getColumn('col_datetime')->getDefault()); self::assertSame($currentDateSql, $onlineTable->getColumn('col_date')->getDefault()); @@ -441,13 +444,14 @@ public function testColumnDefaultValuesCurrentTimeAndDate() : void $comparator = new Comparator(); $diff = $comparator->diffTable($table, $onlineTable); - self::assertFalse($diff, "Tables should be identical with column defauts time and date."); + 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 @@ -457,8 +461,10 @@ public function testEnsureDefaultsAreUnescapedFromSchemaIntrospection() : void $escapeSequences = [ "\\0", // An ASCII NUL (X'00') character - "\\'", "''", // Single quote - '\\"', '""', // Double quote + "\\'", + "''", // Single quote + '\\"', + '""', // Double quote '\\b', // A backspace character '\\n', // A new-line character '\\r', // A carriage return character @@ -475,7 +481,7 @@ public function testEnsureDefaultsAreUnescapedFromSchemaIntrospection() : void col1 VARCHAR(255) NULL DEFAULT {$platform->quoteStringLiteral($default)} )"; $this->_conn->query($sql); - $onlineTable = $this->_sm->listTableDetails("test_column_defaults_with_create"); + $onlineTable = $this->_sm->listTableDetails('test_column_defaults_with_create'); self::assertSame($default, $onlineTable->getColumn('col1')->getDefault()); } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php index d1f0245b015..bc9327677f2 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php @@ -14,15 +14,15 @@ protected function setUp() { parent::setUp(); - if(!isset($GLOBALS['db_username'])) { + if (! isset($GLOBALS['db_username'])) { $this->markTestSkipped('Foo'); } $username = $GLOBALS['db_username']; - $query = "GRANT ALL PRIVILEGES TO ".$username; + $query = 'GRANT ALL PRIVILEGES TO ' . $username; - $conn = \Doctrine\Tests\TestUtil::getTempConnection(); + $conn = TestUtil::getTempConnection(); $conn->executeUpdate($query); } @@ -43,11 +43,11 @@ public function testListTableWithBinary() { $tableName = 'test_binary_table'; - $table = new \Doctrine\DBAL\Schema\Table($tableName); + $table = new Table($tableName); $table->addColumn('id', 'integer'); - $table->addColumn('column_varbinary', 'binary', array()); - $table->addColumn('column_binary', 'binary', array('fixed' => true)); - $table->setPrimaryKey(array('id')); + $table->addColumn('column_varbinary', 'binary', []); + $table->addColumn('column_binary', 'binary', ['fixed' => true]); + $table->setPrimaryKey(['id']); $this->_sm->createTable($table); @@ -73,7 +73,7 @@ public function testAlterTableColumnNotNull() $table->addColumn('id', 'integer'); $table->addColumn('foo', 'integer'); $table->addColumn('bar', 'string'); - $table->setPrimaryKey(array('id')); + $table->setPrimaryKey(['id']); $this->_sm->dropAndCreateTable($table); @@ -84,8 +84,8 @@ public function testAlterTableColumnNotNull() self::assertTrue($columns['bar']->getNotnull()); $diffTable = clone $table; - $diffTable->changeColumn('foo', array('notnull' => false)); - $diffTable->changeColumn('bar', array('length' => 1024)); + $diffTable->changeColumn('foo', ['notnull' => false]); + $diffTable->changeColumn('bar', ['length' => 1024]); $this->_sm->alterTable($comparator->diffTable($table, $diffTable)); @@ -114,36 +114,36 @@ public function testListDatabases() */ public function testListTableDetailsWithDifferentIdentifierQuotingRequirements() { - $primaryTableName = '"Primary_Table"'; + $primaryTableName = '"Primary_Table"'; $offlinePrimaryTable = new Schema\Table($primaryTableName); $offlinePrimaryTable->addColumn( '"Id"', 'integer', - array('autoincrement' => true, 'comment' => 'Explicit casing.') + ['autoincrement' => true, 'comment' => 'Explicit casing.'] ); - $offlinePrimaryTable->addColumn('select', 'integer', array('comment' => 'Reserved keyword.')); - $offlinePrimaryTable->addColumn('foo', 'integer', array('comment' => 'Implicit uppercasing.')); + $offlinePrimaryTable->addColumn('select', 'integer', ['comment' => 'Reserved keyword.']); + $offlinePrimaryTable->addColumn('foo', 'integer', ['comment' => 'Implicit uppercasing.']); $offlinePrimaryTable->addColumn('BAR', 'integer'); $offlinePrimaryTable->addColumn('"BAZ"', 'integer'); - $offlinePrimaryTable->addIndex(array('select'), 'from'); - $offlinePrimaryTable->addIndex(array('foo'), 'foo_index'); - $offlinePrimaryTable->addIndex(array('BAR'), 'BAR_INDEX'); - $offlinePrimaryTable->addIndex(array('"BAZ"'), 'BAZ_INDEX'); - $offlinePrimaryTable->setPrimaryKey(array('"Id"')); + $offlinePrimaryTable->addIndex(['select'], 'from'); + $offlinePrimaryTable->addIndex(['foo'], 'foo_index'); + $offlinePrimaryTable->addIndex(['BAR'], 'BAR_INDEX'); + $offlinePrimaryTable->addIndex(['"BAZ"'], 'BAZ_INDEX'); + $offlinePrimaryTable->setPrimaryKey(['"Id"']); - $foreignTableName = 'foreign'; + $foreignTableName = 'foreign'; $offlineForeignTable = new Schema\Table($foreignTableName); - $offlineForeignTable->addColumn('id', 'integer', array('autoincrement' => true)); + $offlineForeignTable->addColumn('id', 'integer', ['autoincrement' => true]); $offlineForeignTable->addColumn('"Fk"', 'integer'); - $offlineForeignTable->addIndex(array('"Fk"'), '"Fk_index"'); + $offlineForeignTable->addIndex(['"Fk"'], '"Fk_index"'); $offlineForeignTable->addForeignKeyConstraint( $primaryTableName, - array('"Fk"'), - array('"Id"'), - array(), + ['"Fk"'], + ['"Id"'], + [], '"Primary_Table_Fk"' ); - $offlineForeignTable->setPrimaryKey(array('id')); + $offlineForeignTable->setPrimaryKey(['id']); $this->_sm->tryMethod('dropTable', $foreignTableName); $this->_sm->tryMethod('dropTable', $primaryTableName); @@ -162,7 +162,7 @@ public function testListTableDetailsWithDifferentIdentifierQuotingRequirements() self::assertTrue($onlinePrimaryTable->hasColumn('"Id"')); self::assertSame('"Id"', $onlinePrimaryTable->getColumn('"Id"')->getQuotedName($platform)); self::assertTrue($onlinePrimaryTable->hasPrimaryKey()); - self::assertSame(array('"Id"'), $onlinePrimaryTable->getPrimaryKey()->getQuotedColumns($platform)); + self::assertSame(['"Id"'], $onlinePrimaryTable->getPrimaryKey()->getQuotedColumns($platform)); self::assertTrue($onlinePrimaryTable->hasColumn('select')); self::assertSame('"select"', $onlinePrimaryTable->getColumn('select')->getQuotedName($platform)); @@ -178,32 +178,32 @@ public function testListTableDetailsWithDifferentIdentifierQuotingRequirements() self::assertTrue($onlinePrimaryTable->hasIndex('from')); self::assertTrue($onlinePrimaryTable->getIndex('from')->hasColumnAtPosition('"select"')); - self::assertSame(array('"select"'), $onlinePrimaryTable->getIndex('from')->getQuotedColumns($platform)); + self::assertSame(['"select"'], $onlinePrimaryTable->getIndex('from')->getQuotedColumns($platform)); self::assertTrue($onlinePrimaryTable->hasIndex('foo_index')); self::assertTrue($onlinePrimaryTable->getIndex('foo_index')->hasColumnAtPosition('foo')); - self::assertSame(array('FOO'), $onlinePrimaryTable->getIndex('foo_index')->getQuotedColumns($platform)); + self::assertSame(['FOO'], $onlinePrimaryTable->getIndex('foo_index')->getQuotedColumns($platform)); self::assertTrue($onlinePrimaryTable->hasIndex('BAR_INDEX')); self::assertTrue($onlinePrimaryTable->getIndex('BAR_INDEX')->hasColumnAtPosition('BAR')); - self::assertSame(array('BAR'), $onlinePrimaryTable->getIndex('BAR_INDEX')->getQuotedColumns($platform)); + self::assertSame(['BAR'], $onlinePrimaryTable->getIndex('BAR_INDEX')->getQuotedColumns($platform)); self::assertTrue($onlinePrimaryTable->hasIndex('BAZ_INDEX')); self::assertTrue($onlinePrimaryTable->getIndex('BAZ_INDEX')->hasColumnAtPosition('"BAZ"')); - self::assertSame(array('BAZ'), $onlinePrimaryTable->getIndex('BAZ_INDEX')->getQuotedColumns($platform)); + self::assertSame(['BAZ'], $onlinePrimaryTable->getIndex('BAZ_INDEX')->getQuotedColumns($platform)); // Foreign table assertions self::assertTrue($onlineForeignTable->hasColumn('id')); self::assertSame('ID', $onlineForeignTable->getColumn('id')->getQuotedName($platform)); self::assertTrue($onlineForeignTable->hasPrimaryKey()); - self::assertSame(array('ID'), $onlineForeignTable->getPrimaryKey()->getQuotedColumns($platform)); + self::assertSame(['ID'], $onlineForeignTable->getPrimaryKey()->getQuotedColumns($platform)); self::assertTrue($onlineForeignTable->hasColumn('"Fk"')); self::assertSame('"Fk"', $onlineForeignTable->getColumn('"Fk"')->getQuotedName($platform)); self::assertTrue($onlineForeignTable->hasIndex('"Fk_index"')); self::assertTrue($onlineForeignTable->getIndex('"Fk_index"')->hasColumnAtPosition('"Fk"')); - self::assertSame(array('"Fk"'), $onlineForeignTable->getIndex('"Fk_index"')->getQuotedColumns($platform)); + self::assertSame(['"Fk"'], $onlineForeignTable->getIndex('"Fk_index"')->getQuotedColumns($platform)); self::assertTrue($onlineForeignTable->hasForeignKey('"Primary_Table_Fk"')); self::assertSame( @@ -211,11 +211,11 @@ public function testListTableDetailsWithDifferentIdentifierQuotingRequirements() $onlineForeignTable->getForeignKey('"Primary_Table_Fk"')->getQuotedForeignTableName($platform) ); self::assertSame( - array('"Fk"'), + ['"Fk"'], $onlineForeignTable->getForeignKey('"Primary_Table_Fk"')->getQuotedLocalColumns($platform) ); self::assertSame( - array('"Id"'), + ['"Id"'], $onlineForeignTable->getForeignKey('"Primary_Table_Fk"')->getQuotedForeignColumns($platform) ); } @@ -240,18 +240,18 @@ public function testListTableIndexesPrimaryKeyConstraintNameDiffersFromIndexName { $table = new Table('list_table_indexes_pk_id_test'); $table->setSchemaConfig($this->_sm->createSchemaConfig()); - $table->addColumn('id', 'integer', array('notnull' => true)); - $table->addUniqueIndex(array('id'), 'id_unique_index'); + $table->addColumn('id', 'integer', ['notnull' => true]); + $table->addUniqueIndex(['id'], 'id_unique_index'); $this->_sm->dropAndCreateTable($table); // Adding a primary key on already indexed columns // Oracle will reuse the unique index, which cause a constraint name differing from the index name - $this->_sm->createConstraint(new Schema\Index('id_pk_id_index', array('id'), true, true), 'list_table_indexes_pk_id_test'); + $this->_sm->createConstraint(new Schema\Index('id_pk_id_index', ['id'], true, true), 'list_table_indexes_pk_id_test'); $tableIndexes = $this->_sm->listTableIndexes('list_table_indexes_pk_id_test'); self::assertArrayHasKey('primary', $tableIndexes, 'listTableIndexes() has to return a "primary" array key.'); - self::assertEquals(array('id'), array_map('strtolower', $tableIndexes['primary']->getColumns())); + self::assertEquals(['id'], array_map('strtolower', $tableIndexes['primary']->getColumns())); self::assertTrue($tableIndexes['primary']->isUnique()); self::assertTrue($tableIndexes['primary']->isPrimary()); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php index 40d0f03f108..4dc76ba1da0 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Platforms\PostgreSQL94Platform; use Doctrine\DBAL\Schema; use Doctrine\DBAL\Schema\Comparator; +use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Types\Type; @@ -20,7 +21,7 @@ protected function tearDown() { parent::tearDown(); - if (!$this->_conn) { + if (! $this->_conn) { return; } @@ -55,10 +56,10 @@ public function testGetSchemaNames() */ public function testSupportDomainTypeFallback() { - $createDomainTypeSQL = "CREATE DOMAIN MyMoney AS DECIMAL(18,2)"; + $createDomainTypeSQL = 'CREATE DOMAIN MyMoney AS DECIMAL(18,2)'; $this->_conn->exec($createDomainTypeSQL); - $createTableSQL = "CREATE TABLE domain_type_test (id INT PRIMARY KEY, value MyMoney)"; + $createTableSQL = 'CREATE TABLE domain_type_test (id INT PRIMARY KEY, value MyMoney)'; $this->_conn->exec($createTableSQL); $table = $this->_conn->getSchemaManager()->listTableDetails('domain_type_test'); @@ -76,8 +77,8 @@ public function testSupportDomainTypeFallback() */ public function testDetectsAutoIncrement() { - $autoincTable = new \Doctrine\DBAL\Schema\Table('autoinc_table'); - $column = $autoincTable->addColumn('id', 'integer'); + $autoincTable = new Table('autoinc_table'); + $column = $autoincTable->addColumn('id', 'integer'); $column->setAutoincrement(true); $this->_sm->createTable($autoincTable); $autoincTable = $this->_sm->listTableDetails('autoinc_table'); @@ -90,24 +91,24 @@ public function testDetectsAutoIncrement() */ public function testAlterTableAutoIncrementAdd() { - $tableFrom = new \Doctrine\DBAL\Schema\Table('autoinc_table_add'); - $column = $tableFrom->addColumn('id', 'integer'); + $tableFrom = new Table('autoinc_table_add'); + $column = $tableFrom->addColumn('id', 'integer'); $this->_sm->createTable($tableFrom); $tableFrom = $this->_sm->listTableDetails('autoinc_table_add'); self::assertFalse($tableFrom->getColumn('id')->getAutoincrement()); - $tableTo = new \Doctrine\DBAL\Schema\Table('autoinc_table_add'); - $column = $tableTo->addColumn('id', 'integer'); + $tableTo = new Table('autoinc_table_add'); + $column = $tableTo->addColumn('id', 'integer'); $column->setAutoincrement(true); - $c = new \Doctrine\DBAL\Schema\Comparator(); + $c = new Comparator(); $diff = $c->diffTable($tableFrom, $tableTo); - $sql = $this->_conn->getDatabasePlatform()->getAlterTableSQL($diff); - self::assertEquals(array( - "CREATE SEQUENCE autoinc_table_add_id_seq", + $sql = $this->_conn->getDatabasePlatform()->getAlterTableSQL($diff); + self::assertEquals([ + 'CREATE SEQUENCE autoinc_table_add_id_seq', "SELECT setval('autoinc_table_add_id_seq', (SELECT MAX(id) FROM autoinc_table_add))", "ALTER TABLE autoinc_table_add ALTER id SET DEFAULT nextval('autoinc_table_add_id_seq')", - ), $sql); + ], $sql); $this->_sm->alterTable($diff); $tableFinal = $this->_sm->listTableDetails('autoinc_table_add'); @@ -119,20 +120,20 @@ public function testAlterTableAutoIncrementAdd() */ public function testAlterTableAutoIncrementDrop() { - $tableFrom = new \Doctrine\DBAL\Schema\Table('autoinc_table_drop'); - $column = $tableFrom->addColumn('id', 'integer'); + $tableFrom = new Table('autoinc_table_drop'); + $column = $tableFrom->addColumn('id', 'integer'); $column->setAutoincrement(true); $this->_sm->createTable($tableFrom); $tableFrom = $this->_sm->listTableDetails('autoinc_table_drop'); self::assertTrue($tableFrom->getColumn('id')->getAutoincrement()); - $tableTo = new \Doctrine\DBAL\Schema\Table('autoinc_table_drop'); - $column = $tableTo->addColumn('id', 'integer'); + $tableTo = new Table('autoinc_table_drop'); + $column = $tableTo->addColumn('id', 'integer'); - $c = new \Doctrine\DBAL\Schema\Comparator(); + $c = new Comparator(); $diff = $c->diffTable($tableFrom, $tableTo); - self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $diff, "There should be a difference and not false being returned from the table comparison"); - self::assertEquals(array("ALTER TABLE autoinc_table_drop ALTER id DROP DEFAULT"), $this->_conn->getDatabasePlatform()->getAlterTableSQL($diff)); + self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $diff, 'There should be a difference and not false being returned from the table comparison'); + self::assertEquals(['ALTER TABLE autoinc_table_drop ALTER id DROP DEFAULT'], $this->_conn->getDatabasePlatform()->getAlterTableSQL($diff)); $this->_sm->alterTable($diff); $tableFinal = $this->_sm->listTableDetails('autoinc_table_drop'); @@ -146,31 +147,31 @@ public function testTableWithSchema() { $this->_conn->exec('CREATE SCHEMA nested'); - $nestedRelatedTable = new \Doctrine\DBAL\Schema\Table('nested.schemarelated'); - $column = $nestedRelatedTable->addColumn('id', 'integer'); + $nestedRelatedTable = new Table('nested.schemarelated'); + $column = $nestedRelatedTable->addColumn('id', 'integer'); $column->setAutoincrement(true); - $nestedRelatedTable->setPrimaryKey(array('id')); + $nestedRelatedTable->setPrimaryKey(['id']); - $nestedSchemaTable = new \Doctrine\DBAL\Schema\Table('nested.schematable'); - $column = $nestedSchemaTable->addColumn('id', 'integer'); + $nestedSchemaTable = new Table('nested.schematable'); + $column = $nestedSchemaTable->addColumn('id', 'integer'); $column->setAutoincrement(true); - $nestedSchemaTable->setPrimaryKey(array('id')); - $nestedSchemaTable->addUnnamedForeignKeyConstraint($nestedRelatedTable, array('id'), array('id')); + $nestedSchemaTable->setPrimaryKey(['id']); + $nestedSchemaTable->addUnnamedForeignKeyConstraint($nestedRelatedTable, ['id'], ['id']); $this->_sm->createTable($nestedRelatedTable); $this->_sm->createTable($nestedSchemaTable); $tables = $this->_sm->listTableNames(); - self::assertContains('nested.schematable', $tables, "The table should be detected with its non-public schema."); + self::assertContains('nested.schematable', $tables, 'The table should be detected with its non-public schema.'); $nestedSchemaTable = $this->_sm->listTableDetails('nested.schematable'); self::assertTrue($nestedSchemaTable->hasColumn('id')); - self::assertEquals(array('id'), $nestedSchemaTable->getPrimaryKey()->getColumns()); + self::assertEquals(['id'], $nestedSchemaTable->getPrimaryKey()->getColumns()); $relatedFks = $nestedSchemaTable->getForeignKeys(); self::assertCount(1, $relatedFks); $relatedFk = array_pop($relatedFks); - self::assertEquals("nested.schemarelated", $relatedFk->getForeignTableName()); + self::assertEquals('nested.schemarelated', $relatedFk->getForeignTableName()); } /** @@ -188,10 +189,10 @@ public function testReturnQuotedAssets() $table = $this->_sm->listTableDetails('dbal91_something'); self::assertEquals( - array( - "CREATE TABLE dbal91_something (id INT NOT NULL, \"table\" INT DEFAULT NULL, PRIMARY KEY(id))", - "CREATE INDEX IDX_A9401304ECA7352B ON dbal91_something (\"table\")", - ), + [ + 'CREATE TABLE dbal91_something (id INT NOT NULL, "table" INT DEFAULT NULL, PRIMARY KEY(id))', + 'CREATE INDEX IDX_A9401304ECA7352B ON dbal91_something ("table")', + ], $this->_conn->getDatabasePlatform()->getCreateTableSQL($table) ); } @@ -201,11 +202,11 @@ public function testReturnQuotedAssets() */ public function testFilterSchemaExpression() { - $testTable = new \Doctrine\DBAL\Schema\Table('dbal204_test_prefix'); - $column = $testTable->addColumn('id', 'integer'); + $testTable = new Table('dbal204_test_prefix'); + $column = $testTable->addColumn('id', 'integer'); $this->_sm->createTable($testTable); - $testTable = new \Doctrine\DBAL\Schema\Table('dbal204_without_prefix'); - $column = $testTable->addColumn('id', 'integer'); + $testTable = new Table('dbal204_without_prefix'); + $column = $testTable->addColumn('id', 'integer'); $this->_sm->createTable($testTable); $this->_conn->getConfiguration()->setFilterSchemaAssetsExpression('#^dbal204_#'); @@ -219,32 +220,37 @@ public function testFilterSchemaExpression() public function testListForeignKeys() { - if(!$this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { + if (! $this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped('Does not support foreign key constraints.'); } - $fkOptions = array('SET NULL', 'SET DEFAULT', 'NO ACTION','CASCADE', 'RESTRICT'); - $foreignKeys = array(); - $fkTable = $this->getTestTable('test_create_fk1'); - for($i = 0; $i < count($fkOptions); $i++) { + $fkOptions = ['SET NULL', 'SET DEFAULT', 'NO ACTION','CASCADE', 'RESTRICT']; + $foreignKeys = []; + $fkTable = $this->getTestTable('test_create_fk1'); + for ($i = 0; $i < count($fkOptions); $i++) { $fkTable->addColumn("foreign_key_test$i", 'integer'); - $foreignKeys[] = new \Doctrine\DBAL\Schema\ForeignKeyConstraint( - array("foreign_key_test$i"), 'test_create_fk2', array('id'), "foreign_key_test_$i"."_fk", array('onDelete' => $fkOptions[$i])); + $foreignKeys[] = new ForeignKeyConstraint( + ["foreign_key_test$i"], + 'test_create_fk2', + ['id'], + "foreign_key_test_$i" . '_fk', + ['onDelete' => $fkOptions[$i]] + ); } $this->_sm->dropAndCreateTable($fkTable); $this->createTestTable('test_create_fk2'); - foreach($foreignKeys as $foreignKey) { + foreach ($foreignKeys as $foreignKey) { $this->_sm->createForeignKey($foreignKey, 'test_create_fk1'); } $fkeys = $this->_sm->listTableForeignKeys('test_create_fk1'); - self::assertEquals(count($foreignKeys), count($fkeys), "Table 'test_create_fk1' has to have " . count($foreignKeys) . " foreign keys."); + self::assertEquals(count($foreignKeys), count($fkeys), "Table 'test_create_fk1' has to have " . count($foreignKeys) . ' foreign keys.'); for ($i = 0; $i < count($fkeys); $i++) { - self::assertEquals(array("foreign_key_test$i"), array_map('strtolower', $fkeys[$i]->getLocalColumns())); - self::assertEquals(array('id'), array_map('strtolower', $fkeys[$i]->getForeignColumns())); + self::assertEquals(["foreign_key_test$i"], array_map('strtolower', $fkeys[$i]->getLocalColumns())); + self::assertEquals(['id'], array_map('strtolower', $fkeys[$i]->getForeignColumns())); self::assertEquals('test_create_fk2', strtolower($fkeys[0]->getForeignTableName())); - if ($foreignKeys[$i]->getOption('onDelete') == 'NO ACTION') { - self::assertFalse($fkeys[$i]->hasOption('onDelete'), 'Unexpected option: '. $fkeys[$i]->getOption('onDelete')); + if ($foreignKeys[$i]->getOption('onDelete') === 'NO ACTION') { + self::assertFalse($fkeys[$i]->hasOption('onDelete'), 'Unexpected option: ' . $fkeys[$i]->getOption('onDelete')); } else { self::assertEquals($foreignKeys[$i]->getOption('onDelete'), $fkeys[$i]->getOption('onDelete')); } @@ -256,10 +262,10 @@ public function testListForeignKeys() */ public function testDefaultValueCharacterVarying() { - $testTable = new \Doctrine\DBAL\Schema\Table('dbal511_default'); + $testTable = new Table('dbal511_default'); $testTable->addColumn('id', 'integer'); - $testTable->addColumn('def', 'string', array('default' => 'foo')); - $testTable->setPrimaryKey(array('id')); + $testTable->addColumn('def', 'string', ['default' => 'foo']); + $testTable->setPrimaryKey(['id']); $this->_sm->createTable($testTable); @@ -273,15 +279,15 @@ public function testDefaultValueCharacterVarying() */ public function testBooleanDefault() { - $table = new \Doctrine\DBAL\Schema\Table('ddc2843_bools'); + $table = new Table('ddc2843_bools'); $table->addColumn('id', 'integer'); - $table->addColumn('checked', 'boolean', array('default' => false)); + $table->addColumn('checked', 'boolean', ['default' => false]); $this->_sm->createTable($table); $databaseTable = $this->_sm->listTableDetails($table->getName()); - $c = new \Doctrine\DBAL\Schema\Comparator(); + $c = new Comparator(); $diff = $c->diffTable($table, $databaseTable); self::assertFalse($diff); @@ -291,11 +297,11 @@ public function testListTableWithBinary() { $tableName = 'test_binary_table'; - $table = new \Doctrine\DBAL\Schema\Table($tableName); + $table = new Table($tableName); $table->addColumn('id', 'integer'); - $table->addColumn('column_varbinary', 'binary', array()); - $table->addColumn('column_binary', 'binary', array('fixed' => true)); - $table->setPrimaryKey(array('id')); + $table->addColumn('column_varbinary', 'binary', []); + $table->addColumn('column_binary', 'binary', ['fixed' => true]); + $table->setPrimaryKey(['id']); $this->_sm->createTable($table); @@ -314,8 +320,8 @@ public function testListQuotedTable() $offlineTable->addColumn('id', 'integer'); $offlineTable->addColumn('username', 'string'); $offlineTable->addColumn('fk', 'integer'); - $offlineTable->setPrimaryKey(array('id')); - $offlineTable->addForeignKeyConstraint($offlineTable, array('fk'), array('id')); + $offlineTable->setPrimaryKey(['id']); + $offlineTable->addForeignKeyConstraint($offlineTable, ['fk'], ['id']); $this->_sm->dropAndCreateTable($offlineTable); @@ -330,8 +336,8 @@ public function testListTablesExcludesViews() { $this->createTestTable('list_tables_excludes_views'); - $name = "list_tables_excludes_views_test_view"; - $sql = "SELECT * from list_tables_excludes_views"; + $name = 'list_tables_excludes_views_test_view'; + $sql = 'SELECT * from list_tables_excludes_views'; $view = new Schema\View($name, $sql); @@ -342,9 +348,11 @@ public function testListTablesExcludesViews() $foundTable = false; foreach ($tables as $table) { self::assertInstanceOf('Doctrine\DBAL\Schema\Table', $table, 'No Table instance was found in tables array.'); - if (strtolower($table->getName()) == 'list_tables_excludes_views_test_view') { - $foundTable = true; + if (strtolower($table->getName()) !== 'list_tables_excludes_views_test_view') { + continue; } + + $foundTable = true; } self::assertFalse($foundTable, 'View "list_tables_excludes_views_test_view" must not be found in table list'); @@ -359,7 +367,7 @@ public function testPartialIndexes() $offlineTable->addColumn('id', 'integer'); $offlineTable->addColumn('name', 'string'); $offlineTable->addColumn('email', 'string'); - $offlineTable->addUniqueIndex(array('id', 'name'), 'simple_partial_index', array('where' => '(id IS NULL)')); + $offlineTable->addUniqueIndex(['id', 'name'], 'simple_partial_index', ['where' => '(id IS NULL)']); $this->_sm->dropAndCreateTable($offlineTable); @@ -376,10 +384,10 @@ public function testPartialIndexes() /** * @dataProvider jsonbColumnTypeProvider */ - public function testJsonbColumn(string $type): void + public function testJsonbColumn(string $type) : void { - if (!$this->_sm->getDatabasePlatform() instanceof PostgreSQL94Platform) { - $this->markTestSkipped("Requires PostgresSQL 9.4+"); + if (! $this->_sm->getDatabasePlatform() instanceof PostgreSQL94Platform) { + $this->markTestSkipped('Requires PostgresSQL 9.4+'); return; } @@ -394,7 +402,7 @@ public function testJsonbColumn(string $type): void self::assertTrue(true, $columns['foo']->getPlatformOption('jsonb')); } - public function jsonbColumnTypeProvider(): array + public function jsonbColumnTypeProvider() : array { return [ [Type::JSON], @@ -408,12 +416,12 @@ public function jsonbColumnTypeProvider(): array public function testListNegativeColumnDefaultValue() { $table = new Schema\Table('test_default_negative'); - $table->addColumn('col_smallint', 'smallint', array('default' => -1)); - $table->addColumn('col_integer', 'integer', array('default' => -1)); - $table->addColumn('col_bigint', 'bigint', array('default' => -1)); - $table->addColumn('col_float', 'float', array('default' => -1.1)); - $table->addColumn('col_decimal', 'decimal', array('default' => -1.1)); - $table->addColumn('col_string', 'string', array('default' => '(-1)')); + $table->addColumn('col_smallint', 'smallint', ['default' => -1]); + $table->addColumn('col_integer', 'integer', ['default' => -1]); + $table->addColumn('col_bigint', 'bigint', ['default' => -1]); + $table->addColumn('col_float', 'float', ['default' => -1.1]); + $table->addColumn('col_decimal', 'decimal', ['default' => -1.1]); + $table->addColumn('col_string', 'string', ['default' => '(-1)']); $this->_sm->dropAndCreateTable($table); @@ -473,25 +481,24 @@ public function testAutoIncrementCreatesSerialDataTypesWithoutADefaultValueEvenW /** * @group 2916 - * * @dataProvider autoIncrementTypeMigrations */ public function testAlterTableAutoIncrementIntToBigInt(string $from, string $to, string $expected) : void { $tableFrom = new Table('autoinc_type_modification'); - $column = $tableFrom->addColumn('id', $from); + $column = $tableFrom->addColumn('id', $from); $column->setAutoincrement(true); $this->_sm->dropAndCreateTable($tableFrom); $tableFrom = $this->_sm->listTableDetails('autoinc_type_modification'); self::assertTrue($tableFrom->getColumn('id')->getAutoincrement()); $tableTo = new Table('autoinc_type_modification'); - $column = $tableTo->addColumn('id', $to); + $column = $tableTo->addColumn('id', $to); $column->setAutoincrement(true); - $c = new Comparator(); + $c = new Comparator(); $diff = $c->diffTable($tableFrom, $tableTo); - self::assertInstanceOf(TableDiff::class, $diff, "There should be a difference and not false being returned from the table comparison"); + self::assertInstanceOf(TableDiff::class, $diff, 'There should be a difference and not false being returned from the table comparison'); self::assertSame(['ALTER TABLE autoinc_type_modification ALTER id TYPE ' . $expected], $this->_conn->getDatabasePlatform()->getAlterTableSQL($diff)); $this->_sm->alterTable($diff); @@ -510,15 +517,13 @@ public function autoIncrementTypeMigrations() : array class MoneyType extends Type { - public function getName() { - return "MyMoney"; + return 'MyMoney'; } public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { return 'MyMoney'; } - } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php index 996e91699bb..5c68a19bcfd 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php @@ -12,8 +12,8 @@ public function testCreateAndListViews() { $this->createTestTable('view_test_table'); - $name = "doctrine_test_view"; - $sql = "SELECT * from DBA.view_test_table"; + $name = 'doctrine_test_view'; + $sql = 'SELECT * from DBA.view_test_table'; $view = new View($name, $sql); @@ -21,7 +21,7 @@ public function testCreateAndListViews() $views = $this->_sm->listViews(); - self::assertCount(1, $views, "Database has to have one view."); + self::assertCount(1, $views, 'Database has to have one view.'); self::assertInstanceOf('Doctrine\DBAL\Schema\View', $views[$name]); self::assertEquals($name, $views[$name]->getName()); self::assertEquals($sql, $views[$name]->getSql()); @@ -32,14 +32,14 @@ public function testDropAndCreateAdvancedIndex() $table = $this->getTestTable('test_create_advanced_index'); $this->_sm->dropAndCreateTable($table); $this->_sm->dropAndCreateIndex( - new Index('test', array('test'), true, false, array('clustered', 'with_nulls_not_distinct', 'for_olap_workload')), + new Index('test', ['test'], true, false, ['clustered', 'with_nulls_not_distinct', 'for_olap_workload']), $table->getName() ); $tableIndexes = $this->_sm->listTableIndexes('test_create_advanced_index'); self::assertInternalType('array', $tableIndexes); self::assertEquals('test', $tableIndexes['test']->getName()); - self::assertEquals(array('test'), $tableIndexes['test']->getColumns()); + self::assertEquals(['test'], $tableIndexes['test']->getColumns()); self::assertTrue($tableIndexes['test']->isUnique()); self::assertFalse($tableIndexes['test']->isPrimary()); self::assertTrue($tableIndexes['test']->hasFlag('clustered')); @@ -50,9 +50,9 @@ public function testDropAndCreateAdvancedIndex() public function testListTableColumnsWithFixedStringTypeColumn() { $table = new Table('list_table_columns_char'); - $table->addColumn('id', 'integer', array('notnull' => true)); - $table->addColumn('test', 'string', array('fixed' => true)); - $table->setPrimaryKey(array('id')); + $table->addColumn('id', 'integer', ['notnull' => true]); + $table->addColumn('test', 'string', ['fixed' => true]); + $table->setPrimaryKey(['id']); $this->_sm->dropAndCreateTable($table); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php index feee67710c2..218c11292be 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php @@ -13,7 +13,7 @@ class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase { protected function getPlatformName() { - return "mssql"; + return 'mssql'; } /** @@ -23,13 +23,11 @@ public function testDropColumnConstraints() { $table = new Table('sqlsrv_drop_column'); $table->addColumn('id', 'integer'); - $table->addColumn('todrop', 'decimal', array('default' => 10.2)); + $table->addColumn('todrop', 'decimal', ['default' => 10.2]); $this->_sm->createTable($table); - $diff = new TableDiff('sqlsrv_drop_column', array(), array(), array( - new Column('todrop', Type::getType('decimal')) - )); + $diff = new TableDiff('sqlsrv_drop_column', [], [], [new Column('todrop', Type::getType('decimal'))]); $this->_sm->alterTable($diff); $columns = $this->_sm->listTableColumns('sqlsrv_drop_column'); @@ -38,7 +36,7 @@ public function testDropColumnConstraints() public function testColumnCollation() { - $table = new \Doctrine\DBAL\Schema\Table($tableName = 'test_collation'); + $table = new Table($tableName = 'test_collation'); $column = $table->addColumn($columnName = 'test', 'string'); $this->_sm->dropAndCreateTable($table); @@ -57,16 +55,16 @@ public function testColumnCollation() public function testDefaultConstraints() { $platform = $this->_sm->getDatabasePlatform(); - $table = new Table('sqlsrv_default_constraints'); + $table = new Table('sqlsrv_default_constraints'); $table->addColumn('no_default', 'string'); - $table->addColumn('df_integer', 'integer', array('default' => 666)); - $table->addColumn('df_string_1', 'string', array('default' => 'foobar')); - $table->addColumn('df_string_2', 'string', array('default' => 'Doctrine rocks!!!')); - $table->addColumn('df_string_3', 'string', array('default' => 'another default value')); - $table->addColumn('df_string_4', 'string', array('default' => 'column to rename')); - $table->addColumn('df_boolean', 'boolean', array('default' => true)); - $table->addColumn('df_current_date', 'date', array('default' => $platform->getCurrentDateSQL())); - $table->addColumn('df_current_time', 'time', array('default' => $platform->getCurrentTimeSQL())); + $table->addColumn('df_integer', 'integer', ['default' => 666]); + $table->addColumn('df_string_1', 'string', ['default' => 'foobar']); + $table->addColumn('df_string_2', 'string', ['default' => 'Doctrine rocks!!!']); + $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->_sm->createTable($table); $columns = $this->_sm->listTableColumns('sqlsrv_default_constraints'); @@ -80,50 +78,48 @@ public function testDefaultConstraints() self::assertSame($platform->getCurrentDateSQL(), $columns['df_current_date']->getDefault()); self::assertSame($platform->getCurrentTimeSQL(), $columns['df_current_time']->getDefault()); - $diff = new TableDiff( + $diff = new TableDiff( 'sqlsrv_default_constraints', - array( - new Column('df_current_timestamp', Type::getType('datetime'), array('default' => 'CURRENT_TIMESTAMP')) - ), - array( + [new Column('df_current_timestamp', Type::getType('datetime'), ['default' => 'CURRENT_TIMESTAMP'])], + [ 'df_integer' => new ColumnDiff( 'df_integer', - new Column('df_integer', Type::getType('integer'), array('default' => 0)), - array('default'), - new Column('df_integer', Type::getType('integer'), array('default' => 666)) + new Column('df_integer', Type::getType('integer'), ['default' => 0]), + ['default'], + new Column('df_integer', Type::getType('integer'), ['default' => 666]) ), 'df_string_2' => new ColumnDiff( 'df_string_2', new Column('df_string_2', Type::getType('string')), - array('default'), - new Column('df_string_2', Type::getType('string'), array('default' => 'Doctrine rocks!!!')) + ['default'], + new Column('df_string_2', Type::getType('string'), ['default' => 'Doctrine rocks!!!']) ), 'df_string_3' => new ColumnDiff( 'df_string_3', - new Column('df_string_3', Type::getType('string'), array('length' => 50, 'default' => 'another default value')), - array('length'), - new Column('df_string_3', Type::getType('string'), array('length' => 50, 'default' => 'another default value')) + new Column('df_string_3', Type::getType('string'), ['length' => 50, 'default' => 'another default value']), + ['length'], + new Column('df_string_3', Type::getType('string'), ['length' => 50, 'default' => 'another default value']) ), 'df_boolean' => new ColumnDiff( 'df_boolean', - new Column('df_boolean', Type::getType('boolean'), array('default' => false)), - array('default'), - new Column('df_boolean', Type::getType('boolean'), array('default' => true)) - ) - ), - array( - 'df_string_1' => new Column('df_string_1', Type::getType('string')) - ), - array(), - array(), - array(), + new Column('df_boolean', Type::getType('boolean'), ['default' => false]), + ['default'], + new Column('df_boolean', Type::getType('boolean'), ['default' => true]) + ), + ], + [ + 'df_string_1' => new Column('df_string_1', Type::getType('string')), + ], + [], + [], + [], $table ); - $diff->newName = 'sqlsrv_default_constraints'; + $diff->newName = 'sqlsrv_default_constraints'; $diff->renamedColumns['df_string_4'] = new Column( 'df_string_renamed', Type::getType('string'), - array('default' => 'column to rename') + ['default' => 'column to rename'] ); $this->_sm->alterTable($diff); @@ -142,25 +138,25 @@ public function testDefaultConstraints() */ $diff = new TableDiff( 'sqlsrv_default_constraints', - array(), - array( + [], + [ 'df_current_timestamp' => new ColumnDiff( 'df_current_timestamp', new Column('df_current_timestamp', Type::getType('datetime')), - array('default'), - new Column('df_current_timestamp', Type::getType('datetime'), array('default' => 'CURRENT_TIMESTAMP')) + ['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'), array('default' => 666)), - array('default'), - new Column('df_integer', Type::getType('integer'), array('default' => 0)) - ) - ), - array(), - array(), - array(), - array(), + new Column('df_integer', Type::getType('integer'), ['default' => 666]), + ['default'], + new Column('df_integer', Type::getType('integer'), ['default' => 0]) + ), + ], + [], + [], + [], + [], $table ); @@ -177,23 +173,23 @@ public function testDefaultConstraints() public function testColumnComments() { $table = new Table('sqlsrv_column_comment'); - $table->addColumn('id', 'integer', array('autoincrement' => true)); - $table->addColumn('comment_null', 'integer', array('comment' => null)); - $table->addColumn('comment_false', 'integer', array('comment' => false)); - $table->addColumn('comment_empty_string', 'integer', array('comment' => '')); - $table->addColumn('comment_integer_0', 'integer', array('comment' => 0)); - $table->addColumn('comment_float_0', 'integer', array('comment' => 0.0)); - $table->addColumn('comment_string_0', 'integer', array('comment' => '0')); - $table->addColumn('comment', 'integer', array('comment' => 'Doctrine 0wnz you!')); - $table->addColumn('`comment_quoted`', 'integer', array('comment' => 'Doctrine 0wnz comments for explicitly quoted columns!')); - $table->addColumn('create', 'integer', array('comment' => 'Doctrine 0wnz comments for reserved keyword columns!')); + $table->addColumn('id', 'integer', ['autoincrement' => true]); + $table->addColumn('comment_null', 'integer', ['comment' => null]); + $table->addColumn('comment_false', 'integer', ['comment' => false]); + $table->addColumn('comment_empty_string', 'integer', ['comment' => '']); + $table->addColumn('comment_integer_0', 'integer', ['comment' => 0]); + $table->addColumn('comment_float_0', 'integer', ['comment' => 0.0]); + $table->addColumn('comment_string_0', 'integer', ['comment' => '0']); + $table->addColumn('comment', 'integer', ['comment' => 'Doctrine 0wnz you!']); + $table->addColumn('`comment_quoted`', 'integer', ['comment' => 'Doctrine 0wnz comments for explicitly quoted columns!']); + $table->addColumn('create', 'integer', ['comment' => 'Doctrine 0wnz comments for reserved keyword columns!']); $table->addColumn('commented_type', 'object'); - $table->addColumn('commented_type_with_comment', 'array', array('comment' => 'Doctrine array type.')); - $table->setPrimaryKey(array('id')); + $table->addColumn('commented_type_with_comment', 'array', ['comment' => 'Doctrine array type.']); + $table->setPrimaryKey(['id']); $this->_sm->createTable($table); - $columns = $this->_sm->listTableColumns("sqlsrv_column_comment"); + $columns = $this->_sm->listTableColumns('sqlsrv_column_comment'); self::assertCount(12, $columns); self::assertNull($columns['id']->getComment()); self::assertNull($columns['comment_null']->getComment()); @@ -208,92 +204,92 @@ public function testColumnComments() self::assertNull($columns['commented_type']->getComment()); self::assertEquals('Doctrine array type.', $columns['commented_type_with_comment']->getComment()); - $tableDiff = new TableDiff('sqlsrv_column_comment'); - $tableDiff->fromTable = $table; - $tableDiff->addedColumns['added_comment_none'] = new Column('added_comment_none', Type::getType('integer')); - $tableDiff->addedColumns['added_comment_null'] = new Column('added_comment_null', Type::getType('integer'), array('comment' => null)); - $tableDiff->addedColumns['added_comment_false'] = new Column('added_comment_false', Type::getType('integer'), array('comment' => false)); - $tableDiff->addedColumns['added_comment_empty_string'] = new Column('added_comment_empty_string', Type::getType('integer'), array('comment' => '')); - $tableDiff->addedColumns['added_comment_integer_0'] = new Column('added_comment_integer_0', Type::getType('integer'), array('comment' => 0)); - $tableDiff->addedColumns['added_comment_float_0'] = new Column('added_comment_float_0', Type::getType('integer'), array('comment' => 0.0)); - $tableDiff->addedColumns['added_comment_string_0'] = new Column('added_comment_string_0', Type::getType('integer'), array('comment' => '0')); - $tableDiff->addedColumns['added_comment'] = new Column('added_comment', Type::getType('integer'), array('comment' => 'Doctrine')); - $tableDiff->addedColumns['`added_comment_quoted`'] = new Column('`added_comment_quoted`', Type::getType('integer'), array('comment' => 'rulez')); - $tableDiff->addedColumns['select'] = new Column('select', Type::getType('integer'), array('comment' => '666')); - $tableDiff->addedColumns['added_commented_type'] = new Column('added_commented_type', Type::getType('object')); - $tableDiff->addedColumns['added_commented_type_with_comment'] = new Column('added_commented_type_with_comment', Type::getType('array'), array('comment' => '666')); - - $tableDiff->renamedColumns['comment_float_0'] = new Column('comment_double_0', Type::getType('decimal'), array('comment' => 'Double for real!')); + $tableDiff = new TableDiff('sqlsrv_column_comment'); + $tableDiff->fromTable = $table; + $tableDiff->addedColumns['added_comment_none'] = new Column('added_comment_none', Type::getType('integer')); + $tableDiff->addedColumns['added_comment_null'] = new Column('added_comment_null', Type::getType('integer'), ['comment' => null]); + $tableDiff->addedColumns['added_comment_false'] = new Column('added_comment_false', Type::getType('integer'), ['comment' => false]); + $tableDiff->addedColumns['added_comment_empty_string'] = new Column('added_comment_empty_string', Type::getType('integer'), ['comment' => '']); + $tableDiff->addedColumns['added_comment_integer_0'] = new Column('added_comment_integer_0', Type::getType('integer'), ['comment' => 0]); + $tableDiff->addedColumns['added_comment_float_0'] = new Column('added_comment_float_0', Type::getType('integer'), ['comment' => 0.0]); + $tableDiff->addedColumns['added_comment_string_0'] = new Column('added_comment_string_0', Type::getType('integer'), ['comment' => '0']); + $tableDiff->addedColumns['added_comment'] = new Column('added_comment', Type::getType('integer'), ['comment' => 'Doctrine']); + $tableDiff->addedColumns['`added_comment_quoted`'] = new Column('`added_comment_quoted`', Type::getType('integer'), ['comment' => 'rulez']); + $tableDiff->addedColumns['select'] = new Column('select', Type::getType('integer'), ['comment' => '666']); + $tableDiff->addedColumns['added_commented_type'] = new Column('added_commented_type', Type::getType('object')); + $tableDiff->addedColumns['added_commented_type_with_comment'] = new Column('added_commented_type_with_comment', Type::getType('array'), ['comment' => '666']); + + $tableDiff->renamedColumns['comment_float_0'] = new Column('comment_double_0', Type::getType('decimal'), ['comment' => 'Double for real!']); // Add comment to non-commented column. $tableDiff->changedColumns['id'] = new ColumnDiff( 'id', - new Column('id', Type::getType('integer'), array('autoincrement' => true, 'comment' => 'primary')), - array('comment'), - new Column('id', Type::getType('integer'), array('autoincrement' => true)) + new Column('id', Type::getType('integer'), ['autoincrement' => true, 'comment' => 'primary']), + ['comment'], + new Column('id', Type::getType('integer'), ['autoincrement' => true]) ); // Remove comment from null-commented column. $tableDiff->changedColumns['comment_null'] = new ColumnDiff( 'comment_null', new Column('comment_null', Type::getType('string')), - array('type'), - new Column('comment_null', Type::getType('integer'), array('comment' => null)) + ['type'], + new Column('comment_null', Type::getType('integer'), ['comment' => null]) ); // Add comment to false-commented column. $tableDiff->changedColumns['comment_false'] = new ColumnDiff( 'comment_false', - new Column('comment_false', Type::getType('integer'), array('comment' => 'false')), - array('comment'), - new Column('comment_false', Type::getType('integer'), array('comment' => false)) + new Column('comment_false', Type::getType('integer'), ['comment' => 'false']), + ['comment'], + new Column('comment_false', Type::getType('integer'), ['comment' => false]) ); // Change type to custom type from empty string commented column. $tableDiff->changedColumns['comment_empty_string'] = new ColumnDiff( 'comment_empty_string', new Column('comment_empty_string', Type::getType('object')), - array('type'), - new Column('comment_empty_string', Type::getType('integer'), array('comment' => '')) + ['type'], + new Column('comment_empty_string', Type::getType('integer'), ['comment' => '']) ); // Change comment to false-comment from zero-string commented column. $tableDiff->changedColumns['comment_string_0'] = new ColumnDiff( 'comment_string_0', - new Column('comment_string_0', Type::getType('integer'), array('comment' => false)), - array('comment'), - new Column('comment_string_0', Type::getType('integer'), array('comment' => '0')) + new Column('comment_string_0', Type::getType('integer'), ['comment' => false]), + ['comment'], + new Column('comment_string_0', Type::getType('integer'), ['comment' => '0']) ); // Remove comment from regular commented column. $tableDiff->changedColumns['comment'] = new ColumnDiff( 'comment', new Column('comment', Type::getType('integer')), - array('comment'), - new Column('comment', Type::getType('integer'), array('comment' => 'Doctrine 0wnz you!')) + ['comment'], + new Column('comment', Type::getType('integer'), ['comment' => 'Doctrine 0wnz you!']) ); // Change comment and change type to custom type from regular commented column. $tableDiff->changedColumns['`comment_quoted`'] = new ColumnDiff( '`comment_quoted`', - new Column('`comment_quoted`', Type::getType('array'), array('comment' => 'Doctrine array.')), - array('comment', 'type'), - new Column('`comment_quoted`', Type::getType('integer'), array('comment' => 'Doctrine 0wnz you!')) + new Column('`comment_quoted`', Type::getType('array'), ['comment' => 'Doctrine array.']), + ['comment', 'type'], + new Column('`comment_quoted`', Type::getType('integer'), ['comment' => 'Doctrine 0wnz you!']) ); // Remove comment and change type to custom type from regular commented column. $tableDiff->changedColumns['create'] = new ColumnDiff( 'create', new Column('create', Type::getType('object')), - array('comment', 'type'), - new Column('create', Type::getType('integer'), array('comment' => 'Doctrine 0wnz comments for reserved keyword columns!')) + ['comment', 'type'], + new Column('create', Type::getType('integer'), ['comment' => 'Doctrine 0wnz comments for reserved keyword columns!']) ); // Add comment and change custom type to regular type from non-commented column. $tableDiff->changedColumns['commented_type'] = new ColumnDiff( 'commented_type', - new Column('commented_type', Type::getType('integer'), array('comment' => 'foo')), - array('comment', 'type'), + new Column('commented_type', Type::getType('integer'), ['comment' => 'foo']), + ['comment', 'type'], new Column('commented_type', Type::getType('object')) ); @@ -301,15 +297,15 @@ public function testColumnComments() $tableDiff->changedColumns['commented_type_with_comment'] = new ColumnDiff( 'commented_type_with_comment', new Column('commented_type_with_comment', Type::getType('array')), - array('comment'), - new Column('commented_type_with_comment', Type::getType('array'), array('comment' => 'Doctrine array type.')) + ['comment'], + new Column('commented_type_with_comment', Type::getType('array'), ['comment' => 'Doctrine array type.']) ); - $tableDiff->removedColumns['comment_integer_0'] = new Column('comment_integer_0', Type::getType('integer'), array('comment' => 0)); + $tableDiff->removedColumns['comment_integer_0'] = new Column('comment_integer_0', Type::getType('integer'), ['comment' => 0]); $this->_sm->alterTable($tableDiff); - $columns = $this->_sm->listTableColumns("sqlsrv_column_comment"); + $columns = $this->_sm->listTableColumns('sqlsrv_column_comment'); self::assertCount(23, $columns); self::assertEquals('primary', $columns['id']->getComment()); self::assertNull($columns['comment_null']->getComment()); @@ -346,9 +342,9 @@ public function testPkOrdering() // key_ordinal holds the index ordering. index_column_id is just a unique identifier // for index columns within the given index. $table = new Table('sqlsrv_pk_ordering'); - $table->addColumn('colA', 'integer', array('notnull' => true)); - $table->addColumn('colB', 'integer', array('notnull' => true)); - $table->setPrimaryKey(array('colB', 'colA')); + $table->addColumn('colA', 'integer', ['notnull' => true]); + $table->addColumn('colB', 'integer', ['notnull' => true]); + $table->setPrimaryKey(['colB', 'colA']); $this->_sm->createTable($table); $indexes = $this->_sm->listTableIndexes('sqlsrv_pk_ordering'); @@ -356,7 +352,7 @@ public function testPkOrdering() self::assertCount(1, $indexes); $firstIndex = current($indexes); - $columns = $firstIndex->getColumns(); + $columns = $firstIndex->getColumns(); self::assertCount(2, $columns); self::assertEquals('colB', $columns[0]); self::assertEquals('colA', $columns[1]); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index 6c5329a0bab..0a20f5ca4d9 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -6,14 +6,20 @@ use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Events; use Doctrine\DBAL\Platforms\OraclePlatform; +use Doctrine\DBAL\Schema\AbstractAsset; +use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ColumnDiff; use Doctrine\DBAL\Schema\Comparator; +use Doctrine\DBAL\Schema\ForeignKeyConstraint; +use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\SchemaDiff; use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; +use Doctrine\DBAL\Schema\View; use Doctrine\DBAL\Types\Type; +use Doctrine\Tests\DbalFunctionalTestCase; use function array_filter; use function array_keys; use function array_map; @@ -23,7 +29,6 @@ use function current; use function end; use function explode; -use function get_class; use function in_array; use function str_replace; use function strcasecmp; @@ -31,20 +36,17 @@ use function strtolower; use function substr; -class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTestCase +class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase { - /** - * @var \Doctrine\DBAL\Schema\AbstractSchemaManager - */ + /** @var AbstractSchemaManager */ protected $_sm; protected function getPlatformName() { - $class = get_class($this); - $e = explode('\\', $class); + $class = static::class; + $e = explode('\\', $class); $testClass = end($e); - $dbms = strtolower(str_replace('SchemaManagerTest', null, $testClass)); - return $dbms; + return strtolower(str_replace('SchemaManagerTest', null, $testClass)); } protected function setUp() @@ -54,7 +56,7 @@ protected function setUp() $dbms = $this->getPlatformName(); if ($this->_conn->getDatabasePlatform()->getName() !== $dbms) { - $this->markTestSkipped(get_class($this) . ' requires the use of ' . $dbms); + $this->markTestSkipped(static::class . ' requires the use of ' . $dbms); } $this->_sm = $this->_conn->getSchemaManager(); @@ -102,7 +104,7 @@ public function testDropsDatabaseWithActiveConnections() $params['dbname'] = 'test_drop_database'; } - $user = $params['user'] ?? null; + $user = $params['user'] ?? null; $password = $params['password'] ?? null; $connection = $this->_conn->getDriver()->connect($params, $user, $password); @@ -119,8 +121,8 @@ public function testDropsDatabaseWithActiveConnections() */ public function testDropAndCreateSequence() { - if ( ! $this->_conn->getDatabasePlatform()->supportsSequences()) { - $this->markTestSkipped($this->_conn->getDriver()->getName().' does not support sequences.'); + if (! $this->_conn->getDatabasePlatform()->supportsSequences()) { + $this->markTestSkipped($this->_conn->getDriver()->getName() . ' does not support sequences.'); } $name = 'dropcreate_sequences_test_seq'; @@ -134,7 +136,7 @@ private function hasElementWithName(array $items, string $name) : bool { $filteredList = array_filter( $items, - function (\Doctrine\DBAL\Schema\AbstractAsset $item) use ($name) : bool { + static function (AbstractAsset $item) use ($name) : bool { return $item->getShortestName($item->getNamespaceName()) === $name; } ); @@ -172,7 +174,7 @@ public function testListSequences() public function testListDatabases() { - if (!$this->_sm->getDatabasePlatform()->supportsCreateDropDatabase()) { + if (! $this->_sm->getDatabasePlatform()->supportsCreateDropDatabase()) { $this->markTestSkipped('Cannot drop Database client side with this Driver.'); } @@ -189,7 +191,7 @@ public function testListDatabases() */ public function testListNamespaceNames() { - if (!$this->_sm->getDatabasePlatform()->supportsSchemas()) { + if (! $this->_sm->getDatabasePlatform()->supportsSchemas()) { $this->markTestSkipped('Platform does not support schemas.'); } @@ -197,7 +199,7 @@ public function testListNamespaceNames() $namespaces = $this->_sm->listNamespaceNames(); $namespaces = array_map('strtolower', $namespaces); - if (!in_array('test_create_schema', $namespaces)) { + if (! in_array('test_create_schema', $namespaces)) { $this->_conn->executeUpdate($this->_sm->getDatabasePlatform()->getCreateSchemaSQL('test_create_schema')); $namespaces = $this->_sm->listNamespaceNames(); @@ -218,29 +220,31 @@ public function testListTables() $foundTable = false; foreach ($tables as $table) { self::assertInstanceOf('Doctrine\DBAL\Schema\Table', $table); - if (strtolower($table->getName()) == 'list_tables_test') { - $foundTable = true; - - self::assertTrue($table->hasColumn('id')); - self::assertTrue($table->hasColumn('test')); - self::assertTrue($table->hasColumn('foreign_key_test')); + if (strtolower($table->getName()) !== 'list_tables_test') { + continue; } + + $foundTable = true; + + self::assertTrue($table->hasColumn('id')); + self::assertTrue($table->hasColumn('test')); + self::assertTrue($table->hasColumn('foreign_key_test')); } - self::assertTrue( $foundTable , "The 'list_tables_test' table has to be found."); + self::assertTrue($foundTable, "The 'list_tables_test' table has to be found."); } public function createListTableColumns() { $table = new Table('list_table_columns'); - $table->addColumn('id', 'integer', array('notnull' => true)); - $table->addColumn('test', 'string', array('length' => 255, 'notnull' => false, 'default' => 'expected default')); - $table->addColumn('foo', 'text', array('notnull' => true)); - $table->addColumn('bar', 'decimal', array('precision' => 10, 'scale' => 4, 'notnull' => false)); + $table->addColumn('id', 'integer', ['notnull' => true]); + $table->addColumn('test', 'string', ['length' => 255, 'notnull' => false, 'default' => 'expected default']); + $table->addColumn('foo', 'text', ['notnull' => true]); + $table->addColumn('bar', 'decimal', ['precision' => 10, 'scale' => 4, 'notnull' => false]); $table->addColumn('baz1', 'datetime'); $table->addColumn('baz2', 'time'); $table->addColumn('baz3', 'date'); - $table->setPrimaryKey(array('id')); + $table->setPrimaryKey(['id']); return $table; } @@ -251,69 +255,69 @@ public function testListTableColumns() $this->_sm->dropAndCreateTable($table); - $columns = $this->_sm->listTableColumns('list_table_columns'); + $columns = $this->_sm->listTableColumns('list_table_columns'); $columnsKeys = array_keys($columns); self::assertArrayHasKey('id', $columns); self::assertEquals(0, array_search('id', $columnsKeys)); - self::assertEquals('id', strtolower($columns['id']->getname())); + self::assertEquals('id', strtolower($columns['id']->getname())); self::assertInstanceOf('Doctrine\DBAL\Types\IntegerType', $columns['id']->gettype()); - 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::assertEquals(false, $columns['id']->getunsigned()); + self::assertEquals(true, $columns['id']->getnotnull()); + self::assertEquals(null, $columns['id']->getdefault()); + self::assertInternalType('array', $columns['id']->getPlatformOptions()); self::assertArrayHasKey('test', $columns); self::assertEquals(1, array_search('test', $columnsKeys)); self::assertEquals('test', strtolower($columns['test']->getname())); self::assertInstanceOf('Doctrine\DBAL\Types\StringType', $columns['test']->gettype()); - self::assertEquals(255, $columns['test']->getlength()); - 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::assertEquals(255, $columns['test']->getlength()); + 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::assertEquals('foo', strtolower($columns['foo']->getname())); + self::assertEquals('foo', strtolower($columns['foo']->getname())); self::assertEquals(2, array_search('foo', $columnsKeys)); self::assertInstanceOf('Doctrine\DBAL\Types\TextType', $columns['foo']->gettype()); - self::assertEquals(false, $columns['foo']->getunsigned()); - 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::assertEquals(false, $columns['foo']->getunsigned()); + 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::assertEquals('bar', strtolower($columns['bar']->getname())); + self::assertEquals('bar', strtolower($columns['bar']->getname())); self::assertEquals(3, array_search('bar', $columnsKeys)); self::assertInstanceOf('Doctrine\DBAL\Types\DecimalType', $columns['bar']->gettype()); - self::assertEquals(null, $columns['bar']->getlength()); - self::assertEquals(10, $columns['bar']->getprecision()); - self::assertEquals(4, $columns['bar']->getscale()); - self::assertEquals(false, $columns['bar']->getunsigned()); - 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::assertEquals(null, $columns['bar']->getlength()); + self::assertEquals(10, $columns['bar']->getprecision()); + self::assertEquals(4, $columns['bar']->getscale()); + self::assertEquals(false, $columns['bar']->getunsigned()); + 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::assertEquals('baz1', strtolower($columns['baz1']->getname())); self::assertEquals(4, array_search('baz1', $columnsKeys)); self::assertInstanceOf('Doctrine\DBAL\Types\DateTimeType', $columns['baz1']->gettype()); - self::assertEquals(true, $columns['baz1']->getnotnull()); - self::assertEquals(null, $columns['baz1']->getdefault()); - self::assertInternalType('array', $columns['baz1']->getPlatformOptions()); + self::assertEquals(true, $columns['baz1']->getnotnull()); + self::assertEquals(null, $columns['baz1']->getdefault()); + self::assertInternalType('array', $columns['baz1']->getPlatformOptions()); self::assertEquals('baz2', strtolower($columns['baz2']->getname())); self::assertEquals(5, array_search('baz2', $columnsKeys)); - self::assertContains($columns['baz2']->gettype()->getName(), array('time', 'date', 'datetime')); - self::assertEquals(true, $columns['baz2']->getnotnull()); - self::assertEquals(null, $columns['baz2']->getdefault()); - self::assertInternalType('array', $columns['baz2']->getPlatformOptions()); + 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::assertEquals('baz3', strtolower($columns['baz3']->getname())); self::assertEquals(6, array_search('baz3', $columnsKeys)); - self::assertContains($columns['baz3']->gettype()->getName(), array('time', 'date', 'datetime')); - self::assertEquals(true, $columns['baz3']->getnotnull()); - self::assertEquals(null, $columns['baz3']->getdefault()); - self::assertInternalType('array', $columns['baz3']->getPlatformOptions()); + 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()); } /** @@ -324,7 +328,7 @@ public function testListTableColumnsWithFixedStringColumn() $tableName = 'test_list_table_fixed_string'; $table = new Table($tableName); - $table->addColumn('column_char', 'string', array('fixed' => true, 'length' => 2)); + $table->addColumn('column_char', 'string', ['fixed' => true, 'length' => 2]); $this->_sm->createTable($table); @@ -353,7 +357,7 @@ public function testListTableColumnsDispatchEvent() $oldEventManager = $this->_sm->getDatabasePlatform()->getEventManager(); $eventManager = new EventManager(); - $eventManager->addEventListener(array(Events::onSchemaColumnDefinition), $listenerMock); + $eventManager->addEventListener([Events::onSchemaColumnDefinition], $listenerMock); $this->_sm->getDatabasePlatform()->setEventManager($eventManager); @@ -365,8 +369,8 @@ public function testListTableColumnsDispatchEvent() public function testListTableIndexesDispatchEvent() { $table = $this->getTestTable('list_table_indexes_test'); - $table->addUniqueIndex(array('test'), 'test_index_name'); - $table->addIndex(array('id', 'test'), 'test_composite_idx'); + $table->addUniqueIndex(['test'], 'test_index_name'); + $table->addIndex(['id', 'test'], 'test_composite_idx'); $this->_sm->dropAndCreateTable($table); @@ -381,7 +385,7 @@ public function testListTableIndexesDispatchEvent() $oldEventManager = $this->_sm->getDatabasePlatform()->getEventManager(); $eventManager = new EventManager(); - $eventManager->addEventListener(array(Events::onSchemaIndexDefinition), $listenerMock); + $eventManager->addEventListener([Events::onSchemaIndexDefinition], $listenerMock); $this->_sm->getDatabasePlatform()->setEventManager($eventManager); @@ -392,7 +396,7 @@ public function testListTableIndexesDispatchEvent() public function testDiffListTableColumns() { - if ($this->_sm->getDatabasePlatform()->getName() == 'oracle') { + if ($this->_sm->getDatabasePlatform()->getName() === 'oracle') { $this->markTestSkipped('Does not work with Oracle, since it cannot detect DateTime, Date and Time differenecs (at the moment).'); } @@ -400,17 +404,17 @@ public function testDiffListTableColumns() $this->_sm->dropAndCreateTable($offlineTable); $onlineTable = $this->_sm->listTableDetails('list_table_columns'); - $comparator = new \Doctrine\DBAL\Schema\Comparator(); - $diff = $comparator->diffTable($offlineTable, $onlineTable); + $comparator = new Comparator(); + $diff = $comparator->diffTable($offlineTable, $onlineTable); - self::assertFalse($diff, "No differences should be detected with the offline vs online schema."); + self::assertFalse($diff, 'No differences should be detected with the offline vs online schema.'); } public function testListTableIndexes() { $table = $this->getTestCompositeTable('list_table_indexes_test'); - $table->addUniqueIndex(array('test'), 'test_index_name'); - $table->addIndex(array('id', 'test'), 'test_composite_idx'); + $table->addUniqueIndex(['test'], 'test_index_name'); + $table->addIndex(['id', 'test'], 'test_composite_idx'); $this->_sm->dropAndCreateTable($table); @@ -419,17 +423,17 @@ public function testListTableIndexes() self::assertEquals(3, count($tableIndexes)); self::assertArrayHasKey('primary', $tableIndexes, 'listTableIndexes() has to return a "primary" array key.'); - self::assertEquals(array('id', 'other_id'), array_map('strtolower', $tableIndexes['primary']->getColumns())); + self::assertEquals(['id', 'other_id'], array_map('strtolower', $tableIndexes['primary']->getColumns())); self::assertTrue($tableIndexes['primary']->isUnique()); self::assertTrue($tableIndexes['primary']->isPrimary()); self::assertEquals('test_index_name', strtolower($tableIndexes['test_index_name']->getName())); - self::assertEquals(array('test'), array_map('strtolower', $tableIndexes['test_index_name']->getColumns())); + self::assertEquals(['test'], array_map('strtolower', $tableIndexes['test_index_name']->getColumns())); self::assertTrue($tableIndexes['test_index_name']->isUnique()); self::assertFalse($tableIndexes['test_index_name']->isPrimary()); self::assertEquals('test_composite_idx', strtolower($tableIndexes['test_composite_idx']->getName())); - self::assertEquals(array('id', 'test'), array_map('strtolower', $tableIndexes['test_composite_idx']->getColumns())); + self::assertEquals(['id', 'test'], array_map('strtolower', $tableIndexes['test_composite_idx']->getColumns())); self::assertFalse($tableIndexes['test_composite_idx']->isUnique()); self::assertFalse($tableIndexes['test_composite_idx']->isPrimary()); } @@ -437,22 +441,22 @@ public function testListTableIndexes() public function testDropAndCreateIndex() { $table = $this->getTestTable('test_create_index'); - $table->addUniqueIndex(array('test'), 'test'); + $table->addUniqueIndex(['test'], 'test'); $this->_sm->dropAndCreateTable($table); $this->_sm->dropAndCreateIndex($table->getIndex('test'), $table); $tableIndexes = $this->_sm->listTableIndexes('test_create_index'); self::assertInternalType('array', $tableIndexes); - self::assertEquals('test', strtolower($tableIndexes['test']->getName())); - self::assertEquals(array('test'), array_map('strtolower', $tableIndexes['test']->getColumns())); + self::assertEquals('test', strtolower($tableIndexes['test']->getName())); + self::assertEquals(['test'], array_map('strtolower', $tableIndexes['test']->getColumns())); self::assertTrue($tableIndexes['test']->isUnique()); self::assertFalse($tableIndexes['test']->isPrimary()); } public function testCreateTableWithForeignKeys() { - if(!$this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) { + if (! $this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped('Platform does not support foreign keys.'); } @@ -461,34 +465,38 @@ public function testCreateTableWithForeignKeys() $this->_sm->dropAndCreateTable($tableB); $tableA = $this->getTestTable('test_create_fk'); - $tableA->addForeignKeyConstraint('test_foreign', array('foreign_key_test'), array('id')); + $tableA->addForeignKeyConstraint('test_foreign', ['foreign_key_test'], ['id']); $this->_sm->dropAndCreateTable($tableA); - $fkTable = $this->_sm->listTableDetails('test_create_fk'); + $fkTable = $this->_sm->listTableDetails('test_create_fk'); $fkConstraints = $fkTable->getForeignKeys(); self::assertEquals(1, count($fkConstraints), "Table 'test_create_fk1' has to have one foreign key."); $fkConstraint = current($fkConstraints); self::assertInstanceOf('\Doctrine\DBAL\Schema\ForeignKeyConstraint', $fkConstraint); - self::assertEquals('test_foreign', strtolower($fkConstraint->getForeignTableName())); - self::assertEquals(array('foreign_key_test'), array_map('strtolower', $fkConstraint->getColumns())); - self::assertEquals(array('id'), array_map('strtolower', $fkConstraint->getForeignColumns())); + self::assertEquals('test_foreign', strtolower($fkConstraint->getForeignTableName())); + self::assertEquals(['foreign_key_test'], array_map('strtolower', $fkConstraint->getColumns())); + self::assertEquals(['id'], array_map('strtolower', $fkConstraint->getForeignColumns())); - self::assertTrue($fkTable->columnsAreIndexed($fkConstraint->getColumns()), "The columns of a foreign key constraint should always be indexed."); + self::assertTrue($fkTable->columnsAreIndexed($fkConstraint->getColumns()), 'The columns of a foreign key constraint should always be indexed.'); } public function testListForeignKeys() { - if(!$this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { + if (! $this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped('Does not support foreign key constraints.'); } $this->createTestTable('test_create_fk1'); $this->createTestTable('test_create_fk2'); - $foreignKey = new \Doctrine\DBAL\Schema\ForeignKeyConstraint( - array('foreign_key_test'), 'test_create_fk2', array('id'), 'foreign_key_test_fk', array('onDelete' => 'CASCADE') + $foreignKey = new ForeignKeyConstraint( + ['foreign_key_test'], + 'test_create_fk2', + ['id'], + 'foreign_key_test_fk', + ['onDelete' => 'CASCADE'] ); $this->_sm->createForeignKey($foreignKey, 'test_create_fk1'); @@ -498,13 +506,15 @@ public function testListForeignKeys() self::assertEquals(1, count($fkeys), "Table 'test_create_fk1' has to have one foreign key."); self::assertInstanceOf('Doctrine\DBAL\Schema\ForeignKeyConstraint', $fkeys[0]); - self::assertEquals(array('foreign_key_test'), array_map('strtolower', $fkeys[0]->getLocalColumns())); - self::assertEquals(array('id'), array_map('strtolower', $fkeys[0]->getForeignColumns())); - self::assertEquals('test_create_fk2', strtolower($fkeys[0]->getForeignTableName())); + self::assertEquals(['foreign_key_test'], array_map('strtolower', $fkeys[0]->getLocalColumns())); + self::assertEquals(['id'], array_map('strtolower', $fkeys[0]->getForeignColumns())); + self::assertEquals('test_create_fk2', strtolower($fkeys[0]->getForeignTableName())); - if($fkeys[0]->hasOption('onDelete')) { - self::assertEquals('CASCADE', $fkeys[0]->getOption('onDelete')); + if (! $fkeys[0]->hasOption('onDelete')) { + return; } + + self::assertEquals('CASCADE', $fkeys[0]->getOption('onDelete')); } protected function getCreateExampleViewSql() @@ -522,7 +532,7 @@ public function testCreateSchema() public function testAlterTableScenario() { - if(!$this->_sm->getDatabasePlatform()->supportsAlterTable()) { + if (! $this->_sm->getDatabasePlatform()->supportsAlterTable()) { $this->markTestSkipped('Alter Table is not supported by this platform.'); } @@ -536,9 +546,9 @@ public function testAlterTableScenario() self::assertEquals(0, count($table->getForeignKeys())); self::assertEquals(1, count($table->getIndexes())); - $tableDiff = new \Doctrine\DBAL\Schema\TableDiff("alter_table"); - $tableDiff->fromTable = $alterTable; - $tableDiff->addedColumns['foo'] = new \Doctrine\DBAL\Schema\Column('foo', Type::getType('integer')); + $tableDiff = new TableDiff('alter_table'); + $tableDiff->fromTable = $alterTable; + $tableDiff->addedColumns['foo'] = new Column('foo', Type::getType('integer')); $tableDiff->removedColumns['test'] = $table->getColumn('test'); $this->_sm->alterTable($tableDiff); @@ -547,33 +557,33 @@ public function testAlterTableScenario() self::assertFalse($table->hasColumn('test')); self::assertTrue($table->hasColumn('foo')); - $tableDiff = new \Doctrine\DBAL\Schema\TableDiff("alter_table"); - $tableDiff->fromTable = $table; - $tableDiff->addedIndexes[] = new \Doctrine\DBAL\Schema\Index('foo_idx', array('foo')); + $tableDiff = new TableDiff('alter_table'); + $tableDiff->fromTable = $table; + $tableDiff->addedIndexes[] = new Index('foo_idx', ['foo']); $this->_sm->alterTable($tableDiff); $table = $this->_sm->listTableDetails('alter_table'); self::assertEquals(2, count($table->getIndexes())); self::assertTrue($table->hasIndex('foo_idx')); - self::assertEquals(array('foo'), array_map('strtolower', $table->getIndex('foo_idx')->getColumns())); + self::assertEquals(['foo'], array_map('strtolower', $table->getIndex('foo_idx')->getColumns())); self::assertFalse($table->getIndex('foo_idx')->isPrimary()); self::assertFalse($table->getIndex('foo_idx')->isUnique()); - $tableDiff = new \Doctrine\DBAL\Schema\TableDiff("alter_table"); - $tableDiff->fromTable = $table; - $tableDiff->changedIndexes[] = new \Doctrine\DBAL\Schema\Index('foo_idx', array('foo', 'foreign_key_test')); + $tableDiff = new TableDiff('alter_table'); + $tableDiff->fromTable = $table; + $tableDiff->changedIndexes[] = new Index('foo_idx', ['foo', 'foreign_key_test']); $this->_sm->alterTable($tableDiff); $table = $this->_sm->listTableDetails('alter_table'); self::assertEquals(2, count($table->getIndexes())); self::assertTrue($table->hasIndex('foo_idx')); - self::assertEquals(array('foo', 'foreign_key_test'), array_map('strtolower', $table->getIndex('foo_idx')->getColumns())); + self::assertEquals(['foo', 'foreign_key_test'], array_map('strtolower', $table->getIndex('foo_idx')->getColumns())); - $tableDiff = new \Doctrine\DBAL\Schema\TableDiff("alter_table"); - $tableDiff->fromTable = $table; - $tableDiff->renamedIndexes['foo_idx'] = new \Doctrine\DBAL\Schema\Index('bar_idx', array('foo', 'foreign_key_test')); + $tableDiff = new TableDiff('alter_table'); + $tableDiff->fromTable = $table; + $tableDiff->renamedIndexes['foo_idx'] = new Index('bar_idx', ['foo', 'foreign_key_test']); $this->_sm->alterTable($tableDiff); @@ -581,14 +591,14 @@ public function testAlterTableScenario() self::assertEquals(2, count($table->getIndexes())); self::assertTrue($table->hasIndex('bar_idx')); self::assertFalse($table->hasIndex('foo_idx')); - self::assertEquals(array('foo', 'foreign_key_test'), array_map('strtolower', $table->getIndex('bar_idx')->getColumns())); + self::assertEquals(['foo', 'foreign_key_test'], array_map('strtolower', $table->getIndex('bar_idx')->getColumns())); self::assertFalse($table->getIndex('bar_idx')->isPrimary()); self::assertFalse($table->getIndex('bar_idx')->isUnique()); - $tableDiff = new \Doctrine\DBAL\Schema\TableDiff("alter_table"); - $tableDiff->fromTable = $table; - $tableDiff->removedIndexes[] = new \Doctrine\DBAL\Schema\Index('bar_idx', array('foo', 'foreign_key_test')); - $fk = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(array('foreign_key_test'), 'alter_table_foreign', array('id')); + $tableDiff = new TableDiff('alter_table'); + $tableDiff->fromTable = $table; + $tableDiff->removedIndexes[] = new Index('bar_idx', ['foo', 'foreign_key_test']); + $fk = new ForeignKeyConstraint(['foreign_key_test'], 'alter_table_foreign', ['id']); $tableDiff->addedForeignKeys[] = $fk; $this->_sm->alterTable($tableDiff); @@ -597,14 +607,16 @@ public function testAlterTableScenario() // dont check for index size here, some platforms automatically add indexes for foreign keys. self::assertFalse($table->hasIndex('bar_idx')); - if ($this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) { - $fks = $table->getForeignKeys(); - self::assertCount(1, $fks); - $foreignKey = current($fks); - self::assertEquals('alter_table_foreign', strtolower($foreignKey->getForeignTableName())); - self::assertEquals(array('foreign_key_test'), array_map('strtolower', $foreignKey->getColumns())); - self::assertEquals(array('id'), array_map('strtolower', $foreignKey->getForeignColumns())); + if (! $this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) { + return; } + + $fks = $table->getForeignKeys(); + self::assertCount(1, $fks); + $foreignKey = current($fks); + self::assertEquals('alter_table_foreign', strtolower($foreignKey->getForeignTableName())); + self::assertEquals(['foreign_key_test'], array_map('strtolower', $foreignKey->getColumns())); + self::assertEquals(['id'], array_map('strtolower', $foreignKey->getForeignColumns())); } @@ -634,16 +646,16 @@ public function testTableInNamespace() public function testCreateAndListViews() { - if (!$this->_sm->getDatabasePlatform()->supportsViews()) { + if (! $this->_sm->getDatabasePlatform()->supportsViews()) { $this->markTestSkipped('Views is not supported by this platform.'); } $this->createTestTable('view_test_table'); - $name = "doctrine_test_view"; - $sql = "SELECT * FROM view_test_table"; + $name = 'doctrine_test_view'; + $sql = 'SELECT * FROM view_test_table'; - $view = new \Doctrine\DBAL\Schema\View($name, $sql); + $view = new View($name, $sql); $this->_sm->dropAndCreateView($view); @@ -652,14 +664,14 @@ public function testCreateAndListViews() public function testAutoincrementDetection() { - if (!$this->_sm->getDatabasePlatform()->supportsIdentityColumns()) { + if (! $this->_sm->getDatabasePlatform()->supportsIdentityColumns()) { $this->markTestSkipped('This test is only supported on platforms that have autoincrement'); } $table = new Table('test_autoincrement'); $table->setSchemaConfig($this->_sm->createSchemaConfig()); - $table->addColumn('id', 'integer', array('autoincrement' => true)); - $table->setPrimaryKey(array('id')); + $table->addColumn('id', 'integer', ['autoincrement' => true]); + $table->setPrimaryKey(['id']); $this->_sm->createTable($table); @@ -673,7 +685,7 @@ public function testAutoincrementDetection() */ public function testAutoincrementDetectionMulticolumns() { - if (!$this->_sm->getDatabasePlatform()->supportsIdentityColumns()) { + if (! $this->_sm->getDatabasePlatform()->supportsIdentityColumns()) { $this->markTestSkipped('This test is only supported on platforms that have autoincrement'); } @@ -681,7 +693,7 @@ public function testAutoincrementDetectionMulticolumns() $table->setSchemaConfig($this->_sm->createSchemaConfig()); $table->addColumn('id', 'integer'); $table->addColumn('other_id', 'integer'); - $table->setPrimaryKey(array('id', 'other_id')); + $table->setPrimaryKey(['id', 'other_id']); $this->_sm->createTable($table); @@ -695,21 +707,21 @@ public function testAutoincrementDetectionMulticolumns() */ public function testUpdateSchemaWithForeignKeyRenaming() { - if (!$this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) { + if (! $this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped('This test is only supported on platforms that have foreign keys.'); } $table = new Table('test_fk_base'); $table->addColumn('id', 'integer'); - $table->setPrimaryKey(array('id')); + $table->setPrimaryKey(['id']); $tableFK = new Table('test_fk_rename'); $tableFK->setSchemaConfig($this->_sm->createSchemaConfig()); $tableFK->addColumn('id', 'integer'); $tableFK->addColumn('fk_id', 'integer'); - $tableFK->setPrimaryKey(array('id')); - $tableFK->addIndex(array('fk_id'), 'fk_idx'); - $tableFK->addForeignKeyConstraint('test_fk_base', array('fk_id'), array('id')); + $tableFK->setPrimaryKey(['id']); + $tableFK->addIndex(['fk_id'], 'fk_idx'); + $tableFK->addForeignKeyConstraint('test_fk_base', ['fk_id'], ['id']); $this->_sm->createTable($table); $this->_sm->createTable($tableFK); @@ -718,11 +730,11 @@ public function testUpdateSchemaWithForeignKeyRenaming() $tableFKNew->setSchemaConfig($this->_sm->createSchemaConfig()); $tableFKNew->addColumn('id', 'integer'); $tableFKNew->addColumn('rename_fk_id', 'integer'); - $tableFKNew->setPrimaryKey(array('id')); - $tableFKNew->addIndex(array('rename_fk_id'), 'fk_idx'); - $tableFKNew->addForeignKeyConstraint('test_fk_base', array('rename_fk_id'), array('id')); + $tableFKNew->setPrimaryKey(['id']); + $tableFKNew->addIndex(['rename_fk_id'], 'fk_idx'); + $tableFKNew->addForeignKeyConstraint('test_fk_base', ['rename_fk_id'], ['id']); - $c = new \Doctrine\DBAL\Schema\Comparator(); + $c = new Comparator(); $tableDiff = $c->diffTable($tableFK, $tableFKNew); $this->_sm->alterTable($tableDiff); @@ -746,16 +758,16 @@ public function testRenameIndexUsedInForeignKeyConstraint() $primaryTable = new Table('test_rename_index_primary'); $primaryTable->addColumn('id', 'integer'); - $primaryTable->setPrimaryKey(array('id')); + $primaryTable->setPrimaryKey(['id']); $foreignTable = new Table('test_rename_index_foreign'); $foreignTable->addColumn('fk', 'integer'); - $foreignTable->addIndex(array('fk'), 'rename_index_fk_idx'); + $foreignTable->addIndex(['fk'], 'rename_index_fk_idx'); $foreignTable->addForeignKeyConstraint( 'test_rename_index_primary', - array('fk'), - array('id'), - array(), + ['fk'], + ['id'], + [], 'fk_constraint' ); @@ -781,37 +793,41 @@ public function testRenameIndexUsedInForeignKeyConstraint() */ public function testGetColumnComment() { - if ( ! $this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && + if (! $this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && ! $this->_conn->getDatabasePlatform()->supportsCommentOnStatement() && - $this->_conn->getDatabasePlatform()->getName() != 'mssql') { + $this->_conn->getDatabasePlatform()->getName() !== 'mssql') { $this->markTestSkipped('Database does not support column comments.'); } $table = new Table('column_comment_test'); - $table->addColumn('id', 'integer', array('comment' => 'This is a comment')); - $table->setPrimaryKey(array('id')); + $table->addColumn('id', 'integer', ['comment' => 'This is a comment']); + $table->setPrimaryKey(['id']); $this->_sm->createTable($table); - $columns = $this->_sm->listTableColumns("column_comment_test"); + $columns = $this->_sm->listTableColumns('column_comment_test'); self::assertEquals(1, count($columns)); self::assertEquals('This is a comment', $columns['id']->getComment()); - $tableDiff = new \Doctrine\DBAL\Schema\TableDiff('column_comment_test'); - $tableDiff->fromTable = $table; - $tableDiff->changedColumns['id'] = new \Doctrine\DBAL\Schema\ColumnDiff( - 'id', new \Doctrine\DBAL\Schema\Column( - 'id', \Doctrine\DBAL\Types\Type::getType('integer') + $tableDiff = new TableDiff('column_comment_test'); + $tableDiff->fromTable = $table; + $tableDiff->changedColumns['id'] = new ColumnDiff( + 'id', + new Column( + 'id', + Type::getType('integer') ), - array('comment'), - new \Doctrine\DBAL\Schema\Column( - 'id', \Doctrine\DBAL\Types\Type::getType('integer'), array('comment' => 'This is a comment') + ['comment'], + new Column( + 'id', + Type::getType('integer'), + ['comment' => 'This is a comment'] ) ); $this->_sm->alterTable($tableDiff); - $columns = $this->_sm->listTableColumns("column_comment_test"); + $columns = $this->_sm->listTableColumns('column_comment_test'); self::assertEquals(1, count($columns)); self::assertEmpty($columns['id']->getComment()); } @@ -821,27 +837,27 @@ public function testGetColumnComment() */ public function testAutomaticallyAppendCommentOnMarkedColumns() { - if ( ! $this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && + if (! $this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && ! $this->_conn->getDatabasePlatform()->supportsCommentOnStatement() && - $this->_conn->getDatabasePlatform()->getName() != 'mssql') { + $this->_conn->getDatabasePlatform()->getName() !== 'mssql') { $this->markTestSkipped('Database does not support column comments.'); } $table = new Table('column_comment_test2'); - $table->addColumn('id', 'integer', array('comment' => 'This is a comment')); - $table->addColumn('obj', 'object', array('comment' => 'This is a comment')); - $table->addColumn('arr', 'array', array('comment' => 'This is a comment')); - $table->setPrimaryKey(array('id')); + $table->addColumn('id', 'integer', ['comment' => 'This is a comment']); + $table->addColumn('obj', 'object', ['comment' => 'This is a comment']); + $table->addColumn('arr', 'array', ['comment' => 'This is a comment']); + $table->setPrimaryKey(['id']); $this->_sm->createTable($table); - $columns = $this->_sm->listTableColumns("column_comment_test2"); + $columns = $this->_sm->listTableColumns('column_comment_test2'); self::assertEquals(3, count($columns)); self::assertEquals('This is a comment', $columns['id']->getComment()); - self::assertEquals('This is a comment', $columns['obj']->getComment(), "The Doctrine2 Typehint should be stripped from comment."); - self::assertInstanceOf('Doctrine\DBAL\Types\ObjectType', $columns['obj']->getType(), "The Doctrine2 should be detected from comment hint."); - self::assertEquals('This is a comment', $columns['arr']->getComment(), "The Doctrine2 Typehint should be stripped from comment."); - self::assertInstanceOf('Doctrine\DBAL\Types\ArrayType', $columns['arr']->getType(), "The Doctrine2 should be detected from comment hint."); + self::assertEquals('This is a comment', $columns['obj']->getComment(), 'The Doctrine2 Typehint should be stripped from comment.'); + self::assertInstanceOf('Doctrine\DBAL\Types\ObjectType', $columns['obj']->getType(), 'The Doctrine2 should be detected from comment hint.'); + self::assertEquals('This is a comment', $columns['arr']->getComment(), 'The Doctrine2 Typehint should be stripped from comment.'); + self::assertInstanceOf('Doctrine\DBAL\Types\ArrayType', $columns['arr']->getType(), 'The Doctrine2 should be detected from comment hint.'); } /** @@ -849,24 +865,24 @@ public function testAutomaticallyAppendCommentOnMarkedColumns() */ public function testCommentHintOnDateIntervalTypeColumn() { - if ( ! $this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && + if (! $this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && ! $this->_conn->getDatabasePlatform()->supportsCommentOnStatement() && - $this->_conn->getDatabasePlatform()->getName() != 'mssql') { + $this->_conn->getDatabasePlatform()->getName() !== 'mssql') { $this->markTestSkipped('Database does not support column comments.'); } $table = new Table('column_dateinterval_comment'); - $table->addColumn('id', 'integer', array('comment' => 'This is a comment')); - $table->addColumn('date_interval', 'dateinterval', array('comment' => 'This is a comment')); - $table->setPrimaryKey(array('id')); + $table->addColumn('id', 'integer', ['comment' => 'This is a comment']); + $table->addColumn('date_interval', 'dateinterval', ['comment' => 'This is a comment']); + $table->setPrimaryKey(['id']); $this->_sm->createTable($table); - $columns = $this->_sm->listTableColumns("column_dateinterval_comment"); + $columns = $this->_sm->listTableColumns('column_dateinterval_comment'); self::assertEquals(2, count($columns)); self::assertEquals('This is a comment', $columns['id']->getComment()); - self::assertEquals('This is a comment', $columns['date_interval']->getComment(), "The Doctrine2 Typehint should be stripped from comment."); - self::assertInstanceOf('Doctrine\DBAL\Types\DateIntervalType', $columns['date_interval']->getType(), "The Doctrine2 should be detected from comment hint."); + self::assertEquals('This is a comment', $columns['date_interval']->getComment(), 'The Doctrine2 Typehint should be stripped from comment.'); + self::assertInstanceOf('Doctrine\DBAL\Types\DateIntervalType', $columns['date_interval']->getType(), 'The Doctrine2 should be detected from comment hint.'); } /** @@ -877,25 +893,25 @@ public function testChangeColumnsTypeWithDefaultValue() $tableName = 'column_def_change_type'; $table = new Table($tableName); - $table->addColumn('col_int', 'smallint', array('default' => 666)); - $table->addColumn('col_string', 'string', array('default' => 'foo')); + $table->addColumn('col_int', 'smallint', ['default' => 666]); + $table->addColumn('col_string', 'string', ['default' => 'foo']); $this->_sm->dropAndCreateTable($table); - $tableDiff = new TableDiff($tableName); - $tableDiff->fromTable = $table; + $tableDiff = new TableDiff($tableName); + $tableDiff->fromTable = $table; $tableDiff->changedColumns['col_int'] = new ColumnDiff( 'col_int', - new Column('col_int', Type::getType('integer'), array('default' => 666)), - array('type'), - new Column('col_int', Type::getType('smallint'), array('default' => 666)) + new Column('col_int', Type::getType('integer'), ['default' => 666]), + ['type'], + new Column('col_int', Type::getType('smallint'), ['default' => 666]) ); $tableDiff->changedColumns['col_string'] = new ColumnDiff( 'col_string', - new Column('col_string', Type::getType('string'), array('default' => 'foo', 'fixed' => true)), - array('fixed'), - new Column('col_string', Type::getType('string'), array('default' => 'foo')) + new Column('col_string', Type::getType('string'), ['default' => 'foo', 'fixed' => true]), + ['fixed'], + new Column('col_string', Type::getType('string'), ['default' => 'foo']) ); $this->_sm->alterTable($tableDiff); @@ -931,9 +947,10 @@ public function testListTableWithBlob() /** * @param string $name * @param array $data + * * @return Table */ - protected function createTestTable($name = 'test_table', $data = array()) + protected function createTestTable($name = 'test_table', $data = []) { $options = $data['options'] ?? []; @@ -944,25 +961,25 @@ protected function createTestTable($name = 'test_table', $data = array()) return $table; } - protected function getTestTable($name, $options=array()) + protected function getTestTable($name, $options = []) { - $table = new Table($name, array(), array(), array(), false, $options); + $table = new Table($name, [], [], [], false, $options); $table->setSchemaConfig($this->_sm->createSchemaConfig()); - $table->addColumn('id', 'integer', array('notnull' => true)); - $table->setPrimaryKey(array('id')); - $table->addColumn('test', 'string', array('length' => 255)); + $table->addColumn('id', 'integer', ['notnull' => true]); + $table->setPrimaryKey(['id']); + $table->addColumn('test', 'string', ['length' => 255]); $table->addColumn('foreign_key_test', 'integer'); return $table; } protected function getTestCompositeTable($name) { - $table = new Table($name, array(), array(), array(), false, array()); + $table = new Table($name, [], [], [], false, []); $table->setSchemaConfig($this->_sm->createSchemaConfig()); - $table->addColumn('id', 'integer', array('notnull' => true)); - $table->addColumn('other_id', 'integer', array('notnull' => true)); - $table->setPrimaryKey(array('id', 'other_id')); - $table->addColumn('test', 'string', array('length' => 255)); + $table->addColumn('id', 'integer', ['notnull' => true]); + $table->addColumn('other_id', 'integer', ['notnull' => true]); + $table->setPrimaryKey(['id', 'other_id']); + $table->addColumn('test', 'string', ['length' => 255]); return $table; } @@ -971,24 +988,29 @@ protected function assertHasTable($tables, $tableName) $foundTable = false; foreach ($tables as $table) { self::assertInstanceOf('Doctrine\DBAL\Schema\Table', $table, 'No Table instance was found in tables array.'); - if (strtolower($table->getName()) == 'list_tables_test_new_name') { - $foundTable = true; + if (strtolower($table->getName()) !== 'list_tables_test_new_name') { + continue; } + + $foundTable = true; } - self::assertTrue($foundTable, "Could not find new table"); + self::assertTrue($foundTable, 'Could not find new table'); } public function testListForeignKeysComposite() { - if(!$this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { + if (! $this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped('Does not support foreign key constraints.'); } $this->_sm->createTable($this->getTestTable('test_create_fk3')); $this->_sm->createTable($this->getTestCompositeTable('test_create_fk4')); - $foreignKey = new \Doctrine\DBAL\Schema\ForeignKeyConstraint( - array('id', 'foreign_key_test'), 'test_create_fk4', array('id', 'other_id'), 'foreign_key_test_fk2' + $foreignKey = new ForeignKeyConstraint( + ['id', 'foreign_key_test'], + 'test_create_fk4', + ['id', 'other_id'], + 'foreign_key_test_fk2' ); $this->_sm->createForeignKey($foreignKey, 'test_create_fk3'); @@ -998,8 +1020,8 @@ public function testListForeignKeysComposite() self::assertEquals(1, count($fkeys), "Table 'test_create_fk3' has to have one foreign key."); self::assertInstanceOf('Doctrine\DBAL\Schema\ForeignKeyConstraint', $fkeys[0]); - self::assertEquals(array('id', 'foreign_key_test'), array_map('strtolower', $fkeys[0]->getLocalColumns())); - self::assertEquals(array('id', 'other_id'), array_map('strtolower', $fkeys[0]->getForeignColumns())); + self::assertEquals(['id', 'foreign_key_test'], array_map('strtolower', $fkeys[0]->getLocalColumns())); + self::assertEquals(['id', 'other_id'], array_map('strtolower', $fkeys[0]->getForeignColumns())); } /** @@ -1007,16 +1029,16 @@ public function testListForeignKeysComposite() */ public function testColumnDefaultLifecycle() { - $table = new Table("col_def_lifecycle"); - $table->addColumn('id', 'integer', array('autoincrement' => true)); - $table->addColumn('column1', 'string', array('default' => null)); - $table->addColumn('column2', 'string', array('default' => false)); - $table->addColumn('column3', 'string', array('default' => true)); - $table->addColumn('column4', 'string', array('default' => 0)); - $table->addColumn('column5', 'string', array('default' => '')); - $table->addColumn('column6', 'string', array('default' => 'def')); - $table->addColumn('column7', 'integer', array('default' => 0)); - $table->setPrimaryKey(array('id')); + $table = new Table('col_def_lifecycle'); + $table->addColumn('id', 'integer', ['autoincrement' => true]); + $table->addColumn('column1', 'string', ['default' => null]); + $table->addColumn('column2', 'string', ['default' => false]); + $table->addColumn('column3', 'string', ['default' => true]); + $table->addColumn('column4', 'string', ['default' => 0]); + $table->addColumn('column5', 'string', ['default' => '']); + $table->addColumn('column6', 'string', ['default' => 'def']); + $table->addColumn('column7', 'integer', ['default' => 0]); + $table->setPrimaryKey(['id']); $this->_sm->dropAndCreateTable($table); @@ -1033,13 +1055,13 @@ public function testColumnDefaultLifecycle() $diffTable = clone $table; - $diffTable->changeColumn('column1', array('default' => false)); - $diffTable->changeColumn('column2', array('default' => null)); - $diffTable->changeColumn('column3', array('default' => false)); - $diffTable->changeColumn('column4', array('default' => null)); - $diffTable->changeColumn('column5', array('default' => false)); - $diffTable->changeColumn('column6', array('default' => 666)); - $diffTable->changeColumn('column7', array('default' => null)); + $diffTable->changeColumn('column1', ['default' => false]); + $diffTable->changeColumn('column2', ['default' => null]); + $diffTable->changeColumn('column3', ['default' => false]); + $diffTable->changeColumn('column4', ['default' => null]); + $diffTable->changeColumn('column5', ['default' => false]); + $diffTable->changeColumn('column6', ['default' => 666]); + $diffTable->changeColumn('column7', ['default' => null]); $comparator = new Comparator(); @@ -1062,9 +1084,9 @@ public function testListTableWithBinary() $table = new Table($tableName); $table->addColumn('id', 'integer'); - $table->addColumn('column_varbinary', 'binary', array()); - $table->addColumn('column_binary', 'binary', array('fixed' => true)); - $table->setPrimaryKey(array('id')); + $table->addColumn('column_varbinary', 'binary', []); + $table->addColumn('column_binary', 'binary', ['fixed' => true]); + $table->setPrimaryKey(['id']); $this->_sm->createTable($table); @@ -1079,7 +1101,7 @@ public function testListTableWithBinary() public function testListTableDetailsWithFullQualifiedTableName() { - if ( ! $this->_sm->getDatabasePlatform()->supportsSchemas()) { + if (! $this->_sm->getDatabasePlatform()->supportsSchemas()) { $this->markTestSkipped('Test only works on platforms that support schemas.'); } @@ -1088,18 +1110,18 @@ public function testListTableDetailsWithFullQualifiedTableName() $foreignTableName = 'foreign_table'; $table = new Table($foreignTableName); - $table->addColumn('id', 'integer', array('autoincrement' => true)); - $table->setPrimaryKey(array('id')); + $table->addColumn('id', 'integer', ['autoincrement' => true]); + $table->setPrimaryKey(['id']); $this->_sm->dropAndCreateTable($table); $table = new Table($primaryTableName); - $table->addColumn('id', 'integer', array('autoincrement' => true)); + $table->addColumn('id', 'integer', ['autoincrement' => true]); $table->addColumn('foo', 'integer'); $table->addColumn('bar', 'string'); - $table->addForeignKeyConstraint($foreignTableName, array('foo'), array('id')); - $table->addIndex(array('bar')); - $table->setPrimaryKey(array('id')); + $table->addForeignKeyConstraint($foreignTableName, ['foo'], ['id']); + $table->addIndex(['bar']); + $table->setPrimaryKey(['id']); $this->_sm->dropAndCreateTable($table); @@ -1119,38 +1141,38 @@ public function testListTableDetailsWithFullQualifiedTableName() public function testCommentStringsAreQuoted() { - if ( ! $this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && + if (! $this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && ! $this->_conn->getDatabasePlatform()->supportsCommentOnStatement() && - $this->_conn->getDatabasePlatform()->getName() != 'mssql') { + $this->_conn->getDatabasePlatform()->getName() !== 'mssql') { $this->markTestSkipped('Database does not support column comments.'); } $table = new Table('my_table'); - $table->addColumn('id', 'integer', array('comment' => "It's a comment with a quote")); - $table->setPrimaryKey(array('id')); + $table->addColumn('id', 'integer', ['comment' => "It's a comment with a quote"]); + $table->setPrimaryKey(['id']); $this->_sm->createTable($table); - $columns = $this->_sm->listTableColumns("my_table"); + $columns = $this->_sm->listTableColumns('my_table'); self::assertEquals("It's a comment with a quote", $columns['id']->getComment()); } public function testCommentNotDuplicated() { - if ( ! $this->_conn->getDatabasePlatform()->supportsInlineColumnComments()) { + if (! $this->_conn->getDatabasePlatform()->supportsInlineColumnComments()) { $this->markTestSkipped('Database does not support column comments.'); } - $options = array( + $options = [ 'type' => Type::getType('integer'), 'default' => 0, 'notnull' => true, 'comment' => 'expected+column+comment', - ); + ]; $columnDefinition = substr($this->_conn->getDatabasePlatform()->getColumnDeclarationSQL('id', $options), strlen('id') + 1); $table = new Table('my_table'); - $table->addColumn('id', 'integer', array('columnDefinition' => $columnDefinition, 'comment' => 'unexpected_column_comment')); + $table->addColumn('id', 'integer', ['columnDefinition' => $columnDefinition, 'comment' => 'unexpected_column_comment']); $sql = $this->_conn->getDatabasePlatform()->getCreateTableSQL($table); self::assertContains('expected+column+comment', $sql[0]); @@ -1159,35 +1181,34 @@ public function testCommentNotDuplicated() /** * @group DBAL-1009 - * * @dataProvider getAlterColumnComment */ public function testAlterColumnComment($comment1, $expectedComment1, $comment2, $expectedComment2) { - if ( ! $this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && + if (! $this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && ! $this->_conn->getDatabasePlatform()->supportsCommentOnStatement() && - $this->_conn->getDatabasePlatform()->getName() != 'mssql') { + $this->_conn->getDatabasePlatform()->getName() !== 'mssql') { $this->markTestSkipped('Database does not support column comments.'); } $offlineTable = new Table('alter_column_comment_test'); - $offlineTable->addColumn('comment1', 'integer', array('comment' => $comment1)); - $offlineTable->addColumn('comment2', 'integer', array('comment' => $comment2)); + $offlineTable->addColumn('comment1', 'integer', ['comment' => $comment1]); + $offlineTable->addColumn('comment2', 'integer', ['comment' => $comment2]); $offlineTable->addColumn('no_comment1', 'integer'); $offlineTable->addColumn('no_comment2', 'integer'); $this->_sm->dropAndCreateTable($offlineTable); - $onlineTable = $this->_sm->listTableDetails("alter_column_comment_test"); + $onlineTable = $this->_sm->listTableDetails('alter_column_comment_test'); self::assertSame($expectedComment1, $onlineTable->getColumn('comment1')->getComment()); self::assertSame($expectedComment2, $onlineTable->getColumn('comment2')->getComment()); self::assertNull($onlineTable->getColumn('no_comment1')->getComment()); self::assertNull($onlineTable->getColumn('no_comment2')->getComment()); - $onlineTable->changeColumn('comment1', array('comment' => $comment2)); - $onlineTable->changeColumn('comment2', array('comment' => $comment1)); - $onlineTable->changeColumn('no_comment1', array('comment' => $comment1)); - $onlineTable->changeColumn('no_comment2', array('comment' => $comment2)); + $onlineTable->changeColumn('comment1', ['comment' => $comment2]); + $onlineTable->changeColumn('comment2', ['comment' => $comment1]); + $onlineTable->changeColumn('no_comment1', ['comment' => $comment1]); + $onlineTable->changeColumn('no_comment2', ['comment' => $comment2]); $comparator = new Comparator(); @@ -1197,7 +1218,7 @@ public function testAlterColumnComment($comment1, $expectedComment1, $comment2, $this->_sm->alterTable($tableDiff); - $onlineTable = $this->_sm->listTableDetails("alter_column_comment_test"); + $onlineTable = $this->_sm->listTableDetails('alter_column_comment_test'); self::assertSame($expectedComment2, $onlineTable->getColumn('comment1')->getComment()); self::assertSame($expectedComment1, $onlineTable->getColumn('comment2')->getComment()); @@ -1207,20 +1228,20 @@ public function testAlterColumnComment($comment1, $expectedComment1, $comment2, public function getAlterColumnComment() { - return array( - array(null, null, ' ', ' '), - array(null, null, '0', '0'), - array(null, null, 'foo', 'foo'), + return [ + [null, null, ' ', ' '], + [null, null, '0', '0'], + [null, null, 'foo', 'foo'], - array('', null, ' ', ' '), - array('', null, '0', '0'), - array('', null, 'foo', 'foo'), + ['', null, ' ', ' '], + ['', null, '0', '0'], + ['', null, 'foo', 'foo'], - array(' ', ' ', '0', '0'), - array(' ', ' ', 'foo', 'foo'), + [' ', ' ', '0', '0'], + [' ', ' ', 'foo', 'foo'], - array('0', '0', 'foo', 'foo'), - ); + ['0', '0', 'foo', 'foo'], + ]; } /** @@ -1234,14 +1255,14 @@ public function testDoesNotListIndexesImplicitlyCreatedByForeignKeys() $primaryTable = new Table('test_list_index_impl_primary'); $primaryTable->addColumn('id', 'integer'); - $primaryTable->setPrimaryKey(array('id')); + $primaryTable->setPrimaryKey(['id']); $foreignTable = new Table('test_list_index_impl_foreign'); $foreignTable->addColumn('fk1', 'integer'); $foreignTable->addColumn('fk2', 'integer'); - $foreignTable->addIndex(array('fk1'), 'explicit_fk1_idx'); - $foreignTable->addForeignKeyConstraint('test_list_index_impl_primary', array('fk1'), array('id')); - $foreignTable->addForeignKeyConstraint('test_list_index_impl_primary', array('fk2'), array('id')); + $foreignTable->addIndex(['fk1'], 'explicit_fk1_idx'); + $foreignTable->addForeignKeyConstraint('test_list_index_impl_primary', ['fk1'], ['id']); + $foreignTable->addForeignKeyConstraint('test_list_index_impl_primary', ['fk2'], ['id']); $this->_sm->dropAndCreateTable($primaryTable); $this->_sm->dropAndCreateTable($foreignTable); @@ -1258,9 +1279,11 @@ public function testDoesNotListIndexesImplicitlyCreatedByForeignKeys() */ public function removeJsonArrayTable() : void { - if ($this->_sm->tablesExist(['json_array_test'])) { - $this->_sm->dropTable('json_array_test'); + if (! $this->_sm->tablesExist(['json_array_test'])) { + return; } + + $this->_sm->dropTable('json_array_test'); } /** @@ -1314,7 +1337,7 @@ public function testComparatorShouldModifyOnlyTheCommentWhenUpdatingFromJsonArra */ public function testComparatorShouldAddCommentToLegacyJsonArrayTypeThatDoesNotHaveIt() : void { - if ( ! $this->_sm->getDatabasePlatform()->hasNativeJsonType()) { + if (! $this->_sm->getDatabasePlatform()->hasNativeJsonType()) { $this->markTestSkipped('This test is only supported on platforms that have native JSON type.'); } @@ -1336,7 +1359,7 @@ public function testComparatorShouldAddCommentToLegacyJsonArrayTypeThatDoesNotHa */ public function testComparatorShouldReturnAllChangesWhenUsingLegacyJsonArrayType() : void { - if ( ! $this->_sm->getDatabasePlatform()->hasNativeJsonType()) { + if (! $this->_sm->getDatabasePlatform()->hasNativeJsonType()) { $this->markTestSkipped('This test is only supported on platforms that have native JSON type.'); } @@ -1358,7 +1381,7 @@ public function testComparatorShouldReturnAllChangesWhenUsingLegacyJsonArrayType */ public function testComparatorShouldReturnAllChangesWhenUsingLegacyJsonArrayTypeEvenWhenPlatformHasJsonSupport() : void { - if ( ! $this->_sm->getDatabasePlatform()->hasNativeJsonType()) { + if (! $this->_sm->getDatabasePlatform()->hasNativeJsonType()) { $this->markTestSkipped('This test is only supported on platforms that have native JSON type.'); } @@ -1380,7 +1403,7 @@ public function testComparatorShouldReturnAllChangesWhenUsingLegacyJsonArrayType */ public function testComparatorShouldNotAddCommentToJsonTypeSinceItIsTheDefaultNow() : void { - if ( ! $this->_sm->getDatabasePlatform()->hasNativeJsonType()) { + if (! $this->_sm->getDatabasePlatform()->hasNativeJsonType()) { $this->markTestSkipped('This test is only supported on platforms that have native JSON type.'); } @@ -1397,7 +1420,6 @@ public function testComparatorShouldNotAddCommentToJsonTypeSinceItIsTheDefaultNo /** * @dataProvider commentsProvider - * * @group 2596 */ public function testExtractDoctrineTypeFromComment(string $comment, string $expected, string $currentType) : void @@ -1423,7 +1445,7 @@ public function commentsProvider() : array public function testCreateAndListSequences() : void { - if ( ! $this->_sm->getDatabasePlatform()->supportsSequences()) { + if (! $this->_sm->getDatabasePlatform()->supportsSequences()) { self::markTestSkipped('This test is only supported on platforms that support sequences.'); } @@ -1476,7 +1498,7 @@ public function testComparisonWithAutoDetectedSequenceDefinition() : void $createdSequence = array_values( array_filter( $this->_sm->listSequences(), - function (Sequence $sequence) use ($sequenceName) : bool { + static function (Sequence $sequence) use ($sequenceName) : bool { return strcasecmp($sequence->getName(), $sequenceName) === 0; } ) diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php index 14efbff3cce..ca42061b695 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php @@ -3,7 +3,9 @@ namespace Doctrine\Tests\DBAL\Functional\Schema; use Doctrine\DBAL\Schema; +use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Type; +use SQLite3; use function array_map; use function dirname; use function extension_loaded; @@ -23,7 +25,7 @@ public function testListDatabases() public function testCreateAndDropDatabase() { - $path = dirname(__FILE__).'/test_create_and_drop_sqlite_database.sqlite'; + $path = dirname(__FILE__) . '/test_create_and_drop_sqlite_database.sqlite'; $this->_sm->createDatabase($path); self::assertFileExists($path); @@ -40,10 +42,10 @@ public function testDropsDatabaseWithActiveConnections() self::assertFileExists('test_drop_database'); - $params = $this->_conn->getParams(); + $params = $this->_conn->getParams(); $params['dbname'] = 'test_drop_database'; - $user = $params['user'] ?? null; + $user = $params['user'] ?? null; $password = $params['password'] ?? null; $connection = $this->_conn->getDriver()->connect($params, $user, $password); @@ -88,14 +90,29 @@ public function testListForeignKeysFromExistingDatabase() EOS ); - $expected = array( - new Schema\ForeignKeyConstraint(array('log'), 'log', array(null), 'FK_3', - array('onUpdate' => 'SET NULL', 'onDelete' => 'NO ACTION', 'deferrable' => false, 'deferred' => false)), - new Schema\ForeignKeyConstraint(array('parent'), 'user', array('id'), '1', - array('onUpdate' => 'NO ACTION', 'onDelete' => 'CASCADE', 'deferrable' => false, 'deferred' => false)), - new Schema\ForeignKeyConstraint(array('page'), 'page', array('key'), 'FK_1', - array('onUpdate' => 'NO ACTION', 'onDelete' => 'NO ACTION', 'deferrable' => true, 'deferred' => true)), - ); + $expected = [ + new Schema\ForeignKeyConstraint( + ['log'], + 'log', + [null], + 'FK_3', + ['onUpdate' => 'SET NULL', 'onDelete' => 'NO ACTION', 'deferrable' => false, 'deferred' => false] + ), + new Schema\ForeignKeyConstraint( + ['parent'], + 'user', + ['id'], + '1', + ['onUpdate' => 'NO ACTION', 'onDelete' => 'CASCADE', 'deferrable' => false, 'deferred' => false] + ), + new Schema\ForeignKeyConstraint( + ['page'], + 'page', + ['key'], + 'FK_1', + ['onUpdate' => 'NO ACTION', 'onDelete' => 'NO ACTION', 'deferrable' => true, 'deferred' => true] + ), + ]; self::assertEquals($expected, $this->_sm->listTableForeignKeys('user')); } @@ -121,11 +138,11 @@ public function testListTableWithBinary() { $tableName = 'test_binary_table'; - $table = new \Doctrine\DBAL\Schema\Table($tableName); + $table = new Table($tableName); $table->addColumn('id', 'integer'); - $table->addColumn('column_varbinary', 'binary', array()); - $table->addColumn('column_binary', 'binary', array('fixed' => true)); - $table->setPrimaryKey(array('id')); + $table->addColumn('column_varbinary', 'binary', []); + $table->addColumn('column_binary', 'binary', ['fixed' => true]); + $table->setPrimaryKey(['id']); $this->_sm->createTable($table); @@ -140,12 +157,12 @@ public function testListTableWithBinary() public function testNonDefaultPKOrder() { - if ( ! extension_loaded('sqlite3')) { + if (! extension_loaded('sqlite3')) { $this->markTestSkipped('This test requires the SQLite3 extension.'); } - $version = \SQLite3::version(); - if(version_compare($version['versionString'], '3.7.16', '<')) { + $version = SQLite3::version(); + if (version_compare($version['versionString'], '3.7.16', '<')) { $this->markTestSkipped('This version of sqlite doesn\'t return the order of the Primary Key.'); } $this->_conn->exec(<<getColumns())); + self::assertEquals(['other_id', 'id'], array_map('strtolower', $tableIndexes['primary']->getColumns())); } /** @@ -201,15 +218,15 @@ public function testDiffListIntegerAutoincrementTableColumns($integerType, $unsi { $tableName = 'test_int_autoincrement_table'; - $offlineTable = new \Doctrine\DBAL\Schema\Table($tableName); - $offlineTable->addColumn('id', $integerType, array('autoincrement' => true, 'unsigned' => $unsigned)); - $offlineTable->setPrimaryKey(array('id')); + $offlineTable = new Table($tableName); + $offlineTable->addColumn('id', $integerType, ['autoincrement' => true, 'unsigned' => $unsigned]); + $offlineTable->setPrimaryKey(['id']); $this->_sm->dropAndCreateTable($offlineTable); $onlineTable = $this->_sm->listTableDetails($tableName); - $comparator = new Schema\Comparator(); - $diff = $comparator->diffTable($offlineTable, $onlineTable); + $comparator = new Schema\Comparator(); + $diff = $comparator->diffTable($offlineTable, $onlineTable); if ($expectedComparatorDiff) { self::assertEmpty($this->_sm->getDatabasePlatform()->getAlterTableSQL($diff)); @@ -223,14 +240,14 @@ public function testDiffListIntegerAutoincrementTableColumns($integerType, $unsi */ public function getDiffListIntegerAutoincrementTableColumnsData() { - return array( - array('smallint', false, true), - array('smallint', true, true), - array('integer', false, false), - array('integer', true, true), - array('bigint', false, true), - array('bigint', true, true), - ); + return [ + ['smallint', false, true], + ['smallint', true, true], + ['integer', false, false], + ['integer', true, true], + ['bigint', false, true], + ['bigint', true, true], + ]; } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/StatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/StatementTest.php index 480cec4c53c..7c8585c3f77 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/StatementTest.php @@ -7,10 +7,11 @@ use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Type; +use Doctrine\Tests\DbalFunctionalTestCase; use function base64_decode; use function stream_get_contents; -class StatementTest extends \Doctrine\Tests\DbalFunctionalTestCase +class StatementTest extends DbalFunctionalTestCase { protected function setUp() { @@ -18,14 +19,14 @@ protected function setUp() $table = new Table('stmt_test'); $table->addColumn('id', 'integer'); - $table->addColumn('name', 'text', array('notnull' => false)); + $table->addColumn('name', 'text', ['notnull' => false]); $this->_conn->getSchemaManager()->dropAndCreateTable($table); } public function testStatementIsReusableAfterClosingCursor() { - $this->_conn->insert('stmt_test', array('id' => 1)); - $this->_conn->insert('stmt_test', array('id' => 2)); + $this->_conn->insert('stmt_test', ['id' => 1]); + $this->_conn->insert('stmt_test', ['id' => 2]); $stmt = $this->_conn->prepare('SELECT id FROM stmt_test ORDER BY id'); @@ -45,35 +46,35 @@ public function testStatementIsReusableAfterClosingCursor() public function testReuseStatementWithLongerResults() { - $sm = $this->_conn->getSchemaManager(); + $sm = $this->_conn->getSchemaManager(); $table = new Table('stmt_longer_results'); $table->addColumn('param', 'string'); $table->addColumn('val', 'text'); $sm->createTable($table); - $row1 = array( + $row1 = [ 'param' => 'param1', 'val' => 'X', - ); + ]; $this->_conn->insert('stmt_longer_results', $row1); $stmt = $this->_conn->prepare('SELECT param, val FROM stmt_longer_results ORDER BY param'); $stmt->execute(); - self::assertArraySubset(array( - array('param1', 'X'), - ), $stmt->fetchAll(FetchMode::NUMERIC)); + self::assertArraySubset([ + ['param1', 'X'], + ], $stmt->fetchAll(FetchMode::NUMERIC)); - $row2 = array( + $row2 = [ 'param' => 'param2', 'val' => 'A bit longer value', - ); + ]; $this->_conn->insert('stmt_longer_results', $row2); $stmt->execute(); - self::assertArraySubset(array( - array('param1', 'X'), - array('param2', 'A bit longer value'), - ), $stmt->fetchAll(FetchMode::NUMERIC)); + self::assertArraySubset([ + ['param1', 'X'], + ['param2', 'A bit longer value'], + ], $stmt->fetchAll(FetchMode::NUMERIC)); } public function testFetchLongBlob() @@ -82,11 +83,9 @@ public function testFetchLongBlob() // but is still not enough to store a LONGBLOB of the max possible size $this->iniSet('memory_limit', '4G'); - $sm = $this->_conn->getSchemaManager(); + $sm = $this->_conn->getSchemaManager(); $table = new Table('stmt_long_blob'); - $table->addColumn('contents', 'blob', array( - 'length' => 0xFFFFFFFF, - )); + $table->addColumn('contents', 'blob', ['length' => 0xFFFFFFFF]); $sm->createTable($table); $contents = base64_decode(<<_conn->insert('stmt_long_blob', ['contents' => $contents], [ParameterType::LARGE_OBJECT]); @@ -122,8 +121,8 @@ public function testFetchLongBlob() public function testIncompletelyFetchedStatementDoesNotBlockConnection() { - $this->_conn->insert('stmt_test', array('id' => 1)); - $this->_conn->insert('stmt_test', array('id' => 2)); + $this->_conn->insert('stmt_test', ['id' => 1]); + $this->_conn->insert('stmt_test', ['id' => 2]); $stmt1 = $this->_conn->prepare('SELECT id FROM stmt_test'); $stmt1->execute(); @@ -133,32 +132,32 @@ public function testIncompletelyFetchedStatementDoesNotBlockConnection() $stmt1->fetch(); $stmt2 = $this->_conn->prepare('SELECT id FROM stmt_test WHERE id = ?'); - $stmt2->execute(array(1)); + $stmt2->execute([1]); self::assertEquals(1, $stmt2->fetchColumn()); } public function testReuseStatementAfterClosingCursor() { - $this->_conn->insert('stmt_test', array('id' => 1)); - $this->_conn->insert('stmt_test', array('id' => 2)); + $this->_conn->insert('stmt_test', ['id' => 1]); + $this->_conn->insert('stmt_test', ['id' => 2]); $stmt = $this->_conn->prepare('SELECT id FROM stmt_test WHERE id = ?'); - $stmt->execute(array(1)); + $stmt->execute([1]); $id = $stmt->fetchColumn(); self::assertEquals(1, $id); $stmt->closeCursor(); - $stmt->execute(array(2)); + $stmt->execute([2]); $id = $stmt->fetchColumn(); self::assertEquals(2, $id); } public function testReuseStatementWithParameterBoundByReference() { - $this->_conn->insert('stmt_test', array('id' => 1)); - $this->_conn->insert('stmt_test', array('id' => 2)); + $this->_conn->insert('stmt_test', ['id' => 1]); + $this->_conn->insert('stmt_test', ['id' => 2]); $stmt = $this->_conn->prepare('SELECT id FROM stmt_test WHERE id = ?'); $stmt->bindParam(1, $id); @@ -174,8 +173,8 @@ public function testReuseStatementWithParameterBoundByReference() public function testReuseStatementWithReboundValue() { - $this->_conn->insert('stmt_test', array('id' => 1)); - $this->_conn->insert('stmt_test', array('id' => 2)); + $this->_conn->insert('stmt_test', ['id' => 1]); + $this->_conn->insert('stmt_test', ['id' => 2]); $stmt = $this->_conn->prepare('SELECT id FROM stmt_test WHERE id = ?'); @@ -190,8 +189,8 @@ public function testReuseStatementWithReboundValue() public function testReuseStatementWithReboundParam() { - $this->_conn->insert('stmt_test', array('id' => 1)); - $this->_conn->insert('stmt_test', array('id' => 2)); + $this->_conn->insert('stmt_test', ['id' => 1]); + $this->_conn->insert('stmt_test', ['id' => 2]); $stmt = $this->_conn->prepare('SELECT id FROM stmt_test WHERE id = ?'); @@ -252,7 +251,7 @@ public function testFetchFromNonExecutedStatementWithClosedCursor(callable $fetc */ public function testFetchFromExecutedStatementWithClosedCursor(callable $fetch, $expected) { - $this->_conn->insert('stmt_test', array('id' => 1)); + $this->_conn->insert('stmt_test', ['id' => 1]); $stmt = $this->_conn->prepare('SELECT id FROM stmt_test'); $stmt->execute(); @@ -263,26 +262,26 @@ public function testFetchFromExecutedStatementWithClosedCursor(callable $fetch, public static function emptyFetchProvider() { - return array( - 'fetch' => array( - function (Statement $stmt) { + return [ + 'fetch' => [ + static function (Statement $stmt) { return $stmt->fetch(); }, false, - ), - 'fetch-column' => array( - function (Statement $stmt) { + ], + 'fetch-column' => [ + static function (Statement $stmt) { return $stmt->fetchColumn(); }, false, - ), - 'fetch-all' => array( - function (Statement $stmt) { + ], + 'fetch-all' => [ + static function (Statement $stmt) { return $stmt->fetchAll(); }, - array(), - ), - ); + [], + ], + ]; } public function testFetchInColumnMode() : void diff --git a/tests/Doctrine/Tests/DBAL/Functional/TableGeneratorTest.php b/tests/Doctrine/Tests/DBAL/Functional/TableGeneratorTest.php index b8c63644a85..182a337f295 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/TableGeneratorTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/TableGeneratorTest.php @@ -3,15 +3,17 @@ namespace Doctrine\Tests\DBAL\Functional; use Doctrine\DBAL\Id\TableGenerator; +use Doctrine\DBAL\Id\TableGeneratorSchemaVisitor; +use Doctrine\DBAL\Schema\Schema; +use Doctrine\Tests\DbalFunctionalTestCase; +use Throwable; /** * @group DDC-450 */ -class TableGeneratorTest extends \Doctrine\Tests\DbalFunctionalTestCase +class TableGeneratorTest extends DbalFunctionalTestCase { - /** - * @var TableGenerator - */ + /** @var TableGenerator */ private $generator; protected function setUp() @@ -19,43 +21,42 @@ protected function setUp() parent::setUp(); $platform = $this->_conn->getDatabasePlatform(); - if ($platform->getName() == "sqlite") { + if ($platform->getName() === 'sqlite') { $this->markTestSkipped('TableGenerator does not work with SQLite'); } try { - $schema = new \Doctrine\DBAL\Schema\Schema(); - $visitor = new \Doctrine\DBAL\Id\TableGeneratorSchemaVisitor(); + $schema = new Schema(); + $visitor = new TableGeneratorSchemaVisitor(); $schema->visit($visitor); foreach ($schema->toSql($platform) as $sql) { $this->_conn->exec($sql); } - - } catch(\Exception $e) { + } catch (Throwable $e) { } $this->generator = new TableGenerator($this->_conn); } public function testNextVal() { - $id1 = $this->generator->nextValue("tbl1"); - $id2 = $this->generator->nextValue("tbl1"); - $id3 = $this->generator->nextValue("tbl2"); + $id1 = $this->generator->nextValue('tbl1'); + $id2 = $this->generator->nextValue('tbl1'); + $id3 = $this->generator->nextValue('tbl2'); - self::assertGreaterThan(0, $id1, "First id has to be larger than 0"); - self::assertEquals($id1 + 1, $id2, "Second id is one larger than first one."); - self::assertEquals($id1, $id3, "First ids from different tables are equal."); + self::assertGreaterThan(0, $id1, 'First id has to be larger than 0'); + self::assertEquals($id1 + 1, $id2, 'Second id is one larger than first one.'); + self::assertEquals($id1, $id3, 'First ids from different tables are equal.'); } public function testNextValNotAffectedByOuterTransactions() { $this->_conn->beginTransaction(); - $id1 = $this->generator->nextValue("tbl1"); + $id1 = $this->generator->nextValue('tbl1'); $this->_conn->rollBack(); - $id2 = $this->generator->nextValue("tbl1"); + $id2 = $this->generator->nextValue('tbl1'); - self::assertGreaterThan(0, $id1, "First id has to be larger than 0"); - self::assertEquals($id1 + 1, $id2, "Second id is one larger than first one."); + self::assertGreaterThan(0, $id1, 'First id has to be larger than 0'); + self::assertEquals($id1 + 1, $id2, 'Second id is one larger than first one.'); } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/TemporaryTableTest.php b/tests/Doctrine/Tests/DBAL/Functional/TemporaryTableTest.php index 3a1277267a9..5ef755ee4da 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/TemporaryTableTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/TemporaryTableTest.php @@ -4,16 +4,17 @@ use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Type; +use Doctrine\Tests\DbalFunctionalTestCase; +use Throwable; -class TemporaryTableTest extends \Doctrine\Tests\DbalFunctionalTestCase +class TemporaryTableTest extends DbalFunctionalTestCase { protected function setUp() { parent::setUp(); try { - $this->_conn->exec($this->_conn->getDatabasePlatform()->getDropTableSQL("nontemporary")); - } catch(\Exception $e) { - + $this->_conn->exec($this->_conn->getDatabasePlatform()->getDropTableSQL('nontemporary')); + } catch (Throwable $e) { } } @@ -21,89 +22,91 @@ protected function tearDown() { if ($this->_conn) { try { - $tempTable = $this->_conn->getDatabasePlatform()->getTemporaryTableName("my_temporary"); + $tempTable = $this->_conn->getDatabasePlatform()->getTemporaryTableName('my_temporary'); $this->_conn->exec($this->_conn->getDatabasePlatform()->getDropTemporaryTableSQL($tempTable)); - } catch(\Exception $e) { } + } catch (Throwable $e) { + } } parent::tearDown(); } /** - * @group DDC-1337 * @return void + * + * @group DDC-1337 */ public function testDropTemporaryTableNotAutoCommitTransaction() { - if ($this->_conn->getDatabasePlatform()->getName() == 'sqlanywhere' || - $this->_conn->getDatabasePlatform()->getName() == 'oracle') { - $this->markTestSkipped("Test does not work on Oracle and SQL Anywhere."); + if ($this->_conn->getDatabasePlatform()->getName() === 'sqlanywhere' || + $this->_conn->getDatabasePlatform()->getName() === 'oracle') { + $this->markTestSkipped('Test does not work on Oracle and SQL Anywhere.'); } - $platform = $this->_conn->getDatabasePlatform(); - $columnDefinitions = array("id" => array("type" => Type::getType("integer"), "notnull" => true)); - $tempTable = $platform->getTemporaryTableName("my_temporary"); + $platform = $this->_conn->getDatabasePlatform(); + $columnDefinitions = ['id' => ['type' => Type::getType('integer'), 'notnull' => true]]; + $tempTable = $platform->getTemporaryTableName('my_temporary'); $createTempTableSQL = $platform->getCreateTemporaryTableSnippetSQL() . ' ' . $tempTable . ' (' . $platform->getColumnDeclarationListSQL($columnDefinitions) . ')'; $this->_conn->executeUpdate($createTempTableSQL); - $table = new Table("nontemporary"); - $table->addColumn("id", "integer"); - $table->setPrimaryKey(array('id')); + $table = new Table('nontemporary'); + $table->addColumn('id', 'integer'); + $table->setPrimaryKey(['id']); $this->_conn->getSchemaManager()->createTable($table); $this->_conn->beginTransaction(); - $this->_conn->insert("nontemporary", array("id" => 1)); + $this->_conn->insert('nontemporary', ['id' => 1]); $this->_conn->exec($platform->getDropTemporaryTableSQL($tempTable)); - $this->_conn->insert("nontemporary", array("id" => 2)); + $this->_conn->insert('nontemporary', ['id' => 2]); $this->_conn->rollBack(); $rows = $this->_conn->fetchAll('SELECT * FROM nontemporary'); - self::assertEquals(array(), $rows, "In an event of an error this result has one row, because of an implicit commit."); + self::assertEquals([], $rows, 'In an event of an error this result has one row, because of an implicit commit.'); } /** - * @group DDC-1337 * @return void + * + * @group DDC-1337 */ public function testCreateTemporaryTableNotAutoCommitTransaction() { - if ($this->_conn->getDatabasePlatform()->getName() == 'sqlanywhere' || - $this->_conn->getDatabasePlatform()->getName() == 'oracle') { - $this->markTestSkipped("Test does not work on Oracle and SQL Anywhere."); + if ($this->_conn->getDatabasePlatform()->getName() === 'sqlanywhere' || + $this->_conn->getDatabasePlatform()->getName() === 'oracle') { + $this->markTestSkipped('Test does not work on Oracle and SQL Anywhere.'); } - $platform = $this->_conn->getDatabasePlatform(); - $columnDefinitions = array("id" => array("type" => Type::getType("integer"), "notnull" => true)); - $tempTable = $platform->getTemporaryTableName("my_temporary"); + $platform = $this->_conn->getDatabasePlatform(); + $columnDefinitions = ['id' => ['type' => Type::getType('integer'), 'notnull' => true]]; + $tempTable = $platform->getTemporaryTableName('my_temporary'); $createTempTableSQL = $platform->getCreateTemporaryTableSnippetSQL() . ' ' . $tempTable . ' (' . $platform->getColumnDeclarationListSQL($columnDefinitions) . ')'; - $table = new Table("nontemporary"); - $table->addColumn("id", "integer"); - $table->setPrimaryKey(array('id')); + $table = new Table('nontemporary'); + $table->addColumn('id', 'integer'); + $table->setPrimaryKey(['id']); $this->_conn->getSchemaManager()->createTable($table); $this->_conn->beginTransaction(); - $this->_conn->insert("nontemporary", array("id" => 1)); + $this->_conn->insert('nontemporary', ['id' => 1]); $this->_conn->exec($createTempTableSQL); - $this->_conn->insert("nontemporary", array("id" => 2)); + $this->_conn->insert('nontemporary', ['id' => 2]); $this->_conn->rollBack(); try { $this->_conn->exec($platform->getDropTemporaryTableSQL($tempTable)); - } catch(\Exception $e) { - + } catch (Throwable $e) { } $rows = $this->_conn->fetchAll('SELECT * FROM nontemporary'); - self::assertEquals(array(), $rows, "In an event of an error this result has one row, because of an implicit commit."); + self::assertEquals([], $rows, 'In an event of an error this result has one row, because of an implicit commit.'); } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL168Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL168Test.php index 47b1e5eab4a..b43da19b52d 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL168Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL168Test.php @@ -2,22 +2,25 @@ namespace Doctrine\Tests\DBAL\Functional\Ticket; +use Doctrine\DBAL\Schema\Table; +use Doctrine\Tests\DbalFunctionalTestCase; + /** * @group DBAL-168 */ -class DBAL168Test extends \Doctrine\Tests\DbalFunctionalTestCase +class DBAL168Test extends DbalFunctionalTestCase { public function testDomainsTable() { - if ($this->_conn->getDatabasePlatform()->getName() != "postgresql") { + if ($this->_conn->getDatabasePlatform()->getName() !== 'postgresql') { $this->markTestSkipped('PostgreSQL only test'); } - $table = new \Doctrine\DBAL\Schema\Table("domains"); + $table = new Table('domains'); $table->addColumn('id', 'integer'); $table->addColumn('parent_id', 'integer'); - $table->setPrimaryKey(array('id')); - $table->addForeignKeyConstraint('domains', array('parent_id'), array('id')); + $table->setPrimaryKey(['id']); + $table->addForeignKeyConstraint('domains', ['parent_id'], ['id']); $this->_conn->getSchemaManager()->createTable($table); $table = $this->_conn->getSchemaManager()->listTableDetails('domains'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL202Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL202Test.php index cbb7674f893..63d93ffafa7 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL202Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL202Test.php @@ -2,25 +2,28 @@ namespace Doctrine\Tests\DBAL\Functional\Ticket; +use Doctrine\DBAL\Schema\Table; +use Doctrine\Tests\DbalFunctionalTestCase; + /** * @group DBAL-202 */ -class DBAL202Test extends \Doctrine\Tests\DbalFunctionalTestCase +class DBAL202Test extends DbalFunctionalTestCase { protected function setUp() { parent::setUp(); - if ($this->_conn->getDatabasePlatform()->getName() != 'oracle') { + if ($this->_conn->getDatabasePlatform()->getName() !== 'oracle') { $this->markTestSkipped('OCI8 only test'); } if ($this->_conn->getSchemaManager()->tablesExist('DBAL202')) { $this->_conn->exec('DELETE FROM DBAL202'); } else { - $table = new \Doctrine\DBAL\Schema\Table('DBAL202'); + $table = new Table('DBAL202'); $table->addColumn('id', 'integer'); - $table->setPrimaryKey(array('id')); + $table->setPrimaryKey(['id']); $this->_conn->getSchemaManager()->createTable($table); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php index 4db10e1173f..b44e7542489 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php @@ -1,29 +1,33 @@ _conn->getDatabasePlatform()->getName(); - if (!in_array($platform, array('mysql', 'sqlite'))) { - $this->markTestSkipped('Currently restricted to MySQL and SQLite.'); + if (in_array($platform, ['mysql', 'sqlite'])) { + return; } + + $this->markTestSkipped('Currently restricted to MySQL and SQLite.'); } public function testGuidShouldMatchPattern() { - $guid = $this->_conn->query($this->getSelectGuidSql())->fetchColumn(); + $guid = $this->_conn->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'; - self::assertEquals(1, preg_match($pattern, $guid), "GUID does not match pattern"); + self::assertEquals(1, preg_match($pattern, $guid), 'GUID does not match pattern'); } /** @@ -33,12 +37,12 @@ public function testGuidShouldMatchPattern() public function testGuidShouldBeRandom() { $statement = $this->_conn->prepare($this->getSelectGuidSql()); - $guids = array(); + $guids = []; for ($i = 0; $i < 99; $i++) { $statement->execute(); $guid = $statement->fetchColumn(); - self::assertNotContains($guid, $guids, "Duplicate GUID detected"); + self::assertNotContains($guid, $guids, 'Duplicate GUID detected'); $guids[] = $guid; } @@ -47,6 +51,6 @@ public function testGuidShouldBeRandom() private function getSelectGuidSql() { - return "SELECT " . $this->_conn->getDatabasePlatform()->getGuidExpression(); + return 'SELECT ' . $this->_conn->getDatabasePlatform()->getGuidExpression(); } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL461Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL461Test.php index 1f40837daa7..2298898d74d 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL461Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL461Test.php @@ -4,23 +4,25 @@ use Doctrine\DBAL\Schema\SQLServerSchemaManager; use Doctrine\DBAL\Types\DecimalType; +use PHPUnit\Framework\TestCase; +use ReflectionMethod; /** * @group DBAL-461 */ -class DBAL461Test extends \PHPUnit\Framework\TestCase +class DBAL461Test extends TestCase { public function testIssue() { - $conn = $this->createMock('Doctrine\DBAL\Connection'); + $conn = $this->createMock('Doctrine\DBAL\Connection'); $platform = $this->getMockForAbstractClass('Doctrine\DBAL\Platforms\AbstractPlatform'); $platform->registerDoctrineTypeMapping('numeric', 'decimal'); $schemaManager = new SQLServerSchemaManager($conn, $platform); - $reflectionMethod = new \ReflectionMethod($schemaManager, '_getPortableTableColumnDefinition'); + $reflectionMethod = new ReflectionMethod($schemaManager, '_getPortableTableColumnDefinition'); $reflectionMethod->setAccessible(true); - $column = $reflectionMethod->invoke($schemaManager, array( + $column = $reflectionMethod->invoke($schemaManager, [ 'type' => 'numeric(18,0)', 'length' => null, 'default' => null, @@ -30,7 +32,7 @@ public function testIssue() 'autoincrement' => false, 'collation' => 'foo', 'comment' => null, - )); + ]); $this->assertInstanceOf(DecimalType::class, $column->getType()); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL510Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL510Test.php index 4780e6f5c7d..208db06d19b 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL510Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL510Test.php @@ -4,33 +4,36 @@ use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\Table; +use Doctrine\Tests\DbalFunctionalTestCase; /** * @group DBAL-510 */ -class DBAL510Test extends \Doctrine\Tests\DbalFunctionalTestCase +class DBAL510Test extends DbalFunctionalTestCase { protected function setUp() { parent::setUp(); - if ($this->_conn->getDatabasePlatform()->getName() !== "postgresql") { - $this->markTestSkipped('PostgreSQL Only test'); + if ($this->_conn->getDatabasePlatform()->getName() === 'postgresql') { + return; } + + $this->markTestSkipped('PostgreSQL Only test'); } public function testSearchPathSchemaChanges() { - $table = new Table("dbal510tbl"); + $table = new Table('dbal510tbl'); $table->addColumn('id', 'integer'); - $table->setPrimaryKey(array('id')); + $table->setPrimaryKey(['id']); $this->_conn->getSchemaManager()->createTable($table); $onlineTable = $this->_conn->getSchemaManager()->listTableDetails('dbal510tbl'); $comparator = new Comparator(); - $diff = $comparator->diffTable($onlineTable, $table); + $diff = $comparator->diffTable($onlineTable, $table); self::assertFalse($diff); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php index 70210133b1f..0709ffd5632 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php @@ -4,17 +4,16 @@ use Doctrine\DBAL\DBALException; use Doctrine\DBAL\ParameterType; +use Doctrine\Tests\DbalFunctionalTestCase; use PDO; use function in_array; /** * @group DBAL-630 */ -class DBAL630Test extends \Doctrine\Tests\DbalFunctionalTestCase +class DBAL630Test extends DbalFunctionalTestCase { - /** - * @var bool - */ + /** @var bool */ private $running = false; protected function setUp() @@ -23,7 +22,7 @@ protected function setUp() $platform = $this->_conn->getDatabasePlatform()->getName(); - if (!in_array($platform, array('postgresql'))) { + if (! in_array($platform, ['postgresql'])) { $this->markTestSkipped('Currently restricted to PostgreSQL'); } @@ -50,7 +49,7 @@ public function testBooleanConversionSqlLiteral() $id = $this->_conn->lastInsertId('dbal630_id_seq'); self::assertNotEmpty($id); - $row = $this->_conn->fetchAssoc('SELECT bool_col FROM dbal630 WHERE id = ?', array($id)); + $row = $this->_conn->fetchAssoc('SELECT bool_col FROM dbal630 WHERE id = ?', [$id]); self::assertFalse($row['bool_col']); } @@ -65,7 +64,7 @@ public function testBooleanConversionBoolParamRealPrepares() $id = $this->_conn->lastInsertId('dbal630_id_seq'); self::assertNotEmpty($id); - $row = $this->_conn->fetchAssoc('SELECT bool_col FROM dbal630 WHERE id = ?', array($id)); + $row = $this->_conn->fetchAssoc('SELECT bool_col FROM dbal630 WHERE id = ?', [$id]); self::assertFalse($row['bool_col']); } @@ -84,7 +83,7 @@ public function testBooleanConversionBoolParamEmulatedPrepares() self::assertNotEmpty($id); - $row = $this->_conn->fetchAssoc('SELECT bool_col FROM dbal630 WHERE id = ?', array($id)); + $row = $this->_conn->fetchAssoc('SELECT bool_col FROM dbal630 WHERE id = ?', [$id]); self::assertFalse($row['bool_col']); } @@ -108,7 +107,7 @@ public function testBooleanConversionNullParamEmulatedPrepares( self::assertNotEmpty($id); - $row = $this->_conn->fetchAssoc('SELECT bool_col FROM dbal630_allow_nulls WHERE id = ?', array($id)); + $row = $this->_conn->fetchAssoc('SELECT bool_col FROM dbal630_allow_nulls WHERE id = ?', [$id]); self::assertSame($databaseConvertedValue, $row['bool_col']); } @@ -136,36 +135,38 @@ public function testBooleanConversionNullParamEmulatedPreparesWithBooleanTypeInB self::assertNotEmpty($id); - $row = $this->_conn->fetchAssoc('SELECT bool_col FROM dbal630_allow_nulls WHERE id = ?', array($id)); + $row = $this->_conn->fetchAssoc('SELECT bool_col FROM dbal630_allow_nulls WHERE id = ?', [$id]); self::assertSame($databaseConvertedValue, $row['bool_col']); } /** * Boolean conversion mapping provider + * * @return array */ public function booleanTypeConversionUsingBooleanTypeProvider() { - return array( + return [ // statement value, database converted value result - array(true, true), - array(false, false), - array(null, false) - ); + [true, true], + [false, false], + [null, false], + ]; } /** * Boolean conversion mapping provider + * * @return array */ public function booleanTypeConversionWithoutPdoTypeProvider() { - return array( + return [ // statement value, database converted value result - array(true, true), - array(false, false), - array(null, null) - ); + [true, true], + [false, false], + [null, null], + ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL752Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL752Test.php index 5368cdc9192..393e3457eed 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL752Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL752Test.php @@ -1,12 +1,14 @@ _conn->getDatabasePlatform()->getName(); - if (!in_array($platform, array('sqlite'))) { - $this->markTestSkipped('Related to SQLite only'); + if (in_array($platform, ['sqlite'])) { + return; } + + $this->markTestSkipped('Related to SQLite only'); } public function testUnsignedIntegerDetection() diff --git a/tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php b/tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php index 83c6e4dec55..289d5c7fd9a 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php @@ -2,102 +2,110 @@ namespace Doctrine\Tests\DBAL\Functional; +use DateTime; +use Doctrine\DBAL\Schema\AbstractSchemaManager; +use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Type; +use Doctrine\Tests\DbalFunctionalTestCase; +use stdClass; +use Throwable; use function str_repeat; -class TypeConversionTest extends \Doctrine\Tests\DbalFunctionalTestCase +class TypeConversionTest extends DbalFunctionalTestCase { - /** - * @var int - */ + /** @var int */ static private $typeCounter = 0; protected function setUp() { parent::setUp(); - /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ + /** @var AbstractSchemaManager $sm */ $sm = $this->_conn->getSchemaManager(); - $table = new \Doctrine\DBAL\Schema\Table("type_conversion"); - $table->addColumn('id', 'integer', array('notnull' => false)); - $table->addColumn('test_string', 'string', array('notnull' => false)); - $table->addColumn('test_boolean', 'boolean', array('notnull' => false)); - $table->addColumn('test_bigint', 'bigint', array('notnull' => false)); - $table->addColumn('test_smallint', 'bigint', array('notnull' => false)); - $table->addColumn('test_datetime', 'datetime', array('notnull' => false)); - $table->addColumn('test_datetimetz', 'datetimetz', array('notnull' => false)); - $table->addColumn('test_date', 'date', array('notnull' => false)); - $table->addColumn('test_time', 'time', array('notnull' => false)); - $table->addColumn('test_text', 'text', array('notnull' => false)); - $table->addColumn('test_array', 'array', array('notnull' => false)); - $table->addColumn('test_json_array', 'json_array', array('notnull' => false)); - $table->addColumn('test_object', 'object', array('notnull' => false)); - $table->addColumn('test_float', 'float', array('notnull' => false)); - $table->addColumn('test_decimal', 'decimal', array('notnull' => false, 'scale' => 2, 'precision' => 10)); - $table->setPrimaryKey(array('id')); + $table = new Table('type_conversion'); + $table->addColumn('id', 'integer', ['notnull' => false]); + $table->addColumn('test_string', 'string', ['notnull' => false]); + $table->addColumn('test_boolean', 'boolean', ['notnull' => false]); + $table->addColumn('test_bigint', 'bigint', ['notnull' => false]); + $table->addColumn('test_smallint', 'bigint', ['notnull' => false]); + $table->addColumn('test_datetime', 'datetime', ['notnull' => false]); + $table->addColumn('test_datetimetz', 'datetimetz', ['notnull' => false]); + $table->addColumn('test_date', 'date', ['notnull' => false]); + $table->addColumn('test_time', 'time', ['notnull' => false]); + $table->addColumn('test_text', 'text', ['notnull' => false]); + $table->addColumn('test_array', 'array', ['notnull' => false]); + $table->addColumn('test_json_array', 'json_array', ['notnull' => false]); + $table->addColumn('test_object', 'object', ['notnull' => false]); + $table->addColumn('test_float', 'float', ['notnull' => false]); + $table->addColumn('test_decimal', 'decimal', ['notnull' => false, 'scale' => 2, 'precision' => 10]); + $table->setPrimaryKey(['id']); try { $this->_conn->getSchemaManager()->createTable($table); - } catch(\Exception $e) { - + } catch (Throwable $e) { } } public static function dataIdempotentDataConversion() { - $obj = new \stdClass(); - $obj->foo = "bar"; - $obj->bar = "baz"; - - return array( - array('string', 'ABCDEFGaaaBBB', 'string'), - array('boolean', true, 'bool'), - array('boolean', false, 'bool'), - array('bigint', 12345678, 'string'), - array('smallint', 123, 'int'), - array('datetime', new \DateTime('2010-04-05 10:10:10'), 'DateTime'), - array('datetimetz', new \DateTime('2010-04-05 10:10:10'), 'DateTime'), - array('date', new \DateTime('2010-04-05'), 'DateTime'), - array('time', new \DateTime('1970-01-01 10:10:10'), 'DateTime'), - array('text', str_repeat('foo ', 1000), 'string'), - array('array', array('foo' => 'bar'), 'array'), - array('json_array', array('foo' => 'bar'), 'array'), - array('object', $obj, 'object'), - array('float', 1.5, 'float'), - array('decimal', 1.55, 'string'), - ); + $obj = new stdClass(); + $obj->foo = 'bar'; + $obj->bar = 'baz'; + + 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'], + ]; } /** - * @dataProvider dataIdempotentDataConversion * @param string $type * @param mixed $originalValue * @param string $expectedPhpType + * + * @dataProvider dataIdempotentDataConversion */ public function testIdempotentDataConversion($type, $originalValue, $expectedPhpType) { - $columnName = "test_" . $type; - $typeInstance = Type::getType($type); + $columnName = 'test_' . $type; + $typeInstance = Type::getType($type); $insertionValue = $typeInstance->convertToDatabaseValue($originalValue, $this->_conn->getDatabasePlatform()); - $this->_conn->insert('type_conversion', array('id' => ++self::$typeCounter, $columnName => $insertionValue)); + $this->_conn->insert('type_conversion', ['id' => ++self::$typeCounter, $columnName => $insertionValue]); - $sql = "SELECT " . $columnName . " FROM type_conversion WHERE id = " . self::$typeCounter; + $sql = 'SELECT ' . $columnName . ' FROM type_conversion WHERE id = ' . self::$typeCounter; $actualDbValue = $typeInstance->convertToPHPValue($this->_conn->fetchColumn($sql), $this->_conn->getDatabasePlatform()); - if ($originalValue instanceof \DateTime) { - self::assertInstanceOf($expectedPhpType, $actualDbValue, "The expected type from the conversion to and back from the database should be " . $expectedPhpType); + 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); + self::assertInternalType($expectedPhpType, $actualDbValue, 'The expected type from the conversion to and back from the database should be ' . $expectedPhpType); + } + + if ($type === 'datetimetz') { + return; } - if ($type !== "datetimetz") { - self::assertEquals($originalValue, $actualDbValue, "Conversion between values should produce the same out as in value, but doesnt!"); + self::assertEquals($originalValue, $actualDbValue, 'Conversion between values should produce the same out as in value, but doesnt!'); - if ($originalValue instanceof \DateTime) { - self::assertEquals($originalValue->getTimezone()->getName(), $actualDbValue->getTimezone()->getName(), "Timezones should be the same."); - } + if (! ($originalValue instanceof DateTime)) { + return; } + + self::assertEquals($originalValue->getTimezone()->getName(), $actualDbValue->getTimezone()->getName(), 'Timezones should be the same.'); } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php b/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php index 8ce8e373e83..60c32fe9615 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php @@ -2,28 +2,33 @@ namespace Doctrine\Tests\DBAL\Functional; +use DateTime; use Doctrine\DBAL\ParameterType; +use Doctrine\DBAL\Schema\AbstractSchemaManager; +use Doctrine\DBAL\Schema\Sequence; +use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Type; +use Doctrine\Tests\DbalFunctionalTestCase; +use Throwable; use function array_filter; use function strtolower; -class WriteTest extends \Doctrine\Tests\DbalFunctionalTestCase +class WriteTest extends DbalFunctionalTestCase { protected function setUp() { parent::setUp(); try { - /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ - $table = new \Doctrine\DBAL\Schema\Table("write_table"); - $table->addColumn('id', 'integer', array('autoincrement' => true)); + /** @var AbstractSchemaManager $sm */ + $table = new Table('write_table'); + $table->addColumn('id', 'integer', ['autoincrement' => true]); $table->addColumn('test_int', 'integer'); - $table->addColumn('test_string', 'string', array('notnull' => false)); - $table->setPrimaryKey(array('id')); + $table->addColumn('test_string', 'string', ['notnull' => false]); + $table->setPrimaryKey(['id']); $this->_conn->getSchemaManager()->createTable($table); - } catch(\Exception $e) { - + } catch (Throwable $e) { } $this->_conn->executeUpdate('DELETE FROM write_table'); } @@ -33,40 +38,40 @@ protected function setUp() */ public function testExecuteUpdateFirstTypeIsNull() { - $sql = "INSERT INTO write_table (test_string, test_int) VALUES (?, ?)"; + $sql = 'INSERT INTO write_table (test_string, test_int) VALUES (?, ?)'; $this->_conn->executeUpdate($sql, ['text', 1111], [null, ParameterType::INTEGER]); - $sql = "SELECT * FROM write_table WHERE test_string = ? AND test_int = ?"; + $sql = 'SELECT * FROM write_table WHERE test_string = ? AND test_int = ?'; self::assertTrue((bool) $this->_conn->fetchColumn($sql, ['text', 1111])); } public function testExecuteUpdate() { - $sql = "INSERT INTO write_table (test_int) VALUES ( " . $this->_conn->quote(1) . ")"; + $sql = 'INSERT INTO write_table (test_int) VALUES ( ' . $this->_conn->quote(1) . ')'; $affected = $this->_conn->executeUpdate($sql); - self::assertEquals(1, $affected, "executeUpdate() should return the number of affected rows!"); + self::assertEquals(1, $affected, 'executeUpdate() should return the number of affected rows!'); } public function testExecuteUpdateWithTypes() { - $sql = "INSERT INTO write_table (test_int, test_string) VALUES (?, ?)"; + $sql = 'INSERT INTO write_table (test_int, test_string) VALUES (?, ?)'; $affected = $this->_conn->executeUpdate( $sql, [1, 'foo'], [ParameterType::INTEGER, ParameterType::STRING] ); - self::assertEquals(1, $affected, "executeUpdate() should return the number of affected rows!"); + self::assertEquals(1, $affected, 'executeUpdate() should return the number of affected rows!'); } public function testPrepareRowCountReturnsAffectedRows() { - $sql = "INSERT INTO write_table (test_int, test_string) VALUES (?, ?)"; + $sql = 'INSERT INTO write_table (test_int, test_string) VALUES (?, ?)'; $stmt = $this->_conn->prepare($sql); $stmt->bindValue(1, 1); - $stmt->bindValue(2, "foo"); + $stmt->bindValue(2, 'foo'); $stmt->execute(); self::assertEquals(1, $stmt->rowCount()); @@ -74,7 +79,7 @@ public function testPrepareRowCountReturnsAffectedRows() public function testPrepareWithPdoTypes() { - $sql = "INSERT INTO write_table (test_int, test_string) VALUES (?, ?)"; + $sql = 'INSERT INTO write_table (test_int, test_string) VALUES (?, ?)'; $stmt = $this->_conn->prepare($sql); $stmt->bindValue(1, 1, ParameterType::INTEGER); @@ -86,11 +91,11 @@ public function testPrepareWithPdoTypes() public function testPrepareWithDbalTypes() { - $sql = "INSERT INTO write_table (test_int, test_string) VALUES (?, ?)"; + $sql = 'INSERT INTO write_table (test_int, test_string) VALUES (?, ?)'; $stmt = $this->_conn->prepare($sql); $stmt->bindValue(1, 1, Type::getType('integer')); - $stmt->bindValue(2, "foo", Type::getType('string')); + $stmt->bindValue(2, 'foo', Type::getType('string')); $stmt->execute(); self::assertEquals(1, $stmt->rowCount()); @@ -98,11 +103,11 @@ public function testPrepareWithDbalTypes() public function testPrepareWithDbalTypeNames() { - $sql = "INSERT INTO write_table (test_int, test_string) VALUES (?, ?)"; + $sql = 'INSERT INTO write_table (test_int, test_string) VALUES (?, ?)'; $stmt = $this->_conn->prepare($sql); $stmt->bindValue(1, 1, 'integer'); - $stmt->bindValue(2, "foo", 'string'); + $stmt->bindValue(2, 'foo', 'string'); $stmt->execute(); self::assertEquals(1, $stmt->rowCount()); @@ -110,8 +115,8 @@ public function testPrepareWithDbalTypeNames() public function insertRows() { - self::assertEquals(1, $this->_conn->insert('write_table', array('test_int' => 1, 'test_string' => 'foo'))); - self::assertEquals(1, $this->_conn->insert('write_table', array('test_int' => 2, 'test_string' => 'bar'))); + self::assertEquals(1, $this->_conn->insert('write_table', ['test_int' => 1, 'test_string' => 'foo'])); + self::assertEquals(1, $this->_conn->insert('write_table', ['test_int' => 2, 'test_string' => 'bar'])); } public function testInsert() @@ -123,10 +128,10 @@ public function testDelete() { $this->insertRows(); - self::assertEquals(1, $this->_conn->delete('write_table', array('test_int' => 2))); + self::assertEquals(1, $this->_conn->delete('write_table', ['test_int' => 2])); self::assertCount(1, $this->_conn->fetchAll('SELECT * FROM write_table')); - self::assertEquals(1, $this->_conn->delete('write_table', array('test_int' => 1))); + self::assertEquals(1, $this->_conn->delete('write_table', ['test_int' => 1])); self::assertCount(0, $this->_conn->fetchAll('SELECT * FROM write_table')); } @@ -134,42 +139,42 @@ public function testUpdate() { $this->insertRows(); - self::assertEquals(1, $this->_conn->update('write_table', array('test_string' => 'bar'), array('test_string' => 'foo'))); - self::assertEquals(2, $this->_conn->update('write_table', array('test_string' => 'baz'), array('test_string' => 'bar'))); - self::assertEquals(0, $this->_conn->update('write_table', array('test_string' => 'baz'), array('test_string' => 'bar'))); + self::assertEquals(1, $this->_conn->update('write_table', ['test_string' => 'bar'], ['test_string' => 'foo'])); + self::assertEquals(2, $this->_conn->update('write_table', ['test_string' => 'baz'], ['test_string' => 'bar'])); + self::assertEquals(0, $this->_conn->update('write_table', ['test_string' => 'baz'], ['test_string' => 'bar'])); } public function testLastInsertId() { - if ( ! $this->_conn->getDatabasePlatform()->prefersIdentityColumns()) { + if (! $this->_conn->getDatabasePlatform()->prefersIdentityColumns()) { $this->markTestSkipped('Test only works on platforms with identity columns.'); } - self::assertEquals(1, $this->_conn->insert('write_table', array('test_int' => 2, 'test_string' => 'bar'))); + self::assertEquals(1, $this->_conn->insert('write_table', ['test_int' => 2, 'test_string' => 'bar'])); $num = $this->_conn->lastInsertId(); - self::assertNotNull($num, "LastInsertId() should not be null."); - self::assertGreaterThan(0, $num, "LastInsertId() should be non-negative number."); + self::assertNotNull($num, 'LastInsertId() should not be null.'); + self::assertGreaterThan(0, $num, 'LastInsertId() should be non-negative number.'); } public function testLastInsertIdSequence() { - if ( ! $this->_conn->getDatabasePlatform()->supportsSequences()) { + if (! $this->_conn->getDatabasePlatform()->supportsSequences()) { $this->markTestSkipped('Test only works on platforms with sequences.'); } - $sequence = new \Doctrine\DBAL\Schema\Sequence('write_table_id_seq'); + $sequence = new Sequence('write_table_id_seq'); try { $this->_conn->getSchemaManager()->createSequence($sequence); - } catch(\Exception $e) { + } catch (Throwable $e) { } $sequences = $this->_conn->getSchemaManager()->listSequences(); - self::assertCount(1, array_filter($sequences, function($sequence) { + self::assertCount(1, array_filter($sequences, static function ($sequence) { return strtolower($sequence->getName()) === 'write_table_id_seq'; })); - $stmt = $this->_conn->query($this->_conn->getDatabasePlatform()->getSequenceNextValSQL('write_table_id_seq')); + $stmt = $this->_conn->query($this->_conn->getDatabasePlatform()->getSequenceNextValSQL('write_table_id_seq')); $nextSequenceVal = $stmt->fetchColumn(); $lastInsertId = $this->_conn->lastInsertId('write_table_id_seq'); @@ -180,12 +185,11 @@ public function testLastInsertIdSequence() public function testLastInsertIdNoSequenceGiven() { - if ( ! $this->_conn->getDatabasePlatform()->supportsSequences() || $this->_conn->getDatabasePlatform()->supportsIdentityColumns()) { + if (! $this->_conn->getDatabasePlatform()->supportsSequences() || $this->_conn->getDatabasePlatform()->supportsIdentityColumns()) { $this->markTestSkipped("Test only works consistently on platforms that support sequences and don't support identity columns."); } - self::assertFalse($this->_conn->lastInsertId( null )); - + self::assertFalse($this->_conn->lastInsertId(null)); } /** @@ -193,12 +197,12 @@ public function testLastInsertIdNoSequenceGiven() */ public function testInsertWithKeyValueTypes() { - $testString = new \DateTime('2013-04-14 10:10:10'); + $testString = new DateTime('2013-04-14 10:10:10'); $this->_conn->insert( 'write_table', - array('test_int' => '30', 'test_string' => $testString), - array('test_string' => 'datetime', 'test_int' => 'integer') + ['test_int' => '30', 'test_string' => $testString], + ['test_string' => 'datetime', 'test_int' => 'integer'] ); $data = $this->_conn->fetchColumn('SELECT test_string FROM write_table WHERE test_int = 30'); @@ -211,21 +215,21 @@ public function testInsertWithKeyValueTypes() */ public function testUpdateWithKeyValueTypes() { - $testString = new \DateTime('2013-04-14 10:10:10'); + $testString = new DateTime('2013-04-14 10:10:10'); $this->_conn->insert( 'write_table', - array('test_int' => '30', 'test_string' => $testString), - array('test_string' => 'datetime', 'test_int' => 'integer') + ['test_int' => '30', 'test_string' => $testString], + ['test_string' => 'datetime', 'test_int' => 'integer'] ); - $testString = new \DateTime('2013-04-15 10:10:10'); + $testString = new DateTime('2013-04-15 10:10:10'); $this->_conn->update( 'write_table', - array('test_string' => $testString), - array('test_int' => '30'), - array('test_string' => 'datetime', 'test_int' => 'integer') + ['test_string' => $testString], + ['test_int' => '30'], + ['test_string' => 'datetime', 'test_int' => 'integer'] ); $data = $this->_conn->fetchColumn('SELECT test_string FROM write_table WHERE test_int = 30'); @@ -238,14 +242,14 @@ public function testUpdateWithKeyValueTypes() */ public function testDeleteWithKeyValueTypes() { - $val = new \DateTime('2013-04-14 10:10:10'); + $val = new DateTime('2013-04-14 10:10:10'); $this->_conn->insert( 'write_table', - array('test_int' => '30', 'test_string' => $val), - array('test_string' => 'datetime', 'test_int' => 'integer') + ['test_int' => '30', 'test_string' => $val], + ['test_string' => 'datetime', 'test_int' => 'integer'] ); - $this->_conn->delete('write_table', array('test_int' => 30, 'test_string' => $val), array('test_string' => 'datetime', 'test_int' => 'integer')); + $this->_conn->delete('write_table', ['test_int' => 30, 'test_string' => $val], ['test_string' => 'datetime', 'test_int' => 'integer']); $data = $this->_conn->fetchColumn('SELECT test_string FROM write_table WHERE test_int = 30'); @@ -256,19 +260,20 @@ public function testEmptyIdentityInsert() { $platform = $this->_conn->getDatabasePlatform(); - if ( ! ($platform->supportsIdentityColumns() || $platform->usesSequenceEmulatedIdentityColumns()) ) { + if (! ($platform->supportsIdentityColumns() || $platform->usesSequenceEmulatedIdentityColumns())) { $this->markTestSkipped( 'Test only works on platforms with identity columns or sequence emulated identity columns.' ); } - $table = new \Doctrine\DBAL\Schema\Table('test_empty_identity'); - $table->addColumn('id', 'integer', array('autoincrement' => true)); - $table->setPrimaryKey(array('id')); + $table = new Table('test_empty_identity'); + $table->addColumn('id', 'integer', ['autoincrement' => true]); + $table->setPrimaryKey(['id']); try { $this->_conn->getSchemaManager()->dropTable($table->getQuotedName($platform)); - } catch(\Exception $e) { } + } catch (Throwable $e) { + } foreach ($platform->getCreateTableSQL($table) as $sql) { $this->_conn->exec($sql); @@ -289,7 +294,6 @@ public function testEmptyIdentityInsert() $secondId = $this->_conn->lastInsertId($seqName); self::assertGreaterThan($firstId, $secondId); - } /** diff --git a/tests/Doctrine/Tests/DBAL/Logging/DebugStackTest.php b/tests/Doctrine/Tests/DBAL/Logging/DebugStackTest.php index 8d9595f1ec5..914351c75dc 100644 --- a/tests/Doctrine/Tests/DBAL/Logging/DebugStackTest.php +++ b/tests/Doctrine/Tests/DBAL/Logging/DebugStackTest.php @@ -3,8 +3,9 @@ namespace Doctrine\Tests\DBAL\Logging; use Doctrine\DBAL\Logging\DebugStack; +use Doctrine\Tests\DbalTestCase; -class DebugStackTest extends \Doctrine\Tests\DbalTestCase +class DebugStackTest extends DbalTestCase { /** @var DebugStack */ private $logger; @@ -23,14 +24,14 @@ public function testLoggedQuery() { $this->logger->startQuery('SELECT column FROM table'); self::assertEquals( - array( - 1 => array( + [ + 1 => [ 'sql' => 'SELECT column FROM table', 'params' => null, 'types' => null, 'executionMS' => 0, - ), - ), + ], + ], $this->logger->queries ); @@ -42,9 +43,9 @@ public function testLoggedQueryDisabled() { $this->logger->enabled = false; $this->logger->startQuery('SELECT column FROM table'); - self::assertEquals(array(), $this->logger->queries); + self::assertEquals([], $this->logger->queries); $this->logger->stopQuery(); - self::assertEquals(array(), $this->logger->queries); + self::assertEquals([], $this->logger->queries); } } diff --git a/tests/Doctrine/Tests/DBAL/Mocks/MockPlatform.php b/tests/Doctrine/Tests/DBAL/Mocks/MockPlatform.php index 3f8f0477cc2..cb6ec18df32 100644 --- a/tests/Doctrine/Tests/DBAL/Mocks/MockPlatform.php +++ b/tests/Doctrine/Tests/DBAL/Mocks/MockPlatform.php @@ -15,18 +15,27 @@ public function getBlobTypeDeclarationSQL(array $field) throw DBALException::notSupported(__METHOD__); } - public function getBooleanTypeDeclarationSQL(array $columnDef) {} - public function getIntegerTypeDeclarationSQL(array $columnDef) {} - public function getBigIntTypeDeclarationSQL(array $columnDef) {} - public function getSmallIntTypeDeclarationSQL(array $columnDef) {} - public function _getCommonIntegerTypeDeclarationSQL(array $columnDef) {} + public function getBooleanTypeDeclarationSQL(array $columnDef) + { + } + public function getIntegerTypeDeclarationSQL(array $columnDef) + { + } + public function getBigIntTypeDeclarationSQL(array $columnDef) + { + } + public function getSmallIntTypeDeclarationSQL(array $columnDef) + { + } + public function _getCommonIntegerTypeDeclarationSQL(array $columnDef) + { + } public function getVarcharTypeDeclarationSQL(array $field) { - return "DUMMYVARCHAR()"; + return 'DUMMYVARCHAR()'; } - /** @override */ public function getClobTypeDeclarationSQL(array $field) { return 'DUMMYCLOB'; @@ -57,10 +66,10 @@ public function getName() { return 'mock'; } - protected function initializeDoctrineTypeMappings() { + protected function initializeDoctrineTypeMappings() + { } protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) { - } } diff --git a/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php b/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php index 42c549aa399..e60bace5dca 100644 --- a/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php +++ b/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php @@ -2,25 +2,27 @@ namespace Doctrine\Tests\DBAL\Performance; +use DateTime; +use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DbalPerformanceTestCase; /** * Class TypeConversionPerformanceTest - * @package Doctrine\Tests\DBAL\Performance - * @author Bill Schaller + * * @group performance */ class TypeConversionPerformanceTest extends DbalPerformanceTestCase { /** - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException + * * @dataProvider itemCountProvider */ public function testDateTimeTypeConversionPerformance($count) { - $value = new \DateTime; - $type = Type::getType("datetime"); + $value = new DateTime(); + $type = Type::getType('datetime'); $platform = $this->_conn->getDatabasePlatform(); $this->startTiming(); for ($i = 0; $i < $count; $i++) { diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php index b8fcfb35ede..3b81ef680c6 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php @@ -15,14 +15,14 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase { public function testModifyLimitQueryWitoutLimit() { - $sql = $this->_platform->modifyLimitQuery('SELECT n FROM Foo', null , 10); - self::assertEquals('SELECT n FROM Foo LIMIT 18446744073709551615 OFFSET 10',$sql); + $sql = $this->_platform->modifyLimitQuery('SELECT n FROM Foo', null, 10); + self::assertEquals('SELECT n FROM Foo LIMIT 18446744073709551615 OFFSET 10', $sql); } public function testGenerateMixedCaseTableCreate() { - $table = new Table("Foo"); - $table->addColumn("Bar", "integer"); + $table = new Table('Foo'); + $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)); @@ -35,16 +35,12 @@ public function getGenerateTableSql() public function getGenerateTableWithMultiColumnUniqueIndexSql() { - return array( - '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']; } public function getGenerateAlterTableSql() { - return array( - "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" - ); + 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() @@ -88,17 +84,18 @@ public function testGeneratesTypeDeclarationForIntegers() { self::assertEquals( 'INT', - $this->_platform->getIntegerTypeDeclarationSQL(array()) + $this->_platform->getIntegerTypeDeclarationSQL([]) ); self::assertEquals( 'INT AUTO_INCREMENT', - $this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true) - )); + $this->_platform->getIntegerTypeDeclarationSQL(['autoincrement' => true]) + ); self::assertEquals( 'INT AUTO_INCREMENT', $this->_platform->getIntegerTypeDeclarationSQL( - array('autoincrement' => true, 'primary' => true) - )); + ['autoincrement' => true, 'primary' => true] + ) + ); } public function testGeneratesTypeDeclarationForStrings() @@ -106,16 +103,17 @@ public function testGeneratesTypeDeclarationForStrings() self::assertEquals( 'CHAR(10)', $this->_platform->getVarcharTypeDeclarationSQL( - array('length' => 10, 'fixed' => true) - )); + ['length' => 10, 'fixed' => true] + ) + ); self::assertEquals( 'VARCHAR(50)', - $this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)), + $this->_platform->getVarcharTypeDeclarationSQL(['length' => 50]), 'Variable string declaration is not correct' ); self::assertEquals( 'VARCHAR(255)', - $this->_platform->getVarcharTypeDeclarationSQL(array()), + $this->_platform->getVarcharTypeDeclarationSQL([]), 'Long string declaration is not correct' ); } @@ -155,25 +153,25 @@ public function getGenerateForeignKeySql() */ public function testUniquePrimaryKey() { - $keyTable = new Table("foo"); - $keyTable->addColumn("bar", "integer"); - $keyTable->addColumn("baz", "string"); - $keyTable->setPrimaryKey(array("bar")); - $keyTable->addUniqueIndex(array("baz")); + $keyTable = new Table('foo'); + $keyTable->addColumn('bar', 'integer'); + $keyTable->addColumn('baz', 'string'); + $keyTable->setPrimaryKey(['bar']); + $keyTable->addUniqueIndex(['baz']); - $oldTable = new Table("foo"); - $oldTable->addColumn("bar", "integer"); - $oldTable->addColumn("baz", "string"); + $oldTable = new Table('foo'); + $oldTable->addColumn('bar', 'integer'); + $oldTable->addColumn('baz', 'string'); - $c = new \Doctrine\DBAL\Schema\Comparator; + $c = new Comparator(); $diff = $c->diffTable($oldTable, $keyTable); $sql = $this->_platform->getAlterTableSQL($diff); - self::assertEquals(array( - "ALTER TABLE foo ADD PRIMARY KEY (bar)", - "CREATE UNIQUE INDEX UNIQ_8C73652178240498 ON foo (baz)", - ), $sql); + self::assertEquals([ + 'ALTER TABLE foo ADD PRIMARY KEY (bar)', + 'CREATE UNIQUE INDEX UNIQ_8C73652178240498 ON foo (baz)', + ], $sql); } public function testModifyLimitQuery() @@ -193,24 +191,24 @@ public function testModifyLimitQueryWithEmptyOffset() */ public function testGetDateTimeTypeDeclarationSql() { - self::assertEquals("DATETIME", $this->_platform->getDateTimeTypeDeclarationSQL(array('version' => false))); - self::assertEquals("TIMESTAMP", $this->_platform->getDateTimeTypeDeclarationSQL(array('version' => true))); - self::assertEquals("DATETIME", $this->_platform->getDateTimeTypeDeclarationSQL(array())); + 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() { - return array("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"]; } public function getAlterTableColumnCommentsSQL() { - return array("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'"); + 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() { - return array("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"]; } /** @@ -218,47 +216,41 @@ public function getCreateTableColumnTypeCommentsSQL() */ public function testChangeIndexWithForeignKeys() { - $index = new Index("idx", array("col"), false); - $unique = new Index("uniq", array("col"), true); + $index = new Index('idx', ['col'], false); + $unique = new Index('uniq', ['col'], true); - $diff = new TableDiff("test", array(), array(), array(), array($unique), array(), array($index)); - $sql = $this->_platform->getAlterTableSQL($diff); - self::assertEquals(array("ALTER TABLE test DROP INDEX idx, ADD UNIQUE INDEX uniq (col)"), $sql); + $diff = new TableDiff('test', [], [], [], [$unique], [], [$index]); + $sql = $this->_platform->getAlterTableSQL($diff); + self::assertEquals(['ALTER TABLE test DROP INDEX idx, ADD UNIQUE INDEX uniq (col)'], $sql); - $diff = new TableDiff("test", array(), array(), array(), array($index), array(), array($unique)); - $sql = $this->_platform->getAlterTableSQL($diff); - self::assertEquals(array("ALTER TABLE test DROP INDEX uniq, ADD INDEX idx (col)"), $sql); + $diff = new TableDiff('test', [], [], [], [$index], [], [$unique]); + $sql = $this->_platform->getAlterTableSQL($diff); + self::assertEquals(['ALTER TABLE test DROP INDEX uniq, ADD INDEX idx (col)'], $sql); } protected function getQuotedColumnInPrimaryKeySQL() { - return array( - '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']; } protected function getQuotedColumnInIndexSQL() { - return array( - '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']; } protected function getQuotedNameInIndexSQL() { - return array( - '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']; } protected function getQuotedColumnInForeignKeySQL() { - return 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', '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`)', - ); + ]; } public function testCreateTableWithFulltextIndex() @@ -266,13 +258,13 @@ public function testCreateTableWithFulltextIndex() $table = new Table('fulltext_table'); $table->addOption('engine', 'MyISAM'); $table->addColumn('text', 'text'); - $table->addIndex(array('text'), 'fulltext_text'); + $table->addIndex(['text'], 'fulltext_text'); $index = $table->getIndex('fulltext_text'); $index->addFlag('fulltext'); $sql = $this->_platform->getCreateTableSQL($table); - self::assertEquals(array('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() @@ -280,37 +272,37 @@ public function testCreateTableWithSpatialIndex() $table = new Table('spatial_table'); $table->addOption('engine', 'MyISAM'); $table->addColumn('point', 'text'); // This should be a point type - $table->addIndex(array('point'), 'spatial_text'); + $table->addIndex(['point'], 'spatial_text'); $index = $table->getIndex('spatial_text'); $index->addFlag('spatial'); $sql = $this->_platform->getCreateTableSQL($table); - self::assertEquals(array('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() { - self::assertEquals('TINYTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 1))); - self::assertEquals('TINYTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 255))); - self::assertEquals('TEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 256))); - self::assertEquals('TEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 65535))); - self::assertEquals('MEDIUMTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 65536))); - self::assertEquals('MEDIUMTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 16777215))); - self::assertEquals('LONGTEXT', $this->_platform->getClobTypeDeclarationSQL(array('length' => 16777216))); - self::assertEquals('LONGTEXT', $this->_platform->getClobTypeDeclarationSQL(array())); + self::assertEquals('TINYTEXT', $this->_platform->getClobTypeDeclarationSQL(['length' => 1])); + self::assertEquals('TINYTEXT', $this->_platform->getClobTypeDeclarationSQL(['length' => 255])); + self::assertEquals('TEXT', $this->_platform->getClobTypeDeclarationSQL(['length' => 256])); + self::assertEquals('TEXT', $this->_platform->getClobTypeDeclarationSQL(['length' => 65535])); + self::assertEquals('MEDIUMTEXT', $this->_platform->getClobTypeDeclarationSQL(['length' => 65536])); + self::assertEquals('MEDIUMTEXT', $this->_platform->getClobTypeDeclarationSQL(['length' => 16777215])); + self::assertEquals('LONGTEXT', $this->_platform->getClobTypeDeclarationSQL(['length' => 16777216])); + self::assertEquals('LONGTEXT', $this->_platform->getClobTypeDeclarationSQL([])); } public function testBlobTypeDeclarationSQL() { - self::assertEquals('TINYBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 1))); - self::assertEquals('TINYBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 255))); - self::assertEquals('BLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 256))); - self::assertEquals('BLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 65535))); - self::assertEquals('MEDIUMBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 65536))); - self::assertEquals('MEDIUMBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 16777215))); - self::assertEquals('LONGBLOB', $this->_platform->getBlobTypeDeclarationSQL(array('length' => 16777216))); - self::assertEquals('LONGBLOB', $this->_platform->getBlobTypeDeclarationSQL(array())); + self::assertEquals('TINYBLOB', $this->_platform->getBlobTypeDeclarationSQL(['length' => 1])); + self::assertEquals('TINYBLOB', $this->_platform->getBlobTypeDeclarationSQL(['length' => 255])); + self::assertEquals('BLOB', $this->_platform->getBlobTypeDeclarationSQL(['length' => 256])); + self::assertEquals('BLOB', $this->_platform->getBlobTypeDeclarationSQL(['length' => 65535])); + self::assertEquals('MEDIUMBLOB', $this->_platform->getBlobTypeDeclarationSQL(['length' => 65536])); + self::assertEquals('MEDIUMBLOB', $this->_platform->getBlobTypeDeclarationSQL(['length' => 16777215])); + self::assertEquals('LONGBLOB', $this->_platform->getBlobTypeDeclarationSQL(['length' => 16777216])); + self::assertEquals('LONGBLOB', $this->_platform->getBlobTypeDeclarationSQL([])); } /** @@ -321,16 +313,16 @@ public function testAlterTableAddPrimaryKey() $table = new Table('alter_table_add_pk'); $table->addColumn('id', 'integer'); $table->addColumn('foo', 'integer'); - $table->addIndex(array('id'), 'idx_id'); + $table->addIndex(['id'], 'idx_id'); $comparator = new Comparator(); $diffTable = clone $table; $diffTable->dropIndex('idx_id'); - $diffTable->setPrimaryKey(array('id')); + $diffTable->setPrimaryKey(['id']); self::assertEquals( - array('DROP INDEX idx_id ON alter_table_add_pk', 'ALTER TABLE alter_table_add_pk ADD PRIMARY KEY (id)'), + ['DROP INDEX idx_id ON alter_table_add_pk', 'ALTER TABLE alter_table_add_pk ADD PRIMARY KEY (id)'], $this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) ); } @@ -340,23 +332,23 @@ public function testAlterTableAddPrimaryKey() */ public function testAlterPrimaryKeyWithAutoincrementColumn() { - $table = new Table("alter_primary_key"); - $table->addColumn('id', 'integer', array('autoincrement' => true)); + $table = new Table('alter_primary_key'); + $table->addColumn('id', 'integer', ['autoincrement' => true]); $table->addColumn('foo', 'integer'); - $table->setPrimaryKey(array('id')); + $table->setPrimaryKey(['id']); $comparator = new Comparator(); - $diffTable = clone $table; + $diffTable = clone $table; $diffTable->dropPrimaryKey(); - $diffTable->setPrimaryKey(array('foo')); + $diffTable->setPrimaryKey(['foo']); self::assertEquals( - array( + [ 'ALTER TABLE alter_primary_key MODIFY id INT NOT NULL', 'ALTER TABLE alter_primary_key DROP PRIMARY KEY', - 'ALTER TABLE alter_primary_key ADD PRIMARY KEY (foo)' - ), + 'ALTER TABLE alter_primary_key ADD PRIMARY KEY (foo)', + ], $this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) ); } @@ -366,22 +358,22 @@ public function testAlterPrimaryKeyWithAutoincrementColumn() */ public function testDropPrimaryKeyWithAutoincrementColumn() { - $table = new Table("drop_primary_key"); - $table->addColumn('id', 'integer', array('autoincrement' => true)); + $table = new Table('drop_primary_key'); + $table->addColumn('id', 'integer', ['autoincrement' => true]); $table->addColumn('foo', 'integer'); $table->addColumn('bar', 'integer'); - $table->setPrimaryKey(array('id', 'foo')); + $table->setPrimaryKey(['id', 'foo']); $comparator = new Comparator(); - $diffTable = clone $table; + $diffTable = clone $table; $diffTable->dropPrimaryKey(); self::assertEquals( - array( + [ 'ALTER TABLE drop_primary_key MODIFY id INT NOT NULL', - 'ALTER TABLE drop_primary_key DROP PRIMARY KEY' - ), + 'ALTER TABLE drop_primary_key DROP PRIMARY KEY', + ], $this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) ); } @@ -391,24 +383,24 @@ public function testDropPrimaryKeyWithAutoincrementColumn() */ public function testDropNonAutoincrementColumnFromCompositePrimaryKeyWithAutoincrementColumn() { - $table = new Table("tbl"); - $table->addColumn('id', 'integer', array('autoincrement' => true)); + $table = new Table('tbl'); + $table->addColumn('id', 'integer', ['autoincrement' => true]); $table->addColumn('foo', 'integer'); $table->addColumn('bar', 'integer'); - $table->setPrimaryKey(array('id', 'foo')); + $table->setPrimaryKey(['id', 'foo']); $comparator = new Comparator(); - $diffTable = clone $table; + $diffTable = clone $table; $diffTable->dropPrimaryKey(); - $diffTable->setPrimaryKey(array('id')); + $diffTable->setPrimaryKey(['id']); self::assertSame( - array( + [ 'ALTER TABLE tbl MODIFY id INT NOT NULL', 'ALTER TABLE tbl DROP PRIMARY KEY', 'ALTER TABLE tbl ADD PRIMARY KEY (id)', - ), + ], $this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) ); } @@ -418,24 +410,24 @@ public function testDropNonAutoincrementColumnFromCompositePrimaryKeyWithAutoinc */ public function testAddNonAutoincrementColumnToPrimaryKeyWithAutoincrementColumn() { - $table = new Table("tbl"); - $table->addColumn('id', 'integer', array('autoincrement' => true)); + $table = new Table('tbl'); + $table->addColumn('id', 'integer', ['autoincrement' => true]); $table->addColumn('foo', 'integer'); $table->addColumn('bar', 'integer'); - $table->setPrimaryKey(array('id')); + $table->setPrimaryKey(['id']); $comparator = new Comparator(); - $diffTable = clone $table; + $diffTable = clone $table; $diffTable->dropPrimaryKey(); - $diffTable->setPrimaryKey(array('id', 'foo')); + $diffTable->setPrimaryKey(['id', 'foo']); self::assertSame( - array( + [ 'ALTER TABLE tbl MODIFY id INT NOT NULL', 'ALTER TABLE tbl DROP PRIMARY KEY', 'ALTER TABLE tbl ADD PRIMARY KEY (id, foo)', - ), + ], $this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) ); } @@ -445,57 +437,55 @@ public function testAddNonAutoincrementColumnToPrimaryKeyWithAutoincrementColumn */ public function testAddAutoIncrementPrimaryKey() { - $keyTable = new Table("foo"); - $keyTable->addColumn("id", "integer", array('autoincrement' => true)); - $keyTable->addColumn("baz", "string"); - $keyTable->setPrimaryKey(array("id")); + $keyTable = new Table('foo'); + $keyTable->addColumn('id', 'integer', ['autoincrement' => true]); + $keyTable->addColumn('baz', 'string'); + $keyTable->setPrimaryKey(['id']); - $oldTable = new Table("foo"); - $oldTable->addColumn("baz", "string"); + $oldTable = new Table('foo'); + $oldTable->addColumn('baz', 'string'); - $c = new \Doctrine\DBAL\Schema\Comparator; + $c = new Comparator(); $diff = $c->diffTable($oldTable, $keyTable); $sql = $this->_platform->getAlterTableSQL($diff); - self::assertEquals(array( - "ALTER TABLE foo ADD id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)", - ), $sql); + self::assertEquals(['ALTER TABLE foo ADD id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)'], $sql); } public function testNamedPrimaryKey() { - $diff = new TableDiff('mytable'); - $diff->changedIndexes['foo_index'] = new Index('foo_index', array('foo'), true, true); + $diff = new TableDiff('mytable'); + $diff->changedIndexes['foo_index'] = new Index('foo_index', ['foo'], true, true); $sql = $this->_platform->getAlterTableSQL($diff); - self::assertEquals(array( - "ALTER TABLE mytable DROP PRIMARY KEY", - "ALTER TABLE mytable ADD PRIMARY KEY (foo)", - ), $sql); + self::assertEquals([ + 'ALTER TABLE mytable DROP PRIMARY KEY', + 'ALTER TABLE mytable ADD PRIMARY KEY (foo)', + ], $sql); } public function testAlterPrimaryKeyWithNewColumn() { - $table = new Table("yolo"); + $table = new Table('yolo'); $table->addColumn('pkc1', 'integer'); $table->addColumn('col_a', 'integer'); - $table->setPrimaryKey(array('pkc1')); + $table->setPrimaryKey(['pkc1']); $comparator = new Comparator(); - $diffTable = clone $table; + $diffTable = clone $table; $diffTable->addColumn('pkc2', 'integer'); $diffTable->dropPrimaryKey(); - $diffTable->setPrimaryKey(array('pkc1', 'pkc2')); + $diffTable->setPrimaryKey(['pkc1', 'pkc2']); self::assertSame( - array( + [ 'ALTER TABLE yolo DROP PRIMARY KEY', 'ALTER TABLE yolo ADD pkc2 INT NOT NULL', 'ALTER TABLE yolo ADD PRIMARY KEY (pkc1, pkc2)', - ), + ], $this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) ); } @@ -516,13 +506,13 @@ protected function getBinaryMaxLength() public function testReturnsBinaryTypeDeclarationSQL() { - self::assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array())); - self::assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 0))); - self::assertSame('VARBINARY(65535)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 65535))); + self::assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL([])); + self::assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 0])); + self::assertSame('VARBINARY(65535)', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 65535])); - self::assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true))); - self::assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 0))); - self::assertSame('BINARY(65535)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 65535))); + self::assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true])); + self::assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 0])); + self::assertSame('BINARY(65535)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 65535])); } /** @@ -544,15 +534,15 @@ public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() public function testDoesNotPropagateForeignKeyCreationForNonSupportingEngines() { - $table = new Table("foreign_table"); + $table = new Table('foreign_table'); $table->addColumn('id', 'integer'); $table->addColumn('fk_id', 'integer'); - $table->addForeignKeyConstraint('foreign_table', array('fk_id'), array('id')); - $table->setPrimaryKey(array('id')); + $table->addForeignKeyConstraint('foreign_table', ['fk_id'], ['id']); + $table->setPrimaryKey(['id']); $table->addOption('engine', 'MyISAM'); self::assertSame( - array('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 @@ -563,10 +553,10 @@ public function testDoesNotPropagateForeignKeyCreationForNonSupportingEngines() $table->addOption('engine', 'InnoDB'); self::assertSame( - array( + [ '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)' - ), + 'ALTER TABLE foreign_table ADD CONSTRAINT FK_5690FFE2A57719D0 FOREIGN KEY (fk_id) REFERENCES foreign_table (id)', + ], $this->_platform->getCreateTableSQL( $table, AbstractPlatform::CREATE_INDEXES|AbstractPlatform::CREATE_FOREIGNKEYS @@ -576,20 +566,20 @@ public function testDoesNotPropagateForeignKeyCreationForNonSupportingEngines() public function testDoesNotPropagateForeignKeyAlterationForNonSupportingEngines() { - $table = new Table("foreign_table"); + $table = new Table('foreign_table'); $table->addColumn('id', 'integer'); $table->addColumn('fk_id', 'integer'); - $table->addForeignKeyConstraint('foreign_table', array('fk_id'), array('id')); - $table->setPrimaryKey(array('id')); + $table->addForeignKeyConstraint('foreign_table', ['fk_id'], ['id']); + $table->setPrimaryKey(['id']); $table->addOption('engine', 'MyISAM'); - $addedForeignKeys = array(new ForeignKeyConstraint(array('fk_id'), 'foo', array('id'), 'fk_add')); - $changedForeignKeys = array(new ForeignKeyConstraint(array('fk_id'), 'bar', array('id'), 'fk_change')); - $removedForeignKeys = array(new ForeignKeyConstraint(array('fk_id'), 'baz', array('id'), 'fk_remove')); + $addedForeignKeys = [new ForeignKeyConstraint(['fk_id'], 'foo', ['id'], 'fk_add')]; + $changedForeignKeys = [new ForeignKeyConstraint(['fk_id'], 'bar', ['id'], 'fk_change')]; + $removedForeignKeys = [new ForeignKeyConstraint(['fk_id'], 'baz', ['id'], 'fk_remove')]; - $tableDiff = new TableDiff('foreign_table'); - $tableDiff->fromTable = $table; - $tableDiff->addedForeignKeys = $addedForeignKeys; + $tableDiff = new TableDiff('foreign_table'); + $tableDiff->fromTable = $table; + $tableDiff->addedForeignKeys = $addedForeignKeys; $tableDiff->changedForeignKeys = $changedForeignKeys; $tableDiff->removedForeignKeys = $removedForeignKeys; @@ -597,19 +587,19 @@ public function testDoesNotPropagateForeignKeyAlterationForNonSupportingEngines( $table->addOption('engine', 'InnoDB'); - $tableDiff = new TableDiff('foreign_table'); - $tableDiff->fromTable = $table; - $tableDiff->addedForeignKeys = $addedForeignKeys; + $tableDiff = new TableDiff('foreign_table'); + $tableDiff->fromTable = $table; + $tableDiff->addedForeignKeys = $addedForeignKeys; $tableDiff->changedForeignKeys = $changedForeignKeys; $tableDiff->removedForeignKeys = $removedForeignKeys; self::assertSame( - array( + [ 'ALTER TABLE foreign_table DROP FOREIGN KEY fk_remove', 'ALTER TABLE foreign_table DROP FOREIGN KEY fk_change', 'ALTER TABLE foreign_table ADD CONSTRAINT fk_add FOREIGN KEY (fk_id) REFERENCES foo (id)', 'ALTER TABLE foreign_table ADD CONSTRAINT fk_change FOREIGN KEY (fk_id) REFERENCES bar (id)', - ), + ], $this->_platform->getAlterTableSQL($tableDiff) ); } @@ -619,10 +609,10 @@ public function testDoesNotPropagateForeignKeyAlterationForNonSupportingEngines( */ protected function getAlterTableRenameIndexSQL() { - return array( + return [ 'DROP INDEX idx_foo ON mytable', 'CREATE INDEX idx_bar ON mytable (id)', - ); + ]; } /** @@ -630,12 +620,12 @@ protected function getAlterTableRenameIndexSQL() */ protected function getQuotedAlterTableRenameIndexSQL() { - return array( + return [ 'DROP INDEX `create` ON `table`', 'CREATE INDEX `select` ON `table` (id)', 'DROP INDEX `foo` ON `table`', 'CREATE INDEX `bar` ON `table` (id)', - ); + ]; } /** @@ -643,10 +633,10 @@ protected function getQuotedAlterTableRenameIndexSQL() */ protected function getAlterTableRenameIndexInSchemaSQL() { - return array( + return [ 'DROP INDEX idx_foo ON myschema.mytable', 'CREATE INDEX idx_bar ON myschema.mytable (id)', - ); + ]; } /** @@ -654,12 +644,12 @@ protected function getAlterTableRenameIndexInSchemaSQL() */ protected function getQuotedAlterTableRenameIndexInSchemaSQL() { - return array( + return [ 'DROP INDEX `create` ON `schema`.`table`', 'CREATE INDEX `select` ON `schema`.`table` (id)', 'DROP INDEX `foo` ON `schema`.`table`', 'CREATE INDEX `bar` ON `schema`.`table` (id)', - ); + ]; } protected function getQuotesDropForeignKeySQL() @@ -674,22 +664,22 @@ protected function getQuotesDropConstraintSQL() public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() { - $table = new Table("text_blob_default_value"); - $table->addColumn('def_text', 'text', array('default' => 'def')); - $table->addColumn('def_text_null', 'text', array('notnull' => false, 'default' => 'def')); - $table->addColumn('def_blob', 'blob', array('default' => 'def')); - $table->addColumn('def_blob_null', 'blob', array('notnull' => false, 'default' => 'def')); + $table = new Table('text_blob_default_value'); + $table->addColumn('def_text', 'text', ['default' => 'def']); + $table->addColumn('def_text_null', 'text', ['notnull' => false, 'default' => 'def']); + $table->addColumn('def_blob', 'blob', ['default' => 'def']); + $table->addColumn('def_blob_null', 'blob', ['notnull' => false, 'default' => 'def']); self::assertSame( - array('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) ); $diffTable = clone $table; - $diffTable->changeColumn('def_text', array('default' => null)); - $diffTable->changeColumn('def_text_null', array('default' => null)); - $diffTable->changeColumn('def_blob', array('default' => null)); - $diffTable->changeColumn('def_blob_null', array('default' => null)); + $diffTable->changeColumn('def_text', ['default' => null]); + $diffTable->changeColumn('def_text_null', ['default' => null]); + $diffTable->changeColumn('def_blob', ['default' => null]); + $diffTable->changeColumn('def_blob_null', ['default' => null]); $comparator = new Comparator(); @@ -701,8 +691,7 @@ public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() */ protected function getQuotedAlterTableRenameColumnSQL() { - return array( - "ALTER TABLE mytable " . + return ['ALTER TABLE mytable ' . "CHANGE unquoted1 unquoted INT NOT NULL COMMENT 'Unquoted 1', " . "CHANGE unquoted2 `where` INT NOT NULL COMMENT 'Unquoted 2', " . "CHANGE unquoted3 `foo` INT NOT NULL COMMENT 'Unquoted 3', " . @@ -711,8 +700,8 @@ protected function getQuotedAlterTableRenameColumnSQL() "CHANGE `select` `bar` INT NOT NULL COMMENT 'Reserved keyword 3', " . "CHANGE quoted1 quoted INT NOT NULL COMMENT 'Quoted 1', " . "CHANGE quoted2 `and` INT NOT NULL COMMENT 'Quoted 2', " . - "CHANGE quoted3 `baz` INT NOT NULL COMMENT 'Quoted 3'" - ); + "CHANGE quoted3 `baz` INT NOT NULL COMMENT 'Quoted 3'", + ]; } /** @@ -720,15 +709,14 @@ protected function getQuotedAlterTableRenameColumnSQL() */ protected function getQuotedAlterTableChangeColumnLengthSQL() { - return array( - "ALTER TABLE mytable " . + return ['ALTER TABLE mytable ' . "CHANGE unquoted1 unquoted1 VARCHAR(255) NOT NULL COMMENT 'Unquoted 1', " . "CHANGE unquoted2 unquoted2 VARCHAR(255) NOT NULL COMMENT 'Unquoted 2', " . "CHANGE unquoted3 unquoted3 VARCHAR(255) NOT NULL COMMENT 'Unquoted 3', " . "CHANGE `create` `create` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 1', " . "CHANGE `table` `table` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 2', " . - "CHANGE `select` `select` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 3'" - ); + "CHANGE `select` `select` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 3'", + ]; } /** @@ -736,7 +724,7 @@ protected function getQuotedAlterTableChangeColumnLengthSQL() */ public function testReturnsGuidTypeDeclarationSQL() { - self::assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL(array())); + self::assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL([])); } /** @@ -744,9 +732,7 @@ public function testReturnsGuidTypeDeclarationSQL() */ public function getAlterTableRenameColumnSQL() { - return array( - "ALTER TABLE foo CHANGE bar baz INT DEFAULT 666 NOT NULL COMMENT 'rename test'", - ); + return ["ALTER TABLE foo CHANGE bar baz INT DEFAULT 666 NOT NULL COMMENT 'rename test'"]; } /** @@ -754,14 +740,14 @@ public function getAlterTableRenameColumnSQL() */ protected function getQuotesTableIdentifiersInAlterTableSQL() { - return array( + return [ 'ALTER TABLE `foo` DROP FOREIGN KEY fk1', 'ALTER TABLE `foo` DROP FOREIGN KEY fk2', 'ALTER TABLE `foo` RENAME TO `table`, ADD bloo INT NOT NULL, DROP baz, CHANGE bar bar INT DEFAULT NULL, ' . 'CHANGE id war INT NOT NULL', 'ALTER TABLE `table` ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id)', 'ALTER TABLE `table` ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)', - ); + ]; } /** @@ -769,11 +755,11 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() */ protected function getCommentOnColumnSQL() { - return array( + return [ "COMMENT ON COLUMN foo.bar IS 'comment'", "COMMENT ON COLUMN `Foo`.`BAR` IS 'comment'", "COMMENT ON COLUMN `select`.`from` IS 'comment'", - ); + ]; } /** @@ -805,9 +791,7 @@ protected function getQuotesReservedKeywordInTruncateTableSQL() */ protected function getAlterStringToFixedStringSQL() { - return array( - 'ALTER TABLE mytable CHANGE name name CHAR(2) NOT NULL', - ); + return ['ALTER TABLE mytable CHANGE name name CHAR(2) NOT NULL']; } /** @@ -815,12 +799,12 @@ protected function getAlterStringToFixedStringSQL() */ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() { - return array( + return [ 'ALTER TABLE mytable DROP FOREIGN KEY fk_foo', 'DROP INDEX idx_foo ON mytable', 'CREATE INDEX idx_foo_renamed ON mytable (foo)', 'ALTER TABLE mytable ADD CONSTRAINT fk_foo FOREIGN KEY (foo) REFERENCES foreign_table (id)', - ); + ]; } /** @@ -828,14 +812,14 @@ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() */ public function getGeneratesDecimalTypeDeclarationSQL() { - return array( - array(array(), 'NUMERIC(10, 0)'), - array(array('unsigned' => true), 'NUMERIC(10, 0) UNSIGNED'), - array(array('unsigned' => false), 'NUMERIC(10, 0)'), - array(array('precision' => 5), 'NUMERIC(5, 0)'), - array(array('scale' => 5), 'NUMERIC(10, 5)'), - array(array('precision' => 8, 'scale' => 2), 'NUMERIC(8, 2)'), - ); + return [ + [[], 'NUMERIC(10, 0)'], + [['unsigned' => true], 'NUMERIC(10, 0) UNSIGNED'], + [['unsigned' => false], 'NUMERIC(10, 0)'], + [['precision' => 5], 'NUMERIC(5, 0)'], + [['scale' => 5], 'NUMERIC(10, 5)'], + [['precision' => 8, 'scale' => 2], 'NUMERIC(8, 2)'], + ]; } /** @@ -843,14 +827,14 @@ public function getGeneratesDecimalTypeDeclarationSQL() */ public function getGeneratesFloatDeclarationSQL() { - return array( - array(array(), 'DOUBLE PRECISION'), - array(array('unsigned' => true), 'DOUBLE PRECISION UNSIGNED'), - array(array('unsigned' => false), 'DOUBLE PRECISION'), - array(array('precision' => 5), 'DOUBLE PRECISION'), - array(array('scale' => 5), 'DOUBLE PRECISION'), - array(array('precision' => 8, 'scale' => 2), 'DOUBLE PRECISION'), - ); + return [ + [[], 'DOUBLE PRECISION'], + [['unsigned' => true], 'DOUBLE PRECISION UNSIGNED'], + [['unsigned' => false], 'DOUBLE PRECISION'], + [['precision' => 5], 'DOUBLE PRECISION'], + [['scale' => 5], 'DOUBLE PRECISION'], + [['precision' => 8, 'scale' => 2], 'DOUBLE PRECISION'], + ]; } /** diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php index a0b0ea33741..9b303a6e76e 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php @@ -13,17 +13,16 @@ use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Types\Type; +use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\Types\CommentedType; use function get_class; use function implode; use function sprintf; use function str_repeat; -abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase +abstract class AbstractPlatformTestCase extends DbalTestCase { - /** - * @var \Doctrine\DBAL\Platforms\AbstractPlatform - */ + /** @var AbstractPlatform */ protected $_platform; abstract public function createPlatform(); @@ -38,13 +37,13 @@ protected function setUp() */ public function testQuoteIdentifier() { - if ($this->_platform->getName() == "mssql") { + if ($this->_platform->getName() === 'mssql') { $this->markTestSkipped('Not working this way on mssql.'); } $c = $this->_platform->getIdentifierQuoteCharacter(); - self::assertEquals($c."test".$c, $this->_platform->quoteIdentifier("test")); - self::assertEquals($c."test".$c.".".$c."test".$c, $this->_platform->quoteIdentifier("test.test")); + self::assertEquals($c . 'test' . $c, $this->_platform->quoteIdentifier('test')); + self::assertEquals($c . 'test' . $c . '.' . $c . 'test' . $c, $this->_platform->quoteIdentifier('test.test')); self::assertEquals(str_repeat($c, 4), $this->_platform->quoteIdentifier($c)); } @@ -53,19 +52,18 @@ public function testQuoteIdentifier() */ public function testQuoteSingleIdentifier() { - if ($this->_platform->getName() == "mssql") { + if ($this->_platform->getName() === 'mssql') { $this->markTestSkipped('Not working this way on mssql.'); } $c = $this->_platform->getIdentifierQuoteCharacter(); - self::assertEquals($c."test".$c, $this->_platform->quoteSingleIdentifier("test")); - self::assertEquals($c."test.test".$c, $this->_platform->quoteSingleIdentifier("test.test")); + self::assertEquals($c . 'test' . $c, $this->_platform->quoteSingleIdentifier('test')); + self::assertEquals($c . 'test.test' . $c, $this->_platform->quoteSingleIdentifier('test.test')); self::assertEquals(str_repeat($c, 4), $this->_platform->quoteSingleIdentifier($c)); } /** * @group DBAL-1029 - * * @dataProvider getReturnsForeignKeyReferentialActionSQL */ public function testReturnsForeignKeyReferentialActionSQL($action, $expectedSQL) @@ -78,14 +76,14 @@ public function testReturnsForeignKeyReferentialActionSQL($action, $expectedSQL) */ public function getReturnsForeignKeyReferentialActionSQL() { - return array( - array('CASCADE', 'CASCADE'), - array('SET NULL', 'SET NULL'), - array('NO ACTION', 'NO ACTION'), - array('RESTRICT', 'RESTRICT'), - array('SET DEFAULT', 'SET DEFAULT'), - array('CaScAdE', 'CASCADE'), - ); + return [ + ['CASCADE', 'CASCADE'], + ['SET NULL', 'SET NULL'], + ['NO ACTION', 'NO ACTION'], + ['RESTRICT', 'RESTRICT'], + ['SET DEFAULT', 'SET DEFAULT'], + ['CaScAdE', 'CASCADE'], + ]; } public function testGetInvalidForeignKeyReferentialActionSQL() @@ -117,7 +115,7 @@ public function testRegisterUnknownDoctrineMappingType() */ public function testRegistersCommentedDoctrineMappingTypeImplicitly() { - if (!Type::hasType('my_commented')) { + if (! Type::hasType('my_commented')) { Type::addType('my_commented', CommentedType::class); } @@ -129,7 +127,6 @@ public function testRegistersCommentedDoctrineMappingTypeImplicitly() /** * @group DBAL-939 - * * @dataProvider getIsCommentedDoctrineType */ public function testIsCommentedDoctrineType(Type $type, $commented) @@ -141,15 +138,15 @@ public function getIsCommentedDoctrineType() { $this->setUp(); - $data = array(); + $data = []; foreach (Type::getTypesMap() as $typeName => $className) { $type = Type::getType($typeName); - $data[$typeName] = array( + $data[$typeName] = [ $type, $type->requiresSQLCommentHint($this->_platform), - ); + ]; } return $data; @@ -166,9 +163,9 @@ public function testCreateWithNoColumns() public function testGeneratesTableCreationSql() { $table = new Table('test'); - $table->addColumn('id', 'integer', array('notnull' => true, 'autoincrement' => true)); - $table->addColumn('test', 'string', array('notnull' => false, 'length' => 255)); - $table->setPrimaryKey(array('id')); + $table->addColumn('id', 'integer', ['notnull' => true, 'autoincrement' => true]); + $table->addColumn('test', 'string', ['notnull' => false, 'length' => 255]); + $table->setPrimaryKey(['id']); $sql = $this->_platform->getCreateTableSQL($table); self::assertEquals($this->getGenerateTableSql(), $sql[0]); @@ -179,9 +176,9 @@ abstract public function getGenerateTableSql(); public function testGenerateTableWithMultiColumnUniqueIndex() { $table = new Table('test'); - $table->addColumn('foo', 'string', array('notnull' => false, 'length' => 255)); - $table->addColumn('bar', 'string', array('notnull' => false, 'length' => 255)); - $table->addUniqueIndex(array("foo", "bar")); + $table->addColumn('foo', 'string', ['notnull' => false, 'length' => 255]); + $table->addColumn('bar', 'string', ['notnull' => false, 'length' => 255]); + $table->addUniqueIndex(['foo', 'bar']); $sql = $this->_platform->getCreateTableSQL($table); self::assertEquals($this->getGenerateTableWithMultiColumnUniqueIndexSql(), $sql); @@ -191,7 +188,7 @@ abstract public function getGenerateTableWithMultiColumnUniqueIndexSql(); public function testGeneratesIndexCreationSql() { - $indexDef = new \Doctrine\DBAL\Schema\Index('my_idx', array('user_name', 'last_login')); + $indexDef = new Index('my_idx', ['user_name', 'last_login']); self::assertEquals( $this->getGenerateIndexSql(), @@ -203,7 +200,7 @@ abstract public function getGenerateIndexSql(); public function testGeneratesUniqueIndexCreationSql() { - $indexDef = new \Doctrine\DBAL\Schema\Index('index_name', array('test', 'test2'), true); + $indexDef = new Index('index_name', ['test', 'test2'], true); $sql = $this->_platform->getCreateIndexSQL($indexDef, 'test'); self::assertEquals($this->getGenerateUniqueIndexSql(), $sql); @@ -213,20 +210,20 @@ abstract public function getGenerateUniqueIndexSql(); public function testGeneratesPartialIndexesSqlOnlyWhenSupportingPartialIndexes() { - $where = 'test IS NULL AND test2 IS NOT NULL'; - $indexDef = new \Doctrine\DBAL\Schema\Index('name', array('test', 'test2'), false, false, array(), array('where' => $where)); - $uniqueIndex = new \Doctrine\DBAL\Schema\Index('name', array('test', 'test2'), true, false, array(), array('where' => $where)); + $where = 'test IS NULL AND test2 IS NOT NULL'; + $indexDef = new Index('name', ['test', 'test2'], false, false, [], ['where' => $where]); + $uniqueIndex = new Index('name', ['test', 'test2'], true, false, [], ['where' => $where]); $expected = ' WHERE ' . $where; - $actuals = array(); + $actuals = []; if ($this->supportsInlineIndexDeclaration()) { - $actuals []= $this->_platform->getIndexDeclarationSQL('name', $indexDef); + $actuals[] = $this->_platform->getIndexDeclarationSQL('name', $indexDef); } - $actuals []= $this->_platform->getUniqueConstraintDeclarationSQL('name', $uniqueIndex); - $actuals []= $this->_platform->getCreateIndexSQL($indexDef, 'table'); + $actuals[] = $this->_platform->getUniqueConstraintDeclarationSQL('name', $uniqueIndex); + $actuals[] = $this->_platform->getCreateIndexSQL($indexDef, 'table'); foreach ($actuals as $actual) { if ($this->_platform->supportsPartialIndexes()) { @@ -239,7 +236,7 @@ public function testGeneratesPartialIndexesSqlOnlyWhenSupportingPartialIndexes() public function testGeneratesForeignKeyCreationSql() { - $fk = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(array('fk_name_id'), 'other_table', array('id'), ''); + $fk = new ForeignKeyConstraint(['fk_name_id'], 'other_table', ['id'], ''); $sql = $this->_platform->getCreateForeignKeySQL($fk, 'test'); self::assertEquals($sql, $this->getGenerateForeignKeySql()); @@ -249,22 +246,22 @@ abstract public function getGenerateForeignKeySql(); public function testGeneratesConstraintCreationSql() { - $idx = new \Doctrine\DBAL\Schema\Index('constraint_name', array('test'), true, false); + $idx = new Index('constraint_name', ['test'], true, false); $sql = $this->_platform->getCreateConstraintSQL($idx, 'test'); self::assertEquals($this->getGenerateConstraintUniqueIndexSql(), $sql); - $pk = new \Doctrine\DBAL\Schema\Index('constraint_name', array('test'), true, true); + $pk = new Index('constraint_name', ['test'], true, true); $sql = $this->_platform->getCreateConstraintSQL($pk, 'test'); self::assertEquals($this->getGenerateConstraintPrimaryIndexSql(), $sql); - $fk = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(array('fk_name'), 'foreign', array('id'), 'constraint_fk'); + $fk = new ForeignKeyConstraint(['fk_name'], 'foreign', ['id'], 'constraint_fk'); $sql = $this->_platform->getCreateConstraintSQL($fk, 'test'); self::assertEquals($this->getGenerateConstraintForeignKeySql($fk), $sql); } public function testGeneratesForeignKeySqlOnlyWhenSupportingForeignKeys() { - $fk = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(array('fk_name'), 'foreign', array('id'), 'constraint_fk'); + $fk = new ForeignKeyConstraint(['fk_name'], 'foreign', ['id'], 'constraint_fk'); if ($this->_platform->supportsForeignKeyConstraints()) { self::assertInternalType( @@ -291,7 +288,7 @@ public function testGeneratesBitAndComparisonExpressionSql() self::assertEquals($this->getBitAndComparisonExpressionSql(2, 4), $sql); } - protected function getBitOrComparisonExpressionSql($value1, $value2) + protected function getBitOrComparisonExpressionSql($value1, $value2) { return '(' . $value1 . ' | ' . $value2 . ')'; } @@ -329,28 +326,34 @@ public function testGeneratesTableAlterationSql() $expectedSql = $this->getGenerateAlterTableSql(); $table = new Table('mytable'); - $table->addColumn('id', 'integer', array('autoincrement' => true)); + $table->addColumn('id', 'integer', ['autoincrement' => true]); $table->addColumn('foo', 'integer'); $table->addColumn('bar', 'string'); $table->addColumn('bloo', 'boolean'); - $table->setPrimaryKey(array('id')); - - $tableDiff = new TableDiff('mytable'); - $tableDiff->fromTable = $table; - $tableDiff->newName = 'userlist'; - $tableDiff->addedColumns['quota'] = new \Doctrine\DBAL\Schema\Column('quota', \Doctrine\DBAL\Types\Type::getType('integer'), array('notnull' => false)); - $tableDiff->removedColumns['foo'] = new \Doctrine\DBAL\Schema\Column('foo', \Doctrine\DBAL\Types\Type::getType('integer')); - $tableDiff->changedColumns['bar'] = new \Doctrine\DBAL\Schema\ColumnDiff( - 'bar', new \Doctrine\DBAL\Schema\Column( - 'baz', \Doctrine\DBAL\Types\Type::getType('string'), array('default' => 'def') + $table->setPrimaryKey(['id']); + + $tableDiff = new TableDiff('mytable'); + $tableDiff->fromTable = $table; + $tableDiff->newName = 'userlist'; + $tableDiff->addedColumns['quota'] = new Column('quota', Type::getType('integer'), ['notnull' => false]); + $tableDiff->removedColumns['foo'] = new Column('foo', Type::getType('integer')); + $tableDiff->changedColumns['bar'] = new ColumnDiff( + 'bar', + new Column( + 'baz', + Type::getType('string'), + ['default' => 'def'] ), - array('type', 'notnull', 'default') + ['type', 'notnull', 'default'] ); - $tableDiff->changedColumns['bloo'] = new \Doctrine\DBAL\Schema\ColumnDiff( - 'bloo', new \Doctrine\DBAL\Schema\Column( - 'bloo', \Doctrine\DBAL\Types\Type::getType('boolean'), array('default' => false) + $tableDiff->changedColumns['bloo'] = new ColumnDiff( + 'bloo', + new Column( + 'bloo', + Type::getType('boolean'), + ['default' => false] ), - array('type', 'notnull', 'default') + ['type', 'notnull', 'default'] ); $sql = $this->_platform->getAlterTableSQL($tableDiff); @@ -360,14 +363,14 @@ public function testGeneratesTableAlterationSql() public function testGetCustomColumnDeclarationSql() { - $field = array('columnDefinition' => 'MEDIUMINT(6) UNSIGNED'); + $field = ['columnDefinition' => 'MEDIUMINT(6) UNSIGNED']; self::assertEquals('foo MEDIUMINT(6) UNSIGNED', $this->_platform->getColumnDeclarationSQL('foo', $field)); } public function testGetCreateTableSqlDispatchEvent() { $listenerMock = $this->getMockBuilder('GetCreateTableSqlDispatchEvenListener') - ->setMethods(array('onSchemaCreateTable', 'onSchemaCreateTableColumn')) + ->setMethods(['onSchemaCreateTable', 'onSchemaCreateTableColumn']) ->getMock(); $listenerMock ->expects($this->once()) @@ -377,13 +380,13 @@ public function testGetCreateTableSqlDispatchEvent() ->method('onSchemaCreateTableColumn'); $eventManager = new EventManager(); - $eventManager->addEventListener(array(Events::onSchemaCreateTable, Events::onSchemaCreateTableColumn), $listenerMock); + $eventManager->addEventListener([Events::onSchemaCreateTable, Events::onSchemaCreateTableColumn], $listenerMock); $this->_platform->setEventManager($eventManager); $table = new Table('test'); - $table->addColumn('foo', 'string', array('notnull' => false, 'length' => 255)); - $table->addColumn('bar', 'string', array('notnull' => false, 'length' => 255)); + $table->addColumn('foo', 'string', ['notnull' => false, 'length' => 255]); + $table->addColumn('bar', 'string', ['notnull' => false, 'length' => 255]); $this->_platform->getCreateTableSQL($table); } @@ -391,14 +394,14 @@ public function testGetCreateTableSqlDispatchEvent() public function testGetDropTableSqlDispatchEvent() { $listenerMock = $this->getMockBuilder('GetDropTableSqlDispatchEventListener') - ->setMethods(array('onSchemaDropTable')) + ->setMethods(['onSchemaDropTable']) ->getMock(); $listenerMock ->expects($this->once()) ->method('onSchemaDropTable'); $eventManager = new EventManager(); - $eventManager->addEventListener(array(Events::onSchemaDropTable), $listenerMock); + $eventManager->addEventListener([Events::onSchemaDropTable], $listenerMock); $this->_platform->setEventManager($eventManager); @@ -407,13 +410,13 @@ public function testGetDropTableSqlDispatchEvent() public function testGetAlterTableSqlDispatchEvent() { - $events = array( + $events = [ 'onSchemaAlterTable', 'onSchemaAlterTableAddColumn', 'onSchemaAlterTableRemoveColumn', 'onSchemaAlterTableChangeColumn', - 'onSchemaAlterTableRenameColumn' - ); + 'onSchemaAlterTableRenameColumn', + ]; $listenerMock = $this->getMockBuilder('GetAlterTableSqlDispatchEvenListener') ->setMethods($events) @@ -435,13 +438,13 @@ public function testGetAlterTableSqlDispatchEvent() ->method('onSchemaAlterTableRenameColumn'); $eventManager = new EventManager(); - $events = array( + $events = [ Events::onSchemaAlterTable, Events::onSchemaAlterTableAddColumn, Events::onSchemaAlterTableRemoveColumn, Events::onSchemaAlterTableChangeColumn, - Events::onSchemaAlterTableRenameColumn - ); + Events::onSchemaAlterTableRenameColumn, + ]; $eventManager->addEventListener($events, $listenerMock); $this->_platform->setEventManager($eventManager); @@ -451,17 +454,20 @@ public function testGetAlterTableSqlDispatchEvent() $table->addColumn('changed', 'integer'); $table->addColumn('renamed', 'integer'); - $tableDiff = new TableDiff('mytable'); - $tableDiff->fromTable = $table; - $tableDiff->addedColumns['added'] = new \Doctrine\DBAL\Schema\Column('added', \Doctrine\DBAL\Types\Type::getType('integer'), array()); - $tableDiff->removedColumns['removed'] = new \Doctrine\DBAL\Schema\Column('removed', \Doctrine\DBAL\Types\Type::getType('integer'), array()); - $tableDiff->changedColumns['changed'] = new \Doctrine\DBAL\Schema\ColumnDiff( - 'changed', new \Doctrine\DBAL\Schema\Column( - 'changed2', \Doctrine\DBAL\Types\Type::getType('string'), array() + $tableDiff = new TableDiff('mytable'); + $tableDiff->fromTable = $table; + $tableDiff->addedColumns['added'] = new Column('added', Type::getType('integer'), []); + $tableDiff->removedColumns['removed'] = new Column('removed', Type::getType('integer'), []); + $tableDiff->changedColumns['changed'] = new ColumnDiff( + 'changed', + new Column( + 'changed2', + Type::getType('string'), + [] ), - array() + [] ); - $tableDiff->renamedColumns['renamed'] = new \Doctrine\DBAL\Schema\Column('renamed2', \Doctrine\DBAL\Types\Type::getType('integer'), array()); + $tableDiff->renamedColumns['renamed'] = new Column('renamed2', Type::getType('integer'), []); $this->_platform->getAlterTableSQL($tableDiff); } @@ -472,8 +478,8 @@ public function testGetAlterTableSqlDispatchEvent() public function testCreateTableColumnComments() { $table = new Table('test'); - $table->addColumn('id', 'integer', array('comment' => 'This is a comment')); - $table->setPrimaryKey(array('id')); + $table->addColumn('id', 'integer', ['comment' => 'This is a comment']); + $table->setPrimaryKey(['id']); self::assertEquals($this->getCreateTableColumnCommentsSQL(), $this->_platform->getCreateTableSQL($table)); } @@ -483,19 +489,24 @@ public function testCreateTableColumnComments() */ public function testAlterTableColumnComments() { - $tableDiff = new TableDiff('mytable'); - $tableDiff->addedColumns['quota'] = new \Doctrine\DBAL\Schema\Column('quota', \Doctrine\DBAL\Types\Type::getType('integer'), array('comment' => 'A comment')); - $tableDiff->changedColumns['foo'] = new \Doctrine\DBAL\Schema\ColumnDiff( - 'foo', new \Doctrine\DBAL\Schema\Column( - 'foo', \Doctrine\DBAL\Types\Type::getType('string') + $tableDiff = new TableDiff('mytable'); + $tableDiff->addedColumns['quota'] = new Column('quota', Type::getType('integer'), ['comment' => 'A comment']); + $tableDiff->changedColumns['foo'] = new ColumnDiff( + 'foo', + new Column( + 'foo', + Type::getType('string') ), - array('comment') + ['comment'] ); - $tableDiff->changedColumns['bar'] = new \Doctrine\DBAL\Schema\ColumnDiff( - 'bar', new \Doctrine\DBAL\Schema\Column( - 'baz', \Doctrine\DBAL\Types\Type::getType('string'), array('comment' => 'B comment') + $tableDiff->changedColumns['bar'] = new ColumnDiff( + 'bar', + new Column( + 'baz', + Type::getType('string'), + ['comment' => 'B comment'] ), - array('comment') + ['comment'] ); self::assertEquals($this->getAlterTableColumnCommentsSQL(), $this->_platform->getAlterTableSQL($tableDiff)); @@ -506,7 +517,7 @@ public function testCreateTableColumnTypeComments() $table = new Table('test'); $table->addColumn('id', 'integer'); $table->addColumn('data', 'array'); - $table->setPrimaryKey(array('id')); + $table->setPrimaryKey(['id']); self::assertEquals($this->getCreateTableColumnTypeCommentsSQL(), $this->_platform->getCreateTableSQL($table)); } @@ -529,10 +540,10 @@ public function getCreateTableColumnTypeCommentsSQL() public function testGetDefaultValueDeclarationSQL() { // non-timestamp value will get single quotes - $field = array( + $field = [ 'type' => Type::getType('string'), - 'default' => 'non_timestamp' - ); + 'default' => 'non_timestamp', + ]; self::assertEquals(" DEFAULT 'non_timestamp'", $this->_platform->getDefaultValueDeclarationSQL($field)); } @@ -558,11 +569,11 @@ public function testGetDefaultValueDeclarationSQLDateTime() : void public function testGetDefaultValueDeclarationSQLForIntegerTypes() { - foreach(array('bigint', 'integer', 'smallint') as $type) { - $field = array( + foreach (['bigint', 'integer', 'smallint'] as $type) { + $field = [ 'type' => Type::getType($type), - 'default' => 1 - ); + 'default' => 1, + ]; self::assertEquals( ' DEFAULT 1', @@ -608,7 +619,7 @@ public function testQuotedColumnInPrimaryKeyPropagation() { $table = new Table('`quoted`'); $table->addColumn('create', 'string'); - $table->setPrimaryKey(array('create')); + $table->setPrimaryKey(['create']); $sql = $this->_platform->getCreateTableSQL($table); self::assertEquals($this->getQuotedColumnInPrimaryKeySQL(), $sql); @@ -626,7 +637,7 @@ public function testQuotedColumnInIndexPropagation() { $table = new Table('`quoted`'); $table->addColumn('create', 'string'); - $table->addIndex(array('create')); + $table->addIndex(['create']); $sql = $this->_platform->getCreateTableSQL($table); self::assertEquals($this->getQuotedColumnInIndexSQL(), $sql); @@ -636,7 +647,7 @@ public function testQuotedNameInIndexSQL() { $table = new Table('test'); $table->addColumn('column1', 'string'); - $table->addIndex(array('column1'), '`key`'); + $table->addIndex(['column1'], '`key`'); $sql = $this->_platform->getCreateTableSQL($table); self::assertEquals($this->getQuotedNameInIndexSQL(), $sql); @@ -658,7 +669,7 @@ public function testQuotedColumnInForeignKeyPropagation() $foreignTable->addColumn('bar', 'string'); // Foreign column with non-reserved keyword as name (does not need quotation). $foreignTable->addColumn('`foo-bar`', 'string'); // Foreign table with special character in name (needs quotation on some platforms, e.g. Sqlite). - $table->addForeignKeyConstraint($foreignTable, array('create', 'foo', '`bar`'), array('create', 'bar', '`foo-bar`'), array(), 'FK_WITH_RESERVED_KEYWORD'); + $table->addForeignKeyConstraint($foreignTable, ['create', 'foo', '`bar`'], ['create', 'bar', '`foo-bar`'], [], 'FK_WITH_RESERVED_KEYWORD'); // Foreign table with non-reserved keyword as name (does not need quotation). $foreignTable = new Table('foo'); @@ -666,7 +677,7 @@ public function testQuotedColumnInForeignKeyPropagation() $foreignTable->addColumn('bar', 'string'); // Foreign column with non-reserved keyword as name (does not need quotation). $foreignTable->addColumn('`foo-bar`', 'string'); // Foreign table with special character in name (needs quotation on some platforms, e.g. Sqlite). - $table->addForeignKeyConstraint($foreignTable, array('create', 'foo', '`bar`'), array('create', 'bar', '`foo-bar`'), array(), 'FK_WITH_NON_RESERVED_KEYWORD'); + $table->addForeignKeyConstraint($foreignTable, ['create', 'foo', '`bar`'], ['create', 'bar', '`foo-bar`'], [], 'FK_WITH_NON_RESERVED_KEYWORD'); // Foreign table with special character in name (needs quotation on some platforms, e.g. Sqlite). $foreignTable = new Table('`foo-bar`'); @@ -674,7 +685,7 @@ public function testQuotedColumnInForeignKeyPropagation() $foreignTable->addColumn('bar', 'string'); // Foreign column with non-reserved keyword as name (does not need quotation). $foreignTable->addColumn('`foo-bar`', 'string'); // Foreign table with special character in name (needs quotation on some platforms, e.g. Sqlite). - $table->addForeignKeyConstraint($foreignTable, array('create', 'foo', '`bar`'), array('create', 'bar', '`foo-bar`'), array(), 'FK_WITH_INTENDED_QUOTATION'); + $table->addForeignKeyConstraint($foreignTable, ['create', 'foo', '`bar`'], ['create', 'bar', '`foo-bar`'], [], 'FK_WITH_INTENDED_QUOTATION'); $sql = $this->_platform->getCreateTableSQL($table, AbstractPlatform::CREATE_FOREIGNKEYS); self::assertEquals($this->getQuotedColumnInForeignKeySQL(), $sql); @@ -685,7 +696,7 @@ public function testQuotedColumnInForeignKeyPropagation() */ public function testQuotesReservedKeywordInUniqueConstraintDeclarationSQL() { - $index = new Index('select', array('foo'), true); + $index = new Index('select', ['foo'], true); self::assertSame( $this->getQuotesReservedKeywordInUniqueConstraintDeclarationSQL(), @@ -719,7 +730,7 @@ abstract protected function getQuotesReservedKeywordInTruncateTableSQL(); */ public function testQuotesReservedKeywordInIndexDeclarationSQL() { - $index = new Index('select', array('foo')); + $index = new Index('select', ['foo']); if (! $this->supportsInlineIndexDeclaration()) { $this->expectException('Doctrine\DBAL\DBALException'); @@ -770,13 +781,15 @@ public function testGetCreateSchemaSQL() */ public function testAlterTableChangeQuotedColumn() { - $tableDiff = new \Doctrine\DBAL\Schema\TableDiff('mytable'); - $tableDiff->fromTable = new \Doctrine\DBAL\Schema\Table('mytable'); - $tableDiff->changedColumns['foo'] = new \Doctrine\DBAL\Schema\ColumnDiff( - 'select', new \Doctrine\DBAL\Schema\Column( - 'select', \Doctrine\DBAL\Types\Type::getType('string') + $tableDiff = new TableDiff('mytable'); + $tableDiff->fromTable = new Table('mytable'); + $tableDiff->changedColumns['foo'] = new ColumnDiff( + 'select', + new Column( + 'select', + Type::getType('string') ), - array('type') + ['type'] ); self::assertContains( @@ -827,7 +840,7 @@ protected function getBinaryMaxLength() */ public function testReturnsBinaryTypeDeclarationSQL() { - $this->_platform->getBinaryTypeDeclarationSQL(array()); + $this->_platform->getBinaryTypeDeclarationSQL([]); } public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() @@ -848,11 +861,11 @@ public function hasNativeJsonType() */ public function testReturnsJsonTypeDeclarationSQL() { - $column = array( + $column = [ 'length' => 666, 'notnull' => true, 'type' => Type::getType('json_array'), - ); + ]; self::assertSame( $this->_platform->getClobTypeDeclarationSQL($column), @@ -865,13 +878,13 @@ public function testReturnsJsonTypeDeclarationSQL() */ public function testAlterTableRenameIndex() { - $tableDiff = new TableDiff('mytable'); + $tableDiff = new TableDiff('mytable'); $tableDiff->fromTable = new Table('mytable'); $tableDiff->fromTable->addColumn('id', 'integer'); - $tableDiff->fromTable->setPrimaryKey(array('id')); - $tableDiff->renamedIndexes = array( - 'idx_foo' => new Index('idx_bar', array('id')) - ); + $tableDiff->fromTable->setPrimaryKey(['id']); + $tableDiff->renamedIndexes = [ + 'idx_foo' => new Index('idx_bar', ['id']), + ]; self::assertSame( $this->getAlterTableRenameIndexSQL(), @@ -884,10 +897,10 @@ public function testAlterTableRenameIndex() */ protected function getAlterTableRenameIndexSQL() { - return array( + return [ 'DROP INDEX idx_foo', 'CREATE INDEX idx_bar ON mytable (id)', - ); + ]; } /** @@ -895,14 +908,14 @@ protected function getAlterTableRenameIndexSQL() */ public function testQuotesAlterTableRenameIndex() { - $tableDiff = new TableDiff('table'); + $tableDiff = new TableDiff('table'); $tableDiff->fromTable = new Table('table'); $tableDiff->fromTable->addColumn('id', 'integer'); - $tableDiff->fromTable->setPrimaryKey(array('id')); - $tableDiff->renamedIndexes = array( - 'create' => new Index('select', array('id')), - '`foo`' => new Index('`bar`', array('id')), - ); + $tableDiff->fromTable->setPrimaryKey(['id']); + $tableDiff->renamedIndexes = [ + 'create' => new Index('select', ['id']), + '`foo`' => new Index('`bar`', ['id']), + ]; self::assertSame( $this->getQuotedAlterTableRenameIndexSQL(), @@ -915,12 +928,12 @@ public function testQuotesAlterTableRenameIndex() */ protected function getQuotedAlterTableRenameIndexSQL() { - return array( + return [ 'DROP INDEX "create"', 'CREATE INDEX "select" ON "table" (id)', 'DROP INDEX "foo"', 'CREATE INDEX "bar" ON "table" (id)', - ); + ]; } /** @@ -930,31 +943,31 @@ public function testQuotesAlterTableRenameColumn() { $fromTable = new Table('mytable'); - $fromTable->addColumn('unquoted1', 'integer', array('comment' => 'Unquoted 1')); - $fromTable->addColumn('unquoted2', 'integer', array('comment' => 'Unquoted 2')); - $fromTable->addColumn('unquoted3', 'integer', array('comment' => 'Unquoted 3')); + $fromTable->addColumn('unquoted1', 'integer', ['comment' => 'Unquoted 1']); + $fromTable->addColumn('unquoted2', 'integer', ['comment' => 'Unquoted 2']); + $fromTable->addColumn('unquoted3', 'integer', ['comment' => 'Unquoted 3']); - $fromTable->addColumn('create', 'integer', array('comment' => 'Reserved keyword 1')); - $fromTable->addColumn('table', 'integer', array('comment' => 'Reserved keyword 2')); - $fromTable->addColumn('select', 'integer', array('comment' => 'Reserved keyword 3')); + $fromTable->addColumn('create', 'integer', ['comment' => 'Reserved keyword 1']); + $fromTable->addColumn('table', 'integer', ['comment' => 'Reserved keyword 2']); + $fromTable->addColumn('select', 'integer', ['comment' => 'Reserved keyword 3']); - $fromTable->addColumn('`quoted1`', 'integer', array('comment' => 'Quoted 1')); - $fromTable->addColumn('`quoted2`', 'integer', array('comment' => 'Quoted 2')); - $fromTable->addColumn('`quoted3`', 'integer', array('comment' => 'Quoted 3')); + $fromTable->addColumn('`quoted1`', 'integer', ['comment' => 'Quoted 1']); + $fromTable->addColumn('`quoted2`', 'integer', ['comment' => 'Quoted 2']); + $fromTable->addColumn('`quoted3`', 'integer', ['comment' => 'Quoted 3']); $toTable = new Table('mytable'); - $toTable->addColumn('unquoted', 'integer', array('comment' => 'Unquoted 1')); // unquoted -> unquoted - $toTable->addColumn('where', 'integer', array('comment' => 'Unquoted 2')); // unquoted -> reserved keyword - $toTable->addColumn('`foo`', 'integer', array('comment' => 'Unquoted 3')); // unquoted -> quoted + $toTable->addColumn('unquoted', 'integer', ['comment' => 'Unquoted 1']); // unquoted -> unquoted + $toTable->addColumn('where', 'integer', ['comment' => 'Unquoted 2']); // unquoted -> reserved keyword + $toTable->addColumn('`foo`', 'integer', ['comment' => 'Unquoted 3']); // unquoted -> quoted - $toTable->addColumn('reserved_keyword', 'integer', array('comment' => 'Reserved keyword 1')); // reserved keyword -> unquoted - $toTable->addColumn('from', 'integer', array('comment' => 'Reserved keyword 2')); // reserved keyword -> reserved keyword - $toTable->addColumn('`bar`', 'integer', array('comment' => 'Reserved keyword 3')); // reserved keyword -> quoted + $toTable->addColumn('reserved_keyword', 'integer', ['comment' => 'Reserved keyword 1']); // reserved keyword -> unquoted + $toTable->addColumn('from', 'integer', ['comment' => 'Reserved keyword 2']); // reserved keyword -> reserved keyword + $toTable->addColumn('`bar`', 'integer', ['comment' => 'Reserved keyword 3']); // reserved keyword -> quoted - $toTable->addColumn('quoted', 'integer', array('comment' => 'Quoted 1')); // quoted -> unquoted - $toTable->addColumn('and', 'integer', array('comment' => 'Quoted 2')); // quoted -> reserved keyword - $toTable->addColumn('`baz`', 'integer', array('comment' => 'Quoted 3')); // quoted -> quoted + $toTable->addColumn('quoted', 'integer', ['comment' => 'Quoted 1']); // quoted -> unquoted + $toTable->addColumn('and', 'integer', ['comment' => 'Quoted 2']); // quoted -> reserved keyword + $toTable->addColumn('`baz`', 'integer', ['comment' => 'Quoted 3']); // quoted -> quoted $comparator = new Comparator(); @@ -980,23 +993,23 @@ public function testQuotesAlterTableChangeColumnLength() { $fromTable = new Table('mytable'); - $fromTable->addColumn('unquoted1', 'string', array('comment' => 'Unquoted 1', 'length' => 10)); - $fromTable->addColumn('unquoted2', 'string', array('comment' => 'Unquoted 2', 'length' => 10)); - $fromTable->addColumn('unquoted3', 'string', array('comment' => 'Unquoted 3', 'length' => 10)); + $fromTable->addColumn('unquoted1', 'string', ['comment' => 'Unquoted 1', 'length' => 10]); + $fromTable->addColumn('unquoted2', 'string', ['comment' => 'Unquoted 2', 'length' => 10]); + $fromTable->addColumn('unquoted3', 'string', ['comment' => 'Unquoted 3', 'length' => 10]); - $fromTable->addColumn('create', 'string', array('comment' => 'Reserved keyword 1', 'length' => 10)); - $fromTable->addColumn('table', 'string', array('comment' => 'Reserved keyword 2', 'length' => 10)); - $fromTable->addColumn('select', 'string', array('comment' => 'Reserved keyword 3', 'length' => 10)); + $fromTable->addColumn('create', 'string', ['comment' => 'Reserved keyword 1', 'length' => 10]); + $fromTable->addColumn('table', 'string', ['comment' => 'Reserved keyword 2', 'length' => 10]); + $fromTable->addColumn('select', 'string', ['comment' => 'Reserved keyword 3', 'length' => 10]); $toTable = new Table('mytable'); - $toTable->addColumn('unquoted1', 'string', array('comment' => 'Unquoted 1', 'length' => 255)); - $toTable->addColumn('unquoted2', 'string', array('comment' => 'Unquoted 2', 'length' => 255)); - $toTable->addColumn('unquoted3', 'string', array('comment' => 'Unquoted 3', 'length' => 255)); + $toTable->addColumn('unquoted1', 'string', ['comment' => 'Unquoted 1', 'length' => 255]); + $toTable->addColumn('unquoted2', 'string', ['comment' => 'Unquoted 2', 'length' => 255]); + $toTable->addColumn('unquoted3', 'string', ['comment' => 'Unquoted 3', 'length' => 255]); - $toTable->addColumn('create', 'string', array('comment' => 'Reserved keyword 1', 'length' => 255)); - $toTable->addColumn('table', 'string', array('comment' => 'Reserved keyword 2', 'length' => 255)); - $toTable->addColumn('select', 'string', array('comment' => 'Reserved keyword 3', 'length' => 255)); + $toTable->addColumn('create', 'string', ['comment' => 'Reserved keyword 1', 'length' => 255]); + $toTable->addColumn('table', 'string', ['comment' => 'Reserved keyword 2', 'length' => 255]); + $toTable->addColumn('select', 'string', ['comment' => 'Reserved keyword 3', 'length' => 255]); $comparator = new Comparator(); @@ -1020,13 +1033,13 @@ abstract protected function getQuotedAlterTableChangeColumnLengthSQL(); */ public function testAlterTableRenameIndexInSchema() { - $tableDiff = new TableDiff('myschema.mytable'); + $tableDiff = new TableDiff('myschema.mytable'); $tableDiff->fromTable = new Table('myschema.mytable'); $tableDiff->fromTable->addColumn('id', 'integer'); - $tableDiff->fromTable->setPrimaryKey(array('id')); - $tableDiff->renamedIndexes = array( - 'idx_foo' => new Index('idx_bar', array('id')) - ); + $tableDiff->fromTable->setPrimaryKey(['id']); + $tableDiff->renamedIndexes = [ + 'idx_foo' => new Index('idx_bar', ['id']), + ]; self::assertSame( $this->getAlterTableRenameIndexInSchemaSQL(), @@ -1039,10 +1052,10 @@ public function testAlterTableRenameIndexInSchema() */ protected function getAlterTableRenameIndexInSchemaSQL() { - return array( + return [ 'DROP INDEX idx_foo', 'CREATE INDEX idx_bar ON myschema.mytable (id)', - ); + ]; } /** @@ -1050,14 +1063,14 @@ protected function getAlterTableRenameIndexInSchemaSQL() */ public function testQuotesAlterTableRenameIndexInSchema() { - $tableDiff = new TableDiff('`schema`.table'); + $tableDiff = new TableDiff('`schema`.table'); $tableDiff->fromTable = new Table('`schema`.table'); $tableDiff->fromTable->addColumn('id', 'integer'); - $tableDiff->fromTable->setPrimaryKey(array('id')); - $tableDiff->renamedIndexes = array( - 'create' => new Index('select', array('id')), - '`foo`' => new Index('`bar`', array('id')), - ); + $tableDiff->fromTable->setPrimaryKey(['id']); + $tableDiff->renamedIndexes = [ + 'create' => new Index('select', ['id']), + '`foo`' => new Index('`bar`', ['id']), + ]; self::assertSame( $this->getQuotedAlterTableRenameIndexInSchemaSQL(), @@ -1070,12 +1083,12 @@ public function testQuotesAlterTableRenameIndexInSchema() */ protected function getQuotedAlterTableRenameIndexInSchemaSQL() { - return array( + return [ 'DROP INDEX "schema"."create"', 'CREATE INDEX "select" ON "schema"."table" (id)', 'DROP INDEX "schema"."foo"', 'CREATE INDEX "bar" ON "schema"."table" (id)', - ); + ]; } /** @@ -1089,11 +1102,11 @@ public function testQuotesDropForeignKeySQL() ); } - $tableName = 'table'; - $table = new Table($tableName); + $tableName = 'table'; + $table = new Table($tableName); $foreignKeyName = 'select'; - $foreignKey = new ForeignKeyConstraint(array(), 'foo', array(), 'select'); - $expectedSql = $this->getQuotesDropForeignKeySQL(); + $foreignKey = new ForeignKeyConstraint([], 'foo', [], 'select'); + $expectedSql = $this->getQuotesDropForeignKeySQL(); self::assertSame($expectedSql, $this->_platform->getDropForeignKeySQL($foreignKeyName, $tableName)); self::assertSame($expectedSql, $this->_platform->getDropForeignKeySQL($foreignKey, $table)); @@ -1109,11 +1122,11 @@ protected function getQuotesDropForeignKeySQL() */ public function testQuotesDropConstraintSQL() { - $tableName = 'table'; - $table = new Table($tableName); + $tableName = 'table'; + $table = new Table($tableName); $constraintName = 'select'; - $constraint = new ForeignKeyConstraint(array(), 'foo', array(), 'select'); - $expectedSql = $this->getQuotesDropConstraintSQL(); + $constraint = new ForeignKeyConstraint([], 'foo', [], 'select'); + $expectedSql = $this->getQuotesDropConstraintSQL(); self::assertSame($expectedSql, $this->_platform->getDropConstraintSQL($constraintName, $tableName)); self::assertSame($expectedSql, $this->_platform->getDropConstraintSQL($constraint, $table)); @@ -1158,14 +1171,14 @@ public function testGetCommentOnColumnSQLWithQuoteCharacter() self::assertEquals( $this->getQuotedCommentOnColumnSQLWithQuoteCharacter(), - $this->_platform->getCommentOnColumnSQL('mytable', 'id', "It" . $c . "s a quote !") + $this->_platform->getCommentOnColumnSQL('mytable', 'id', 'It' . $c . 's a quote !') ); } /** - * @return array - * * @see testGetCommentOnColumnSQL + * + * @return array */ abstract protected function getCommentOnColumnSQL(); @@ -1176,17 +1189,16 @@ public function testGetCommentOnColumnSQL() { self::assertSame( $this->getCommentOnColumnSQL(), - array( + [ $this->_platform->getCommentOnColumnSQL('foo', 'bar', 'comment'), // regular identifiers $this->_platform->getCommentOnColumnSQL('`Foo`', '`BAR`', 'comment'), // explicitly quoted identifiers $this->_platform->getCommentOnColumnSQL('select', 'from', 'comment'), // reserved keyword identifiers - ) + ] ); } /** * @group DBAL-1176 - * * @dataProvider getGeneratesInlineColumnCommentSQL */ public function testGeneratesInlineColumnCommentSQL($comment, $expectedSql) @@ -1200,17 +1212,17 @@ public function testGeneratesInlineColumnCommentSQL($comment, $expectedSql) public function getGeneratesInlineColumnCommentSQL() { - return array( - 'regular comment' => array('Regular comment', $this->getInlineColumnRegularCommentSQL()), - 'comment requiring escaping' => array( + return [ + 'regular comment' => ['Regular comment', $this->getInlineColumnRegularCommentSQL()], + 'comment requiring escaping' => [ sprintf( 'Using inline comment delimiter %s works', $this->getInlineColumnCommentDelimiter() ), - $this->getInlineColumnCommentRequiringEscapingSQL() - ), - 'empty comment' => array('', $this->getInlineColumnEmptyCommentSQL()), - ); + $this->getInlineColumnCommentRequiringEscapingSQL(), + ], + 'empty comment' => ['', $this->getInlineColumnEmptyCommentSQL()], + ]; } protected function getInlineColumnCommentDelimiter() @@ -1284,12 +1296,11 @@ public function testQuoteStringLiteral() /** * @group DBAL-423 - * * @expectedException \Doctrine\DBAL\DBALException */ public function testReturnsGuidTypeDeclarationSQL() { - $this->_platform->getGuidTypeDeclarationSQL(array()); + $this->_platform->getGuidTypeDeclarationSQL([]); } /** @@ -1301,15 +1312,15 @@ public function testGeneratesAlterTableRenameColumnSQL() $table->addColumn( 'bar', 'integer', - array('notnull' => true, 'default' => 666, 'comment' => 'rename test') + ['notnull' => true, 'default' => 666, 'comment' => 'rename test'] ); - $tableDiff = new TableDiff('foo'); - $tableDiff->fromTable = $table; + $tableDiff = new TableDiff('foo'); + $tableDiff->fromTable = $table; $tableDiff->renamedColumns['bar'] = new Column( 'baz', Type::getType('integer'), - array('notnull' => true, 'default' => 666, 'comment' => 'rename test') + ['notnull' => true, 'default' => 666, 'comment' => 'rename test'] ); self::assertSame($this->getAlterTableRenameColumnSQL(), $this->_platform->getAlterTableSQL($tableDiff)); @@ -1332,24 +1343,24 @@ public function testQuotesTableIdentifiersInAlterTableSQL() $table->addColumn('fk3', 'integer'); $table->addColumn('bar', 'integer'); $table->addColumn('baz', 'integer'); - $table->addForeignKeyConstraint('fk_table', array('fk'), array('id'), array(), 'fk1'); - $table->addForeignKeyConstraint('fk_table', array('fk2'), array('id'), array(), 'fk2'); + $table->addForeignKeyConstraint('fk_table', ['fk'], ['id'], [], 'fk1'); + $table->addForeignKeyConstraint('fk_table', ['fk2'], ['id'], [], 'fk2'); - $tableDiff = new TableDiff('"foo"'); - $tableDiff->fromTable = $table; - $tableDiff->newName = 'table'; - $tableDiff->addedColumns['bloo'] = new Column('bloo', Type::getType('integer')); + $tableDiff = new TableDiff('"foo"'); + $tableDiff->fromTable = $table; + $tableDiff->newName = 'table'; + $tableDiff->addedColumns['bloo'] = new Column('bloo', Type::getType('integer')); $tableDiff->changedColumns['bar'] = new ColumnDiff( 'bar', - new Column('bar', Type::getType('integer'), array('notnull' => false)), - array('notnull'), + new Column('bar', Type::getType('integer'), ['notnull' => false]), + ['notnull'], $table->getColumn('bar') ); - $tableDiff->renamedColumns['id'] = new Column('war', Type::getType('integer')); + $tableDiff->renamedColumns['id'] = new Column('war', Type::getType('integer')); $tableDiff->removedColumns['baz'] = new Column('baz', Type::getType('integer')); - $tableDiff->addedForeignKeys[] = new ForeignKeyConstraint(array('fk3'), 'fk_table', array('id'), 'fk_add'); - $tableDiff->changedForeignKeys[] = new ForeignKeyConstraint(array('fk2'), 'fk_table2', array('id'), 'fk2'); - $tableDiff->removedForeignKeys[] = new ForeignKeyConstraint(array('fk'), 'fk_table', array('id'), 'fk1'); + $tableDiff->addedForeignKeys[] = new ForeignKeyConstraint(['fk3'], 'fk_table', ['id'], 'fk_add'); + $tableDiff->changedForeignKeys[] = new ForeignKeyConstraint(['fk2'], 'fk_table2', ['id'], 'fk2'); + $tableDiff->removedForeignKeys[] = new ForeignKeyConstraint(['fk'], 'fk_table', ['id'], 'fk1'); self::assertSame( $this->getQuotesTableIdentifiersInAlterTableSQL(), @@ -1367,18 +1378,20 @@ abstract protected function getQuotesTableIdentifiersInAlterTableSQL(); */ public function testAlterStringToFixedString() { - $table = new Table('mytable'); - $table->addColumn('name', 'string', array('length' => 2)); + $table->addColumn('name', 'string', ['length' => 2]); - $tableDiff = new TableDiff('mytable'); + $tableDiff = new TableDiff('mytable'); $tableDiff->fromTable = $table; - $tableDiff->changedColumns['name'] = new \Doctrine\DBAL\Schema\ColumnDiff( - 'name', new \Doctrine\DBAL\Schema\Column( - 'name', \Doctrine\DBAL\Types\Type::getType('string'), array('fixed' => true, 'length' => 2) + $tableDiff->changedColumns['name'] = new ColumnDiff( + 'name', + new Column( + 'name', + Type::getType('string'), + ['fixed' => true, 'length' => 2] ), - array('fixed') + ['fixed'] ); $sql = $this->_platform->getAlterTableSQL($tableDiff); @@ -1400,20 +1413,20 @@ public function testGeneratesAlterTableRenameIndexUsedByForeignKeySQL() { $foreignTable = new Table('foreign_table'); $foreignTable->addColumn('id', 'integer'); - $foreignTable->setPrimaryKey(array('id')); + $foreignTable->setPrimaryKey(['id']); $primaryTable = new Table('mytable'); $primaryTable->addColumn('foo', 'integer'); $primaryTable->addColumn('bar', 'integer'); $primaryTable->addColumn('baz', 'integer'); - $primaryTable->addIndex(array('foo'), 'idx_foo'); - $primaryTable->addIndex(array('bar'), 'idx_bar'); - $primaryTable->addForeignKeyConstraint($foreignTable, array('foo'), array('id'), array(), 'fk_foo'); - $primaryTable->addForeignKeyConstraint($foreignTable, array('bar'), array('id'), array(), 'fk_bar'); + $primaryTable->addIndex(['foo'], 'idx_foo'); + $primaryTable->addIndex(['bar'], 'idx_bar'); + $primaryTable->addForeignKeyConstraint($foreignTable, ['foo'], ['id'], [], 'fk_foo'); + $primaryTable->addForeignKeyConstraint($foreignTable, ['bar'], ['id'], [], 'fk_bar'); - $tableDiff = new TableDiff('mytable'); - $tableDiff->fromTable = $primaryTable; - $tableDiff->renamedIndexes['idx_foo'] = new Index('idx_foo_renamed', array('foo')); + $tableDiff = new TableDiff('mytable'); + $tableDiff->fromTable = $primaryTable; + $tableDiff->renamedIndexes['idx_foo'] = new Index('idx_foo_renamed', ['foo']); self::assertSame( $this->getGeneratesAlterTableRenameIndexUsedByForeignKeySQL(), @@ -1428,7 +1441,6 @@ abstract protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL /** * @group DBAL-1082 - * * @dataProvider getGeneratesDecimalTypeDeclarationSQL */ public function testGeneratesDecimalTypeDeclarationSQL(array $column, $expectedSql) @@ -1441,19 +1453,18 @@ public function testGeneratesDecimalTypeDeclarationSQL(array $column, $expectedS */ public function getGeneratesDecimalTypeDeclarationSQL() { - return array( - array(array(), 'NUMERIC(10, 0)'), - array(array('unsigned' => true), 'NUMERIC(10, 0)'), - array(array('unsigned' => false), 'NUMERIC(10, 0)'), - array(array('precision' => 5), 'NUMERIC(5, 0)'), - array(array('scale' => 5), 'NUMERIC(10, 5)'), - array(array('precision' => 8, 'scale' => 2), 'NUMERIC(8, 2)'), - ); + return [ + [[], 'NUMERIC(10, 0)'], + [['unsigned' => true], 'NUMERIC(10, 0)'], + [['unsigned' => false], 'NUMERIC(10, 0)'], + [['precision' => 5], 'NUMERIC(5, 0)'], + [['scale' => 5], 'NUMERIC(10, 5)'], + [['precision' => 8, 'scale' => 2], 'NUMERIC(8, 2)'], + ]; } /** * @group DBAL-1082 - * * @dataProvider getGeneratesFloatDeclarationSQL */ public function testGeneratesFloatDeclarationSQL(array $column, $expectedSql) @@ -1466,14 +1477,14 @@ public function testGeneratesFloatDeclarationSQL(array $column, $expectedSql) */ public function getGeneratesFloatDeclarationSQL() { - return array( - array(array(), 'DOUBLE PRECISION'), - array(array('unsigned' => true), 'DOUBLE PRECISION'), - array(array('unsigned' => false), 'DOUBLE PRECISION'), - array(array('precision' => 5), 'DOUBLE PRECISION'), - array(array('scale' => 5), 'DOUBLE PRECISION'), - array(array('precision' => 8, 'scale' => 2), 'DOUBLE PRECISION'), - ); + return [ + [[], 'DOUBLE PRECISION'], + [['unsigned' => true], 'DOUBLE PRECISION'], + [['unsigned' => false], 'DOUBLE PRECISION'], + [['precision' => 5], 'DOUBLE PRECISION'], + [['scale' => 5], 'DOUBLE PRECISION'], + [['precision' => 8, 'scale' => 2], 'DOUBLE PRECISION'], + ]; } public function testItEscapesStringsForLike() : void diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php index bca9063c55c..06b1604912b 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php @@ -3,7 +3,10 @@ namespace Doctrine\Tests\DBAL\Platforms; use Doctrine\DBAL\Schema\Column; +use Doctrine\DBAL\Schema\ColumnDiff; use Doctrine\DBAL\Schema\Comparator; +use Doctrine\DBAL\Schema\ForeignKeyConstraint; +use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\TransactionIsolationLevel; @@ -18,15 +21,15 @@ public function getGenerateTableSql() public function getGenerateTableWithMultiColumnUniqueIndexSql() { - return array( + return [ 'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL)', - 'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)' - ); + 'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)', + ]; } public function getGenerateAlterTableSql() { - return array( + return [ 'ALTER TABLE mytable ADD quota INT DEFAULT NULL', 'ALTER TABLE mytable DROP foo', 'ALTER TABLE mytable ALTER bar TYPE VARCHAR(255)', @@ -36,7 +39,7 @@ public function getGenerateAlterTableSql() "ALTER TABLE mytable ALTER bloo SET DEFAULT 'false'", 'ALTER TABLE mytable ALTER bloo SET NOT NULL', 'ALTER TABLE mytable RENAME TO userlist', - ); + ]; } public function getGenerateIndexSql() @@ -51,51 +54,75 @@ public function getGenerateForeignKeySql() public function testGeneratesForeignKeySqlForNonStandardOptions() { - $foreignKey = new \Doctrine\DBAL\Schema\ForeignKeyConstraint( - array('foreign_id'), 'my_table', array('id'), 'my_fk', array('onDelete' => 'CASCADE') + $foreignKey = new ForeignKeyConstraint( + ['foreign_id'], + 'my_table', + ['id'], + 'my_fk', + ['onDelete' => 'CASCADE'] ); self::assertEquals( - "CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE", + 'CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE', $this->_platform->getForeignKeyDeclarationSQL($foreignKey) ); - $foreignKey = new \Doctrine\DBAL\Schema\ForeignKeyConstraint( - array('foreign_id'), 'my_table', array('id'), 'my_fk', array('match' => 'full') + $foreignKey = new ForeignKeyConstraint( + ['foreign_id'], + 'my_table', + ['id'], + 'my_fk', + ['match' => 'full'] ); self::assertEquals( - "CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) MATCH full NOT DEFERRABLE INITIALLY IMMEDIATE", + 'CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) MATCH full NOT DEFERRABLE INITIALLY IMMEDIATE', $this->_platform->getForeignKeyDeclarationSQL($foreignKey) ); - $foreignKey = new \Doctrine\DBAL\Schema\ForeignKeyConstraint( - array('foreign_id'), 'my_table', array('id'), 'my_fk', array('deferrable' => true) + $foreignKey = new ForeignKeyConstraint( + ['foreign_id'], + 'my_table', + ['id'], + 'my_fk', + ['deferrable' => true] ); self::assertEquals( - "CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) DEFERRABLE INITIALLY IMMEDIATE", + 'CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) DEFERRABLE INITIALLY IMMEDIATE', $this->_platform->getForeignKeyDeclarationSQL($foreignKey) ); - $foreignKey = new \Doctrine\DBAL\Schema\ForeignKeyConstraint( - array('foreign_id'), 'my_table', array('id'), 'my_fk', array('deferred' => true) + $foreignKey = new ForeignKeyConstraint( + ['foreign_id'], + 'my_table', + ['id'], + 'my_fk', + ['deferred' => true] ); self::assertEquals( - "CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) NOT DEFERRABLE INITIALLY DEFERRED", + 'CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) NOT DEFERRABLE INITIALLY DEFERRED', $this->_platform->getForeignKeyDeclarationSQL($foreignKey) ); - $foreignKey = new \Doctrine\DBAL\Schema\ForeignKeyConstraint( - array('foreign_id'), 'my_table', array('id'), 'my_fk', array('feferred' => true) + $foreignKey = new ForeignKeyConstraint( + ['foreign_id'], + 'my_table', + ['id'], + 'my_fk', + ['feferred' => true] ); self::assertEquals( - "CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) NOT DEFERRABLE INITIALLY DEFERRED", + 'CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) NOT DEFERRABLE INITIALLY DEFERRED', $this->_platform->getForeignKeyDeclarationSQL($foreignKey) ); - $foreignKey = new \Doctrine\DBAL\Schema\ForeignKeyConstraint( - array('foreign_id'), 'my_table', array('id'), 'my_fk', array('deferrable' => true, 'deferred' => true, 'match' => 'full') + $foreignKey = new ForeignKeyConstraint( + ['foreign_id'], + 'my_table', + ['id'], + 'my_fk', + ['deferrable' => true, 'deferred' => true, 'match' => 'full'] ); self::assertEquals( - "CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) MATCH full DEFERRABLE INITIALLY DEFERRED", + 'CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) MATCH full DEFERRABLE INITIALLY DEFERRED', $this->_platform->getForeignKeyDeclarationSQL($foreignKey) ); } @@ -138,11 +165,11 @@ public function testGeneratesDDLSnippets() public function testGenerateTableWithAutoincrement() { - $table = new \Doctrine\DBAL\Schema\Table('autoinc_table'); + $table = new Table('autoinc_table'); $column = $table->addColumn('id', 'integer'); $column->setAutoincrement(true); - self::assertEquals(array('CREATE TABLE autoinc_table (id SERIAL NOT NULL)'), $this->_platform->getCreateTableSQL($table)); + self::assertEquals(['CREATE TABLE autoinc_table (id SERIAL NOT NULL)'], $this->_platform->getCreateTableSQL($table)); } public static function serialTypes() : array @@ -159,7 +186,7 @@ public static function serialTypes() : array */ public function testGenerateTableWithAutoincrementDoesNotSetDefault(string $type, string $definition) : void { - $table = new \Doctrine\DBAL\Schema\Table('autoinc_table_notnull'); + $table = new Table('autoinc_table_notnull'); $column = $table->addColumn('id', $type); $column->setAutoIncrement(true); $column->setNotNull(false); @@ -175,7 +202,7 @@ public function testGenerateTableWithAutoincrementDoesNotSetDefault(string $type */ public function testCreateTableWithAutoincrementAndNotNullAddsConstraint(string $type, string $definition) : void { - $table = new \Doctrine\DBAL\Schema\Table('autoinc_table_notnull_enabled'); + $table = new Table('autoinc_table_notnull_enabled'); $column = $table->addColumn('id', $type); $column->setAutoIncrement(true); $column->setNotNull(true); @@ -206,17 +233,18 @@ public function testGeneratesTypeDeclarationForIntegers() { self::assertEquals( 'INT', - $this->_platform->getIntegerTypeDeclarationSQL(array()) + $this->_platform->getIntegerTypeDeclarationSQL([]) ); self::assertEquals( 'SERIAL', - $this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true) - )); + $this->_platform->getIntegerTypeDeclarationSQL(['autoincrement' => true]) + ); self::assertEquals( 'SERIAL', $this->_platform->getIntegerTypeDeclarationSQL( - array('autoincrement' => true, 'primary' => true) - )); + ['autoincrement' => true, 'primary' => true] + ) + ); } public function testGeneratesTypeDeclarationForStrings() @@ -224,16 +252,17 @@ public function testGeneratesTypeDeclarationForStrings() self::assertEquals( 'CHAR(10)', $this->_platform->getVarcharTypeDeclarationSQL( - array('length' => 10, 'fixed' => true)) + ['length' => 10, 'fixed' => true] + ) ); self::assertEquals( 'VARCHAR(50)', - $this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)), + $this->_platform->getVarcharTypeDeclarationSQL(['length' => 50]), 'Variable string declaration is not correct' ); self::assertEquals( 'VARCHAR(255)', - $this->_platform->getVarcharTypeDeclarationSQL(array()), + $this->_platform->getVarcharTypeDeclarationSQL([]), 'Long string declaration is not correct' ); } @@ -245,7 +274,7 @@ public function getGenerateUniqueIndexSql() public function testGeneratesSequenceSqlCommands() { - $sequence = new \Doctrine\DBAL\Schema\Sequence('myseq', 20, 1); + $sequence = new Sequence('myseq', 20, 1); self::assertEquals( 'CREATE SEQUENCE myseq INCREMENT BY 20 MINVALUE 1 START 1', $this->_platform->getCreateSequenceSQL($sequence) @@ -307,71 +336,69 @@ public function testModifyLimitQueryWithEmptyOffset() public function getCreateTableColumnCommentsSQL() { - return array( - "CREATE TABLE test (id INT NOT NULL, PRIMARY KEY(id))", + return [ + 'CREATE TABLE test (id INT NOT NULL, PRIMARY KEY(id))', "COMMENT ON COLUMN test.id IS 'This is a comment'", - ); + ]; } public function getAlterTableColumnCommentsSQL() { - return array( - "ALTER TABLE mytable ADD quota INT NOT NULL", + return [ + 'ALTER TABLE mytable ADD quota INT NOT NULL', "COMMENT ON COLUMN mytable.quota IS 'A comment'", - "COMMENT ON COLUMN mytable.foo IS NULL", + 'COMMENT ON COLUMN mytable.foo IS NULL', "COMMENT ON COLUMN mytable.baz IS 'B comment'", - ); + ]; } public function getCreateTableColumnTypeCommentsSQL() { - return array( - "CREATE TABLE test (id INT NOT NULL, data TEXT NOT NULL, PRIMARY KEY(id))", - "COMMENT ON COLUMN test.data IS '(DC2Type:array)'" - ); + return [ + 'CREATE TABLE test (id INT NOT NULL, data TEXT NOT NULL, PRIMARY KEY(id))', + "COMMENT ON COLUMN test.data IS '(DC2Type:array)'", + ]; } protected function getQuotedColumnInPrimaryKeySQL() { - return array( - 'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, PRIMARY KEY("create"))', - ); + return ['CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, PRIMARY KEY("create"))']; } protected function getQuotedColumnInIndexSQL() { - return array( + return [ 'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL)', 'CREATE INDEX IDX_22660D028FD6E0FB ON "quoted" ("create")', - ); + ]; } protected function getQuotedNameInIndexSQL() { - return array( + return [ 'CREATE TABLE test (column1 VARCHAR(255) NOT NULL)', 'CREATE INDEX "key" ON test (column1)', - ); + ]; } protected function getQuotedColumnInForeignKeySQL() { - return array( + return [ 'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, foo VARCHAR(255) NOT NULL, "bar" VARCHAR(255) NOT NULL)', 'ALTER TABLE "quoted" ADD CONSTRAINT FK_WITH_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES "foreign" ("create", bar, "foo-bar") NOT DEFERRABLE INITIALLY IMMEDIATE', 'ALTER TABLE "quoted" ADD CONSTRAINT FK_WITH_NON_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES foo ("create", bar, "foo-bar") NOT DEFERRABLE INITIALLY IMMEDIATE', 'ALTER TABLE "quoted" ADD CONSTRAINT FK_WITH_INTENDED_QUOTATION FOREIGN KEY ("create", foo, "bar") REFERENCES "foo-bar" ("create", bar, "foo-bar") NOT DEFERRABLE INITIALLY IMMEDIATE', - ); + ]; } /** - * @group DBAL-457 - * @dataProvider pgBooleanProvider - * * @param string $databaseValue * @param string $preparedStatementValue * @param int $integerValue * @param bool $booleanValue + * + * @group DBAL-457 + * @dataProvider pgBooleanProvider */ public function testConvertBooleanAsLiteralStrings( $databaseValue, @@ -400,21 +427,20 @@ public function testConvertBooleanAsLiteralIntegers() } /** - * @group DBAL-630 - * @dataProvider pgBooleanProvider - * * @param string $databaseValue * @param string $preparedStatementValue * @param int $integerValue * @param bool $booleanValue + * + * @group DBAL-630 + * @dataProvider pgBooleanProvider */ public function testConvertBooleanAsDatabaseValueStrings( $databaseValue, $preparedStatementValue, $integerValue, $booleanValue - ) - { + ) { $platform = $this->createPlatform(); self::assertSame($integerValue, $platform->convertBooleansToDatabaseValue($booleanValue)); @@ -433,12 +459,12 @@ public function testConvertBooleanAsDatabaseValueIntegers() } /** - * @dataProvider pgBooleanProvider - * * @param string $databaseValue * @param string $prepareStatementValue * @param int $integerValue * @param bool $booleanValue + * + * @dataProvider pgBooleanProvider */ public function testConvertFromBoolean($databaseValue, $prepareStatementValue, $integerValue, $booleanValue) { @@ -453,60 +479,71 @@ public function testConvertFromBoolean($databaseValue, $prepareStatementValue, $ */ public function testThrowsExceptionWithInvalidBooleanLiteral() { - $platform = $this->createPlatform()->convertBooleansToDatabaseValue("my-bool"); + $platform = $this->createPlatform()->convertBooleansToDatabaseValue('my-bool'); } public function testGetCreateSchemaSQL() { $schemaName = 'schema'; - $sql = $this->_platform->getCreateSchemaSQL($schemaName); + $sql = $this->_platform->getCreateSchemaSQL($schemaName); self::assertEquals('CREATE SCHEMA ' . $schemaName, $sql); } public function testAlterDecimalPrecisionScale() { - $table = new Table('mytable'); $table->addColumn('dfoo1', 'decimal'); - $table->addColumn('dfoo2', 'decimal', array('precision' => 10, 'scale' => 6)); - $table->addColumn('dfoo3', 'decimal', array('precision' => 10, 'scale' => 6)); - $table->addColumn('dfoo4', 'decimal', array('precision' => 10, 'scale' => 6)); + $table->addColumn('dfoo2', 'decimal', ['precision' => 10, 'scale' => 6]); + $table->addColumn('dfoo3', 'decimal', ['precision' => 10, 'scale' => 6]); + $table->addColumn('dfoo4', 'decimal', ['precision' => 10, 'scale' => 6]); - $tableDiff = new TableDiff('mytable'); + $tableDiff = new TableDiff('mytable'); $tableDiff->fromTable = $table; - $tableDiff->changedColumns['dloo1'] = new \Doctrine\DBAL\Schema\ColumnDiff( - 'dloo1', new \Doctrine\DBAL\Schema\Column( - 'dloo1', \Doctrine\DBAL\Types\Type::getType('decimal'), array('precision' => 16, 'scale' => 6) + $tableDiff->changedColumns['dloo1'] = new ColumnDiff( + 'dloo1', + new Column( + 'dloo1', + Type::getType('decimal'), + ['precision' => 16, 'scale' => 6] ), - array('precision') - ); - $tableDiff->changedColumns['dloo2'] = new \Doctrine\DBAL\Schema\ColumnDiff( - 'dloo2', new \Doctrine\DBAL\Schema\Column( - 'dloo2', \Doctrine\DBAL\Types\Type::getType('decimal'), array('precision' => 10, 'scale' => 4) + ['precision'] + ); + $tableDiff->changedColumns['dloo2'] = new ColumnDiff( + 'dloo2', + new Column( + 'dloo2', + Type::getType('decimal'), + ['precision' => 10, 'scale' => 4] ), - array('scale') - ); - $tableDiff->changedColumns['dloo3'] = new \Doctrine\DBAL\Schema\ColumnDiff( - 'dloo3', new \Doctrine\DBAL\Schema\Column( - 'dloo3', \Doctrine\DBAL\Types\Type::getType('decimal'), array('precision' => 10, 'scale' => 6) + ['scale'] + ); + $tableDiff->changedColumns['dloo3'] = new ColumnDiff( + 'dloo3', + new Column( + 'dloo3', + Type::getType('decimal'), + ['precision' => 10, 'scale' => 6] ), - array() - ); - $tableDiff->changedColumns['dloo4'] = new \Doctrine\DBAL\Schema\ColumnDiff( - 'dloo4', new \Doctrine\DBAL\Schema\Column( - 'dloo4', \Doctrine\DBAL\Types\Type::getType('decimal'), array('precision' => 16, 'scale' => 8) + [] + ); + $tableDiff->changedColumns['dloo4'] = new ColumnDiff( + 'dloo4', + new Column( + 'dloo4', + Type::getType('decimal'), + ['precision' => 16, 'scale' => 8] ), - array('precision', 'scale') + ['precision', 'scale'] ); $sql = $this->_platform->getAlterTableSQL($tableDiff); - $expectedSql = array( + $expectedSql = [ 'ALTER TABLE mytable ALTER dloo1 TYPE NUMERIC(16, 6)', 'ALTER TABLE mytable ALTER dloo2 TYPE NUMERIC(10, 4)', 'ALTER TABLE mytable ALTER dloo4 TYPE NUMERIC(16, 8)', - ); + ]; self::assertEquals($expectedSql, $sql); } @@ -518,22 +555,22 @@ public function testDroppingConstraintsBeforeColumns() { $newTable = new Table('mytable'); $newTable->addColumn('id', 'integer'); - $newTable->setPrimaryKey(array('id')); + $newTable->setPrimaryKey(['id']); $oldTable = clone $newTable; $oldTable->addColumn('parent_id', 'integer'); - $oldTable->addUnnamedForeignKeyConstraint('mytable', array('parent_id'), array('id')); + $oldTable->addUnnamedForeignKeyConstraint('mytable', ['parent_id'], ['id']); - $comparator = new \Doctrine\DBAL\Schema\Comparator(); - $tableDiff = $comparator->diffTable($oldTable, $newTable); + $comparator = new Comparator(); + $tableDiff = $comparator->diffTable($oldTable, $newTable); $sql = $this->_platform->getAlterTableSQL($tableDiff); - $expectedSql = array( + $expectedSql = [ 'ALTER TABLE mytable DROP CONSTRAINT FK_6B2BD609727ACA70', 'DROP INDEX IDX_6B2BD609727ACA70', 'ALTER TABLE mytable DROP parent_id', - ); + ]; self::assertEquals($expectedSql, $sql); } @@ -560,15 +597,15 @@ public function testReturnsIdentitySequenceName() */ public function testCreateSequenceWithCache($cacheSize, $expectedSql) { - $sequence = new \Doctrine\DBAL\Schema\Sequence('foo', 1, 1, $cacheSize); + $sequence = new Sequence('foo', 1, 1, $cacheSize); self::assertContains($expectedSql, $this->_platform->getCreateSequenceSQL($sequence)); } public function dataCreateSequenceWithCache() { - return array( - array(3, 'CACHE 3') - ); + return [ + [3, 'CACHE 3'], + ]; } protected function getBinaryDefaultLength() @@ -583,24 +620,24 @@ protected function getBinaryMaxLength() public function testReturnsBinaryTypeDeclarationSQL() { - self::assertSame('BYTEA', $this->_platform->getBinaryTypeDeclarationSQL(array())); - self::assertSame('BYTEA', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 0))); - self::assertSame('BYTEA', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 9999999))); + self::assertSame('BYTEA', $this->_platform->getBinaryTypeDeclarationSQL([])); + self::assertSame('BYTEA', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 0])); + self::assertSame('BYTEA', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 9999999])); - self::assertSame('BYTEA', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true))); - self::assertSame('BYTEA', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 0))); - self::assertSame('BYTEA', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 9999999))); + self::assertSame('BYTEA', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true])); + self::assertSame('BYTEA', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 0])); + self::assertSame('BYTEA', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 9999999])); } public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType() { $table1 = new Table('mytable'); $table1->addColumn('column_varbinary', 'binary'); - $table1->addColumn('column_binary', 'binary', array('fixed' => true)); + $table1->addColumn('column_binary', 'binary', ['fixed' => true]); $table1->addColumn('column_blob', 'blob'); $table2 = new Table('mytable'); - $table2->addColumn('column_varbinary', 'binary', array('fixed' => true)); + $table2->addColumn('column_varbinary', 'binary', ['fixed' => true]); $table2->addColumn('column_binary', 'binary'); $table2->addColumn('column_blob', 'binary'); @@ -612,9 +649,9 @@ public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType() self::assertEmpty($this->_platform->getAlterTableSQL($comparator->diffTable($table1, $table2))); $table2 = new Table('mytable'); - $table2->addColumn('column_varbinary', 'binary', array('length' => 42)); + $table2->addColumn('column_varbinary', 'binary', ['length' => 42]); $table2->addColumn('column_binary', 'blob'); - $table2->addColumn('column_blob', 'binary', array('length' => 11, 'fixed' => true)); + $table2->addColumn('column_blob', 'binary', ['length' => 11, 'fixed' => true]); // VARBINARY -> VARBINARY with changed length // BINARY -> BLOB @@ -623,7 +660,7 @@ public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType() $table2 = new Table('mytable'); $table2->addColumn('column_varbinary', 'blob'); - $table2->addColumn('column_binary', 'binary', array('length' => 42, 'fixed' => true)); + $table2->addColumn('column_binary', 'binary', ['length' => 42, 'fixed' => true]); $table2->addColumn('column_blob', 'blob'); // VARBINARY -> BLOB @@ -637,9 +674,7 @@ public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType() */ protected function getAlterTableRenameIndexSQL() { - return array( - 'ALTER INDEX idx_foo RENAME TO idx_bar', - ); + return ['ALTER INDEX idx_foo RENAME TO idx_bar']; } /** @@ -647,38 +682,39 @@ protected function getAlterTableRenameIndexSQL() */ protected function getQuotedAlterTableRenameIndexSQL() { - return array( + return [ 'ALTER INDEX "create" RENAME TO "select"', 'ALTER INDEX "foo" RENAME TO "bar"', - ); + ]; } /** * PostgreSQL boolean strings provider + * * @return array */ public function pgBooleanProvider() { - return array( + return [ // Database value, prepared statement value, boolean integer value, boolean value. - array(true, 'true', 1, true), - array('t', 'true', 1, true), - array('true', 'true', 1, true), - array('y', 'true', 1, true), - array('yes', 'true', 1, true), - array('on', 'true', 1, true), - array('1', 'true', 1, true), - - array(false, 'false', 0, false), - array('f', 'false', 0, false), - array('false', 'false', 0, false), - array( 'n', 'false', 0, false), - array('no', 'false', 0, false), - array('off', 'false', 0, false), - array('0', 'false', 0, false), - - array(null, 'NULL', null, null) - ); + [true, 'true', 1, true], + ['t', 'true', 1, true], + ['true', 'true', 1, true], + ['y', 'true', 1, true], + ['yes', 'true', 1, true], + ['on', 'true', 1, true], + ['1', 'true', 1, true], + + [false, 'false', 0, false], + ['f', 'false', 0, false], + ['false', 'false', 0, false], + [ 'n', 'false', 0, false], + ['no', 'false', 0, false], + ['off', 'false', 0, false], + ['0', 'false', 0, false], + + [null, 'NULL', null, null], + ]; } /** @@ -686,7 +722,7 @@ public function pgBooleanProvider() */ protected function getQuotedAlterTableRenameColumnSQL() { - return array( + return [ 'ALTER TABLE mytable RENAME COLUMN unquoted1 TO unquoted', 'ALTER TABLE mytable RENAME COLUMN unquoted2 TO "where"', 'ALTER TABLE mytable RENAME COLUMN unquoted3 TO "foo"', @@ -696,7 +732,7 @@ protected function getQuotedAlterTableRenameColumnSQL() 'ALTER TABLE mytable RENAME COLUMN quoted1 TO quoted', 'ALTER TABLE mytable RENAME COLUMN quoted2 TO "and"', 'ALTER TABLE mytable RENAME COLUMN quoted3 TO "baz"', - ); + ]; } /** @@ -704,14 +740,14 @@ protected function getQuotedAlterTableRenameColumnSQL() */ protected function getQuotedAlterTableChangeColumnLengthSQL() { - return array( + return [ 'ALTER TABLE mytable ALTER unquoted1 TYPE VARCHAR(255)', 'ALTER TABLE mytable ALTER unquoted2 TYPE VARCHAR(255)', 'ALTER TABLE mytable ALTER unquoted3 TYPE VARCHAR(255)', 'ALTER TABLE mytable ALTER "create" TYPE VARCHAR(255)', 'ALTER TABLE mytable ALTER "table" TYPE VARCHAR(255)', 'ALTER TABLE mytable ALTER "select" TYPE VARCHAR(255)', - ); + ]; } /** @@ -719,9 +755,7 @@ protected function getQuotedAlterTableChangeColumnLengthSQL() */ protected function getAlterTableRenameIndexInSchemaSQL() { - return array( - 'ALTER INDEX myschema.idx_foo RENAME TO idx_bar', - ); + return ['ALTER INDEX myschema.idx_foo RENAME TO idx_bar']; } /** @@ -729,10 +763,10 @@ protected function getAlterTableRenameIndexInSchemaSQL() */ protected function getQuotedAlterTableRenameIndexInSchemaSQL() { - return array( + return [ 'ALTER INDEX "schema"."create" RENAME TO "select"', 'ALTER INDEX "schema"."foo" RENAME TO "bar"', - ); + ]; } protected function getQuotesDropForeignKeySQL() @@ -743,7 +777,7 @@ protected function getQuotesDropForeignKeySQL() public function testGetNullCommentOnColumnSQL() { self::assertEquals( - "COMMENT ON COLUMN mytable.id IS NULL", + 'COMMENT ON COLUMN mytable.id IS NULL', $this->_platform->getCommentOnColumnSQL('mytable', 'id', null) ); } @@ -753,7 +787,7 @@ public function testGetNullCommentOnColumnSQL() */ public function testReturnsGuidTypeDeclarationSQL() { - self::assertSame('UUID', $this->_platform->getGuidTypeDeclarationSQL(array())); + self::assertSame('UUID', $this->_platform->getGuidTypeDeclarationSQL([])); } /** @@ -761,9 +795,7 @@ public function testReturnsGuidTypeDeclarationSQL() */ public function getAlterTableRenameColumnSQL() { - return array( - 'ALTER TABLE foo RENAME COLUMN bar TO baz', - ); + return ['ALTER TABLE foo RENAME COLUMN bar TO baz']; } /** @@ -771,7 +803,7 @@ public function getAlterTableRenameColumnSQL() */ protected function getQuotesTableIdentifiersInAlterTableSQL() { - return array( + return [ 'ALTER TABLE "foo" DROP CONSTRAINT fk1', 'ALTER TABLE "foo" DROP CONSTRAINT fk2', 'ALTER TABLE "foo" ADD bloo INT NOT NULL', @@ -783,7 +815,7 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() 'INITIALLY IMMEDIATE', 'ALTER TABLE "table" ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id) NOT DEFERRABLE ' . 'INITIALLY IMMEDIATE', - ); + ]; } /** @@ -791,11 +823,11 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() */ protected function getCommentOnColumnSQL() { - return array( + return [ 'COMMENT ON COLUMN foo.bar IS \'comment\'', 'COMMENT ON COLUMN "Foo"."BAR" IS \'comment\'', 'COMMENT ON COLUMN "select"."from" IS \'comment\'', - ); + ]; } /** @@ -803,8 +835,8 @@ protected function getCommentOnColumnSQL() */ public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() { - $table1 = new Table('"foo"', array(new Column('"bar"', Type::getType('integer')))); - $table2 = new Table('"foo"', array(new Column('"bar"', Type::getType('integer'), array('comment' => 'baz')))); + $table1 = new Table('"foo"', [new Column('"bar"', Type::getType('integer'))]); + $table2 = new Table('"foo"', [new Column('"bar"', Type::getType('integer'), ['comment' => 'baz'])]); $comparator = new Comparator(); @@ -812,9 +844,7 @@ public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); self::assertSame( - array( - 'COMMENT ON COLUMN "foo"."bar" IS \'baz\'', - ), + ['COMMENT ON COLUMN "foo"."bar" IS \'baz\''], $this->_platform->getAlterTableSQL($tableDiff) ); } @@ -848,9 +878,7 @@ protected function getQuotesReservedKeywordInTruncateTableSQL() */ protected function getAlterStringToFixedStringSQL() { - return array( - 'ALTER TABLE mytable ALTER name TYPE CHAR(2)', - ); + return ['ALTER TABLE mytable ALTER name TYPE CHAR(2)']; } /** @@ -858,9 +886,7 @@ protected function getAlterStringToFixedStringSQL() */ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() { - return array( - 'ALTER INDEX idx_foo RENAME TO idx_foo_renamed', - ); + return ['ALTER INDEX idx_foo RENAME TO idx_foo_renamed']; } /** diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php index 72864db1250..ef75fa7dfe6 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php @@ -2,8 +2,10 @@ namespace Doctrine\Tests\DBAL\Platforms; +use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ColumnDiff; +use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\TransactionIsolationLevel; @@ -19,15 +21,15 @@ public function getGenerateTableSql() public function getGenerateTableWithMultiColumnUniqueIndexSql() { - return array( + return [ 'CREATE TABLE test (foo NVARCHAR(255), bar NVARCHAR(255))', - 'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar) WHERE foo IS NOT NULL AND bar IS NOT NULL' - ); + 'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar) WHERE foo IS NOT NULL AND bar IS NOT NULL', + ]; } public function getGenerateAlterTableSql() { - return array( + return [ 'ALTER TABLE mytable ADD quota INT', 'ALTER TABLE mytable DROP COLUMN foo', 'ALTER TABLE mytable ALTER COLUMN baz NVARCHAR(255) NOT NULL', @@ -38,11 +40,11 @@ public function getGenerateAlterTableSql() "DECLARE @sql NVARCHAR(MAX) = N''; " . "SELECT @sql += N'EXEC sp_rename N''' + dc.name + ''', N''' " . "+ REPLACE(dc.name, '6B2BD609', 'E2B58069') + ''', ''OBJECT'';' " . - "FROM sys.default_constraints dc " . - "JOIN sys.tables tbl ON dc.parent_object_id = tbl.object_id " . + 'FROM sys.default_constraints dc ' . + 'JOIN sys.tables tbl ON dc.parent_object_id = tbl.object_id ' . "WHERE tbl.name = 'userlist';" . - "EXEC sp_executesql @sql" - ); + 'EXEC sp_executesql @sql', + ]; } /** @@ -95,41 +97,43 @@ public function testGeneratesDDLSnippets() public function testGeneratesTypeDeclarationForIntegers() { self::assertEquals( - 'INT', - $this->_platform->getIntegerTypeDeclarationSQL(array()) + 'INT', + $this->_platform->getIntegerTypeDeclarationSQL([]) ); self::assertEquals( - 'INT IDENTITY', - $this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true) - )); + 'INT IDENTITY', + $this->_platform->getIntegerTypeDeclarationSQL(['autoincrement' => true]) + ); self::assertEquals( - 'INT IDENTITY', - $this->_platform->getIntegerTypeDeclarationSQL( - array('autoincrement' => true, 'primary' => true) - )); + 'INT IDENTITY', + $this->_platform->getIntegerTypeDeclarationSQL( + ['autoincrement' => true, 'primary' => true] + ) + ); } public function testGeneratesTypeDeclarationsForStrings() { self::assertEquals( - 'NCHAR(10)', - $this->_platform->getVarcharTypeDeclarationSQL( - array('length' => 10, 'fixed' => true) - )); + 'NCHAR(10)', + $this->_platform->getVarcharTypeDeclarationSQL( + ['length' => 10, 'fixed' => true] + ) + ); self::assertEquals( - 'NVARCHAR(50)', - $this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)), - 'Variable string declaration is not correct' + 'NVARCHAR(50)', + $this->_platform->getVarcharTypeDeclarationSQL(['length' => 50]), + 'Variable string declaration is not correct' ); self::assertEquals( - 'NVARCHAR(255)', - $this->_platform->getVarcharTypeDeclarationSQL(array()), - 'Long string declaration is not correct' + 'NVARCHAR(255)', + $this->_platform->getVarcharTypeDeclarationSQL([]), + 'Long string declaration is not correct' ); - self::assertSame('VARCHAR(MAX)', $this->_platform->getClobTypeDeclarationSQL(array())); + self::assertSame('VARCHAR(MAX)', $this->_platform->getClobTypeDeclarationSQL([])); self::assertSame( 'VARCHAR(MAX)', - $this->_platform->getClobTypeDeclarationSQL(array('length' => 5, 'fixed' => true)) + $this->_platform->getClobTypeDeclarationSQL(['length' => 5, 'fixed' => true]) ); } @@ -175,114 +179,114 @@ public function getGenerateForeignKeySql() public function testModifyLimitQuery() { - $querySql = 'SELECT * FROM user'; + $querySql = 'SELECT * FROM user'; $alteredSql = 'SELECT TOP 10 * FROM user'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10, 0); + $sql = $this->_platform->modifyLimitQuery($querySql, 10, 0); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } public function testModifyLimitQueryWithEmptyOffset() { - $querySql = 'SELECT * FROM user'; + $querySql = 'SELECT * FROM user'; $alteredSql = 'SELECT TOP 10 * FROM user'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->_platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } public function testModifyLimitQueryWithOffset() { - if ( ! $this->_platform->supportsLimitOffset()) { + if (! $this->_platform->supportsLimitOffset()) { $this->markTestSkipped(sprintf('Platform "%s" does not support offsets in result limiting.', $this->_platform->getName())); } - $querySql = 'SELECT * FROM user ORDER BY username DESC'; + $querySql = 'SELECT * FROM user ORDER BY username DESC'; $alteredSql = 'SELECT TOP 15 * FROM user ORDER BY username DESC'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10, 5); + $sql = $this->_platform->modifyLimitQuery($querySql, 10, 5); $this->expectCteWithMinAndMaxRowNums($alteredSql, 6, 15, $sql); } public function testModifyLimitQueryWithAscOrderBy() { - $querySql = 'SELECT * FROM user ORDER BY username ASC'; + $querySql = 'SELECT * FROM user ORDER BY username ASC'; $alteredSql = 'SELECT TOP 10 * FROM user ORDER BY username ASC'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->_platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } public function testModifyLimitQueryWithLowercaseOrderBy() { - $querySql = 'SELECT * FROM user order by username'; + $querySql = 'SELECT * FROM user order by username'; $alteredSql = 'SELECT TOP 10 * FROM user order by username'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->_platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } public function testModifyLimitQueryWithDescOrderBy() { - $querySql = 'SELECT * FROM user ORDER BY username DESC'; + $querySql = 'SELECT * FROM user ORDER BY username DESC'; $alteredSql = 'SELECT TOP 10 * FROM user ORDER BY username DESC'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->_platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } public function testModifyLimitQueryWithMultipleOrderBy() { - $querySql = 'SELECT * FROM user ORDER BY username DESC, usereamil ASC'; + $querySql = 'SELECT * FROM user ORDER BY username DESC, usereamil ASC'; $alteredSql = 'SELECT TOP 10 * FROM user ORDER BY username DESC, usereamil ASC'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->_platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } public function testModifyLimitQueryWithSubSelect() { - $querySql = 'SELECT * FROM (SELECT u.id as uid, u.name as uname) dctrn_result'; + $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'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->_platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } public function testModifyLimitQueryWithSubSelectAndOrder() { - $querySql = 'SELECT * FROM (SELECT u.id as uid, u.name as uname ORDER BY u.name DESC) dctrn_result'; + $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'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->_platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); - $querySql = 'SELECT * FROM (SELECT u.id, u.name ORDER BY u.name DESC) dctrn_result'; + $querySql = 'SELECT * FROM (SELECT u.id, u.name ORDER BY u.name DESC) dctrn_result'; $alteredSql = 'SELECT TOP 10 * FROM (SELECT u.id, u.name) dctrn_result'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->_platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } public function testModifyLimitQueryWithSubSelectAndMultipleOrder() { - if ( ! $this->_platform->supportsLimitOffset()) { + if (! $this->_platform->supportsLimitOffset()) { $this->markTestSkipped(sprintf('Platform "%s" does not support offsets in result limiting.', $this->_platform->getName())); } - $querySql = 'SELECT * FROM (SELECT u.id as uid, u.name as uname ORDER BY u.name DESC, id ASC) dctrn_result'; + $querySql = 'SELECT * FROM (SELECT u.id as uid, u.name as uname ORDER BY u.name DESC, id ASC) dctrn_result'; $alteredSql = 'SELECT TOP 15 * FROM (SELECT u.id as uid, u.name as uname) dctrn_result'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10, 5); + $sql = $this->_platform->modifyLimitQuery($querySql, 10, 5); $this->expectCteWithMinAndMaxRowNums($alteredSql, 6, 15, $sql); - $querySql = 'SELECT * FROM (SELECT u.id uid, u.name uname ORDER BY u.name DESC, id ASC) dctrn_result'; + $querySql = 'SELECT * FROM (SELECT u.id uid, u.name uname ORDER BY u.name DESC, id ASC) dctrn_result'; $alteredSql = 'SELECT TOP 15 * FROM (SELECT u.id uid, u.name uname) dctrn_result'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10, 5); + $sql = $this->_platform->modifyLimitQuery($querySql, 10, 5); $this->expectCteWithMinAndMaxRowNums($alteredSql, 6, 15, $sql); - $querySql = 'SELECT * FROM (SELECT u.id, u.name ORDER BY u.name DESC, id ASC) dctrn_result'; + $querySql = 'SELECT * FROM (SELECT u.id, u.name ORDER BY u.name DESC, id ASC) dctrn_result'; $alteredSql = 'SELECT TOP 15 * FROM (SELECT u.id, u.name) dctrn_result'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10, 5); + $sql = $this->_platform->modifyLimitQuery($querySql, 10, 5); $this->expectCteWithMinAndMaxRowNums($alteredSql, 6, 15, $sql); } public function testModifyLimitQueryWithFromColumnNames() { - $querySql = 'SELECT a.fromFoo, fromBar FROM foo'; + $querySql = 'SELECT a.fromFoo, fromBar FROM foo'; $alteredSql = 'SELECT TOP 10 a.fromFoo, fromBar FROM foo'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->_platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } @@ -291,15 +295,15 @@ public function testModifyLimitQueryWithFromColumnNames() */ public function testModifyLimitQueryWithExtraLongQuery() { - $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) '; - $query.= 'AND (table2.column2 = table7.column7) AND (table2.column2 = table8.column8) AND (table3.column3 = table4.column4) AND (table3.column3 = table5.column5) AND (table3.column3 = table6.column6) AND (table3.column3 = table7.column7) AND (table3.column3 = table8.column8) AND (table4.column4 = table5.column5) AND (table4.column4 = table6.column6) AND (table4.column4 = table7.column7) AND (table4.column4 = table8.column8) '; - $query.= 'AND (table5.column5 = table6.column6) AND (table5.column5 = table7.column7) AND (table5.column5 = table8.column8) AND (table6.column6 = table7.column7) AND (table6.column6 = table8.column8) AND (table7.column7 = table8.column8)'; + $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) '; + $query .= 'AND (table2.column2 = table7.column7) AND (table2.column2 = table8.column8) AND (table3.column3 = table4.column4) AND (table3.column3 = table5.column5) AND (table3.column3 = table6.column6) AND (table3.column3 = table7.column7) AND (table3.column3 = table8.column8) AND (table4.column4 = table5.column5) AND (table4.column4 = table6.column6) AND (table4.column4 = table7.column7) AND (table4.column4 = table8.column8) '; + $query .= 'AND (table5.column5 = table6.column6) AND (table5.column5 = table7.column7) AND (table5.column5 = table8.column8) AND (table6.column6 = table7.column7) AND (table6.column6 = table8.column8) AND (table7.column7 = table8.column8)'; - $alteredSql = 'SELECT TOP 10 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 '; - $alteredSql.= '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) '; - $alteredSql.= 'AND (table2.column2 = table7.column7) AND (table2.column2 = table8.column8) AND (table3.column3 = table4.column4) AND (table3.column3 = table5.column5) AND (table3.column3 = table6.column6) AND (table3.column3 = table7.column7) AND (table3.column3 = table8.column8) AND (table4.column4 = table5.column5) AND (table4.column4 = table6.column6) AND (table4.column4 = table7.column7) AND (table4.column4 = table8.column8) '; - $alteredSql.= 'AND (table5.column5 = table6.column6) AND (table5.column5 = table7.column7) AND (table5.column5 = table8.column8) AND (table6.column6 = table7.column7) AND (table6.column6 = table8.column8) AND (table7.column7 = table8.column8)'; + $alteredSql = 'SELECT TOP 10 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 '; + $alteredSql .= '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) '; + $alteredSql .= 'AND (table2.column2 = table7.column7) AND (table2.column2 = table8.column8) AND (table3.column3 = table4.column4) AND (table3.column3 = table5.column5) AND (table3.column3 = table6.column6) AND (table3.column3 = table7.column7) AND (table3.column3 = table8.column8) AND (table4.column4 = table5.column5) AND (table4.column4 = table6.column6) AND (table4.column4 = table7.column7) AND (table4.column4 = table8.column8) '; + $alteredSql .= 'AND (table5.column5 = table6.column6) AND (table5.column5 = table7.column7) AND (table5.column5 = table8.column8) AND (table6.column6 = table7.column7) AND (table6.column6 = table8.column8) AND (table7.column7 = table8.column8)'; $sql = $this->_platform->modifyLimitQuery($query, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); @@ -310,7 +314,7 @@ public function testModifyLimitQueryWithExtraLongQuery() */ public function testModifyLimitQueryWithOrderByClause() { - if ( ! $this->_platform->supportsLimitOffset()) { + if (! $this->_platform->supportsLimitOffset()) { $this->markTestSkipped(sprintf('Platform "%s" does not support offsets in result limiting.', $this->_platform->getName())); } @@ -326,21 +330,21 @@ public function testModifyLimitQueryWithOrderByClause() */ public function testModifyLimitQueryWithSubSelectInSelectList() { - $querySql = "SELECT " . - "u.id, " . - "(u.foo/2) foodiv, " . - "CONCAT(u.bar, u.baz) barbaz, " . - "(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count " . - "FROM user u " . + $querySql = 'SELECT ' . + 'u.id, ' . + '(u.foo/2) foodiv, ' . + 'CONCAT(u.bar, u.baz) barbaz, ' . + '(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count ' . + 'FROM user u ' . "WHERE u.status = 'disabled'"; - $alteredSql = "SELECT TOP 10 " . - "u.id, " . - "(u.foo/2) foodiv, " . - "CONCAT(u.bar, u.baz) barbaz, " . - "(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count " . - "FROM user u " . + $alteredSql = 'SELECT TOP 10 ' . + 'u.id, ' . + '(u.foo/2) foodiv, ' . + 'CONCAT(u.bar, u.baz) barbaz, ' . + '(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count ' . + 'FROM user u ' . "WHERE u.status = 'disabled'"; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->_platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } @@ -350,27 +354,27 @@ public function testModifyLimitQueryWithSubSelectInSelectList() */ public function testModifyLimitQueryWithSubSelectInSelectListAndOrderByClause() { - if ( ! $this->_platform->supportsLimitOffset()) { + if (! $this->_platform->supportsLimitOffset()) { $this->markTestSkipped(sprintf('Platform "%s" does not support offsets in result limiting.', $this->_platform->getName())); } - $querySql = "SELECT " . - "u.id, " . - "(u.foo/2) foodiv, " . - "CONCAT(u.bar, u.baz) barbaz, " . - "(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count " . - "FROM user u " . + $querySql = 'SELECT ' . + 'u.id, ' . + '(u.foo/2) foodiv, ' . + 'CONCAT(u.bar, u.baz) barbaz, ' . + '(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count ' . + 'FROM user u ' . "WHERE u.status = 'disabled' " . - "ORDER BY u.username DESC"; - $alteredSql = "SELECT TOP 15 " . - "u.id, " . - "(u.foo/2) foodiv, " . - "CONCAT(u.bar, u.baz) barbaz, " . - "(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count " . - "FROM user u " . + 'ORDER BY u.username DESC'; + $alteredSql = 'SELECT TOP 15 ' . + 'u.id, ' . + '(u.foo/2) foodiv, ' . + 'CONCAT(u.bar, u.baz) barbaz, ' . + '(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count ' . + 'FROM user u ' . "WHERE u.status = 'disabled' " . - "ORDER BY u.username DESC"; - $sql = $this->_platform->modifyLimitQuery($querySql, 10, 5); + 'ORDER BY u.username DESC'; + $sql = $this->_platform->modifyLimitQuery($querySql, 10, 5); $this->expectCteWithMinAndMaxRowNums($alteredSql, 6, 15, $sql); } @@ -379,102 +383,102 @@ public function testModifyLimitQueryWithSubSelectInSelectListAndOrderByClause() */ public function testModifyLimitQueryWithAggregateFunctionInOrderByClause() { - $querySql = "SELECT " . - "MAX(heading_id) aliased, " . - "code " . - "FROM operator_model_operator " . - "GROUP BY code " . - "ORDER BY MAX(heading_id) DESC"; - $alteredSql = "SELECT TOP 1 " . - "MAX(heading_id) aliased, " . - "code " . - "FROM operator_model_operator " . - "GROUP BY code " . - "ORDER BY MAX(heading_id) DESC"; - $sql = $this->_platform->modifyLimitQuery($querySql, 1, 0); + $querySql = 'SELECT ' . + 'MAX(heading_id) aliased, ' . + 'code ' . + 'FROM operator_model_operator ' . + 'GROUP BY code ' . + 'ORDER BY MAX(heading_id) DESC'; + $alteredSql = 'SELECT TOP 1 ' . + 'MAX(heading_id) aliased, ' . + 'code ' . + 'FROM operator_model_operator ' . + 'GROUP BY code ' . + 'ORDER BY MAX(heading_id) DESC'; + $sql = $this->_platform->modifyLimitQuery($querySql, 1, 0); $this->expectCteWithMaxRowNum($alteredSql, 1, $sql); } /** - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromBaseTable() { - $querySql = "SELECT DISTINCT id_0, name_1 " - . "FROM (" - . "SELECT t1.id AS id_0, t2.name AS name_1 " - . "FROM table_parent t1 " - . "LEFT JOIN join_table t2 ON t1.id = t2.table_id " - . "ORDER BY t1.id ASC" - . ") dctrn_result " - . "ORDER BY id_0 ASC"; - $alteredSql = "SELECT DISTINCT TOP 5 id_0, name_1 " - . "FROM (" - . "SELECT t1.id AS id_0, t2.name AS name_1 " - . "FROM table_parent t1 " - . "LEFT JOIN join_table t2 ON t1.id = t2.table_id" - . ") dctrn_result " - . "ORDER BY id_0 ASC"; - $sql = $this->_platform->modifyLimitQuery($querySql, 5); + $querySql = 'SELECT DISTINCT id_0, name_1 ' + . 'FROM (' + . 'SELECT t1.id AS id_0, t2.name AS name_1 ' + . 'FROM table_parent t1 ' + . 'LEFT JOIN join_table t2 ON t1.id = t2.table_id ' + . 'ORDER BY t1.id ASC' + . ') dctrn_result ' + . 'ORDER BY id_0 ASC'; + $alteredSql = 'SELECT DISTINCT TOP 5 id_0, name_1 ' + . 'FROM (' + . 'SELECT t1.id AS id_0, t2.name AS name_1 ' + . 'FROM table_parent t1 ' + . 'LEFT JOIN join_table t2 ON t1.id = t2.table_id' + . ') dctrn_result ' + . 'ORDER BY id_0 ASC'; + $sql = $this->_platform->modifyLimitQuery($querySql, 5); $this->expectCteWithMaxRowNum($alteredSql, 5, $sql); } /** - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromJoinTable() { - $querySql = "SELECT DISTINCT id_0, name_1 " - . "FROM (" - . "SELECT t1.id AS id_0, t2.name AS name_1 " - . "FROM table_parent t1 " - . "LEFT JOIN join_table t2 ON t1.id = t2.table_id " - . "ORDER BY t2.name ASC" - . ") dctrn_result " - . "ORDER BY name_1 ASC"; - $alteredSql = "SELECT DISTINCT TOP 5 id_0, name_1 " - . "FROM (" - . "SELECT t1.id AS id_0, t2.name AS name_1 " - . "FROM table_parent t1 " - . "LEFT JOIN join_table t2 ON t1.id = t2.table_id" - . ") dctrn_result " - . "ORDER BY name_1 ASC"; - $sql = $this->_platform->modifyLimitQuery($querySql, 5); + $querySql = 'SELECT DISTINCT id_0, name_1 ' + . 'FROM (' + . 'SELECT t1.id AS id_0, t2.name AS name_1 ' + . 'FROM table_parent t1 ' + . 'LEFT JOIN join_table t2 ON t1.id = t2.table_id ' + . 'ORDER BY t2.name ASC' + . ') dctrn_result ' + . 'ORDER BY name_1 ASC'; + $alteredSql = 'SELECT DISTINCT TOP 5 id_0, name_1 ' + . 'FROM (' + . 'SELECT t1.id AS id_0, t2.name AS name_1 ' + . 'FROM table_parent t1 ' + . 'LEFT JOIN join_table t2 ON t1.id = t2.table_id' + . ') dctrn_result ' + . 'ORDER BY name_1 ASC'; + $sql = $this->_platform->modifyLimitQuery($querySql, 5); $this->expectCteWithMaxRowNum($alteredSql, 5, $sql); } /** - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnsFromBothTables() { - $querySql = "SELECT DISTINCT id_0, name_1, foo_2 " - . "FROM (" - . "SELECT t1.id AS id_0, t2.name AS name_1, t2.foo AS foo_2 " - . "FROM table_parent t1 " - . "LEFT JOIN join_table t2 ON t1.id = t2.table_id " - . "ORDER BY t2.name ASC, t2.foo DESC" - . ") dctrn_result " - . "ORDER BY name_1 ASC, foo_2 DESC"; - $alteredSql = "SELECT DISTINCT TOP 5 id_0, name_1, foo_2 " - . "FROM (" - . "SELECT t1.id AS id_0, t2.name AS name_1, t2.foo AS foo_2 " - . "FROM table_parent t1 " - . "LEFT JOIN join_table t2 ON t1.id = t2.table_id" - . ") dctrn_result " - . "ORDER BY name_1 ASC, foo_2 DESC"; - $sql = $this->_platform->modifyLimitQuery($querySql, 5); + $querySql = 'SELECT DISTINCT id_0, name_1, foo_2 ' + . 'FROM (' + . 'SELECT t1.id AS id_0, t2.name AS name_1, t2.foo AS foo_2 ' + . 'FROM table_parent t1 ' + . 'LEFT JOIN join_table t2 ON t1.id = t2.table_id ' + . 'ORDER BY t2.name ASC, t2.foo DESC' + . ') dctrn_result ' + . 'ORDER BY name_1 ASC, foo_2 DESC'; + $alteredSql = 'SELECT DISTINCT TOP 5 id_0, name_1, foo_2 ' + . 'FROM (' + . 'SELECT t1.id AS id_0, t2.name AS name_1, t2.foo AS foo_2 ' + . 'FROM table_parent t1 ' + . 'LEFT JOIN join_table t2 ON t1.id = t2.table_id' + . ') dctrn_result ' + . 'ORDER BY name_1 ASC, foo_2 DESC'; + $sql = $this->_platform->modifyLimitQuery($querySql, 5); $this->expectCteWithMaxRowNum($alteredSql, 5, $sql); } public function testModifyLimitSubquerySimple() { - $querySql = "SELECT DISTINCT id_0 FROM " - . "(SELECT k0_.id AS id_0, k0_.field AS field_1 " - . "FROM key_table k0_ WHERE (k0_.where_field IN (1))) dctrn_result"; - $alteredSql = "SELECT DISTINCT TOP 20 id_0 FROM (SELECT k0_.id AS id_0, k0_.field AS field_1 " - . "FROM key_table k0_ WHERE (k0_.where_field IN (1))) dctrn_result"; - $sql = $this->_platform->modifyLimitQuery($querySql, 20); + $querySql = 'SELECT DISTINCT id_0 FROM ' + . '(SELECT k0_.id AS id_0, k0_.field AS field_1 ' + . 'FROM key_table k0_ WHERE (k0_.where_field IN (1))) dctrn_result'; + $alteredSql = 'SELECT DISTINCT TOP 20 id_0 FROM (SELECT k0_.id AS id_0, k0_.field AS field_1 ' + . 'FROM key_table k0_ WHERE (k0_.where_field IN (1))) dctrn_result'; + $sql = $this->_platform->modifyLimitQuery($querySql, 20); $this->expectCteWithMaxRowNum($alteredSql, 20, $sql); } @@ -503,7 +507,7 @@ public function testQuoteSingleIdentifier() */ public function testCreateClusteredIndex() { - $idx = new \Doctrine\DBAL\Schema\Index('idx', array('id')); + $idx = new Index('idx', ['id']); $idx->addFlag('clustered'); self::assertEquals('CREATE CLUSTERED INDEX idx ON tbl (id)', $this->_platform->getCreateIndexSQL($idx, 'tbl')); } @@ -513,12 +517,12 @@ public function testCreateClusteredIndex() */ public function testCreateNonClusteredPrimaryKeyInTable() { - $table = new \Doctrine\DBAL\Schema\Table("tbl"); - $table->addColumn("id", "integer"); - $table->setPrimaryKey(Array("id")); + $table = new Table('tbl'); + $table->addColumn('id', 'integer'); + $table->setPrimaryKey(['id']); $table->getIndex('primary')->addFlag('nonclustered'); - self::assertEquals(array('CREATE TABLE tbl (id INT NOT NULL, PRIMARY KEY NONCLUSTERED (id))'), $this->_platform->getCreateTableSQL($table)); + self::assertEquals(['CREATE TABLE tbl (id INT NOT NULL, PRIMARY KEY NONCLUSTERED (id))'], $this->_platform->getCreateTableSQL($table)); } /** @@ -526,54 +530,52 @@ public function testCreateNonClusteredPrimaryKeyInTable() */ public function testCreateNonClusteredPrimaryKey() { - $idx = new \Doctrine\DBAL\Schema\Index('idx', array('id'), false, true); + $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() { - $idx = new \Doctrine\DBAL\Schema\Index('idx', array('id'), false, true); + $idx = new Index('idx', ['id'], false, true); self::assertEquals('ALTER TABLE tbl ADD PRIMARY KEY (id)', $this->_platform->getCreateIndexSQL($idx, 'tbl')); } protected function getQuotedColumnInPrimaryKeySQL() { - return array( - 'CREATE TABLE [quoted] ([create] NVARCHAR(255) NOT NULL, PRIMARY KEY ([create]))', - ); + return ['CREATE TABLE [quoted] ([create] NVARCHAR(255) NOT NULL, PRIMARY KEY ([create]))']; } protected function getQuotedColumnInIndexSQL() { - return array( + return [ 'CREATE TABLE [quoted] ([create] NVARCHAR(255) NOT NULL)', 'CREATE INDEX IDX_22660D028FD6E0FB ON [quoted] ([create])', - ); + ]; } protected function getQuotedNameInIndexSQL() { - return array( + return [ 'CREATE TABLE test (column1 NVARCHAR(255) NOT NULL)', 'CREATE INDEX [key] ON test (column1)', - ); + ]; } protected function getQuotedColumnInForeignKeySQL() { - return array( + return [ 'CREATE TABLE [quoted] ([create] NVARCHAR(255) NOT NULL, foo NVARCHAR(255) NOT NULL, [bar] NVARCHAR(255) NOT NULL)', '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])', - ); + ]; } public function testGetCreateSchemaSQL() { $schemaName = 'schema'; - $sql = $this->_platform->getCreateSchemaSQL($schemaName); + $sql = $this->_platform->getCreateSchemaSQL($schemaName); self::assertEquals('CREATE SCHEMA ' . $schemaName, $sql); } @@ -639,10 +641,10 @@ public function testAlterTableWithSchemaUpdateColumnComments() */ public function getCreateTableColumnCommentsSQL() { - return array( - "CREATE TABLE test (id INT NOT NULL, PRIMARY KEY (id))", + return [ + 'CREATE TABLE test (id INT NOT NULL, PRIMARY KEY (id))', "EXEC sp_addextendedproperty N'MS_Description', N'This is a comment', N'SCHEMA', 'dbo', N'TABLE', 'test', N'COLUMN', id", - ); + ]; } /** @@ -650,12 +652,12 @@ public function getCreateTableColumnCommentsSQL() */ public function getAlterTableColumnCommentsSQL() { - return array( - "ALTER TABLE mytable ADD quota INT NOT NULL", + return [ + 'ALTER TABLE mytable ADD quota INT NOT NULL', "EXEC sp_addextendedproperty N'MS_Description', N'A comment', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', quota", // todo //"EXEC sp_addextendedproperty N'MS_Description', N'B comment', N'SCHEMA', dbo, N'TABLE', mytable, N'COLUMN', baz", - ); + ]; } /** @@ -663,10 +665,10 @@ public function getAlterTableColumnCommentsSQL() */ public function getCreateTableColumnTypeCommentsSQL() { - return array( - "CREATE TABLE test (id INT NOT NULL, data VARCHAR(MAX) NOT NULL, PRIMARY KEY (id))", + return [ + 'CREATE TABLE test (id INT NOT NULL, data VARCHAR(MAX) NOT NULL, PRIMARY KEY (id))', "EXEC sp_addextendedproperty N'MS_Description', N'(DC2Type:array)', N'SCHEMA', 'dbo', N'TABLE', 'test', N'COLUMN', data", - ); + ]; } /** @@ -675,24 +677,24 @@ public function getCreateTableColumnTypeCommentsSQL() public function testGeneratesCreateTableSQLWithColumnComments() { $table = new Table('mytable'); - $table->addColumn('id', 'integer', array('autoincrement' => true)); - $table->addColumn('comment_null', 'integer', array('comment' => null)); - $table->addColumn('comment_false', 'integer', array('comment' => false)); - $table->addColumn('comment_empty_string', 'integer', array('comment' => '')); - $table->addColumn('comment_integer_0', 'integer', array('comment' => 0)); - $table->addColumn('comment_float_0', 'integer', array('comment' => 0.0)); - $table->addColumn('comment_string_0', 'integer', array('comment' => '0')); - $table->addColumn('comment', 'integer', array('comment' => 'Doctrine 0wnz you!')); - $table->addColumn('`comment_quoted`', 'integer', array('comment' => 'Doctrine 0wnz comments for explicitly quoted columns!')); - $table->addColumn('create', 'integer', array('comment' => 'Doctrine 0wnz comments for reserved keyword columns!')); + $table->addColumn('id', 'integer', ['autoincrement' => true]); + $table->addColumn('comment_null', 'integer', ['comment' => null]); + $table->addColumn('comment_false', 'integer', ['comment' => false]); + $table->addColumn('comment_empty_string', 'integer', ['comment' => '']); + $table->addColumn('comment_integer_0', 'integer', ['comment' => 0]); + $table->addColumn('comment_float_0', 'integer', ['comment' => 0.0]); + $table->addColumn('comment_string_0', 'integer', ['comment' => '0']); + $table->addColumn('comment', 'integer', ['comment' => 'Doctrine 0wnz you!']); + $table->addColumn('`comment_quoted`', 'integer', ['comment' => 'Doctrine 0wnz comments for explicitly quoted columns!']); + $table->addColumn('create', 'integer', ['comment' => 'Doctrine 0wnz comments for reserved keyword columns!']); $table->addColumn('commented_type', 'object'); - $table->addColumn('commented_type_with_comment', 'array', array('comment' => 'Doctrine array type.')); - $table->addColumn('comment_with_string_literal_char', 'string', array('comment' => "O'Reilly")); - $table->setPrimaryKey(array('id')); + $table->addColumn('commented_type_with_comment', 'array', ['comment' => 'Doctrine array type.']); + $table->addColumn('comment_with_string_literal_char', 'string', ['comment' => "O'Reilly"]); + $table->setPrimaryKey(['id']); self::assertEquals( - array( - "CREATE TABLE mytable (id INT IDENTITY NOT NULL, comment_null INT NOT NULL, comment_false INT NOT NULL, comment_empty_string INT NOT NULL, comment_integer_0 INT NOT NULL, comment_float_0 INT NOT NULL, comment_string_0 INT NOT NULL, comment INT NOT NULL, [comment_quoted] INT NOT NULL, [create] INT NOT NULL, commented_type VARCHAR(MAX) NOT NULL, commented_type_with_comment VARCHAR(MAX) NOT NULL, comment_with_string_literal_char NVARCHAR(255) NOT NULL, PRIMARY KEY (id))", + [ + 'CREATE TABLE mytable (id INT IDENTITY NOT NULL, comment_null INT NOT NULL, comment_false INT NOT NULL, comment_empty_string INT NOT NULL, comment_integer_0 INT NOT NULL, comment_float_0 INT NOT NULL, comment_string_0 INT NOT NULL, comment INT NOT NULL, [comment_quoted] INT NOT NULL, [create] INT NOT NULL, commented_type VARCHAR(MAX) NOT NULL, commented_type_with_comment VARCHAR(MAX) NOT NULL, comment_with_string_literal_char NVARCHAR(255) NOT NULL, PRIMARY KEY (id))', "EXEC sp_addextendedproperty N'MS_Description', N'0', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', comment_integer_0", "EXEC sp_addextendedproperty N'MS_Description', N'0', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', comment_float_0", "EXEC sp_addextendedproperty N'MS_Description', N'0', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', comment_string_0", @@ -702,7 +704,7 @@ public function testGeneratesCreateTableSQLWithColumnComments() "EXEC sp_addextendedproperty N'MS_Description', N'(DC2Type:object)', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', commented_type", "EXEC sp_addextendedproperty N'MS_Description', N'Doctrine array type.(DC2Type:array)', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', commented_type_with_comment", "EXEC sp_addextendedproperty N'MS_Description', N'O''Reilly', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', comment_with_string_literal_char", - ), + ], $this->_platform->getCreateTableSQL($table) ); } @@ -714,108 +716,108 @@ public function testGeneratesCreateTableSQLWithColumnComments() public function testGeneratesAlterTableSQLWithColumnComments() { $table = new Table('mytable'); - $table->addColumn('id', 'integer', array('autoincrement' => true)); - $table->addColumn('comment_null', 'integer', array('comment' => null)); - $table->addColumn('comment_false', 'integer', array('comment' => false)); - $table->addColumn('comment_empty_string', 'integer', array('comment' => '')); - $table->addColumn('comment_integer_0', 'integer', array('comment' => 0)); - $table->addColumn('comment_float_0', 'integer', array('comment' => 0.0)); - $table->addColumn('comment_string_0', 'integer', array('comment' => '0')); - $table->addColumn('comment', 'integer', array('comment' => 'Doctrine 0wnz you!')); - $table->addColumn('`comment_quoted`', 'integer', array('comment' => 'Doctrine 0wnz comments for explicitly quoted columns!')); - $table->addColumn('create', 'integer', array('comment' => 'Doctrine 0wnz comments for reserved keyword columns!')); + $table->addColumn('id', 'integer', ['autoincrement' => true]); + $table->addColumn('comment_null', 'integer', ['comment' => null]); + $table->addColumn('comment_false', 'integer', ['comment' => false]); + $table->addColumn('comment_empty_string', 'integer', ['comment' => '']); + $table->addColumn('comment_integer_0', 'integer', ['comment' => 0]); + $table->addColumn('comment_float_0', 'integer', ['comment' => 0.0]); + $table->addColumn('comment_string_0', 'integer', ['comment' => '0']); + $table->addColumn('comment', 'integer', ['comment' => 'Doctrine 0wnz you!']); + $table->addColumn('`comment_quoted`', 'integer', ['comment' => 'Doctrine 0wnz comments for explicitly quoted columns!']); + $table->addColumn('create', 'integer', ['comment' => 'Doctrine 0wnz comments for reserved keyword columns!']); $table->addColumn('commented_type', 'object'); - $table->addColumn('commented_type_with_comment', 'array', array('comment' => 'Doctrine array type.')); - $table->addColumn('comment_with_string_literal_quote_char', 'array', array('comment' => "O'Reilly")); - $table->setPrimaryKey(array('id')); - - $tableDiff = new TableDiff('mytable'); - $tableDiff->fromTable = $table; - $tableDiff->addedColumns['added_comment_none'] = new Column('added_comment_none', Type::getType('integer')); - $tableDiff->addedColumns['added_comment_null'] = new Column('added_comment_null', Type::getType('integer'), array('comment' => null)); - $tableDiff->addedColumns['added_comment_false'] = new Column('added_comment_false', Type::getType('integer'), array('comment' => false)); - $tableDiff->addedColumns['added_comment_empty_string'] = new Column('added_comment_empty_string', Type::getType('integer'), array('comment' => '')); - $tableDiff->addedColumns['added_comment_integer_0'] = new Column('added_comment_integer_0', Type::getType('integer'), array('comment' => 0)); - $tableDiff->addedColumns['added_comment_float_0'] = new Column('added_comment_float_0', Type::getType('integer'), array('comment' => 0.0)); - $tableDiff->addedColumns['added_comment_string_0'] = new Column('added_comment_string_0', Type::getType('integer'), array('comment' => '0')); - $tableDiff->addedColumns['added_comment'] = new Column('added_comment', Type::getType('integer'), array('comment' => 'Doctrine')); - $tableDiff->addedColumns['`added_comment_quoted`'] = new Column('`added_comment_quoted`', Type::getType('integer'), array('comment' => 'rulez')); - $tableDiff->addedColumns['select'] = new Column('select', Type::getType('integer'), array('comment' => '666')); - $tableDiff->addedColumns['added_commented_type'] = new Column('added_commented_type', Type::getType('object')); - $tableDiff->addedColumns['added_commented_type_with_comment'] = new Column('added_commented_type_with_comment', Type::getType('array'), array('comment' => '666')); - $tableDiff->addedColumns['added_comment_with_string_literal_char'] = new Column('added_comment_with_string_literal_char', Type::getType('string'), array('comment' => "''")); - - $tableDiff->renamedColumns['comment_float_0'] = new Column('comment_double_0', Type::getType('decimal'), array('comment' => 'Double for real!')); + $table->addColumn('commented_type_with_comment', 'array', ['comment' => 'Doctrine array type.']); + $table->addColumn('comment_with_string_literal_quote_char', 'array', ['comment' => "O'Reilly"]); + $table->setPrimaryKey(['id']); + + $tableDiff = new TableDiff('mytable'); + $tableDiff->fromTable = $table; + $tableDiff->addedColumns['added_comment_none'] = new Column('added_comment_none', Type::getType('integer')); + $tableDiff->addedColumns['added_comment_null'] = new Column('added_comment_null', Type::getType('integer'), ['comment' => null]); + $tableDiff->addedColumns['added_comment_false'] = new Column('added_comment_false', Type::getType('integer'), ['comment' => false]); + $tableDiff->addedColumns['added_comment_empty_string'] = new Column('added_comment_empty_string', Type::getType('integer'), ['comment' => '']); + $tableDiff->addedColumns['added_comment_integer_0'] = new Column('added_comment_integer_0', Type::getType('integer'), ['comment' => 0]); + $tableDiff->addedColumns['added_comment_float_0'] = new Column('added_comment_float_0', Type::getType('integer'), ['comment' => 0.0]); + $tableDiff->addedColumns['added_comment_string_0'] = new Column('added_comment_string_0', Type::getType('integer'), ['comment' => '0']); + $tableDiff->addedColumns['added_comment'] = new Column('added_comment', Type::getType('integer'), ['comment' => 'Doctrine']); + $tableDiff->addedColumns['`added_comment_quoted`'] = new Column('`added_comment_quoted`', Type::getType('integer'), ['comment' => 'rulez']); + $tableDiff->addedColumns['select'] = new Column('select', Type::getType('integer'), ['comment' => '666']); + $tableDiff->addedColumns['added_commented_type'] = new Column('added_commented_type', Type::getType('object')); + $tableDiff->addedColumns['added_commented_type_with_comment'] = new Column('added_commented_type_with_comment', Type::getType('array'), ['comment' => '666']); + $tableDiff->addedColumns['added_comment_with_string_literal_char'] = new Column('added_comment_with_string_literal_char', Type::getType('string'), ['comment' => "''"]); + + $tableDiff->renamedColumns['comment_float_0'] = new Column('comment_double_0', Type::getType('decimal'), ['comment' => 'Double for real!']); // Add comment to non-commented column. $tableDiff->changedColumns['id'] = new ColumnDiff( 'id', - new Column('id', Type::getType('integer'), array('autoincrement' => true, 'comment' => 'primary')), - array('comment'), - new Column('id', Type::getType('integer'), array('autoincrement' => true)) + new Column('id', Type::getType('integer'), ['autoincrement' => true, 'comment' => 'primary']), + ['comment'], + new Column('id', Type::getType('integer'), ['autoincrement' => true]) ); // Remove comment from null-commented column. $tableDiff->changedColumns['comment_null'] = new ColumnDiff( 'comment_null', new Column('comment_null', Type::getType('string')), - array('type'), - new Column('comment_null', Type::getType('integer'), array('comment' => null)) + ['type'], + new Column('comment_null', Type::getType('integer'), ['comment' => null]) ); // Add comment to false-commented column. $tableDiff->changedColumns['comment_false'] = new ColumnDiff( 'comment_false', - new Column('comment_false', Type::getType('integer'), array('comment' => 'false')), - array('comment'), - new Column('comment_false', Type::getType('integer'), array('comment' => false)) + new Column('comment_false', Type::getType('integer'), ['comment' => 'false']), + ['comment'], + new Column('comment_false', Type::getType('integer'), ['comment' => false]) ); // Change type to custom type from empty string commented column. $tableDiff->changedColumns['comment_empty_string'] = new ColumnDiff( 'comment_empty_string', new Column('comment_empty_string', Type::getType('object')), - array('type'), - new Column('comment_empty_string', Type::getType('integer'), array('comment' => '')) + ['type'], + new Column('comment_empty_string', Type::getType('integer'), ['comment' => '']) ); // Change comment to false-comment from zero-string commented column. $tableDiff->changedColumns['comment_string_0'] = new ColumnDiff( 'comment_string_0', - new Column('comment_string_0', Type::getType('integer'), array('comment' => false)), - array('comment'), - new Column('comment_string_0', Type::getType('integer'), array('comment' => '0')) + new Column('comment_string_0', Type::getType('integer'), ['comment' => false]), + ['comment'], + new Column('comment_string_0', Type::getType('integer'), ['comment' => '0']) ); // Remove comment from regular commented column. $tableDiff->changedColumns['comment'] = new ColumnDiff( 'comment', new Column('comment', Type::getType('integer')), - array('comment'), - new Column('comment', Type::getType('integer'), array('comment' => 'Doctrine 0wnz you!')) + ['comment'], + new Column('comment', Type::getType('integer'), ['comment' => 'Doctrine 0wnz you!']) ); // Change comment and change type to custom type from regular commented column. $tableDiff->changedColumns['`comment_quoted`'] = new ColumnDiff( '`comment_quoted`', - new Column('`comment_quoted`', Type::getType('array'), array('comment' => 'Doctrine array.')), - array('comment', 'type'), - new Column('`comment_quoted`', Type::getType('integer'), array('comment' => 'Doctrine 0wnz you!')) + new Column('`comment_quoted`', Type::getType('array'), ['comment' => 'Doctrine array.']), + ['comment', 'type'], + new Column('`comment_quoted`', Type::getType('integer'), ['comment' => 'Doctrine 0wnz you!']) ); // Remove comment and change type to custom type from regular commented column. $tableDiff->changedColumns['create'] = new ColumnDiff( 'create', new Column('create', Type::getType('object')), - array('comment', 'type'), - new Column('create', Type::getType('integer'), array('comment' => 'Doctrine 0wnz comments for reserved keyword columns!')) + ['comment', 'type'], + new Column('create', Type::getType('integer'), ['comment' => 'Doctrine 0wnz comments for reserved keyword columns!']) ); // Add comment and change custom type to regular type from non-commented column. $tableDiff->changedColumns['commented_type'] = new ColumnDiff( 'commented_type', - new Column('commented_type', Type::getType('integer'), array('comment' => 'foo')), - array('comment', 'type'), + new Column('commented_type', Type::getType('integer'), ['comment' => 'foo']), + ['comment', 'type'], new Column('commented_type', Type::getType('object')) ); @@ -823,45 +825,45 @@ public function testGeneratesAlterTableSQLWithColumnComments() $tableDiff->changedColumns['commented_type_with_comment'] = new ColumnDiff( 'commented_type_with_comment', new Column('commented_type_with_comment', Type::getType('array')), - array('comment'), - new Column('commented_type_with_comment', Type::getType('array'), array('comment' => 'Doctrine array type.')) + ['comment'], + new Column('commented_type_with_comment', Type::getType('array'), ['comment' => 'Doctrine array type.']) ); // Change comment from comment with string literal char column. $tableDiff->changedColumns['comment_with_string_literal_char'] = new ColumnDiff( 'comment_with_string_literal_char', - new Column('comment_with_string_literal_char', Type::getType('string'), array('comment' => "'")), - array('comment'), - new Column('comment_with_string_literal_char', Type::getType('array'), array('comment' => "O'Reilly")) + new Column('comment_with_string_literal_char', Type::getType('string'), ['comment' => "'"]), + ['comment'], + new Column('comment_with_string_literal_char', Type::getType('array'), ['comment' => "O'Reilly"]) ); - $tableDiff->removedColumns['comment_integer_0'] = new Column('comment_integer_0', Type::getType('integer'), array('comment' => 0)); + $tableDiff->removedColumns['comment_integer_0'] = new Column('comment_integer_0', Type::getType('integer'), ['comment' => 0]); self::assertEquals( - array( + [ // Renamed columns. "sp_RENAME 'mytable.comment_float_0', 'comment_double_0', 'COLUMN'", // Added columns. - "ALTER TABLE mytable ADD added_comment_none INT NOT NULL", - "ALTER TABLE mytable ADD added_comment_null INT NOT NULL", - "ALTER TABLE mytable ADD added_comment_false INT NOT NULL", - "ALTER TABLE mytable ADD added_comment_empty_string INT NOT NULL", - "ALTER TABLE mytable ADD added_comment_integer_0 INT NOT NULL", - "ALTER TABLE mytable ADD added_comment_float_0 INT NOT NULL", - "ALTER TABLE mytable ADD added_comment_string_0 INT NOT NULL", - "ALTER TABLE mytable ADD added_comment INT NOT NULL", - "ALTER TABLE mytable ADD [added_comment_quoted] INT NOT NULL", - "ALTER TABLE mytable ADD [select] INT NOT NULL", - "ALTER TABLE mytable ADD added_commented_type VARCHAR(MAX) NOT NULL", - "ALTER TABLE mytable ADD added_commented_type_with_comment VARCHAR(MAX) NOT NULL", - "ALTER TABLE mytable ADD added_comment_with_string_literal_char NVARCHAR(255) NOT NULL", - "ALTER TABLE mytable DROP COLUMN comment_integer_0", - "ALTER TABLE mytable ALTER COLUMN comment_null NVARCHAR(255) NOT NULL", - "ALTER TABLE mytable ALTER COLUMN comment_empty_string VARCHAR(MAX) NOT NULL", - "ALTER TABLE mytable ALTER COLUMN [comment_quoted] VARCHAR(MAX) NOT NULL", - "ALTER TABLE mytable ALTER COLUMN [create] VARCHAR(MAX) NOT NULL", - "ALTER TABLE mytable ALTER COLUMN commented_type INT NOT NULL", + 'ALTER TABLE mytable ADD added_comment_none INT NOT NULL', + 'ALTER TABLE mytable ADD added_comment_null INT NOT NULL', + 'ALTER TABLE mytable ADD added_comment_false INT NOT NULL', + 'ALTER TABLE mytable ADD added_comment_empty_string INT NOT NULL', + 'ALTER TABLE mytable ADD added_comment_integer_0 INT NOT NULL', + 'ALTER TABLE mytable ADD added_comment_float_0 INT NOT NULL', + 'ALTER TABLE mytable ADD added_comment_string_0 INT NOT NULL', + 'ALTER TABLE mytable ADD added_comment INT NOT NULL', + 'ALTER TABLE mytable ADD [added_comment_quoted] INT NOT NULL', + 'ALTER TABLE mytable ADD [select] INT NOT NULL', + 'ALTER TABLE mytable ADD added_commented_type VARCHAR(MAX) NOT NULL', + 'ALTER TABLE mytable ADD added_commented_type_with_comment VARCHAR(MAX) NOT NULL', + 'ALTER TABLE mytable ADD added_comment_with_string_literal_char NVARCHAR(255) NOT NULL', + 'ALTER TABLE mytable DROP COLUMN comment_integer_0', + 'ALTER TABLE mytable ALTER COLUMN comment_null NVARCHAR(255) NOT NULL', + 'ALTER TABLE mytable ALTER COLUMN comment_empty_string VARCHAR(MAX) NOT NULL', + 'ALTER TABLE mytable ALTER COLUMN [comment_quoted] VARCHAR(MAX) NOT NULL', + 'ALTER TABLE mytable ALTER COLUMN [create] VARCHAR(MAX) NOT NULL', + 'ALTER TABLE mytable ALTER COLUMN commented_type INT NOT NULL', // Added columns. "EXEC sp_addextendedproperty N'MS_Description', N'0', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', added_comment_integer_0", @@ -885,7 +887,7 @@ public function testGeneratesAlterTableSQLWithColumnComments() "EXEC sp_updateextendedproperty N'MS_Description', N'foo', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', commented_type", "EXEC sp_updateextendedproperty N'MS_Description', N'(DC2Type:array)', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', commented_type_with_comment", "EXEC sp_updateextendedproperty N'MS_Description', N'''', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', comment_with_string_literal_char", - ), + ], $this->_platform->getAlterTableSQL($tableDiff) ); } @@ -978,13 +980,13 @@ protected function getBinaryMaxLength() public function testReturnsBinaryTypeDeclarationSQL() { - self::assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array())); - self::assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 0))); - self::assertSame('VARBINARY(8000)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 8000))); + self::assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL([])); + self::assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 0])); + self::assertSame('VARBINARY(8000)', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 8000])); - self::assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true))); - self::assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 0))); - self::assertSame('BINARY(8000)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 8000))); + self::assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true])); + self::assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 0])); + self::assertSame('BINARY(8000)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 8000])); } /** @@ -1002,9 +1004,7 @@ public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() */ protected function getAlterTableRenameIndexSQL() { - return array( - "EXEC sp_RENAME N'mytable.idx_foo', N'idx_bar', N'INDEX'", - ); + return ["EXEC sp_RENAME N'mytable.idx_foo', N'idx_bar', N'INDEX'"]; } /** @@ -1012,10 +1012,10 @@ protected function getAlterTableRenameIndexSQL() */ protected function getQuotedAlterTableRenameIndexSQL() { - return array( + return [ "EXEC sp_RENAME N'[table].[create]', N'[select]', N'INDEX'", "EXEC sp_RENAME N'[table].[foo]', N'[bar]', N'INDEX'", - ); + ]; } /** @@ -1026,37 +1026,37 @@ public function testChangeColumnsTypeWithDefaultValue() $tableName = 'column_def_change_type'; $table = new Table($tableName); - $table->addColumn('col_int', 'smallint', array('default' => 666)); - $table->addColumn('col_string', 'string', array('default' => 'foo')); + $table->addColumn('col_int', 'smallint', ['default' => 666]); + $table->addColumn('col_string', 'string', ['default' => 'foo']); - $tableDiff = new TableDiff($tableName); - $tableDiff->fromTable = $table; + $tableDiff = new TableDiff($tableName); + $tableDiff->fromTable = $table; $tableDiff->changedColumns['col_int'] = new ColumnDiff( 'col_int', - new Column('col_int', Type::getType('integer'), array('default' => 666)), - array('type'), - new Column('col_int', Type::getType('smallint'), array('default' => 666)) + new Column('col_int', Type::getType('integer'), ['default' => 666]), + ['type'], + new Column('col_int', Type::getType('smallint'), ['default' => 666]) ); $tableDiff->changedColumns['col_string'] = new ColumnDiff( 'col_string', - new Column('col_string', Type::getType('string'), array('default' => 666, 'fixed' => true)), - array('fixed'), - new Column('col_string', Type::getType('string'), array('default' => 666)) + new Column('col_string', Type::getType('string'), ['default' => 666, 'fixed' => true]), + ['fixed'], + new Column('col_string', Type::getType('string'), ['default' => 666]) ); $expected = $this->_platform->getAlterTableSQL($tableDiff); self::assertSame( $expected, - array( + [ 'ALTER TABLE column_def_change_type DROP CONSTRAINT DF_829302E0_FA2CB292', 'ALTER TABLE column_def_change_type ALTER COLUMN col_int INT NOT NULL', 'ALTER TABLE column_def_change_type ADD CONSTRAINT DF_829302E0_FA2CB292 DEFAULT 666 FOR col_int', 'ALTER TABLE column_def_change_type DROP CONSTRAINT DF_829302E0_2725A6D0', 'ALTER TABLE column_def_change_type ALTER COLUMN col_string NCHAR(255) NOT NULL', "ALTER TABLE column_def_change_type ADD CONSTRAINT DF_829302E0_2725A6D0 DEFAULT '666' FOR col_string", - ) + ] ); } @@ -1065,7 +1065,7 @@ public function testChangeColumnsTypeWithDefaultValue() */ protected function getQuotedAlterTableRenameColumnSQL() { - return array( + return [ "sp_RENAME 'mytable.unquoted1', 'unquoted', 'COLUMN'", "sp_RENAME 'mytable.unquoted2', '[where]', 'COLUMN'", "sp_RENAME 'mytable.unquoted3', '[foo]', 'COLUMN'", @@ -1075,7 +1075,7 @@ protected function getQuotedAlterTableRenameColumnSQL() "sp_RENAME 'mytable.quoted1', 'quoted', 'COLUMN'", "sp_RENAME 'mytable.quoted2', '[and]', 'COLUMN'", "sp_RENAME 'mytable.quoted3', '[baz]', 'COLUMN'", - ); + ]; } /** @@ -1091,9 +1091,7 @@ protected function getQuotedAlterTableChangeColumnLengthSQL() */ protected function getAlterTableRenameIndexInSchemaSQL() { - return array( - "EXEC sp_RENAME N'myschema.mytable.idx_foo', N'idx_bar', N'INDEX'", - ); + return ["EXEC sp_RENAME N'myschema.mytable.idx_foo', N'idx_bar', N'INDEX'"]; } /** @@ -1101,10 +1099,10 @@ protected function getAlterTableRenameIndexInSchemaSQL() */ protected function getQuotedAlterTableRenameIndexInSchemaSQL() { - return array( + return [ "EXEC sp_RENAME N'[schema].[table].[create]', N'[select]', N'INDEX'", "EXEC sp_RENAME N'[schema].[table].[foo]', N'[bar]', N'INDEX'", - ); + ]; } protected function getQuotesDropForeignKeySQL() @@ -1128,16 +1126,16 @@ public function testGeneratesIdentifierNamesInDefaultConstraintDeclarationSQL($t public function getGeneratesIdentifierNamesInDefaultConstraintDeclarationSQL() { - return array( + return [ // Unquoted identifiers non-reserved keywords. - array('mytable', array('name' => 'mycolumn', 'default' => 'foo'), " CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'foo' FOR mycolumn"), + ['mytable', ['name' => 'mycolumn', 'default' => 'foo'], " CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'foo' FOR mycolumn"], // Quoted identifiers non-reserved keywords. - array('`mytable`', array('name' => '`mycolumn`', 'default' => 'foo'), " CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'foo' FOR [mycolumn]"), + ['`mytable`', ['name' => '`mycolumn`', 'default' => 'foo'], " CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'foo' FOR [mycolumn]"], // Unquoted identifiers reserved keywords. - array('table', array('name' => 'select', 'default' => 'foo'), " CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'foo' FOR [select]"), + ['table', ['name' => 'select', 'default' => 'foo'], " CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'foo' FOR [select]"], // Quoted identifiers reserved keywords. - array('`table`', array('name' => '`select`', 'default' => 'foo'), " CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'foo' FOR [select]"), - ); + ['`table`', ['name' => '`select`', 'default' => 'foo'], " CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'foo' FOR [select]"], + ]; } /** @@ -1151,40 +1149,40 @@ public function testGeneratesIdentifierNamesInCreateTableSQL($table, $expectedSq public function getGeneratesIdentifierNamesInCreateTableSQL() { - return array( + return [ // Unquoted identifiers non-reserved keywords. - array( - new Table('mytable', array(new Column('mycolumn', Type::getType('string'), array('default' => 'foo')))), - array( + [ + new Table('mytable', [new Column('mycolumn', Type::getType('string'), ['default' => 'foo'])]), + [ 'CREATE TABLE mytable (mycolumn NVARCHAR(255) NOT NULL)', - "ALTER TABLE mytable ADD CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'foo' FOR mycolumn" - ) - ), + "ALTER TABLE mytable ADD CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'foo' FOR mycolumn", + ], + ], // Quoted identifiers reserved keywords. - array( - new Table('`mytable`', array(new Column('`mycolumn`', Type::getType('string'), array('default' => 'foo')))), - array( + [ + new Table('`mytable`', [new Column('`mycolumn`', Type::getType('string'), ['default' => 'foo'])]), + [ 'CREATE TABLE [mytable] ([mycolumn] NVARCHAR(255) NOT NULL)', - "ALTER TABLE [mytable] ADD CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'foo' FOR [mycolumn]" - ) - ), + "ALTER TABLE [mytable] ADD CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'foo' FOR [mycolumn]", + ], + ], // Unquoted identifiers reserved keywords. - array( - new Table('table', array(new Column('select', Type::getType('string'), array('default' => 'foo')))), - array( + [ + new Table('table', [new Column('select', Type::getType('string'), ['default' => 'foo'])]), + [ 'CREATE TABLE [table] ([select] NVARCHAR(255) NOT NULL)', - "ALTER TABLE [table] ADD CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'foo' FOR [select]" - ) - ), + "ALTER TABLE [table] ADD CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'foo' FOR [select]", + ], + ], // Quoted identifiers reserved keywords. - array( - new Table('`table`', array(new Column('`select`', Type::getType('string'), array('default' => 'foo')))), - array( + [ + new Table('`table`', [new Column('`select`', Type::getType('string'), ['default' => 'foo'])]), + [ 'CREATE TABLE [table] ([select] NVARCHAR(255) NOT NULL)', - "ALTER TABLE [table] ADD CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'foo' FOR [select]" - ) - ), - ); + "ALTER TABLE [table] ADD CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'foo' FOR [select]", + ], + ], + ]; } /** @@ -1198,104 +1196,104 @@ public function testGeneratesIdentifierNamesInAlterTableSQL($tableDiff, $expecte public function getGeneratesIdentifierNamesInAlterTableSQL() { - return array( + return [ // Unquoted identifiers non-reserved keywords. - array( + [ new TableDiff( 'mytable', - array(new Column('addcolumn', Type::getType('string'), array('default' => 'foo'))), - array( + [new Column('addcolumn', Type::getType('string'), ['default' => 'foo'])], + [ 'mycolumn' => new ColumnDiff( 'mycolumn', - new Column('mycolumn', Type::getType('string'), array('default' => 'bar')), - array('default'), - new Column('mycolumn', Type::getType('string'), array('default' => 'foo')) - ) - ), - array(new Column('removecolumn', Type::getType('string'), array('default' => 'foo'))) + new Column('mycolumn', Type::getType('string'), ['default' => 'bar']), + ['default'], + new Column('mycolumn', Type::getType('string'), ['default' => 'foo']) + ), + ], + [new Column('removecolumn', Type::getType('string'), ['default' => 'foo'])] ), - array( + [ 'ALTER TABLE mytable ADD addcolumn NVARCHAR(255) NOT NULL', "ALTER TABLE mytable ADD CONSTRAINT DF_6B2BD609_4AD86123 DEFAULT 'foo' FOR addcolumn", 'ALTER TABLE mytable DROP COLUMN removecolumn', 'ALTER TABLE mytable DROP CONSTRAINT DF_6B2BD609_9BADD926', 'ALTER TABLE mytable ALTER COLUMN mycolumn NVARCHAR(255) NOT NULL', - "ALTER TABLE mytable ADD CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'bar' FOR mycolumn" - ) - ), + "ALTER TABLE mytable ADD CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'bar' FOR mycolumn", + ], + ], // Quoted identifiers non-reserved keywords. - array( + [ new TableDiff( '`mytable`', - array(new Column('`addcolumn`', Type::getType('string'), array('default' => 'foo'))), - array( + [new Column('`addcolumn`', Type::getType('string'), ['default' => 'foo'])], + [ 'mycolumn' => new ColumnDiff( '`mycolumn`', - new Column('`mycolumn`', Type::getType('string'), array('default' => 'bar')), - array('default'), - new Column('`mycolumn`', Type::getType('string'), array('default' => 'foo')) - ) - ), - array(new Column('`removecolumn`', Type::getType('string'), array('default' => 'foo'))) + new Column('`mycolumn`', Type::getType('string'), ['default' => 'bar']), + ['default'], + new Column('`mycolumn`', Type::getType('string'), ['default' => 'foo']) + ), + ], + [new Column('`removecolumn`', Type::getType('string'), ['default' => 'foo'])] ), - array( + [ 'ALTER TABLE [mytable] ADD [addcolumn] NVARCHAR(255) NOT NULL', "ALTER TABLE [mytable] ADD CONSTRAINT DF_6B2BD609_4AD86123 DEFAULT 'foo' FOR [addcolumn]", 'ALTER TABLE [mytable] DROP COLUMN [removecolumn]', 'ALTER TABLE [mytable] DROP CONSTRAINT DF_6B2BD609_9BADD926', 'ALTER TABLE [mytable] ALTER COLUMN [mycolumn] NVARCHAR(255) NOT NULL', - "ALTER TABLE [mytable] ADD CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'bar' FOR [mycolumn]" - ) - ), + "ALTER TABLE [mytable] ADD CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'bar' FOR [mycolumn]", + ], + ], // Unquoted identifiers reserved keywords. - array( + [ new TableDiff( 'table', - array(new Column('add', Type::getType('string'), array('default' => 'foo'))), - array( + [new Column('add', Type::getType('string'), ['default' => 'foo'])], + [ 'select' => new ColumnDiff( 'select', - new Column('select', Type::getType('string'), array('default' => 'bar')), - array('default'), - new Column('select', Type::getType('string'), array('default' => 'foo')) - ) - ), - array(new Column('drop', Type::getType('string'), array('default' => 'foo'))) + new Column('select', Type::getType('string'), ['default' => 'bar']), + ['default'], + new Column('select', Type::getType('string'), ['default' => 'foo']) + ), + ], + [new Column('drop', Type::getType('string'), ['default' => 'foo'])] ), - array( + [ 'ALTER TABLE [table] ADD [add] NVARCHAR(255) NOT NULL', "ALTER TABLE [table] ADD CONSTRAINT DF_F6298F46_FD1A73E7 DEFAULT 'foo' FOR [add]", 'ALTER TABLE [table] DROP COLUMN [drop]', 'ALTER TABLE [table] DROP CONSTRAINT DF_F6298F46_4BF2EAC0', 'ALTER TABLE [table] ALTER COLUMN [select] NVARCHAR(255) NOT NULL', - "ALTER TABLE [table] ADD CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'bar' FOR [select]" - ) - ), + "ALTER TABLE [table] ADD CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'bar' FOR [select]", + ], + ], // Quoted identifiers reserved keywords. - array( + [ new TableDiff( '`table`', - array(new Column('`add`', Type::getType('string'), array('default' => 'foo'))), - array( + [new Column('`add`', Type::getType('string'), ['default' => 'foo'])], + [ 'select' => new ColumnDiff( '`select`', - new Column('`select`', Type::getType('string'), array('default' => 'bar')), - array('default'), - new Column('`select`', Type::getType('string'), array('default' => 'foo')) - ) - ), - array(new Column('`drop`', Type::getType('string'), array('default' => 'foo'))) + new Column('`select`', Type::getType('string'), ['default' => 'bar']), + ['default'], + new Column('`select`', Type::getType('string'), ['default' => 'foo']) + ), + ], + [new Column('`drop`', Type::getType('string'), ['default' => 'foo'])] ), - array( + [ 'ALTER TABLE [table] ADD [add] NVARCHAR(255) NOT NULL', "ALTER TABLE [table] ADD CONSTRAINT DF_F6298F46_FD1A73E7 DEFAULT 'foo' FOR [add]", 'ALTER TABLE [table] DROP COLUMN [drop]', 'ALTER TABLE [table] DROP CONSTRAINT DF_F6298F46_4BF2EAC0', 'ALTER TABLE [table] ALTER COLUMN [select] NVARCHAR(255) NOT NULL', - "ALTER TABLE [table] ADD CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'bar' FOR [select]" - ) - ), - ); + "ALTER TABLE [table] ADD CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'bar' FOR [select]", + ], + ], + ]; } /** @@ -1303,7 +1301,7 @@ public function getGeneratesIdentifierNamesInAlterTableSQL() */ public function testReturnsGuidTypeDeclarationSQL() { - self::assertSame('UNIQUEIDENTIFIER', $this->_platform->getGuidTypeDeclarationSQL(array())); + self::assertSame('UNIQUEIDENTIFIER', $this->_platform->getGuidTypeDeclarationSQL([])); } /** @@ -1311,11 +1309,11 @@ public function testReturnsGuidTypeDeclarationSQL() */ public function getAlterTableRenameColumnSQL() { - return array( + return [ "sp_RENAME 'foo.bar', 'baz', 'COLUMN'", 'ALTER TABLE foo DROP CONSTRAINT DF_8C736521_76FF8CAA', 'ALTER TABLE foo ADD CONSTRAINT DF_8C736521_78240498 DEFAULT 666 FOR baz', - ); + ]; } /** @@ -1323,7 +1321,7 @@ public function getAlterTableRenameColumnSQL() */ protected function getQuotesTableIdentifiersInAlterTableSQL() { - return array( + return [ 'ALTER TABLE [foo] DROP CONSTRAINT fk1', 'ALTER TABLE [foo] DROP CONSTRAINT fk2', "sp_RENAME '[foo].id', 'war', 'COLUMN'", @@ -1337,7 +1335,7 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() "WHERE tbl.name = 'table';EXEC sp_executesql @sql", 'ALTER TABLE [table] ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id)', 'ALTER TABLE [table] ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)', - ); + ]; } /** @@ -1345,11 +1343,11 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() */ protected function getCommentOnColumnSQL() { - return array( + return [ "COMMENT ON COLUMN foo.bar IS 'comment'", "COMMENT ON COLUMN [Foo].[BAR] IS 'comment'", "COMMENT ON COLUMN [select].[from] IS 'comment'", - ); + ]; } /** @@ -1357,14 +1355,14 @@ protected function getCommentOnColumnSQL() */ public function getReturnsForeignKeyReferentialActionSQL() { - return array( - array('CASCADE', 'CASCADE'), - array('SET NULL', 'SET NULL'), - array('NO ACTION', 'NO ACTION'), - array('RESTRICT', 'NO ACTION'), - array('SET DEFAULT', 'SET DEFAULT'), - array('CaScAdE', 'CASCADE'), - ); + return [ + ['CASCADE', 'CASCADE'], + ['SET NULL', 'SET NULL'], + ['NO ACTION', 'NO ACTION'], + ['RESTRICT', 'NO ACTION'], + ['SET DEFAULT', 'SET DEFAULT'], + ['CaScAdE', 'CASCADE'], + ]; } /** @@ -1396,9 +1394,7 @@ protected function getQuotesReservedKeywordInTruncateTableSQL() */ protected function getAlterStringToFixedStringSQL() { - return array( - 'ALTER TABLE mytable ALTER COLUMN name NCHAR(2) NOT NULL', - ); + return ['ALTER TABLE mytable ALTER COLUMN name NCHAR(2) NOT NULL']; } /** @@ -1406,21 +1402,19 @@ protected function getAlterStringToFixedStringSQL() */ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() { - return array( - "EXEC sp_RENAME N'mytable.idx_foo', N'idx_foo_renamed', N'INDEX'", - ); + return ["EXEC sp_RENAME N'mytable.idx_foo', N'idx_foo_renamed', N'INDEX'"]; } public function testModifyLimitQueryWithTopNSubQueryWithOrderBy() { - $querySql = 'SELECT * FROM test t WHERE t.id = (SELECT TOP 1 t2.id FROM test t2 ORDER BY t2.data DESC)'; + $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)'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->_platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); - $querySql = 'SELECT * FROM test t WHERE t.id = (SELECT TOP 1 t2.id FROM test t2 ORDER BY t2.data DESC) ORDER BY t.data2 DESC'; + $querySql = 'SELECT * FROM test t WHERE t.id = (SELECT TOP 1 t2.id FROM test t2 ORDER BY t2.data DESC) ORDER BY t.data2 DESC'; $alteredSql = 'SELECT TOP 10 * FROM test t WHERE t.id = (SELECT TOP 1 t2.id FROM test t2 ORDER BY t2.data DESC) ORDER BY t.data2 DESC'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->_platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php index 5373b3f640d..841021b9653 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php @@ -13,9 +13,7 @@ class DB2PlatformTest extends AbstractPlatformTestCase { - /** - * @var \Doctrine\DBAL\Platforms\DB2Platform - */ + /** @var DB2Platform */ protected $_platform; public function createPlatform() @@ -25,19 +23,19 @@ public function createPlatform() public function getGenerateAlterTableSql() { - return array( - "ALTER TABLE mytable ALTER COLUMN baz SET DATA TYPE VARCHAR(255)", - "ALTER TABLE mytable ALTER COLUMN baz SET NOT NULL", + return [ + 'ALTER TABLE mytable ALTER COLUMN baz SET DATA TYPE VARCHAR(255)', + 'ALTER TABLE mytable ALTER COLUMN baz SET NOT NULL', "ALTER TABLE mytable ALTER COLUMN baz SET DEFAULT 'def'", - "ALTER TABLE mytable ALTER COLUMN bloo SET DATA TYPE SMALLINT", - "ALTER TABLE mytable ALTER COLUMN bloo SET NOT NULL", + 'ALTER TABLE mytable ALTER COLUMN bloo SET DATA TYPE SMALLINT', + 'ALTER TABLE mytable ALTER COLUMN bloo SET NOT NULL', "ALTER TABLE mytable ALTER COLUMN bloo SET DEFAULT '0'", - "ALTER TABLE mytable " . - "ADD COLUMN quota INTEGER DEFAULT NULL " . - "DROP COLUMN foo", + 'ALTER TABLE mytable ' . + 'ADD COLUMN quota INTEGER DEFAULT NULL ' . + 'DROP COLUMN foo', "CALL SYSPROC.ADMIN_CMD ('REORG TABLE mytable')", 'RENAME TABLE mytable TO userlist', - ); + ]; } public function getGenerateForeignKeySql() @@ -57,10 +55,10 @@ public function getGenerateTableSql() public function getGenerateTableWithMultiColumnUniqueIndexSql() { - return array( + return [ 'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL)', - 'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)' - ); + 'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)', + ]; } public function getGenerateUniqueIndexSql() @@ -70,35 +68,33 @@ public function getGenerateUniqueIndexSql() protected function getQuotedColumnInForeignKeySQL() { - return array( + return [ 'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, foo VARCHAR(255) NOT NULL, "bar" VARCHAR(255) NOT NULL)', '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")', - ); + ]; } protected function getQuotedColumnInIndexSQL() { - return array( + return [ 'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL)', - 'CREATE INDEX IDX_22660D028FD6E0FB ON "quoted" ("create")' - ); + 'CREATE INDEX IDX_22660D028FD6E0FB ON "quoted" ("create")', + ]; } protected function getQuotedNameInIndexSQL() { - return array( + return [ 'CREATE TABLE test (column1 VARCHAR(255) NOT NULL)', 'CREATE INDEX "key" ON test (column1)', - ); + ]; } protected function getQuotedColumnInPrimaryKeySQL() { - return array( - 'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, PRIMARY KEY("create"))' - ); + return ['CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, PRIMARY KEY("create"))']; } protected function getBitAndComparisonExpressionSql($value1, $value2) @@ -106,37 +102,37 @@ protected function getBitAndComparisonExpressionSql($value1, $value2) return 'BITAND(' . $value1 . ', ' . $value2 . ')'; } - protected function getBitOrComparisonExpressionSql($value1, $value2) + protected function getBitOrComparisonExpressionSql($value1, $value2) { return 'BITOR(' . $value1 . ', ' . $value2 . ')'; } public function getCreateTableColumnCommentsSQL() { - return array( - "CREATE TABLE test (id INTEGER NOT NULL, PRIMARY KEY(id))", + return [ + 'CREATE TABLE test (id INTEGER NOT NULL, PRIMARY KEY(id))', "COMMENT ON COLUMN test.id IS 'This is a comment'", - ); + ]; } public function getAlterTableColumnCommentsSQL() { - return array( - "ALTER TABLE mytable " . - "ADD COLUMN quota INTEGER NOT NULL WITH DEFAULT", + return [ + 'ALTER TABLE mytable ' . + 'ADD COLUMN quota INTEGER NOT NULL WITH DEFAULT', "CALL SYSPROC.ADMIN_CMD ('REORG TABLE mytable')", "COMMENT ON COLUMN mytable.quota IS 'A comment'", "COMMENT ON COLUMN mytable.foo IS ''", "COMMENT ON COLUMN mytable.baz IS 'B comment'", - ); + ]; } public function getCreateTableColumnTypeCommentsSQL() { - return array( + return [ 'CREATE TABLE test (id INTEGER NOT NULL, "data" CLOB(1M) NOT NULL, PRIMARY KEY(id))', 'COMMENT ON COLUMN test."data" IS \'(DC2Type:array)\'', - ); + ]; } public function testHasCorrectPlatformName() @@ -148,17 +144,17 @@ public function testGeneratesCreateTableSQLWithCommonIndexes() { $table = new Table('test'); $table->addColumn('id', 'integer'); - $table->addColumn('name', 'string', array('length' => 50)); - $table->setPrimaryKey(array('id')); - $table->addIndex(array('name')); - $table->addIndex(array('id', 'name'), 'composite_idx'); + $table->addColumn('name', 'string', ['length' => 50]); + $table->setPrimaryKey(['id']); + $table->addIndex(['name']); + $table->addIndex(['id', 'name'], 'composite_idx'); self::assertEquals( - array( + [ 'CREATE TABLE test (id INTEGER NOT NULL, name VARCHAR(50) NOT NULL, PRIMARY KEY(id))', 'CREATE INDEX IDX_D87F7E0C5E237E06 ON test (name)', - 'CREATE INDEX composite_idx ON test (id, name)' - ), + 'CREATE INDEX composite_idx ON test (id, name)', + ], $this->_platform->getCreateTableSQL($table) ); } @@ -169,22 +165,22 @@ public function testGeneratesCreateTableSQLWithForeignKeyConstraints() $table->addColumn('id', 'integer'); $table->addColumn('fk_1', 'integer'); $table->addColumn('fk_2', 'integer'); - $table->setPrimaryKey(array('id')); - $table->addForeignKeyConstraint('foreign_table', array('fk_1', 'fk_2'), array('pk_1', 'pk_2')); + $table->setPrimaryKey(['id']); + $table->addForeignKeyConstraint('foreign_table', ['fk_1', 'fk_2'], ['pk_1', 'pk_2']); $table->addForeignKeyConstraint( 'foreign_table2', - array('fk_1', 'fk_2'), - array('pk_1', 'pk_2'), - array(), + ['fk_1', 'fk_2'], + ['pk_1', 'pk_2'], + [], 'named_fk' ); self::assertEquals( - array( + [ 'CREATE TABLE test (id INTEGER NOT NULL, fk_1 INTEGER NOT NULL, fk_2 INTEGER NOT NULL)', 'ALTER TABLE test ADD CONSTRAINT FK_D87F7E0C177612A38E7F4319 FOREIGN KEY (fk_1, fk_2) REFERENCES foreign_table (pk_1, pk_2)', 'ALTER TABLE test ADD CONSTRAINT named_fk FOREIGN KEY (fk_1, fk_2) REFERENCES foreign_table2 (pk_1, pk_2)', - ), + ], $this->_platform->getCreateTableSQL($table, AbstractPlatform::CREATE_FOREIGNKEYS) ); } @@ -193,52 +189,44 @@ public function testGeneratesCreateTableSQLWithCheckConstraints() { $table = new Table('test'); $table->addColumn('id', 'integer'); - $table->addColumn('check_max', 'integer', array('platformOptions' => array('max' => 10))); - $table->addColumn('check_min', 'integer', array('platformOptions' => array('min' => 10))); - $table->setPrimaryKey(array('id')); + $table->addColumn('check_max', 'integer', ['platformOptions' => ['max' => 10]]); + $table->addColumn('check_min', 'integer', ['platformOptions' => ['min' => 10]]); + $table->setPrimaryKey(['id']); self::assertEquals( - array( - 'CREATE TABLE test (id INTEGER NOT NULL, check_max INTEGER NOT NULL, check_min INTEGER NOT NULL, PRIMARY KEY(id), CHECK (check_max <= 10), CHECK (check_min >= 10))' - ), + ['CREATE TABLE test (id INTEGER NOT NULL, check_max INTEGER NOT NULL, check_min INTEGER NOT NULL, PRIMARY KEY(id), CHECK (check_max <= 10), CHECK (check_min >= 10))'], $this->_platform->getCreateTableSQL($table) ); } public function testGeneratesColumnTypesDeclarationSQL() { - $fullColumnDef = array( + $fullColumnDef = [ 'length' => 10, 'fixed' => true, 'unsigned' => true, - 'autoincrement' => true - ); + 'autoincrement' => true, + ]; - self::assertEquals('VARCHAR(255)', $this->_platform->getVarcharTypeDeclarationSQL(array())); - self::assertEquals('VARCHAR(10)', $this->_platform->getVarcharTypeDeclarationSQL(array('length' => 10))); + self::assertEquals('VARCHAR(255)', $this->_platform->getVarcharTypeDeclarationSQL([])); + self::assertEquals('VARCHAR(10)', $this->_platform->getVarcharTypeDeclarationSQL(['length' => 10])); self::assertEquals('CHAR(254)', $this->_platform->getVarcharTypeDeclarationSQL(['fixed' => true])); self::assertEquals('CHAR(10)', $this->_platform->getVarcharTypeDeclarationSQL($fullColumnDef)); - self::assertEquals('SMALLINT', $this->_platform->getSmallIntTypeDeclarationSQL(array())); - self::assertEquals('SMALLINT', $this->_platform->getSmallIntTypeDeclarationSQL(array( - 'unsigned' => true - ))); + self::assertEquals('SMALLINT', $this->_platform->getSmallIntTypeDeclarationSQL([])); + self::assertEquals('SMALLINT', $this->_platform->getSmallIntTypeDeclarationSQL(['unsigned' => true])); self::assertEquals('SMALLINT GENERATED BY DEFAULT AS IDENTITY', $this->_platform->getSmallIntTypeDeclarationSQL($fullColumnDef)); - self::assertEquals('INTEGER', $this->_platform->getIntegerTypeDeclarationSQL(array())); - self::assertEquals('INTEGER', $this->_platform->getIntegerTypeDeclarationSQL(array( - 'unsigned' => true - ))); + self::assertEquals('INTEGER', $this->_platform->getIntegerTypeDeclarationSQL([])); + self::assertEquals('INTEGER', $this->_platform->getIntegerTypeDeclarationSQL(['unsigned' => true])); self::assertEquals('INTEGER GENERATED BY DEFAULT AS IDENTITY', $this->_platform->getIntegerTypeDeclarationSQL($fullColumnDef)); - self::assertEquals('BIGINT', $this->_platform->getBigIntTypeDeclarationSQL(array())); - self::assertEquals('BIGINT', $this->_platform->getBigIntTypeDeclarationSQL(array( - 'unsigned' => true - ))); + self::assertEquals('BIGINT', $this->_platform->getBigIntTypeDeclarationSQL([])); + self::assertEquals('BIGINT', $this->_platform->getBigIntTypeDeclarationSQL(['unsigned' => true])); self::assertEquals('BIGINT GENERATED BY DEFAULT AS IDENTITY', $this->_platform->getBigIntTypeDeclarationSQL($fullColumnDef)); self::assertEquals('BLOB(1M)', $this->_platform->getBlobTypeDeclarationSQL($fullColumnDef)); self::assertEquals('SMALLINT', $this->_platform->getBooleanTypeDeclarationSQL($fullColumnDef)); self::assertEquals('CLOB(1M)', $this->_platform->getClobTypeDeclarationSQL($fullColumnDef)); self::assertEquals('DATE', $this->_platform->getDateTypeDeclarationSQL($fullColumnDef)); - self::assertEquals('TIMESTAMP(0) WITH DEFAULT', $this->_platform->getDateTimeTypeDeclarationSQL(array('version' => true))); + self::assertEquals('TIMESTAMP(0) WITH DEFAULT', $this->_platform->getDateTimeTypeDeclarationSQL(['version' => true])); self::assertEquals('TIMESTAMP(0)', $this->_platform->getDateTimeTypeDeclarationSQL($fullColumnDef)); self::assertEquals('TIME', $this->_platform->getTimeTypeDeclarationSQL($fullColumnDef)); } @@ -291,15 +279,15 @@ public function getIsCommentedDoctrineType() { $data = parent::getIsCommentedDoctrineType(); - $data[Type::BOOLEAN] = array(Type::getType(Type::BOOLEAN), true); + $data[Type::BOOLEAN] = [Type::getType(Type::BOOLEAN), true]; return $data; } public function testGeneratesDDLSnippets() { - self::assertEquals("CREATE DATABASE foobar", $this->_platform->getCreateDatabaseSQL('foobar')); - self::assertEquals("DROP DATABASE foobar", $this->_platform->getDropDatabaseSQL('foobar')); + self::assertEquals('CREATE DATABASE foobar', $this->_platform->getCreateDatabaseSQL('foobar')); + self::assertEquals('DROP DATABASE foobar', $this->_platform->getDropDatabaseSQL('foobar')); self::assertEquals('DECLARE GLOBAL TEMPORARY TABLE', $this->_platform->getCreateTemporaryTableSnippetSQL()); self::assertEquals('TRUNCATE foobar IMMEDIATE', $this->_platform->getTruncateTableSQL('foobar')); self::assertEquals('TRUNCATE foobar IMMEDIATE', $this->_platform->getTruncateTableSQL('foobar'), true); @@ -314,7 +302,7 @@ public function testGeneratesCreateUnnamedPrimaryKeySQL() self::assertEquals( 'ALTER TABLE foo ADD PRIMARY KEY (a, b)', $this->_platform->getCreatePrimaryKeySQL( - new Index('any_pk_name', array('a', 'b'), true, true), + new Index('any_pk_name', ['a', 'b'], true, true), 'foo' ) ); @@ -442,9 +430,7 @@ public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() */ protected function getAlterTableRenameIndexSQL() { - return array( - 'RENAME INDEX idx_foo TO idx_bar', - ); + return ['RENAME INDEX idx_foo TO idx_bar']; } /** @@ -452,10 +438,10 @@ protected function getAlterTableRenameIndexSQL() */ protected function getQuotedAlterTableRenameIndexSQL() { - return array( + return [ 'RENAME INDEX "create" TO "select"', 'RENAME INDEX "foo" TO "bar"', - ); + ]; } /** @@ -463,8 +449,7 @@ protected function getQuotedAlterTableRenameIndexSQL() */ protected function getQuotedAlterTableRenameColumnSQL() { - return array( - 'ALTER TABLE mytable ' . + return ['ALTER TABLE mytable ' . 'RENAME COLUMN unquoted1 TO unquoted ' . 'RENAME COLUMN unquoted2 TO "where" ' . 'RENAME COLUMN unquoted3 TO "foo" ' . @@ -473,8 +458,8 @@ protected function getQuotedAlterTableRenameColumnSQL() 'RENAME COLUMN "select" TO "bar" ' . 'RENAME COLUMN quoted1 TO quoted ' . 'RENAME COLUMN quoted2 TO "and" ' . - 'RENAME COLUMN quoted3 TO "baz"' - ); + 'RENAME COLUMN quoted3 TO "baz"', + ]; } /** @@ -490,9 +475,7 @@ protected function getQuotedAlterTableChangeColumnLengthSQL() */ protected function getAlterTableRenameIndexInSchemaSQL() { - return array( - 'RENAME INDEX myschema.idx_foo TO idx_bar', - ); + return ['RENAME INDEX myschema.idx_foo TO idx_bar']; } /** @@ -500,10 +483,10 @@ protected function getAlterTableRenameIndexInSchemaSQL() */ protected function getQuotedAlterTableRenameIndexInSchemaSQL() { - return array( + return [ 'RENAME INDEX "schema"."create" TO "select"', 'RENAME INDEX "schema"."foo" TO "bar"', - ); + ]; } /** @@ -511,7 +494,7 @@ protected function getQuotedAlterTableRenameIndexInSchemaSQL() */ public function testReturnsGuidTypeDeclarationSQL() { - self::assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL(array())); + self::assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL([])); } /** @@ -519,9 +502,7 @@ public function testReturnsGuidTypeDeclarationSQL() */ public function getAlterTableRenameColumnSQL() { - return array( - 'ALTER TABLE foo RENAME COLUMN bar TO baz', - ); + return ['ALTER TABLE foo RENAME COLUMN bar TO baz']; } /** @@ -529,7 +510,7 @@ public function getAlterTableRenameColumnSQL() */ protected function getQuotesTableIdentifiersInAlterTableSQL() { - return array( + return [ 'ALTER TABLE "foo" DROP FOREIGN KEY fk1', 'ALTER TABLE "foo" DROP FOREIGN KEY fk2', 'ALTER TABLE "foo" ' . @@ -541,7 +522,7 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() 'RENAME TABLE "foo" TO "table"', 'ALTER TABLE "table" ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id)', 'ALTER TABLE "table" ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)', - ); + ]; } /** @@ -549,27 +530,26 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() */ protected function getCommentOnColumnSQL() { - return array( + return [ 'COMMENT ON COLUMN foo.bar IS \'comment\'', 'COMMENT ON COLUMN "Foo"."BAR" IS \'comment\'', 'COMMENT ON COLUMN "select"."from" IS \'comment\'', - ); + ]; } /** * @group DBAL-944 - * * @dataProvider getGeneratesAlterColumnSQL */ public function testGeneratesAlterColumnSQL($changedProperty, Column $column, $expectedSQLClause = null) { - $tableDiff = new TableDiff('foo'); - $tableDiff->fromTable = new Table('foo'); - $tableDiff->changedColumns['bar'] = new ColumnDiff('bar', $column, array($changedProperty)); + $tableDiff = new TableDiff('foo'); + $tableDiff->fromTable = new Table('foo'); + $tableDiff->changedColumns['bar'] = new ColumnDiff('bar', $column, [$changedProperty]); - $expectedSQL = array(); + $expectedSQL = []; - if (null !== $expectedSQLClause) { + if ($expectedSQLClause !== null) { $expectedSQL[] = 'ALTER TABLE foo ALTER COLUMN bar ' . $expectedSQLClause; } @@ -583,63 +563,63 @@ public function testGeneratesAlterColumnSQL($changedProperty, Column $column, $e */ public function getGeneratesAlterColumnSQL() { - return array( - array( + return [ + [ 'columnDefinition', - new Column('bar', Type::getType('decimal'), array('columnDefinition' => 'MONEY NOT NULL')), - 'MONEY NOT NULL' - ), - array( + new Column('bar', Type::getType('decimal'), ['columnDefinition' => 'MONEY NOT NULL']), + 'MONEY NOT NULL', + ], + [ 'type', new Column('bar', Type::getType('integer')), - 'SET DATA TYPE INTEGER' - ), - array( + 'SET DATA TYPE INTEGER', + ], + [ 'length', - new Column('bar', Type::getType('string'), array('length' => 100)), - 'SET DATA TYPE VARCHAR(100)' - ), - array( + new Column('bar', Type::getType('string'), ['length' => 100]), + 'SET DATA TYPE VARCHAR(100)', + ], + [ 'precision', - new Column('bar', Type::getType('decimal'), array('precision' => 10, 'scale' => 2)), - 'SET DATA TYPE NUMERIC(10, 2)' - ), - array( + new Column('bar', Type::getType('decimal'), ['precision' => 10, 'scale' => 2]), + 'SET DATA TYPE NUMERIC(10, 2)', + ], + [ 'scale', - new Column('bar', Type::getType('decimal'), array('precision' => 5, 'scale' => 4)), - 'SET DATA TYPE NUMERIC(5, 4)' - ), - array( + new Column('bar', Type::getType('decimal'), ['precision' => 5, 'scale' => 4]), + 'SET DATA TYPE NUMERIC(5, 4)', + ], + [ 'fixed', - new Column('bar', Type::getType('string'), array('length' => 20, 'fixed' => true)), - 'SET DATA TYPE CHAR(20)' - ), - array( + new Column('bar', Type::getType('string'), ['length' => 20, 'fixed' => true]), + 'SET DATA TYPE CHAR(20)', + ], + [ 'notnull', - new Column('bar', Type::getType('string'), array('notnull' => true)), - 'SET NOT NULL' - ), - array( + new Column('bar', Type::getType('string'), ['notnull' => true]), + 'SET NOT NULL', + ], + [ 'notnull', - new Column('bar', Type::getType('string'), array('notnull' => false)), - 'DROP NOT NULL' - ), - array( + new Column('bar', Type::getType('string'), ['notnull' => false]), + 'DROP NOT NULL', + ], + [ 'default', - new Column('bar', Type::getType('string'), array('default' => 'foo')), - "SET DEFAULT 'foo'" - ), - array( + new Column('bar', Type::getType('string'), ['default' => 'foo']), + "SET DEFAULT 'foo'", + ], + [ 'default', - new Column('bar', Type::getType('integer'), array('autoincrement' => true, 'default' => 666)), - null - ), - array( + new Column('bar', Type::getType('integer'), ['autoincrement' => true, 'default' => 666]), + null, + ], + [ 'default', new Column('bar', Type::getType('string')), - "DROP DEFAULT" - ), - ); + 'DROP DEFAULT', + ], + ]; } /** @@ -687,10 +667,10 @@ protected function supportsCommentOnStatement() */ protected function getAlterStringToFixedStringSQL() { - return array( + return [ 'ALTER TABLE mytable ALTER COLUMN name SET DATA TYPE CHAR(2)', 'CALL SYSPROC.ADMIN_CMD (\'REORG TABLE mytable\')', - ); + ]; } /** @@ -698,9 +678,7 @@ protected function getAlterStringToFixedStringSQL() */ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() { - return array( - 'RENAME INDEX idx_foo TO idx_foo_renamed', - ); + return ['RENAME INDEX idx_foo TO idx_foo_renamed']; } /** diff --git a/tests/Doctrine/Tests/DBAL/Platforms/MariaDb1027PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/MariaDb1027PlatformTest.php index 138a55ef714..95938f477c1 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/MariaDb1027PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/MariaDb1027PlatformTest.php @@ -22,6 +22,7 @@ public function testHasNativeJsonType() : void /** * From MariaDB 10.2.7, JSON type is an alias to LONGTEXT + * * @link https://mariadb.com/kb/en/library/json-data-type/ */ public function testReturnsJsonTypeDeclarationSQL() : void diff --git a/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php index 2ea04fe75a8..bef9aa6a545 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php @@ -22,7 +22,7 @@ public function testHasNativeJsonType() public function testReturnsJsonTypeDeclarationSQL() { - self::assertSame('JSON', $this->_platform->getJsonTypeDeclarationSQL(array())); + self::assertSame('JSON', $this->_platform->getJsonTypeDeclarationSQL([])); } public function testInitializesJsonTypeMapping() @@ -36,9 +36,7 @@ public function testInitializesJsonTypeMapping() */ protected function getAlterTableRenameIndexSQL() { - return array( - 'ALTER TABLE mytable RENAME INDEX idx_foo TO idx_bar', - ); + return ['ALTER TABLE mytable RENAME INDEX idx_foo TO idx_bar']; } /** @@ -46,10 +44,10 @@ protected function getAlterTableRenameIndexSQL() */ protected function getQuotedAlterTableRenameIndexSQL() { - return array( + return [ 'ALTER TABLE `table` RENAME INDEX `create` TO `select`', 'ALTER TABLE `table` RENAME INDEX `foo` TO `bar`', - ); + ]; } /** @@ -57,9 +55,7 @@ protected function getQuotedAlterTableRenameIndexSQL() */ protected function getAlterTableRenameIndexInSchemaSQL() { - return array( - 'ALTER TABLE myschema.mytable RENAME INDEX idx_foo TO idx_bar', - ); + return ['ALTER TABLE myschema.mytable RENAME INDEX idx_foo TO idx_bar']; } /** @@ -67,10 +63,10 @@ protected function getAlterTableRenameIndexInSchemaSQL() */ protected function getQuotedAlterTableRenameIndexInSchemaSQL() { - return array( + return [ 'ALTER TABLE `schema`.`table` RENAME INDEX `create` TO `select`', 'ALTER TABLE `schema`.`table` RENAME INDEX `foo` TO `bar`', - ); + ]; } /** @@ -78,8 +74,6 @@ protected function getQuotedAlterTableRenameIndexInSchemaSQL() */ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() { - return array( - 'ALTER TABLE mytable RENAME INDEX idx_foo TO idx_foo_renamed', - ); + 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 2dc3a7ce28e..3372ef94051 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php @@ -9,7 +9,7 @@ class MySqlPlatformTest extends AbstractMySQLPlatformTestCase { public function createPlatform() { - return new MysqlPlatform; + return new MysqlPlatform(); } public function testHasCorrectDefaultTransactionIsolationLevel() diff --git a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php index 5e270b4a1e7..da210021a85 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php @@ -5,9 +5,12 @@ use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Schema\Column; +use Doctrine\DBAL\Schema\ColumnDiff; use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\ForeignKeyConstraint; +use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Table; +use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\TransactionIsolationLevel; use Doctrine\DBAL\Types\Type; use function array_walk; @@ -67,7 +70,7 @@ public function testInvalidIdentifiers($identifier) public function createPlatform() { - return new OraclePlatform; + return new OraclePlatform(); } public function getGenerateTableSql() @@ -77,20 +80,20 @@ public function getGenerateTableSql() public function getGenerateTableWithMultiColumnUniqueIndexSql() { - return array( + return [ 'CREATE TABLE test (foo VARCHAR2(255) DEFAULT NULL NULL, bar VARCHAR2(255) DEFAULT NULL NULL)', 'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)', - ); + ]; } public function getGenerateAlterTableSql() { - return array( + return [ 'ALTER TABLE mytable ADD (quota NUMBER(10) DEFAULT NULL NULL)', "ALTER TABLE mytable MODIFY (baz VARCHAR2(255) DEFAULT 'def' NOT NULL, bloo NUMBER(1) DEFAULT '0' NOT NULL)", - "ALTER TABLE mytable DROP (foo)", - "ALTER TABLE mytable RENAME TO userlist", - ); + 'ALTER TABLE mytable DROP (foo)', + 'ALTER TABLE mytable RENAME TO userlist', + ]; } /** @@ -149,17 +152,18 @@ public function testGeneratesTypeDeclarationForIntegers() { self::assertEquals( 'NUMBER(10)', - $this->_platform->getIntegerTypeDeclarationSQL(array()) + $this->_platform->getIntegerTypeDeclarationSQL([]) ); self::assertEquals( 'NUMBER(10)', - $this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true) - )); + $this->_platform->getIntegerTypeDeclarationSQL(['autoincrement' => true]) + ); self::assertEquals( 'NUMBER(10)', $this->_platform->getIntegerTypeDeclarationSQL( - array('autoincrement' => true, 'primary' => true) - )); + ['autoincrement' => true, 'primary' => true] + ) + ); } public function testGeneratesTypeDeclarationsForStrings() @@ -167,16 +171,17 @@ public function testGeneratesTypeDeclarationsForStrings() self::assertEquals( 'CHAR(10)', $this->_platform->getVarcharTypeDeclarationSQL( - array('length' => 10, 'fixed' => true) - )); + ['length' => 10, 'fixed' => true] + ) + ); self::assertEquals( 'VARCHAR2(50)', - $this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)), + $this->_platform->getVarcharTypeDeclarationSQL(['length' => 50]), 'Variable string declaration is not correct' ); self::assertEquals( 'VARCHAR2(255)', - $this->_platform->getVarcharTypeDeclarationSQL(array()), + $this->_platform->getVarcharTypeDeclarationSQL([]), 'Long string declaration is not correct' ); } @@ -221,12 +226,11 @@ public function getGenerateForeignKeySql() /** * @group DBAL-1097 - * * @dataProvider getGeneratesAdvancedForeignKeyOptionsSQLData */ public function testGeneratesAdvancedForeignKeyOptionsSQL(array $options, $expectedSql) { - $foreignKey = new ForeignKeyConstraint(array('foo'), 'foreign_table', array('bar'), null, $options); + $foreignKey = new ForeignKeyConstraint(['foo'], 'foreign_table', ['bar'], null, $options); self::assertSame($expectedSql, $this->_platform->getAdvancedForeignKeyOptionsSQL($foreignKey)); } @@ -236,14 +240,14 @@ public function testGeneratesAdvancedForeignKeyOptionsSQL(array $options, $expec */ public function getGeneratesAdvancedForeignKeyOptionsSQLData() { - return array( - array(array(), ''), - array(array('onUpdate' => 'CASCADE'), ''), - array(array('onDelete' => 'CASCADE'), ' ON DELETE CASCADE'), - array(array('onDelete' => 'NO ACTION'), ''), - array(array('onDelete' => 'RESTRICT'), ''), - array(array('onUpdate' => 'SET NULL', 'onDelete' => 'SET NULL'), ' ON DELETE SET NULL'), - ); + return [ + [[], ''], + [['onUpdate' => 'CASCADE'], ''], + [['onDelete' => 'CASCADE'], ' ON DELETE CASCADE'], + [['onDelete' => 'NO ACTION'], ''], + [['onDelete' => 'RESTRICT'], ''], + [['onUpdate' => 'SET NULL', 'onDelete' => 'SET NULL'], ' ON DELETE SET NULL'], + ]; } /** @@ -251,13 +255,13 @@ public function getGeneratesAdvancedForeignKeyOptionsSQLData() */ public function getReturnsForeignKeyReferentialActionSQL() { - return array( - array('CASCADE', 'CASCADE'), - array('SET NULL', 'SET NULL'), - array('NO ACTION', ''), - array('RESTRICT', ''), - array('CaScAdE', 'CASCADE'), - ); + return [ + ['CASCADE', 'CASCADE'], + ['SET NULL', 'SET NULL'], + ['NO ACTION', ''], + ['RESTRICT', ''], + ['CaScAdE', 'CASCADE'], + ]; } public function testModifyLimitQuery() @@ -299,56 +303,56 @@ public function testModifyLimitQueryWithDescOrderBy() public function testGenerateTableWithAutoincrement() { $columnName = strtoupper('id' . uniqid()); - $tableName = strtoupper('table' . uniqid()); - $table = new \Doctrine\DBAL\Schema\Table($tableName); - $column = $table->addColumn($columnName, 'integer'); + $tableName = strtoupper('table' . uniqid()); + $table = new Table($tableName); + $column = $table->addColumn($columnName, 'integer'); $column->setAutoincrement(true); - $targets = array( + $targets = [ "CREATE TABLE {$tableName} ({$columnName} NUMBER(10) NOT NULL)", "DECLARE constraints_Count NUMBER; BEGIN SELECT COUNT(CONSTRAINT_NAME) INTO constraints_Count FROM USER_CONSTRAINTS WHERE TABLE_NAME = '{$tableName}' AND CONSTRAINT_TYPE = 'P'; IF constraints_Count = 0 OR constraints_Count = '' THEN EXECUTE IMMEDIATE 'ALTER TABLE {$tableName} ADD CONSTRAINT {$tableName}_AI_PK PRIMARY KEY ({$columnName})'; END IF; END;", "CREATE SEQUENCE {$tableName}_SEQ START WITH 1 MINVALUE 1 INCREMENT BY 1", - "CREATE TRIGGER {$tableName}_AI_PK BEFORE INSERT ON {$tableName} FOR EACH ROW DECLARE last_Sequence NUMBER; last_InsertID NUMBER; BEGIN SELECT {$tableName}_SEQ.NEXTVAL INTO :NEW.{$columnName} FROM DUAL; IF (:NEW.{$columnName} IS NULL OR :NEW.{$columnName} = 0) THEN SELECT {$tableName}_SEQ.NEXTVAL INTO :NEW.{$columnName} FROM DUAL; ELSE SELECT NVL(Last_Number, 0) INTO last_Sequence FROM User_Sequences WHERE Sequence_Name = '{$tableName}_SEQ'; SELECT :NEW.{$columnName} INTO last_InsertID FROM DUAL; WHILE (last_InsertID > last_Sequence) LOOP SELECT {$tableName}_SEQ.NEXTVAL INTO last_Sequence FROM DUAL; END LOOP; END IF; END;" - ); + "CREATE TRIGGER {$tableName}_AI_PK BEFORE INSERT ON {$tableName} FOR EACH ROW DECLARE last_Sequence NUMBER; last_InsertID NUMBER; BEGIN SELECT {$tableName}_SEQ.NEXTVAL INTO :NEW.{$columnName} FROM DUAL; IF (:NEW.{$columnName} IS NULL OR :NEW.{$columnName} = 0) THEN SELECT {$tableName}_SEQ.NEXTVAL INTO :NEW.{$columnName} FROM DUAL; ELSE SELECT NVL(Last_Number, 0) INTO last_Sequence FROM User_Sequences WHERE Sequence_Name = '{$tableName}_SEQ'; SELECT :NEW.{$columnName} INTO last_InsertID FROM DUAL; WHILE (last_InsertID > last_Sequence) LOOP SELECT {$tableName}_SEQ.NEXTVAL INTO last_Sequence FROM DUAL; END LOOP; END IF; END;", + ]; $statements = $this->_platform->getCreateTableSQL($table); //strip all the whitespace from the statements - array_walk($statements, function(&$value){ - $value = preg_replace('/\s+/', ' ',$value); + array_walk($statements, static function (&$value) { + $value = preg_replace('/\s+/', ' ', $value); }); - foreach($targets as $key => $sql){ - self::assertArrayHasKey($key,$statements); + foreach ($targets as $key => $sql) { + self::assertArrayHasKey($key, $statements); self::assertEquals($sql, $statements[$key]); } } public function getCreateTableColumnCommentsSQL() { - return array( - "CREATE TABLE test (id NUMBER(10) NOT NULL, PRIMARY KEY(id))", + return [ + 'CREATE TABLE test (id NUMBER(10) NOT NULL, PRIMARY KEY(id))', "COMMENT ON COLUMN test.id IS 'This is a comment'", - ); + ]; } public function getCreateTableColumnTypeCommentsSQL() { - return array( - "CREATE TABLE test (id NUMBER(10) NOT NULL, data CLOB NOT NULL, PRIMARY KEY(id))", - "COMMENT ON COLUMN test.data IS '(DC2Type:array)'" - ); + return [ + 'CREATE TABLE test (id NUMBER(10) NOT NULL, data CLOB NOT NULL, PRIMARY KEY(id))', + "COMMENT ON COLUMN test.data IS '(DC2Type:array)'", + ]; } public function getAlterTableColumnCommentsSQL() { - return array( - "ALTER TABLE mytable ADD (quota NUMBER(10) NOT NULL)", + return [ + 'ALTER TABLE mytable ADD (quota NUMBER(10) NOT NULL)', "COMMENT ON COLUMN mytable.quota IS 'A comment'", "COMMENT ON COLUMN mytable.foo IS ''", "COMMENT ON COLUMN mytable.baz IS 'B comment'", - ); + ]; } public function getBitAndComparisonExpressionSql($value1, $value2) { - return 'BITAND('.$value1 . ', ' . $value2 . ')'; + return 'BITAND(' . $value1 . ', ' . $value2 . ')'; } public function getBitOrComparisonExpressionSql($value1, $value2) @@ -360,33 +364,33 @@ public function getBitOrComparisonExpressionSql($value1, $value2) protected function getQuotedColumnInPrimaryKeySQL() { - return array('CREATE TABLE "quoted" ("create" VARCHAR2(255) NOT NULL, PRIMARY KEY("create"))'); + return ['CREATE TABLE "quoted" ("create" VARCHAR2(255) NOT NULL, PRIMARY KEY("create"))']; } protected function getQuotedColumnInIndexSQL() { - return array( + return [ 'CREATE TABLE "quoted" ("create" VARCHAR2(255) NOT NULL)', 'CREATE INDEX IDX_22660D028FD6E0FB ON "quoted" ("create")', - ); + ]; } protected function getQuotedNameInIndexSQL() { - return array( + return [ 'CREATE TABLE test (column1 VARCHAR2(255) NOT NULL)', 'CREATE INDEX "key" ON test (column1)', - ); + ]; } protected function getQuotedColumnInForeignKeySQL() { - return array( + return [ 'CREATE TABLE "quoted" ("create" VARCHAR2(255) NOT NULL, foo VARCHAR2(255) NOT NULL, "bar" VARCHAR2(255) NOT NULL)', '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")', - ); + ]; } /** @@ -395,29 +399,36 @@ protected function getQuotedColumnInForeignKeySQL() */ public function testAlterTableNotNULL() { - $tableDiff = new \Doctrine\DBAL\Schema\TableDiff('mytable'); - $tableDiff->changedColumns['foo'] = new \Doctrine\DBAL\Schema\ColumnDiff( - 'foo', new \Doctrine\DBAL\Schema\Column( - 'foo', \Doctrine\DBAL\Types\Type::getType('string'), array('default' => 'bla', 'notnull' => true) + $tableDiff = new TableDiff('mytable'); + $tableDiff->changedColumns['foo'] = new ColumnDiff( + 'foo', + new Column( + 'foo', + Type::getType('string'), + ['default' => 'bla', 'notnull' => true] ), - array('type') - ); - $tableDiff->changedColumns['bar'] = new \Doctrine\DBAL\Schema\ColumnDiff( - 'bar', new \Doctrine\DBAL\Schema\Column( - 'baz', \Doctrine\DBAL\Types\Type::getType('string'), array('default' => 'bla', 'notnull' => true) + ['type'] + ); + $tableDiff->changedColumns['bar'] = new ColumnDiff( + 'bar', + new Column( + 'baz', + Type::getType('string'), + ['default' => 'bla', 'notnull' => true] ), - array('type', 'notnull') - ); - $tableDiff->changedColumns['metar'] = new \Doctrine\DBAL\Schema\ColumnDiff( - 'metar', new \Doctrine\DBAL\Schema\Column( - 'metar', \Doctrine\DBAL\Types\Type::getType('string'), array('length' => 2000, 'notnull' => false) + ['type', 'notnull'] + ); + $tableDiff->changedColumns['metar'] = new ColumnDiff( + 'metar', + new Column( + 'metar', + Type::getType('string'), + ['length' => 2000, 'notnull' => false] ), - array('notnull') + ['notnull'] ); - $expectedSql = array( - "ALTER TABLE mytable MODIFY (foo VARCHAR2(255) DEFAULT 'bla', baz VARCHAR2(255) DEFAULT 'bla' NOT NULL, metar VARCHAR2(2000) DEFAULT NULL NULL)", - ); + $expectedSql = ["ALTER TABLE mytable MODIFY (foo VARCHAR2(255) DEFAULT 'bla', baz VARCHAR2(255) DEFAULT 'bla' NOT NULL, metar VARCHAR2(2000) DEFAULT NULL NULL)"]; self::assertEquals($expectedSql, $this->_platform->getAlterTableSQL($tableDiff)); } @@ -443,13 +454,13 @@ protected function getBinaryMaxLength() public function testReturnsBinaryTypeDeclarationSQL() { - self::assertSame('RAW(255)', $this->_platform->getBinaryTypeDeclarationSQL(array())); - self::assertSame('RAW(2000)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 0))); - self::assertSame('RAW(2000)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 2000))); + self::assertSame('RAW(255)', $this->_platform->getBinaryTypeDeclarationSQL([])); + self::assertSame('RAW(2000)', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 0])); + self::assertSame('RAW(2000)', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 2000])); - self::assertSame('RAW(255)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true))); - self::assertSame('RAW(2000)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 0))); - self::assertSame('RAW(2000)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 2000))); + self::assertSame('RAW(255)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true])); + self::assertSame('RAW(2000)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 0])); + self::assertSame('RAW(2000)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 2000])); } /** @@ -466,10 +477,10 @@ public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType() { $table1 = new Table('mytable'); $table1->addColumn('column_varbinary', 'binary'); - $table1->addColumn('column_binary', 'binary', array('fixed' => true)); + $table1->addColumn('column_binary', 'binary', ['fixed' => true]); $table2 = new Table('mytable'); - $table2->addColumn('column_varbinary', 'binary', array('fixed' => true)); + $table2->addColumn('column_varbinary', 'binary', ['fixed' => true]); $table2->addColumn('column_binary', 'binary'); $comparator = new Comparator(); @@ -505,17 +516,17 @@ public function testReturnsIdentitySequenceName() */ public function testCreateSequenceWithCache($cacheSize, $expectedSql) { - $sequence = new \Doctrine\DBAL\Schema\Sequence('foo', 1, 1, $cacheSize); + $sequence = new Sequence('foo', 1, 1, $cacheSize); self::assertContains($expectedSql, $this->_platform->getCreateSequenceSQL($sequence)); } public function dataCreateSequenceWithCache() { - return array( - array(1, 'NOCACHE'), - array(0, 'NOCACHE'), - array(3, 'CACHE 3') - ); + return [ + [1, 'NOCACHE'], + [0, 'NOCACHE'], + [3, 'CACHE 3'], + ]; } /** @@ -523,9 +534,7 @@ public function dataCreateSequenceWithCache() */ protected function getAlterTableRenameIndexSQL() { - return array( - 'ALTER INDEX idx_foo RENAME TO idx_bar', - ); + return ['ALTER INDEX idx_foo RENAME TO idx_bar']; } /** @@ -533,10 +542,10 @@ protected function getAlterTableRenameIndexSQL() */ protected function getQuotedAlterTableRenameIndexSQL() { - return array( + return [ 'ALTER INDEX "create" RENAME TO "select"', 'ALTER INDEX "foo" RENAME TO "bar"', - ); + ]; } /** @@ -544,7 +553,7 @@ protected function getQuotedAlterTableRenameIndexSQL() */ protected function getQuotedAlterTableRenameColumnSQL() { - return array( + return [ 'ALTER TABLE mytable RENAME COLUMN unquoted1 TO unquoted', 'ALTER TABLE mytable RENAME COLUMN unquoted2 TO "where"', 'ALTER TABLE mytable RENAME COLUMN unquoted3 TO "foo"', @@ -554,7 +563,7 @@ protected function getQuotedAlterTableRenameColumnSQL() 'ALTER TABLE mytable RENAME COLUMN quoted1 TO quoted', 'ALTER TABLE mytable RENAME COLUMN quoted2 TO "and"', 'ALTER TABLE mytable RENAME COLUMN quoted3 TO "baz"', - ); + ]; } /** @@ -570,9 +579,7 @@ protected function getQuotedAlterTableChangeColumnLengthSQL() */ protected function getAlterTableRenameIndexInSchemaSQL() { - return array( - 'ALTER INDEX myschema.idx_foo RENAME TO idx_bar', - ); + return ['ALTER INDEX myschema.idx_foo RENAME TO idx_bar']; } /** @@ -580,10 +587,10 @@ protected function getAlterTableRenameIndexInSchemaSQL() */ protected function getQuotedAlterTableRenameIndexInSchemaSQL() { - return array( + return [ 'ALTER INDEX "schema"."create" RENAME TO "select"', 'ALTER INDEX "schema"."foo" RENAME TO "bar"', - ); + ]; } protected function getQuotesDropForeignKeySQL() @@ -596,7 +603,7 @@ protected function getQuotesDropForeignKeySQL() */ public function testReturnsGuidTypeDeclarationSQL() { - self::assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL(array())); + self::assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL([])); } /** @@ -604,9 +611,7 @@ public function testReturnsGuidTypeDeclarationSQL() */ public function getAlterTableRenameColumnSQL() { - return array( - 'ALTER TABLE foo RENAME COLUMN bar TO baz', - ); + return ['ALTER TABLE foo RENAME COLUMN bar TO baz']; } /** @@ -620,32 +625,32 @@ public function testReturnsDropAutoincrementSQL($table, $expectedSql) public function getReturnsDropAutoincrementSQL() { - return array( - array( + return [ + [ 'myTable', - array( + [ 'DROP TRIGGER MYTABLE_AI_PK', 'DROP SEQUENCE MYTABLE_SEQ', 'ALTER TABLE MYTABLE DROP CONSTRAINT MYTABLE_AI_PK', - ) - ), - array( + ], + ], + [ '"myTable"', - array( + [ 'DROP TRIGGER "myTable_AI_PK"', 'DROP SEQUENCE "myTable_SEQ"', 'ALTER TABLE "myTable" DROP CONSTRAINT "myTable_AI_PK"', - ) - ), - array( + ], + ], + [ 'table', - array( + [ 'DROP TRIGGER TABLE_AI_PK', 'DROP SEQUENCE TABLE_SEQ', 'ALTER TABLE "TABLE" DROP CONSTRAINT TABLE_AI_PK', - ) - ), - ); + ], + ], + ]; } /** @@ -653,7 +658,7 @@ public function getReturnsDropAutoincrementSQL() */ protected function getQuotesTableIdentifiersInAlterTableSQL() { - return array( + return [ 'ALTER TABLE "foo" DROP CONSTRAINT fk1', 'ALTER TABLE "foo" DROP CONSTRAINT fk2', 'ALTER TABLE "foo" ADD (bloo NUMBER(10) NOT NULL)', @@ -663,7 +668,7 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() 'ALTER TABLE "foo" RENAME TO "table"', 'ALTER TABLE "table" ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id)', 'ALTER TABLE "table" ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)', - ); + ]; } /** @@ -671,11 +676,11 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() */ protected function getCommentOnColumnSQL() { - return array( + return [ 'COMMENT ON COLUMN foo.bar IS \'comment\'', 'COMMENT ON COLUMN "Foo"."BAR" IS \'comment\'', 'COMMENT ON COLUMN "select"."from" IS \'comment\'', - ); + ]; } /** @@ -683,8 +688,8 @@ protected function getCommentOnColumnSQL() */ public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() { - $table1 = new Table('"foo"', array(new Column('"bar"', Type::getType('integer')))); - $table2 = new Table('"foo"', array(new Column('"bar"', Type::getType('integer'), array('comment' => 'baz')))); + $table1 = new Table('"foo"', [new Column('"bar"', Type::getType('integer'))]); + $table2 = new Table('"foo"', [new Column('"bar"', Type::getType('integer'), ['comment' => 'baz'])]); $comparator = new Comparator(); @@ -692,9 +697,7 @@ public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); self::assertSame( - array( - 'COMMENT ON COLUMN "foo"."bar" IS \'baz\'', - ), + ['COMMENT ON COLUMN "foo"."bar" IS \'baz\''], $this->_platform->getAlterTableSQL($tableDiff) ); } @@ -702,7 +705,7 @@ public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() public function testQuotedTableNames() { $table = new Table('"test"'); - $table->addColumn('"id"', 'integer', array('autoincrement' => true)); + $table->addColumn('"id"', 'integer', ['autoincrement' => true]); // assert tabel self::assertTrue($table->isQuoted()); @@ -753,8 +756,8 @@ public function testReturnsGetListTableColumnsSQL($database, $expectedSql) public function getReturnsGetListTableColumnsSQL() { - return array( - array( + return [ + [ null, "SELECT c.*, ( @@ -765,9 +768,9 @@ public function getReturnsGetListTableColumnsSQL() ) AS comments FROM user_tab_columns c WHERE c.table_name = 'test' - ORDER BY c.column_id" - ), - array( + ORDER BY c.column_id", + ], + [ '/', "SELECT c.*, ( @@ -778,9 +781,9 @@ public function getReturnsGetListTableColumnsSQL() ) AS comments FROM user_tab_columns c WHERE c.table_name = 'test' - ORDER BY c.column_id" - ), - array( + ORDER BY c.column_id", + ], + [ 'scott', "SELECT c.*, ( @@ -791,9 +794,9 @@ public function getReturnsGetListTableColumnsSQL() ) AS comments FROM all_tab_columns c WHERE c.table_name = 'test' AND c.owner = 'SCOTT' - ORDER BY c.column_id" - ), - ); + ORDER BY c.column_id", + ], + ]; } /** @@ -825,9 +828,7 @@ protected function getQuotesReservedKeywordInTruncateTableSQL() */ protected function getAlterStringToFixedStringSQL() { - return array( - 'ALTER TABLE mytable MODIFY (name CHAR(2) DEFAULT NULL)', - ); + return ['ALTER TABLE mytable MODIFY (name CHAR(2) DEFAULT NULL)']; } /** @@ -835,9 +836,7 @@ protected function getAlterStringToFixedStringSQL() */ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() { - return array( - 'ALTER INDEX idx_foo RENAME TO idx_foo_renamed', - ); + return ['ALTER INDEX idx_foo RENAME TO idx_foo_renamed']; } /** diff --git a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL92PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL92PlatformTest.php index 0189dbdfe36..48297877125 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL92PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL92PlatformTest.php @@ -28,24 +28,24 @@ public function testHasNativeJsonType() */ public function testReturnsJsonTypeDeclarationSQL() { - self::assertSame('JSON', $this->_platform->getJsonTypeDeclarationSQL(array())); + self::assertSame('JSON', $this->_platform->getJsonTypeDeclarationSQL([])); } public function testReturnsSmallIntTypeDeclarationSQL() { self::assertSame( 'SMALLSERIAL', - $this->_platform->getSmallIntTypeDeclarationSQL(array('autoincrement' => true)) + $this->_platform->getSmallIntTypeDeclarationSQL(['autoincrement' => true]) ); self::assertSame( 'SMALLINT', - $this->_platform->getSmallIntTypeDeclarationSQL(array('autoincrement' => false)) + $this->_platform->getSmallIntTypeDeclarationSQL(['autoincrement' => false]) ); self::assertSame( 'SMALLINT', - $this->_platform->getSmallIntTypeDeclarationSQL(array()) + $this->_platform->getSmallIntTypeDeclarationSQL([]) ); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL94PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL94PlatformTest.php index d566007afc2..673a724ecdc 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL94PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL94PlatformTest.php @@ -18,8 +18,8 @@ public function createPlatform() public function testReturnsJsonTypeDeclarationSQL() { parent::testReturnsJsonTypeDeclarationSQL(); - self::assertSame('JSON', $this->_platform->getJsonTypeDeclarationSQL(array('jsonb' => false))); - self::assertSame('JSONB', $this->_platform->getJsonTypeDeclarationSQL(array('jsonb' => true))); + self::assertSame('JSON', $this->_platform->getJsonTypeDeclarationSQL(['jsonb' => false])); + self::assertSame('JSONB', $this->_platform->getJsonTypeDeclarationSQL(['jsonb' => true])); } public function testInitializesJsonTypeMapping() diff --git a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php index 6db159df48e..4022eb0ff04 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php @@ -8,7 +8,7 @@ class PostgreSqlPlatformTest extends AbstractPostgreSqlPlatformTestCase { public function createPlatform() { - return new PostgreSqlPlatform; + return new PostgreSqlPlatform(); } public function testSupportsPartialIndexes() diff --git a/tests/Doctrine/Tests/DBAL/Platforms/ReservedKeywordsValidatorTest.php b/tests/Doctrine/Tests/DBAL/Platforms/ReservedKeywordsValidatorTest.php index bf1ad773238..22ab967fd7e 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/ReservedKeywordsValidatorTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/ReservedKeywordsValidatorTest.php @@ -2,43 +2,41 @@ namespace Doctrine\Tests\DBAL\Platforms; +use Doctrine\DBAL\Platforms\Keywords\MySQLKeywords; use Doctrine\DBAL\Platforms\Keywords\ReservedKeywordsValidator; use Doctrine\DBAL\Schema\Table; +use Doctrine\Tests\DbalTestCase; -class ReservedKeywordsValidatorTest extends \Doctrine\Tests\DbalTestCase +class ReservedKeywordsValidatorTest extends DbalTestCase { - /** - * @var ReservedKeywordsValidator - */ + /** @var ReservedKeywordsValidator */ private $validator; protected function setUp() { - $this->validator = new ReservedKeywordsValidator(array( - new \Doctrine\DBAL\Platforms\Keywords\MySQLKeywords() - )); + $this->validator = new ReservedKeywordsValidator([new MySQLKeywords()]); } public function testReservedTableName() { - $table = new Table("TABLE"); + $table = new Table('TABLE'); $this->validator->acceptTable($table); self::assertEquals( - array('Table TABLE keyword violations: MySQL'), + ['Table TABLE keyword violations: MySQL'], $this->validator->getViolations() ); } public function testReservedColumnName() { - $table = new Table("TABLE"); + $table = new Table('TABLE'); $column = $table->addColumn('table', 'string'); $this->validator->acceptColumn($table, $column); self::assertEquals( - array('Table TABLE column table keyword violations: MySQL'), + ['Table TABLE column table keyword violations: MySQL'], $this->validator->getViolations() ); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere11PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere11PlatformTest.php index c59a9b1ac12..c384d16de45 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere11PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere11PlatformTest.php @@ -6,14 +6,12 @@ class SQLAnywhere11PlatformTest extends SQLAnywherePlatformTest { - /** - * @var \Doctrine\DBAL\Platforms\SQLAnywhere11Platform - */ + /** @var SQLAnywhere11Platform */ protected $_platform; public function createPlatform() { - return new SQLAnywhere11Platform; + return new SQLAnywhere11Platform(); } public function testDoesNotSupportRegexp() diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere12PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere12PlatformTest.php index 4c6763ae124..4219c9d0514 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere12PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere12PlatformTest.php @@ -8,14 +8,12 @@ class SQLAnywhere12PlatformTest extends SQLAnywhere11PlatformTest { - /** - * @var \Doctrine\DBAL\Platforms\SQLAnywhere12Platform - */ + /** @var SQLAnywhere12Platform */ protected $_platform; public function createPlatform() { - return new SQLAnywhere12Platform; + return new SQLAnywhere12Platform(); } public function testDoesNotSupportSequences() @@ -48,7 +46,7 @@ public function testGeneratesSequenceSqlCommands() $this->_platform->getDropSequenceSQL($sequence) ); self::assertEquals( - "SELECT myseq.NEXTVAL", + 'SELECT myseq.NEXTVAL', $this->_platform->getSequenceNextValSQL('myseq') ); self::assertEquals( @@ -61,12 +59,12 @@ public function testGeneratesDateTimeTzColumnTypeDeclarationSQL() { self::assertEquals( 'TIMESTAMP WITH TIME ZONE', - $this->_platform->getDateTimeTzTypeDeclarationSQL(array( + $this->_platform->getDateTimeTzTypeDeclarationSQL([ 'length' => 10, 'fixed' => true, 'unsigned' => true, - 'autoincrement' => true - )) + 'autoincrement' => true, + ]) ); } @@ -88,10 +86,10 @@ public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() $this->_platform->getCreateIndexSQL( new Index( 'fooindex', - array('a', 'b'), + ['a', 'b'], true, false, - array('virtual', 'clustered', 'with_nulls_not_distinct', 'for_olap_workload') + ['virtual', 'clustered', 'with_nulls_not_distinct', 'for_olap_workload'] ), 'footable' ) @@ -101,10 +99,10 @@ public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() $this->_platform->getCreateIndexSQL( new Index( 'fooindex', - array('a', 'b'), + ['a', 'b'], false, false, - array('virtual', 'clustered', 'with_nulls_not_distinct', 'for_olap_workload') + ['virtual', 'clustered', 'with_nulls_not_distinct', 'for_olap_workload'] ), 'footable' ) @@ -116,10 +114,10 @@ public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() $this->_platform->getCreateIndexSQL( new Index( 'fooindex', - array('a', 'b'), + ['a', 'b'], false, true, - array('with_nulls_not_distinct') + ['with_nulls_not_distinct'] ), 'footable' ) @@ -131,10 +129,10 @@ public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() $this->_platform->getCreateIndexSQL( new Index( 'fooindex', - array('a', 'b'), + ['a', 'b'], false, false, - array('with_nulls_not_distinct') + ['with_nulls_not_distinct'] ), 'footable' ) diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere16PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere16PlatformTest.php index c66bb5177ab..bbf99527f65 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere16PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere16PlatformTest.php @@ -9,7 +9,7 @@ class SQLAnywhere16PlatformTest extends SQLAnywhere12PlatformTest { public function createPlatform() { - return new SQLAnywhere16Platform; + return new SQLAnywhere16Platform(); } public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() @@ -19,10 +19,10 @@ public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() $this->_platform->getCreateIndexSQL( new Index( 'fooindex', - array('a', 'b'), + ['a', 'b'], true, false, - array('with_nulls_distinct') + ['with_nulls_distinct'] ), 'footable' ) @@ -34,10 +34,10 @@ public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() $this->_platform->getCreateIndexSQL( new Index( 'fooindex', - array('a', 'b'), + ['a', 'b'], false, true, - array('with_nulls_distinct') + ['with_nulls_distinct'] ), 'footable' ) @@ -49,10 +49,10 @@ public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() $this->_platform->getCreateIndexSQL( new Index( 'fooindex', - array('a', 'b'), + ['a', 'b'], false, false, - array('with_nulls_distinct') + ['with_nulls_distinct'] ), 'footable' ) @@ -68,10 +68,10 @@ public function testThrowsExceptionOnInvalidWithNullsNotDistinctIndexOptions() $this->_platform->getCreateIndexSQL( new Index( 'fooindex', - array('a', 'b'), + ['a', 'b'], false, false, - array('with_nulls_distinct', 'with_nulls_not_distinct') + ['with_nulls_distinct', 'with_nulls_not_distinct'] ), 'footable' ); diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php index 6c514b55f53..7c6d161c371 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\DBAL\Platforms; -use Doctrine\DBAL\Connection; use Doctrine\DBAL\LockMode; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\SQLAnywherePlatform; @@ -22,22 +21,20 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase { - /** - * @var \Doctrine\DBAL\Platforms\SQLAnywherePlatform - */ + /** @var SQLAnywherePlatform */ protected $_platform; public function createPlatform() { - return new SQLAnywherePlatform; + return new SQLAnywherePlatform(); } public function getGenerateAlterTableSql() { - return 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", - 'ALTER TABLE mytable RENAME userlist' - ); + 'ALTER TABLE mytable RENAME userlist', + ]; } public function getGenerateForeignKeySql() @@ -57,10 +54,10 @@ public function getGenerateTableSql() public function getGenerateTableWithMultiColumnUniqueIndexSql() { - return array( + return [ 'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL)', - 'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)' - ); + 'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)', + ]; } public function getGenerateUniqueIndexSql() @@ -70,58 +67,54 @@ public function getGenerateUniqueIndexSql() protected function getQuotedColumnInForeignKeySQL() { - return array( - '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"))', - ); + 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() { - return array( + return [ 'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL)', - 'CREATE INDEX IDX_22660D028FD6E0FB ON "quoted" ("create")' - ); + 'CREATE INDEX IDX_22660D028FD6E0FB ON "quoted" ("create")', + ]; } protected function getQuotedNameInIndexSQL() { - return array( + return [ 'CREATE TABLE test (column1 VARCHAR(255) NOT NULL)', 'CREATE INDEX "key" ON test (column1)', - ); + ]; } protected function getQuotedColumnInPrimaryKeySQL() { - return array( - 'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, PRIMARY KEY ("create"))' - ); + return ['CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, PRIMARY KEY ("create"))']; } public function getCreateTableColumnCommentsSQL() { - return array( - "CREATE TABLE test (id INT NOT NULL, PRIMARY KEY (id))", + return [ + 'CREATE TABLE test (id INT NOT NULL, PRIMARY KEY (id))', "COMMENT ON COLUMN test.id IS 'This is a comment'", - ); + ]; } public function getAlterTableColumnCommentsSQL() { - return array( - "ALTER TABLE mytable ADD quota INT NOT NULL", + return [ + 'ALTER TABLE mytable ADD quota INT NOT NULL', "COMMENT ON COLUMN mytable.quota IS 'A comment'", - "COMMENT ON COLUMN mytable.foo IS NULL", + 'COMMENT ON COLUMN mytable.foo IS NULL', "COMMENT ON COLUMN mytable.baz IS 'B comment'", - ); + ]; } public function getCreateTableColumnTypeCommentsSQL() { - return array( - "CREATE TABLE test (id INT NOT NULL, data TEXT NOT NULL, PRIMARY KEY (id))", - "COMMENT ON COLUMN test.data IS '(DC2Type:array)'" - ); + return [ + 'CREATE TABLE test (id INT NOT NULL, data TEXT NOT NULL, PRIMARY KEY (id))', + "COMMENT ON COLUMN test.data IS '(DC2Type:array)'", + ]; } public function testHasCorrectPlatformName() @@ -133,17 +126,17 @@ public function testGeneratesCreateTableSQLWithCommonIndexes() { $table = new Table('test'); $table->addColumn('id', 'integer'); - $table->addColumn('name', 'string', array('length' => 50)); - $table->setPrimaryKey(array('id')); - $table->addIndex(array('name')); - $table->addIndex(array('id', 'name'), 'composite_idx'); + $table->addColumn('name', 'string', ['length' => 50]); + $table->setPrimaryKey(['id']); + $table->addIndex(['name']); + $table->addIndex(['id', 'name'], 'composite_idx'); self::assertEquals( - array( + [ 'CREATE TABLE test (id INT NOT NULL, name VARCHAR(50) NOT NULL, PRIMARY KEY (id))', 'CREATE INDEX IDX_D87F7E0C5E237E06 ON test (name)', - 'CREATE INDEX composite_idx ON test (id, name)' - ), + 'CREATE INDEX composite_idx ON test (id, name)', + ], $this->_platform->getCreateTableSQL($table) ); } @@ -154,22 +147,21 @@ public function testGeneratesCreateTableSQLWithForeignKeyConstraints() $table->addColumn('id', 'integer'); $table->addColumn('fk_1', 'integer'); $table->addColumn('fk_2', 'integer'); - $table->setPrimaryKey(array('id')); - $table->addForeignKeyConstraint('foreign_table', array('fk_1', 'fk_2'), array('pk_1', 'pk_2')); + $table->setPrimaryKey(['id']); + $table->addForeignKeyConstraint('foreign_table', ['fk_1', 'fk_2'], ['pk_1', 'pk_2']); $table->addForeignKeyConstraint( 'foreign_table2', - array('fk_1', 'fk_2'), - array('pk_1', 'pk_2'), - array(), + ['fk_1', 'fk_2'], + ['pk_1', 'pk_2'], + [], 'named_fk' ); self::assertEquals( - array( - 'CREATE TABLE test (id INT NOT NULL, fk_1 INT NOT NULL, fk_2 INT NOT NULL, ' . + ['CREATE TABLE test (id INT NOT NULL, fk_1 INT NOT NULL, fk_2 INT NOT NULL, ' . 'CONSTRAINT FK_D87F7E0C177612A38E7F4319 FOREIGN KEY (fk_1, fk_2) REFERENCES foreign_table (pk_1, pk_2), ' . - 'CONSTRAINT named_fk FOREIGN KEY (fk_1, fk_2) REFERENCES foreign_table2 (pk_1, pk_2))' - ), + 'CONSTRAINT named_fk FOREIGN KEY (fk_1, fk_2) REFERENCES foreign_table2 (pk_1, pk_2))', + ], $this->_platform->getCreateTableSQL($table, AbstractPlatform::CREATE_FOREIGNKEYS) ); } @@ -178,14 +170,12 @@ public function testGeneratesCreateTableSQLWithCheckConstraints() { $table = new Table('test'); $table->addColumn('id', 'integer'); - $table->addColumn('check_max', 'integer', array('platformOptions' => array('max' => 10))); - $table->addColumn('check_min', 'integer', array('platformOptions' => array('min' => 10))); - $table->setPrimaryKey(array('id')); + $table->addColumn('check_max', 'integer', ['platformOptions' => ['max' => 10]]); + $table->addColumn('check_min', 'integer', ['platformOptions' => ['min' => 10]]); + $table->setPrimaryKey(['id']); self::assertEquals( - array( - 'CREATE TABLE test (id INT NOT NULL, check_max INT NOT NULL, check_min INT NOT NULL, PRIMARY KEY (id), CHECK (check_max <= 10), CHECK (check_min >= 10))' - ), + ['CREATE TABLE test (id INT NOT NULL, check_max INT NOT NULL, check_min INT NOT NULL, PRIMARY KEY (id), CHECK (check_max <= 10), CHECK (check_min >= 10))'], $this->_platform->getCreateTableSQL($table) ); } @@ -193,20 +183,18 @@ public function testGeneratesCreateTableSQLWithCheckConstraints() public function testGeneratesTableAlterationWithRemovedColumnCommentSql() { $table = new Table('mytable'); - $table->addColumn('foo', 'string', array('comment' => 'foo comment')); + $table->addColumn('foo', 'string', ['comment' => 'foo comment']); - $tableDiff = new TableDiff('mytable'); - $tableDiff->fromTable = $table; + $tableDiff = new TableDiff('mytable'); + $tableDiff->fromTable = $table; $tableDiff->changedColumns['foo'] = new ColumnDiff( 'foo', new Column('foo', Type::getType('string')), - array('comment') + ['comment'] ); self::assertEquals( - array( - "COMMENT ON COLUMN mytable.foo IS NULL" - ), + ['COMMENT ON COLUMN mytable.foo IS NULL'], $this->_platform->getAlterTableSQL($tableDiff) ); } @@ -216,7 +204,7 @@ public function testGeneratesTableAlterationWithRemovedColumnCommentSql() */ public function testAppendsLockHint($lockMode, $lockHint) { - $fromClause = 'FROM users'; + $fromClause = 'FROM users'; $expectedResult = $fromClause . $lockHint; self::assertSame($expectedResult, $this->_platform->appendLockHint($fromClause, $lockMode)); @@ -224,15 +212,15 @@ public function testAppendsLockHint($lockMode, $lockHint) public function getLockHints() { - return array( - array(null, ''), - array(false, ''), - array(true, ''), - array(LockMode::NONE, ' WITH (NOLOCK)'), - array(LockMode::OPTIMISTIC, ''), - array(LockMode::PESSIMISTIC_READ, ' WITH (UPDLOCK)'), - array(LockMode::PESSIMISTIC_WRITE, ' WITH (XLOCK)'), - ); + return [ + [null, ''], + [false, ''], + [true, ''], + [LockMode::NONE, ' WITH (NOLOCK)'], + [LockMode::OPTIMISTIC, ''], + [LockMode::PESSIMISTIC_READ, ' WITH (UPDLOCK)'], + [LockMode::PESSIMISTIC_WRITE, ' WITH (XLOCK)'], + ]; } public function testHasCorrectMaxIdentifierLength() @@ -243,8 +231,8 @@ public function testHasCorrectMaxIdentifierLength() public function testFixesSchemaElementNames() { $maxIdentifierLength = $this->_platform->getMaxIdentifierLength(); - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $schemaElementName = ''; + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $schemaElementName = ''; for ($i = 0; $i < $maxIdentifierLength + 100; $i++) { $schemaElementName .= $characters[mt_rand(0, strlen($characters) - 1)]; @@ -264,27 +252,21 @@ public function testFixesSchemaElementNames() public function testGeneratesColumnTypesDeclarationSQL() { - $fullColumnDef = array( + $fullColumnDef = [ 'length' => 10, 'fixed' => true, 'unsigned' => true, - 'autoincrement' => true - ); + 'autoincrement' => true, + ]; - self::assertEquals('SMALLINT', $this->_platform->getSmallIntTypeDeclarationSQL(array())); - self::assertEquals('UNSIGNED SMALLINT', $this->_platform->getSmallIntTypeDeclarationSQL(array( - 'unsigned' => true - ))); + self::assertEquals('SMALLINT', $this->_platform->getSmallIntTypeDeclarationSQL([])); + self::assertEquals('UNSIGNED SMALLINT', $this->_platform->getSmallIntTypeDeclarationSQL(['unsigned' => true])); self::assertEquals('UNSIGNED SMALLINT IDENTITY', $this->_platform->getSmallIntTypeDeclarationSQL($fullColumnDef)); - self::assertEquals('INT', $this->_platform->getIntegerTypeDeclarationSQL(array())); - self::assertEquals('UNSIGNED INT', $this->_platform->getIntegerTypeDeclarationSQL(array( - 'unsigned' => true - ))); + self::assertEquals('INT', $this->_platform->getIntegerTypeDeclarationSQL([])); + self::assertEquals('UNSIGNED INT', $this->_platform->getIntegerTypeDeclarationSQL(['unsigned' => true])); self::assertEquals('UNSIGNED INT IDENTITY', $this->_platform->getIntegerTypeDeclarationSQL($fullColumnDef)); - self::assertEquals('BIGINT', $this->_platform->getBigIntTypeDeclarationSQL(array())); - self::assertEquals('UNSIGNED BIGINT', $this->_platform->getBigIntTypeDeclarationSQL(array( - 'unsigned' => true - ))); + self::assertEquals('BIGINT', $this->_platform->getBigIntTypeDeclarationSQL([])); + self::assertEquals('UNSIGNED BIGINT', $this->_platform->getBigIntTypeDeclarationSQL(['unsigned' => true])); self::assertEquals('UNSIGNED BIGINT IDENTITY', $this->_platform->getBigIntTypeDeclarationSQL($fullColumnDef)); self::assertEquals('LONG BINARY', $this->_platform->getBlobTypeDeclarationSQL($fullColumnDef)); self::assertEquals('BIT', $this->_platform->getBooleanTypeDeclarationSQL($fullColumnDef)); @@ -331,14 +313,14 @@ public function testGeneratesPrimaryKeyDeclarationSQL() self::assertEquals( 'CONSTRAINT pk PRIMARY KEY CLUSTERED (a, b)', $this->_platform->getPrimaryKeyDeclarationSQL( - new Index(null, array('a', 'b'), true, true, array('clustered')), + new Index(null, ['a', 'b'], true, true, ['clustered']), 'pk' ) ); self::assertEquals( 'PRIMARY KEY (a, b)', $this->_platform->getPrimaryKeyDeclarationSQL( - new Index(null, array('a', 'b'), true, true) + new Index(null, ['a', 'b'], true, true) ) ); } @@ -347,7 +329,7 @@ public function testCannotGeneratePrimaryKeyDeclarationSQLWithEmptyColumns() { $this->expectException('\InvalidArgumentException'); - $this->_platform->getPrimaryKeyDeclarationSQL(new Index('pk', array(), true, true)); + $this->_platform->getPrimaryKeyDeclarationSQL(new Index('pk', [], true, true)); } public function testGeneratesCreateUnnamedPrimaryKeySQL() @@ -355,14 +337,14 @@ public function testGeneratesCreateUnnamedPrimaryKeySQL() self::assertEquals( 'ALTER TABLE foo ADD PRIMARY KEY CLUSTERED (a, b)', $this->_platform->getCreatePrimaryKeySQL( - new Index('pk', array('a', 'b'), true, true, array('clustered')), + new Index('pk', ['a', 'b'], true, true, ['clustered']), 'foo' ) ); self::assertEquals( 'ALTER TABLE foo ADD PRIMARY KEY (a, b)', $this->_platform->getCreatePrimaryKeySQL( - new Index('any_pk_name', array('a', 'b'), true, true), + new Index('any_pk_name', ['a', 'b'], true, true), new Table('foo') ) ); @@ -374,12 +356,12 @@ public function testGeneratesUniqueConstraintDeclarationSQL() 'CONSTRAINT unique_constraint UNIQUE CLUSTERED (a, b)', $this->_platform->getUniqueConstraintDeclarationSQL( 'unique_constraint', - new Index(null, array('a', 'b'), true, false, array('clustered')) + new Index(null, ['a', 'b'], true, false, ['clustered']) ) ); self::assertEquals( 'UNIQUE (a, b)', - $this->_platform->getUniqueConstraintDeclarationSQL(null, new Index(null, array('a', 'b'), true, false)) + $this->_platform->getUniqueConstraintDeclarationSQL(null, new Index(null, ['a', 'b'], true, false)) ); } @@ -387,7 +369,7 @@ public function testCannotGenerateUniqueConstraintDeclarationSQLWithEmptyColumns { $this->expectException('\InvalidArgumentException'); - $this->_platform->getUniqueConstraintDeclarationSQL('constr', new Index('constr', array(), true)); + $this->_platform->getUniqueConstraintDeclarationSQL('constr', new Index('constr', [], true)); } public function testGeneratesForeignKeyConstraintsWithAdvancedPlatformOptionsSQL() @@ -398,21 +380,21 @@ public function testGeneratesForeignKeyConstraintsWithAdvancedPlatformOptionsSQL 'REFERENCES foreign_table (c, d) ' . 'MATCH UNIQUE SIMPLE ON UPDATE CASCADE ON DELETE SET NULL CHECK ON COMMIT CLUSTERED FOR OLAP WORKLOAD', $this->_platform->getForeignKeyDeclarationSQL( - new ForeignKeyConstraint(array('a', 'b'), 'foreign_table', array('c', 'd'), 'fk', array( + new ForeignKeyConstraint(['a', 'b'], 'foreign_table', ['c', 'd'], 'fk', [ 'notnull' => true, 'match' => SQLAnywherePlatform::FOREIGN_KEY_MATCH_SIMPLE_UNIQUE, 'onUpdate' => 'CASCADE', 'onDelete' => 'SET NULL', 'check_on_commit' => true, 'clustered' => true, - 'for_olap_workload' => true - )) + 'for_olap_workload' => true, + ]) ) ); self::assertEquals( 'FOREIGN KEY (a, b) REFERENCES foreign_table (c, d)', $this->_platform->getForeignKeyDeclarationSQL( - new ForeignKeyConstraint(array('a', 'b'), 'foreign_table', array('c', 'd')) + new ForeignKeyConstraint(['a', 'b'], 'foreign_table', ['c', 'd']) ) ); } @@ -435,26 +417,26 @@ public function testCannotGenerateInvalidForeignKeyMatchClauseSQL() public function testCannotGenerateForeignKeyConstraintSQLWithEmptyLocalColumns() { $this->expectException('\InvalidArgumentException'); - $this->_platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint(array(), 'foreign_tbl', array('c', 'd'))); + $this->_platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint([], 'foreign_tbl', ['c', 'd'])); } public function testCannotGenerateForeignKeyConstraintSQLWithEmptyForeignColumns() { $this->expectException('\InvalidArgumentException'); - $this->_platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint(array('a', 'b'), 'foreign_tbl', array())); + $this->_platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint(['a', 'b'], 'foreign_tbl', [])); } public function testCannotGenerateForeignKeyConstraintSQLWithEmptyForeignTableName() { $this->expectException('\InvalidArgumentException'); - $this->_platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint(array('a', 'b'), '', array('c', 'd'))); + $this->_platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint(['a', 'b'], '', ['c', 'd'])); } public function testCannotGenerateCommonIndexWithCreateConstraintSQL() { $this->expectException('\InvalidArgumentException'); - $this->_platform->getCreateConstraintSQL(new Index('fooindex', array()), new Table('footable')); + $this->_platform->getCreateConstraintSQL(new Index('fooindex', []), new Table('footable')); } public function testCannotGenerateCustomConstraintWithCreateConstraintSQL() @@ -471,10 +453,10 @@ public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() $this->_platform->getCreateIndexSQL( new Index( 'fooindex', - array('a', 'b'), + ['a', 'b'], true, false, - array('virtual', 'clustered', 'for_olap_workload') + ['virtual', 'clustered', 'for_olap_workload'] ), 'footable' ) @@ -485,12 +467,12 @@ public function testDoesNotSupportIndexDeclarationInCreateAlterTableStatements() { $this->expectException('\Doctrine\DBAL\DBALException'); - $this->_platform->getIndexDeclarationSQL('index', new Index('index', array())); + $this->_platform->getIndexDeclarationSQL('index', new Index('index', [])); } public function testGeneratesDropIndexSQL() { - $index = new Index('fooindex', array()); + $index = new Index('fooindex', []); self::assertEquals('DROP INDEX fooindex', $this->_platform->getDropIndexSQL($index)); self::assertEquals('DROP INDEX footable.fooindex', $this->_platform->getDropIndexSQL($index, 'footable')); @@ -504,14 +486,14 @@ public function testCannotGenerateDropIndexSQLWithInvalidIndexParameter() { $this->expectException('\InvalidArgumentException'); - $this->_platform->getDropIndexSQL(array('index'), 'table'); + $this->_platform->getDropIndexSQL(['index'], 'table'); } public function testCannotGenerateDropIndexSQLWithInvalidTableParameter() { $this->expectException('\InvalidArgumentException'); - $this->_platform->getDropIndexSQL('index', array('table')); + $this->_platform->getDropIndexSQL('index', ['table']); } public function testGeneratesSQLSnippets() @@ -542,8 +524,8 @@ public function testGeneratesSQLSnippets() self::assertEquals("DATEADD(SECOND, -1 * 1, '1987/05/02')", $this->_platform->getDateSubSecondsExpression("'1987/05/02'", 1)); self::assertEquals("DATEADD(WEEK, -1 * 3, '1987/05/02')", $this->_platform->getDateSubWeeksExpression("'1987/05/02'", 3)); self::assertEquals("DATEADD(YEAR, -1 * 10, '1987/05/02')", $this->_platform->getDateSubYearsExpression("'1987/05/02'", 10)); - self::assertEquals("Y-m-d H:i:s.u", $this->_platform->getDateTimeFormatString()); - self::assertEquals("H:i:s.u", $this->_platform->getTimeFormatString()); + self::assertEquals('Y-m-d H:i:s.u', $this->_platform->getDateTimeFormatString()); + self::assertEquals('H:i:s.u', $this->_platform->getTimeFormatString()); self::assertEquals('', $this->_platform->getForUpdateSQL()); self::assertEquals('NEWID()', $this->_platform->getGuidExpression()); self::assertEquals('LOCATE(string_column, substring_column)', $this->_platform->getLocateExpression('string_column', 'substring_column')); @@ -788,13 +770,13 @@ protected function getBinaryMaxLength() public function testReturnsBinaryTypeDeclarationSQL() { - self::assertSame('VARBINARY(1)', $this->_platform->getBinaryTypeDeclarationSQL(array())); - self::assertSame('VARBINARY(1)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 0))); - self::assertSame('VARBINARY(32767)', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 32767))); + self::assertSame('VARBINARY(1)', $this->_platform->getBinaryTypeDeclarationSQL([])); + self::assertSame('VARBINARY(1)', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 0])); + self::assertSame('VARBINARY(32767)', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 32767])); - self::assertSame('BINARY(1)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true))); - self::assertSame('BINARY(1)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 0))); - self::assertSame('BINARY(32767)', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 32767))); + self::assertSame('BINARY(1)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true])); + self::assertSame('BINARY(1)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 0])); + self::assertSame('BINARY(32767)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 32767])); } /** @@ -812,9 +794,7 @@ public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() */ protected function getAlterTableRenameIndexSQL() { - return array( - 'ALTER INDEX idx_foo ON mytable RENAME TO idx_bar', - ); + return ['ALTER INDEX idx_foo ON mytable RENAME TO idx_bar']; } /** @@ -822,10 +802,10 @@ protected function getAlterTableRenameIndexSQL() */ protected function getQuotedAlterTableRenameIndexSQL() { - return array( + return [ 'ALTER INDEX "create" ON "table" RENAME TO "select"', 'ALTER INDEX "foo" ON "table" RENAME TO "bar"', - ); + ]; } /** @@ -833,7 +813,7 @@ protected function getQuotedAlterTableRenameIndexSQL() */ protected function getQuotedAlterTableRenameColumnSQL() { - return array( + return [ 'ALTER TABLE mytable RENAME unquoted1 TO unquoted', 'ALTER TABLE mytable RENAME unquoted2 TO "where"', 'ALTER TABLE mytable RENAME unquoted3 TO "foo"', @@ -843,7 +823,7 @@ protected function getQuotedAlterTableRenameColumnSQL() 'ALTER TABLE mytable RENAME quoted1 TO quoted', 'ALTER TABLE mytable RENAME quoted2 TO "and"', 'ALTER TABLE mytable RENAME quoted3 TO "baz"', - ); + ]; } /** @@ -859,9 +839,7 @@ protected function getQuotedAlterTableChangeColumnLengthSQL() */ protected function getAlterTableRenameIndexInSchemaSQL() { - return array( - 'ALTER INDEX idx_foo ON myschema.mytable RENAME TO idx_bar', - ); + return ['ALTER INDEX idx_foo ON myschema.mytable RENAME TO idx_bar']; } /** @@ -869,10 +847,10 @@ protected function getAlterTableRenameIndexInSchemaSQL() */ protected function getQuotedAlterTableRenameIndexInSchemaSQL() { - return array( + return [ 'ALTER INDEX "create" ON "schema"."table" RENAME TO "select"', 'ALTER INDEX "foo" ON "schema"."table" RENAME TO "bar"', - ); + ]; } /** @@ -880,7 +858,7 @@ protected function getQuotedAlterTableRenameIndexInSchemaSQL() */ public function testReturnsGuidTypeDeclarationSQL() { - self::assertSame('UNIQUEIDENTIFIER', $this->_platform->getGuidTypeDeclarationSQL(array())); + self::assertSame('UNIQUEIDENTIFIER', $this->_platform->getGuidTypeDeclarationSQL([])); } /** @@ -888,9 +866,7 @@ public function testReturnsGuidTypeDeclarationSQL() */ public function getAlterTableRenameColumnSQL() { - return array( - 'ALTER TABLE foo RENAME bar TO baz', - ); + return ['ALTER TABLE foo RENAME bar TO baz']; } /** @@ -898,7 +874,7 @@ public function getAlterTableRenameColumnSQL() */ protected function getQuotesTableIdentifiersInAlterTableSQL() { - return array( + return [ 'ALTER TABLE "foo" DROP FOREIGN KEY fk1', 'ALTER TABLE "foo" DROP FOREIGN KEY fk2', 'ALTER TABLE "foo" RENAME id TO war', @@ -906,7 +882,7 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() 'ALTER TABLE "foo" RENAME "table"', 'ALTER TABLE "table" ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id)', 'ALTER TABLE "table" ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)', - ); + ]; } /** @@ -914,11 +890,11 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() */ protected function getCommentOnColumnSQL() { - return array( + return [ 'COMMENT ON COLUMN foo.bar IS \'comment\'', 'COMMENT ON COLUMN "Foo"."BAR" IS \'comment\'', 'COMMENT ON COLUMN "select"."from" IS \'comment\'', - ); + ]; } /** @@ -926,8 +902,8 @@ protected function getCommentOnColumnSQL() */ public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() { - $table1 = new Table('"foo"', array(new Column('"bar"', Type::getType('integer')))); - $table2 = new Table('"foo"', array(new Column('"bar"', Type::getType('integer'), array('comment' => 'baz')))); + $table1 = new Table('"foo"', [new Column('"bar"', Type::getType('integer'))]); + $table2 = new Table('"foo"', [new Column('"bar"', Type::getType('integer'), ['comment' => 'baz'])]); $comparator = new Comparator(); @@ -935,9 +911,7 @@ public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); self::assertSame( - array( - 'COMMENT ON COLUMN "foo"."bar" IS \'baz\'', - ), + ['COMMENT ON COLUMN "foo"."bar" IS \'baz\''], $this->_platform->getAlterTableSQL($tableDiff) ); } @@ -947,14 +921,14 @@ public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() */ public function getReturnsForeignKeyReferentialActionSQL() { - return array( - array('CASCADE', 'CASCADE'), - array('SET NULL', 'SET NULL'), - array('NO ACTION', 'RESTRICT'), - array('RESTRICT', 'RESTRICT'), - array('SET DEFAULT', 'SET DEFAULT'), - array('CaScAdE', 'CASCADE'), - ); + return [ + ['CASCADE', 'CASCADE'], + ['SET NULL', 'SET NULL'], + ['NO ACTION', 'RESTRICT'], + ['RESTRICT', 'RESTRICT'], + ['SET DEFAULT', 'SET DEFAULT'], + ['CaScAdE', 'CASCADE'], + ]; } /** @@ -994,9 +968,7 @@ protected function supportsInlineIndexDeclaration() */ protected function getAlterStringToFixedStringSQL() { - return array( - 'ALTER TABLE mytable ALTER name CHAR(2) NOT NULL', - ); + return ['ALTER TABLE mytable ALTER name CHAR(2) NOT NULL']; } /** @@ -1004,9 +976,7 @@ protected function getAlterStringToFixedStringSQL() */ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() { - return array( - 'ALTER INDEX idx_foo ON mytable RENAME TO idx_foo_renamed', - ); + return ['ALTER INDEX idx_foo ON mytable RENAME TO idx_foo_renamed']; } /** diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAzurePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAzurePlatformTest.php index f1b93e0eb48..e42aaeb8eaf 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAzurePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAzurePlatformTest.php @@ -2,6 +2,8 @@ namespace Doctrine\Tests\DBAL\Platforms; +use Doctrine\DBAL\Platforms\SQLAzurePlatform; +use Doctrine\DBAL\Schema\Table; use Doctrine\Tests\DbalTestCase; /** @@ -9,23 +11,21 @@ */ class SQLAzurePlatformTest extends DbalTestCase { - /** - * @var \Doctrine\DBAL\Platforms\SQLAzurePlatform - */ + /** @var SQLAzurePlatform */ private $platform; protected function setUp() { - $this->platform = new \Doctrine\DBAL\Platforms\SQLAzurePlatform(); + $this->platform = new SQLAzurePlatform(); } public function testCreateFederatedOnTable() { - $table = new \Doctrine\DBAL\Schema\Table("tbl"); - $table->addColumn("id", "integer"); + $table = new Table('tbl'); + $table->addColumn('id', 'integer'); $table->addOption('azure.federatedOnDistributionName', 'TblId'); $table->addOption('azure.federatedOnColumnName', 'id'); - self::assertEquals(array('CREATE TABLE tbl (id INT NOT NULL) FEDERATED ON (TblId = id)'), $this->platform->getCreateTableSQL($table)); + self::assertEquals(['CREATE TABLE tbl (id INT NOT NULL) FEDERATED ON (TblId = id)'], $this->platform->getCreateTableSQL($table)); } } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2008PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2008PlatformTest.php index 3670c4a80a6..024bf65de93 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2008PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2008PlatformTest.php @@ -8,7 +8,7 @@ class SQLServer2008PlatformTest extends AbstractSQLServerPlatformTestCase { public function createPlatform() { - return new SQLServer2008Platform; + return new SQLServer2008Platform(); } public function testGeneratesTypeDeclarationForDateTimeTz() diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php index 69e0840b629..00dcdf24cb6 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Platforms; +use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Platforms\SQLServer2012Platform; use Doctrine\DBAL\Schema\Sequence; @@ -9,7 +10,7 @@ class SQLServer2012PlatformTest extends AbstractSQLServerPlatformTestCase { public function createPlatform() { - return new SQLServer2012Platform; + return new SQLServer2012Platform(); } public function testSupportsSequences() @@ -38,7 +39,7 @@ public function testGeneratesSequenceSqlCommands() $this->_platform->getDropSequenceSQL('myseq') ); self::assertEquals( - "SELECT NEXT VALUE FOR myseq", + 'SELECT NEXT VALUE FOR myseq', $this->_platform->getSequenceNextValSQL('myseq') ); } @@ -124,19 +125,18 @@ public function testModifyLimitQueryWithFromColumnNames() */ public function testModifyLimitQueryWithExtraLongQuery() { - $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) '; - $query.= 'AND (table2.column2 = table7.column7) AND (table2.column2 = table8.column8) AND (table3.column3 = table4.column4) AND (table3.column3 = table5.column5) AND (table3.column3 = table6.column6) AND (table3.column3 = table7.column7) AND (table3.column3 = table8.column8) AND (table4.column4 = table5.column5) AND (table4.column4 = table6.column6) AND (table4.column4 = table7.column7) AND (table4.column4 = table8.column8) '; - $query.= 'AND (table5.column5 = table6.column6) AND (table5.column5 = table7.column7) AND (table5.column5 = table8.column8) AND (table6.column6 = table7.column7) AND (table6.column6 = table8.column8) AND (table7.column7 = table8.column8)'; + $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) '; + $query .= 'AND (table2.column2 = table7.column7) AND (table2.column2 = table8.column8) AND (table3.column3 = table4.column4) AND (table3.column3 = table5.column5) AND (table3.column3 = table6.column6) AND (table3.column3 = table7.column7) AND (table3.column3 = table8.column8) AND (table4.column4 = table5.column5) AND (table4.column4 = table6.column6) AND (table4.column4 = table7.column7) AND (table4.column4 = table8.column8) '; + $query .= 'AND (table5.column5 = table6.column6) AND (table5.column5 = table7.column7) AND (table5.column5 = table8.column8) AND (table6.column6 = table7.column7) AND (table6.column6 = table8.column8) AND (table7.column7 = table8.column8)'; $sql = $this->_platform->modifyLimitQuery($query, 10); - $expected = '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 '; - $expected.= '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) '; - $expected.= 'AND (table2.column2 = table7.column7) AND (table2.column2 = table8.column8) AND (table3.column3 = table4.column4) AND (table3.column3 = table5.column5) AND (table3.column3 = table6.column6) AND (table3.column3 = table7.column7) AND (table3.column3 = table8.column8) AND (table4.column4 = table5.column5) AND (table4.column4 = table6.column6) AND (table4.column4 = table7.column7) AND (table4.column4 = table8.column8) '; - $expected.= 'AND (table5.column5 = table6.column6) AND (table5.column5 = table7.column7) AND (table5.column5 = table8.column8) AND (table6.column6 = table7.column7) AND (table6.column6 = table8.column8) AND (table7.column7 = table8.column8) '; - $expected.= 'ORDER BY (SELECT 0) OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY'; - + $expected = '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 '; + $expected .= '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) '; + $expected .= 'AND (table2.column2 = table7.column7) AND (table2.column2 = table8.column8) AND (table3.column3 = table4.column4) AND (table3.column3 = table5.column5) AND (table3.column3 = table6.column6) AND (table3.column3 = table7.column7) AND (table3.column3 = table8.column8) AND (table4.column4 = table5.column5) AND (table4.column4 = table6.column6) AND (table4.column4 = table7.column7) AND (table4.column4 = table8.column8) '; + $expected .= 'AND (table5.column5 = table6.column6) AND (table5.column5 = table7.column7) AND (table5.column5 = table8.column8) AND (table6.column6 = table7.column7) AND (table6.column6 = table8.column8) AND (table7.column7 = table8.column8) '; + $expected .= 'ORDER BY (SELECT 0) OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY'; self::assertEquals($expected, $sql); } @@ -159,26 +159,26 @@ public function testModifyLimitQueryWithOrderByClause() public function testModifyLimitQueryWithSubSelectInSelectList() { $sql = $this->_platform->modifyLimitQuery( - "SELECT " . - "u.id, " . - "(u.foo/2) foodiv, " . - "CONCAT(u.bar, u.baz) barbaz, " . - "(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count " . - "FROM user u " . + 'SELECT ' . + 'u.id, ' . + '(u.foo/2) foodiv, ' . + 'CONCAT(u.bar, u.baz) barbaz, ' . + '(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count ' . + 'FROM user u ' . "WHERE u.status = 'disabled'", 10 ); self::assertEquals( - "SELECT " . - "u.id, " . - "(u.foo/2) foodiv, " . - "CONCAT(u.bar, u.baz) barbaz, " . - "(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count " . - "FROM user u " . + 'SELECT ' . + 'u.id, ' . + '(u.foo/2) foodiv, ' . + 'CONCAT(u.bar, u.baz) barbaz, ' . + '(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count ' . + 'FROM user u ' . "WHERE u.status = 'disabled' " . - "ORDER BY (SELECT 0) OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY", + 'ORDER BY (SELECT 0) OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY', $sql ); } @@ -189,28 +189,28 @@ public function testModifyLimitQueryWithSubSelectInSelectList() public function testModifyLimitQueryWithSubSelectInSelectListAndOrderByClause() { $sql = $this->_platform->modifyLimitQuery( - "SELECT " . - "u.id, " . - "(u.foo/2) foodiv, " . - "CONCAT(u.bar, u.baz) barbaz, " . - "(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count " . - "FROM user u " . + 'SELECT ' . + 'u.id, ' . + '(u.foo/2) foodiv, ' . + 'CONCAT(u.bar, u.baz) barbaz, ' . + '(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count ' . + 'FROM user u ' . "WHERE u.status = 'disabled' " . - "ORDER BY u.username DESC", + 'ORDER BY u.username DESC', 10, 5 ); self::assertEquals( - "SELECT " . - "u.id, " . - "(u.foo/2) foodiv, " . - "CONCAT(u.bar, u.baz) barbaz, " . - "(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count " . - "FROM user u " . + 'SELECT ' . + 'u.id, ' . + '(u.foo/2) foodiv, ' . + 'CONCAT(u.bar, u.baz) barbaz, ' . + '(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count ' . + 'FROM user u ' . "WHERE u.status = 'disabled' " . - "ORDER BY u.username DESC " . - "OFFSET 5 ROWS FETCH NEXT 10 ROWS ONLY", + 'ORDER BY u.username DESC ' . + 'OFFSET 5 ROWS FETCH NEXT 10 ROWS ONLY', $sql ); } @@ -221,154 +221,154 @@ public function testModifyLimitQueryWithSubSelectInSelectListAndOrderByClause() public function testModifyLimitQueryWithAggregateFunctionInOrderByClause() { $sql = $this->_platform->modifyLimitQuery( - "SELECT " . - "MAX(heading_id) aliased, " . - "code " . - "FROM operator_model_operator " . - "GROUP BY code " . - "ORDER BY MAX(heading_id) DESC", + 'SELECT ' . + 'MAX(heading_id) aliased, ' . + 'code ' . + 'FROM operator_model_operator ' . + 'GROUP BY code ' . + 'ORDER BY MAX(heading_id) DESC', 1, 0 ); self::assertEquals( - "SELECT " . - "MAX(heading_id) aliased, " . - "code " . - "FROM operator_model_operator " . - "GROUP BY code " . - "ORDER BY MAX(heading_id) DESC " . - "OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY", + 'SELECT ' . + 'MAX(heading_id) aliased, ' . + 'code ' . + 'FROM operator_model_operator ' . + 'GROUP BY code ' . + 'ORDER BY MAX(heading_id) DESC ' . + 'OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY', $sql ); } public function testModifyLimitQueryWithFromSubquery() { - $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); + $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); - $expected = "SELECT DISTINCT id_0 FROM (SELECT k0_.id AS id_0 FROM key_measure k0_ WHERE (k0_.id_zone in(2))) dctrn_result ORDER BY 1 OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY"; + $expected = 'SELECT DISTINCT id_0 FROM (SELECT k0_.id AS id_0 FROM key_measure k0_ WHERE (k0_.id_zone in(2))) dctrn_result ORDER BY 1 OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY'; self::assertEquals($sql, $expected); } public function testModifyLimitQueryWithFromSubqueryAndOrder() { - $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); + $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); - $expected = "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 OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY"; + $expected = '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 OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY'; self::assertEquals($sql, $expected); } public function testModifyLimitQueryWithComplexOrderByExpression() { - $sql = $this->_platform->modifyLimitQuery("SELECT * FROM table ORDER BY (table.x * table.y) DESC", 10); + $sql = $this->_platform->modifyLimitQuery('SELECT * FROM table ORDER BY (table.x * table.y) DESC', 10); - $expected = "SELECT * FROM table ORDER BY (table.x * table.y) DESC OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY"; + $expected = 'SELECT * FROM table ORDER BY (table.x * table.y) DESC OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY'; self::assertEquals($sql, $expected); } /** - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromBaseTable() { - $querySql = "SELECT DISTINCT id_0, name_1 " - . "FROM (" - . "SELECT t1.id AS id_0, t2.name AS name_1 " - . "FROM table_parent t1 " - . "LEFT JOIN join_table t2 ON t1.id = t2.table_id" - . ") dctrn_result " - . "ORDER BY id_0 ASC"; - $alteredSql = "SELECT DISTINCT id_0, name_1 " - . "FROM (" - . "SELECT t1.id AS id_0, t2.name AS name_1 " - . "FROM table_parent t1 " - . "LEFT JOIN join_table t2 ON t1.id = t2.table_id" - . ") dctrn_result " - . "ORDER BY id_0 ASC OFFSET 0 ROWS FETCH NEXT 5 ROWS ONLY"; - $sql = $this->_platform->modifyLimitQuery($querySql, 5); + $querySql = 'SELECT DISTINCT id_0, name_1 ' + . 'FROM (' + . 'SELECT t1.id AS id_0, t2.name AS name_1 ' + . 'FROM table_parent t1 ' + . 'LEFT JOIN join_table t2 ON t1.id = t2.table_id' + . ') dctrn_result ' + . 'ORDER BY id_0 ASC'; + $alteredSql = 'SELECT DISTINCT id_0, name_1 ' + . 'FROM (' + . 'SELECT t1.id AS id_0, t2.name AS name_1 ' + . 'FROM table_parent t1 ' + . 'LEFT JOIN join_table t2 ON t1.id = t2.table_id' + . ') dctrn_result ' + . 'ORDER BY id_0 ASC OFFSET 0 ROWS FETCH NEXT 5 ROWS ONLY'; + $sql = $this->_platform->modifyLimitQuery($querySql, 5); self::assertEquals($alteredSql, $sql); } /** - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromJoinTable() { - $querySql = "SELECT DISTINCT id_0, name_1 " - . "FROM (" - . "SELECT t1.id AS id_0, t2.name AS name_1 " - . "FROM table_parent t1 " - . "LEFT JOIN join_table t2 ON t1.id = t2.table_id" - . ") dctrn_result " - . "ORDER BY name_1 ASC"; - $alteredSql = "SELECT DISTINCT id_0, name_1 " - . "FROM (" - . "SELECT t1.id AS id_0, t2.name AS name_1 " - . "FROM table_parent t1 " - . "LEFT JOIN join_table t2 ON t1.id = t2.table_id" - . ") dctrn_result " - . "ORDER BY name_1 ASC OFFSET 0 ROWS FETCH NEXT 5 ROWS ONLY"; - $sql = $this->_platform->modifyLimitQuery($querySql, 5); + $querySql = 'SELECT DISTINCT id_0, name_1 ' + . 'FROM (' + . 'SELECT t1.id AS id_0, t2.name AS name_1 ' + . 'FROM table_parent t1 ' + . 'LEFT JOIN join_table t2 ON t1.id = t2.table_id' + . ') dctrn_result ' + . 'ORDER BY name_1 ASC'; + $alteredSql = 'SELECT DISTINCT id_0, name_1 ' + . 'FROM (' + . 'SELECT t1.id AS id_0, t2.name AS name_1 ' + . 'FROM table_parent t1 ' + . 'LEFT JOIN join_table t2 ON t1.id = t2.table_id' + . ') dctrn_result ' + . 'ORDER BY name_1 ASC OFFSET 0 ROWS FETCH NEXT 5 ROWS ONLY'; + $sql = $this->_platform->modifyLimitQuery($querySql, 5); self::assertEquals($alteredSql, $sql); } /** - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnsFromBothTables() { - $querySql = "SELECT DISTINCT id_0, name_1, foo_2 " - . "FROM (" - . "SELECT t1.id AS id_0, t2.name AS name_1, t2.foo AS foo_2 " - . "FROM table_parent t1 " - . "LEFT JOIN join_table t2 ON t1.id = t2.table_id" - . ") dctrn_result " - . "ORDER BY name_1 ASC, foo_2 DESC"; - $alteredSql = "SELECT DISTINCT id_0, name_1, foo_2 " - . "FROM (" - . "SELECT t1.id AS id_0, t2.name AS name_1, t2.foo AS foo_2 " - . "FROM table_parent t1 " - . "LEFT JOIN join_table t2 ON t1.id = t2.table_id" - . ") dctrn_result " - . "ORDER BY name_1 ASC, foo_2 DESC OFFSET 0 ROWS FETCH NEXT 5 ROWS ONLY"; - $sql = $this->_platform->modifyLimitQuery($querySql, 5); + $querySql = 'SELECT DISTINCT id_0, name_1, foo_2 ' + . 'FROM (' + . 'SELECT t1.id AS id_0, t2.name AS name_1, t2.foo AS foo_2 ' + . 'FROM table_parent t1 ' + . 'LEFT JOIN join_table t2 ON t1.id = t2.table_id' + . ') dctrn_result ' + . 'ORDER BY name_1 ASC, foo_2 DESC'; + $alteredSql = 'SELECT DISTINCT id_0, name_1, foo_2 ' + . 'FROM (' + . 'SELECT t1.id AS id_0, t2.name AS name_1, t2.foo AS foo_2 ' + . 'FROM table_parent t1 ' + . 'LEFT JOIN join_table t2 ON t1.id = t2.table_id' + . ') dctrn_result ' + . 'ORDER BY name_1 ASC, foo_2 DESC OFFSET 0 ROWS FETCH NEXT 5 ROWS ONLY'; + $sql = $this->_platform->modifyLimitQuery($querySql, 5); self::assertEquals($alteredSql, $sql); } public function testModifyLimitSubquerySimple() { - $querySql = "SELECT DISTINCT id_0 FROM " - . "(SELECT k0_.id AS id_0, k0_.field AS field_1 " - . "FROM key_table k0_ WHERE (k0_.where_field IN (1))) dctrn_result"; - $alteredSql = "SELECT DISTINCT id_0 FROM (SELECT k0_.id AS id_0, k0_.field AS field_1 " - . "FROM key_table k0_ WHERE (k0_.where_field IN (1))) dctrn_result ORDER BY 1 OFFSET 0 ROWS FETCH NEXT 20 ROWS ONLY"; - $sql = $this->_platform->modifyLimitQuery($querySql, 20); + $querySql = 'SELECT DISTINCT id_0 FROM ' + . '(SELECT k0_.id AS id_0, k0_.field AS field_1 ' + . 'FROM key_table k0_ WHERE (k0_.where_field IN (1))) dctrn_result'; + $alteredSql = 'SELECT DISTINCT id_0 FROM (SELECT k0_.id AS id_0, k0_.field AS field_1 ' + . 'FROM key_table k0_ WHERE (k0_.where_field IN (1))) dctrn_result ORDER BY 1 OFFSET 0 ROWS FETCH NEXT 20 ROWS ONLY'; + $sql = $this->_platform->modifyLimitQuery($querySql, 20); self::assertEquals($alteredSql, $sql); } public function testModifyLimitQueryWithTopNSubQueryWithOrderBy() { - $querySql = 'SELECT * FROM test t WHERE t.id = (SELECT TOP 1 t2.id FROM test t2 ORDER BY t2.data DESC)'; + $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'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->_platform->modifyLimitQuery($querySql, 10); self::assertEquals($expectedSql, $sql); - $querySql = 'SELECT * FROM test t WHERE t.id = (SELECT TOP 1 t2.id FROM test t2 ORDER BY t2.data DESC) ORDER BY t.data2 DESC'; + $querySql = 'SELECT * FROM test t WHERE t.id = (SELECT TOP 1 t2.id FROM test t2 ORDER BY t2.data DESC) ORDER BY t.data2 DESC'; $expectedSql = 'SELECT * FROM test t WHERE t.id = (SELECT TOP 1 t2.id FROM test t2 ORDER BY t2.data DESC) ORDER BY t.data2 DESC OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->_platform->modifyLimitQuery($querySql, 10); self::assertEquals($expectedSql, $sql); } public function testModifyLimitQueryWithNewlineBeforeOrderBy() { - $querySql = "SELECT * FROM test\nORDER BY col DESC"; + $querySql = "SELECT * FROM test\nORDER BY col DESC"; $expectedSql = "SELECT * FROM test\nORDER BY col DESC OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY"; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->_platform->modifyLimitQuery($querySql, 10); self::assertEquals($expectedSql, $sql); } } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php index f8b42f61819..eeaf5171bf3 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php @@ -7,10 +7,9 @@ class SQLServerPlatformTest extends AbstractSQLServerPlatformTestCase { - public function createPlatform() { - return new SQLServerPlatform; + return new SQLServerPlatform(); } /** @@ -36,15 +35,15 @@ public function testScrubInnerOrderBy($query, $limit, $offset, $expectedResult) public function getLockHints() { - return array( - array(null, ''), - array(false, ''), - array(true, ''), - array(LockMode::NONE, ' WITH (NOLOCK)'), - array(LockMode::OPTIMISTIC, ''), - array(LockMode::PESSIMISTIC_READ, ' WITH (HOLDLOCK, ROWLOCK)'), - array(LockMode::PESSIMISTIC_WRITE, ' WITH (UPDLOCK, ROWLOCK)'), - ); + return [ + [null, ''], + [false, ''], + [true, ''], + [LockMode::NONE, ' WITH (NOLOCK)'], + [LockMode::OPTIMISTIC, ''], + [LockMode::PESSIMISTIC_READ, ' WITH (HOLDLOCK, ROWLOCK)'], + [LockMode::PESSIMISTIC_WRITE, ' WITH (UPDLOCK, ROWLOCK)'], + ]; } public function getModifyLimitQueries() diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php index 3975b8fd2c7..67abba9fca5 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php @@ -14,7 +14,7 @@ class SqlitePlatformTest extends AbstractPlatformTestCase { public function createPlatform() { - return new SqlitePlatform; + return new SqlitePlatform(); } public function getGenerateTableSql() @@ -24,10 +24,10 @@ public function getGenerateTableSql() public function getGenerateTableWithMultiColumnUniqueIndexSql() { - return array( + return [ 'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL)', 'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)', - ); + ]; } public function testGeneratesSqlSnippets() @@ -66,7 +66,7 @@ public function testIgnoresUnsignedIntegerDeclarationForAutoIncrementalIntegers( { self::assertSame( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true, 'unsigned' => true)) + $this->_platform->getIntegerTypeDeclarationSQL(['autoincrement' => true, 'unsigned' => true]) ); } @@ -78,24 +78,25 @@ public function testGeneratesTypeDeclarationForTinyIntegers() { self::assertEquals( 'TINYINT', - $this->_platform->getTinyIntTypeDeclarationSQL(array()) + $this->_platform->getTinyIntTypeDeclarationSQL([]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getTinyIntTypeDeclarationSQL(array('autoincrement' => true)) + $this->_platform->getTinyIntTypeDeclarationSQL(['autoincrement' => true]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', $this->_platform->getTinyIntTypeDeclarationSQL( - array('autoincrement' => true, 'primary' => true)) + ['autoincrement' => true, 'primary' => true] + ) ); self::assertEquals( 'TINYINT', - $this->_platform->getTinyIntTypeDeclarationSQL(array('unsigned' => false)) + $this->_platform->getTinyIntTypeDeclarationSQL(['unsigned' => false]) ); self::assertEquals( 'TINYINT UNSIGNED', - $this->_platform->getTinyIntTypeDeclarationSQL(array('unsigned' => true)) + $this->_platform->getTinyIntTypeDeclarationSQL(['unsigned' => true]) ); } @@ -107,28 +108,29 @@ public function testGeneratesTypeDeclarationForSmallIntegers() { self::assertEquals( 'SMALLINT', - $this->_platform->getSmallIntTypeDeclarationSQL(array()) + $this->_platform->getSmallIntTypeDeclarationSQL([]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getSmallIntTypeDeclarationSQL(array('autoincrement' => true)) + $this->_platform->getSmallIntTypeDeclarationSQL(['autoincrement' => true]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getTinyIntTypeDeclarationSQL(array('autoincrement' => true, 'unsigned' => true)) + $this->_platform->getTinyIntTypeDeclarationSQL(['autoincrement' => true, 'unsigned' => true]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', $this->_platform->getSmallIntTypeDeclarationSQL( - array('autoincrement' => true, 'primary' => true)) + ['autoincrement' => true, 'primary' => true] + ) ); self::assertEquals( 'SMALLINT', - $this->_platform->getSmallIntTypeDeclarationSQL(array('unsigned' => false)) + $this->_platform->getSmallIntTypeDeclarationSQL(['unsigned' => false]) ); self::assertEquals( 'SMALLINT UNSIGNED', - $this->_platform->getSmallIntTypeDeclarationSQL(array('unsigned' => true)) + $this->_platform->getSmallIntTypeDeclarationSQL(['unsigned' => true]) ); } @@ -140,28 +142,29 @@ public function testGeneratesTypeDeclarationForMediumIntegers() { self::assertEquals( 'MEDIUMINT', - $this->_platform->getMediumIntTypeDeclarationSQL(array()) + $this->_platform->getMediumIntTypeDeclarationSQL([]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getMediumIntTypeDeclarationSQL(array('autoincrement' => true)) + $this->_platform->getMediumIntTypeDeclarationSQL(['autoincrement' => true]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getMediumIntTypeDeclarationSQL(array('autoincrement' => true, 'unsigned' => true)) + $this->_platform->getMediumIntTypeDeclarationSQL(['autoincrement' => true, 'unsigned' => true]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', $this->_platform->getMediumIntTypeDeclarationSQL( - array('autoincrement' => true, 'primary' => true)) + ['autoincrement' => true, 'primary' => true] + ) ); self::assertEquals( 'MEDIUMINT', - $this->_platform->getMediumIntTypeDeclarationSQL(array('unsigned' => false)) + $this->_platform->getMediumIntTypeDeclarationSQL(['unsigned' => false]) ); self::assertEquals( 'MEDIUMINT UNSIGNED', - $this->_platform->getMediumIntTypeDeclarationSQL(array('unsigned' => true)) + $this->_platform->getMediumIntTypeDeclarationSQL(['unsigned' => true]) ); } @@ -169,28 +172,29 @@ public function testGeneratesTypeDeclarationForIntegers() { self::assertEquals( 'INTEGER', - $this->_platform->getIntegerTypeDeclarationSQL(array()) + $this->_platform->getIntegerTypeDeclarationSQL([]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true)) + $this->_platform->getIntegerTypeDeclarationSQL(['autoincrement' => true]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true, 'unsigned' => true)) + $this->_platform->getIntegerTypeDeclarationSQL(['autoincrement' => true, 'unsigned' => true]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', $this->_platform->getIntegerTypeDeclarationSQL( - array('autoincrement' => true, 'primary' => true)) + ['autoincrement' => true, 'primary' => true] + ) ); self::assertEquals( 'INTEGER', - $this->_platform->getIntegerTypeDeclarationSQL(array('unsigned' => false)) + $this->_platform->getIntegerTypeDeclarationSQL(['unsigned' => false]) ); self::assertEquals( 'INTEGER UNSIGNED', - $this->_platform->getIntegerTypeDeclarationSQL(array('unsigned' => true)) + $this->_platform->getIntegerTypeDeclarationSQL(['unsigned' => true]) ); } @@ -202,28 +206,29 @@ public function testGeneratesTypeDeclarationForBigIntegers() { self::assertEquals( 'BIGINT', - $this->_platform->getBigIntTypeDeclarationSQL(array()) + $this->_platform->getBigIntTypeDeclarationSQL([]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getBigIntTypeDeclarationSQL(array('autoincrement' => true)) + $this->_platform->getBigIntTypeDeclarationSQL(['autoincrement' => true]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getBigIntTypeDeclarationSQL(array('autoincrement' => true, 'unsigned' => true)) + $this->_platform->getBigIntTypeDeclarationSQL(['autoincrement' => true, 'unsigned' => true]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', $this->_platform->getBigIntTypeDeclarationSQL( - array('autoincrement' => true, 'primary' => true)) + ['autoincrement' => true, 'primary' => true] + ) ); self::assertEquals( 'BIGINT', - $this->_platform->getBigIntTypeDeclarationSQL(array('unsigned' => false)) + $this->_platform->getBigIntTypeDeclarationSQL(['unsigned' => false]) ); self::assertEquals( 'BIGINT UNSIGNED', - $this->_platform->getBigIntTypeDeclarationSQL(array('unsigned' => true)) + $this->_platform->getBigIntTypeDeclarationSQL(['unsigned' => true]) ); } @@ -232,16 +237,17 @@ public function testGeneratesTypeDeclarationForStrings() self::assertEquals( 'CHAR(10)', $this->_platform->getVarcharTypeDeclarationSQL( - array('length' => 10, 'fixed' => true)) + ['length' => 10, 'fixed' => true] + ) ); self::assertEquals( 'VARCHAR(50)', - $this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)), + $this->_platform->getVarcharTypeDeclarationSQL(['length' => 50]), 'Variable string declaration is not correct' ); self::assertEquals( 'VARCHAR(255)', - $this->_platform->getVarcharTypeDeclarationSQL(array()), + $this->_platform->getVarcharTypeDeclarationSQL([]), 'Long string declaration is not correct' ); } @@ -297,14 +303,14 @@ public function testModifyLimitQueryWithOffsetAndEmptyLimit() public function getGenerateAlterTableSql() { - return array( - "CREATE TEMPORARY TABLE __temp__mytable AS SELECT id, bar, bloo FROM mytable", - "DROP TABLE mytable", + return [ + 'CREATE TEMPORARY TABLE __temp__mytable AS SELECT id, bar, bloo FROM mytable', + 'DROP TABLE mytable', "CREATE TABLE mytable (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, baz VARCHAR(255) DEFAULT 'def' NOT NULL, bloo BOOLEAN DEFAULT '0' NOT NULL, quota INTEGER DEFAULT NULL)", - "INSERT INTO mytable (id, baz, bloo) SELECT id, bar, bloo FROM __temp__mytable", - "DROP TABLE __temp__mytable", - "ALTER TABLE mytable RENAME TO userlist", - ); + 'INSERT INTO mytable (id, baz, bloo) SELECT id, bar, bloo FROM __temp__mytable', + 'DROP TABLE __temp__mytable', + 'ALTER TABLE mytable RENAME TO userlist', + ]; } /** @@ -312,9 +318,9 @@ public function getGenerateAlterTableSql() */ public function testGenerateTableSqlShouldNotAutoQuotePrimaryKey() { - $table = new \Doctrine\DBAL\Schema\Table('test'); - $table->addColumn('"like"', 'integer', array('notnull' => true, 'autoincrement' => true)); - $table->setPrimaryKey(array('"like"')); + $table = new Table('test'); + $table->addColumn('"like"', 'integer', ['notnull' => true, 'autoincrement' => true]); + $table->setPrimaryKey(['"like"']); $createTableSQL = $this->_platform->getCreateTableSQL($table); self::assertEquals( @@ -325,14 +331,14 @@ public function testGenerateTableSqlShouldNotAutoQuotePrimaryKey() public function testAlterTableAddColumns() { - $diff = new TableDiff('user'); - $diff->addedColumns['foo'] = new Column('foo', Type::getType('string')); - $diff->addedColumns['count'] = new Column('count', Type::getType('integer'), array('notnull' => false, 'default' => 1)); + $diff = new TableDiff('user'); + $diff->addedColumns['foo'] = new Column('foo', Type::getType('string')); + $diff->addedColumns['count'] = new Column('count', Type::getType('integer'), ['notnull' => false, 'default' => 1]); - $expected = array( + $expected = [ 'ALTER TABLE user ADD COLUMN foo VARCHAR(255) NOT NULL', 'ALTER TABLE user ADD COLUMN count INTEGER DEFAULT 1', - ); + ]; self::assertEquals($expected, $this->_platform->getAlterTableSQL($diff)); } @@ -349,12 +355,11 @@ public function testAlterTableAddComplexColumns(TableDiff $diff) : void public function complexDiffProvider() : array { - $date = new TableDiff('user'); - $date->addedColumns['time'] = new Column('time', Type::getType('date'), array('default' => 'CURRENT_DATE')); + $date = new TableDiff('user'); + $date->addedColumns['time'] = new Column('time', Type::getType('date'), ['default' => 'CURRENT_DATE']); - - $id = new TableDiff('user'); - $id->addedColumns['id'] = new Column('id', Type::getType('integer'), array('autoincrement' => true)); + $id = new TableDiff('user'); + $id->addedColumns['id'] = new Column('id', Type::getType('integer'), ['autoincrement' => true]); return [ 'date column with default value' => [$date], @@ -369,12 +374,12 @@ public function testCreateTableWithDeferredForeignKeys() $table->addColumn('article', 'integer'); $table->addColumn('post', 'integer'); $table->addColumn('parent', 'integer'); - $table->setPrimaryKey(array('id')); - $table->addForeignKeyConstraint('article', array('article'), array('id'), array('deferrable' => true)); - $table->addForeignKeyConstraint('post', array('post'), array('id'), array('deferred' => true)); - $table->addForeignKeyConstraint('user', array('parent'), array('id'), array('deferrable' => true, 'deferred' => true)); + $table->setPrimaryKey(['id']); + $table->addForeignKeyConstraint('article', ['article'], ['id'], ['deferrable' => true]); + $table->addForeignKeyConstraint('post', ['post'], ['id'], ['deferred' => true]); + $table->addForeignKeyConstraint('user', ['parent'], ['id'], ['deferrable' => true, 'deferred' => true]); - $sql = array( + $sql = [ 'CREATE TABLE user (' . 'id INTEGER NOT NULL, article INTEGER NOT NULL, post INTEGER NOT NULL, parent INTEGER NOT NULL' . ', PRIMARY KEY(id)' @@ -385,7 +390,7 @@ public function testCreateTableWithDeferredForeignKeys() 'CREATE INDEX IDX_8D93D64923A0E66 ON user (article)', 'CREATE INDEX IDX_8D93D6495A8A6C8D ON user (post)', 'CREATE INDEX IDX_8D93D6493D8E604F ON user (parent)', - ); + ]; self::assertEquals($sql, $this->_platform->getCreateTableSQL($table)); } @@ -397,21 +402,21 @@ public function testAlterTable() $table->addColumn('article', 'integer'); $table->addColumn('post', 'integer'); $table->addColumn('parent', 'integer'); - $table->setPrimaryKey(array('id')); - $table->addForeignKeyConstraint('article', array('article'), array('id'), array('deferrable' => true)); - $table->addForeignKeyConstraint('post', array('post'), array('id'), array('deferred' => true)); - $table->addForeignKeyConstraint('user', array('parent'), array('id'), array('deferrable' => true, 'deferred' => true)); - $table->addIndex(array('article', 'post'), 'index1'); - - $diff = new TableDiff('user'); - $diff->fromTable = $table; - $diff->newName = 'client'; - $diff->renamedColumns['id'] = new \Doctrine\DBAL\Schema\Column('key', \Doctrine\DBAL\Types\Type::getType('integer'), array()); - $diff->renamedColumns['post'] = new \Doctrine\DBAL\Schema\Column('comment', \Doctrine\DBAL\Types\Type::getType('integer'), array()); - $diff->removedColumns['parent'] = new \Doctrine\DBAL\Schema\Column('comment', \Doctrine\DBAL\Types\Type::getType('integer'), array()); + $table->setPrimaryKey(['id']); + $table->addForeignKeyConstraint('article', ['article'], ['id'], ['deferrable' => true]); + $table->addForeignKeyConstraint('post', ['post'], ['id'], ['deferred' => true]); + $table->addForeignKeyConstraint('user', ['parent'], ['id'], ['deferrable' => true, 'deferred' => true]); + $table->addIndex(['article', 'post'], 'index1'); + + $diff = new TableDiff('user'); + $diff->fromTable = $table; + $diff->newName = 'client'; + $diff->renamedColumns['id'] = new Column('key', Type::getType('integer'), []); + $diff->renamedColumns['post'] = new Column('comment', Type::getType('integer'), []); + $diff->removedColumns['parent'] = new Column('comment', Type::getType('integer'), []); $diff->removedIndexes['index1'] = $table->getIndex('index1'); - $sql = array( + $sql = [ 'DROP INDEX IDX_8D93D64923A0E66', 'DROP INDEX IDX_8D93D6495A8A6C8D', 'DROP INDEX IDX_8D93D6493D8E604F', @@ -429,43 +434,41 @@ public function testAlterTable() 'ALTER TABLE user RENAME TO client', 'CREATE INDEX IDX_8D93D64923A0E66 ON client (article)', 'CREATE INDEX IDX_8D93D6495A8A6C8D ON client (comment)', - ); + ]; self::assertEquals($sql, $this->_platform->getAlterTableSQL($diff)); } protected function getQuotedColumnInPrimaryKeySQL() { - return array( - 'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, PRIMARY KEY("create"))', - ); + return ['CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, PRIMARY KEY("create"))']; } protected function getQuotedColumnInIndexSQL() { - return array( + return [ 'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL)', 'CREATE INDEX IDX_22660D028FD6E0FB ON "quoted" ("create")', - ); + ]; } protected function getQuotedNameInIndexSQL() { - return array( + return [ 'CREATE TABLE test (column1 VARCHAR(255) NOT NULL)', 'CREATE INDEX "key" ON test (column1)', - ); + ]; } protected function getQuotedColumnInForeignKeySQL() { - return 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") NOT DEFERRABLE INITIALLY IMMEDIATE, ' . 'CONSTRAINT FK_WITH_NON_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES foo ("create", bar, "foo-bar") NOT DEFERRABLE INITIALLY IMMEDIATE, ' . 'CONSTRAINT FK_WITH_INTENDED_QUOTATION FOREIGN KEY ("create", foo, "bar") REFERENCES "foo-bar" ("create", bar, "foo-bar") NOT DEFERRABLE INITIALLY IMMEDIATE)', - ); + ]; } protected function getBinaryDefaultLength() @@ -480,13 +483,13 @@ protected function getBinaryMaxLength() public function testReturnsBinaryTypeDeclarationSQL() { - self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(array())); - self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 0))); - self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 9999999))); + self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL([])); + self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 0])); + self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 9999999])); - self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true))); - self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 0))); - self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 9999999))); + self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true])); + self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 0])); + self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 9999999])); } /** @@ -494,14 +497,14 @@ public function testReturnsBinaryTypeDeclarationSQL() */ protected function getAlterTableRenameIndexSQL() { - return array( + return [ 'CREATE TEMPORARY TABLE __temp__mytable AS SELECT id FROM mytable', 'DROP TABLE mytable', 'CREATE TABLE mytable (id INTEGER NOT NULL, PRIMARY KEY(id))', 'INSERT INTO mytable (id) SELECT id FROM __temp__mytable', 'DROP TABLE __temp__mytable', 'CREATE INDEX idx_bar ON mytable (id)', - ); + ]; } /** @@ -509,7 +512,7 @@ protected function getAlterTableRenameIndexSQL() */ protected function getQuotedAlterTableRenameIndexSQL() { - return array( + return [ 'CREATE TEMPORARY TABLE __temp__table AS SELECT id FROM "table"', 'DROP TABLE "table"', 'CREATE TABLE "table" (id INTEGER NOT NULL, PRIMARY KEY(id))', @@ -517,7 +520,7 @@ protected function getQuotedAlterTableRenameIndexSQL() 'DROP TABLE __temp__table', 'CREATE INDEX "select" ON "table" (id)', 'CREATE INDEX "bar" ON "table" (id)', - ); + ]; } /** @@ -525,7 +528,7 @@ protected function getQuotedAlterTableRenameIndexSQL() */ protected function getQuotedAlterTableRenameColumnSQL() { - return array( + return [ 'CREATE TEMPORARY TABLE __temp__mytable AS SELECT unquoted1, unquoted2, unquoted3, "create", "table", "select", "quoted1", "quoted2", "quoted3" FROM mytable', 'DROP TABLE mytable', 'CREATE TABLE mytable (unquoted INTEGER NOT NULL --Unquoted 1 @@ -540,7 +543,7 @@ protected function getQuotedAlterTableRenameColumnSQL() )', 'INSERT INTO mytable (unquoted, "where", "foo", reserved_keyword, "from", "bar", quoted, "and", "baz") SELECT unquoted1, unquoted2, unquoted3, "create", "table", "select", "quoted1", "quoted2", "quoted3" FROM __temp__mytable', 'DROP TABLE __temp__mytable', - ); + ]; } /** @@ -548,7 +551,7 @@ protected function getQuotedAlterTableRenameColumnSQL() */ protected function getQuotedAlterTableChangeColumnLengthSQL() { - return array( + return [ 'CREATE TEMPORARY TABLE __temp__mytable AS SELECT unquoted1, unquoted2, unquoted3, "create", "table", "select" FROM mytable', 'DROP TABLE mytable', 'CREATE TABLE mytable (unquoted1 VARCHAR(255) NOT NULL --Unquoted 1 @@ -560,7 +563,7 @@ protected function getQuotedAlterTableChangeColumnLengthSQL() )', 'INSERT INTO mytable (unquoted1, unquoted2, unquoted3, "create", "table", "select") SELECT unquoted1, unquoted2, unquoted3, "create", "table", "select" FROM __temp__mytable', 'DROP TABLE __temp__mytable', - ); + ]; } /** @@ -590,7 +593,7 @@ public function testQuotesAlterTableRenameIndexInSchema() */ public function testReturnsGuidTypeDeclarationSQL() { - self::assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL(array())); + self::assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL([])); } /** @@ -598,14 +601,14 @@ public function testReturnsGuidTypeDeclarationSQL() */ public function getAlterTableRenameColumnSQL() { - return array( + return [ 'CREATE TEMPORARY TABLE __temp__foo AS SELECT bar FROM foo', 'DROP TABLE foo', 'CREATE TABLE foo (baz INTEGER DEFAULT 666 NOT NULL --rename test )', 'INSERT INTO foo (baz) SELECT bar FROM __temp__foo', 'DROP TABLE __temp__foo', - ); + ]; } /** @@ -613,7 +616,7 @@ public function getAlterTableRenameColumnSQL() */ protected function getQuotesTableIdentifiersInAlterTableSQL() { - return array( + return [ 'DROP INDEX IDX_8C736521A81E660E', 'DROP INDEX IDX_8C736521FDC58D6C', 'CREATE TEMPORARY TABLE __temp__foo AS SELECT fk, fk2, id, fk3, bar FROM "foo"', @@ -627,7 +630,7 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() 'ALTER TABLE "foo" RENAME TO "table"', 'CREATE INDEX IDX_8C736521A81E660E ON "table" (fk)', 'CREATE INDEX IDX_8C736521FDC58D6C ON "table" (fk2)', - ); + ]; } /** @@ -635,11 +638,11 @@ protected function getQuotesTableIdentifiersInAlterTableSQL() */ protected function getCommentOnColumnSQL() { - return array( + return [ 'COMMENT ON COLUMN foo.bar IS \'comment\'', 'COMMENT ON COLUMN "Foo"."BAR" IS \'comment\'', 'COMMENT ON COLUMN "select"."from" IS \'comment\'', - ); + ]; } protected function getInlineColumnCommentDelimiter() @@ -691,13 +694,13 @@ protected function getQuotesReservedKeywordInTruncateTableSQL() */ protected function getAlterStringToFixedStringSQL() { - return array( + return [ 'CREATE TEMPORARY TABLE __temp__mytable AS SELECT name FROM mytable', 'DROP TABLE mytable', 'CREATE TABLE mytable (name CHAR(2) NOT NULL)', 'INSERT INTO mytable (name) SELECT name FROM __temp__mytable', 'DROP TABLE __temp__mytable', - ); + ]; } /** @@ -705,7 +708,7 @@ protected function getAlterStringToFixedStringSQL() */ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() { - return array( + return [ 'DROP INDEX idx_foo', 'DROP INDEX idx_bar', 'CREATE TEMPORARY TABLE __temp__mytable AS SELECT foo, bar, baz FROM mytable', @@ -715,7 +718,7 @@ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() 'DROP TABLE __temp__mytable', 'CREATE INDEX idx_bar ON mytable (bar)', 'CREATE INDEX idx_foo_renamed ON mytable (foo)', - ); + ]; } /** diff --git a/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php b/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php index 83775e13f2e..5a783ef6415 100644 --- a/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php @@ -6,23 +6,19 @@ use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Portability\Connection; use Doctrine\DBAL\Portability\Statement; +use Doctrine\Tests\DbalTestCase; +use PHPUnit_Framework_MockObject_MockObject; use function iterator_to_array; -class StatementTest extends \Doctrine\Tests\DbalTestCase +class StatementTest extends DbalTestCase { - /** - * @var \Doctrine\DBAL\Portability\Connection|\PHPUnit_Framework_MockObject_MockObject - */ + /** @var Connection|PHPUnit_Framework_MockObject_MockObject */ protected $conn; - /** - * @var \Doctrine\DBAL\Portability\Statement - */ + /** @var Statement */ protected $stmt; - /** - * @var \Doctrine\DBAL\Driver\Statement|\PHPUnit_Framework_MockObject_MockObject - */ + /** @var \Doctrine\DBAL\Driver\Statement|PHPUnit_Framework_MockObject_MockObject */ protected $wrappedStmt; /** @@ -100,7 +96,7 @@ public function testErrorCode() public function testErrorInfo() { - $errorInfo = array('666', 'Evil error.'); + $errorInfo = ['666', 'Evil error.']; $this->wrappedStmt->expects($this->once()) ->method('errorInfo') @@ -111,10 +107,10 @@ public function testErrorInfo() public function testExecute() { - $params = array( + $params = [ 'foo', - 'bar' - ); + 'bar', + ]; $this->wrappedStmt->expects($this->once()) ->method('execute') @@ -128,7 +124,7 @@ public function testSetFetchMode() { $fetchMode = FetchMode::CUSTOM_OBJECT; $arg1 = 'MyClass'; - $arg2 = array(1, 2); + $arg2 = [1, 2]; $this->wrappedStmt->expects($this->once()) ->method('setFetchMode') @@ -161,7 +157,7 @@ public function testRowCount() } /** - * @return \Doctrine\DBAL\Portability\Connection|\PHPUnit_Framework_MockObject_MockObject + * @return Connection|PHPUnit_Framework_MockObject_MockObject */ protected function createConnection() { @@ -171,10 +167,7 @@ protected function createConnection() } /** - * @param \Doctrine\DBAL\Driver\Statement $wrappedStatement - * @param \Doctrine\DBAL\Portability\Connection $connection - * - * @return \Doctrine\DBAL\Portability\Statement + * @return Statement */ protected function createStatement(\Doctrine\DBAL\Driver\Statement $wrappedStatement, Connection $connection) { @@ -182,7 +175,7 @@ protected function createStatement(\Doctrine\DBAL\Driver\Statement $wrappedState } /** - * @return \Doctrine\DBAL\Driver\Statement|\PHPUnit_Framework_MockObject_MockObject + * @return \Doctrine\DBAL\Driver\Statement|PHPUnit_Framework_MockObject_MockObject */ protected function createWrappedStatement() { diff --git a/tests/Doctrine/Tests/DBAL/Query/Expression/CompositeExpressionTest.php b/tests/Doctrine/Tests/DBAL/Query/Expression/CompositeExpressionTest.php index 2ae9d0087e4..512dfb08224 100644 --- a/tests/Doctrine/Tests/DBAL/Query/Expression/CompositeExpressionTest.php +++ b/tests/Doctrine/Tests/DBAL/Query/Expression/CompositeExpressionTest.php @@ -3,15 +3,16 @@ namespace Doctrine\Tests\DBAL\Query\Expression; use Doctrine\DBAL\Query\Expression\CompositeExpression; +use Doctrine\Tests\DbalTestCase; /** * @group DBAL-12 */ -class CompositeExpressionTest extends \Doctrine\Tests\DbalTestCase +class CompositeExpressionTest extends DbalTestCase { public function testCount() { - $expr = new CompositeExpression(CompositeExpression::TYPE_OR, array('u.group_id = 1')); + $expr = new CompositeExpression(CompositeExpression::TYPE_OR, ['u.group_id = 1']); self::assertCount(1, $expr); @@ -22,15 +23,15 @@ public function testCount() public function testAdd() { - $expr = new CompositeExpression(CompositeExpression::TYPE_OR, array('u.group_id = 1')); + $expr = new CompositeExpression(CompositeExpression::TYPE_OR, ['u.group_id = 1']); self::assertCount(1, $expr); - $expr->add(new CompositeExpression(CompositeExpression::TYPE_AND, array())); + $expr->add(new CompositeExpression(CompositeExpression::TYPE_AND, [])); self::assertCount(1, $expr); - $expr->add(new CompositeExpression(CompositeExpression::TYPE_OR, array('u.user_id = 1'))); + $expr->add(new CompositeExpression(CompositeExpression::TYPE_OR, ['u.user_id = 1'])); self::assertCount(2, $expr); @@ -55,49 +56,49 @@ public function testCompositeUsageAndGeneration($type, $parts, $expects) public function provideDataForConvertToString() { - return array( - array( + return [ + [ CompositeExpression::TYPE_AND, - array('u.user = 1'), - 'u.user = 1' - ), - array( + ['u.user = 1'], + 'u.user = 1', + ], + [ CompositeExpression::TYPE_AND, - array('u.user = 1', 'u.group_id = 1'), - '(u.user = 1) AND (u.group_id = 1)' - ), - array( + ['u.user = 1', 'u.group_id = 1'], + '(u.user = 1) AND (u.group_id = 1)', + ], + [ CompositeExpression::TYPE_OR, - array('u.user = 1'), - 'u.user = 1' - ), - array( + ['u.user = 1'], + 'u.user = 1', + ], + [ CompositeExpression::TYPE_OR, - array('u.group_id = 1', 'u.group_id = 2'), - '(u.group_id = 1) OR (u.group_id = 2)' - ), - array( + ['u.group_id = 1', 'u.group_id = 2'], + '(u.group_id = 1) OR (u.group_id = 2)', + ], + [ CompositeExpression::TYPE_AND, - array( + [ 'u.user = 1', new CompositeExpression( CompositeExpression::TYPE_OR, - array('u.group_id = 1', 'u.group_id = 2') - ) - ), - '(u.user = 1) AND ((u.group_id = 1) OR (u.group_id = 2))' - ), - array( + ['u.group_id = 1', 'u.group_id = 2'] + ), + ], + '(u.user = 1) AND ((u.group_id = 1) OR (u.group_id = 2))', + ], + [ CompositeExpression::TYPE_OR, - array( + [ 'u.group_id = 1', new CompositeExpression( CompositeExpression::TYPE_AND, - array('u.user = 1', 'u.group_id = 2') - ) - ), - '(u.group_id = 1) OR ((u.user = 1) AND (u.group_id = 2))' - ), - ); + ['u.user = 1', 'u.group_id = 2'] + ), + ], + '(u.group_id = 1) OR ((u.user = 1) AND (u.group_id = 2))', + ], + ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php b/tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php index d4a1d111942..1fe2ac97416 100644 --- a/tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php +++ b/tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php @@ -4,15 +4,14 @@ use Doctrine\DBAL\Query\Expression\CompositeExpression; use Doctrine\DBAL\Query\Expression\ExpressionBuilder; +use Doctrine\Tests\DbalTestCase; /** * @group DBAL-12 */ -class ExpressionBuilderTest extends \Doctrine\Tests\DbalTestCase +class ExpressionBuilderTest extends DbalTestCase { - /** - * @var ExpressionBuilder - */ + /** @var ExpressionBuilder */ protected $expr; protected function setUp() @@ -42,44 +41,44 @@ public function testAndX($parts, $expected) public function provideDataForAndX() { - return array( - array( - array('u.user = 1'), - 'u.user = 1' - ), - array( - array('u.user = 1', 'u.group_id = 1'), - '(u.user = 1) AND (u.group_id = 1)' - ), - array( - array('u.user = 1'), - 'u.user = 1' - ), - array( - array('u.group_id = 1', 'u.group_id = 2'), - '(u.group_id = 1) AND (u.group_id = 2)' - ), - array( - array( + return [ + [ + ['u.user = 1'], + 'u.user = 1', + ], + [ + ['u.user = 1', 'u.group_id = 1'], + '(u.user = 1) AND (u.group_id = 1)', + ], + [ + ['u.user = 1'], + 'u.user = 1', + ], + [ + ['u.group_id = 1', 'u.group_id = 2'], + '(u.group_id = 1) AND (u.group_id = 2)', + ], + [ + [ 'u.user = 1', new CompositeExpression( CompositeExpression::TYPE_OR, - array('u.group_id = 1', 'u.group_id = 2') - ) - ), - '(u.user = 1) AND ((u.group_id = 1) OR (u.group_id = 2))' - ), - array( - array( + ['u.group_id = 1', 'u.group_id = 2'] + ), + ], + '(u.user = 1) AND ((u.group_id = 1) OR (u.group_id = 2))', + ], + [ + [ 'u.group_id = 1', new CompositeExpression( CompositeExpression::TYPE_AND, - array('u.user = 1', 'u.group_id = 2') - ) - ), - '(u.group_id = 1) AND ((u.user = 1) AND (u.group_id = 2))' - ), - ); + ['u.user = 1', 'u.group_id = 2'] + ), + ], + '(u.group_id = 1) AND ((u.user = 1) AND (u.group_id = 2))', + ], + ]; } /** @@ -98,44 +97,44 @@ public function testOrX($parts, $expected) public function provideDataForOrX() { - return array( - array( - array('u.user = 1'), - 'u.user = 1' - ), - array( - array('u.user = 1', 'u.group_id = 1'), - '(u.user = 1) OR (u.group_id = 1)' - ), - array( - array('u.user = 1'), - 'u.user = 1' - ), - array( - array('u.group_id = 1', 'u.group_id = 2'), - '(u.group_id = 1) OR (u.group_id = 2)' - ), - array( - array( + return [ + [ + ['u.user = 1'], + 'u.user = 1', + ], + [ + ['u.user = 1', 'u.group_id = 1'], + '(u.user = 1) OR (u.group_id = 1)', + ], + [ + ['u.user = 1'], + 'u.user = 1', + ], + [ + ['u.group_id = 1', 'u.group_id = 2'], + '(u.group_id = 1) OR (u.group_id = 2)', + ], + [ + [ 'u.user = 1', new CompositeExpression( CompositeExpression::TYPE_OR, - array('u.group_id = 1', 'u.group_id = 2') - ) - ), - '(u.user = 1) OR ((u.group_id = 1) OR (u.group_id = 2))' - ), - array( - array( + ['u.group_id = 1', 'u.group_id = 2'] + ), + ], + '(u.user = 1) OR ((u.group_id = 1) OR (u.group_id = 2))', + ], + [ + [ 'u.group_id = 1', new CompositeExpression( CompositeExpression::TYPE_AND, - array('u.user = 1', 'u.group_id = 2') - ) - ), - '(u.group_id = 1) OR ((u.user = 1) AND (u.group_id = 2))' - ), - ); + ['u.user = 1', 'u.group_id = 2'] + ), + ], + '(u.group_id = 1) OR ((u.user = 1) AND (u.group_id = 2))', + ], + ]; } /** @@ -150,14 +149,14 @@ public function testComparison($leftExpr, $operator, $rightExpr, $expected) public function provideDataForComparison() { - return array( - array('u.user_id', ExpressionBuilder::EQ, '1', 'u.user_id = 1'), - array('u.user_id', ExpressionBuilder::NEQ, '1', 'u.user_id <> 1'), - array('u.salary', ExpressionBuilder::LT, '10000', 'u.salary < 10000'), - array('u.salary', ExpressionBuilder::LTE, '10000', 'u.salary <= 10000'), - array('u.salary', ExpressionBuilder::GT, '10000', 'u.salary > 10000'), - array('u.salary', ExpressionBuilder::GTE, '10000', 'u.salary >= 10000'), - ); + return [ + ['u.user_id', ExpressionBuilder::EQ, '1', 'u.user_id = 1'], + ['u.user_id', ExpressionBuilder::NEQ, '1', 'u.user_id <> 1'], + ['u.salary', ExpressionBuilder::LT, '10000', 'u.salary < 10000'], + ['u.salary', ExpressionBuilder::LTE, '10000', 'u.salary <= 10000'], + ['u.salary', ExpressionBuilder::GT, '10000', 'u.salary > 10000'], + ['u.salary', ExpressionBuilder::GTE, '10000', 'u.salary >= 10000'], + ]; } public function testEq() @@ -202,7 +201,7 @@ public function testIsNotNull() public function testIn() { - self::assertEquals('u.groups IN (1, 3, 4, 7)', $this->expr->in('u.groups', array(1,3,4,7))); + self::assertEquals('u.groups IN (1, 3, 4, 7)', $this->expr->in('u.groups', [1, 3, 4, 7])); } public function testInWithPlaceholder() @@ -212,7 +211,7 @@ public function testInWithPlaceholder() public function testNotIn() { - self::assertEquals('u.groups NOT IN (1, 3, 4, 7)', $this->expr->notIn('u.groups', array(1,3,4,7))); + self::assertEquals('u.groups NOT IN (1, 3, 4, 7)', $this->expr->notIn('u.groups', [1, 3, 4, 7])); } public function testNotInWithPlaceholder() diff --git a/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php b/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php index 97145d53d3a..1bbb61e8a06 100644 --- a/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php +++ b/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php @@ -2,18 +2,18 @@ namespace Doctrine\Tests\DBAL\Query; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Query\Expression\ExpressionBuilder; use Doctrine\DBAL\Query\QueryBuilder; +use Doctrine\Tests\DbalTestCase; /** * @group DBAL-12 */ -class QueryBuilderTest extends \Doctrine\Tests\DbalTestCase +class QueryBuilderTest extends DbalTestCase { - /** - * @var \Doctrine\DBAL\Connection - */ + /** @var Connection */ protected $conn; protected function setUp() @@ -58,7 +58,7 @@ public function testSelectWithSimpleWhere() ->from('users', 'u') ->where($expr->andX($expr->eq('u.nickname', '?'))); - self::assertEquals("SELECT u.id FROM users u WHERE u.nickname = ?", (string) $qb); + self::assertEquals('SELECT u.id FROM users u WHERE u.nickname = ?', (string) $qb); } public function testSelectWithLeftJoin() @@ -181,7 +181,7 @@ public function testSelectEmptyGroupBy() $expr = $qb->expr(); $qb->select('u.*', 'p.*') - ->groupBy(array()) + ->groupBy([]) ->from('users', 'u'); self::assertEquals('SELECT u.*, p.* FROM users u', (string) $qb); @@ -193,7 +193,7 @@ public function testSelectEmptyAddGroupBy() $expr = $qb->expr(); $qb->select('u.*', 'p.*') - ->addGroupBy(array()) + ->addGroupBy([]) ->from('users', 'u'); self::assertEquals('SELECT u.*, p.* FROM users u', (string) $qb); @@ -348,7 +348,7 @@ public function testSelectAddAddOrderBy() public function testEmptySelect() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb2 = $qb->select(); self::assertSame($qb, $qb2); @@ -369,7 +369,7 @@ public function testSelectAddSelect() public function testEmptyAddSelect() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb2 = $qb->addSelect(); self::assertSame($qb, $qb2); @@ -391,7 +391,7 @@ public function testSelectMultipleFrom() public function testUpdate() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb->update('users', 'u') ->set('u.foo', '?') ->set('u.bar', '?'); @@ -402,7 +402,7 @@ public function testUpdate() public function testUpdateWithoutAlias() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb->update('users') ->set('foo', '?') ->set('bar', '?'); @@ -412,7 +412,7 @@ public function testUpdateWithoutAlias() public function testUpdateWhere() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb->update('users', 'u') ->set('u.foo', '?') ->where('u.foo = ?'); @@ -422,7 +422,7 @@ public function testUpdateWhere() public function testEmptyUpdate() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb2 = $qb->update(); self::assertEquals(QueryBuilder::UPDATE, $qb->getType()); @@ -431,7 +431,7 @@ public function testEmptyUpdate() public function testDelete() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb->delete('users', 'u'); self::assertEquals(QueryBuilder::DELETE, $qb->getType()); @@ -440,7 +440,7 @@ public function testDelete() public function testDeleteWithoutAlias() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb->delete('users'); self::assertEquals(QueryBuilder::DELETE, $qb->getType()); @@ -449,7 +449,7 @@ public function testDeleteWithoutAlias() public function testDeleteWhere() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb->delete('users', 'u') ->where('u.foo = ?'); @@ -458,7 +458,7 @@ public function testDeleteWhere() public function testEmptyDelete() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb2 = $qb->delete(); self::assertEquals(QueryBuilder::DELETE, $qb->getType()); @@ -470,10 +470,10 @@ public function testInsertValues() $qb = new QueryBuilder($this->conn); $qb->insert('users') ->values( - array( + [ 'foo' => '?', - 'bar' => '?' - ) + 'bar' => '?', + ] ); self::assertEquals(QueryBuilder::INSERT, $qb->getType()); @@ -485,16 +485,16 @@ public function testInsertReplaceValues() $qb = new QueryBuilder($this->conn); $qb->insert('users') ->values( - array( + [ 'foo' => '?', - 'bar' => '?' - ) + 'bar' => '?', + ] ) ->values( - array( + [ 'bar' => '?', - 'foo' => '?' - ) + 'foo' => '?', + ] ); self::assertEquals(QueryBuilder::INSERT, $qb->getType()); @@ -518,9 +518,7 @@ public function testInsertValuesSetValue() $qb = new QueryBuilder($this->conn); $qb->insert('users') ->values( - array( - 'foo' => '?' - ) + ['foo' => '?'] ) ->setValue('bar', '?'); @@ -530,7 +528,7 @@ public function testInsertValuesSetValue() public function testEmptyInsert() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb2 = $qb->insert(); self::assertEquals(QueryBuilder::INSERT, $qb->getType()); @@ -539,13 +537,13 @@ public function testEmptyInsert() public function testGetConnection() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); self::assertSame($this->conn, $qb->getConnection()); } public function testGetState() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); self::assertEquals(QueryBuilder::STATE_CLEAN, $qb->getState()); @@ -561,7 +559,7 @@ public function testGetState() public function testSetMaxResults() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb->setMaxResults(10); self::assertEquals(QueryBuilder::STATE_DIRTY, $qb->getState()); @@ -570,7 +568,7 @@ public function testSetMaxResults() public function testSetFirstResult() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb->setFirstResult(10); self::assertEquals(QueryBuilder::STATE_DIRTY, $qb->getState()); @@ -579,7 +577,7 @@ public function testSetFirstResult() public function testResetQueryPart() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb->select('u.*')->from('users', 'u')->where('u.name = ?'); @@ -590,18 +588,18 @@ public function testResetQueryPart() public function testResetQueryParts() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb->select('u.*')->from('users', 'u')->where('u.name = ?')->orderBy('u.name'); self::assertEquals('SELECT u.* FROM users u WHERE u.name = ? ORDER BY u.name ASC', (string) $qb); - $qb->resetQueryParts(array('where', 'orderBy')); + $qb->resetQueryParts(['where', 'orderBy']); self::assertEquals('SELECT u.* FROM users u', (string) $qb); } public function testCreateNamedParameter() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb->select('u.*')->from('users', 'u')->where( $qb->expr()->eq('u.name', $qb->createNamedParameter(10, ParameterType::INTEGER)) @@ -614,7 +612,7 @@ public function testCreateNamedParameter() public function testCreateNamedParameterCustomPlaceholder() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb->select('u.*')->from('users', 'u')->where( $qb->expr()->eq('u.name', $qb->createNamedParameter(10, ParameterType::INTEGER, ':test')) @@ -627,7 +625,7 @@ public function testCreateNamedParameterCustomPlaceholder() public function testCreatePositionalParameter() { - $qb = new QueryBuilder($this->conn); + $qb = new QueryBuilder($this->conn); $qb->select('u.*')->from('users', 'u')->where( $qb->expr()->eq('u.name', $qb->createPositionalParameter(10, ParameterType::INTEGER)) @@ -785,7 +783,7 @@ public function testSelectWithSimpleWhereWithoutTableAlias() ->from('users') ->where('awesome=9001'); - self::assertEquals("SELECT id, name FROM users WHERE awesome=9001", (string) $qb); + self::assertEquals('SELECT id, name FROM users WHERE awesome=9001', (string) $qb); } public function testComplexSelectWithoutTableAliases() @@ -823,7 +821,7 @@ public function testSelectAllFromTableWithoutTableAlias() $qb->select('users.*') ->from('users'); - self::assertEquals("SELECT users.* FROM users", (string) $qb); + self::assertEquals('SELECT users.* FROM users', (string) $qb); } public function testSelectAllWithoutTableAlias() @@ -833,7 +831,7 @@ public function testSelectAllWithoutTableAlias() $qb->select('*') ->from('users'); - self::assertEquals("SELECT * FROM users", (string) $qb); + self::assertEquals('SELECT * FROM users', (string) $qb); } /** @@ -866,12 +864,12 @@ public function testGetParameterTypes() $qb->select('*')->from('users'); - self::assertSame(array(), $qb->getParameterTypes()); + self::assertSame([], $qb->getParameterTypes()); $qb->where('name = :name'); $qb->setParameter('name', 'foo'); - self::assertSame(array(), $qb->getParameterTypes()); + self::assertSame([], $qb->getParameterTypes()); $qb->setParameter('name', 'foo', ParameterType::STRING); diff --git a/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php b/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php index 0e057953b8a..09b518dcf21 100644 --- a/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php +++ b/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php @@ -5,60 +5,61 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\SQLParserUtils; +use Doctrine\Tests\DbalTestCase; /** * @group DBAL-78 * @group DDC-1372 */ -class SQLParserUtilsTest extends \Doctrine\Tests\DbalTestCase +class SQLParserUtilsTest extends DbalTestCase { public function dataGetPlaceholderPositions() { - return array( + return [ // none - array('SELECT * FROM Foo', true, array()), - array('SELECT * FROM Foo', false, array()), + ['SELECT * FROM Foo', true, []], + ['SELECT * FROM Foo', false, []], // Positionals - array('SELECT ?', true, array(7)), - array('SELECT * FROM Foo WHERE bar IN (?, ?, ?)', true, array(32, 35, 38)), - array('SELECT ? FROM ?', true, array(7, 14)), - array('SELECT "?" FROM foo', true, array()), - array("SELECT '?' FROM foo", true, array()), - array("SELECT `?` FROM foo", true, array()), // Ticket DBAL-552 - array("SELECT [?] FROM foo", true, array()), - array("SELECT 'Doctrine\DBAL?' FROM foo", true, array()), // Ticket DBAL-558 - array('SELECT "Doctrine\DBAL?" FROM foo', true, array()), // Ticket DBAL-558 - array('SELECT `Doctrine\DBAL?` FROM foo', true, array()), // Ticket DBAL-558 - array('SELECT [Doctrine\DBAL?] FROM foo', true, array()), // Ticket DBAL-558 - array('SELECT "?" FROM foo WHERE bar = ?', true, array(32)), - array("SELECT '?' FROM foo WHERE bar = ?", true, array(32)), - array("SELECT `?` FROM foo WHERE bar = ?", true, array(32)), // Ticket DBAL-552 - array("SELECT [?] FROM foo WHERE bar = ?", true, array(32)), - array('SELECT * FROM foo WHERE jsonb_exists_any(foo.bar, ARRAY[?])', true, array(56)), // Ticket GH-2295 - array("SELECT 'Doctrine\DBAL?' FROM foo WHERE bar = ?", true, array(45)), // Ticket DBAL-558 - array('SELECT "Doctrine\DBAL?" FROM foo WHERE bar = ?', true, array(45)), // Ticket DBAL-558 - array('SELECT `Doctrine\DBAL?` FROM foo WHERE bar = ?', true, array(45)), // Ticket DBAL-558 - array('SELECT [Doctrine\DBAL?] FROM foo WHERE bar = ?', true, array(45)), // Ticket DBAL-558 - array("SELECT * FROM FOO WHERE bar = 'it\\'s a trap? \\\\' OR bar = ?\nAND baz = \"\\\"quote\\\" me on it? \\\\\" OR baz = ?", true, array(58, 104)), - array('SELECT * FROM foo WHERE foo = ? AND bar = ?', true, array(1 => 42, 0 => 30)), // explicit keys + ['SELECT ?', true, [7]], + ['SELECT * FROM Foo WHERE bar IN (?, ?, ?)', true, [32, 35, 38]], + ['SELECT ? FROM ?', true, [7, 14]], + ['SELECT "?" FROM foo', true, []], + ["SELECT '?' FROM foo", true, []], + ['SELECT `?` FROM foo', true, []], // Ticket DBAL-552 + ['SELECT [?] FROM foo', true, []], + ["SELECT 'Doctrine\DBAL?' FROM foo", true, []], // Ticket DBAL-558 + ['SELECT "Doctrine\DBAL?" FROM foo', true, []], // Ticket DBAL-558 + ['SELECT `Doctrine\DBAL?` FROM foo', true, []], // Ticket DBAL-558 + ['SELECT [Doctrine\DBAL?] FROM foo', true, []], // Ticket DBAL-558 + ['SELECT "?" FROM foo WHERE bar = ?', true, [32]], + ["SELECT '?' FROM foo WHERE bar = ?", true, [32]], + ['SELECT `?` FROM foo WHERE bar = ?', true, [32]], // Ticket DBAL-552 + ['SELECT [?] FROM foo WHERE bar = ?', true, [32]], + ['SELECT * FROM foo WHERE jsonb_exists_any(foo.bar, ARRAY[?])', true, [56]], // Ticket GH-2295 + ["SELECT 'Doctrine\DBAL?' FROM foo WHERE bar = ?", true, [45]], // Ticket DBAL-558 + ['SELECT "Doctrine\DBAL?" FROM foo WHERE bar = ?', true, [45]], // Ticket DBAL-558 + ['SELECT `Doctrine\DBAL?` FROM foo WHERE bar = ?', true, [45]], // Ticket DBAL-558 + ['SELECT [Doctrine\DBAL?] FROM foo WHERE bar = ?', true, [45]], // Ticket DBAL-558 + ["SELECT * FROM FOO WHERE bar = 'it\\'s a trap? \\\\' OR bar = ?\nAND baz = \"\\\"quote\\\" me on it? \\\\\" OR baz = ?", true, [58, 104]], + ['SELECT * FROM foo WHERE foo = ? AND bar = ?', true, [1 => 42, 0 => 30]], // explicit keys // named - array('SELECT :foo FROM :bar', false, array(7 => 'foo', 17 => 'bar')), - array('SELECT * FROM Foo WHERE bar IN (:name1, :name2)', false, array(32 => 'name1', 40 => 'name2')), - array('SELECT ":foo" FROM Foo WHERE bar IN (:name1, :name2)', false, array(37 => 'name1', 45 => 'name2')), - array("SELECT ':foo' FROM Foo WHERE bar IN (:name1, :name2)", false, array(37 => 'name1', 45 => 'name2')), - array('SELECT :foo_id', false, array(7 => 'foo_id')), // Ticket DBAL-231 - array('SELECT @rank := 1', false, array()), // Ticket DBAL-398 - array('SELECT @rank := 1 AS rank, :foo AS foo FROM :bar', false, array(27 => 'foo', 44 => 'bar')), // Ticket DBAL-398 - array('SELECT * FROM Foo WHERE bar > :start_date AND baz > :start_date', false, array(30 => 'start_date', 52 => 'start_date')), // Ticket GH-113 - array('SELECT foo::date as date FROM Foo WHERE bar > :start_date AND baz > :start_date', false, array(46 => 'start_date', 68 => 'start_date')), // Ticket GH-259 - array('SELECT `d.ns:col_name` FROM my_table d WHERE `d.date` >= :param1', false, array(57 => 'param1')), // Ticket DBAL-552 - array('SELECT [d.ns:col_name] FROM my_table d WHERE [d.date] >= :param1', false, array(57 => 'param1')), // Ticket DBAL-552 + ['SELECT :foo FROM :bar', false, [7 => 'foo', 17 => 'bar']], + ['SELECT * FROM Foo WHERE bar IN (:name1, :name2)', false, [32 => 'name1', 40 => 'name2']], + ['SELECT ":foo" FROM Foo WHERE bar IN (:name1, :name2)', false, [37 => 'name1', 45 => 'name2']], + ["SELECT ':foo' FROM Foo WHERE bar IN (:name1, :name2)", false, [37 => 'name1', 45 => 'name2']], + ['SELECT :foo_id', false, [7 => 'foo_id']], // Ticket DBAL-231 + ['SELECT @rank := 1', false, []], // Ticket DBAL-398 + ['SELECT @rank := 1 AS rank, :foo AS foo FROM :bar', false, [27 => 'foo', 44 => 'bar']], // Ticket DBAL-398 + ['SELECT * FROM Foo WHERE bar > :start_date AND baz > :start_date', false, [30 => 'start_date', 52 => 'start_date']], // Ticket GH-113 + ['SELECT foo::date as date FROM Foo WHERE bar > :start_date AND baz > :start_date', false, [46 => 'start_date', 68 => 'start_date']], // Ticket GH-259 + ['SELECT `d.ns:col_name` FROM my_table d WHERE `d.date` >= :param1', false, [57 => 'param1']], // Ticket DBAL-552 + ['SELECT [d.ns:col_name] FROM my_table d WHERE [d.date] >= :param1', false, [57 => 'param1']], // Ticket DBAL-552 ['SELECT * FROM foo WHERE jsonb_exists_any(foo.bar, ARRAY[:foo])', false, [56 => 'foo']], // Ticket GH-2295 ['SELECT * FROM foo WHERE jsonb_exists_any(foo.bar, array[:foo])', false, [56 => 'foo']], - array( -<<<'SQLDATA' + [ + <<<'SQLDATA' SELECT * FROM foo WHERE bar = ':not_a_param1 ''":not_a_param2"''' OR bar=:a_param1 @@ -67,15 +68,21 @@ public function dataGetPlaceholderPositions() OR bar='' OR bar=:a_param3 SQLDATA - , false, array(74 => 'a_param1', 91 => 'a_param2', 190 => 'a_param3') - ), - array("SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE '\\\\') AND (data.description LIKE :condition_1 ESCAPE '\\\\') ORDER BY id ASC", false, array(121 => 'condition_0', 174 => 'condition_1')), - array('SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE "\\\\") AND (data.description LIKE :condition_1 ESCAPE "\\\\") ORDER BY id ASC', false, array(121 => 'condition_0', 174 => 'condition_1')), - array('SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE "\\\\") AND (data.description LIKE :condition_1 ESCAPE \'\\\\\') ORDER BY id ASC', false, array(121 => 'condition_0', 174 => 'condition_1')), - array('SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE `\\\\`) AND (data.description LIKE :condition_1 ESCAPE `\\\\`) ORDER BY id ASC', false, array(121 => 'condition_0', 174 => 'condition_1')), - array('SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE \'\\\\\') AND (data.description LIKE :condition_1 ESCAPE `\\\\`) ORDER BY id ASC', false, array(121 => 'condition_0', 174 => 'condition_1')), + , + false, + [ + 74 => 'a_param1', + 91 => 'a_param2', + 190 => 'a_param3', + ], + ], + ["SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE '\\\\') AND (data.description LIKE :condition_1 ESCAPE '\\\\') ORDER BY id ASC", false, [121 => 'condition_0', 174 => 'condition_1']], + ['SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE "\\\\") AND (data.description LIKE :condition_1 ESCAPE "\\\\") ORDER BY id ASC', false, [121 => 'condition_0', 174 => 'condition_1']], + ['SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE "\\\\") AND (data.description LIKE :condition_1 ESCAPE \'\\\\\') ORDER BY id ASC', false, [121 => 'condition_0', 174 => 'condition_1']], + ['SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE `\\\\`) AND (data.description LIKE :condition_1 ESCAPE `\\\\`) ORDER BY id ASC', false, [121 => 'condition_0', 174 => 'condition_1']], + ['SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE \'\\\\\') AND (data.description LIKE :condition_1 ESCAPE `\\\\`) ORDER BY id ASC', false, [121 => 'condition_0', 174 => 'condition_1']], - ); + ]; } /** @@ -89,120 +96,120 @@ public function testGetPlaceholderPositions($query, $isPositional, $expectedPara public function dataExpandListParameters() { - return array( + return [ // Positional: Very simple with one needle - array( - "SELECT * FROM Foo WHERE foo IN (?)", - array(array(1, 2, 3)), - array(Connection::PARAM_INT_ARRAY), + [ + 'SELECT * FROM Foo WHERE foo IN (?)', + [[1, 2, 3]], + [Connection::PARAM_INT_ARRAY], 'SELECT * FROM Foo WHERE foo IN (?, ?, ?)', - array(1, 2, 3), - array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER) - ), + [1, 2, 3], + [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER], + ], // Positional: One non-list before d one after list-needle - array( - "SELECT * FROM Foo WHERE foo = ? AND bar IN (?)", - array("string", array(1, 2, 3)), - array(ParameterType::STRING, Connection::PARAM_INT_ARRAY), + [ + 'SELECT * FROM Foo WHERE foo = ? AND bar IN (?)', + ['string', [1, 2, 3]], + [ParameterType::STRING, Connection::PARAM_INT_ARRAY], 'SELECT * FROM Foo WHERE foo = ? AND bar IN (?, ?, ?)', - array("string", 1, 2, 3), - array(ParameterType::STRING, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER) - ), + ['string', 1, 2, 3], + [ParameterType::STRING, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER], + ], // Positional: One non-list after list-needle - array( - "SELECT * FROM Foo WHERE bar IN (?) AND baz = ?", - array(array(1, 2, 3), "foo"), - array(Connection::PARAM_INT_ARRAY, ParameterType::STRING), + [ + 'SELECT * FROM Foo WHERE bar IN (?) AND baz = ?', + [[1, 2, 3], 'foo'], + [Connection::PARAM_INT_ARRAY, ParameterType::STRING], 'SELECT * FROM Foo WHERE bar IN (?, ?, ?) AND baz = ?', - array(1, 2, 3, "foo"), - array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING) - ), + [1, 2, 3, 'foo'], + [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING], + ], // Positional: One non-list before and one after list-needle - array( - "SELECT * FROM Foo WHERE foo = ? AND bar IN (?) AND baz = ?", - array(1, array(1, 2, 3), 4), - array(ParameterType::INTEGER, Connection::PARAM_INT_ARRAY, ParameterType::INTEGER), + [ + 'SELECT * FROM Foo WHERE foo = ? AND bar IN (?) AND baz = ?', + [1, [1, 2, 3], 4], + [ParameterType::INTEGER, Connection::PARAM_INT_ARRAY, ParameterType::INTEGER], 'SELECT * FROM Foo WHERE foo = ? AND bar IN (?, ?, ?) AND baz = ?', - array(1, 1, 2, 3, 4), - array( + [1, 1, 2, 3, 4], + [ ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, - ) - ), + ], + ], // Positional: Two lists - array( - "SELECT * FROM Foo WHERE foo IN (?, ?)", - array(array(1, 2, 3), array(4, 5)), - array(Connection::PARAM_INT_ARRAY, Connection::PARAM_INT_ARRAY), + [ + 'SELECT * FROM Foo WHERE foo IN (?, ?)', + [[1, 2, 3], [4, 5]], + [Connection::PARAM_INT_ARRAY, Connection::PARAM_INT_ARRAY], 'SELECT * FROM Foo WHERE foo IN (?, ?, ?, ?, ?)', - array(1, 2, 3, 4, 5), - array( + [1, 2, 3, 4, 5], + [ ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, - ) - ), + ], + ], // Positional: Empty "integer" array DDC-1978 - array( - "SELECT * FROM Foo WHERE foo IN (?)", - array(array()), - array(Connection::PARAM_INT_ARRAY), + [ + 'SELECT * FROM Foo WHERE foo IN (?)', + [[]], + [Connection::PARAM_INT_ARRAY], 'SELECT * FROM Foo WHERE foo IN (NULL)', - array(), - array() - ), + [], + [], + ], // Positional: Empty "str" array DDC-1978 - array( - "SELECT * FROM Foo WHERE foo IN (?)", - array(array()), - array(Connection::PARAM_STR_ARRAY), + [ + 'SELECT * FROM Foo WHERE foo IN (?)', + [[]], + [Connection::PARAM_STR_ARRAY], 'SELECT * FROM Foo WHERE foo IN (NULL)', - array(), - array() - ), + [], + [], + ], // Positional: explicit keys for params and types - array( - "SELECT * FROM Foo WHERE foo = ? AND bar = ? AND baz = ?", - array(1 => 'bar', 2 => 'baz', 0 => 1), - array(2 => ParameterType::STRING, 1 => ParameterType::STRING), + [ 'SELECT * FROM Foo WHERE foo = ? AND bar = ? AND baz = ?', - array(1 => 'bar', 0 => 1, 2 => 'baz'), - array(1 => ParameterType::STRING, 2 => ParameterType::STRING), - ), + [1 => 'bar', 2 => 'baz', 0 => 1], + [2 => ParameterType::STRING, 1 => ParameterType::STRING], + 'SELECT * FROM Foo WHERE foo = ? AND bar = ? AND baz = ?', + [1 => 'bar', 0 => 1, 2 => 'baz'], + [1 => ParameterType::STRING, 2 => ParameterType::STRING], + ], // Positional: explicit keys for array params and array types - array( - "SELECT * FROM Foo WHERE foo IN (?) AND bar IN (?) AND baz = ?", - array(1 => array('bar1', 'bar2'), 2 => true, 0 => array(1, 2, 3)), - array(2 => ParameterType::BOOLEAN, 1 => Connection::PARAM_STR_ARRAY, 0 => Connection::PARAM_INT_ARRAY), + [ + 'SELECT * FROM Foo WHERE foo IN (?) AND bar IN (?) AND baz = ?', + [1 => ['bar1', 'bar2'], 2 => true, 0 => [1, 2, 3]], + [2 => ParameterType::BOOLEAN, 1 => Connection::PARAM_STR_ARRAY, 0 => Connection::PARAM_INT_ARRAY], 'SELECT * FROM Foo WHERE foo IN (?, ?, ?) AND bar IN (?, ?) AND baz = ?', - array(1, 2, 3, 'bar1', 'bar2', true), - array( + [1, 2, 3, 'bar1', 'bar2', true], + [ ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING, ParameterType::STRING, ParameterType::BOOLEAN, - ) - ), + ], + ], // Positional starts from 1: One non-list before and one after list-needle - array( - "SELECT * FROM Foo WHERE foo = ? AND bar IN (?) AND baz = ? AND foo IN (?)", - array(1 => 1, 2 => array(1, 2, 3), 3 => 4, 4 => array(5, 6)), - array( + [ + 'SELECT * FROM Foo WHERE foo = ? AND bar IN (?) AND baz = ? AND foo IN (?)', + [1 => 1, 2 => [1, 2, 3], 3 => 4, 4 => [5, 6]], + [ 1 => ParameterType::INTEGER, 2 => Connection::PARAM_INT_ARRAY, 3 => ParameterType::INTEGER, 4 => Connection::PARAM_INT_ARRAY, - ), + ], 'SELECT * FROM Foo WHERE foo = ? AND bar IN (?, ?, ?) AND baz = ? AND foo IN (?, ?)', - array(1, 1, 2, 3, 4, 5, 6), - array( + [1, 1, 2, 3, 4, 5, 6], + [ ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, @@ -210,194 +217,194 @@ public function dataExpandListParameters() ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, - ) - ), + ], + ], // Named parameters : Very simple with param int - array( - "SELECT * FROM Foo WHERE foo = :foo", - array('foo'=>1), - array('foo' => ParameterType::INTEGER), + [ + 'SELECT * FROM Foo WHERE foo = :foo', + ['foo' => 1], + ['foo' => ParameterType::INTEGER], 'SELECT * FROM Foo WHERE foo = ?', - array(1), - array(ParameterType::INTEGER), - ), + [1], + [ParameterType::INTEGER], + ], // Named parameters : Very simple with param int and string - array( - "SELECT * FROM Foo WHERE foo = :foo AND bar = :bar", - array('bar'=>'Some String','foo'=>1), - array('foo' => ParameterType::INTEGER, 'bar' => ParameterType::STRING), + [ + 'SELECT * FROM Foo WHERE foo = :foo AND bar = :bar', + ['bar' => 'Some String','foo' => 1], + ['foo' => ParameterType::INTEGER, 'bar' => ParameterType::STRING], 'SELECT * FROM Foo WHERE foo = ? AND bar = ?', - array(1,'Some String'), - array(ParameterType::INTEGER, ParameterType::STRING) - ), + [1,'Some String'], + [ParameterType::INTEGER, ParameterType::STRING], + ], // Named parameters : Very simple with one needle - array( - "SELECT * FROM Foo WHERE foo IN (:foo)", - array('foo'=>array(1, 2, 3)), - array('foo'=>Connection::PARAM_INT_ARRAY), + [ + 'SELECT * FROM Foo WHERE foo IN (:foo)', + ['foo' => [1, 2, 3]], + ['foo' => Connection::PARAM_INT_ARRAY], 'SELECT * FROM Foo WHERE foo IN (?, ?, ?)', - array(1, 2, 3), - array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER), - ), + [1, 2, 3], + [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER], + ], // Named parameters: One non-list before d one after list-needle - array( - "SELECT * FROM Foo WHERE foo = :foo AND bar IN (:bar)", - array('foo'=>"string", 'bar'=>array(1, 2, 3)), - array('foo' => ParameterType::STRING, 'bar' => Connection::PARAM_INT_ARRAY), + [ + 'SELECT * FROM Foo WHERE foo = :foo AND bar IN (:bar)', + ['foo' => 'string', 'bar' => [1, 2, 3]], + ['foo' => ParameterType::STRING, 'bar' => Connection::PARAM_INT_ARRAY], 'SELECT * FROM Foo WHERE foo = ? AND bar IN (?, ?, ?)', - array("string", 1, 2, 3), - array(ParameterType::STRING, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER) - ), + ['string', 1, 2, 3], + [ParameterType::STRING, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER], + ], // Named parameters: One non-list after list-needle - array( - "SELECT * FROM Foo WHERE bar IN (:bar) AND baz = :baz", - array('bar'=>array(1, 2, 3), 'baz'=>"foo"), - array('bar'=>Connection::PARAM_INT_ARRAY, 'baz'=>ParameterType::STRING), + [ + 'SELECT * FROM Foo WHERE bar IN (:bar) AND baz = :baz', + ['bar' => [1, 2, 3], 'baz' => 'foo'], + ['bar' => Connection::PARAM_INT_ARRAY, 'baz' => ParameterType::STRING], 'SELECT * FROM Foo WHERE bar IN (?, ?, ?) AND baz = ?', - array(1, 2, 3, "foo"), - array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING) - ), + [1, 2, 3, 'foo'], + [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING], + ], // Named parameters: One non-list before and one after list-needle - array( - "SELECT * FROM Foo WHERE foo = :foo AND bar IN (:bar) AND baz = :baz", - array('bar'=>array(1, 2, 3),'foo'=>1, 'baz'=>4), - array('bar'=>Connection::PARAM_INT_ARRAY, 'foo'=>ParameterType::INTEGER, 'baz'=>ParameterType::INTEGER), + [ + 'SELECT * FROM Foo WHERE foo = :foo AND bar IN (:bar) AND baz = :baz', + ['bar' => [1, 2, 3],'foo' => 1, 'baz' => 4], + ['bar' => Connection::PARAM_INT_ARRAY, 'foo' => ParameterType::INTEGER, 'baz' => ParameterType::INTEGER], 'SELECT * FROM Foo WHERE foo = ? AND bar IN (?, ?, ?) AND baz = ?', - array(1, 1, 2, 3, 4), - array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER) - ), + [1, 1, 2, 3, 4], + [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER], + ], // Named parameters: Two lists - array( - "SELECT * FROM Foo WHERE foo IN (:a, :b)", - array('b'=>array(4, 5),'a'=>array(1, 2, 3)), - array('a'=>Connection::PARAM_INT_ARRAY, 'b'=>Connection::PARAM_INT_ARRAY), + [ + 'SELECT * FROM Foo WHERE foo IN (:a, :b)', + ['b' => [4, 5],'a' => [1, 2, 3]], + ['a' => Connection::PARAM_INT_ARRAY, 'b' => Connection::PARAM_INT_ARRAY], 'SELECT * FROM Foo WHERE foo IN (?, ?, ?, ?, ?)', - array(1, 2, 3, 4, 5), - array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER) - ), + [1, 2, 3, 4, 5], + [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER], + ], // Named parameters : With the same name arg type string - array( - "SELECT * FROM Foo WHERE foo <> :arg AND bar = :arg", - array('arg'=>"Some String"), - array('arg'=>ParameterType::STRING), + [ + 'SELECT * FROM Foo WHERE foo <> :arg AND bar = :arg', + ['arg' => 'Some String'], + ['arg' => ParameterType::STRING], 'SELECT * FROM Foo WHERE foo <> ? AND bar = ?', - array("Some String","Some String"), - array(ParameterType::STRING,ParameterType::STRING,) - ), + ['Some String','Some String'], + [ParameterType::STRING,ParameterType::STRING], + ], // Named parameters : With the same name arg - array( - "SELECT * FROM Foo WHERE foo IN (:arg) AND NOT bar IN (:arg)", - array('arg'=>array(1, 2, 3)), - array('arg'=>Connection::PARAM_INT_ARRAY), + [ + 'SELECT * FROM Foo WHERE foo IN (:arg) AND NOT bar IN (:arg)', + ['arg' => [1, 2, 3]], + ['arg' => Connection::PARAM_INT_ARRAY], 'SELECT * FROM Foo WHERE foo IN (?, ?, ?) AND NOT bar IN (?, ?, ?)', - array(1, 2, 3, 1, 2, 3), - array(ParameterType::INTEGER,ParameterType::INTEGER, ParameterType::INTEGER,ParameterType::INTEGER,ParameterType::INTEGER, ParameterType::INTEGER) - ), + [1, 2, 3, 1, 2, 3], + [ParameterType::INTEGER,ParameterType::INTEGER, ParameterType::INTEGER,ParameterType::INTEGER,ParameterType::INTEGER, ParameterType::INTEGER], + ], // Named parameters : Same name, other name in between DBAL-299 - array( - "SELECT * FROM Foo WHERE (:foo = 2) AND (:bar = 3) AND (:foo = 2)", - array('foo'=>2,'bar'=>3), - array('foo'=>ParameterType::INTEGER,'bar'=>ParameterType::INTEGER), + [ + 'SELECT * FROM Foo WHERE (:foo = 2) AND (:bar = 3) AND (:foo = 2)', + ['foo' => 2,'bar' => 3], + ['foo' => ParameterType::INTEGER,'bar' => ParameterType::INTEGER], 'SELECT * FROM Foo WHERE (? = 2) AND (? = 3) AND (? = 2)', - array(2, 3, 2), - array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER) - ), + [2, 3, 2], + [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER], + ], // Named parameters : Empty "integer" array DDC-1978 - array( - "SELECT * FROM Foo WHERE foo IN (:foo)", - array('foo'=>array()), - array('foo'=>Connection::PARAM_INT_ARRAY), + [ + 'SELECT * FROM Foo WHERE foo IN (:foo)', + ['foo' => []], + ['foo' => Connection::PARAM_INT_ARRAY], 'SELECT * FROM Foo WHERE foo IN (NULL)', - array(), - array() - ), + [], + [], + ], // Named parameters : Two empty "str" array DDC-1978 - array( - "SELECT * FROM Foo WHERE foo IN (:foo) OR bar IN (:bar)", - array('foo'=>array(), 'bar'=>array()), - array('foo'=>Connection::PARAM_STR_ARRAY, 'bar'=>Connection::PARAM_STR_ARRAY), + [ + 'SELECT * FROM Foo WHERE foo IN (:foo) OR bar IN (:bar)', + ['foo' => [], 'bar' => []], + ['foo' => Connection::PARAM_STR_ARRAY, 'bar' => Connection::PARAM_STR_ARRAY], 'SELECT * FROM Foo WHERE foo IN (NULL) OR bar IN (NULL)', - array(), - array() - ), - array( - "SELECT * FROM Foo WHERE foo IN (:foo) OR bar = :bar OR baz = :baz", - array('foo' => array(1, 2), 'bar' => 'bar', 'baz' => 'baz'), - array('foo' => Connection::PARAM_INT_ARRAY, 'baz' => 'string'), + [], + [], + ], + [ + 'SELECT * FROM Foo WHERE foo IN (:foo) OR bar = :bar OR baz = :baz', + ['foo' => [1, 2], 'bar' => 'bar', 'baz' => 'baz'], + ['foo' => Connection::PARAM_INT_ARRAY, 'baz' => 'string'], 'SELECT * FROM Foo WHERE foo IN (?, ?) OR bar = ? OR baz = ?', - array(1, 2, 'bar', 'baz'), - array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING, 'string') - ), - array( - "SELECT * FROM Foo WHERE foo IN (:foo) OR bar = :bar", - array('foo' => array(1, 2), 'bar' => 'bar'), - array('foo' => Connection::PARAM_INT_ARRAY), + [1, 2, 'bar', 'baz'], + [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING, 'string'], + ], + [ + 'SELECT * FROM Foo WHERE foo IN (:foo) OR bar = :bar', + ['foo' => [1, 2], 'bar' => 'bar'], + ['foo' => Connection::PARAM_INT_ARRAY], 'SELECT * FROM Foo WHERE foo IN (?, ?) OR bar = ?', - array(1, 2, 'bar'), - array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING) - ), + [1, 2, 'bar'], + [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING], + ], // Params/types with colons - array( - "SELECT * FROM Foo WHERE foo = :foo OR bar = :bar", - array(':foo' => 'foo', ':bar' => 'bar'), - array(':foo' => ParameterType::INTEGER), + [ + 'SELECT * FROM Foo WHERE foo = :foo OR bar = :bar', + [':foo' => 'foo', ':bar' => 'bar'], + [':foo' => ParameterType::INTEGER], 'SELECT * FROM Foo WHERE foo = ? OR bar = ?', - array('foo', 'bar'), - array(ParameterType::INTEGER, ParameterType::STRING) - ), - array( - "SELECT * FROM Foo WHERE foo = :foo OR bar = :bar", - array(':foo' => 'foo', ':bar' => 'bar'), - array(':foo' => ParameterType::INTEGER, 'bar' => ParameterType::INTEGER), + ['foo', 'bar'], + [ParameterType::INTEGER, ParameterType::STRING], + ], + [ + 'SELECT * FROM Foo WHERE foo = :foo OR bar = :bar', + [':foo' => 'foo', ':bar' => 'bar'], + [':foo' => ParameterType::INTEGER, 'bar' => ParameterType::INTEGER], 'SELECT * FROM Foo WHERE foo = ? OR bar = ?', - array('foo', 'bar'), - array(ParameterType::INTEGER, ParameterType::INTEGER) - ), - array( - "SELECT * FROM Foo WHERE foo IN (:foo) OR bar = :bar", - array(':foo' => array(1, 2), ':bar' => 'bar'), - array('foo' => Connection::PARAM_INT_ARRAY), + ['foo', 'bar'], + [ParameterType::INTEGER, ParameterType::INTEGER], + ], + [ + 'SELECT * FROM Foo WHERE foo IN (:foo) OR bar = :bar', + [':foo' => [1, 2], ':bar' => 'bar'], + ['foo' => Connection::PARAM_INT_ARRAY], 'SELECT * FROM Foo WHERE foo IN (?, ?) OR bar = ?', - array(1, 2, 'bar'), - array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING) - ), - array( - "SELECT * FROM Foo WHERE foo IN (:foo) OR bar = :bar", - array('foo' => array(1, 2), 'bar' => 'bar'), - array(':foo' => Connection::PARAM_INT_ARRAY), + [1, 2, 'bar'], + [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING], + ], + [ + 'SELECT * FROM Foo WHERE foo IN (:foo) OR bar = :bar', + ['foo' => [1, 2], 'bar' => 'bar'], + [':foo' => Connection::PARAM_INT_ARRAY], 'SELECT * FROM Foo WHERE foo IN (?, ?) OR bar = ?', - array(1, 2, 'bar'), - array(ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING) - ), + [1, 2, 'bar'], + [ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::STRING], + ], // DBAL-522 - null valued parameters are not considered - array( + [ 'INSERT INTO Foo (foo, bar) values (:foo, :bar)', - array('foo' => 1, 'bar' => null), - array(':foo' => ParameterType::INTEGER, ':bar' => ParameterType::NULL), + ['foo' => 1, 'bar' => null], + [':foo' => ParameterType::INTEGER, ':bar' => ParameterType::NULL], 'INSERT INTO Foo (foo, bar) values (?, ?)', - array(1, null), - array(ParameterType::INTEGER, ParameterType::NULL) - ), - array( + [1, null], + [ParameterType::INTEGER, ParameterType::NULL], + ], + [ 'INSERT INTO Foo (foo, bar) values (?, ?)', - array(1, null), - array(ParameterType::INTEGER, ParameterType::NULL), + [1, null], + [ParameterType::INTEGER, ParameterType::NULL], 'INSERT INTO Foo (foo, bar) values (?, ?)', - array(1, null), - array(ParameterType::INTEGER, ParameterType::NULL) - ), + [1, null], + [ParameterType::INTEGER, ParameterType::NULL], + ], // DBAL-1205 - Escaped single quotes SQL- and C-Style - array( + [ "SELECT * FROM Foo WHERE foo = :foo||''':not_a_param''\\'' OR bar = ''':not_a_param''\\'':bar", - array(':foo' => 1, ':bar' => 2), - array(':foo' => ParameterType::INTEGER, 'bar' => ParameterType::INTEGER), + [':foo' => 1, ':bar' => 2], + [':foo' => ParameterType::INTEGER, 'bar' => ParameterType::INTEGER], 'SELECT * FROM Foo WHERE foo = ?||\'\'\':not_a_param\'\'\\\'\' OR bar = \'\'\':not_a_param\'\'\\\'\'?', - array(1, 2), - array(ParameterType::INTEGER, ParameterType::INTEGER) - ), - ); + [1, 2], + [ParameterType::INTEGER, ParameterType::INTEGER], + ], + ]; } /** @@ -405,53 +412,53 @@ public function dataExpandListParameters() */ public function testExpandListParameters($q, $p, $t, $expectedQuery, $expectedParams, $expectedTypes) { - list($query, $params, $types) = SQLParserUtils::expandListParameters($q, $p, $t); + [$query, $params, $types] = SQLParserUtils::expandListParameters($q, $p, $t); - self::assertEquals($expectedQuery, $query, "Query was not rewritten correctly."); - self::assertEquals($expectedParams, $params, "Params dont match"); - self::assertEquals($expectedTypes, $types, "Types dont match"); + 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 array( - array( - "SELECT * FROM foo WHERE bar = :param", - array('other' => 'val'), - array(), - ), - array( - "SELECT * FROM foo WHERE bar = :param", - array(), - array(), - ), - array( - "SELECT * FROM foo WHERE bar = :param", - array(), - array('param' => Connection::PARAM_INT_ARRAY), - ), - array( - "SELECT * FROM foo WHERE bar = :param", - array(), - array(':param' => Connection::PARAM_INT_ARRAY), - ), - array( - "SELECT * FROM foo WHERE bar = :param", - array(), - array('bar' => Connection::PARAM_INT_ARRAY), - ), - array( - "SELECT * FROM foo WHERE bar = :param", - array('bar' => 'value'), - array('bar' => Connection::PARAM_INT_ARRAY), - ), - ); + return [ + [ + 'SELECT * FROM foo WHERE bar = :param', + ['other' => 'val'], + [], + ], + [ + 'SELECT * FROM foo WHERE bar = :param', + [], + [], + ], + [ + 'SELECT * FROM foo WHERE bar = :param', + [], + ['param' => Connection::PARAM_INT_ARRAY], + ], + [ + 'SELECT * FROM foo WHERE bar = :param', + [], + [':param' => Connection::PARAM_INT_ARRAY], + ], + [ + 'SELECT * FROM foo WHERE bar = :param', + [], + ['bar' => Connection::PARAM_INT_ARRAY], + ], + [ + 'SELECT * FROM foo WHERE bar = :param', + ['bar' => 'value'], + ['bar' => Connection::PARAM_INT_ARRAY], + ], + ]; } /** * @dataProvider dataQueryWithMissingParameters */ - public function testExceptionIsThrownForMissingParam($query, $params, $types = array()) + public function testExceptionIsThrownForMissingParam($query, $params, $types = []) { $this->expectException('Doctrine\DBAL\SQLParserUtilsException'); $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 13bf74f6aff..046118f91fa 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ColumnDiffTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ColumnDiffTest.php @@ -5,8 +5,9 @@ use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ColumnDiff; use Doctrine\DBAL\Types\Type; +use PHPUnit\Framework\TestCase; -class ColumnDiffTest extends \PHPUnit\Framework\TestCase +class ColumnDiffTest extends TestCase { /** * @group DBAL-1255 @@ -14,15 +15,15 @@ class ColumnDiffTest extends \PHPUnit\Framework\TestCase public function testPreservesOldColumnNameQuotation() { $fromColumn = new Column('"foo"', Type::getType(Type::INTEGER)); - $toColumn = new Column('bar', Type::getType(Type::INTEGER)); + $toColumn = new Column('bar', Type::getType(Type::INTEGER)); - $columnDiff = new ColumnDiff('"foo"', $toColumn, array()); + $columnDiff = new ColumnDiff('"foo"', $toColumn, []); self::assertTrue($columnDiff->getOldColumnName()->isQuoted()); - $columnDiff = new ColumnDiff('"foo"', $toColumn, array(), $fromColumn); + $columnDiff = new ColumnDiff('"foo"', $toColumn, [], $fromColumn); self::assertTrue($columnDiff->getOldColumnName()->isQuoted()); - $columnDiff = new ColumnDiff('foo', $toColumn, array(), $fromColumn); + $columnDiff = new ColumnDiff('foo', $toColumn, [], $fromColumn); self::assertTrue($columnDiff->getOldColumnName()->isQuoted()); } } diff --git a/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php b/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php index c78595442fa..51fe749e28e 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ColumnTest.php @@ -2,17 +2,20 @@ namespace Doctrine\Tests\DBAL\Schema; -use Doctrine\DBAL\Exception\InvalidArgumentException; +use Doctrine\DBAL\Platforms\MySqlPlatform; +use Doctrine\DBAL\Platforms\SqlitePlatform; +use Doctrine\DBAL\Platforms\SQLServerPlatform; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Types\Type; +use PHPUnit\Framework\TestCase; -class ColumnTest extends \PHPUnit\Framework\TestCase +class ColumnTest extends TestCase { public function testGet() { $column = $this->createColumn(); - self::assertEquals("foo", $column->getName()); + self::assertEquals('foo', $column->getName()); self::assertSame(Type::getType('string'), $column->getType()); self::assertEquals(200, $column->getLength()); @@ -21,14 +24,14 @@ public function testGet() self::assertTrue($column->getUnsigned()); self::assertFalse($column->getNotNull()); self::assertTrue($column->getFixed()); - self::assertEquals("baz", $column->getDefault()); + self::assertEquals('baz', $column->getDefault()); - self::assertEquals(array('foo' => 'bar'), $column->getPlatformOptions()); + self::assertEquals(['foo' => 'bar'], $column->getPlatformOptions()); self::assertTrue($column->hasPlatformOption('foo')); self::assertEquals('bar', $column->getPlatformOption('foo')); self::assertFalse($column->hasPlatformOption('bar')); - self::assertEquals(array('bar' => 'baz'), $column->getCustomSchemaOptions()); + self::assertEquals(['bar' => 'baz'], $column->getCustomSchemaOptions()); self::assertTrue($column->hasCustomSchemaOption('bar')); self::assertEquals('baz', $column->getCustomSchemaOption('bar')); self::assertFalse($column->hasCustomSchemaOption('foo')); @@ -36,7 +39,7 @@ public function testGet() public function testToArray() { - $expected = array( + $expected = [ 'name' => 'foo', 'type' => Type::getType('string'), 'default' => 'baz', @@ -50,8 +53,8 @@ public function testToArray() 'columnDefinition' => null, 'comment' => null, 'foo' => 'bar', - 'bar' => 'baz' - ); + 'bar' => 'baz', + ]; self::assertEquals($expected, $this->createColumn()->toArray()); } @@ -83,7 +86,7 @@ public function testOptionsShouldNotBeIgnored() : void */ public function createColumn() { - $options = array( + $options = [ 'length' => 200, 'precision' => 5, 'scale' => 2, @@ -91,12 +94,12 @@ public function createColumn() 'notnull' => false, 'fixed' => true, 'default' => 'baz', - 'platformOptions' => array('foo' => 'bar'), - 'customSchemaOptions' => array('bar' => 'baz'), - ); + 'platformOptions' => ['foo' => 'bar'], + 'customSchemaOptions' => ['bar' => 'baz'], + ]; $string = Type::getType('string'); - return new Column("foo", $string, $options); + return new Column('foo', $string, $options); } /** @@ -106,18 +109,18 @@ public function createColumn() public function testQuotedColumnName() { $string = Type::getType('string'); - $column = new Column("`bar`", $string, array()); + $column = new Column('`bar`', $string, []); - $mysqlPlatform = new \Doctrine\DBAL\Platforms\MySqlPlatform(); - $sqlitePlatform = new \Doctrine\DBAL\Platforms\SqlitePlatform(); + $mysqlPlatform = new MySqlPlatform(); + $sqlitePlatform = new SqlitePlatform(); self::assertEquals('bar', $column->getName()); self::assertEquals('`bar`', $column->getQuotedName($mysqlPlatform)); self::assertEquals('"bar"', $column->getQuotedName($sqlitePlatform)); - $column = new Column("[bar]", $string); + $column = new Column('[bar]', $string); - $sqlServerPlatform = new \Doctrine\DBAL\Platforms\SQLServerPlatform(); + $sqlServerPlatform = new SQLServerPlatform(); self::assertEquals('bar', $column->getName()); self::assertEquals('[bar]', $column->getQuotedName($sqlServerPlatform)); @@ -129,7 +132,7 @@ public function testQuotedColumnName() */ public function testIsQuoted($columnName, $isQuoted) { - $type = Type::getType('string'); + $type = Type::getType('string'); $column = new Column($columnName, $type); self::assertSame($isQuoted, $column->isQuoted()); @@ -137,12 +140,12 @@ public function testIsQuoted($columnName, $isQuoted) public function getIsQuoted() { - return array( - array('bar', false), - array('`bar`', true), - array('"bar"', true), - array('[bar]', true), - ); + return [ + ['bar', false], + ['`bar`', true], + ['"bar"', true], + ['[bar]', true], + ]; } /** @@ -150,11 +153,11 @@ public function getIsQuoted() */ public function testColumnComment() { - $column = new Column("bar", Type::getType('string')); + $column = new Column('bar', Type::getType('string')); self::assertNull($column->getComment()); - $column->setComment("foo"); - self::assertEquals("foo", $column->getComment()); + $column->setComment('foo'); + self::assertEquals('foo', $column->getComment()); $columnArray = $column->toArray(); self::assertArrayHasKey('comment', $columnArray); diff --git a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php index 24d097c3006..b0b27d09d79 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php @@ -31,169 +31,176 @@ use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Types\Type; +use PHPUnit\Framework\TestCase; use function array_keys; /** - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.doctrine-project.org - * @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved. - * @license http://ez.no/licenses/new_bsd New BSD License - * @since 2.0 - * @version $Revision$ - * @author Benjamin Eberlei */ -class ComparatorTest extends \PHPUnit\Framework\TestCase +class ComparatorTest extends TestCase { public function testCompareSame1() { - $schema1 = new Schema( array( - 'bugdb' => new Table('bugdb', - array ( - 'integerfield1' => new Column('integerfield1', Type::getType('integer' ) ), - ) + $schema1 = new Schema([ + 'bugdb' => new Table( + 'bugdb', + [ + 'integerfield1' => new Column('integerfield1', Type::getType('integer')), + ] ), - ) ); - $schema2 = new Schema( array( - 'bugdb' => new Table('bugdb', - array ( - 'integerfield1' => new Column('integerfield1', Type::getType('integer') ), - ) + ]); + $schema2 = new Schema([ + 'bugdb' => new Table( + 'bugdb', + [ + 'integerfield1' => new Column('integerfield1', Type::getType('integer')), + ] ), - ) ); + ]); - $expected = new SchemaDiff(); + $expected = new SchemaDiff(); $expected->fromSchema = $schema1; - self::assertEquals($expected, Comparator::compareSchemas( $schema1, $schema2 ) ); + self::assertEquals($expected, Comparator::compareSchemas($schema1, $schema2)); } public function testCompareSame2() { - $schema1 = new Schema( array( - 'bugdb' => new Table('bugdb', - array ( + $schema1 = new Schema([ + 'bugdb' => new Table( + 'bugdb', + [ 'integerfield1' => new Column('integerfield1', Type::getType('integer')), 'integerfield2' => new Column('integerfield2', Type::getType('integer')), - ) + ] ), - ) ); - $schema2 = new Schema( array( - 'bugdb' => new Table('bugdb', - array ( + ]); + $schema2 = new Schema([ + 'bugdb' => new Table( + 'bugdb', + [ 'integerfield2' => new Column('integerfield2', Type::getType('integer')), 'integerfield1' => new Column('integerfield1', Type::getType('integer')), - ) + ] ), - ) ); + ]); - $expected = new SchemaDiff(); + $expected = new SchemaDiff(); $expected->fromSchema = $schema1; - self::assertEquals($expected, Comparator::compareSchemas( $schema1, $schema2 ) ); + self::assertEquals($expected, Comparator::compareSchemas($schema1, $schema2)); } public function testCompareMissingTable() { - $schemaConfig = new \Doctrine\DBAL\Schema\SchemaConfig; - $table = new Table('bugdb', array ('integerfield1' => new Column('integerfield1', Type::getType('integer')))); + $schemaConfig = new SchemaConfig(); + $table = new Table('bugdb', ['integerfield1' => new Column('integerfield1', Type::getType('integer'))]); $table->setSchemaConfig($schemaConfig); - $schema1 = new Schema( array($table), array(), $schemaConfig ); - $schema2 = new Schema( array(), array(), $schemaConfig ); + $schema1 = new Schema([$table], [], $schemaConfig); + $schema2 = new Schema([], [], $schemaConfig); - $expected = new SchemaDiff( array(), array(), array('bugdb' => $table), $schema1 ); + $expected = new SchemaDiff([], [], ['bugdb' => $table], $schema1); - self::assertEquals($expected, Comparator::compareSchemas( $schema1, $schema2 ) ); + self::assertEquals($expected, Comparator::compareSchemas($schema1, $schema2)); } public function testCompareNewTable() { - $schemaConfig = new \Doctrine\DBAL\Schema\SchemaConfig; - $table = new Table('bugdb', array ('integerfield1' => new Column('integerfield1', Type::getType('integer')))); + $schemaConfig = new SchemaConfig(); + $table = new Table('bugdb', ['integerfield1' => new Column('integerfield1', Type::getType('integer'))]); $table->setSchemaConfig($schemaConfig); - $schema1 = new Schema( array(), array(), $schemaConfig ); - $schema2 = new Schema( array($table), array(), $schemaConfig ); + $schema1 = new Schema([], [], $schemaConfig); + $schema2 = new Schema([$table], [], $schemaConfig); - $expected = new SchemaDiff( array('bugdb' => $table), array(), array(), $schema1 ); + $expected = new SchemaDiff(['bugdb' => $table], [], [], $schema1); - self::assertEquals($expected, Comparator::compareSchemas( $schema1, $schema2 ) ); + self::assertEquals($expected, Comparator::compareSchemas($schema1, $schema2)); } public function testCompareOnlyAutoincrementChanged() { - $column1 = new Column('foo', Type::getType('integer'), array('autoincrement' => true)); - $column2 = new Column('foo', Type::getType('integer'), array('autoincrement' => false)); + $column1 = new Column('foo', Type::getType('integer'), ['autoincrement' => true]); + $column2 = new Column('foo', Type::getType('integer'), ['autoincrement' => false]); - $comparator = new Comparator(); + $comparator = new Comparator(); $changedProperties = $comparator->diffColumn($column1, $column2); - self::assertEquals(array('autoincrement'), $changedProperties); + self::assertEquals(['autoincrement'], $changedProperties); } public function testCompareMissingField() { $missingColumn = new Column('integerfield1', Type::getType('integer')); - $schema1 = new Schema( array( - 'bugdb' => new Table('bugdb', - array ( + $schema1 = new Schema([ + 'bugdb' => new Table( + 'bugdb', + [ 'integerfield1' => $missingColumn, 'integerfield2' => new Column('integerfield2', Type::getType('integer')), - ) + ] ), - ) ); - $schema2 = new Schema( array( - 'bugdb' => new Table('bugdb', - array ( + ]); + $schema2 = new Schema([ + 'bugdb' => new Table( + 'bugdb', + [ 'integerfield2' => new Column('integerfield2', Type::getType('integer')), - ) + ] ), - ) ); - - $expected = new SchemaDiff ( array(), - array ( - 'bugdb' => new TableDiff( 'bugdb', array(), array(), - array ( - 'integerfield1' => $missingColumn, - ) - ) - ) + ]); + + $expected = new SchemaDiff( + [], + [ + 'bugdb' => new TableDiff( + 'bugdb', + [], + [], + ['integerfield1' => $missingColumn] + ), + ] ); - $expected->fromSchema = $schema1; + $expected->fromSchema = $schema1; $expected->changedTables['bugdb']->fromTable = $schema1->getTable('bugdb'); - self::assertEquals($expected, Comparator::compareSchemas( $schema1, $schema2 ) ); + self::assertEquals($expected, Comparator::compareSchemas($schema1, $schema2)); } public function testCompareNewField() { - $schema1 = new Schema( array( - 'bugdb' => new Table('bugdb', - array ( + $schema1 = new Schema([ + 'bugdb' => new Table( + 'bugdb', + [ 'integerfield1' => new Column('integerfield1', Type::getType('integer')), - ) + ] ), - ) ); - $schema2 = new Schema( array( - 'bugdb' => new Table('bugdb', - array ( + ]); + $schema2 = new Schema([ + 'bugdb' => new Table( + 'bugdb', + [ 'integerfield1' => new Column('integerfield1', Type::getType('integer')), 'integerfield2' => new Column('integerfield2', Type::getType('integer')), - ) + ] ), - ) ); - - $expected = new SchemaDiff ( array(), - array ( - 'bugdb' => new TableDiff ('bugdb', - array ( + ]); + + $expected = new SchemaDiff( + [], + [ + 'bugdb' => new TableDiff( + 'bugdb', + [ 'integerfield2' => new Column('integerfield2', Type::getType('integer')), - ) + ] ), - ) + ] ); - $expected->fromSchema = $schema1; + $expected->fromSchema = $schema1; $expected->changedTables['bugdb']->fromTable = $schema1->getTable('bugdb'); - self::assertEquals($expected, Comparator::compareSchemas( $schema1, $schema2 ) ); + self::assertEquals($expected, Comparator::compareSchemas($schema1, $schema2)); } public function testCompareChangedColumns_ChangeType() @@ -202,8 +209,8 @@ public function testCompareChangedColumns_ChangeType() $column2 = new Column('charfield1', Type::getType('integer')); $c = new Comparator(); - self::assertEquals(array('type'), $c->diffColumn($column1, $column2)); - self::assertEquals(array(), $c->diffColumn($column1, $column1)); + self::assertEquals(['type'], $c->diffColumn($column1, $column2)); + self::assertEquals([], $c->diffColumn($column1, $column1)); } public function testCompareChangedColumns_ChangeCustomSchemaOption() @@ -218,216 +225,245 @@ public function testCompareChangedColumns_ChangeCustomSchemaOption() $column2->setCustomSchemaOption('foo2', 'bar2'); $c = new Comparator(); - self::assertEquals(array('foo1', 'foo2'), $c->diffColumn($column1, $column2)); - self::assertEquals(array(), $c->diffColumn($column1, $column1)); + self::assertEquals(['foo1', 'foo2'], $c->diffColumn($column1, $column2)); + self::assertEquals([], $c->diffColumn($column1, $column1)); } public function testCompareChangeColumns_MultipleNewColumnsRename() { - $tableA = new Table("foo"); + $tableA = new Table('foo'); $tableA->addColumn('datefield1', 'datetime'); - $tableB = new Table("foo"); + $tableB = new Table('foo'); $tableB->addColumn('new_datefield1', 'datetime'); $tableB->addColumn('new_datefield2', 'datetime'); - $c = new Comparator(); + $c = new Comparator(); $tableDiff = $c->diffTable($tableA, $tableB); - self::assertCount(1, $tableDiff->renamedColumns, "we should have one rename datefield1 => new_datefield1."); + self::assertCount(1, $tableDiff->renamedColumns, 'we should have one rename datefield1 => new_datefield1.'); self::assertArrayHasKey('datefield1', $tableDiff->renamedColumns, "'datefield1' should be set to be renamed to new_datefield1"); self::assertCount(1, $tableDiff->addedColumns, "'new_datefield2' should be added"); self::assertArrayHasKey('new_datefield2', $tableDiff->addedColumns, "'new_datefield2' should be added, not created through renaming!"); - self::assertCount(0, $tableDiff->removedColumns, "Nothing should be removed."); - self::assertCount(0, $tableDiff->changedColumns, "Nothing should be changed as all fields old & new have diff names."); + self::assertCount(0, $tableDiff->removedColumns, 'Nothing should be removed.'); + self::assertCount(0, $tableDiff->changedColumns, 'Nothing should be changed as all fields old & new have diff names.'); } public function testCompareRemovedIndex() { - $schema1 = new Schema( array( - 'bugdb' => new Table('bugdb', - array ( + $schema1 = new Schema([ + 'bugdb' => new Table( + 'bugdb', + [ 'integerfield1' => new Column('integerfield1', Type::getType('integer')), 'integerfield2' => new Column('integerfield2', Type::getType('integer')), - ), - array ( - 'primary' => new Index('primary', - array( - 'integerfield1' - ), + ], + [ + 'primary' => new Index( + 'primary', + ['integerfield1'], true - ) - ) + ), + ] ), - ) ); - $schema2 = new Schema( array( - 'bugdb' => new Table('bugdb', - array ( + ]); + $schema2 = new Schema([ + 'bugdb' => new Table( + 'bugdb', + [ 'integerfield1' => new Column('integerfield1', Type::getType('integer')), 'integerfield2' => new Column('integerfield2', Type::getType('integer')), - ) + ] ), - ) ); - - $expected = new SchemaDiff ( array(), - array ( - 'bugdb' => new TableDiff( 'bugdb', array(), array(), array(), array(), array(), - array ( - 'primary' => new Index('primary', - array( - 'integerfield1' + ]); + + $expected = new SchemaDiff( + [], + [ + 'bugdb' => new TableDiff( + 'bugdb', + [], + [], + [], + [], + [], + [ + 'primary' => new Index( + 'primary', + ['integerfield1'], + true ), - true - ) - ) + ] ), - ) + ] ); - $expected->fromSchema = $schema1; + $expected->fromSchema = $schema1; $expected->changedTables['bugdb']->fromTable = $schema1->getTable('bugdb'); - self::assertEquals($expected, Comparator::compareSchemas( $schema1, $schema2 ) ); + self::assertEquals($expected, Comparator::compareSchemas($schema1, $schema2)); } public function testCompareNewIndex() { - $schema1 = new Schema( array( - 'bugdb' => new Table('bugdb', - array ( + $schema1 = new Schema([ + 'bugdb' => new Table( + 'bugdb', + [ 'integerfield1' => new Column('integerfield1', Type::getType('integer')), 'integerfield2' => new Column('integerfield2', Type::getType('integer')), - ) + ] ), - ) ); - $schema2 = new Schema( array( - 'bugdb' => new Table('bugdb', - array ( + ]); + $schema2 = new Schema([ + 'bugdb' => new Table( + 'bugdb', + [ 'integerfield1' => new Column('integerfield1', Type::getType('integer')), 'integerfield2' => new Column('integerfield2', Type::getType('integer')), - ), - array ( - 'primary' => new Index('primary', - array( - 'integerfield1' - ), + ], + [ + 'primary' => new Index( + 'primary', + ['integerfield1'], true - ) - ) + ), + ] ), - ) ); - - $expected = new SchemaDiff ( array(), - array ( - 'bugdb' => new TableDiff( 'bugdb', array(), array(), array(), - array ( - 'primary' => new Index('primary', - array( - 'integerfield1' - ), + ]); + + $expected = new SchemaDiff( + [], + [ + 'bugdb' => new TableDiff( + 'bugdb', + [], + [], + [], + [ + 'primary' => new Index( + 'primary', + ['integerfield1'], true - ) - ) + ), + ] ), - ) + ] ); - $expected->fromSchema = $schema1; + $expected->fromSchema = $schema1; $expected->changedTables['bugdb']->fromTable = $schema1->getTable('bugdb'); - self::assertEquals($expected, Comparator::compareSchemas( $schema1, $schema2 ) ); + self::assertEquals($expected, Comparator::compareSchemas($schema1, $schema2)); } public function testCompareChangedIndex() { - $schema1 = new Schema( array( - 'bugdb' => new Table('bugdb', - array ( + $schema1 = new Schema([ + 'bugdb' => new Table( + 'bugdb', + [ 'integerfield1' => new Column('integerfield1', Type::getType('integer')), 'integerfield2' => new Column('integerfield2', Type::getType('integer')), - ), - array ( - 'primary' => new Index('primary', - array( - 'integerfield1' - ), + ], + [ + 'primary' => new Index( + 'primary', + ['integerfield1'], true - ) - ) + ), + ] ), - ) ); - $schema2 = new Schema( array( - 'bugdb' => new Table('bugdb', - array ( + ]); + $schema2 = new Schema([ + 'bugdb' => new Table( + 'bugdb', + [ 'integerfield1' => new Column('integerfield1', Type::getType('integer')), 'integerfield2' => new Column('integerfield2', Type::getType('integer')), - ), - array ( - 'primary' => new Index('primary', - array('integerfield1', 'integerfield2'), + ], + [ + 'primary' => new Index( + 'primary', + ['integerfield1', 'integerfield2'], true - ) - ) + ), + ] ), - ) ); - - $expected = new SchemaDiff ( array(), - array ( - 'bugdb' => new TableDiff( 'bugdb', array(), array(), array(), array(), - array ( - 'primary' => new Index('primary', - array( + ]); + + $expected = new SchemaDiff( + [], + [ + 'bugdb' => new TableDiff( + 'bugdb', + [], + [], + [], + [], + [ + 'primary' => new Index( + 'primary', + [ 'integerfield1', - 'integerfield2' - ), + 'integerfield2', + ], true - ) - ) + ), + ] ), - ) + ] ); - $expected->fromSchema = $schema1; + $expected->fromSchema = $schema1; $expected->changedTables['bugdb']->fromTable = $schema1->getTable('bugdb'); - self::assertEquals($expected, Comparator::compareSchemas( $schema1, $schema2 )); + self::assertEquals($expected, Comparator::compareSchemas($schema1, $schema2)); } public function testCompareChangedIndexFieldPositions() { - $schema1 = new Schema( array( - 'bugdb' => new Table('bugdb', - array ( + $schema1 = new Schema([ + 'bugdb' => new Table( + 'bugdb', + [ 'integerfield1' => new Column('integerfield1', Type::getType('integer')), 'integerfield2' => new Column('integerfield2', Type::getType('integer')), - ), - array ( - 'primary' => new Index('primary', array('integerfield1', 'integerfield2'), true) - ) + ], + [ + 'primary' => new Index('primary', ['integerfield1', 'integerfield2'], true), + ] ), - ) ); - $schema2 = new Schema( array( - 'bugdb' => new Table('bugdb', - array ( + ]); + $schema2 = new Schema([ + 'bugdb' => new Table( + 'bugdb', + [ 'integerfield1' => new Column('integerfield1', Type::getType('integer')), 'integerfield2' => new Column('integerfield2', Type::getType('integer')), - ), - array ( - 'primary' => new Index('primary', array('integerfield2', 'integerfield1'), true) - ) + ], + [ + 'primary' => new Index('primary', ['integerfield2', 'integerfield1'], true), + ] ), - ) ); - - $expected = new SchemaDiff ( array(), - array ( - 'bugdb' => new TableDiff('bugdb', array(), array(), array(), array(), - array ( - 'primary' => new Index('primary', array('integerfield2', 'integerfield1'), true) - ) + ]); + + $expected = new SchemaDiff( + [], + [ + 'bugdb' => new TableDiff( + 'bugdb', + [], + [], + [], + [], + [ + 'primary' => new Index('primary', ['integerfield2', 'integerfield1'], true), + ] ), - ) + ] ); - $expected->fromSchema = $schema1; + $expected->fromSchema = $schema1; $expected->changedTables['bugdb']->fromTable = $schema1->getTable('bugdb'); - self::assertEquals($expected, Comparator::compareSchemas( $schema1, $schema2 )); + self::assertEquals($expected, Comparator::compareSchemas($schema1, $schema2)); } public function testCompareSequences() @@ -447,11 +483,11 @@ public function testCompareSequences() public function testRemovedSequence() { $schema1 = new Schema(); - $seq = $schema1->createSequence('foo'); + $seq = $schema1->createSequence('foo'); $schema2 = new Schema(); - $c = new Comparator(); + $c = new Comparator(); $diffSchema = $c->compare($schema1, $schema2); self::assertCount(1, $diffSchema->removedSequences); @@ -463,9 +499,9 @@ public function testAddedSequence() $schema1 = new Schema(); $schema2 = new Schema(); - $seq = $schema2->createSequence('foo'); + $seq = $schema2->createSequence('foo'); - $c = new Comparator(); + $c = new Comparator(); $diffSchema = $c->compare($schema1, $schema2); self::assertCount(1, $diffSchema->newSequences); @@ -474,17 +510,17 @@ public function testAddedSequence() public function testTableAddForeignKey() { - $tableForeign = new Table("bar"); + $tableForeign = new Table('bar'); $tableForeign->addColumn('id', 'integer'); - $table1 = new Table("foo"); + $table1 = new Table('foo'); $table1->addColumn('fk', 'integer'); - $table2 = new Table("foo"); + $table2 = new Table('foo'); $table2->addColumn('fk', 'integer'); - $table2->addForeignKeyConstraint($tableForeign, array('fk'), array('id')); + $table2->addForeignKeyConstraint($tableForeign, ['fk'], ['id']); - $c = new Comparator(); + $c = new Comparator(); $tableDiff = $c->diffTable($table1, $table2); self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); @@ -493,17 +529,17 @@ public function testTableAddForeignKey() public function testTableRemoveForeignKey() { - $tableForeign = new Table("bar"); + $tableForeign = new Table('bar'); $tableForeign->addColumn('id', 'integer'); - $table1 = new Table("foo"); + $table1 = new Table('foo'); $table1->addColumn('fk', 'integer'); - $table2 = new Table("foo"); + $table2 = new Table('foo'); $table2->addColumn('fk', 'integer'); - $table2->addForeignKeyConstraint($tableForeign, array('fk'), array('id')); + $table2->addForeignKeyConstraint($tableForeign, ['fk'], ['id']); - $c = new Comparator(); + $c = new Comparator(); $tableDiff = $c->diffTable($table2, $table1); self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); @@ -512,18 +548,18 @@ public function testTableRemoveForeignKey() public function testTableUpdateForeignKey() { - $tableForeign = new Table("bar"); + $tableForeign = new Table('bar'); $tableForeign->addColumn('id', 'integer'); - $table1 = new Table("foo"); + $table1 = new Table('foo'); $table1->addColumn('fk', 'integer'); - $table1->addForeignKeyConstraint($tableForeign, array('fk'), array('id')); + $table1->addForeignKeyConstraint($tableForeign, ['fk'], ['id']); - $table2 = new Table("foo"); + $table2 = new Table('foo'); $table2->addColumn('fk', 'integer'); - $table2->addForeignKeyConstraint($tableForeign, array('fk'), array('id'), array('onUpdate' => 'CASCADE')); + $table2->addForeignKeyConstraint($tableForeign, ['fk'], ['id'], ['onUpdate' => 'CASCADE']); - $c = new Comparator(); + $c = new Comparator(); $tableDiff = $c->diffTable($table1, $table2); self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); @@ -532,21 +568,21 @@ public function testTableUpdateForeignKey() public function testMovedForeignKeyForeignTable() { - $tableForeign = new Table("bar"); + $tableForeign = new Table('bar'); $tableForeign->addColumn('id', 'integer'); - $tableForeign2 = new Table("bar2"); + $tableForeign2 = new Table('bar2'); $tableForeign2->addColumn('id', 'integer'); - $table1 = new Table("foo"); + $table1 = new Table('foo'); $table1->addColumn('fk', 'integer'); - $table1->addForeignKeyConstraint($tableForeign, array('fk'), array('id')); + $table1->addForeignKeyConstraint($tableForeign, ['fk'], ['id']); - $table2 = new Table("foo"); + $table2 = new Table('foo'); $table2->addColumn('fk', 'integer'); - $table2->addForeignKeyConstraint($tableForeign2, array('fk'), array('id')); + $table2->addForeignKeyConstraint($tableForeign2, ['fk'], ['id']); - $c = new Comparator(); + $c = new Comparator(); $tableDiff = $c->diffTable($table1, $table2); self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); @@ -567,7 +603,7 @@ public function testTablesCaseInsensitive() $schemaB->createTable('Baz'); $schemaB->createTable('old'); - $c = new Comparator(); + $c = new Comparator(); $diff = $c->compare($schemaA, $schemaB); self::assertSchemaTableChangeCount($diff, 1, 0, 1); @@ -587,7 +623,7 @@ public function testSequencesCaseInsensitive() $schemaB->createSequence('baz'); $schemaB->createSequence('old'); - $c = new Comparator(); + $c = new Comparator(); $diff = $c->compare($schemaA, $schemaB); self::assertSchemaSequenceChangeCount($diff, 1, 0, 1); @@ -595,13 +631,13 @@ public function testSequencesCaseInsensitive() public function testCompareColumnCompareCaseInsensitive() { - $tableA = new Table("foo"); + $tableA = new Table('foo'); $tableA->addColumn('id', 'integer'); - $tableB = new Table("foo"); + $tableB = new Table('foo'); $tableB->addColumn('ID', 'integer'); - $c = new Comparator(); + $c = new Comparator(); $tableDiff = $c->diffTable($tableA, $tableB); self::assertFalse($tableDiff); @@ -609,18 +645,18 @@ public function testCompareColumnCompareCaseInsensitive() public function testCompareIndexBasedOnPropertiesNotName() { - $tableA = new Table("foo"); + $tableA = new Table('foo'); $tableA->addColumn('id', 'integer'); - $tableA->addIndex(array("id"), "foo_bar_idx"); + $tableA->addIndex(['id'], 'foo_bar_idx'); - $tableB = new Table("foo"); + $tableB = new Table('foo'); $tableB->addColumn('ID', 'integer'); - $tableB->addIndex(array("id"), "bar_foo_idx"); + $tableB->addIndex(['id'], 'bar_foo_idx'); - $c = new Comparator(); - $tableDiff = new TableDiff('foo'); - $tableDiff->fromTable = $tableA; - $tableDiff->renamedIndexes['foo_bar_idx'] = new Index('bar_foo_idx', array('id')); + $c = new Comparator(); + $tableDiff = new TableDiff('foo'); + $tableDiff->fromTable = $tableA; + $tableDiff->renamedIndexes['foo_bar_idx'] = new Index('bar_foo_idx', ['id']); self::assertEquals( $tableDiff, @@ -630,15 +666,15 @@ public function testCompareIndexBasedOnPropertiesNotName() public function testCompareForeignKeyBasedOnPropertiesNotName() { - $tableA = new Table("foo"); + $tableA = new Table('foo'); $tableA->addColumn('id', 'integer'); - $tableA->addNamedForeignKeyConstraint('foo_constraint', 'bar', array('id'), array('id')); + $tableA->addNamedForeignKeyConstraint('foo_constraint', 'bar', ['id'], ['id']); - $tableB = new Table("foo"); + $tableB = new Table('foo'); $tableB->addColumn('ID', 'integer'); - $tableB->addNamedForeignKeyConstraint('bar_constraint', 'bar', array('id'), array('id')); + $tableB->addNamedForeignKeyConstraint('bar_constraint', 'bar', ['id'], ['id']); - $c = new Comparator(); + $c = new Comparator(); $tableDiff = $c->diffTable($tableA, $tableB); self::assertFalse($tableDiff); @@ -646,8 +682,8 @@ public function testCompareForeignKeyBasedOnPropertiesNotName() public function testCompareForeignKey_RestrictNoAction_AreTheSame() { - $fk1 = new ForeignKeyConstraint(array("foo"), "bar", array("baz"), "fk1", array('onDelete' => 'NO ACTION')); - $fk2 = new ForeignKeyConstraint(array("foo"), "bar", array("baz"), "fk1", array('onDelete' => 'RESTRICT')); + $fk1 = new ForeignKeyConstraint(['foo'], 'bar', ['baz'], 'fk1', ['onDelete' => 'NO ACTION']); + $fk2 = new ForeignKeyConstraint(['foo'], 'bar', ['baz'], 'fk1', ['onDelete' => 'RESTRICT']); $c = new Comparator(); self::assertFalse($c->diffForeignKey($fk1, $fk2)); @@ -658,8 +694,8 @@ public function testCompareForeignKey_RestrictNoAction_AreTheSame() */ public function testCompareForeignKeyNamesUnqualified_AsNoSchemaInformationIsAvailable() { - $fk1 = new ForeignKeyConstraint(array("foo"), "foo.bar", array("baz"), "fk1"); - $fk2 = new ForeignKeyConstraint(array("foo"), "baz.bar", array("baz"), "fk1"); + $fk1 = new ForeignKeyConstraint(['foo'], 'foo.bar', ['baz'], 'fk1'); + $fk2 = new ForeignKeyConstraint(['foo'], 'baz.bar', ['baz'], 'fk1'); $c = new Comparator(); self::assertFalse($c->diffForeignKey($fk1, $fk2)); @@ -667,13 +703,13 @@ public function testCompareForeignKeyNamesUnqualified_AsNoSchemaInformationIsAva public function testDetectRenameColumn() { - $tableA = new Table("foo"); + $tableA = new Table('foo'); $tableA->addColumn('foo', 'integer'); - $tableB = new Table("foo"); + $tableB = new Table('foo'); $tableB->addColumn('bar', 'integer'); - $c = new Comparator(); + $c = new Comparator(); $tableDiff = $c->diffTable($tableA, $tableB); self::assertCount(0, $tableDiff->addedColumns); @@ -691,14 +727,14 @@ public function testDetectRenameColumn() */ public function testDetectRenameColumnAmbiguous() { - $tableA = new Table("foo"); + $tableA = new Table('foo'); $tableA->addColumn('foo', 'integer'); $tableA->addColumn('bar', 'integer'); - $tableB = new Table("foo"); + $tableB = new Table('foo'); $tableB->addColumn('baz', 'integer'); - $c = new Comparator(); + $c = new Comparator(); $tableDiff = $c->diffTable($tableA, $tableB); self::assertCount(1, $tableDiff->addedColumns, "'baz' should be added, not created through renaming!"); @@ -706,7 +742,7 @@ public function testDetectRenameColumnAmbiguous() self::assertCount(2, $tableDiff->removedColumns, "'foo' and 'bar' should both be dropped, an ambiguity exists which one could be renamed to 'baz'."); self::assertArrayHasKey('foo', $tableDiff->removedColumns, "'foo' should be removed."); self::assertArrayHasKey('bar', $tableDiff->removedColumns, "'bar' should be removed."); - self::assertCount(0, $tableDiff->renamedColumns, "no renamings should take place."); + self::assertCount(0, $tableDiff->renamedColumns, 'no renamings should take place.'); } /** @@ -719,12 +755,12 @@ public function testDetectRenameIndex() $table2 = clone $table1; - $table1->addIndex(array('foo'), 'idx_foo'); + $table1->addIndex(['foo'], 'idx_foo'); - $table2->addIndex(array('foo'), 'idx_bar'); + $table2->addIndex(['foo'], 'idx_bar'); $comparator = new Comparator(); - $tableDiff = $comparator->diffTable($table1, $table2); + $tableDiff = $comparator->diffTable($table1, $table2); self::assertCount(0, $tableDiff->addedIndexes); self::assertCount(0, $tableDiff->removedIndexes); @@ -746,13 +782,13 @@ public function testDetectRenameIndexAmbiguous() $table2 = clone $table1; - $table1->addIndex(array('foo'), 'idx_foo'); - $table1->addIndex(array('foo'), 'idx_bar'); + $table1->addIndex(['foo'], 'idx_foo'); + $table1->addIndex(['foo'], 'idx_bar'); - $table2->addIndex(array('foo'), 'idx_baz'); + $table2->addIndex(['foo'], 'idx_baz'); $comparator = new Comparator(); - $tableDiff = $comparator->diffTable($table1, $table2); + $tableDiff = $comparator->diffTable($table1, $table2); self::assertCount(1, $tableDiff->addedIndexes); self::assertArrayHasKey('idx_baz', $tableDiff->addedIndexes); @@ -766,13 +802,13 @@ public function testDetectChangeIdentifierType() { $this->markTestSkipped('DBAL-2 was reopened, this test cannot work anymore.'); - $tableA = new Table("foo"); - $tableA->addColumn('id', 'integer', array('autoincrement' => false)); + $tableA = new Table('foo'); + $tableA->addColumn('id', 'integer', ['autoincrement' => false]); - $tableB = new Table("foo"); - $tableB->addColumn('id', 'integer', array('autoincrement' => true)); + $tableB = new Table('foo'); + $tableB->addColumn('id', 'integer', ['autoincrement' => true]); - $c = new Comparator(); + $c = new Comparator(); $tableDiff = $c->diffTable($tableA, $tableB); self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); @@ -785,25 +821,25 @@ public function testDetectChangeIdentifierType() */ public function testDiff() { - $table = new \Doctrine\DBAL\Schema\Table('twitter_users'); - $table->addColumn('id', 'integer', array('autoincrement' => true)); + $table = new Table('twitter_users'); + $table->addColumn('id', 'integer', ['autoincrement' => true]); $table->addColumn('twitterId', 'integer'); $table->addColumn('displayName', 'string'); - $table->setPrimaryKey(array('id')); + $table->setPrimaryKey(['id']); - $newtable = new \Doctrine\DBAL\Schema\Table('twitter_users'); - $newtable->addColumn('id', 'integer', array('autoincrement' => true)); + $newtable = new Table('twitter_users'); + $newtable->addColumn('id', 'integer', ['autoincrement' => true]); $newtable->addColumn('twitter_id', 'integer'); $newtable->addColumn('display_name', 'string'); $newtable->addColumn('logged_in_at', 'datetime'); - $newtable->setPrimaryKey(array('id')); + $newtable->setPrimaryKey(['id']); - $c = new Comparator(); + $c = new Comparator(); $tableDiff = $c->diffTable($table, $newtable); self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); - self::assertEquals(array('twitterid', 'displayname'), array_keys($tableDiff->renamedColumns)); - self::assertEquals(array('logged_in_at'), array_keys($tableDiff->addedColumns)); + self::assertEquals(['twitterid', 'displayname'], array_keys($tableDiff->renamedColumns)); + self::assertEquals(['logged_in_at'], array_keys($tableDiff->addedColumns)); self::assertCount(0, $tableDiff->removedColumns); } @@ -813,17 +849,17 @@ public function testDiff() */ public function testChangedSequence() { - $schema = new Schema(); + $schema = new Schema(); $sequence = $schema->createSequence('baz'); $schemaNew = clone $schema; /* @var $schemaNew Schema */ $schemaNew->getSequence('baz')->setAllocationSize(20); - $c = new \Doctrine\DBAL\Schema\Comparator; + $c = new Comparator(); $diff = $c->compare($schema, $schemaNew); - self::assertSame($diff->changedSequences[0] , $schemaNew->getSequence('baz')); + self::assertSame($diff->changedSequences[0], $schemaNew->getSequence('baz')); } /** @@ -837,7 +873,7 @@ public function testDiffDecimalWithNullPrecision() $column2 = new Column('foo', Type::getType('decimal')); $c = new Comparator(); - self::assertEquals(array(), $c->diffColumn($column, $column2)); + self::assertEquals([], $c->diffColumn($column, $column2)); } /** @@ -846,15 +882,15 @@ public function testDiffDecimalWithNullPrecision() public function testFqnSchemaComparison() { $config = new SchemaConfig(); - $config->setName("foo"); + $config->setName('foo'); - $oldSchema = new Schema(array(), array(), $config); + $oldSchema = new Schema([], [], $config); $oldSchema->createTable('bar'); - $newSchema= new Schema(array(), array(), $config); + $newSchema = new Schema([], [], $config); $newSchema->createTable('foo.bar'); - $expected = new SchemaDiff(); + $expected = new SchemaDiff(); $expected->fromSchema = $oldSchema; self::assertEquals($expected, Comparator::compareSchemas($oldSchema, $newSchema)); @@ -866,24 +902,24 @@ public function testFqnSchemaComparison() public function testNamespacesComparison() { $config = new SchemaConfig(); - $config->setName("schemaName"); + $config->setName('schemaName'); - $oldSchema = new Schema(array(), array(), $config); + $oldSchema = new Schema([], [], $config); $oldSchema->createTable('taz'); $oldSchema->createTable('war.tab'); - $newSchema= new Schema(array(), array(), $config); + $newSchema = new Schema([], [], $config); $newSchema->createTable('bar.tab'); $newSchema->createTable('baz.tab'); $newSchema->createTable('war.tab'); - $expected = new SchemaDiff(); - $expected->fromSchema = $oldSchema; - $expected->newNamespaces = array('bar' => 'bar', 'baz' => 'baz'); + $expected = new SchemaDiff(); + $expected->fromSchema = $oldSchema; + $expected->newNamespaces = ['bar' => 'bar', 'baz' => 'baz']; $diff = Comparator::compareSchemas($oldSchema, $newSchema); - self::assertEquals(array('bar' => 'bar', 'baz' => 'baz'), $diff->newNamespaces); + self::assertEquals(['bar' => 'bar', 'baz' => 'baz'], $diff->newNamespaces); self::assertCount(2, $diff->newTables); } @@ -893,15 +929,15 @@ public function testNamespacesComparison() public function testFqnSchemaComparisonDifferentSchemaNameButSameTableNoDiff() { $config = new SchemaConfig(); - $config->setName("foo"); + $config->setName('foo'); - $oldSchema = new Schema(array(), array(), $config); + $oldSchema = new Schema([], [], $config); $oldSchema->createTable('foo.bar'); $newSchema = new Schema(); $newSchema->createTable('bar'); - $expected = new SchemaDiff(); + $expected = new SchemaDiff(); $expected->fromSchema = $oldSchema; self::assertEquals($expected, Comparator::compareSchemas($oldSchema, $newSchema)); @@ -913,14 +949,14 @@ public function testFqnSchemaComparisonDifferentSchemaNameButSameTableNoDiff() public function testFqnSchemaComparisonNoSchemaSame() { $config = new SchemaConfig(); - $config->setName("foo"); - $oldSchema = new Schema(array(), array(), $config); + $config->setName('foo'); + $oldSchema = new Schema([], [], $config); $oldSchema->createTable('bar'); $newSchema = new Schema(); $newSchema->createTable('bar'); - $expected = new SchemaDiff(); + $expected = new SchemaDiff(); $expected->fromSchema = $oldSchema; self::assertEquals($expected, Comparator::compareSchemas($oldSchema, $newSchema)); @@ -932,17 +968,17 @@ public function testFqnSchemaComparisonNoSchemaSame() public function testAutoIncrementSequences() { $oldSchema = new Schema(); - $table = $oldSchema->createTable("foo"); - $table->addColumn("id", "integer", array("autoincrement" => true)); - $table->setPrimaryKey(array("id")); - $oldSchema->createSequence("foo_id_seq"); + $table = $oldSchema->createTable('foo'); + $table->addColumn('id', 'integer', ['autoincrement' => true]); + $table->setPrimaryKey(['id']); + $oldSchema->createSequence('foo_id_seq'); $newSchema = new Schema(); - $table = $newSchema->createTable("foo"); - $table->addColumn("id", "integer", array("autoincrement" => true)); - $table->setPrimaryKey(array("id")); + $table = $newSchema->createTable('foo'); + $table->addColumn('id', 'integer', ['autoincrement' => true]); + $table->setPrimaryKey(['id']); - $c = new Comparator(); + $c = new Comparator(); $diff = $c->compare($oldSchema, $newSchema); self::assertCount(0, $diff->removedSequences); @@ -956,17 +992,17 @@ public function testAutoIncrementSequences() public function testAutoIncrementNoSequences() { $oldSchema = new Schema(); - $table = $oldSchema->createTable("foo"); - $table->addColumn("id", "integer", array("autoincrement" => true)); - $table->setPrimaryKey(array("id")); + $table = $oldSchema->createTable('foo'); + $table->addColumn('id', 'integer', ['autoincrement' => true]); + $table->setPrimaryKey(['id']); $newSchema = new Schema(); - $table = $newSchema->createTable("foo"); - $table->addColumn("id", "integer", array("autoincrement" => true)); - $table->setPrimaryKey(array("id")); - $newSchema->createSequence("foo_id_seq"); + $table = $newSchema->createTable('foo'); + $table->addColumn('id', 'integer', ['autoincrement' => true]); + $table->setPrimaryKey(['id']); + $newSchema->createSequence('foo_id_seq'); - $c = new Comparator(); + $c = new Comparator(); $diff = $c->compare($oldSchema, $newSchema); self::assertCount(0, $diff->newSequences); @@ -992,8 +1028,8 @@ public function testAvoidMultipleDropForeignKey() $tableC->addColumn('table_a_id', 'integer'); $tableC->addColumn('table_b_id', 'integer'); - $tableC->addForeignKeyConstraint($tableA, array('table_a_id'), array('id')); - $tableC->addForeignKeyConstraint($tableB, array('table_b_id'), array('id')); + $tableC->addForeignKeyConstraint($tableA, ['table_a_id'], ['id']); + $tableC->addForeignKeyConstraint($tableB, ['table_b_id'], ['id']); $newSchema = new Schema(); @@ -1018,16 +1054,16 @@ public function testCompareChangedColumn() $tableFoo->addColumn('id', 'integer'); $newSchema = new Schema(); - $table = $newSchema->createTable('foo'); + $table = $newSchema->createTable('foo'); $table->addColumn('id', 'string'); - $expected = new SchemaDiff(); - $expected->fromSchema = $oldSchema; - $tableDiff = $expected->changedTables['foo'] = new TableDiff('foo'); - $tableDiff->fromTable = $tableFoo; - $columnDiff = $tableDiff->changedColumns['id'] = new ColumnDiff('id', $table->getColumn('id')); - $columnDiff->fromColumn = $tableFoo->getColumn('id'); - $columnDiff->changedProperties = array('type'); + $expected = new SchemaDiff(); + $expected->fromSchema = $oldSchema; + $tableDiff = $expected->changedTables['foo'] = new TableDiff('foo'); + $tableDiff->fromTable = $tableFoo; + $columnDiff = $tableDiff->changedColumns['id'] = new ColumnDiff('id', $table->getColumn('id')); + $columnDiff->fromColumn = $tableFoo->getColumn('id'); + $columnDiff->changedProperties = ['type']; self::assertEquals($expected, Comparator::compareSchemas($oldSchema, $newSchema)); } @@ -1040,16 +1076,16 @@ public function testCompareChangedBinaryColumn() $tableFoo->addColumn('id', 'binary'); $newSchema = new Schema(); - $table = $newSchema->createTable('foo'); - $table->addColumn('id', 'binary', array('length' => 42, 'fixed' => true)); + $table = $newSchema->createTable('foo'); + $table->addColumn('id', 'binary', ['length' => 42, 'fixed' => true]); - $expected = new SchemaDiff(); - $expected->fromSchema = $oldSchema; - $tableDiff = $expected->changedTables['foo'] = new TableDiff('foo'); - $tableDiff->fromTable = $tableFoo; - $columnDiff = $tableDiff->changedColumns['id'] = new ColumnDiff('id', $table->getColumn('id')); - $columnDiff->fromColumn = $tableFoo->getColumn('id'); - $columnDiff->changedProperties = array('length', 'fixed'); + $expected = new SchemaDiff(); + $expected->fromSchema = $oldSchema; + $tableDiff = $expected->changedTables['foo'] = new TableDiff('foo'); + $tableDiff->fromTable = $tableFoo; + $columnDiff = $tableDiff->changedColumns['id'] = new ColumnDiff('id', $table->getColumn('id')); + $columnDiff->fromColumn = $tableFoo->getColumn('id'); + $columnDiff->changedProperties = ['length', 'fixed']; self::assertEquals($expected, Comparator::compareSchemas($oldSchema, $newSchema)); } @@ -1059,11 +1095,11 @@ public function testCompareChangedBinaryColumn() */ public function testCompareQuotedAndUnquotedForeignKeyColumns() { - $fk1 = new ForeignKeyConstraint(array("foo"), "bar", array("baz"), "fk1", array('onDelete' => 'NO ACTION')); - $fk2 = new ForeignKeyConstraint(array("`foo`"), "bar", array("`baz`"), "fk1", array('onDelete' => 'NO ACTION')); + $fk1 = new ForeignKeyConstraint(['foo'], 'bar', ['baz'], 'fk1', ['onDelete' => 'NO ACTION']); + $fk2 = new ForeignKeyConstraint(['`foo`'], 'bar', ['`baz`'], 'fk1', ['onDelete' => 'NO ACTION']); $comparator = new Comparator(); - $diff = $comparator->diffForeignKey($fk1, $fk2); + $diff = $comparator->diffForeignKey($fk1, $fk2); self::assertFalse($diff); } @@ -1074,7 +1110,7 @@ public function testCompareQuotedAndUnquotedForeignKeyColumns() * @param int $changeTableCount * @param int $removeTableCount */ - public function assertSchemaTableChangeCount($diff, $newTableCount=0, $changeTableCount=0, $removeTableCount=0) + public function assertSchemaTableChangeCount($diff, $newTableCount = 0, $changeTableCount = 0, $removeTableCount = 0) { self::assertCount($newTableCount, $diff->newTables); self::assertCount($changeTableCount, $diff->changedTables); @@ -1087,45 +1123,45 @@ public function assertSchemaTableChangeCount($diff, $newTableCount=0, $changeTab * @param int $changeSequenceCount * @param int $changeSequenceCount */ - public function assertSchemaSequenceChangeCount($diff, $newSequenceCount=0, $changeSequenceCount=0, $removeSequenceCount=0) + public function assertSchemaSequenceChangeCount($diff, $newSequenceCount = 0, $changeSequenceCount = 0, $removeSequenceCount = 0) { - 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."); + 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() { - $column1 = new Column('foo', Type::getType('string'), array('platformOptions' => array('foo' => 'foo', 'bar' => 'bar'))); - $column2 = new Column('foo', Type::getType('string'), array('platformOptions' => array('foo' => 'foo', 'foobar' => 'foobar'))); - $column3 = new Column('foo', Type::getType('string'), array('platformOptions' => array('foo' => 'foo', 'bar' => 'rab'))); + $column1 = new Column('foo', Type::getType('string'), ['platformOptions' => ['foo' => 'foo', 'bar' => 'bar']]); + $column2 = new Column('foo', Type::getType('string'), ['platformOptions' => ['foo' => 'foo', 'foobar' => 'foobar']]); + $column3 = new Column('foo', Type::getType('string'), ['platformOptions' => ['foo' => 'foo', 'bar' => 'rab']]); $column4 = new Column('foo', Type::getType('string')); $comparator = new Comparator(); - self::assertEquals(array(), $comparator->diffColumn($column1, $column2)); - self::assertEquals(array(), $comparator->diffColumn($column2, $column1)); - self::assertEquals(array('bar'), $comparator->diffColumn($column1, $column3)); - self::assertEquals(array('bar'), $comparator->diffColumn($column3, $column1)); - self::assertEquals(array(), $comparator->diffColumn($column1, $column4)); - self::assertEquals(array(), $comparator->diffColumn($column4, $column1)); + self::assertEquals([], $comparator->diffColumn($column1, $column2)); + self::assertEquals([], $comparator->diffColumn($column2, $column1)); + self::assertEquals(['bar'], $comparator->diffColumn($column1, $column3)); + self::assertEquals(['bar'], $comparator->diffColumn($column3, $column1)); + self::assertEquals([], $comparator->diffColumn($column1, $column4)); + self::assertEquals([], $comparator->diffColumn($column4, $column1)); } public function testComplexDiffColumn() { - $column1 = new Column('foo', Type::getType('string'), array( - 'platformOptions' => array('foo' => 'foo'), - 'customSchemaOptions' => array('foo' => 'bar'), - )); + $column1 = new Column('foo', Type::getType('string'), [ + 'platformOptions' => ['foo' => 'foo'], + 'customSchemaOptions' => ['foo' => 'bar'], + ]); - $column2 = new Column('foo', Type::getType('string'), array( - 'platformOptions' => array('foo' => 'bar'), - )); + $column2 = new Column('foo', Type::getType('string'), [ + 'platformOptions' => ['foo' => 'bar'], + ]); $comparator = new Comparator(); - self::assertEquals(array(), $comparator->diffColumn($column1, $column2)); - self::assertEquals(array(), $comparator->diffColumn($column2, $column1)); + self::assertEquals([], $comparator->diffColumn($column1, $column2)); + self::assertEquals([], $comparator->diffColumn($column2, $column1)); } /** @@ -1135,15 +1171,15 @@ public function testComparesNamespaces() { $comparator = new Comparator(); $fromSchema = $this->getMockBuilder('Doctrine\DBAL\Schema\Schema') - ->setMethods(array('getNamespaces', 'hasNamespace')) + ->setMethods(['getNamespaces', 'hasNamespace']) ->getMock(); - $toSchema = $this->getMockBuilder('Doctrine\DBAL\Schema\Schema') - ->setMethods(array('getNamespaces', 'hasNamespace')) + $toSchema = $this->getMockBuilder('Doctrine\DBAL\Schema\Schema') + ->setMethods(['getNamespaces', 'hasNamespace']) ->getMock(); $fromSchema->expects($this->once()) ->method('getNamespaces') - ->will($this->returnValue(array('foo', 'bar'))); + ->will($this->returnValue(['foo', 'bar'])); $fromSchema->expects($this->at(0)) ->method('hasNamespace') @@ -1157,7 +1193,7 @@ public function testComparesNamespaces() $toSchema->expects($this->once()) ->method('getNamespaces') - ->will($this->returnValue(array('bar', 'baz'))); + ->will($this->returnValue(['bar', 'baz'])); $toSchema->expects($this->at(1)) ->method('hasNamespace') @@ -1169,10 +1205,10 @@ public function testComparesNamespaces() ->with('bar') ->will($this->returnValue(true)); - $expected = new SchemaDiff(); - $expected->fromSchema = $fromSchema; - $expected->newNamespaces = array('baz' => 'baz'); - $expected->removedNamespaces = array('foo' => 'foo'); + $expected = new SchemaDiff(); + $expected->fromSchema = $fromSchema; + $expected->newNamespaces = ['baz' => 'baz']; + $expected->removedNamespaces = ['foo' => 'foo']; self::assertEquals($expected, $comparator->compare($fromSchema, $toSchema)); } @@ -1181,15 +1217,15 @@ public function testCompareGuidColumns() { $comparator = new Comparator(); - $column1 = new Column('foo', Type::getType('guid'), array('comment' => 'GUID 1')); + $column1 = new Column('foo', Type::getType('guid'), ['comment' => 'GUID 1']); $column2 = new Column( 'foo', Type::getType('guid'), - array('notnull' => false, 'length' => '36', 'fixed' => true, 'default' => 'NEWID()', 'comment' => 'GUID 2.') + ['notnull' => false, 'length' => '36', 'fixed' => true, 'default' => 'NEWID()', 'comment' => 'GUID 2.'] ); - self::assertEquals(array('notnull', 'default', 'comment'), $comparator->diffColumn($column1, $column2)); - self::assertEquals(array('notnull', 'default', 'comment'), $comparator->diffColumn($column2, $column1)); + self::assertEquals(['notnull', 'default', 'comment'], $comparator->diffColumn($column1, $column2)); + self::assertEquals(['notnull', 'default', 'comment'], $comparator->diffColumn($column2, $column1)); } /** @@ -1199,12 +1235,12 @@ public function testCompareGuidColumns() */ public function testCompareColumnComments($comment1, $comment2, $equals) { - $column1 = new Column('foo', Type::getType('integer'), array('comment' => $comment1)); - $column2 = new Column('foo', Type::getType('integer'), array('comment' => $comment2)); + $column1 = new Column('foo', Type::getType('integer'), ['comment' => $comment1]); + $column2 = new Column('foo', Type::getType('integer'), ['comment' => $comment2]); $comparator = new Comparator(); - $expectedDiff = $equals ? array() : array('comment'); + $expectedDiff = $equals ? [] : ['comment']; $actualDiff = $comparator->diffColumn($column1, $column2); @@ -1217,66 +1253,74 @@ public function testCompareColumnComments($comment1, $comment2, $equals) public function getCompareColumnComments() { - return array( - array(null, null, true), - array('', '', true), - array(' ', ' ', true), - array('0', '0', true), - array('foo', 'foo', true), - - array(null, '', true), - array(null, ' ', false), - array(null, '0', false), - array(null, 'foo', false), - - array('', ' ', false), - array('', '0', false), - array('', 'foo', false), - - array(' ', '0', false), - array(' ', 'foo', false), - - array('0', 'foo', false), - ); + return [ + [null, null, true], + ['', '', true], + [' ', ' ', true], + ['0', '0', true], + ['foo', 'foo', true], + + [null, '', true], + [null, ' ', false], + [null, '0', false], + [null, 'foo', false], + + ['', ' ', false], + ['', '0', false], + ['', 'foo', false], + + [' ', '0', false], + [' ', 'foo', false], + + ['0', 'foo', false], + ]; } public function testForeignKeyRemovalWithRenamedLocalColumn() { - $fromSchema = new Schema( array( - 'table1' => new Table('table1', - array( + $fromSchema = new Schema([ + 'table1' => new Table( + 'table1', + [ 'id' => new Column('id', Type::getType('integer')), - )), - 'table2' => new Table('table2', - array( + ] + ), + 'table2' => new Table( + 'table2', + [ 'id' => new Column('id', Type::getType('integer')), - 'id_table1' => new Column('id_table1', Type::getType('integer')) - ), - array(), - array( - new ForeignKeyConstraint(array('id_table1'), 'table1', array('id'), 'fk_table2_table1') - )) - )); - $toSchema = new Schema( array( - 'table2' => new Table('table2', - array( + 'id_table1' => new Column('id_table1', Type::getType('integer')), + ], + [], + [ + new ForeignKeyConstraint(['id_table1'], 'table1', ['id'], 'fk_table2_table1'), + ] + ), + ]); + $toSchema = new Schema([ + 'table2' => new Table( + 'table2', + [ 'id' => new Column('id', Type::getType('integer')), - 'id_table3' => new Column('id_table3', Type::getType('integer')) - ), - array(), - array( - new ForeignKeyConstraint(array('id_table3'), 'table3', array('id'), 'fk_table2_table3') - )), - 'table3' => new Table('table3', - array( - 'id' => new Column('id', Type::getType('integer')) - )) - )); - $actual = Comparator::compareSchemas($fromSchema, $toSchema); - self::assertArrayHasKey("table2", $actual->changedTables); + 'id_table3' => new Column('id_table3', Type::getType('integer')), + ], + [], + [ + new ForeignKeyConstraint(['id_table3'], 'table3', ['id'], 'fk_table2_table3'), + ] + ), + 'table3' => new Table( + 'table3', + [ + 'id' => new Column('id', Type::getType('integer')), + ] + ), + ]); + $actual = Comparator::compareSchemas($fromSchema, $toSchema); + self::assertArrayHasKey('table2', $actual->changedTables); self::assertCount(1, $actual->orphanedForeignKeys); - self::assertEquals("fk_table2_table1", $actual->orphanedForeignKeys[0]->getName()); - self::assertCount(1, $actual->changedTables['table2']->addedForeignKeys, "FK to table3 should be added."); - self::assertEquals("table3", $actual->changedTables['table2']->addedForeignKeys[0]->getForeignTableName()); + self::assertEquals('fk_table2_table1', $actual->orphanedForeignKeys[0]->getName()); + self::assertCount(1, $actual->changedTables['table2']->addedForeignKeys, 'FK to table3 should be added.'); + self::assertEquals('table3', $actual->changedTables['table2']->addedForeignKeys[0]->getForeignTableName()); } } diff --git a/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php index d5592a4cbde..053ead6c1bc 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php @@ -8,28 +8,26 @@ use Doctrine\DBAL\Driver; use Doctrine\DBAL\Platforms\DB2Platform; use Doctrine\DBAL\Schema\DB2SchemaManager; +use PHPUnit\Framework\TestCase; +use PHPUnit_Framework_MockObject_MockObject; /** * @covers \Doctrine\DBAL\Schema\DB2SchemaManager */ -final class DB2SchemaManagerTest extends \PHPUnit\Framework\TestCase +final class DB2SchemaManagerTest extends TestCase { - /** - * @var Connection|\PHPUnit_Framework_MockObject_MockObject - */ + /** @var Connection|PHPUnit_Framework_MockObject_MockObject */ private $conn; - /** - * @var DB2SchemaManager - */ + /** @var DB2SchemaManager */ private $manager; protected function setUp() { - $eventManager = new EventManager(); - $driverMock = $this->createMock(Driver::class); - $platform = $this->createMock(DB2Platform::class); - $this->conn = $this + $eventManager = new EventManager(); + $driverMock = $this->createMock(Driver::class); + $platform = $this->createMock(DB2Platform::class); + $this->conn = $this ->getMockBuilder(Connection::class) ->setMethods(['fetchAll']) ->setConstructorArgs([['platform' => $platform], $driverMock, new Configuration(), $eventManager]) @@ -38,26 +36,20 @@ protected function setUp() } /** - * @group DBAL-2701 * @see https://github.com/doctrine/dbal/issues/2701 + * * @return void + * + * @group DBAL-2701 */ public function testListTableNamesFiltersAssetNamesCorrectly() { $this->conn->getConfiguration()->setFilterSchemaAssetsExpression('/^(?!T_)/'); $this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue([ - [ - 'name' => 'FOO', - ], - [ - 'name' => 'T_FOO', - ], - [ - 'name' => 'BAR', - ], - [ - 'name' => 'T_BAR', - ], + ['name' => 'FOO'], + ['name' => 'T_FOO'], + ['name' => 'BAR'], + ['name' => 'T_BAR'], ])); self::assertSame( diff --git a/tests/Doctrine/Tests/DBAL/Schema/ForeignKeyConstraintTest.php b/tests/Doctrine/Tests/DBAL/Schema/ForeignKeyConstraintTest.php index 291731bab6d..10bd92d52e6 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ForeignKeyConstraintTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ForeignKeyConstraintTest.php @@ -3,17 +3,17 @@ namespace Doctrine\Tests\DBAL\Schema; use Doctrine\DBAL\Schema\ForeignKeyConstraint; +use PHPUnit\Framework\TestCase; -class ForeignKeyConstraintTest extends \PHPUnit\Framework\TestCase +class ForeignKeyConstraintTest extends TestCase { /** * @group DBAL-1062 - * * @dataProvider getIntersectsIndexColumnsData */ public function testIntersectsIndexColumns(array $indexColumns, $expectedResult) { - $foreignKey = new ForeignKeyConstraint(array('foo', 'bar'), 'foreign_table', array('fk_foo', 'fk_bar')); + $foreignKey = new ForeignKeyConstraint(['foo', 'bar'], 'foreign_table', ['fk_foo', 'fk_bar']); $index = $this->getMockBuilder('Doctrine\DBAL\Schema\Index') ->disableOriginalConstructor() @@ -30,27 +30,27 @@ public function testIntersectsIndexColumns(array $indexColumns, $expectedResult) */ public function getIntersectsIndexColumnsData() { - return array( - array(array('baz'), false), - array(array('baz', 'bloo'), false), + return [ + [['baz'], false], + [['baz', 'bloo'], false], - array(array('foo'), true), - array(array('bar'), true), + [['foo'], true], + [['bar'], true], - array(array('foo', 'bar'), true), - array(array('bar', 'foo'), true), + [['foo', 'bar'], true], + [['bar', 'foo'], true], - array(array('foo', 'baz'), true), - array(array('baz', 'foo'), true), + [['foo', 'baz'], true], + [['baz', 'foo'], true], - array(array('bar', 'baz'), true), - array(array('baz', 'bar'), true), + [['bar', 'baz'], true], + [['baz', 'bar'], true], - array(array('foo', 'bloo', 'baz'), true), - array(array('bloo', 'foo', 'baz'), true), - array(array('bloo', 'baz', 'foo'), true), + [['foo', 'bloo', 'baz'], true], + [['bloo', 'foo', 'baz'], true], + [['bloo', 'baz', 'foo'], true], - array(array('FOO'), true), - ); + [['FOO'], true], + ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Schema/IndexTest.php b/tests/Doctrine/Tests/DBAL/Schema/IndexTest.php index 1f49fd5e14d..af962f95f95 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/IndexTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/IndexTest.php @@ -3,21 +3,22 @@ namespace Doctrine\Tests\DBAL\Schema; use Doctrine\DBAL\Schema\Index; +use PHPUnit\Framework\TestCase; -class IndexTest extends \PHPUnit\Framework\TestCase +class IndexTest extends TestCase { - public function createIndex($unique = false, $primary = false, $options = array()) + public function createIndex($unique = false, $primary = false, $options = []) { - return new Index("foo", array("bar", "baz"), $unique, $primary, array(), $options); + return new Index('foo', ['bar', 'baz'], $unique, $primary, [], $options); } public function testCreateIndex() { $idx = $this->createIndex(); - self::assertEquals("foo", $idx->getName()); + self::assertEquals('foo', $idx->getName()); $columns = $idx->getColumns(); self::assertCount(2, $columns); - self::assertEquals(array("bar", "baz"), $columns); + self::assertEquals(['bar', 'baz'], $columns); self::assertFalse($idx->isUnique()); self::assertFalse($idx->isPrimary()); } @@ -69,7 +70,7 @@ public function testFulfilledByIndex() { $idx1 = $this->createIndex(); $idx2 = $this->createIndex(); - $pri = $this->createIndex(true, true); + $pri = $this->createIndex(true, true); $uniq = $this->createIndex(true); self::assertTrue($idx1->isFullfilledBy($idx2)); @@ -79,9 +80,9 @@ public function testFulfilledByIndex() public function testFulfilledWithPartial() { - $without = new Index('without', array('col1', 'col2'), true, false, array(), array()); - $partial = new Index('partial', array('col1', 'col2'), true, false, array(), array('where' => 'col1 IS NULL')); - $another = new Index('another', array('col1', 'col2'), true, false, array(), array('where' => 'col1 IS NULL')); + $without = new Index('without', ['col1', 'col2'], true, false, [], []); + $partial = new Index('partial', ['col1', 'col2'], true, false, [], ['where' => 'col1 IS NULL']); + $another = new Index('another', ['col1', 'col2'], true, false, [], ['where' => 'col1 IS NULL']); self::assertFalse($partial->isFullfilledBy($without)); self::assertFalse($without->isFullfilledBy($partial)); @@ -94,9 +95,9 @@ public function testFulfilledWithPartial() public function testOverrulesWithPartial() { - $without = new Index('without', array('col1', 'col2'), true, false, array(), array()); - $partial = new Index('partial', array('col1', 'col2'), true, false, array(), array('where' => 'col1 IS NULL')); - $another = new Index('another', array('col1', 'col2'), true, false, array(), array('where' => 'col1 IS NULL')); + $without = new Index('without', ['col1', 'col2'], true, false, [], []); + $partial = new Index('partial', ['col1', 'col2'], true, false, [], ['where' => 'col1 IS NULL']); + $another = new Index('another', ['col1', 'col2'], true, false, [], ['where' => 'col1 IS NULL']); self::assertFalse($partial->overrules($without)); self::assertFalse($without->overrules($partial)); @@ -119,7 +120,7 @@ public function testFlags() $idx1->addFlag('clustered'); self::assertTrue($idx1->hasFlag('clustered')); self::assertTrue($idx1->hasFlag('CLUSTERED')); - self::assertSame(array('clustered'), $idx1->getFlags()); + self::assertSame(['clustered'], $idx1->getFlags()); $idx1->removeFlag('clustered'); self::assertFalse($idx1->hasFlag('clustered')); @@ -131,14 +132,14 @@ public function testFlags() */ public function testIndexQuotes() { - $index = new Index("foo", array("`bar`", "`baz`")); + $index = new Index('foo', ['`bar`', '`baz`']); - self::assertTrue($index->spansColumns(array("bar", "baz"))); - self::assertTrue($index->hasColumnAtPosition("bar", 0)); - self::assertTrue($index->hasColumnAtPosition("baz", 1)); + self::assertTrue($index->spansColumns(['bar', 'baz'])); + self::assertTrue($index->hasColumnAtPosition('bar', 0)); + self::assertTrue($index->hasColumnAtPosition('baz', 1)); - self::assertFalse($index->hasColumnAtPosition("bar", 1)); - self::assertFalse($index->hasColumnAtPosition("baz", 0)); + self::assertFalse($index->hasColumnAtPosition('bar', 1)); + self::assertFalse($index->hasColumnAtPosition('baz', 0)); } public function testOptions() @@ -147,11 +148,11 @@ public function testOptions() self::assertFalse($idx1->hasOption('where')); self::assertEmpty($idx1->getOptions()); - $idx2 = $this->createIndex(false, false, array('where' => 'name IS NULL')); + $idx2 = $this->createIndex(false, false, ['where' => 'name IS NULL']); self::assertTrue($idx2->hasOption('where')); self::assertTrue($idx2->hasOption('WHERE')); self::assertSame('name IS NULL', $idx2->getOption('where')); self::assertSame('name IS NULL', $idx2->getOption('WHERE')); - self::assertSame(array('where' => 'name IS NULL'), $idx2->getOptions()); + self::assertSame(['where' => 'name IS NULL'], $idx2->getOptions()); } } diff --git a/tests/Doctrine/Tests/DBAL/Schema/MySqlInheritCharsetTest.php b/tests/Doctrine/Tests/DBAL/Schema/MySqlInheritCharsetTest.php index c5b7ad0dd77..9ae399c7a04 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/MySqlInheritCharsetTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/MySqlInheritCharsetTest.php @@ -38,7 +38,7 @@ public function testTableOptions() : void { $eventManager = new EventManager(); $driverMock = $this->createMock('Doctrine\DBAL\Driver'); - $platform = new \Doctrine\DBAL\Platforms\MySqlPlatform(); + $platform = new MySqlPlatform(); // default, no overrides $table = new Table('foobar', [new Column('aa', Type::getType('integer'))]); diff --git a/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php index e8129d3a20f..2a3837140c0 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php @@ -5,14 +5,14 @@ use Doctrine\Common\EventManager; use Doctrine\DBAL\Configuration; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\MySqlSchemaManager; +use PHPUnit\Framework\TestCase; use function array_map; -class MySqlSchemaManagerTest extends \PHPUnit\Framework\TestCase +class MySqlSchemaManagerTest extends TestCase { - /** - * @var \Doctrine\DBAL\Schema\AbstractSchemaManager - */ + /** @var AbstractSchemaManager */ private $manager; /** @var Connection */ @@ -20,12 +20,12 @@ class MySqlSchemaManagerTest extends \PHPUnit\Framework\TestCase protected function setUp() { - $eventManager = new EventManager(); - $driverMock = $this->createMock('Doctrine\DBAL\Driver'); - $platform = $this->createMock('Doctrine\DBAL\Platforms\MySqlPlatform'); - $this->conn = $this->getMockBuilder('Doctrine\DBAL\Connection') - ->setMethods(array('fetchAll')) - ->setConstructorArgs(array(array('platform' => $platform), $driverMock, new Configuration(), $eventManager)) + $eventManager = new EventManager(); + $driverMock = $this->createMock('Doctrine\DBAL\Driver'); + $platform = $this->createMock('Doctrine\DBAL\Platforms\MySqlPlatform'); + $this->conn = $this->getMockBuilder('Doctrine\DBAL\Connection') + ->setMethods(['fetchAll']) + ->setConstructorArgs([['platform' => $platform], $driverMock, new Configuration(), $eventManager]) ->getMock(); $this->manager = new MySqlSchemaManager($this->conn); } @@ -34,40 +34,40 @@ public function testCompositeForeignKeys() { $this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue($this->getFKDefinition())); $fkeys = $this->manager->listTableForeignKeys('dummy'); - self::assertCount(1, $fkeys, "Table has to have one foreign key."); + self::assertCount(1, $fkeys, 'Table has to have one foreign key.'); self::assertInstanceOf('Doctrine\DBAL\Schema\ForeignKeyConstraint', $fkeys[0]); - self::assertEquals(array('column_1', 'column_2', 'column_3'), array_map('strtolower', $fkeys[0]->getLocalColumns())); - self::assertEquals(array('column_1', 'column_2', 'column_3'), array_map('strtolower', $fkeys[0]->getForeignColumns())); + self::assertEquals(['column_1', 'column_2', 'column_3'], array_map('strtolower', $fkeys[0]->getLocalColumns())); + self::assertEquals(['column_1', 'column_2', 'column_3'], array_map('strtolower', $fkeys[0]->getForeignColumns())); } public function getFKDefinition() { - return array( - array( - "CONSTRAINT_NAME" => "FK_C1B1712387FE737264DE5A5511B8B3E", - "COLUMN_NAME" => "column_1", - "REFERENCED_TABLE_NAME" => "dummy", - "REFERENCED_COLUMN_NAME" => "column_1", - "update_rule" => "RESTRICT", - "delete_rule" => "RESTRICT", - ), - array( - "CONSTRAINT_NAME" => "FK_C1B1712387FE737264DE5A5511B8B3E", - "COLUMN_NAME" => "column_2", - "REFERENCED_TABLE_NAME" => "dummy", - "REFERENCED_COLUMN_NAME" => "column_2", - "update_rule" => "RESTRICT", - "delete_rule" => "RESTRICT", - ), - array( - "CONSTRAINT_NAME" => "FK_C1B1712387FE737264DE5A5511B8B3E", - "COLUMN_NAME" => "column_3", - "REFERENCED_TABLE_NAME" => "dummy", - "REFERENCED_COLUMN_NAME" => "column_3", - "update_rule" => "RESTRICT", - "delete_rule" => "RESTRICT", - ) - ); + return [ + [ + 'CONSTRAINT_NAME' => 'FK_C1B1712387FE737264DE5A5511B8B3E', + 'COLUMN_NAME' => 'column_1', + 'REFERENCED_TABLE_NAME' => 'dummy', + 'REFERENCED_COLUMN_NAME' => 'column_1', + 'update_rule' => 'RESTRICT', + 'delete_rule' => 'RESTRICT', + ], + [ + 'CONSTRAINT_NAME' => 'FK_C1B1712387FE737264DE5A5511B8B3E', + 'COLUMN_NAME' => 'column_2', + 'REFERENCED_TABLE_NAME' => 'dummy', + 'REFERENCED_COLUMN_NAME' => 'column_2', + 'update_rule' => 'RESTRICT', + 'delete_rule' => 'RESTRICT', + ], + [ + 'CONSTRAINT_NAME' => 'FK_C1B1712387FE737264DE5A5511B8B3E', + 'COLUMN_NAME' => 'column_3', + 'REFERENCED_TABLE_NAME' => 'dummy', + 'REFERENCED_COLUMN_NAME' => 'column_3', + 'update_rule' => 'RESTRICT', + 'delete_rule' => 'RESTRICT', + ], + ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php b/tests/Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php index ff8e9b32256..0d45a5ef5e5 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php @@ -2,44 +2,45 @@ namespace Doctrine\Tests\DBAL\Schema\Platforms; +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\Table; +use PHPUnit\Framework\TestCase; -class MySQLSchemaTest extends \PHPUnit\Framework\TestCase +class MySQLSchemaTest extends TestCase { /** @var Comparator */ private $comparator; - /** - * - * @var \Doctrine\DBAL\Platforms\AbstractPlatform - */ + /** @var AbstractPlatform */ private $platform; protected function setUp() { $this->comparator = new Comparator(); - $this->platform = new \Doctrine\DBAL\Platforms\MySqlPlatform; + $this->platform = new MySqlPlatform(); } public function testSwitchPrimaryKeyOrder() { - $tableOld = new Table("test"); + $tableOld = new Table('test'); $tableOld->addColumn('foo_id', 'integer'); $tableOld->addColumn('bar_id', 'integer'); $tableNew = clone $tableOld; - $tableOld->setPrimaryKey(array('foo_id', 'bar_id')); - $tableNew->setPrimaryKey(array('bar_id', 'foo_id')); + $tableOld->setPrimaryKey(['foo_id', 'bar_id']); + $tableNew->setPrimaryKey(['bar_id', 'foo_id']); $diff = $this->comparator->diffTable($tableOld, $tableNew); - $sql = $this->platform->getAlterTableSQL($diff); + $sql = $this->platform->getAlterTableSQL($diff); self::assertEquals( - array( + [ 'ALTER TABLE test DROP PRIMARY KEY', - 'ALTER TABLE test ADD PRIMARY KEY (bar_id, foo_id)' - ), $sql + 'ALTER TABLE test ADD PRIMARY KEY (bar_id, foo_id)', + ], + $sql ); } @@ -48,16 +49,16 @@ public function testSwitchPrimaryKeyOrder() */ public function testGenerateForeignKeySQL() { - $tableOld = new Table("test"); + $tableOld = new Table('test'); $tableOld->addColumn('foo_id', 'integer'); - $tableOld->addUnnamedForeignKeyConstraint('test_foreign', array('foo_id'), array('foo_id')); + $tableOld->addUnnamedForeignKeyConstraint('test_foreign', ['foo_id'], ['foo_id']); - $sqls = array(); + $sqls = []; foreach ($tableOld->getForeignKeys() as $fk) { $sqls[] = $this->platform->getCreateForeignKeySQL($fk, $tableOld); } - self::assertEquals(array("ALTER TABLE test ADD CONSTRAINT FK_D87F7E0C8E48560F FOREIGN KEY (foo_id) REFERENCES test_foreign (foo_id)"), $sqls); + self::assertEquals(['ALTER TABLE test ADD CONSTRAINT FK_D87F7E0C8E48560F FOREIGN KEY (foo_id) REFERENCES test_foreign (foo_id)'], $sqls); } /** @@ -65,18 +66,18 @@ public function testGenerateForeignKeySQL() */ public function testClobNoAlterTable() { - $tableOld = new Table("test"); + $tableOld = new Table('test'); $tableOld->addColumn('id', 'integer'); - $tableOld->addColumn('description', 'string', array('length' => 65536)); + $tableOld->addColumn('description', 'string', ['length' => 65536]); $tableNew = clone $tableOld; - $tableNew->setPrimaryKey(array('id')); + $tableNew->setPrimaryKey(['id']); $diff = $this->comparator->diffTable($tableOld, $tableNew); - $sql = $this->platform->getAlterTableSQL($diff); + $sql = $this->platform->getAlterTableSQL($diff); self::assertEquals( - array('ALTER TABLE test ADD PRIMARY KEY (id)'), + ['ALTER TABLE test ADD PRIMARY KEY (id)'], $sql ); } diff --git a/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php b/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php index 5541bb04396..b25f81601be 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php @@ -2,33 +2,35 @@ namespace Doctrine\Tests\DBAL\Schema; +use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\SchemaDiff; use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; +use PHPUnit\Framework\TestCase; -class SchemaDiffTest extends \PHPUnit\Framework\TestCase +class SchemaDiffTest extends TestCase { public function testSchemaDiffToSql() { - $diff = $this->createSchemaDiff(); + $diff = $this->createSchemaDiff(); $platform = $this->createPlatform(true); $sql = $diff->toSql($platform); - $expected = array('create_schema', 'drop_orphan_fk', 'alter_seq', 'drop_seq', 'create_seq', 'create_table', 'create_foreign_key', 'drop_table', 'alter_table'); + $expected = ['create_schema', 'drop_orphan_fk', 'alter_seq', 'drop_seq', 'create_seq', 'create_table', 'create_foreign_key', 'drop_table', 'alter_table']; self::assertEquals($expected, $sql); } public function testSchemaDiffToSaveSql() { - $diff = $this->createSchemaDiff(); + $diff = $this->createSchemaDiff(); $platform = $this->createPlatform(false); $sql = $diff->toSaveSql($platform); - $expected = array('create_schema', 'alter_seq', 'create_seq', 'create_table', 'create_foreign_key', 'alter_table'); + $expected = ['create_schema', 'alter_seq', 'create_seq', 'create_table', 'create_foreign_key', 'alter_table']; self::assertEquals($expected, $sql); } @@ -63,7 +65,7 @@ public function createPlatform($unsafe = false) $platform->expects($this->exactly(1)) ->method('getCreateTableSql') ->with($this->isInstanceOf('Doctrine\DBAL\Schema\Table')) - ->will($this->returnValue(array('create_table'))); + ->will($this->returnValue(['create_table'])); $platform->expects($this->exactly(1)) ->method('getCreateForeignKeySQL') ->with($this->isInstanceOf('Doctrine\DBAL\Schema\ForeignKeyConstraint')) @@ -71,7 +73,7 @@ public function createPlatform($unsafe = false) $platform->expects($this->exactly(1)) ->method('getAlterTableSql') ->with($this->isInstanceOf('Doctrine\DBAL\Schema\TableDiff')) - ->will($this->returnValue(array('alter_table'))); + ->will($this->returnValue(['alter_table'])); if ($unsafe) { $platform->expects($this->exactly(1)) ->method('getDropForeignKeySql') @@ -95,18 +97,18 @@ public function createPlatform($unsafe = false) public function createSchemaDiff() { - $diff = new SchemaDiff(); - $diff->newNamespaces['foo_ns'] = 'foo_ns'; + $diff = new SchemaDiff(); + $diff->newNamespaces['foo_ns'] = 'foo_ns'; $diff->removedNamespaces['bar_ns'] = 'bar_ns'; $diff->changedSequences['foo_seq'] = new Sequence('foo_seq'); - $diff->newSequences['bar_seq'] = new Sequence('bar_seq'); + $diff->newSequences['bar_seq'] = new Sequence('bar_seq'); $diff->removedSequences['baz_seq'] = new Sequence('baz_seq'); - $diff->newTables['foo_table'] = new Table('foo_table'); - $diff->removedTables['bar_table'] = new Table('bar_table'); - $diff->changedTables['baz_table'] = new TableDiff('baz_table'); + $diff->newTables['foo_table'] = new Table('foo_table'); + $diff->removedTables['bar_table'] = new Table('bar_table'); + $diff->changedTables['baz_table'] = new TableDiff('baz_table'); $diff->newTables['foo_table']->addColumn('foreign_id', 'integer'); - $diff->newTables['foo_table']->addForeignKeyConstraint('foreign_table', array('foreign_id'), array('id')); - $fk = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(array('id'), 'foreign_table', array('id')); + $diff->newTables['foo_table']->addForeignKeyConstraint('foreign_table', ['foreign_id'], ['id']); + $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/Schema/SchemaTest.php b/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php index 81db2c51e08..c9bad262d74 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php @@ -3,19 +3,21 @@ namespace Doctrine\Tests\DBAL\Schema; use Doctrine\DBAL\Schema\Schema; +use Doctrine\DBAL\Schema\SchemaConfig; use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Table; +use PHPUnit\Framework\TestCase; use function current; use function strlen; -class SchemaTest extends \PHPUnit\Framework\TestCase +class SchemaTest extends TestCase { public function testAddTable() { - $tableName = "public.foo"; - $table = new Table($tableName); + $tableName = 'public.foo'; + $table = new Table($tableName); - $schema = new Schema(array($table)); + $schema = new Schema([$table]); self::assertTrue($schema->hasTable($tableName)); @@ -28,11 +30,11 @@ public function testAddTable() public function testTableMatchingCaseInsensitive() { - $table = new Table("Foo"); + $table = new Table('Foo'); - $schema = new Schema(array($table)); - self::assertTrue($schema->hasTable("foo")); - self::assertTrue($schema->hasTable("FOO")); + $schema = new Schema([$table]); + self::assertTrue($schema->hasTable('foo')); + self::assertTrue($schema->hasTable('FOO')); self::assertSame($table, $schema->getTable('FOO')); self::assertSame($table, $schema->getTable('foo')); @@ -41,70 +43,70 @@ public function testTableMatchingCaseInsensitive() public function testGetUnknownTableThrowsException() { - $this->expectException("Doctrine\DBAL\Schema\SchemaException"); + $this->expectException('Doctrine\DBAL\Schema\SchemaException'); $schema = new Schema(); - $schema->getTable("unknown"); + $schema->getTable('unknown'); } public function testCreateTableTwiceThrowsException() { - $this->expectException("Doctrine\DBAL\Schema\SchemaException"); + $this->expectException('Doctrine\DBAL\Schema\SchemaException'); - $tableName = "foo"; - $table = new Table($tableName); - $tables = array($table, $table); + $tableName = 'foo'; + $table = new Table($tableName); + $tables = [$table, $table]; $schema = new Schema($tables); } public function testRenameTable() { - $tableName = "foo"; - $table = new Table($tableName); - $schema = new Schema(array($table)); - - self::assertTrue($schema->hasTable("foo")); - $schema->renameTable("foo", "bar"); - self::assertFalse($schema->hasTable("foo")); - self::assertTrue($schema->hasTable("bar")); - self::assertSame($table, $schema->getTable("bar")); + $tableName = 'foo'; + $table = new Table($tableName); + $schema = new Schema([$table]); + + self::assertTrue($schema->hasTable('foo')); + $schema->renameTable('foo', 'bar'); + self::assertFalse($schema->hasTable('foo')); + self::assertTrue($schema->hasTable('bar')); + self::assertSame($table, $schema->getTable('bar')); } public function testDropTable() { - $tableName = "foo"; - $table = new Table($tableName); - $schema = new Schema(array($table)); + $tableName = 'foo'; + $table = new Table($tableName); + $schema = new Schema([$table]); - self::assertTrue($schema->hasTable("foo")); + self::assertTrue($schema->hasTable('foo')); - $schema->dropTable("foo"); + $schema->dropTable('foo'); - self::assertFalse($schema->hasTable("foo")); + self::assertFalse($schema->hasTable('foo')); } public function testCreateTable() { $schema = new Schema(); - self::assertFalse($schema->hasTable("foo")); + self::assertFalse($schema->hasTable('foo')); - $table = $schema->createTable("foo"); + $table = $schema->createTable('foo'); self::assertInstanceOf('Doctrine\DBAL\Schema\Table', $table); - self::assertEquals("foo", $table->getName()); - self::assertTrue($schema->hasTable("foo")); + self::assertEquals('foo', $table->getName()); + self::assertTrue($schema->hasTable('foo')); } public function testAddSequences() { - $sequence = new Sequence("a_seq", 1, 1); + $sequence = new Sequence('a_seq', 1, 1); - $schema = new Schema(array(), array($sequence)); + $schema = new Schema([], [$sequence]); - self::assertTrue($schema->hasSequence("a_seq")); - self::assertInstanceOf('Doctrine\DBAL\Schema\Sequence', $schema->getSequence("a_seq")); + self::assertTrue($schema->hasSequence('a_seq')); + self::assertInstanceOf('Doctrine\DBAL\Schema\Sequence', $schema->getSequence('a_seq')); $sequences = $schema->getSequences(); self::assertArrayHasKey('public.a_seq', $sequences); @@ -112,9 +114,9 @@ public function testAddSequences() public function testSequenceAccessCaseInsensitive() { - $sequence = new Sequence("a_Seq"); + $sequence = new Sequence('a_Seq'); - $schema = new Schema(array(), array($sequence)); + $schema = new Schema([], [$sequence]); self::assertTrue($schema->hasSequence('a_seq')); self::assertTrue($schema->hasSequence('a_Seq')); self::assertTrue($schema->hasSequence('A_SEQ')); @@ -126,23 +128,23 @@ public function testSequenceAccessCaseInsensitive() public function testGetUnknownSequenceThrowsException() { - $this->expectException("Doctrine\DBAL\Schema\SchemaException"); + $this->expectException('Doctrine\DBAL\Schema\SchemaException'); $schema = new Schema(); - $schema->getSequence("unknown"); + $schema->getSequence('unknown'); } public function testCreateSequence() { - $schema = new Schema(); + $schema = new Schema(); $sequence = $schema->createSequence('a_seq', 10, 20); self::assertEquals('a_seq', $sequence->getName()); self::assertEquals(10, $sequence->getAllocationSize()); self::assertEquals(20, $sequence->getInitialValue()); - self::assertTrue($schema->hasSequence("a_seq")); - self::assertInstanceOf('Doctrine\DBAL\Schema\Sequence', $schema->getSequence("a_seq")); + self::assertTrue($schema->hasSequence('a_seq')); + self::assertInstanceOf('Doctrine\DBAL\Schema\Sequence', $schema->getSequence('a_seq')); $sequences = $schema->getSequences(); self::assertArrayHasKey('public.a_seq', $sequences); @@ -150,32 +152,32 @@ public function testCreateSequence() public function testDropSequence() { - $sequence = new Sequence("a_seq", 1, 1); + $sequence = new Sequence('a_seq', 1, 1); - $schema = new Schema(array(), array($sequence)); + $schema = new Schema([], [$sequence]); - $schema->dropSequence("a_seq"); - self::assertFalse($schema->hasSequence("a_seq")); + $schema->dropSequence('a_seq'); + self::assertFalse($schema->hasSequence('a_seq')); } public function testAddSequenceTwiceThrowsException() { - $this->expectException("Doctrine\DBAL\Schema\SchemaException"); + $this->expectException('Doctrine\DBAL\Schema\SchemaException'); - $sequence = new Sequence("a_seq", 1, 1); + $sequence = new Sequence('a_seq', 1, 1); - $schema = new Schema(array(), array($sequence, $sequence)); + $schema = new Schema([], [$sequence, $sequence]); } public function testConfigMaxIdentifierLength() { - $schemaConfig = new \Doctrine\DBAL\Schema\SchemaConfig(); + $schemaConfig = new SchemaConfig(); $schemaConfig->setMaxIdentifierLength(5); - $schema = new Schema(array(), array(), $schemaConfig); - $table = $schema->createTable("smalltable"); + $schema = new Schema([], [], $schemaConfig); + $table = $schema->createTable('smalltable'); $table->addColumn('long_id', 'integer'); - $table->addIndex(array('long_id')); + $table->addIndex(['long_id']); $index = current($table->getIndexes()); self::assertEquals(5, strlen($index->getName())); @@ -183,7 +185,7 @@ public function testConfigMaxIdentifierLength() public function testDeepClone() { - $schema = new Schema(); + $schema = new Schema(); $sequence = $schema->createSequence('baz'); $tableA = $schema->createTable('foo'); @@ -192,7 +194,7 @@ public function testDeepClone() $tableB = $schema->createTable('bar'); $tableB->addColumn('id', 'integer'); $tableB->addColumn('foo_id', 'integer'); - $tableB->addForeignKeyConstraint($tableA, array('foo_id'), array('id')); + $tableB->addForeignKeyConstraint($tableA, ['foo_id'], ['id']); $schemaNew = clone $schema; @@ -269,12 +271,11 @@ public function testCreatesNamespace() self::assertTrue($schema->hasNamespace('`bar`')); self::assertTrue($schema->hasNamespace('`BAR`')); - self::assertSame(array('foo' => 'foo', 'bar' => '`bar`'), $schema->getNamespaces()); + self::assertSame(['foo' => 'foo', 'bar' => '`bar`'], $schema->getNamespaces()); } /** * @group DBAL-669 - * * @expectedException \Doctrine\DBAL\Schema\SchemaException */ public function testThrowsExceptionOnCreatingNamespaceTwice() @@ -350,7 +351,7 @@ public function testCreatesNamespaceThroughAddingSequenceImplicitly() */ public function testVisitsVisitor() { - $schema = new Schema(); + $schema = new Schema(); $visitor = $this->createMock('Doctrine\DBAL\Schema\Visitor\Visitor'); $schema->createNamespace('foo'); @@ -396,7 +397,7 @@ public function testVisitsVisitor() */ public function testVisitsNamespaceVisitor() { - $schema = new Schema(); + $schema = new Schema(); $visitor = $this->createMock('Doctrine\DBAL\Schema\Visitor\AbstractVisitor'); $schema->createNamespace('foo'); diff --git a/tests/Doctrine/Tests/DBAL/Schema/SequenceTest.php b/tests/Doctrine/Tests/DBAL/Schema/SequenceTest.php index 9414830b48a..b3a72017c16 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/SequenceTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/SequenceTest.php @@ -4,21 +4,22 @@ use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Table; +use Doctrine\Tests\DbalTestCase; -class SequenceTest extends \Doctrine\Tests\DbalTestCase +class SequenceTest extends DbalTestCase { /** * @group DDC-1657 */ public function testIsAutoincrementFor() { - $table = new Table("foo"); - $table->addColumn("id", "integer", array("autoincrement" => true)); - $table->setPrimaryKey(array("id")); + $table = new Table('foo'); + $table->addColumn('id', 'integer', ['autoincrement' => true]); + $table->setPrimaryKey(['id']); - $sequence = new Sequence("foo_id_seq"); - $sequence2 = new Sequence("bar_id_seq"); - $sequence3 = new Sequence("other.foo_id_seq"); + $sequence = new Sequence('foo_id_seq'); + $sequence2 = new Sequence('bar_id_seq'); + $sequence3 = new Sequence('other.foo_id_seq'); self::assertTrue($sequence->isAutoIncrementsFor($table)); self::assertFalse($sequence2->isAutoIncrementsFor($table)); @@ -28,14 +29,14 @@ public function testIsAutoincrementFor() public function testIsAutoincrementForCaseInsensitive() { $table = new Table('foo'); - $table->addColumn('ID', 'integer', array('autoincrement' => true)); - $table->setPrimaryKey(array('ID')); + $table->addColumn('ID', 'integer', ['autoincrement' => true]); + $table->setPrimaryKey(['ID']); - $sequence = new Sequence("foo_id_seq"); - $sequence1 = new Sequence("foo_ID_seq"); - $sequence2 = new Sequence("bar_id_seq"); - $sequence3 = new Sequence("bar_ID_seq"); - $sequence4 = new Sequence("other.foo_id_seq"); + $sequence = new Sequence('foo_id_seq'); + $sequence1 = new Sequence('foo_ID_seq'); + $sequence2 = new Sequence('bar_id_seq'); + $sequence3 = new Sequence('bar_ID_seq'); + $sequence4 = new Sequence('other.foo_id_seq'); self::assertTrue($sequence->isAutoIncrementsFor($table)); self::assertTrue($sequence1->isAutoIncrementsFor($table)); @@ -44,4 +45,3 @@ public function testIsAutoincrementForCaseInsensitive() self::assertFalse($sequence4->isAutoIncrementsFor($table)); } } - diff --git a/tests/Doctrine/Tests/DBAL/Schema/SqliteSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Schema/SqliteSchemaManagerTest.php index 8a6759663e7..7b3031624af 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/SqliteSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/SqliteSchemaManagerTest.php @@ -5,12 +5,13 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Schema\SqliteSchemaManager; +use PHPUnit\Framework\TestCase; +use ReflectionMethod; -class SqliteSchemaManagerTest extends \PHPUnit\Framework\TestCase +class SqliteSchemaManagerTest extends TestCase { /** * @dataProvider getDataColumnCollation - * * @group 2865 */ public function testParseColumnCollation(?string $collation, string $column, string $sql) : void @@ -19,7 +20,7 @@ public function testParseColumnCollation(?string $collation, string $column, str $conn->method('getDatabasePlatform')->willReturn(new SqlitePlatform()); $manager = new SqliteSchemaManager($conn); - $ref = new \ReflectionMethod($manager, 'parseColumnCollationFromSQL'); + $ref = new ReflectionMethod($manager, 'parseColumnCollationFromSQL'); $ref->setAccessible(true); self::assertSame($collation, $ref->invoke($manager, $column, $sql)); @@ -49,7 +50,6 @@ public function getDataColumnCollation() /** * @dataProvider getDataColumnComment - * * @group 2865 */ public function testParseColumnCommentFromSQL(?string $comment, string $column, string $sql) : void @@ -58,7 +58,7 @@ public function testParseColumnCommentFromSQL(?string $comment, string $column, $conn->method('getDatabasePlatform')->willReturn(new SqlitePlatform()); $manager = new SqliteSchemaManager($conn); - $ref = new \ReflectionMethod($manager, 'parseColumnCommentFromSQL'); + $ref = new ReflectionMethod($manager, 'parseColumnCommentFromSQL'); $ref->setAccessible(true); self::assertSame($comment, $ref->invoke($manager, $column, $sql)); @@ -68,40 +68,58 @@ public function getDataColumnComment() { return [ 'Single column with no comment' => [ - null, 'a', 'CREATE TABLE "a" ("a" TEXT DEFAULT "a" COLLATE RTRIM)', + null, + 'a', + 'CREATE TABLE "a" ("a" TEXT DEFAULT "a" COLLATE RTRIM)', ], 'Single column with type comment' => [ - '(DC2Type:x)', 'a', 'CREATE TABLE "a" ("a" CLOB DEFAULT NULL COLLATE BINARY --(DC2Type:x) + '(DC2Type:x)', + 'a', + 'CREATE TABLE "a" ("a" CLOB DEFAULT NULL COLLATE BINARY --(DC2Type:x) )', ], 'Multiple similar columns with type comment 1' => [ - null, 'b', 'CREATE TABLE "a" (a TEXT COLLATE RTRIM, "b" TEXT DEFAULT "a" COLLATE RTRIM, "bb" CLOB DEFAULT NULL COLLATE BINARY --(DC2Type:x) + null, + 'b', + 'CREATE TABLE "a" (a TEXT COLLATE RTRIM, "b" TEXT DEFAULT "a" COLLATE RTRIM, "bb" CLOB DEFAULT NULL COLLATE BINARY --(DC2Type:x) )', ], 'Multiple similar columns with type comment 2' => [ - '(DC2Type:x)', 'b', 'CREATE TABLE "a" (a TEXT COLLATE RTRIM, "bb" TEXT DEFAULT "a" COLLATE RTRIM, "b" CLOB DEFAULT NULL COLLATE BINARY --(DC2Type:x) + '(DC2Type:x)', + 'b', + 'CREATE TABLE "a" (a TEXT COLLATE RTRIM, "bb" TEXT DEFAULT "a" COLLATE RTRIM, "b" CLOB DEFAULT NULL COLLATE BINARY --(DC2Type:x) )', ], 'Multiple similar columns on different lines, with type comment 1' => [ - null, 'bb', 'CREATE TABLE "a" (a TEXT COLLATE RTRIM, "b" CLOB DEFAULT NULL COLLATE BINARY --(DC2Type:x) + null, + 'bb', + 'CREATE TABLE "a" (a TEXT COLLATE RTRIM, "b" CLOB DEFAULT NULL COLLATE BINARY --(DC2Type:x) , "bb" TEXT DEFAULT "a" COLLATE RTRIM', ], 'Multiple similar columns on different lines, with type comment 2' => [ - '(DC2Type:x)', 'bb', 'CREATE TABLE "a" (a TEXT COLLATE RTRIM, "bb" CLOB DEFAULT NULL COLLATE BINARY --(DC2Type:x) + '(DC2Type:x)', + 'bb', + 'CREATE TABLE "a" (a TEXT COLLATE RTRIM, "bb" CLOB DEFAULT NULL COLLATE BINARY --(DC2Type:x) , "b" TEXT DEFAULT "a" COLLATE RTRIM', ], 'Column with numeric but no comment 1' => [ - null, 'a', 'CREATE TABLE "a" ("a" NUMERIC(10, 0) NOT NULL, "b" CLOB NOT NULL --(DC2Type:array) + null, + 'a', + 'CREATE TABLE "a" ("a" NUMERIC(10, 0) NOT NULL, "b" CLOB NOT NULL --(DC2Type:array) , "c" CHAR(36) NOT NULL --(DC2Type:guid) )', ], 'Column with numeric but no comment 2' => [ - null, 'a', 'CREATE TABLE "b" ("a" NUMERIC(10, 0) NOT NULL, "b" CLOB NOT NULL --(DC2Type:array) + null, + 'a', + 'CREATE TABLE "b" ("a" NUMERIC(10, 0) NOT NULL, "b" CLOB NOT NULL --(DC2Type:array) , "c" CHAR(36) NOT NULL --(DC2Type:guid) )', ], 'Column with numeric but no comment 3' => [ - '(DC2Type:guid)', 'c', 'CREATE TABLE "b" ("a" NUMERIC(10, 0) NOT NULL, "b" CLOB NOT NULL --(DC2Type:array) + '(DC2Type:guid)', + 'c', + 'CREATE TABLE "b" ("a" NUMERIC(10, 0) NOT NULL, "b" CLOB NOT NULL --(DC2Type:array) , "c" CHAR(36) NOT NULL --(DC2Type:guid) )', ], diff --git a/tests/Doctrine/Tests/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php b/tests/Doctrine/Tests/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php index 0071d217280..442c283ef59 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php @@ -22,70 +22,70 @@ use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Synchronizer\SingleDatabaseSynchronizer; +use PHPUnit\Framework\TestCase; /** * @requires extension pdo_sqlite */ -class SingleDatabaseSynchronizerTest extends \PHPUnit\Framework\TestCase +class SingleDatabaseSynchronizerTest extends TestCase { private $conn; private $synchronizer; protected function setUp() { - $this->conn = DriverManager::getConnection(array( + $this->conn = DriverManager::getConnection([ 'driver' => 'pdo_sqlite', 'memory' => true, - )); + ]); $this->synchronizer = new SingleDatabaseSynchronizer($this->conn); } public function testGetCreateSchema() { $schema = new Schema(); - $table = $schema->createTable('test'); + $table = $schema->createTable('test'); $table->addColumn('id', 'integer'); - $table->setPrimaryKey(array('id')); + $table->setPrimaryKey(['id']); $sql = $this->synchronizer->getCreateSchema($schema); - self::assertEquals(array('CREATE TABLE test (id INTEGER NOT NULL, PRIMARY KEY(id))'), $sql); + self::assertEquals(['CREATE TABLE test (id INTEGER NOT NULL, PRIMARY KEY(id))'], $sql); } public function testGetUpdateSchema() { $schema = new Schema(); - $table = $schema->createTable('test'); + $table = $schema->createTable('test'); $table->addColumn('id', 'integer'); - $table->setPrimaryKey(array('id')); + $table->setPrimaryKey(['id']); $sql = $this->synchronizer->getUpdateSchema($schema); - self::assertEquals(array('CREATE TABLE test (id INTEGER NOT NULL, PRIMARY KEY(id))'), $sql); + self::assertEquals(['CREATE TABLE test (id INTEGER NOT NULL, PRIMARY KEY(id))'], $sql); } public function testGetDropSchema() { $schema = new Schema(); - $table = $schema->createTable('test'); + $table = $schema->createTable('test'); $table->addColumn('id', 'integer'); - $table->setPrimaryKey(array('id')); + $table->setPrimaryKey(['id']); $this->synchronizer->createSchema($schema); $sql = $this->synchronizer->getDropSchema($schema); - self::assertEquals(array('DROP TABLE test'), $sql); + self::assertEquals(['DROP TABLE test'], $sql); } public function testGetDropAllSchema() { $schema = new Schema(); - $table = $schema->createTable('test'); + $table = $schema->createTable('test'); $table->addColumn('id', 'integer'); - $table->setPrimaryKey(array('id')); + $table->setPrimaryKey(['id']); $this->synchronizer->createSchema($schema); $sql = $this->synchronizer->getDropAllSchema(); - self::assertEquals(array('DROP TABLE test'), $sql); + self::assertEquals(['DROP TABLE test'], $sql); } } - diff --git a/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php b/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php index f78d9519a12..097c9e2f1e1 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php @@ -5,8 +5,9 @@ use Doctrine\DBAL\Schema\Identifier; use Doctrine\DBAL\Schema\TableDiff; use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use PHPUnit\Framework\TestCase; -class TableDiffTest extends \PHPUnit\Framework\TestCase +class TableDiffTest extends TestCase { /** * @group DBAL-1013 @@ -24,11 +25,11 @@ public function testReturnsName() public function testPrefersNameFromTableObject() { $platformMock = new MockPlatform(); - $tableMock = $this->getMockBuilder('Doctrine\DBAL\Schema\Table') + $tableMock = $this->getMockBuilder('Doctrine\DBAL\Schema\Table') ->disableOriginalConstructor() ->getMock(); - $tableDiff = new TableDiff('foo'); + $tableDiff = new TableDiff('foo'); $tableDiff->fromTable = $tableMock; $tableMock->expects($this->once()) diff --git a/tests/Doctrine/Tests/DBAL/Schema/TableTest.php b/tests/Doctrine/Tests/DBAL/Schema/TableTest.php index 9c4dee07eed..09cc4662f48 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/TableTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/TableTest.php @@ -3,50 +3,53 @@ namespace Doctrine\Tests\DBAL\Schema; use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Platforms\MySqlPlatform; +use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Type; +use Doctrine\Tests\DbalTestCase; use function array_shift; use function current; -class TableTest extends \Doctrine\Tests\DbalTestCase +class TableTest extends DbalTestCase { public function testCreateWithInvalidTableName() { $this->expectException(DBALException::class); - new \Doctrine\DBAL\Schema\Table(''); + new Table(''); } public function testGetName() { - $table = new Table("foo", array(), array(), array()); - self::assertEquals("foo", $table->getName()); + $table = new Table('foo', [], [], []); + self::assertEquals('foo', $table->getName()); } public function testColumns() { - $type = Type::getType('integer'); - $columns = array(); - $columns[] = new Column("foo", $type); - $columns[] = new Column("bar", $type); - $table = new Table("foo", $columns, array(), array()); + $type = Type::getType('integer'); + $columns = []; + $columns[] = new Column('foo', $type); + $columns[] = new Column('bar', $type); + $table = new Table('foo', $columns, [], []); - self::assertTrue($table->hasColumn("foo")); - self::assertTrue($table->hasColumn("bar")); - self::assertFalse($table->hasColumn("baz")); + self::assertTrue($table->hasColumn('foo')); + self::assertTrue($table->hasColumn('bar')); + self::assertFalse($table->hasColumn('baz')); - self::assertInstanceOf('Doctrine\DBAL\Schema\Column', $table->getColumn("foo")); - self::assertInstanceOf('Doctrine\DBAL\Schema\Column', $table->getColumn("bar")); + self::assertInstanceOf('Doctrine\DBAL\Schema\Column', $table->getColumn('foo')); + self::assertInstanceOf('Doctrine\DBAL\Schema\Column', $table->getColumn('bar')); self::assertCount(2, $table->getColumns()); } public function testColumnsCaseInsensitive() { - $table = new Table("foo"); + $table = new Table('foo'); $column = $table->addColumn('Foo', 'integer'); self::assertTrue($table->hasColumn('Foo')); @@ -62,74 +65,74 @@ public function testCreateColumn() { $type = Type::getType('integer'); - $table = new Table("foo"); + $table = new Table('foo'); - self::assertFalse($table->hasColumn("bar")); - $table->addColumn("bar", 'integer'); - self::assertTrue($table->hasColumn("bar")); - self::assertSame($type, $table->getColumn("bar")->getType()); + self::assertFalse($table->hasColumn('bar')); + $table->addColumn('bar', 'integer'); + self::assertTrue($table->hasColumn('bar')); + self::assertSame($type, $table->getColumn('bar')->getType()); } public function testDropColumn() { - $type = Type::getType('integer'); - $columns = array(); - $columns[] = new Column("foo", $type); - $columns[] = new Column("bar", $type); - $table = new Table("foo", $columns, array(), array()); + $type = Type::getType('integer'); + $columns = []; + $columns[] = new Column('foo', $type); + $columns[] = new Column('bar', $type); + $table = new Table('foo', $columns, [], []); - self::assertTrue($table->hasColumn("foo")); - self::assertTrue($table->hasColumn("bar")); + self::assertTrue($table->hasColumn('foo')); + self::assertTrue($table->hasColumn('bar')); - $table->dropColumn("foo")->dropColumn("bar"); + $table->dropColumn('foo')->dropColumn('bar'); - self::assertFalse($table->hasColumn("foo")); - self::assertFalse($table->hasColumn("bar")); + self::assertFalse($table->hasColumn('foo')); + self::assertFalse($table->hasColumn('bar')); } public function testGetUnknownColumnThrowsException() { - $this->expectException("Doctrine\DBAL\Schema\SchemaException"); + $this->expectException('Doctrine\DBAL\Schema\SchemaException'); - $table = new Table("foo", array(), array(), array()); + $table = new Table('foo', [], [], []); $table->getColumn('unknown'); } public function testAddColumnTwiceThrowsException() { - $this->expectException("Doctrine\DBAL\Schema\SchemaException"); + $this->expectException('Doctrine\DBAL\Schema\SchemaException'); - $type = \Doctrine\DBAL\Types\Type::getType('integer'); - $columns = array(); - $columns[] = new Column("foo", $type); - $columns[] = new Column("foo", $type); - $table = new Table("foo", $columns, array(), array()); + $type = Type::getType('integer'); + $columns = []; + $columns[] = new Column('foo', $type); + $columns[] = new Column('foo', $type); + $table = new Table('foo', $columns, [], []); } public function testCreateIndex() { - $type = \Doctrine\DBAL\Types\Type::getType('integer'); - $columns = array(new Column("foo", $type), new Column("bar", $type), new Column("baz", $type)); - $table = new Table("foo", $columns); + $type = Type::getType('integer'); + $columns = [new Column('foo', $type), new Column('bar', $type), new Column('baz', $type)]; + $table = new Table('foo', $columns); - $table->addIndex(array("foo", "bar"), "foo_foo_bar_idx"); - $table->addUniqueIndex(array("bar", "baz"), "foo_bar_baz_uniq"); + $table->addIndex(['foo', 'bar'], 'foo_foo_bar_idx'); + $table->addUniqueIndex(['bar', 'baz'], 'foo_bar_baz_uniq'); - self::assertTrue($table->hasIndex("foo_foo_bar_idx")); - self::assertTrue($table->hasIndex("foo_bar_baz_uniq")); + self::assertTrue($table->hasIndex('foo_foo_bar_idx')); + self::assertTrue($table->hasIndex('foo_bar_baz_uniq')); } public function testIndexCaseInsensitive() { - $type = \Doctrine\DBAL\Types\Type::getType('integer'); - $columns = array( - new Column("foo", $type), - new Column("bar", $type), - new Column("baz", $type) - ); - $table = new Table("foo", $columns); + $type = Type::getType('integer'); + $columns = [ + new Column('foo', $type), + new Column('bar', $type), + new Column('baz', $type), + ]; + $table = new Table('foo', $columns); - $table->addIndex(array("foo", "bar", "baz"), "Foo_Idx"); + $table->addIndex(['foo', 'bar', 'baz'], 'Foo_Idx'); self::assertTrue($table->hasIndex('foo_idx')); self::assertTrue($table->hasIndex('Foo_Idx')); @@ -138,20 +141,20 @@ public function testIndexCaseInsensitive() public function testAddIndexes() { - $type = \Doctrine\DBAL\Types\Type::getType('integer'); - $columns = array( - new Column("foo", $type), - new Column("bar", $type), - ); - $indexes = array( - new Index("the_primary", array("foo"), true, true), - new Index("bar_idx", array("bar"), false, false), - ); - $table = new Table("foo", $columns, $indexes, array()); - - self::assertTrue($table->hasIndex("the_primary")); - self::assertTrue($table->hasIndex("bar_idx")); - self::assertFalse($table->hasIndex("some_idx")); + $type = Type::getType('integer'); + $columns = [ + new Column('foo', $type), + new Column('bar', $type), + ]; + $indexes = [ + new Index('the_primary', ['foo'], true, true), + new Index('bar_idx', ['bar'], false, false), + ]; + $table = new Table('foo', $columns, $indexes, []); + + self::assertTrue($table->hasIndex('the_primary')); + self::assertTrue($table->hasIndex('bar_idx')); + self::assertFalse($table->hasIndex('some_idx')); self::assertInstanceOf('Doctrine\DBAL\Schema\Index', $table->getPrimaryKey()); self::assertInstanceOf('Doctrine\DBAL\Schema\Index', $table->getIndex('the_primary')); @@ -160,43 +163,43 @@ public function testAddIndexes() public function testGetUnknownIndexThrowsException() { - $this->expectException("Doctrine\DBAL\Schema\SchemaException"); + $this->expectException('Doctrine\DBAL\Schema\SchemaException'); - $table = new Table("foo", array(), array(), array()); - $table->getIndex("unknownIndex"); + $table = new Table('foo', [], [], []); + $table->getIndex('unknownIndex'); } public function testAddTwoPrimaryThrowsException() { - $this->expectException("Doctrine\DBAL\Schema\SchemaException"); + $this->expectException('Doctrine\DBAL\Schema\SchemaException'); - $type = \Doctrine\DBAL\Types\Type::getType('integer'); - $columns = array(new Column("foo", $type), new Column("bar", $type)); - $indexes = array( - new Index("the_primary", array("foo"), true, true), - new Index("other_primary", array("bar"), true, true), - ); - $table = new Table("foo", $columns, $indexes, array()); + $type = Type::getType('integer'); + $columns = [new Column('foo', $type), new Column('bar', $type)]; + $indexes = [ + new Index('the_primary', ['foo'], true, true), + new Index('other_primary', ['bar'], true, true), + ]; + $table = new Table('foo', $columns, $indexes, []); } public function testAddTwoIndexesWithSameNameThrowsException() { - $this->expectException("Doctrine\DBAL\Schema\SchemaException"); + $this->expectException('Doctrine\DBAL\Schema\SchemaException'); - $type = \Doctrine\DBAL\Types\Type::getType('integer'); - $columns = array(new Column("foo", $type), new Column("bar", $type)); - $indexes = array( - new Index("an_idx", array("foo"), false, false), - new Index("an_idx", array("bar"), false, false), - ); - $table = new Table("foo", $columns, $indexes, array()); + $type = Type::getType('integer'); + $columns = [new Column('foo', $type), new Column('bar', $type)]; + $indexes = [ + new Index('an_idx', ['foo'], false, false), + new Index('an_idx', ['bar'], false, false), + ]; + $table = new Table('foo', $columns, $indexes, []); } public function testConstraints() { - $constraint = new ForeignKeyConstraint(array(), "foo", array()); + $constraint = new ForeignKeyConstraint([], 'foo', []); - $tableA = new Table("foo", array(), array(), array($constraint)); + $tableA = new Table('foo', [], [], [$constraint]); $constraints = $tableA->getForeignKeys(); self::assertCount(1, $constraints); @@ -205,109 +208,109 @@ public function testConstraints() public function testOptions() { - $table = new Table("foo", array(), array(), array(), false, array("foo" => "bar")); + $table = new Table('foo', [], [], [], false, ['foo' => 'bar']); - self::assertTrue($table->hasOption("foo")); - self::assertEquals("bar", $table->getOption("foo")); + self::assertTrue($table->hasOption('foo')); + self::assertEquals('bar', $table->getOption('foo')); } public function testBuilderSetPrimaryKey() { - $table = new Table("foo"); + $table = new Table('foo'); - $table->addColumn("bar", 'integer'); - $table->setPrimaryKey(array("bar")); + $table->addColumn('bar', 'integer'); + $table->setPrimaryKey(['bar']); - self::assertTrue($table->hasIndex("primary")); + self::assertTrue($table->hasIndex('primary')); self::assertInstanceOf('Doctrine\DBAL\Schema\Index', $table->getPrimaryKey()); - self::assertTrue($table->getIndex("primary")->isUnique()); - self::assertTrue($table->getIndex("primary")->isPrimary()); + self::assertTrue($table->getIndex('primary')->isUnique()); + self::assertTrue($table->getIndex('primary')->isPrimary()); } public function testBuilderAddUniqueIndex() { - $table = new Table("foo"); + $table = new Table('foo'); - $table->addColumn("bar", 'integer'); - $table->addUniqueIndex(array("bar"), "my_idx"); + $table->addColumn('bar', 'integer'); + $table->addUniqueIndex(['bar'], 'my_idx'); - self::assertTrue($table->hasIndex("my_idx")); - self::assertTrue($table->getIndex("my_idx")->isUnique()); - self::assertFalse($table->getIndex("my_idx")->isPrimary()); + self::assertTrue($table->hasIndex('my_idx')); + self::assertTrue($table->getIndex('my_idx')->isUnique()); + self::assertFalse($table->getIndex('my_idx')->isPrimary()); } public function testBuilderAddIndex() { - $table = new Table("foo"); + $table = new Table('foo'); - $table->addColumn("bar", 'integer'); - $table->addIndex(array("bar"), "my_idx"); + $table->addColumn('bar', 'integer'); + $table->addIndex(['bar'], 'my_idx'); - self::assertTrue($table->hasIndex("my_idx")); - self::assertFalse($table->getIndex("my_idx")->isUnique()); - self::assertFalse($table->getIndex("my_idx")->isPrimary()); + self::assertTrue($table->hasIndex('my_idx')); + self::assertFalse($table->getIndex('my_idx')->isUnique()); + self::assertFalse($table->getIndex('my_idx')->isPrimary()); } public function testBuilderAddIndexWithInvalidNameThrowsException() { - $this->expectException("Doctrine\DBAL\Schema\SchemaException"); + $this->expectException('Doctrine\DBAL\Schema\SchemaException'); - $table = new Table("foo"); - $table->addColumn("bar",'integer'); - $table->addIndex(array("bar"), "invalid name %&/"); + $table = new Table('foo'); + $table->addColumn('bar', 'integer'); + $table->addIndex(['bar'], 'invalid name %&/'); } public function testBuilderAddIndexWithUnknownColumnThrowsException() { - $this->expectException("Doctrine\DBAL\Schema\SchemaException"); + $this->expectException('Doctrine\DBAL\Schema\SchemaException'); - $table = new Table("foo"); - $table->addIndex(array("bar"), "invalidName"); + $table = new Table('foo'); + $table->addIndex(['bar'], 'invalidName'); } public function testBuilderOptions() { - $table = new Table("foo"); - $table->addOption("foo", "bar"); - self::assertTrue($table->hasOption("foo")); - self::assertEquals("bar", $table->getOption("foo")); + $table = new Table('foo'); + $table->addOption('foo', 'bar'); + self::assertTrue($table->hasOption('foo')); + self::assertEquals('bar', $table->getOption('foo')); } public function testAddForeignKeyConstraint_UnknownLocalColumn_ThrowsException() { - $this->expectException("Doctrine\DBAL\Schema\SchemaException"); + $this->expectException('Doctrine\DBAL\Schema\SchemaException'); - $table = new Table("foo"); - $table->addColumn("id", 'integer'); + $table = new Table('foo'); + $table->addColumn('id', 'integer'); - $foreignTable = new Table("bar"); - $foreignTable->addColumn("id", 'integer'); + $foreignTable = new Table('bar'); + $foreignTable->addColumn('id', 'integer'); - $table->addForeignKeyConstraint($foreignTable, array("foo"), array("id")); + $table->addForeignKeyConstraint($foreignTable, ['foo'], ['id']); } public function testAddForeignKeyConstraint_UnknownForeignColumn_ThrowsException() { - $this->expectException("Doctrine\DBAL\Schema\SchemaException"); + $this->expectException('Doctrine\DBAL\Schema\SchemaException'); - $table = new Table("foo"); - $table->addColumn("id", 'integer'); + $table = new Table('foo'); + $table->addColumn('id', 'integer'); - $foreignTable = new Table("bar"); - $foreignTable->addColumn("id", 'integer'); + $foreignTable = new Table('bar'); + $foreignTable->addColumn('id', 'integer'); - $table->addForeignKeyConstraint($foreignTable, array("id"), array("foo")); + $table->addForeignKeyConstraint($foreignTable, ['id'], ['foo']); } public function testAddForeignKeyConstraint() { - $table = new Table("foo"); - $table->addColumn("id", 'integer'); + $table = new Table('foo'); + $table->addColumn('id', 'integer'); - $foreignTable = new Table("bar"); - $foreignTable->addColumn("id", 'integer'); + $foreignTable = new Table('bar'); + $foreignTable->addColumn('id', 'integer'); - $table->addForeignKeyConstraint($foreignTable, array("id"), array("id"), array("foo" => "bar")); + $table->addForeignKeyConstraint($foreignTable, ['id'], ['id'], ['foo' => 'bar']); $constraints = $table->getForeignKeys(); self::assertCount(1, $constraints); @@ -315,30 +318,30 @@ public function testAddForeignKeyConstraint() self::assertInstanceOf('Doctrine\DBAL\Schema\ForeignKeyConstraint', $constraint); - self::assertTrue($constraint->hasOption("foo")); - self::assertEquals("bar", $constraint->getOption("foo")); + self::assertTrue($constraint->hasOption('foo')); + self::assertEquals('bar', $constraint->getOption('foo')); } public function testAddIndexWithCaseSensitiveColumnProblem() { - $table = new Table("foo"); - $table->addColumn("id", 'integer'); + $table = new Table('foo'); + $table->addColumn('id', 'integer'); - $table->addIndex(array("ID"), "my_idx"); + $table->addIndex(['ID'], 'my_idx'); self::assertTrue($table->hasIndex('my_idx')); - self::assertEquals(array("ID"), $table->getIndex("my_idx")->getColumns()); - self::assertTrue($table->getIndex('my_idx')->spansColumns(array('id'))); + self::assertEquals(['ID'], $table->getIndex('my_idx')->getColumns()); + self::assertTrue($table->getIndex('my_idx')->spansColumns(['id'])); } public function testAddPrimaryKey_ColumnsAreExplicitlySetToNotNull() { - $table = new Table("foo"); - $column = $table->addColumn("id", 'integer', array('notnull' => false)); + $table = new Table('foo'); + $column = $table->addColumn('id', 'integer', ['notnull' => false]); self::assertFalse($column->getNotnull()); - $table->setPrimaryKey(array('id')); + $table->setPrimaryKey(['id']); self::assertTrue($column->getNotnull()); } @@ -348,9 +351,9 @@ public function testAddPrimaryKey_ColumnsAreExplicitlySetToNotNull() */ public function testAllowImplicitSchemaTableInAutogeneratedIndexNames() { - $table = new Table("foo.bar"); - $table->addColumn('baz', 'integer', array()); - $table->addIndex(array('baz')); + $table = new Table('foo.bar'); + $table->addColumn('baz', 'integer', []); + $table->addIndex(['baz']); self::assertCount(1, $table->getIndexes()); } @@ -360,20 +363,20 @@ public function testAllowImplicitSchemaTableInAutogeneratedIndexNames() */ public function testAddForeignKeyIndexImplicitly() { - $table = new Table("foo"); - $table->addColumn("id", 'integer'); + $table = new Table('foo'); + $table->addColumn('id', 'integer'); - $foreignTable = new Table("bar"); - $foreignTable->addColumn("id", 'integer'); + $foreignTable = new Table('bar'); + $foreignTable->addColumn('id', 'integer'); - $table->addForeignKeyConstraint($foreignTable, array("id"), array("id"), array("foo" => "bar")); + $table->addForeignKeyConstraint($foreignTable, ['id'], ['id'], ['foo' => 'bar']); $indexes = $table->getIndexes(); self::assertCount(1, $indexes); $index = current($indexes); self::assertTrue($table->hasIndex($index->getName())); - self::assertEquals(array('id'), $index->getColumns()); + self::assertEquals(['id'], $index->getColumns()); } /** @@ -383,16 +386,16 @@ public function testAddForeignKeyDoesNotCreateDuplicateIndex() { $table = new Table('foo'); $table->addColumn('bar', 'integer'); - $table->addIndex(array('bar'), 'bar_idx'); + $table->addIndex(['bar'], 'bar_idx'); $foreignTable = new Table('bar'); $foreignTable->addColumn('foo', 'integer'); - $table->addForeignKeyConstraint($foreignTable, array('bar'), array('foo')); + $table->addForeignKeyConstraint($foreignTable, ['bar'], ['foo']); self::assertCount(1, $table->getIndexes()); self::assertTrue($table->hasIndex('bar_idx')); - self::assertSame(array('bar'), $table->getIndex('bar_idx')->getColumns()); + self::assertSame(['bar'], $table->getIndex('bar_idx')->getColumns()); } /** @@ -404,22 +407,22 @@ public function testAddForeignKeyAddsImplicitIndexIfIndexColumnsDoNotSpan() $table->addColumn('bar', 'integer'); $table->addColumn('baz', 'string'); $table->addColumn('bloo', 'string'); - $table->addIndex(array('baz', 'bar'), 'composite_idx'); - $table->addIndex(array('bar', 'baz', 'bloo'), 'full_idx'); + $table->addIndex(['baz', 'bar'], 'composite_idx'); + $table->addIndex(['bar', 'baz', 'bloo'], 'full_idx'); $foreignTable = new Table('bar'); $foreignTable->addColumn('foo', 'integer'); $foreignTable->addColumn('baz', 'string'); - $table->addForeignKeyConstraint($foreignTable, array('bar', 'baz'), array('foo', 'baz')); + $table->addForeignKeyConstraint($foreignTable, ['bar', 'baz'], ['foo', 'baz']); self::assertCount(3, $table->getIndexes()); self::assertTrue($table->hasIndex('composite_idx')); self::assertTrue($table->hasIndex('full_idx')); self::assertTrue($table->hasIndex('idx_8c73652176ff8caa78240498')); - self::assertSame(array('baz', 'bar'), $table->getIndex('composite_idx')->getColumns()); - self::assertSame(array('bar', 'baz', 'bloo'), $table->getIndex('full_idx')->getColumns()); - self::assertSame(array('bar', 'baz'), $table->getIndex('idx_8c73652176ff8caa78240498')->getColumns()); + self::assertSame(['baz', 'bar'], $table->getIndex('composite_idx')->getColumns()); + self::assertSame(['bar', 'baz', 'bloo'], $table->getIndex('full_idx')->getColumns()); + self::assertSame(['bar', 'baz'], $table->getIndex('idx_8c73652176ff8caa78240498')->getColumns()); } /** @@ -428,15 +431,15 @@ public function testAddForeignKeyAddsImplicitIndexIfIndexColumnsDoNotSpan() */ public function testOverrulingIndexDoesNotDropOverruledIndex() { - $table = new Table("bar"); - $table->addColumn('baz', 'integer', array()); - $table->addIndex(array('baz')); + $table = new Table('bar'); + $table->addColumn('baz', 'integer', []); + $table->addIndex(['baz']); $indexes = $table->getIndexes(); self::assertCount(1, $indexes); $index = current($indexes); - $table->addUniqueIndex(array('baz')); + $table->addUniqueIndex(['baz']); self::assertCount(2, $table->getIndexes()); self::assertTrue($table->hasIndex($index->getName())); } @@ -448,14 +451,14 @@ public function testAllowsAddingDuplicateIndexesBasedOnColumns() { $table = new Table('foo'); $table->addColumn('bar', 'integer'); - $table->addIndex(array('bar'), 'bar_idx'); - $table->addIndex(array('bar'), 'duplicate_idx'); + $table->addIndex(['bar'], 'bar_idx'); + $table->addIndex(['bar'], 'duplicate_idx'); self::assertCount(2, $table->getIndexes()); self::assertTrue($table->hasIndex('bar_idx')); self::assertTrue($table->hasIndex('duplicate_idx')); - self::assertSame(array('bar'), $table->getIndex('bar_idx')->getColumns()); - self::assertSame(array('bar'), $table->getIndex('duplicate_idx')->getColumns()); + self::assertSame(['bar'], $table->getIndex('bar_idx')->getColumns()); + self::assertSame(['bar'], $table->getIndex('duplicate_idx')->getColumns()); } /** @@ -466,14 +469,14 @@ public function testAllowsAddingFulfillingIndexesBasedOnColumns() $table = new Table('foo'); $table->addColumn('bar', 'integer'); $table->addColumn('baz', 'string'); - $table->addIndex(array('bar'), 'bar_idx'); - $table->addIndex(array('bar', 'baz'), 'fulfilling_idx'); + $table->addIndex(['bar'], 'bar_idx'); + $table->addIndex(['bar', 'baz'], 'fulfilling_idx'); self::assertCount(2, $table->getIndexes()); self::assertTrue($table->hasIndex('bar_idx')); self::assertTrue($table->hasIndex('fulfilling_idx')); - self::assertSame(array('bar'), $table->getIndex('bar_idx')->getColumns()); - self::assertSame(array('bar', 'baz'), $table->getIndex('fulfilling_idx')->getColumns()); + self::assertSame(['bar'], $table->getIndex('bar_idx')->getColumns()); + self::assertSame(['bar', 'baz'], $table->getIndex('fulfilling_idx')->getColumns()); } /** @@ -482,14 +485,14 @@ public function testAllowsAddingFulfillingIndexesBasedOnColumns() */ public function testPrimaryKeyOverrulingUniqueIndexDoesNotDropUniqueIndex() { - $table = new Table("bar"); - $table->addColumn('baz', 'integer', array()); - $table->addUniqueIndex(array('baz'), 'idx_unique'); + $table = new Table('bar'); + $table->addColumn('baz', 'integer', []); + $table->addUniqueIndex(['baz'], 'idx_unique'); - $table->setPrimaryKey(array('baz')); + $table->setPrimaryKey(['baz']); $indexes = $table->getIndexes(); - self::assertCount(2, $indexes, "Table should only contain both the primary key table index and the unique one, even though it was overruled."); + self::assertCount(2, $indexes, 'Table should only contain both the primary key table index and the unique one, even though it was overruled.'); self::assertTrue($table->hasPrimaryKey()); self::assertTrue($table->hasIndex('idx_unique')); @@ -502,11 +505,11 @@ public function testAddingFulfillingRegularIndexOverridesImplicitForeignKeyConst $localTable = new Table('local'); $localTable->addColumn('id', 'integer'); - $localTable->addForeignKeyConstraint($foreignTable, array('id'), array('id')); + $localTable->addForeignKeyConstraint($foreignTable, ['id'], ['id']); self::assertCount(1, $localTable->getIndexes()); - $localTable->addIndex(array('id'), 'explicit_idx'); + $localTable->addIndex(['id'], 'explicit_idx'); self::assertCount(1, $localTable->getIndexes()); self::assertTrue($localTable->hasIndex('explicit_idx')); @@ -519,11 +522,11 @@ public function testAddingFulfillingUniqueIndexOverridesImplicitForeignKeyConstr $localTable = new Table('local'); $localTable->addColumn('id', 'integer'); - $localTable->addForeignKeyConstraint($foreignTable, array('id'), array('id')); + $localTable->addForeignKeyConstraint($foreignTable, ['id'], ['id']); self::assertCount(1, $localTable->getIndexes()); - $localTable->addUniqueIndex(array('id'), 'explicit_idx'); + $localTable->addUniqueIndex(['id'], 'explicit_idx'); self::assertCount(1, $localTable->getIndexes()); self::assertTrue($localTable->hasIndex('explicit_idx')); @@ -536,11 +539,11 @@ public function testAddingFulfillingPrimaryKeyOverridesImplicitForeignKeyConstra $localTable = new Table('local'); $localTable->addColumn('id', 'integer'); - $localTable->addForeignKeyConstraint($foreignTable, array('id'), array('id')); + $localTable->addForeignKeyConstraint($foreignTable, ['id'], ['id']); self::assertCount(1, $localTable->getIndexes()); - $localTable->setPrimaryKey(array('id'), 'explicit_idx'); + $localTable->setPrimaryKey(['id'], 'explicit_idx'); self::assertCount(1, $localTable->getIndexes()); self::assertTrue($localTable->hasIndex('explicit_idx')); @@ -553,14 +556,14 @@ public function testAddingFulfillingExplicitIndexOverridingImplicitForeignKeyCon $localTable = new Table('local'); $localTable->addColumn('id', 'integer'); - $localTable->addForeignKeyConstraint($foreignTable, array('id'), array('id')); + $localTable->addForeignKeyConstraint($foreignTable, ['id'], ['id']); self::assertCount(1, $localTable->getIndexes()); self::assertTrue($localTable->hasIndex('IDX_8BD688E8BF396750')); $implicitIndex = $localTable->getIndex('IDX_8BD688E8BF396750'); - $localTable->addIndex(array('id'), 'IDX_8BD688E8BF396750'); + $localTable->addIndex(['id'], 'IDX_8BD688E8BF396750'); self::assertCount(1, $localTable->getIndexes()); self::assertTrue($localTable->hasIndex('IDX_8BD688E8BF396750')); @@ -572,10 +575,10 @@ public function testAddingFulfillingExplicitIndexOverridingImplicitForeignKeyCon */ public function testQuotedTableName() { - $table = new Table("`bar`"); + $table = new Table('`bar`'); - $mysqlPlatform = new \Doctrine\DBAL\Platforms\MySqlPlatform(); - $sqlitePlatform = new \Doctrine\DBAL\Platforms\SqlitePlatform(); + $mysqlPlatform = new MySqlPlatform(); + $sqlitePlatform = new SqlitePlatform(); self::assertEquals('bar', $table->getName()); self::assertEquals('`bar`', $table->getQuotedName($mysqlPlatform)); @@ -587,12 +590,12 @@ public function testQuotedTableName() */ public function testTableHasPrimaryKey() { - $table = new Table("test"); + $table = new Table('test'); self::assertFalse($table->hasPrimaryKey()); - $table->addColumn("foo", "integer"); - $table->setPrimaryKey(array("foo")); + $table->addColumn('foo', 'integer'); + $table->setPrimaryKey(['foo']); self::assertTrue($table->hasPrimaryKey()); } @@ -602,7 +605,7 @@ public function testTableHasPrimaryKey() */ public function testAddIndexWithQuotedColumns() { - $table = new Table("test"); + $table = new Table('test'); $table->addColumn('"foo"', 'integer'); $table->addColumn('bar', 'integer'); $table->addIndex(['"foo"', '"bar"']); @@ -615,10 +618,10 @@ public function testAddIndexWithQuotedColumns() */ public function testAddForeignKeyWithQuotedColumnsAndTable() { - $table = new Table("test"); + $table = new Table('test'); $table->addColumn('"foo"', 'integer'); $table->addColumn('bar', 'integer'); - $table->addForeignKeyConstraint('"boing"', ['"foo"', '"bar"'], ["id"]); + $table->addForeignKeyConstraint('"boing"', ['"foo"', '"bar"'], ['id']); self::assertCount(1, $table->getForeignKeys()); } @@ -628,9 +631,9 @@ public function testAddForeignKeyWithQuotedColumnsAndTable() */ public function testQuoteSchemaPrefixed() { - $table = new Table("`test`.`test`"); - self::assertEquals("test.test", $table->getName()); - self::assertEquals("`test`.`test`", $table->getQuotedName(new \Doctrine\DBAL\Platforms\MySqlPlatform)); + $table = new Table('`test`.`test`'); + self::assertEquals('test.test', $table->getName()); + self::assertEquals('`test`.`test`', $table->getQuotedName(new MySqlPlatform())); } /** @@ -638,13 +641,13 @@ public function testQuoteSchemaPrefixed() */ public function testFullQualifiedTableName() { - $table = new Table("`test`.`test`"); - self::assertEquals('test.test', $table->getFullQualifiedName("test")); - self::assertEquals('test.test', $table->getFullQualifiedName("other")); + $table = new Table('`test`.`test`'); + self::assertEquals('test.test', $table->getFullQualifiedName('test')); + self::assertEquals('test.test', $table->getFullQualifiedName('other')); - $table = new Table("test"); - self::assertEquals('test.test', $table->getFullQualifiedName("test")); - self::assertEquals('other.test', $table->getFullQualifiedName("other")); + $table = new Table('test'); + self::assertEquals('test.test', $table->getFullQualifiedName('test')); + self::assertEquals('other.test', $table->getFullQualifiedName('other')); } /** @@ -652,9 +655,9 @@ public function testFullQualifiedTableName() */ public function testDropIndex() { - $table = new Table("test"); + $table = new Table('test'); $table->addColumn('id', 'integer'); - $table->addIndex(array('id'), 'idx'); + $table->addIndex(['id'], 'idx'); self::assertTrue($table->hasIndex('idx')); @@ -667,9 +670,9 @@ public function testDropIndex() */ public function testDropPrimaryKey() { - $table = new Table("test"); + $table = new Table('test'); $table->addColumn('id', 'integer'); - $table->setPrimaryKey(array('id')); + $table->setPrimaryKey(['id']); self::assertTrue($table->hasPrimaryKey()); @@ -682,14 +685,14 @@ public function testDropPrimaryKey() */ public function testRenameIndex() { - $table = new Table("test"); + $table = new Table('test'); $table->addColumn('id', 'integer'); $table->addColumn('foo', 'integer'); $table->addColumn('bar', 'integer'); $table->addColumn('baz', 'integer'); - $table->setPrimaryKey(array('id'), 'pk'); - $table->addIndex(array('foo'), 'idx', array('flag')); - $table->addUniqueIndex(array('bar', 'baz'), 'uniq'); + $table->setPrimaryKey(['id'], 'pk'); + $table->addIndex(['foo'], 'idx', ['flag']); + $table->addUniqueIndex(['bar', 'baz'], 'uniq'); // Rename to custom name. self::assertSame($table, $table->renameIndex('pk', 'pk_new')); @@ -705,13 +708,13 @@ public function testRenameIndex() self::assertFalse($table->hasIndex('idx')); self::assertFalse($table->hasIndex('uniq')); - self::assertEquals(new Index('pk_new', array('id'), true, true), $table->getPrimaryKey()); - self::assertEquals(new Index('pk_new', array('id'), true, true), $table->getIndex('pk_new')); + self::assertEquals(new Index('pk_new', ['id'], true, true), $table->getPrimaryKey()); + self::assertEquals(new Index('pk_new', ['id'], true, true), $table->getIndex('pk_new')); self::assertEquals( - new Index('idx_new', array('foo'), false, false, array('flag')), + new Index('idx_new', ['foo'], false, false, ['flag']), $table->getIndex('idx_new') ); - self::assertEquals(new Index('uniq_new', array('bar', 'baz'), true), $table->getIndex('uniq_new')); + self::assertEquals(new Index('uniq_new', ['bar', 'baz'], true), $table->getIndex('uniq_new')); // Rename to auto-generated name. self::assertSame($table, $table->renameIndex('pk_new', null)); @@ -727,14 +730,14 @@ public function testRenameIndex() self::assertFalse($table->hasIndex('idx_new')); self::assertFalse($table->hasIndex('uniq_new')); - self::assertEquals(new Index('primary', array('id'), true, true), $table->getPrimaryKey()); - self::assertEquals(new Index('primary', array('id'), true, true), $table->getIndex('primary')); + self::assertEquals(new Index('primary', ['id'], true, true), $table->getPrimaryKey()); + self::assertEquals(new Index('primary', ['id'], true, true), $table->getIndex('primary')); self::assertEquals( - new Index('IDX_D87F7E0C8C736521', array('foo'), false, false, array('flag')), + new Index('IDX_D87F7E0C8C736521', ['foo'], false, false, ['flag']), $table->getIndex('IDX_D87F7E0C8C736521') ); self::assertEquals( - new Index('UNIQ_D87F7E0C76FF8CAA78240498', array('bar', 'baz'), true), + new Index('UNIQ_D87F7E0C76FF8CAA78240498', ['bar', 'baz'], true), $table->getIndex('UNIQ_D87F7E0C76FF8CAA78240498') ); @@ -756,11 +759,11 @@ public function testKeepsIndexOptionsOnRenamingRegularIndex() { $table = new Table('foo'); $table->addColumn('id', 'integer'); - $table->addIndex(array('id'), 'idx_bar', array(), array('where' => '1 = 1')); + $table->addIndex(['id'], 'idx_bar', [], ['where' => '1 = 1']); $table->renameIndex('idx_bar', 'idx_baz'); - self::assertSame(array('where' => '1 = 1'), $table->getIndex('idx_baz')->getOptions()); + self::assertSame(['where' => '1 = 1'], $table->getIndex('idx_baz')->getOptions()); } /** @@ -770,11 +773,11 @@ public function testKeepsIndexOptionsOnRenamingUniqueIndex() { $table = new Table('foo'); $table->addColumn('id', 'integer'); - $table->addUniqueIndex(array('id'), 'idx_bar', array('where' => '1 = 1')); + $table->addUniqueIndex(['id'], 'idx_bar', ['where' => '1 = 1']); $table->renameIndex('idx_bar', 'idx_baz'); - self::assertSame(array('where' => '1 = 1'), $table->getIndex('idx_baz')->getOptions()); + self::assertSame(['where' => '1 = 1'], $table->getIndex('idx_baz')->getOptions()); } /** @@ -783,9 +786,9 @@ public function testKeepsIndexOptionsOnRenamingUniqueIndex() */ public function testThrowsExceptionOnRenamingNonExistingIndex() { - $table = new Table("test"); + $table = new Table('test'); $table->addColumn('id', 'integer'); - $table->addIndex(array('id'), 'idx'); + $table->addIndex(['id'], 'idx'); $table->renameIndex('foo', 'bar'); } @@ -796,11 +799,11 @@ public function testThrowsExceptionOnRenamingNonExistingIndex() */ public function testThrowsExceptionOnRenamingToAlreadyExistingIndex() { - $table = new Table("test"); + $table = new Table('test'); $table->addColumn('id', 'integer'); $table->addColumn('foo', 'integer'); - $table->addIndex(array('id'), 'idx_id'); - $table->addIndex(array('foo'), 'idx_foo'); + $table->addIndex(['id'], 'idx_id'); + $table->addIndex(['foo'], 'idx_foo'); $table->renameIndex('idx_id', 'idx_foo'); } @@ -814,8 +817,8 @@ public function testNormalizesColumnNames($assetName) $table = new Table('test'); $table->addColumn($assetName, 'integer'); - $table->addIndex(array($assetName), $assetName); - $table->addForeignKeyConstraint('test', array($assetName), array($assetName), array(), $assetName); + $table->addIndex([$assetName], $assetName); + $table->addForeignKeyConstraint('test', [$assetName], [$assetName], [], $assetName); self::assertTrue($table->hasColumn($assetName)); self::assertTrue($table->hasColumn('foo')); @@ -865,15 +868,15 @@ public function testNormalizesColumnNames($assetName) public function getNormalizesAssetNames() { - return array( - array('foo'), - array('FOO'), - array('`foo`'), - array('`FOO`'), - array('"foo"'), - array('"FOO"'), - array('"foo"'), - array('"FOO"'), - ); + return [ + ['foo'], + ['FOO'], + ['`foo`'], + ['`FOO`'], + ['"foo"'], + ['"FOO"'], + ['"foo"'], + ['"FOO"'], + ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php b/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php index bc76b62010a..f94e1c1d019 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php @@ -2,18 +2,20 @@ namespace Doctrine\Tests\DBAL\Schema\Visitor; -use \Doctrine\DBAL\Schema\Visitor\CreateSchemaSqlCollector; - -class CreateSchemaSqlCollectorTest extends \PHPUnit\Framework\TestCase +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Schema\ForeignKeyConstraint; +use Doctrine\DBAL\Schema\Sequence; +use Doctrine\DBAL\Schema\Table; +use Doctrine\DBAL\Schema\Visitor\CreateSchemaSqlCollector; +use PHPUnit\Framework\TestCase; +use PHPUnit_Framework_MockObject_MockObject; + +class CreateSchemaSqlCollectorTest extends TestCase { - /** - * @var \Doctrine\DBAL\Platforms\AbstractPlatform|\PHPUnit_Framework_MockObject_MockObject - */ + /** @var AbstractPlatform|PHPUnit_Framework_MockObject_MockObject */ private $platformMock; - /** - * @var \Doctrine\DBAL\Schema\Visitor\CreateSchemaSqlCollector - */ + /** @var CreateSchemaSqlCollector */ private $visitor; /** @@ -25,19 +27,19 @@ protected function setUp() $this->platformMock = $this->getMockBuilder('Doctrine\DBAL\Platforms\AbstractPlatform') ->setMethods( - array( + [ 'getCreateForeignKeySQL', 'getCreateSchemaSQL', 'getCreateSequenceSQL', 'getCreateTableSQL', 'supportsForeignKeyConstraints', - 'supportsSchemas' - ) + 'supportsSchemas', + ] ) ->getMockForAbstractClass(); - $this->visitor = new CreateSchemaSqlCollector($this->platformMock); + $this->visitor = new CreateSchemaSqlCollector($this->platformMock); - foreach (array('getCreateSchemaSQL', 'getCreateTableSQL', 'getCreateForeignKeySQL', 'getCreateSequenceSQL') as $method) { + foreach (['getCreateSchemaSQL', 'getCreateTableSQL', 'getCreateForeignKeySQL', 'getCreateSequenceSQL'] as $method) { $this->platformMock->expects($this->any()) ->method($method) ->will($this->returnValue('foo')); @@ -60,7 +62,7 @@ public function testAcceptsNamespace() $this->visitor->acceptNamespace('foo'); - self::assertSame(array('foo'), $this->visitor->getQueries()); + self::assertSame(['foo'], $this->visitor->getQueries()); } public function testAcceptsTable() @@ -69,7 +71,7 @@ public function testAcceptsTable() $this->visitor->acceptTable($table); - self::assertSame(array('foo'), $this->visitor->getQueries()); + self::assertSame(['foo'], $this->visitor->getQueries()); } public function testAcceptsForeignKey() @@ -82,7 +84,7 @@ public function testAcceptsForeignKey() ->method('supportsForeignKeyConstraints') ->will($this->returnValue(true)); - $table = $this->createTableMock(); + $table = $this->createTableMock(); $foreignKey = $this->createForeignKeyConstraintMock(); $this->visitor->acceptForeignKey($table, $foreignKey); @@ -91,7 +93,7 @@ public function testAcceptsForeignKey() $this->visitor->acceptForeignKey($table, $foreignKey); - self::assertSame(array('foo'), $this->visitor->getQueries()); + self::assertSame(['foo'], $this->visitor->getQueries()); } public function testAcceptsSequences() @@ -100,20 +102,20 @@ public function testAcceptsSequences() $this->visitor->acceptSequence($sequence); - self::assertSame(array('foo'), $this->visitor->getQueries()); + self::assertSame(['foo'], $this->visitor->getQueries()); } public function testResetsQueries() { - foreach (array('supportsSchemas', 'supportsForeignKeyConstraints') as $method) { + foreach (['supportsSchemas', 'supportsForeignKeyConstraints'] as $method) { $this->platformMock->expects($this->any()) ->method($method) ->will($this->returnValue(true)); } - $table = $this->createTableMock(); + $table = $this->createTableMock(); $foreignKey = $this->createForeignKeyConstraintMock(); - $sequence = $this->createSequenceMock(); + $sequence = $this->createSequenceMock(); $this->visitor->acceptNamespace('foo'); $this->visitor->acceptTable($table); @@ -128,7 +130,7 @@ public function testResetsQueries() } /** - * @return \Doctrine\DBAL\Schema\ForeignKeyConstraint|\PHPUnit_Framework_MockObject_MockObject + * @return ForeignKeyConstraint|PHPUnit_Framework_MockObject_MockObject */ private function createForeignKeyConstraintMock() { @@ -138,7 +140,7 @@ private function createForeignKeyConstraintMock() } /** - * @return \Doctrine\DBAL\Schema\Sequence|\PHPUnit_Framework_MockObject_MockObject + * @return Sequence|PHPUnit_Framework_MockObject_MockObject */ private function createSequenceMock() { @@ -148,7 +150,7 @@ private function createSequenceMock() } /** - * @return \Doctrine\DBAL\Schema\Table|\PHPUnit_Framework_MockObject_MockObject + * @return Table|PHPUnit_Framework_MockObject_MockObject */ private function createTableMock() { diff --git a/tests/Doctrine/Tests/DBAL/Schema/Visitor/DropSchemaSqlCollectorTest.php b/tests/Doctrine/Tests/DBAL/Schema/Visitor/DropSchemaSqlCollectorTest.php index 20e20127f04..c65996cab7b 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Visitor/DropSchemaSqlCollectorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Visitor/DropSchemaSqlCollectorTest.php @@ -3,11 +3,12 @@ namespace Doctrine\Tests\DBAL\Schema\Visitor; use Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector; +use PHPUnit\Framework\TestCase; /** * @covers Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector */ -class DropSchemaSqlCollectorTest extends \PHPUnit\Framework\TestCase +class DropSchemaSqlCollectorTest extends TestCase { public function testGetQueriesUsesAcceptedForeignKeys() { @@ -18,7 +19,7 @@ public function testGetQueriesUsesAcceptedForeignKeys() $keyConstraintTwo = $this->getStubKeyConstraint('second'); $platform = $this->getMockBuilder('Doctrine\DBAL\Platforms\AbstractPlatform') - ->setMethods(array('getDropForeignKeySQL')) + ->setMethods(['getDropForeignKeySQL']) ->getMockForAbstractClass(); $collector = new DropSchemaSqlCollector($platform); @@ -60,11 +61,11 @@ private function getStubKeyConstraint($name) $constraint->expects($this->any()) ->method('getForeignColumns') - ->will($this->returnValue(array())); + ->will($this->returnValue([])); $constraint->expects($this->any()) ->method('getColumns') - ->will($this->returnValue(array())); + ->will($this->returnValue([])); return $constraint; } @@ -75,7 +76,7 @@ public function testGivenForeignKeyWithZeroLength_acceptForeignKeyThrowsExceptio $this->getMockForAbstractClass('Doctrine\DBAL\Platforms\AbstractPlatform') ); - $this->expectException( 'Doctrine\DBAL\Schema\SchemaException' ); + $this->expectException('Doctrine\DBAL\Schema\SchemaException'); $collector->acceptForeignKey($this->getTableMock(), $this->getStubKeyConstraint('')); } } diff --git a/tests/Doctrine/Tests/DBAL/Schema/Visitor/RemoveNamespacedAssetsTest.php b/tests/Doctrine/Tests/DBAL/Schema/Visitor/RemoveNamespacedAssetsTest.php index 356295d56b9..c3e52b0ffaf 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Visitor/RemoveNamespacedAssetsTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Visitor/RemoveNamespacedAssetsTest.php @@ -6,27 +6,28 @@ use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\SchemaConfig; use Doctrine\DBAL\Schema\Visitor\RemoveNamespacedAssets; +use PHPUnit\Framework\TestCase; use function array_keys; -class RemoveNamespacedAssetsTest extends \PHPUnit\Framework\TestCase +class RemoveNamespacedAssetsTest extends TestCase { /** * @group DBAL-204 */ public function testRemoveNamespacedAssets() { - $config = new SchemaConfig; - $config->setName("test"); - $schema = new Schema(array(), array(), $config); + $config = new SchemaConfig(); + $config->setName('test'); + $schema = new Schema([], [], $config); - $schema->createTable("test.test"); - $schema->createTable("foo.bar"); - $schema->createTable("baz"); + $schema->createTable('test.test'); + $schema->createTable('foo.bar'); + $schema->createTable('baz'); $schema->visit(new RemoveNamespacedAssets()); $tables = $schema->getTables(); - self::assertEquals(array("test.test", "test.baz"), array_keys($tables), "Only 2 tables should be present, both in 'test' namespace."); + self::assertEquals(['test.test', 'test.baz'], array_keys($tables), "Only 2 tables should be present, both in 'test' namespace."); } /** @@ -34,22 +35,22 @@ public function testRemoveNamespacedAssets() */ public function testCleanupForeignKeys() { - $config = new SchemaConfig; - $config->setName("test"); - $schema = new Schema(array(), array(), $config); + $config = new SchemaConfig(); + $config->setName('test'); + $schema = new Schema([], [], $config); - $fooTable = $schema->createTable("foo.bar"); + $fooTable = $schema->createTable('foo.bar'); $fooTable->addColumn('id', 'integer'); - $testTable = $schema->createTable("test.test"); + $testTable = $schema->createTable('test.test'); $testTable->addColumn('id', 'integer'); - $testTable->addForeignKeyConstraint("foo.bar", array("id"), array("id")); + $testTable->addForeignKeyConstraint('foo.bar', ['id'], ['id']); $schema->visit(new RemoveNamespacedAssets()); $sql = $schema->toSql(new MySqlPlatform()); - self::assertCount(1, $sql, "Just one CREATE TABLE statement, no foreign key and table to foo.bar"); + self::assertCount(1, $sql, 'Just one CREATE TABLE statement, no foreign key and table to foo.bar'); } /** @@ -57,21 +58,21 @@ public function testCleanupForeignKeys() */ public function testCleanupForeignKeysDifferentOrder() { - $config = new SchemaConfig; - $config->setName("test"); - $schema = new Schema(array(), array(), $config); + $config = new SchemaConfig(); + $config->setName('test'); + $schema = new Schema([], [], $config); - $testTable = $schema->createTable("test.test"); + $testTable = $schema->createTable('test.test'); $testTable->addColumn('id', 'integer'); - $fooTable = $schema->createTable("foo.bar"); + $fooTable = $schema->createTable('foo.bar'); $fooTable->addColumn('id', 'integer'); - $testTable->addForeignKeyConstraint("foo.bar", array("id"), array("id")); + $testTable->addForeignKeyConstraint('foo.bar', ['id'], ['id']); $schema->visit(new RemoveNamespacedAssets()); $sql = $schema->toSql(new MySqlPlatform()); - self::assertCount(1, $sql, "Just one CREATE TABLE statement, no foreign key and table to foo.bar"); + self::assertCount(1, $sql, 'Just one CREATE TABLE statement, no foreign key and table to foo.bar'); } } diff --git a/tests/Doctrine/Tests/DBAL/Schema/Visitor/SchemaSqlCollectorTest.php b/tests/Doctrine/Tests/DBAL/Schema/Visitor/SchemaSqlCollectorTest.php index 96a441210e1..d326a817c0d 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Visitor/SchemaSqlCollectorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Visitor/SchemaSqlCollectorTest.php @@ -3,51 +3,52 @@ namespace Doctrine\Tests\DBAL\Schema\Visitor; use Doctrine\DBAL\Schema\Schema; +use PHPUnit\Framework\TestCase; -class SchemaSqlCollectorTest extends \PHPUnit\Framework\TestCase +class SchemaSqlCollectorTest extends TestCase { public function testCreateSchema() { $platformMock = $this->getMockBuilder('Doctrine\DBAL\Platforms\MySqlPlatform') - ->setMethods(array('getCreateTableSql', 'getCreateSequenceSql', 'getCreateForeignKeySql')) + ->setMethods(['getCreateTableSql', 'getCreateSequenceSql', 'getCreateForeignKeySql']) ->getMock(); $platformMock->expects($this->exactly(2)) ->method('getCreateTableSql') - ->will($this->returnValue(array("foo"))); + ->will($this->returnValue(['foo'])); $platformMock->expects($this->exactly(1)) ->method('getCreateSequenceSql') - ->will($this->returnValue("bar")); + ->will($this->returnValue('bar')); $platformMock->expects($this->exactly(1)) ->method('getCreateForeignKeySql') - ->will($this->returnValue("baz")); + ->will($this->returnValue('baz')); $schema = $this->createFixtureSchema(); $sql = $schema->toSql($platformMock); - self::assertEquals(array("foo", "foo", "bar", "baz"), $sql); + self::assertEquals(['foo', 'foo', 'bar', 'baz'], $sql); } public function testDropSchema() { $platformMock = $this->getMockBuilder('Doctrine\DBAL\Platforms\MySqlPlatform') - ->setMethods(array('getDropTableSql', 'getDropSequenceSql', 'getDropForeignKeySql')) + ->setMethods(['getDropTableSql', 'getDropSequenceSql', 'getDropForeignKeySql']) ->getMock(); $platformMock->expects($this->exactly(2)) ->method('getDropTableSql') - ->will($this->returnValue("tbl")); + ->will($this->returnValue('tbl')); $platformMock->expects($this->exactly(1)) ->method('getDropSequenceSql') - ->will($this->returnValue("seq")); + ->will($this->returnValue('seq')); $platformMock->expects($this->exactly(1)) ->method('getDropForeignKeySql') - ->will($this->returnValue("fk")); + ->will($this->returnValue('fk')); $schema = $this->createFixtureSchema(); $sql = $schema->toDropSql($platformMock); - self::assertEquals(array("fk", "seq", "tbl", "tbl"), $sql); + self::assertEquals(['fk', 'seq', 'tbl', 'tbl'], $sql); } /** @@ -56,18 +57,18 @@ public function testDropSchema() public function createFixtureSchema() { $schema = new Schema(); - $tableA = $schema->createTable("foo"); - $tableA->addColumn("id", 'integer'); - $tableA->addColumn("bar", 'string', array('length' => 255)); - $tableA->setPrimaryKey(array("id")); + $tableA = $schema->createTable('foo'); + $tableA->addColumn('id', 'integer'); + $tableA->addColumn('bar', 'string', ['length' => 255]); + $tableA->setPrimaryKey(['id']); - $schema->createSequence("foo_seq"); + $schema->createSequence('foo_seq'); - $tableB = $schema->createTable("bar"); - $tableB->addColumn("id", 'integer'); - $tableB->setPrimaryKey(array("id")); + $tableB = $schema->createTable('bar'); + $tableB->addColumn('id', 'integer'); + $tableB->setPrimaryKey(['id']); - $tableA->addForeignKeyConstraint($tableB, array("bar"), array("id")); + $tableA->addForeignKeyConstraint($tableB, ['bar'], ['id']); return $schema; } diff --git a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php index 9c96cbfc975..0eafb7eae01 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php @@ -21,24 +21,25 @@ use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser; +use PHPUnit\Framework\TestCase; /** * @requires extension pdo_sqlite */ -class PoolingShardConnectionTest extends \PHPUnit\Framework\TestCase +class PoolingShardConnectionTest extends TestCase { public function testConnect() { - $conn = DriverManager::getConnection(array( + $conn = DriverManager::getConnection([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', - 'global' => array('memory' => true), - 'shards' => array( - array('id' => 1, 'memory' => true), - array('id' => 2, 'memory' => true), - ), + 'global' => ['memory' => true], + 'shards' => [ + ['id' => 1, 'memory' => true], + ['id' => 2, 'memory' => true], + ], 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', - )); + ]); self::assertFalse($conn->isConnected(0)); $conn->connect(0); @@ -66,15 +67,15 @@ public function testNoGlobalServerException() $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage("Connection Parameters require 'global' and 'shards' configurations."); - DriverManager::getConnection(array( + DriverManager::getConnection([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', - 'shards' => array( - array('id' => 1, 'memory' => true), - array('id' => 2, 'memory' => true), - ), + 'shards' => [ + ['id' => 1, 'memory' => true], + ['id' => 2, 'memory' => true], + ], 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', - )); + ]); } public function testNoShardsServersException() @@ -82,12 +83,12 @@ public function testNoShardsServersException() $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage("Connection Parameters require 'global' and 'shards' configurations."); - DriverManager::getConnection(array( + DriverManager::getConnection([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', - 'global' => array('memory' => true), + 'global' => ['memory' => true], 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', - )); + ]); } public function testNoShardsChoserException() @@ -95,15 +96,15 @@ public function testNoShardsChoserException() $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage("Missing Shard Choser configuration 'shardChoser'"); - DriverManager::getConnection(array( + DriverManager::getConnection([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', - 'global' => array('memory' => true), - 'shards' => array( - array('id' => 1, 'memory' => true), - array('id' => 2, 'memory' => true), - ), - )); + 'global' => ['memory' => true], + 'shards' => [ + ['id' => 1, 'memory' => true], + ['id' => 2, 'memory' => true], + ], + ]); } public function testShardChoserWrongInstance() @@ -111,16 +112,16 @@ public function testShardChoserWrongInstance() $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage("The 'shardChoser' configuration is not a valid instance of Doctrine\DBAL\Sharding\ShardChoser\ShardChoser"); - DriverManager::getConnection(array( + DriverManager::getConnection([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', - 'global' => array('memory' => true), - 'shards' => array( - array('id' => 1, 'memory' => true), - array('id' => 2, 'memory' => true), - ), - 'shardChoser' => new \stdClass, - )); + 'global' => ['memory' => true], + 'shards' => [ + ['id' => 1, 'memory' => true], + ['id' => 2, 'memory' => true], + ], + 'shardChoser' => new \stdClass(), + ]); } public function testShardNonNumericId() @@ -128,15 +129,15 @@ public function testShardNonNumericId() $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage('Shard Id has to be a non-negative number.'); - DriverManager::getConnection(array( + DriverManager::getConnection([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', - 'global' => array('memory' => true), - 'shards' => array( - array('id' => 'foo', 'memory' => true), - ), + 'global' => ['memory' => true], + 'shards' => [ + ['id' => 'foo', 'memory' => true], + ], 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', - )); + ]); } public function testShardMissingId() @@ -144,15 +145,15 @@ public function testShardMissingId() $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage("Missing 'id' for one configured shard. Please specify a unique shard-id."); - DriverManager::getConnection(array( + DriverManager::getConnection([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', - 'global' => array('memory' => true), - 'shards' => array( - array('memory' => true), - ), + 'global' => ['memory' => true], + 'shards' => [ + ['memory' => true], + ], 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', - )); + ]); } public function testDuplicateShardId() @@ -160,29 +161,29 @@ public function testDuplicateShardId() $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage('Shard 1 is duplicated in the configuration.'); - DriverManager::getConnection(array( + DriverManager::getConnection([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', - 'global' => array('memory' => true), - 'shards' => array( - array('id' => 1, 'memory' => true), - array('id' => 1, 'memory' => true), - ), + 'global' => ['memory' => true], + 'shards' => [ + ['id' => 1, 'memory' => true], + ['id' => 1, 'memory' => true], + ], 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', - )); + ]); } public function testSwitchShardWithOpenTransactionException() { - $conn = DriverManager::getConnection(array( + $conn = DriverManager::getConnection([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', - 'global' => array('memory' => true), - 'shards' => array( - array('id' => 1, 'memory' => true), - ), + 'global' => ['memory' => true], + 'shards' => [ + ['id' => 1, 'memory' => true], + ], 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', - )); + ]); $conn->beginTransaction(); @@ -193,15 +194,15 @@ public function testSwitchShardWithOpenTransactionException() public function testGetActiveShardId() { - $conn = DriverManager::getConnection(array( + $conn = DriverManager::getConnection([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', - 'global' => array('memory' => true), - 'shards' => array( - array('id' => 1, 'memory' => true), - ), + 'global' => ['memory' => true], + 'shards' => [ + ['id' => 1, 'memory' => true], + ], 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', - )); + ]); self::assertNull($conn->getActiveShardId()); @@ -217,55 +218,55 @@ public function testGetActiveShardId() public function testGetParamsOverride() { - $conn = DriverManager::getConnection(array( + $conn = DriverManager::getConnection([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', - 'global' => array('memory' => true, 'host' => 'localhost'), - 'shards' => array( - array('id' => 1, 'memory' => true, 'host' => 'foo'), - ), + 'global' => ['memory' => true, 'host' => 'localhost'], + 'shards' => [ + ['id' => 1, 'memory' => true, 'host' => 'foo'], + ], 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', - )); + ]); - self::assertEquals(array( + self::assertEquals([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', - 'global' => array('memory' => true, 'host' => 'localhost'), - 'shards' => array( - array('id' => 1, 'memory' => true, 'host' => 'foo'), - ), + 'global' => ['memory' => true, 'host' => 'localhost'], + 'shards' => [ + ['id' => 1, 'memory' => true, 'host' => 'foo'], + ], 'shardChoser' => new MultiTenantShardChoser(), 'memory' => true, 'host' => 'localhost', - ), $conn->getParams()); + ], $conn->getParams()); $conn->connect(1); - self::assertEquals(array( + self::assertEquals([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', - 'global' => array('memory' => true, 'host' => 'localhost'), - 'shards' => array( - array('id' => 1, 'memory' => true, 'host' => 'foo'), - ), + 'global' => ['memory' => true, 'host' => 'localhost'], + 'shards' => [ + ['id' => 1, 'memory' => true, 'host' => 'foo'], + ], 'shardChoser' => new MultiTenantShardChoser(), 'id' => 1, 'memory' => true, 'host' => 'foo', - ), $conn->getParams()); + ], $conn->getParams()); } public function testGetHostOverride() { - $conn = DriverManager::getConnection(array( + $conn = DriverManager::getConnection([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', 'host' => 'localhost', - 'global' => array('memory' => true), - 'shards' => array( - array('id' => 1, 'memory' => true, 'host' => 'foo'), - ), + 'global' => ['memory' => true], + 'shards' => [ + ['id' => 1, 'memory' => true, 'host' => 'foo'], + ], 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', - )); + ]); self::assertEquals('localhost', $conn->getHost()); @@ -275,16 +276,16 @@ public function testGetHostOverride() public function testGetPortOverride() { - $conn = DriverManager::getConnection(array( + $conn = DriverManager::getConnection([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', 'port' => 3306, - 'global' => array('memory' => true), - 'shards' => array( - array('id' => 1, 'memory' => true, 'port' => 3307), - ), + 'global' => ['memory' => true], + 'shards' => [ + ['id' => 1, 'memory' => true, 'port' => 3307], + ], 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', - )); + ]); self::assertEquals(3306, $conn->getPort()); @@ -294,16 +295,16 @@ public function testGetPortOverride() public function testGetUsernameOverride() { - $conn = DriverManager::getConnection(array( + $conn = DriverManager::getConnection([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', 'user' => 'foo', - 'global' => array('memory' => true), - 'shards' => array( - array('id' => 1, 'memory' => true, 'user' => 'bar'), - ), + 'global' => ['memory' => true], + 'shards' => [ + ['id' => 1, 'memory' => true, 'user' => 'bar'], + ], 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', - )); + ]); self::assertEquals('foo', $conn->getUsername()); @@ -313,16 +314,16 @@ public function testGetUsernameOverride() public function testGetPasswordOverride() { - $conn = DriverManager::getConnection(array( + $conn = DriverManager::getConnection([ 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', 'driver' => 'pdo_sqlite', 'password' => 'foo', - 'global' => array('memory' => true), - 'shards' => array( - array('id' => 1, 'memory' => true, 'password' => 'bar'), - ), + 'global' => ['memory' => true], + 'shards' => [ + ['id' => 1, 'memory' => true, 'password' => 'bar'], + ], 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', - )); + ]); self::assertEquals('foo', $conn->getPassword()); diff --git a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php index dccb1b1c53d..cc5809effab 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php @@ -19,13 +19,14 @@ namespace Doctrine\Tests\DBAL\Sharding; use Doctrine\DBAL\Sharding\PoolingShardManager; +use PHPUnit\Framework\TestCase; -class PoolingShardManagerTest extends \PHPUnit\Framework\TestCase +class PoolingShardManagerTest extends TestCase { private function createConnectionMock() { return $this->getMockBuilder('Doctrine\DBAL\Sharding\PoolingShardConnection') - ->setMethods(array('connect', 'getParams', 'fetchAll')) + ->setMethods(['connect', 'getParams', 'fetchAll']) ->disableOriginalConstructor() ->getMock(); } @@ -35,7 +36,9 @@ private function createPassthroughShardChoser() $mock = $this->createMock('Doctrine\DBAL\Sharding\ShardChoser\ShardChoser'); $mock->expects($this->any()) ->method('pickShard') - ->will($this->returnCallback(function($value) { return $value; })); + ->will($this->returnCallback(static function ($value) { + return $value; + })); return $mock; } @@ -44,7 +47,9 @@ private function createStaticShardChoser() $mock = $this->createMock('Doctrine\DBAL\Sharding\ShardChoser\ShardChoser'); $mock->expects($this->any()) ->method('pickShard') - ->will($this->returnCallback(function($value) { return 1; })); + ->will($this->returnCallback(static function ($value) { + return 1; + })); return $mock; } @@ -62,8 +67,8 @@ public function testSelectGlobal() public function testSelectShard() { $shardId = 10; - $conn = $this->createConnectionMock(); - $conn->expects($this->at(0))->method('getParams')->will($this->returnValue(array('shardChoser' => $this->createPassthroughShardChoser()))); + $conn = $this->createConnectionMock(); + $conn->expects($this->at(0))->method('getParams')->will($this->returnValue(['shardChoser' => $this->createPassthroughShardChoser()])); $conn->expects($this->at(1))->method('connect')->with($this->equalTo($shardId)); $shardManager = new PoolingShardManager($conn); @@ -77,73 +82,73 @@ public function testGetShards() $conn = $this->createConnectionMock(); $conn->expects($this->any())->method('getParams')->will( $this->returnValue( - array('shards' => array( array('id' => 1), array('id' => 2) ), 'shardChoser' => $this->createPassthroughShardChoser()) + ['shards' => [ ['id' => 1], ['id' => 2] ], 'shardChoser' => $this->createPassthroughShardChoser()] ) ); $shardManager = new PoolingShardManager($conn); - $shards = $shardManager->getShards(); + $shards = $shardManager->getShards(); - self::assertEquals(array(array('id' => 1), array('id' => 2)), $shards); + self::assertEquals([['id' => 1], ['id' => 2]], $shards); } public function testQueryAll() { - $sql = "SELECT * FROM table"; - $params = array(1); - $types = array(1); + $sql = 'SELECT * FROM table'; + $params = [1]; + $types = [1]; $conn = $this->createConnectionMock(); $conn->expects($this->at(0))->method('getParams')->will($this->returnValue( - array('shards' => array( array('id' => 1), array('id' => 2) ), 'shardChoser' => $this->createPassthroughShardChoser()) + ['shards' => [ ['id' => 1], ['id' => 2] ], 'shardChoser' => $this->createPassthroughShardChoser()] )); $conn->expects($this->at(1))->method('getParams')->will($this->returnValue( - array('shards' => array( array('id' => 1), array('id' => 2) ), 'shardChoser' => $this->createPassthroughShardChoser()) + ['shards' => [ ['id' => 1], ['id' => 2] ], 'shardChoser' => $this->createPassthroughShardChoser()] )); $conn->expects($this->at(2))->method('connect')->with($this->equalTo(1)); $conn->expects($this->at(3)) ->method('fetchAll') ->with($this->equalTo($sql), $this->equalTo($params), $this->equalTo($types)) - ->will($this->returnValue(array( array('id' => 1) ) )); + ->will($this->returnValue([ ['id' => 1] ])); $conn->expects($this->at(4))->method('connect')->with($this->equalTo(2)); $conn->expects($this->at(5)) ->method('fetchAll') ->with($this->equalTo($sql), $this->equalTo($params), $this->equalTo($types)) - ->will($this->returnValue(array( array('id' => 2) ) )); + ->will($this->returnValue([ ['id' => 2] ])); $shardManager = new PoolingShardManager($conn); - $result = $shardManager->queryAll($sql, $params, $types); + $result = $shardManager->queryAll($sql, $params, $types); - self::assertEquals(array(array('id' => 1), array('id' => 2)), $result); + self::assertEquals([['id' => 1], ['id' => 2]], $result); } public function testQueryAllWithStaticShardChoser() { - $sql = "SELECT * FROM table"; - $params = array(1); - $types = array(1); + $sql = 'SELECT * FROM table'; + $params = [1]; + $types = [1]; $conn = $this->createConnectionMock(); $conn->expects($this->at(0))->method('getParams')->will($this->returnValue( - array('shards' => array( array('id' => 1), array('id' => 2) ), 'shardChoser' => $this->createStaticShardChoser()) + ['shards' => [ ['id' => 1], ['id' => 2] ], 'shardChoser' => $this->createStaticShardChoser()] )); $conn->expects($this->at(1))->method('getParams')->will($this->returnValue( - array('shards' => array( array('id' => 1), array('id' => 2) ), 'shardChoser' => $this->createStaticShardChoser()) + ['shards' => [ ['id' => 1], ['id' => 2] ], 'shardChoser' => $this->createStaticShardChoser()] )); $conn->expects($this->at(2))->method('connect')->with($this->equalTo(1)); $conn->expects($this->at(3)) ->method('fetchAll') ->with($this->equalTo($sql), $this->equalTo($params), $this->equalTo($types)) - ->will($this->returnValue(array( array('id' => 1) ) )); + ->will($this->returnValue([ ['id' => 1] ])); $conn->expects($this->at(4))->method('connect')->with($this->equalTo(2)); $conn->expects($this->at(5)) ->method('fetchAll') ->with($this->equalTo($sql), $this->equalTo($params), $this->equalTo($types)) - ->will($this->returnValue(array( array('id' => 2) ) )); + ->will($this->returnValue([ ['id' => 2] ])); $shardManager = new PoolingShardManager($conn); - $result = $shardManager->queryAll($sql, $params, $types); + $result = $shardManager->queryAll($sql, $params, $types); - self::assertEquals(array(array('id' => 1), array('id' => 2)), $result); + self::assertEquals([['id' => 1], ['id' => 2]], $result); } } diff --git a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/AbstractTestCase.php b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/AbstractTestCase.php index ced8f6615e6..2e67d0a023f 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/AbstractTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/AbstractTestCase.php @@ -2,48 +2,46 @@ namespace Doctrine\Tests\DBAL\Sharding\SQLAzure; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Sharding\SQLAzure\SQLAzureShardManager; +use PHPUnit\Framework\TestCase; use function strpos; -abstract class AbstractTestCase extends \PHPUnit\Framework\TestCase +abstract class AbstractTestCase extends TestCase { - /** - * @var \Doctrine\DBAL\Connection - */ + /** @var Connection */ protected $conn; - /** - * @var SQLAzureShardManager - */ + /** @var SQLAzureShardManager */ protected $sm; protected function setUp() { - if (!isset($GLOBALS['db_type']) || strpos($GLOBALS['db_type'], "sqlsrv") === false) { + if (! isset($GLOBALS['db_type']) || strpos($GLOBALS['db_type'], 'sqlsrv') === false) { $this->markTestSkipped('No driver or sqlserver driver specified.'); } - $params = array( + $params = [ 'driver' => $GLOBALS['db_type'], 'dbname' => $GLOBALS['db_name'], 'user' => $GLOBALS['db_username'], 'password' => $GLOBALS['db_password'], 'host' => $GLOBALS['db_host'], - 'sharding' => array( + 'sharding' => [ 'federationName' => 'Orders_Federation', 'distributionKey' => 'CustID', 'distributionType' => 'integer', 'filteringEnabled' => false, - ), - 'driverOptions' => array('MultipleActiveResultSets' => false) - ); + ], + 'driverOptions' => ['MultipleActiveResultSets' => false], + ]; $this->conn = DriverManager::getConnection($params); $serverEdition = $this->conn->fetchColumn("SELECT CONVERT(NVARCHAR(128), SERVERPROPERTY('Edition'))"); - if (0 !== strpos($serverEdition, 'SQL Azure')) { + if (strpos($serverEdition, 'SQL Azure') !== 0) { $this->markTestSkipped('SQL Azure only test.'); } @@ -62,8 +60,8 @@ public function createShopSchema() $products->addColumn('ProductID', 'integer'); $products->addColumn('SupplierID', 'integer'); $products->addColumn('ProductName', 'string'); - $products->addColumn('Price', 'decimal', array('scale' => 2, 'precision' => 12)); - $products->setPrimaryKey(array('ProductID')); + $products->addColumn('Price', 'decimal', ['scale' => 2, 'precision' => 12]); + $products->setPrimaryKey(['ProductID']); $products->addOption('azure.federated', true); $customers = $schema->createTable('Customers'); @@ -71,7 +69,7 @@ public function createShopSchema() $customers->addColumn('CompanyName', 'string'); $customers->addColumn('FirstName', 'string'); $customers->addColumn('LastName', 'string'); - $customers->setPrimaryKey(array('CustomerID')); + $customers->setPrimaryKey(['CustomerID']); $customers->addOption('azure.federated', true); $customers->addOption('azure.federatedOnColumnName', 'CustomerID'); @@ -79,7 +77,7 @@ public function createShopSchema() $orders->addColumn('CustomerID', 'integer'); $orders->addColumn('OrderID', 'integer'); $orders->addColumn('OrderDate', 'datetime'); - $orders->setPrimaryKey(array('CustomerID', 'OrderID')); + $orders->setPrimaryKey(['CustomerID', 'OrderID']); $orders->addOption('azure.federated', true); $orders->addOption('azure.federatedOnColumnName', 'CustomerID'); @@ -88,7 +86,7 @@ public function createShopSchema() $orderItems->addColumn('OrderID', 'integer'); $orderItems->addColumn('ProductID', 'integer'); $orderItems->addColumn('Quantity', 'integer'); - $orderItems->setPrimaryKey(array('CustomerID', 'OrderID', 'ProductID')); + $orderItems->setPrimaryKey(['CustomerID', 'OrderID', 'ProductID']); $orderItems->addOption('azure.federated', true); $orderItems->addOption('azure.federatedOnColumnName', 'CustomerID'); diff --git a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/FunctionalTest.php b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/FunctionalTest.php index b65c99a6ebe..8a99ea70879 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/FunctionalTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/FunctionalTest.php @@ -1,4 +1,5 @@ sm->selectShard(0); - $this->conn->insert("Products", array( - "ProductID" => 1, - "SupplierID" => 2, - "ProductName" => "Test", - "Price" => 10.45 - )); - - $this->conn->insert("Customers", array( - "CustomerID" => 1, - "CompanyName" => "Foo", - "FirstName" => "Benjamin", - "LastName" => "E.", - )); - - $query = "SELECT * FROM Products"; - $data = $this->conn->fetchAll($query); + $this->conn->insert('Products', [ + 'ProductID' => 1, + 'SupplierID' => 2, + 'ProductName' => 'Test', + 'Price' => 10.45, + ]); + + $this->conn->insert('Customers', [ + 'CustomerID' => 1, + 'CompanyName' => 'Foo', + 'FirstName' => 'Benjamin', + 'LastName' => 'E.', + ]); + + $query = 'SELECT * FROM Products'; + $data = $this->conn->fetchAll($query); self::assertGreaterThan(0, count($data)); - $query = "SELECT * FROM Customers"; - $data = $this->conn->fetchAll($query); + $query = 'SELECT * FROM Customers'; + $data = $this->conn->fetchAll($query); self::assertGreaterThan(0, count($data)); - $data = $this->sm->queryAll("SELECT * FROM Customers"); + $data = $this->sm->queryAll('SELECT * FROM Customers'); self::assertGreaterThan(0, count($data)); } } diff --git a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/MultiTenantVisitorTest.php b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/MultiTenantVisitorTest.php index 99be4eff108..d49831e907d 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/MultiTenantVisitorTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/MultiTenantVisitorTest.php @@ -22,44 +22,44 @@ use Doctrine\DBAL\Platforms\SQLAzurePlatform; use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Sharding\SQLAzure\Schema\MultiTenantVisitor; +use PHPUnit\Framework\TestCase; -class MultiTenantVisitorTest extends \PHPUnit\Framework\TestCase +class MultiTenantVisitorTest extends TestCase { public function testMultiTenantPrimaryKey() { $platform = new SQLAzurePlatform(); - $visitor = new MultiTenantVisitor(); + $visitor = new MultiTenantVisitor(); $schema = new Schema(); - $foo = $schema->createTable('foo'); + $foo = $schema->createTable('foo'); $foo->addColumn('id', 'string'); - $foo->setPrimaryKey(array('id')); + $foo->setPrimaryKey(['id']); $schema->visit($visitor); - self::assertEquals(array('id', 'tenant_id'), $foo->getPrimaryKey()->getColumns()); + self::assertEquals(['id', 'tenant_id'], $foo->getPrimaryKey()->getColumns()); self::assertTrue($foo->hasColumn('tenant_id')); } public function testMultiTenantNonPrimaryKey() { $platform = new SQLAzurePlatform(); - $visitor = new MultiTenantVisitor(); + $visitor = new MultiTenantVisitor(); $schema = new Schema(); - $foo = $schema->createTable('foo'); + $foo = $schema->createTable('foo'); $foo->addColumn('id', 'string'); $foo->addColumn('created', 'datetime'); - $foo->setPrimaryKey(array('id')); - $foo->addIndex(array('created'), 'idx'); + $foo->setPrimaryKey(['id']); + $foo->addIndex(['created'], 'idx'); $foo->getPrimaryKey()->addFlag('nonclustered'); $foo->getIndex('idx')->addFlag('clustered'); $schema->visit($visitor); - self::assertEquals(array('id'), $foo->getPrimaryKey()->getColumns()); + self::assertEquals(['id'], $foo->getPrimaryKey()->getColumns()); self::assertTrue($foo->hasColumn('tenant_id')); - self::assertEquals(array('created', 'tenant_id'), $foo->getIndex('idx')->getColumns()); + self::assertEquals(['created', 'tenant_id'], $foo->getIndex('idx')->getColumns()); } } - diff --git a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizerTest.php b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizerTest.php index 7561b12b3ec..20e479a3e00 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizerTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizerTest.php @@ -1,4 +1,5 @@ createShopSchema(); $synchronizer = new SQLAzureFederationsSynchronizer($this->conn, $this->sm); - $sql = $synchronizer->getCreateSchema($schema); + $sql = $synchronizer->getCreateSchema($schema); - self::assertEquals(array ( + self::assertEquals([ "--Create Federation\nCREATE FEDERATION Orders_Federation (CustID INT RANGE)", - "USE FEDERATION Orders_Federation (CustID = 0) WITH RESET, FILTERING = OFF;", - "CREATE TABLE Products (ProductID INT NOT NULL, SupplierID INT NOT NULL, ProductName NVARCHAR(255) NOT NULL, Price NUMERIC(12, 2) NOT NULL, PRIMARY KEY (ProductID))", - "CREATE TABLE Customers (CustomerID INT NOT NULL, CompanyName NVARCHAR(255) NOT NULL, FirstName NVARCHAR(255) NOT NULL, LastName NVARCHAR(255) NOT NULL, PRIMARY KEY (CustomerID))", - "CREATE TABLE Orders (CustomerID INT NOT NULL, OrderID INT NOT NULL, OrderDate DATETIME2(6) NOT NULL, PRIMARY KEY (CustomerID, OrderID))", - "CREATE TABLE OrderItems (CustomerID INT NOT NULL, OrderID INT NOT NULL, ProductID INT NOT NULL, Quantity INT NOT NULL, PRIMARY KEY (CustomerID, OrderID, ProductID))", - ), $sql); + 'USE FEDERATION Orders_Federation (CustID = 0) WITH RESET, FILTERING = OFF;', + 'CREATE TABLE Products (ProductID INT NOT NULL, SupplierID INT NOT NULL, ProductName NVARCHAR(255) NOT NULL, Price NUMERIC(12, 2) NOT NULL, PRIMARY KEY (ProductID))', + 'CREATE TABLE Customers (CustomerID INT NOT NULL, CompanyName NVARCHAR(255) NOT NULL, FirstName NVARCHAR(255) NOT NULL, LastName NVARCHAR(255) NOT NULL, PRIMARY KEY (CustomerID))', + 'CREATE TABLE Orders (CustomerID INT NOT NULL, OrderID INT NOT NULL, OrderDate DATETIME2(6) NOT NULL, PRIMARY KEY (CustomerID, OrderID))', + 'CREATE TABLE OrderItems (CustomerID INT NOT NULL, OrderID INT NOT NULL, ProductID INT NOT NULL, Quantity INT NOT NULL, PRIMARY KEY (CustomerID, OrderID, ProductID))', + ], $sql); } public function testUpdateSchema() @@ -31,7 +32,7 @@ public function testUpdateSchema() $sql = $synchronizer->getUpdateSchema($schema); - self::assertEquals(array(), $sql); + self::assertEquals([], $sql); } public function testDropSchema() diff --git a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php index 80d510f7d12..04dc31723ef 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php @@ -3,16 +3,17 @@ namespace Doctrine\Tests\DBAL\Sharding\SQLAzure; use Doctrine\DBAL\Sharding\SQLAzure\SQLAzureShardManager; +use PHPUnit\Framework\TestCase; -class SQLAzureShardManagerTest extends \PHPUnit\Framework\TestCase +class SQLAzureShardManagerTest extends TestCase { public function testNoFederationName() { $this->expectException('Doctrine\DBAL\Sharding\ShardingException'); $this->expectExceptionMessage('SQLAzure requires a federation name to be set during sharding configuration.'); - $conn = $this->createConnection(array('sharding' => array('distributionKey' => 'abc', 'distributionType' => 'integer'))); - $sm = new SQLAzureShardManager($conn); + $conn = $this->createConnection(['sharding' => ['distributionKey' => 'abc', 'distributionType' => 'integer']]); + $sm = new SQLAzureShardManager($conn); } public function testNoDistributionKey() @@ -20,21 +21,21 @@ public function testNoDistributionKey() $this->expectException('Doctrine\DBAL\Sharding\ShardingException'); $this->expectExceptionMessage('SQLAzure requires a distribution key to be set during sharding configuration.'); - $conn = $this->createConnection(array('sharding' => array('federationName' => 'abc', 'distributionType' => 'integer'))); - $sm = new SQLAzureShardManager($conn); + $conn = $this->createConnection(['sharding' => ['federationName' => 'abc', 'distributionType' => 'integer']]); + $sm = new SQLAzureShardManager($conn); } public function testNoDistributionType() { $this->expectException('Doctrine\DBAL\Sharding\ShardingException'); - $conn = $this->createConnection(array('sharding' => array('federationName' => 'abc', 'distributionKey' => 'foo'))); - $sm = new SQLAzureShardManager($conn); + $conn = $this->createConnection(['sharding' => ['federationName' => 'abc', 'distributionKey' => 'foo']]); + $sm = new SQLAzureShardManager($conn); } public function testGetDefaultDistributionValue() { - $conn = $this->createConnection(array('sharding' => array('federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer'))); + $conn = $this->createConnection(['sharding' => ['federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer']]); $sm = new SQLAzureShardManager($conn); self::assertNull($sm->getCurrentDistributionValue()); @@ -42,7 +43,7 @@ public function testGetDefaultDistributionValue() public function testSelectGlobalTransactionActive() { - $conn = $this->createConnection(array('sharding' => array('federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer'))); + $conn = $this->createConnection(['sharding' => ['federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer']]); $conn->expects($this->at(1))->method('isTransactionActive')->will($this->returnValue(true)); $this->expectException('Doctrine\DBAL\Sharding\ShardingException'); @@ -54,7 +55,7 @@ public function testSelectGlobalTransactionActive() public function testSelectGlobal() { - $conn = $this->createConnection(array('sharding' => array('federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer'))); + $conn = $this->createConnection(['sharding' => ['federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer']]); $conn->expects($this->at(1))->method('isTransactionActive')->will($this->returnValue(false)); $conn->expects($this->at(2))->method('exec')->with($this->equalTo('USE FEDERATION ROOT WITH RESET')); @@ -64,7 +65,7 @@ public function testSelectGlobal() public function testSelectShard() { - $conn = $this->createConnection(array('sharding' => array('federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer'))); + $conn = $this->createConnection(['sharding' => ['federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer']]); $conn->expects($this->at(1))->method('isTransactionActive')->will($this->returnValue(true)); $this->expectException('Doctrine\DBAL\Sharding\ShardingException'); @@ -78,7 +79,7 @@ public function testSelectShard() public function testSelectShardNoDistributionValue() { - $conn = $this->createConnection(array('sharding' => array('federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer'))); + $conn = $this->createConnection(['sharding' => ['federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer']]); $conn->expects($this->at(1))->method('isTransactionActive')->will($this->returnValue(false)); $this->expectException('Doctrine\DBAL\Sharding\ShardingException'); @@ -91,7 +92,7 @@ public function testSelectShardNoDistributionValue() private function createConnection(array $params) { $conn = $this->getMockBuilder('Doctrine\DBAL\Connection') - ->setMethods(array('getParams', 'exec', 'isTransactionActive')) + ->setMethods(['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 cf4da5b317d..d3eaf32ccfa 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/ShardChoser/MultiTenantShardChoserTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/ShardChoser/MultiTenantShardChoserTest.php @@ -20,13 +20,14 @@ namespace Doctrine\Tests\DBAL\Sharding\ShardChoser; use Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser; +use PHPUnit\Framework\TestCase; -class MultiTenantShardChoserTest extends \PHPUnit\Framework\TestCase +class MultiTenantShardChoserTest extends TestCase { public function testPickShard() { $choser = new MultiTenantShardChoser(); - $conn = $this->createConnectionMock(); + $conn = $this->createConnectionMock(); self::assertEquals(1, $choser->pickShard(1, $conn)); self::assertEquals(2, $choser->pickShard(2, $conn)); @@ -35,9 +36,8 @@ public function testPickShard() private function createConnectionMock() { return $this->getMockBuilder('Doctrine\DBAL\Sharding\PoolingShardConnection') - ->setMethods(array('connect', 'getParams', 'fetchAll')) + ->setMethods(['connect', 'getParams', 'fetchAll']) ->disableOriginalConstructor() ->getMock(); } } - diff --git a/tests/Doctrine/Tests/DBAL/StatementTest.php b/tests/Doctrine/Tests/DBAL/StatementTest.php index fa22536f2d4..88559c07ceb 100644 --- a/tests/Doctrine/Tests/DBAL/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/StatementTest.php @@ -2,48 +2,44 @@ namespace Doctrine\Tests\DBAL; +use Doctrine\DBAL\Configuration; +use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Logging\SQLLogger; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Statement; -use Doctrine\DBAL\Logging\SQLLogger; +use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use Doctrine\Tests\DbalTestCase; +use Exception; +use PDOStatement; -class StatementTest extends \Doctrine\Tests\DbalTestCase +class StatementTest extends DbalTestCase { - /** - * - * @var \Doctrine\DBAL\Connection - */ + /** @var Connection */ private $conn; - /** - * - * @var \Doctrine\DBAL\Configuration - */ + /** @var Configuration */ private $configuration; - /** - * @var \PDOStatement - */ + /** @var PDOStatement */ private $pdoStatement; protected function setUp() { $this->pdoStatement = $this->getMockBuilder('\PDOStatement') - ->setMethods(array('execute', 'bindParam', 'bindValue')) + ->setMethods(['execute', 'bindParam', 'bindValue']) ->getMock(); - $platform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform(); - $driverConnection = $this->createMock('\Doctrine\DBAL\Driver\Connection'); + $platform = new MockPlatform(); + $driverConnection = $this->createMock('\Doctrine\DBAL\Driver\Connection'); $driverConnection->expects($this->any()) ->method('prepare') ->will($this->returnValue($this->pdoStatement)); - $driver = $this->createMock('\Doctrine\DBAL\Driver'); - $constructorArgs = array( - array( - 'platform' => $platform - ), - $driver - ); - $this->conn = $this->getMockBuilder('\Doctrine\DBAL\Connection') + $driver = $this->createMock('\Doctrine\DBAL\Driver'); + $constructorArgs = [ + ['platform' => $platform], + $driver, + ]; + $this->conn = $this->getMockBuilder('\Doctrine\DBAL\Connection') ->setConstructorArgs($constructorArgs) ->getMock(); $this->conn->expects($this->atLeastOnce()) @@ -58,7 +54,6 @@ protected function setUp() $this->conn->expects($this->any()) ->method('getDriver') ->will($this->returnValue($driver)); - } public function testExecuteCallsLoggerStartQueryWithParametersWhenValuesBound() @@ -86,11 +81,11 @@ public function testExecuteCallsLoggerStartQueryWithParametersWhenValuesBound() public function testExecuteCallsLoggerStartQueryWithParametersWhenParamsPassedToExecute() { - $name = 'foo'; - $var = 'bar'; - $values = array($name => $var); - $types = array(); - $sql = ''; + $name = 'foo'; + $var = 'bar'; + $values = [$name => $var]; + $types = []; + $sql = ''; $logger = $this->createMock('\Doctrine\DBAL\Logging\SQLLogger'); $logger->expects($this->once()) @@ -141,7 +136,7 @@ public function testExecuteCallsLoggerStopQueryOnException() // Needed to satisfy construction of DBALException $this->conn->expects($this->any()) ->method('resolveParams') - ->will($this->returnValue(array())); + ->will($this->returnValue([])); $logger->expects($this->once()) ->method('startQuery'); @@ -151,9 +146,9 @@ public function testExecuteCallsLoggerStopQueryOnException() $this->pdoStatement->expects($this->once()) ->method('execute') - ->will($this->throwException(new \Exception("Mock test exception"))); + ->will($this->throwException(new Exception('Mock test exception'))); - $statement = new Statement("", $this->conn); + $statement = new Statement('', $this->conn); $statement->execute(); } } diff --git a/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php b/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php index 164a609198a..84907e09316 100644 --- a/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php +++ b/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php @@ -2,21 +2,23 @@ namespace Doctrine\Tests\DBAL\Tools\Console; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\Tools\Console\Command\RunSqlCommand; use Doctrine\DBAL\Tools\Console\ConsoleRunner; +use LogicException; +use PHPUnit\Framework\TestCase; +use RuntimeException; use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; -class RunSqlCommandTest extends \PHPUnit\Framework\TestCase +class RunSqlCommandTest extends TestCase { /** @var CommandTester */ private $commandTester; /** @var RunSqlCommand */ private $command; - /** - * @var \Doctrine\DBAL\Connection - */ + /** @var Connection */ private $connectionMock; protected function setUp() @@ -24,12 +26,12 @@ protected function setUp() $application = new Application(); $application->add(new RunSqlCommand()); - $this->command = $application->find('dbal:run-sql'); + $this->command = $application->find('dbal:run-sql'); $this->commandTester = new CommandTester($this->command); $this->connectionMock = $this->createMock('\Doctrine\DBAL\Connection'); $this->connectionMock->method('fetchAll') - ->willReturn(array(array(1))); + ->willReturn([[1]]); $this->connectionMock->method('executeUpdate') ->willReturn(42); @@ -40,12 +42,12 @@ protected function setUp() public function testMissingSqlArgument() { try { - $this->commandTester->execute(array( + $this->commandTester->execute([ 'command' => $this->command->getName(), 'sql' => null, - )); + ]); $this->fail('Expected a runtime exception when omitting sql argument'); - } catch (\RuntimeException $e) { + } catch (RuntimeException $e) { self::assertContains("Argument 'SQL", $e->getMessage()); } } @@ -53,13 +55,13 @@ public function testMissingSqlArgument() public function testIncorrectDepthOption() { try { - $this->commandTester->execute(array( + $this->commandTester->execute([ 'command' => $this->command->getName(), 'sql' => 'SELECT 1', '--depth' => 'string', - )); + ]); $this->fail('Expected a logic exception when executing with a stringy depth'); - } catch (\LogicException $e) { + } catch (LogicException $e) { self::assertContains("Option 'depth'", $e->getMessage()); } } @@ -68,10 +70,10 @@ public function testSelectStatementsPrintsResult() { $this->expectConnectionFetchAll(); - $this->commandTester->execute(array( + $this->commandTester->execute([ 'command' => $this->command->getName(), 'sql' => 'SELECT 1', - )); + ]); self::assertRegExp('@int.*1.*@', $this->commandTester->getDisplay()); self::assertRegExp('@array.*1.*@', $this->commandTester->getDisplay()); @@ -81,10 +83,10 @@ public function testUpdateStatementsPrintsAffectedLines() { $this->expectConnectionExecuteUpdate(); - $this->commandTester->execute(array( + $this->commandTester->execute([ 'command' => $this->command->getName(), 'sql' => 'UPDATE foo SET bar = 42', - )); + ]); self::assertRegExp('@int.*42.*@', $this->commandTester->getDisplay()); self::assertNotRegExp('@array.*1.*@', $this->commandTester->getDisplay()); @@ -114,11 +116,11 @@ public function testStatementsWithFetchResultPrintsResult() { $this->expectConnectionFetchAll(); - $this->commandTester->execute(array( + $this->commandTester->execute([ 'command' => $this->command->getName(), 'sql' => '"WITH bar as (SELECT 1) SELECT * FROM bar', '--force-fetch' => true, - )); + ]); self::assertRegExp('@int.*1.*@', $this->commandTester->getDisplay()); self::assertRegExp('@array.*1.*@', $this->commandTester->getDisplay()); diff --git a/tests/Doctrine/Tests/DBAL/Tools/DumperTest.php b/tests/Doctrine/Tests/DBAL/Tools/DumperTest.php index cf4fe4d560a..2aae261561f 100644 --- a/tests/Doctrine/Tests/DBAL/Tools/DumperTest.php +++ b/tests/Doctrine/Tests/DBAL/Tools/DumperTest.php @@ -9,6 +9,7 @@ use DateTimeZone; use Doctrine\DBAL\Tools\Dumper; use Doctrine\Tests\DbalTestCase; +use stdClass; use function print_r; use function strpos; use function substr; @@ -17,7 +18,7 @@ class DumperTest extends DbalTestCase { public function testExportObject() { - $obj = new \stdClass(); + $obj = new stdClass(); $obj->foo = 'bar'; $obj->bar = 1234; diff --git a/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php b/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php index c6599e66d65..b536c0c1d21 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php @@ -5,31 +5,28 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use Doctrine\Tests\DbalTestCase; use function serialize; -class ArrayTest extends \Doctrine\Tests\DbalTestCase +class ArrayTest extends DbalTestCase { - /** - * @var AbstractPlatform - */ + /** @var AbstractPlatform */ protected $_platform; - /** - * @var Type - */ + /** @var Type */ protected $_type; protected function setUp() { $this->_platform = new MockPlatform(); - $this->_type = Type::getType('array'); + $this->_type = Type::getType('array'); } public function testArrayConvertsToDatabaseValue() { self::assertInternalType( 'string', - $this->_type->convertToDatabaseValue(array(), $this->_platform) + $this->_type->convertToDatabaseValue([], $this->_platform) ); } @@ -37,7 +34,7 @@ public function testArrayConvertsToPHPValue() { self::assertInternalType( 'array', - $this->_type->convertToPHPValue(serialize(array()), $this->_platform) + $this->_type->convertToPHPValue(serialize([]), $this->_platform) ); } diff --git a/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php b/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php index a86b530c247..985c06605c5 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php @@ -2,25 +2,24 @@ namespace Doctrine\Tests\DBAL\Types; +use DateTime; +use DateTimeImmutable; +use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use PHPUnit\Framework\TestCase; +use stdClass; use function date_default_timezone_get; use function date_default_timezone_set; -abstract class BaseDateTypeTestCase extends \PHPUnit\Framework\TestCase +abstract class BaseDateTypeTestCase extends TestCase { - /** - * @var MockPlatform - */ + /** @var MockPlatform */ protected $platform; - /** - * @var \Doctrine\DBAL\Types\Type - */ + /** @var Type */ protected $type; - /** - * @var string - */ + /** @var string */ private $currentTimezone; /** @@ -44,13 +43,13 @@ protected function tearDown() public function testDateConvertsToDatabaseValue() { - self::assertInternalType('string', $this->type->convertToDatabaseValue(new \DateTime(), $this->platform)); + self::assertInternalType('string', $this->type->convertToDatabaseValue(new DateTime(), $this->platform)); } /** - * @dataProvider invalidPHPValuesProvider - * * @param mixed $value + * + * @dataProvider invalidPHPValuesProvider */ public function testInvalidTypeConversionToDatabaseValue($value) { @@ -66,7 +65,7 @@ public function testNullConversion() public function testConvertDateTimeToPHPValue() { - $date = new \DateTime('now'); + $date = new DateTime('now'); self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform)); } @@ -80,7 +79,7 @@ public function testConvertDateTimeToPHPValue() */ public function testConvertDateTimeImmutableToPHPValue() { - $date = new \DateTimeImmutable('now'); + $date = new DateTimeImmutable('now'); self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform)); } @@ -96,7 +95,7 @@ public function testDateTimeImmutableConvertsToDatabaseValue() { self::assertInternalType( 'string', - $this->type->convertToDatabaseValue(new \DateTimeImmutable(), $this->platform) + $this->type->convertToDatabaseValue(new DateTimeImmutable(), $this->platform) ); } @@ -112,7 +111,7 @@ public function invalidPHPValuesProvider() ['10:11:12'], ['2015-01-31'], ['2015-01-31 10:11:12'], - [new \stdClass()], + [new stdClass()], [$this], [27], [-1], diff --git a/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php b/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php index 9881c897960..fbcf5fb9357 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php @@ -3,22 +3,20 @@ namespace Doctrine\Tests\DBAL\Types; use Doctrine\DBAL\ParameterType; +use Doctrine\DBAL\Types\BinaryType; use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use Doctrine\Tests\DbalTestCase; use function base64_encode; use function fopen; use function stream_get_contents; -class BinaryTest extends \Doctrine\Tests\DbalTestCase +class BinaryTest extends DbalTestCase { - /** - * @var \Doctrine\Tests\DBAL\Mocks\MockPlatform - */ + /** @var MockPlatform */ protected $platform; - /** - * @var \Doctrine\DBAL\Types\BinaryType - */ + /** @var BinaryType */ protected $type; /** @@ -42,7 +40,7 @@ public function testReturnsName() public function testReturnsSQLDeclaration() { - self::assertSame('DUMMYBINARY', $this->type->getSQLDeclaration(array(), $this->platform)); + self::assertSame('DUMMYBINARY', $this->type->getSQLDeclaration([], $this->platform)); } public function testBinaryNullConvertsToPHPValue() @@ -78,15 +76,15 @@ public function testThrowsConversionExceptionOnInvalidDatabaseValue($value) public function getInvalidDatabaseValues() { - return array( - array(false), - array(true), - array(0), - array(1), - array(-1), - array(0.0), - array(1.1), - array(-1.1), - ); + return [ + [false], + [true], + [0], + [1], + [-1], + [0.0], + [1.1], + [-1.1], + ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Types/BlobTest.php b/tests/Doctrine/Tests/DBAL/Types/BlobTest.php index 1ee3fefc43c..5500836cfdb 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BlobTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BlobTest.php @@ -2,23 +2,21 @@ namespace Doctrine\Tests\DBAL\Types; +use Doctrine\DBAL\Types\BlobType; use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use Doctrine\Tests\DbalTestCase; use function base64_encode; use function chr; use function fopen; use function stream_get_contents; -class BlobTest extends \Doctrine\Tests\DbalTestCase +class BlobTest extends DbalTestCase { - /** - * @var \Doctrine\Tests\DBAL\Mocks\MockPlatform - */ + /** @var MockPlatform */ protected $platform; - /** - * @var \Doctrine\DBAL\Types\BlobType - */ + /** @var BlobType */ protected $type; /** @@ -27,7 +25,7 @@ class BlobTest extends \Doctrine\Tests\DbalTestCase protected function setUp() { $this->platform = new MockPlatform(); - $this->type = Type::getType('blob'); + $this->type = Type::getType('blob'); } public function testBlobNullConvertsToPHPValue() diff --git a/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php b/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php index 0c5cb3ccecd..21b043d1c70 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php @@ -4,23 +4,20 @@ use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use Doctrine\Tests\DbalTestCase; -class BooleanTest extends \Doctrine\Tests\DbalTestCase +class BooleanTest extends DbalTestCase { - /** - * @var MockPlatform - */ + /** @var MockPlatform */ protected $_platform; - /** - * @var Type - */ + /** @var Type */ protected $_type; protected function setUp() { $this->_platform = new MockPlatform(); - $this->_type = Type::getType('boolean'); + $this->_type = Type::getType('boolean'); } public function testBooleanConvertsToDatabaseValue() diff --git a/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php b/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php index a8847030c29..2740e708e10 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php @@ -3,14 +3,17 @@ namespace Doctrine\Tests\DBAL\Types; use Doctrine\DBAL\Types\ConversionException; +use Exception; +use PHPUnit\Framework\TestCase; +use stdClass; use function tmpfile; -class ConversionExceptionTest extends \PHPUnit\Framework\TestCase +class ConversionExceptionTest extends TestCase { /** - * @dataProvider scalarsProvider - * * @param mixed $scalarValue + * + * @dataProvider scalarsProvider */ public function testConversionFailedInvalidTypeWithScalar($scalarValue) { @@ -24,9 +27,9 @@ public function testConversionFailedInvalidTypeWithScalar($scalarValue) ); } /** - * @dataProvider nonScalarsProvider - * * @param mixed $nonScalar + * + * @dataProvider nonScalarsProvider */ public function testConversionFailedInvalidTypeWithNonScalar($nonScalar) { @@ -42,7 +45,7 @@ public function testConversionFailedInvalidTypeWithNonScalar($nonScalar) public function testConversionFailedFormatPreservesPreviousException() { - $previous = new \Exception(); + $previous = new Exception(); $exception = ConversionException::conversionFailedFormat('foo', 'bar', 'baz', $previous); @@ -60,7 +63,7 @@ public function nonScalarsProvider() [['foo']], [null], [$this], - [new \stdClass()], + [new stdClass()], [tmpfile()], ]; } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php index 7c60986240e..5fd15d812d3 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php @@ -2,28 +2,28 @@ namespace Doctrine\Tests\DBAL\Types; +use DateTime; +use DateTimeImmutable; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\DateImmutableType; use Doctrine\DBAL\Types\Type; +use PHPUnit\Framework\TestCase; +use Prophecy\Prophecy\ObjectProphecy; use function get_class; -class DateImmutableTypeTest extends \PHPUnit\Framework\TestCase +class DateImmutableTypeTest extends TestCase { - /** - * @var \Doctrine\DBAL\Platforms\AbstractPlatform|\Prophecy\Prophecy\ObjectProphecy - */ + /** @var AbstractPlatform|ObjectProphecy */ private $platform; - /** - * @var DateImmutableType - */ + /** @var DateImmutableType */ private $type; protected function setUp() { - $this->type = Type::getType('date_immutable'); + $this->type = Type::getType('date_immutable'); $this->platform = $this->prophesize(AbstractPlatform::class); } @@ -44,7 +44,7 @@ public function testReturnsBindingType() public function testConvertsDateTimeImmutableInstanceToDatabaseValue() { - $date = $this->prophesize(\DateTimeImmutable::class); + $date = $this->prophesize(DateTimeImmutable::class); $this->platform->getDateFormatString()->willReturn('Y-m-d')->shouldBeCalled(); $date->format('Y-m-d')->willReturn('2016-01-01')->shouldBeCalled(); @@ -64,12 +64,12 @@ public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() { $this->expectException(ConversionException::class); - $this->type->convertToDatabaseValue(new \DateTime(), $this->platform->reveal()); + $this->type->convertToDatabaseValue(new DateTime(), $this->platform->reveal()); } public function testConvertsDateTimeImmutableInstanceToPHPValue() { - $date = new \DateTimeImmutable(); + $date = new DateTimeImmutable(); self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform->reveal())); } @@ -85,7 +85,7 @@ public function testConvertsDateStringToPHPValue() $date = $this->type->convertToPHPValue('2016-01-01', $this->platform->reveal()); - self::assertInstanceOf(\DateTimeImmutable::class, $date); + self::assertInstanceOf(DateTimeImmutable::class, $date); self::assertSame('2016-01-01', $date->format('Y-m-d')); } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php b/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php index 61919ec6c87..27d83ae7df7 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php @@ -2,22 +2,21 @@ namespace Doctrine\Tests\DBAL\Types; +use DateInterval; +use DateTime; 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 stdClass; final class DateIntervalTest extends DbalTestCase { - /** - * @var MockPlatform - */ + /** @var MockPlatform */ private $platform; - /** - * @var \Doctrine\DBAL\Types\DateIntervalType - */ + /** @var DateIntervalType */ private $type; /** @@ -33,10 +32,10 @@ protected function setUp() : void public function testDateIntervalConvertsToDatabaseValue() : void { - $interval = new \DateInterval('P2Y1DT1H2M3S'); + $interval = new DateInterval('P2Y1DT1H2M3S'); $expected = '+P02Y00M01DT01H02M03S'; - $actual = $this->type->convertToDatabaseValue($interval, $this->platform); + $actual = $this->type->convertToDatabaseValue($interval, $this->platform); self::assertEquals($expected, $actual); } @@ -45,13 +44,13 @@ public function testDateIntervalConvertsToPHPValue() : void { $interval = $this->type->convertToPHPValue('+P02Y00M01DT01H02M03S', $this->platform); - self::assertInstanceOf(\DateInterval::class, $interval); + self::assertInstanceOf(DateInterval::class, $interval); self::assertEquals('+P02Y00M01DT01H02M03S', $interval->format(DateIntervalType::FORMAT)); } public function testNegativeDateIntervalConvertsToDatabaseValue() : void { - $interval = new \DateInterval('P2Y1DT1H2M3S'); + $interval = new DateInterval('P2Y1DT1H2M3S'); $interval->invert = 1; $actual = $this->type->convertToDatabaseValue($interval, $this->platform); @@ -63,7 +62,7 @@ public function testNegativeDateIntervalConvertsToPHPValue() : void { $interval = $this->type->convertToPHPValue('-P02Y00M01DT01H02M03S', $this->platform); - self::assertInstanceOf(\DateInterval::class, $interval); + self::assertInstanceOf(DateInterval::class, $interval); self::assertEquals('-P02Y00M01DT01H02M03S', $interval->format(DateIntervalType::FORMAT)); } @@ -71,7 +70,7 @@ public function testDateIntervalFormatWithoutSignConvertsToPHPValue() : void { $interval = $this->type->convertToPHPValue('P02Y00M01DT01H02M03S', $this->platform); - self::assertInstanceOf(\DateInterval::class, $interval); + self::assertInstanceOf(DateInterval::class, $interval); self::assertEquals('+P02Y00M01DT01H02M03S', $interval->format(DateIntervalType::FORMAT)); } @@ -124,14 +123,14 @@ public function invalidPHPValuesProvider() : array ['10:11:12'], ['2015-01-31'], ['2015-01-31 10:11:12'], - [new \stdClass()], + [new stdClass()], [$this], [27], [-1], [1.2], [[]], [['an array']], - [new \DateTime()], + [new DateTime()], ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTest.php index c68ebc7f471..6b41eab3c50 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Types; +use DateTime; use Doctrine\DBAL\Types\Type; use function date_default_timezone_set; @@ -21,7 +22,7 @@ public function testDateConvertsToPHPValue() { // Birthday of jwage and also birthday of Doctrine. Send him a present ;) self::assertInstanceOf( - \DateTime::class, + DateTime::class, $this->type->convertToPHPValue('1985-09-01', $this->platform) ); } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php index 9cb1f9c6b72..dfedcca32b1 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php @@ -2,28 +2,28 @@ namespace Doctrine\Tests\DBAL\Types; +use DateTime; +use DateTimeImmutable; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\DateTimeImmutableType; use Doctrine\DBAL\Types\Type; +use PHPUnit\Framework\TestCase; +use Prophecy\Prophecy\ObjectProphecy; use function get_class; -class DateTimeImmutableTypeTest extends \PHPUnit\Framework\TestCase +class DateTimeImmutableTypeTest extends TestCase { - /** - * @var \Doctrine\DBAL\Platforms\AbstractPlatform|\Prophecy\Prophecy\ObjectProphecy - */ + /** @var AbstractPlatform|ObjectProphecy */ private $platform; - /** - * @var DateTimeImmutableType - */ + /** @var DateTimeImmutableType */ private $type; protected function setUp() { - $this->type = Type::getType('datetime_immutable'); + $this->type = Type::getType('datetime_immutable'); $this->platform = $this->prophesize(AbstractPlatform::class); } @@ -44,7 +44,7 @@ public function testReturnsBindingType() public function testConvertsDateTimeImmutableInstanceToDatabaseValue() { - $date = $this->prophesize(\DateTimeImmutable::class); + $date = $this->prophesize(DateTimeImmutable::class); $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(); @@ -64,12 +64,12 @@ public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() { $this->expectException(ConversionException::class); - $this->type->convertToDatabaseValue(new \DateTime(), $this->platform->reveal()); + $this->type->convertToDatabaseValue(new DateTime(), $this->platform->reveal()); } public function testConvertsDateTimeImmutableInstanceToPHPValue() { - $date = new \DateTimeImmutable(); + $date = new DateTimeImmutable(); self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform->reveal())); } @@ -85,7 +85,7 @@ public function testConvertsDateTimeStringToPHPValue() $date = $this->type->convertToPHPValue('2016-01-01 15:58:59', $this->platform->reveal()); - self::assertInstanceOf(\DateTimeImmutable::class, $date); + self::assertInstanceOf(DateTimeImmutable::class, $date); self::assertSame('2016-01-01 15:58:59', $date->format('Y-m-d H:i:s')); } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php index 3b66c260c8d..d104f83a835 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Types; +use DateTime; use Doctrine\DBAL\Types\Type; class DateTimeTest extends BaseDateTypeTestCase @@ -18,10 +19,10 @@ protected function setUp() public function testDateTimeConvertsToDatabaseValue() { - $date = new \DateTime('1985-09-01 10:10:10'); + $date = new DateTime('1985-09-01 10:10:10'); $expected = $date->format($this->platform->getDateTimeTzFormatString()); - $actual = $this->type->convertToDatabaseValue($date, $this->platform); + $actual = $this->type->convertToDatabaseValue($date, $this->platform); self::assertEquals($expected, $actual); } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php index 9563d968082..df47f7b3991 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php @@ -2,28 +2,28 @@ namespace Doctrine\Tests\DBAL\Types; +use DateTime; +use DateTimeImmutable; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\DateTimeTzImmutableType; use Doctrine\DBAL\Types\Type; +use PHPUnit\Framework\TestCase; +use Prophecy\Prophecy\ObjectProphecy; use function get_class; -class DateTimeTzImmutableTypeTest extends \PHPUnit\Framework\TestCase +class DateTimeTzImmutableTypeTest extends TestCase { - /** - * @var \Doctrine\DBAL\Platforms\AbstractPlatform|\Prophecy\Prophecy\ObjectProphecy - */ + /** @var AbstractPlatform|ObjectProphecy */ private $platform; - /** - * @var DateTimeTzImmutableType - */ + /** @var DateTimeTzImmutableType */ private $type; protected function setUp() { - $this->type = Type::getType('datetimetz_immutable'); + $this->type = Type::getType('datetimetz_immutable'); $this->platform = $this->prophesize(AbstractPlatform::class); } @@ -44,7 +44,7 @@ public function testReturnsBindingType() public function testConvertsDateTimeImmutableInstanceToDatabaseValue() { - $date = $this->prophesize(\DateTimeImmutable::class); + $date = $this->prophesize(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(); @@ -64,12 +64,12 @@ public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() { $this->expectException(ConversionException::class); - $this->type->convertToDatabaseValue(new \DateTime(), $this->platform->reveal()); + $this->type->convertToDatabaseValue(new DateTime(), $this->platform->reveal()); } public function testConvertsDateTimeImmutableInstanceToPHPValue() { - $date = new \DateTimeImmutable(); + $date = new DateTimeImmutable(); self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform->reveal())); } @@ -85,7 +85,7 @@ public function testConvertsDateTimeWithTimezoneStringToPHPValue() $date = $this->type->convertToPHPValue('2016-01-01 15:58:59 UTC', $this->platform->reveal()); - self::assertInstanceOf(\DateTimeImmutable::class, $date); + self::assertInstanceOf(DateTimeImmutable::class, $date); self::assertSame('2016-01-01 15:58:59 UTC', $date->format('Y-m-d H:i:s T')); } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php index bcc77b4c989..8f97ff83167 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Types; +use DateTime; use Doctrine\DBAL\Types\Type; class DateTimeTzTest extends BaseDateTypeTestCase @@ -18,10 +19,10 @@ protected function setUp() public function testDateTimeConvertsToDatabaseValue() { - $date = new \DateTime('1985-09-01 10:10:10'); + $date = new DateTime('1985-09-01 10:10:10'); $expected = $date->format($this->platform->getDateTimeTzFormatString()); - $actual = $this->type->convertToDatabaseValue($date, $this->platform); + $actual = $this->type->convertToDatabaseValue($date, $this->platform); self::assertEquals($expected, $actual); } diff --git a/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php b/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php index 9571629af25..aedb6c98bb6 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php @@ -4,23 +4,20 @@ use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use Doctrine\Tests\DbalTestCase; -class DecimalTest extends \Doctrine\Tests\DbalTestCase +class DecimalTest extends DbalTestCase { - /** - * @var MockPlatform - */ + /** @var MockPlatform */ protected $_platform; - /** - * @var Type - */ + /** @var Type */ protected $_type; protected function setUp() { $this->_platform = new MockPlatform(); - $this->_type = Type::getType('decimal'); + $this->_type = Type::getType('decimal'); } public function testDecimalConvertsToPHPValue() diff --git a/tests/Doctrine/Tests/DBAL/Types/FloatTest.php b/tests/Doctrine/Tests/DBAL/Types/FloatTest.php index 036481ce10e..e3fc70a8be9 100644 --- a/tests/Doctrine/Tests/DBAL/Types/FloatTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/FloatTest.php @@ -4,23 +4,20 @@ use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use Doctrine\Tests\DbalTestCase; -class FloatTest extends \Doctrine\Tests\DbalTestCase +class FloatTest extends DbalTestCase { - /** - * @var MockPlatform - */ + /** @var MockPlatform */ protected $_platform; - /** - * @var Type - */ + /** @var Type */ protected $_type; protected function setUp() { $this->_platform = new MockPlatform(); - $this->_type = Type::getType('float'); + $this->_type = Type::getType('float'); } public function testFloatConvertsToPHPValue() diff --git a/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php index cfc40999ef1..439e9de7168 100644 --- a/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php @@ -9,26 +9,22 @@ class GuidTypeTest extends DbalTestCase { - /** - * @var MockPlatform - */ + /** @var MockPlatform */ protected $_platform; - /** - * @var Type - */ + /** @var Type */ protected $_type; protected function setUp() { $this->_platform = new MockPlatform(); - $this->_type = Type::getType('guid'); + $this->_type = Type::getType('guid'); } public function testConvertToPHPValue() { - self::assertInternalType("string", $this->_type->convertToPHPValue("foo", $this->_platform)); - self::assertInternalType("string", $this->_type->convertToPHPValue("", $this->_platform)); + self::assertInternalType('string', $this->_type->convertToPHPValue('foo', $this->_platform)); + self::assertInternalType('string', $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 51d57d5c98e..07fda0d8165 100644 --- a/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php @@ -4,23 +4,20 @@ use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use Doctrine\Tests\DbalTestCase; -class IntegerTest extends \Doctrine\Tests\DbalTestCase +class IntegerTest extends DbalTestCase { - /** - * @var MockPlatform - */ + /** @var MockPlatform */ protected $_platform; - /** - * @var Type - */ + /** @var Type */ protected $_type; protected function setUp() { $this->_platform = new MockPlatform(); - $this->_type = Type::getType('integer'); + $this->_type = Type::getType('integer'); } public function testIntegerConvertsToPHPValue() diff --git a/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php b/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php index 3972002caf8..564371a30b3 100644 --- a/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php @@ -3,22 +3,20 @@ namespace Doctrine\Tests\DBAL\Types; use Doctrine\DBAL\ParameterType; +use Doctrine\DBAL\Types\JsonArrayType; use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use Doctrine\Tests\DbalTestCase; use function base64_encode; use function fopen; use function json_encode; -class JsonArrayTest extends \Doctrine\Tests\DbalTestCase +class JsonArrayTest extends DbalTestCase { - /** - * @var \Doctrine\Tests\DBAL\Mocks\MockPlatform - */ + /** @var MockPlatform */ protected $platform; - /** - * @var \Doctrine\DBAL\Types\JsonArrayType - */ + /** @var JsonArrayType */ protected $type; /** @@ -42,22 +40,22 @@ public function testReturnsName() public function testReturnsSQLDeclaration() { - self::assertSame('DUMMYJSON', $this->type->getSQLDeclaration(array(), $this->platform)); + self::assertSame('DUMMYJSON', $this->type->getSQLDeclaration([], $this->platform)); } public function testJsonNullConvertsToPHPValue() { - self::assertSame(array(), $this->type->convertToPHPValue(null, $this->platform)); + self::assertSame([], $this->type->convertToPHPValue(null, $this->platform)); } public function testJsonEmptyStringConvertsToPHPValue() { - self::assertSame(array(), $this->type->convertToPHPValue('', $this->platform)); + self::assertSame([], $this->type->convertToPHPValue('', $this->platform)); } public function testJsonStringConvertsToPHPValue() { - $value = array('foo' => 'bar', 'bar' => 'foo'); + $value = ['foo' => 'bar', 'bar' => 'foo']; $databaseValue = json_encode($value); $phpValue = $this->type->convertToPHPValue($databaseValue, $this->platform); @@ -66,7 +64,7 @@ public function testJsonStringConvertsToPHPValue() public function testJsonResourceConvertsToPHPValue() { - $value = array('foo' => 'bar', 'bar' => 'foo'); + $value = ['foo' => 'bar', 'bar' => 'foo']; $databaseValue = fopen('data://text/plain;base64,' . base64_encode(json_encode($value)), 'r'); $phpValue = $this->type->convertToPHPValue($databaseValue, $this->platform); diff --git a/tests/Doctrine/Tests/DBAL/Types/JsonTest.php b/tests/Doctrine/Tests/DBAL/Types/JsonTest.php index ddf72b22d79..18ef77a6394 100644 --- a/tests/Doctrine/Tests/DBAL/Types/JsonTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/JsonTest.php @@ -3,22 +3,20 @@ namespace Doctrine\Tests\DBAL\Types; use Doctrine\DBAL\ParameterType; +use Doctrine\DBAL\Types\JsonType; use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use Doctrine\Tests\DbalTestCase; use function base64_encode; use function fopen; use function json_encode; -class JsonTest extends \Doctrine\Tests\DbalTestCase +class JsonTest extends DbalTestCase { - /** - * @var \Doctrine\Tests\DBAL\Mocks\MockPlatform - */ + /** @var MockPlatform */ protected $platform; - /** - * @var \Doctrine\DBAL\Types\JsonType - */ + /** @var JsonType */ protected $type; /** @@ -42,7 +40,7 @@ public function testReturnsName() public function testReturnsSQLDeclaration() { - self::assertSame('DUMMYJSON', $this->type->getSQLDeclaration(array(), $this->platform)); + self::assertSame('DUMMYJSON', $this->type->getSQLDeclaration([], $this->platform)); } public function testJsonNullConvertsToPHPValue() @@ -57,7 +55,7 @@ public function testJsonEmptyStringConvertsToPHPValue() public function testJsonStringConvertsToPHPValue() { - $value = array('foo' => 'bar', 'bar' => 'foo'); + $value = ['foo' => 'bar', 'bar' => 'foo']; $databaseValue = json_encode($value); $phpValue = $this->type->convertToPHPValue($databaseValue, $this->platform); @@ -73,12 +71,12 @@ public function testConversionFailure($data) public function providerFailure() { - return array(array('a'), array('{')); + return [['a'], ['{']]; } public function testJsonResourceConvertsToPHPValue() { - $value = array('foo' => 'bar', 'bar' => 'foo'); + $value = ['foo' => 'bar', 'bar' => 'foo']; $databaseValue = fopen('data://text/plain;base64,' . base64_encode(json_encode($value)), 'r'); $phpValue = $this->type->convertToPHPValue($databaseValue, $this->platform); diff --git a/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php b/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php index bd4fcd8057d..7f1794e0d0c 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php @@ -4,34 +4,32 @@ use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use Doctrine\Tests\DbalTestCase; +use stdClass; use function serialize; -class ObjectTest extends \Doctrine\Tests\DbalTestCase +class ObjectTest extends DbalTestCase { - /** - * @var MockPlatform - */ + /** @var MockPlatform */ protected $_platform; - /** - * @var Type - */ + /** @var Type */ protected $_type; protected function setUp() { $this->_platform = new MockPlatform(); - $this->_type = Type::getType('object'); + $this->_type = Type::getType('object'); } public function testObjectConvertsToDatabaseValue() { - self::assertInternalType('string', $this->_type->convertToDatabaseValue(new \stdClass(), $this->_platform)); + self::assertInternalType('string', $this->_type->convertToDatabaseValue(new stdClass(), $this->_platform)); } public function testObjectConvertsToPHPValue() { - self::assertInternalType('object', $this->_type->convertToPHPValue(serialize(new \stdClass), $this->_platform)); + self::assertInternalType('object', $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 89a50117e15..3d4770a9c43 100644 --- a/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php @@ -4,23 +4,20 @@ use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use Doctrine\Tests\DbalTestCase; -class SmallIntTest extends \Doctrine\Tests\DbalTestCase +class SmallIntTest extends DbalTestCase { - /** - * @var MockPlatform - */ + /** @var MockPlatform */ protected $_platform; - /** - * @var Type - */ + /** @var Type */ protected $_type; protected function setUp() { $this->_platform = new MockPlatform(); - $this->_type = Type::getType('smallint'); + $this->_type = Type::getType('smallint'); } public function testSmallIntConvertsToPHPValue() diff --git a/tests/Doctrine/Tests/DBAL/Types/StringTest.php b/tests/Doctrine/Tests/DBAL/Types/StringTest.php index e968b9f0d99..b19dff22683 100644 --- a/tests/Doctrine/Tests/DBAL/Types/StringTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/StringTest.php @@ -4,28 +4,25 @@ use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use Doctrine\Tests\DbalTestCase; -class StringTest extends \Doctrine\Tests\DbalTestCase +class StringTest extends DbalTestCase { - /** - * @var MockPlatform - */ + /** @var MockPlatform */ protected $_platform; - /** - * @var Type - */ + /** @var Type */ protected $_type; protected function setUp() { $this->_platform = new MockPlatform(); - $this->_type = Type::getType('string'); + $this->_type = Type::getType('string'); } public function testReturnsSqlDeclarationFromPlatformVarchar() { - self::assertEquals("DUMMYVARCHAR()", $this->_type->getSqlDeclaration(array(), $this->_platform)); + self::assertEquals('DUMMYVARCHAR()', $this->_type->getSqlDeclaration([], $this->_platform)); } public function testReturnsDefaultLengthFromPlatformVarchar() @@ -35,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::assertInternalType('string', $this->_type->convertToPHPValue('foo', $this->_platform)); + self::assertInternalType('string', $this->_type->convertToPHPValue('', $this->_platform)); } public function testNullConversion() @@ -46,7 +43,7 @@ public function testNullConversion() public function testSQLConversion() { - self::assertFalse($this->_type->canRequireSQLConversion(), "String type can never require SQL conversion to work."); + 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)); self::assertEquals('t.foo', $this->_type->convertToPHPValueSQL('t.foo', $this->_platform)); } diff --git a/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php index 78ae5917f77..0f7427df3ed 100644 --- a/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php @@ -2,28 +2,28 @@ namespace Doctrine\Tests\DBAL\Types; +use DateTime; +use DateTimeImmutable; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\TimeImmutableType; use Doctrine\DBAL\Types\Type; +use PHPUnit\Framework\TestCase; +use Prophecy\Prophecy\ObjectProphecy; use function get_class; -class TimeImmutableTypeTest extends \PHPUnit\Framework\TestCase +class TimeImmutableTypeTest extends TestCase { - /** - * @var \Doctrine\DBAL\Platforms\AbstractPlatform|\Prophecy\Prophecy\ObjectProphecy - */ + /** @var AbstractPlatform|ObjectProphecy */ private $platform; - /** - * @var TimeImmutableType - */ + /** @var TimeImmutableType */ private $type; protected function setUp() { - $this->type = Type::getType('time_immutable'); + $this->type = Type::getType('time_immutable'); $this->platform = $this->prophesize(AbstractPlatform::class); } @@ -44,7 +44,7 @@ public function testReturnsBindingType() public function testConvertsDateTimeImmutableInstanceToDatabaseValue() { - $date = $this->prophesize(\DateTimeImmutable::class); + $date = $this->prophesize(DateTimeImmutable::class); $this->platform->getTimeFormatString()->willReturn('H:i:s')->shouldBeCalled(); $date->format('H:i:s')->willReturn('15:58:59')->shouldBeCalled(); @@ -64,12 +64,12 @@ public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() { $this->expectException(ConversionException::class); - $this->type->convertToDatabaseValue(new \DateTime(), $this->platform->reveal()); + $this->type->convertToDatabaseValue(new DateTime(), $this->platform->reveal()); } public function testConvertsDateTimeImmutableInstanceToPHPValue() { - $date = new \DateTimeImmutable(); + $date = new DateTimeImmutable(); self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform->reveal())); } @@ -85,7 +85,7 @@ public function testConvertsTimeStringToPHPValue() $date = $this->type->convertToPHPValue('15:58:59', $this->platform->reveal()); - self::assertInstanceOf(\DateTimeImmutable::class, $date); + self::assertInstanceOf(DateTimeImmutable::class, $date); self::assertSame('15:58:59', $date->format('H:i:s')); } diff --git a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php index ebf21284651..870bb23cc98 100644 --- a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php @@ -2,22 +2,22 @@ namespace Doctrine\Tests\DBAL\Types; +use DateTime; +use DateTimeImmutable; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; -use Doctrine\DBAL\Types\VarDateTimeImmutableType; use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\VarDateTimeImmutableType; +use PHPUnit\Framework\TestCase; +use Prophecy\Prophecy\ObjectProphecy; -class VarDateTimeImmutableTypeTest extends \PHPUnit\Framework\TestCase +class VarDateTimeImmutableTypeTest extends TestCase { - /** - * @var \Doctrine\DBAL\Platforms\AbstractPlatform|\Prophecy\Prophecy\ObjectProphecy - */ + /** @var AbstractPlatform|ObjectProphecy */ private $platform; - /** - * @var VarDateTimeImmutableType - */ + /** @var VarDateTimeImmutableType */ private $type; protected function setUp() @@ -26,7 +26,7 @@ protected function setUp() Type::addType('vardatetime_immutable', VarDateTimeImmutableType::class); } - $this->type = Type::getType('vardatetime_immutable'); + $this->type = Type::getType('vardatetime_immutable'); $this->platform = $this->prophesize(AbstractPlatform::class); } @@ -42,7 +42,7 @@ public function testReturnsBindingType() public function testConvertsDateTimeImmutableInstanceToDatabaseValue() { - $date = $this->prophesize(\DateTimeImmutable::class); + $date = $this->prophesize(DateTimeImmutable::class); $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(); @@ -62,12 +62,12 @@ public function testDoesNotSupportMutableDateTimeToDatabaseValueConversion() { $this->expectException(ConversionException::class); - $this->type->convertToDatabaseValue(new \DateTime(), $this->platform->reveal()); + $this->type->convertToDatabaseValue(new DateTime(), $this->platform->reveal()); } public function testConvertsDateTimeImmutableInstanceToPHPValue() { - $date = new \DateTimeImmutable(); + $date = new DateTimeImmutable(); self::assertSame($date, $this->type->convertToPHPValue($date, $this->platform->reveal())); } @@ -83,7 +83,7 @@ public function testConvertsDateishStringToPHPValue() $date = $this->type->convertToPHPValue('2016-01-01 15:58:59.123456 UTC', $this->platform->reveal()); - self::assertInstanceOf(\DateTimeImmutable::class, $date); + 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')); } diff --git a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php index 4af76968cf1..a4e5139d266 100644 --- a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php @@ -2,25 +2,23 @@ namespace Doctrine\Tests\DBAL\Types; +use DateTime; use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; +use Doctrine\Tests\DbalTestCase; -class VarDateTimeTest extends \Doctrine\Tests\DbalTestCase +class VarDateTimeTest extends DbalTestCase { - /** - * @var MockPlatform - */ + /** @var MockPlatform */ protected $_platform; - /** - * @var Type - */ + /** @var Type */ protected $_type; protected function setUp() { $this->_platform = new MockPlatform(); - if (!Type::hasType('vardatetime')) { + if (! Type::hasType('vardatetime')) { Type::addType('vardatetime', 'Doctrine\DBAL\Types\VarDateTimeType'); } $this->_type = Type::getType('vardatetime'); @@ -28,10 +26,10 @@ protected function setUp() public function testDateTimeConvertsToDatabaseValue() { - $date = new \DateTime('1985-09-01 10:10:10'); + $date = new DateTime('1985-09-01 10:10:10'); $expected = $date->format($this->_platform->getDateTimeTzFormatString()); - $actual = $this->_type->convertToDatabaseValue($date, $this->_platform); + $actual = $this->_type->convertToDatabaseValue($date, $this->_platform); self::assertEquals($expected, $actual); } @@ -66,7 +64,7 @@ public function testNullConversion() public function testConvertDateTimeToPHPValue() { - $date = new \DateTime("now"); + $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 ac26d8aa1dd..2c94e29555d 100644 --- a/tests/Doctrine/Tests/DBAL/UtilTest.php +++ b/tests/Doctrine/Tests/DBAL/UtilTest.php @@ -2,73 +2,77 @@ namespace Doctrine\Tests\DBAL; -class UtilTest extends \Doctrine\Tests\DbalTestCase +use Doctrine\DBAL\Driver\OCI8\OCI8Statement; +use Doctrine\Tests\DbalTestCase; + +class UtilTest extends DbalTestCase { public static function dataConvertPositionalToNamedParameters() { - return array( - array( + return [ + [ 'SELECT name FROM users WHERE id = ?', 'SELECT name FROM users WHERE id = :param1', - array(1 => ':param1') - ), - array( + [1 => ':param1'], + ], + [ 'SELECT name FROM users WHERE id = ? AND status = ?', 'SELECT name FROM users WHERE id = :param1 AND status = :param2', - array(1 => ':param1', 2 => ':param2'), - ), - array( + [1 => ':param1', 2 => ':param2'], + ], + [ "UPDATE users SET name = '???', status = ?", "UPDATE users SET name = '???', status = :param1", - array(1 => ':param1'), - ), - array( + [1 => ':param1'], + ], + [ "UPDATE users SET status = ?, name = '???'", "UPDATE users SET status = :param1, name = '???'", - array(1 => ':param1'), - ), - array( + [1 => ':param1'], + ], + [ "UPDATE users SET foo = ?, name = '???', status = ?", "UPDATE users SET foo = :param1, name = '???', status = :param2", - array(1 => ':param1', 2 => ':param2'), - ), - array( + [1 => ':param1', 2 => ':param2'], + ], + [ 'UPDATE users SET name = "???", status = ?', 'UPDATE users SET name = "???", status = :param1', - array(1 => ':param1'), - ), - array( + [1 => ':param1'], + ], + [ 'UPDATE users SET status = ?, name = "???"', 'UPDATE users SET status = :param1, name = "???"', - array(1 => ':param1'), - ), - array( + [1 => ':param1'], + ], + [ 'UPDATE users SET foo = ?, name = "???", status = ?', 'UPDATE users SET foo = :param1, name = "???", status = :param2', - array(1 => ':param1', 2 => ':param2'), - ), - array( + [1 => ':param1', 2 => ':param2'], + ], + [ 'SELECT * FROM users WHERE id = ? AND name = "" AND status = ?', 'SELECT * FROM users WHERE id = :param1 AND name = "" AND status = :param2', - array(1 => ':param1', 2 => ':param2'), - ), - array( + [1 => ':param1', 2 => ':param2'], + ], + [ "SELECT * FROM users WHERE id = ? AND name = '' AND status = ?", "SELECT * FROM users WHERE id = :param1 AND name = '' AND status = :param2", - array(1 => ':param1', 2 => ':param2'), - ) - ); + [1 => ':param1', 2 => ':param2'], + ], + ]; } /** - * @dataProvider dataConvertPositionalToNamedParameters * @param string $inputSQL * @param string $expectedOutputSQL * @param array $expectedOutputParamsMap + * + * @dataProvider dataConvertPositionalToNamedParameters */ public function testConvertPositionalToNamedParameters($inputSQL, $expectedOutputSQL, $expectedOutputParamsMap) { - list($statement, $params) = \Doctrine\DBAL\Driver\OCI8\OCI8Statement::convertPositionalToNamedPlaceholders($inputSQL); + [$statement, $params] = OCI8Statement::convertPositionalToNamedPlaceholders($inputSQL); self::assertEquals($expectedOutputSQL, $statement); self::assertEquals($expectedOutputParamsMap, $params); diff --git a/tests/Doctrine/Tests/DbalFunctionalTestCase.php b/tests/Doctrine/Tests/DbalFunctionalTestCase.php index 17154eac9f6..9fabe2d8101 100644 --- a/tests/Doctrine/Tests/DbalFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DbalFunctionalTestCase.php @@ -1,6 +1,12 @@ close(); - self::$_sharedConn = null; + if (! self::$_sharedConn) { + return; } + + self::$_sharedConn->close(); + self::$_sharedConn = null; } protected function setUp() { - if ( ! isset(self::$_sharedConn)) { + if (! isset(self::$_sharedConn)) { self::$_sharedConn = TestUtil::getConnection(); } $this->_conn = self::$_sharedConn; - $this->_sqlLoggerStack = new \Doctrine\DBAL\Logging\DebugStack(); + $this->_sqlLoggerStack = new DebugStack(); $this->_conn->getConfiguration()->setSQLLogger($this->_sqlLoggerStack); } @@ -57,45 +61,47 @@ protected function tearDown() } } - protected function onNotSuccessfulTest(\Throwable $t) + protected function onNotSuccessfulTest(Throwable $t) { - if ($t instanceof \PHPUnit\Framework\AssertionFailedError) { + if ($t instanceof AssertionFailedError) { throw $t; } - if(isset($this->_sqlLoggerStack->queries) && count($this->_sqlLoggerStack->queries)) { - $queries = ""; - $i = count($this->_sqlLoggerStack->queries); + if (isset($this->_sqlLoggerStack->queries) && count($this->_sqlLoggerStack->queries)) { + $queries = ''; + $i = count($this->_sqlLoggerStack->queries); foreach (array_reverse($this->_sqlLoggerStack->queries) as $query) { - $params = array_map(function($p) { + $params = array_map(static function ($p) { if (is_object($p)) { return get_class($p); } elseif (is_scalar($p)) { - return "'".$p."'"; + return "'" . $p . "'"; } return var_export($p, true); - }, $query['params'] ?: array()); - $queries .= $i.". SQL: '".$query['sql']."' Params: ".implode(", ", $params).PHP_EOL; + }, $query['params'] ?: []); + $queries .= $i . ". SQL: '" . $query['sql'] . "' Params: " . implode(', ', $params) . PHP_EOL; $i--; } - $trace = $t->getTrace(); - $traceMsg = ""; - foreach($trace as $part) { - if(isset($part['file'])) { - if(strpos($part['file'], "PHPUnit/") !== false) { - // Beginning with PHPUnit files we don't print the trace anymore. - break; - } + $trace = $t->getTrace(); + $traceMsg = ''; + foreach ($trace as $part) { + if (! isset($part['file'])) { + continue; + } - $traceMsg .= $part['file'].":".$part['line'].PHP_EOL; + if (strpos($part['file'], 'PHPUnit/') !== false) { + // Beginning with PHPUnit files we don't print the trace anymore. + break; } + + $traceMsg .= $part['file'] . ':' . $part['line'] . PHP_EOL; } - $message = "[".get_class($t)."] ".$t->getMessage().PHP_EOL.PHP_EOL."With queries:".PHP_EOL.$queries.PHP_EOL."Trace:".PHP_EOL.$traceMsg; + $message = '[' . get_class($t) . '] ' . $t->getMessage() . PHP_EOL . PHP_EOL . 'With queries:' . PHP_EOL . $queries . PHP_EOL . 'Trace:' . PHP_EOL . $traceMsg; - throw new \Exception($message, (int) $t->getCode(), $t); + throw new Exception($message, (int) $t->getCode(), $t); } throw $t; } diff --git a/tests/Doctrine/Tests/DbalPerformanceTestCase.php b/tests/Doctrine/Tests/DbalPerformanceTestCase.php index 0422e5aa987..bfc60201bef 100644 --- a/tests/Doctrine/Tests/DbalPerformanceTestCase.php +++ b/tests/Doctrine/Tests/DbalPerformanceTestCase.php @@ -1,17 +1,15 @@ startTime, "Test timing was started"); - self::assertNotNull($this->runTime, "Test timing was stopped"); + self::assertNotNull($this->startTime, 'Test timing was started'); + self::assertNotNull($this->runTime, 'Test timing was stopped'); } /** diff --git a/tests/Doctrine/Tests/DbalPerformanceTestListener.php b/tests/Doctrine/Tests/DbalPerformanceTestListener.php index 46085829434..06e8ce77e96 100644 --- a/tests/Doctrine/Tests/DbalPerformanceTestListener.php +++ b/tests/Doctrine/Tests/DbalPerformanceTestListener.php @@ -11,15 +11,12 @@ /** * Listener for collecting and reporting results of performance tests - * - * @author Bill Schaller */ class DbalPerformanceTestListener implements TestListener { use TestListenerDefaultImplementation; - /** - * @var string[][] - */ + + /** @var string[][] */ private $timings = []; /** @@ -28,18 +25,19 @@ class DbalPerformanceTestListener implements TestListener public function endTest(Test $test, float $time) : void { // This listener only applies to performance tests. - if ($test instanceof \Doctrine\Tests\DbalPerformanceTestCase) - { - // we identify perf tests by class, method, and dataset - $class = str_replace('Doctrine\Tests\DBAL\Performance\\', '', get_class($test)); + if (! ($test instanceof DbalPerformanceTestCase)) { + return; + } - if (!isset($this->timings[$class])) { - $this->timings[$class] = []; - } + // we identify perf tests by class, method, and dataset + $class = str_replace('Doctrine\Tests\DBAL\Performance\\', '', get_class($test)); - // Store timing data for each test in the order they were run. - $this->timings[$class][$test->getName(true)] = $test->getTime(); + if (! isset($this->timings[$class])) { + $this->timings[$class] = []; } + + // Store timing data for each test in the order they were run. + $this->timings[$class][$test->getName(true)] = $test->getTime(); } /** @@ -50,15 +48,17 @@ public function endTest(Test $test, float $time) : void */ public function __destruct() { - if (!empty($this->timings)) { - // Report timings. - print("\nPerformance test results:\n\n"); + if (empty($this->timings)) { + return; + } + + // Report timings. + print "\nPerformance test results:\n\n"; - foreach($this->timings as $class => $tests) { - printf("%s:\n", $class); - foreach($tests as $test => $time) { - printf("\t%s: %.3f seconds\n", $test, $time); - } + foreach ($this->timings as $class => $tests) { + printf("%s:\n", $class); + foreach ($tests as $test => $time) { + printf("\t%s: %.3f seconds\n", $test, $time); } } } diff --git a/tests/Doctrine/Tests/DbalTestCase.php b/tests/Doctrine/Tests/DbalTestCase.php index b577893e6f1..8664141c03e 100644 --- a/tests/Doctrine/Tests/DbalTestCase.php +++ b/tests/Doctrine/Tests/DbalTestCase.php @@ -2,9 +2,11 @@ namespace Doctrine\Tests; +use PHPUnit\Framework\TestCase; + /** * Base testcase class for all dbal testcases. */ -abstract class DbalTestCase extends \PHPUnit\Framework\TestCase +abstract class DbalTestCase extends TestCase { } diff --git a/tests/Doctrine/Tests/Mocks/ConnectionMock.php b/tests/Doctrine/Tests/Mocks/ConnectionMock.php index fb5dcc47b4d..989b063adc6 100644 --- a/tests/Doctrine/Tests/Mocks/ConnectionMock.php +++ b/tests/Doctrine/Tests/Mocks/ConnectionMock.php @@ -1,23 +1,19 @@ _platformMock; } - /** - * @override - */ - public function insert($tableName, array $data, array $types = array()) + public function insert($tableName, array $data, array $types = []) { $this->_inserts[$tableName][] = $data; } - /** - * @override - */ public function lastInsertId($seqName = null) { return $this->_lastInsertId; } - /** - * @override - */ public function quote($input, $type = null) { if (is_string($input)) { @@ -74,7 +58,7 @@ public function getInserts() public function reset() { - $this->_inserts = array(); + $this->_inserts = []; $this->_lastInsertId = 0; } } diff --git a/tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php b/tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php index 021746831af..231d6dbc5dc 100644 --- a/tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php +++ b/tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php @@ -3,66 +3,61 @@ namespace Doctrine\Tests\Mocks; use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Platforms\AbstractPlatform; -class DatabasePlatformMock extends \Doctrine\DBAL\Platforms\AbstractPlatform +class DatabasePlatformMock extends AbstractPlatform { - /** - * @var string - */ - private $_sequenceNextValSql = ""; + /** @var string */ + private $_sequenceNextValSql = ''; - /** - * @var bool - */ + /** @var bool */ private $_prefersIdentityColumns = true; - /** - * @var bool - */ + /** @var bool */ private $_prefersSequences = false; - /** - * @override - */ public function prefersIdentityColumns() { return $this->_prefersIdentityColumns; } - /** - * @override - */ public function prefersSequences() { return $this->_prefersSequences; } - /** @override */ public function getSequenceNextValSQL($sequenceName) { return $this->_sequenceNextValSql; } - /** @override */ - public function getBooleanTypeDeclarationSQL(array $field) {} + public function getBooleanTypeDeclarationSQL(array $field) + { + } - /** @override */ - public function getIntegerTypeDeclarationSQL(array $field) {} + public function getIntegerTypeDeclarationSQL(array $field) + { + } - /** @override */ - public function getBigIntTypeDeclarationSQL(array $field) {} + public function getBigIntTypeDeclarationSQL(array $field) + { + } - /** @override */ - public function getSmallIntTypeDeclarationSQL(array $field) {} + public function getSmallIntTypeDeclarationSQL(array $field) + { + } - /** @override */ - protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) {} + protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) + { + } - /** @override */ - public function getVarcharTypeDeclarationSQL(array $field) {} + public function getVarcharTypeDeclarationSQL(array $field) + { + } - /** @override */ - public function getClobTypeDeclarationSQL(array $field) {} + public function getClobTypeDeclarationSQL(array $field) + { + } /* MOCK API */ @@ -85,11 +80,11 @@ public function getName() { return 'mock'; } - protected function initializeDoctrineTypeMappings() { + protected function initializeDoctrineTypeMappings() + { } protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) { - } /** * Gets the SQL Snippet used to declare a BLOB column type. diff --git a/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php b/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php index 760dbff40cf..7b8872f2ea8 100644 --- a/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php +++ b/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php @@ -2,22 +2,41 @@ namespace Doctrine\Tests\Mocks; +use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\ParameterType; -class DriverConnectionMock implements \Doctrine\DBAL\Driver\Connection +class DriverConnectionMock implements Connection { - public function prepare($prepareString) {} - public function query() {} + public function prepare($prepareString) + { + } + public function query() + { + } 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() {} + public function exec($statement) + { + } + public function lastInsertId($name = null) + { + } + public function beginTransaction() + { + } + public function commit() + { + } + public function rollBack() + { + } + public function errorCode() + { + } + public function errorInfo() + { + } } diff --git a/tests/Doctrine/Tests/Mocks/DriverMock.php b/tests/Doctrine/Tests/Mocks/DriverMock.php index 61b2d992aff..432bb9135ac 100644 --- a/tests/Doctrine/Tests/Mocks/DriverMock.php +++ b/tests/Doctrine/Tests/Mocks/DriverMock.php @@ -2,53 +2,36 @@ namespace Doctrine\Tests\Mocks; +use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\AbstractSchemaManager; +use Throwable; -class DriverMock implements \Doctrine\DBAL\Driver +class DriverMock implements Driver { - /** - * @var DatabasePlatformMock - */ + /** @var DatabasePlatformMock */ private $_platformMock; - /** - * @var AbstractSchemaManager - */ + /** @var AbstractSchemaManager */ private $_schemaManagerMock; - public function connect(array $params, $username = null, $password = null, array $driverOptions = array()) + public function connect(array $params, $username = null, $password = null, array $driverOptions = []) { return new DriverConnectionMock(); } - /** - * Constructs the Sqlite PDO DSN. - * - * @return string The DSN. - * @override - */ - protected function _constructPdoDsn(array $params) - { - return ""; - } - - /** - * @override - */ public function getDatabasePlatform() { - if ( ! $this->_platformMock) { - $this->_platformMock = new DatabasePlatformMock; + if (! $this->_platformMock) { + $this->_platformMock = new DatabasePlatformMock(); } return $this->_platformMock; } - /** - * @override - */ - public function getSchemaManager(\Doctrine\DBAL\Connection $conn) + public function getSchemaManager(Connection $conn) { - if($this->_schemaManagerMock == null) { + if ($this->_schemaManagerMock === null) { return new SchemaManagerMock($conn); } @@ -57,7 +40,7 @@ public function getSchemaManager(\Doctrine\DBAL\Connection $conn) /* MOCK API */ - public function setDatabasePlatform(\Doctrine\DBAL\Platforms\AbstractPlatform $platform) + public function setDatabasePlatform(AbstractPlatform $platform) { $this->_platformMock = $platform; } @@ -72,12 +55,12 @@ public function getName() return 'mock'; } - public function getDatabase(\Doctrine\DBAL\Connection $conn) + public function getDatabase(Connection $conn) { return; } - public function convertExceptionCode(\Exception $exception) + public function convertExceptionCode(Throwable $exception) { return 0; } diff --git a/tests/Doctrine/Tests/Mocks/DriverResultStatementMock.php b/tests/Doctrine/Tests/Mocks/DriverResultStatementMock.php index 04c085c7459..46573c39494 100644 --- a/tests/Doctrine/Tests/Mocks/DriverResultStatementMock.php +++ b/tests/Doctrine/Tests/Mocks/DriverResultStatementMock.php @@ -3,7 +3,8 @@ namespace Doctrine\Tests\Mocks; use Doctrine\DBAL\Driver\ResultStatement; +use IteratorAggregate; -interface DriverResultStatementMock extends ResultStatement, \IteratorAggregate +interface DriverResultStatementMock extends ResultStatement, IteratorAggregate { } diff --git a/tests/Doctrine/Tests/Mocks/DriverStatementMock.php b/tests/Doctrine/Tests/Mocks/DriverStatementMock.php index 62f09464c0f..5c14d6962e2 100644 --- a/tests/Doctrine/Tests/Mocks/DriverStatementMock.php +++ b/tests/Doctrine/Tests/Mocks/DriverStatementMock.php @@ -3,7 +3,8 @@ namespace Doctrine\Tests\Mocks; use Doctrine\DBAL\Driver\Statement; +use IteratorAggregate; -interface DriverStatementMock extends Statement, \IteratorAggregate +interface DriverStatementMock extends Statement, IteratorAggregate { } diff --git a/tests/Doctrine/Tests/Mocks/SchemaManagerMock.php b/tests/Doctrine/Tests/Mocks/SchemaManagerMock.php index d4c3c28c004..6eccd68609e 100644 --- a/tests/Doctrine/Tests/Mocks/SchemaManagerMock.php +++ b/tests/Doctrine/Tests/Mocks/SchemaManagerMock.php @@ -2,12 +2,17 @@ namespace Doctrine\Tests\Mocks; -class SchemaManagerMock extends \Doctrine\DBAL\Schema\AbstractSchemaManager +use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Schema\AbstractSchemaManager; + +class SchemaManagerMock extends AbstractSchemaManager { - public function __construct(\Doctrine\DBAL\Connection $conn) + public function __construct(Connection $conn) { parent::__construct($conn); } - protected function _getPortableTableColumnDefinition($tableColumn) {} -} \ No newline at end of file + protected function _getPortableTableColumnDefinition($tableColumn) + { + } +} diff --git a/tests/Doctrine/Tests/TestUtil.php b/tests/Doctrine/Tests/TestUtil.php index be90e6c8ae8..37553595490 100644 --- a/tests/Doctrine/Tests/TestUtil.php +++ b/tests/Doctrine/Tests/TestUtil.php @@ -11,14 +11,10 @@ /** * TestUtil is a class with static utility methods used during tests. - * - * @author robo */ class TestUtil { - /** - * @var bool Whether the database schema is initialized. - */ + /** @var bool Whether the database schema is initialized. */ private static $initialized = false; /** @@ -51,7 +47,8 @@ public static function getConnection() return $conn; } - private static function getConnectionParams() { + private static function getConnectionParams() + { if (self::hasRequiredConnectionParams()) { return self::getSpecifiedConnectionParams(); } @@ -78,16 +75,17 @@ private static function hasRequiredConnectionParams() ); } - private static function getSpecifiedConnectionParams() { + private static function getSpecifiedConnectionParams() + { $realDbParams = self::getParamsForMainConnection(); - $tmpDbParams = self::getParamsForTemporaryConnection(); + $tmpDbParams = self::getParamsForTemporaryConnection(); $realConn = DriverManager::getConnection($realDbParams); // Connect to tmpdb in order to drop and create the real test db. $tmpConn = DriverManager::getConnection($tmpDbParams); - $platform = $tmpConn->getDatabasePlatform(); + $platform = $tmpConn->getDatabasePlatform(); if (! self::$initialized) { if ($platform->supportsCreateDropDatabase()) { @@ -101,7 +99,7 @@ private static function getSpecifiedConnectionParams() { $sm = $realConn->getSchemaManager(); $schema = $sm->createSchema(); - $stmts = $schema->toDropSql($realConn->getDatabasePlatform()); + $stmts = $schema->toDropSql($realConn->getDatabasePlatform()); foreach ($stmts as $stmt) { $realConn->exec($stmt); @@ -120,10 +118,10 @@ private static function getFallbackConnectionParams() Assert::markTestSkipped('PDO SQLite extension is not loaded'); } - $params = array( + $params = [ 'driver' => 'pdo_sqlite', - 'memory' => true - ); + 'memory' => true, + ]; if (isset($GLOBALS['db_path'])) { $params['path'] = $GLOBALS['db_path']; @@ -133,26 +131,29 @@ private static function getFallbackConnectionParams() return $params; } - private static function addDbEventSubscribers(Connection $conn) { - if (isset($GLOBALS['db_event_subscribers'])) { - $evm = $conn->getEventManager(); - foreach (explode(",", $GLOBALS['db_event_subscribers']) as $subscriberClass) { - $subscriberInstance = new $subscriberClass(); - $evm->addEventSubscriber($subscriberInstance); - } + private static function addDbEventSubscribers(Connection $conn) + { + if (! isset($GLOBALS['db_event_subscribers'])) { + return; + } + + $evm = $conn->getEventManager(); + foreach (explode(',', $GLOBALS['db_event_subscribers']) as $subscriberClass) { + $subscriberInstance = new $subscriberClass(); + $evm->addEventSubscriber($subscriberInstance); } } private static function getParamsForTemporaryConnection() { - $connectionParams = array( + $connectionParams = [ 'driver' => $GLOBALS['tmpdb_type'], 'user' => $GLOBALS['tmpdb_username'], 'password' => $GLOBALS['tmpdb_password'], 'host' => $GLOBALS['tmpdb_host'], 'dbname' => null, - 'port' => $GLOBALS['tmpdb_port'] - ); + 'port' => $GLOBALS['tmpdb_port'], + ]; if (isset($GLOBALS['tmpdb_name'])) { $connectionParams['dbname'] = $GLOBALS['tmpdb_name']; @@ -171,14 +172,14 @@ private static function getParamsForTemporaryConnection() private static function getParamsForMainConnection() { - $connectionParams = array( + $connectionParams = [ 'driver' => $GLOBALS['db_type'], 'user' => $GLOBALS['db_username'], 'password' => $GLOBALS['db_password'], 'host' => $GLOBALS['db_host'], 'dbname' => $GLOBALS['db_name'], - 'port' => $GLOBALS['db_port'] - ); + 'port' => $GLOBALS['db_port'], + ]; if (isset($GLOBALS['db_server'])) { $connectionParams['server'] = $GLOBALS['db_server']; diff --git a/tests/Doctrine/Tests/Types/MySqlPointType.php b/tests/Doctrine/Tests/Types/MySqlPointType.php index d325cb272d6..7e95418bc18 100644 --- a/tests/Doctrine/Tests/Types/MySqlPointType.php +++ b/tests/Doctrine/Tests/Types/MySqlPointType.php @@ -20,6 +20,6 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla public function getMappedDatabaseTypes(AbstractPlatform $platform) { - return array('point'); + return ['point']; } } diff --git a/tests/continuousphp/bootstrap.php b/tests/continuousphp/bootstrap.php index feaa1887e6a..cfdfb40eb1a 100644 --- a/tests/continuousphp/bootstrap.php +++ b/tests/continuousphp/bootstrap.php @@ -2,7 +2,7 @@ declare(strict_types=1); -(function () : void { +(static function () : void { $pos = array_search('--coverage-clover', $_SERVER['argv'], true); if ($pos === false) { @@ -11,7 +11,7 @@ $file = $_SERVER['argv'][$pos + 1]; - register_shutdown_function(function () use ($file) : void { + register_shutdown_function(static function () use ($file) : void { $cmd = 'wget https://github.com/scrutinizer-ci/ocular/releases/download/1.5.2/ocular.phar' . ' && php ocular.phar code-coverage:upload --format=php-clover ' . escapeshellarg($file); diff --git a/tests/phpstan-polyfill.php b/tests/phpstan-polyfill.php index 13b5aa1e185..f27e09de3a0 100644 --- a/tests/phpstan-polyfill.php +++ b/tests/phpstan-polyfill.php @@ -2,7 +2,7 @@ declare(strict_types=1); -(function () : void { +(static function () : void { foreach (['ibm_db2', 'mysqli', 'oci8', 'sqlsrv', 'pgsql'] as $extension) { if (extension_loaded($extension)) { continue; From 9efa3e4166d41c2bbb685213ab5d6e0e1019d92b Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sun, 23 Sep 2018 14:44:03 -0700 Subject: [PATCH 28/76] Manual fixes --- .../Doctrine/Tests/DBAL/ConfigurationTest.php | 17 - tests/Doctrine/Tests/DBAL/ConnectionTest.php | 127 ++--- .../DBAL/Driver/AbstractDB2DriverTest.php | 3 +- .../Tests/DBAL/Driver/AbstractDriverTest.php | 59 ++- .../DBAL/Driver/AbstractMySQLDriverTest.php | 9 +- .../DBAL/Driver/AbstractOracleDriverTest.php | 3 +- .../Driver/AbstractPostgreSQLDriverTest.php | 33 +- .../Driver/AbstractSQLAnywhereDriverTest.php | 64 +-- .../Driver/AbstractSQLServerDriverTest.php | 58 ++- .../DBAL/Driver/AbstractSQLiteDriverTest.php | 3 +- .../Driver/DrizzlePDOMySql/DriverTest.php | 9 +- .../DBAL/Driver/IBMDB2/DB2ConnectionTest.php | 2 +- .../Driver/Mysqli/MysqliConnectionTest.php | 2 +- .../DBAL/Driver/OCI8/OCI8ConnectionTest.php | 2 +- .../DBAL/Driver/OCI8/OCI8StatementTest.php | 7 +- .../Tests/DBAL/Driver/PDOPgSql/DriverTest.php | 7 +- .../SQLAnywhere/SQLAnywhereConnectionTest.php | 2 +- .../Driver/SQLSrv/SQLSrvConnectionTest.php | 2 +- .../DBAL/Events/MysqlSessionInitTest.php | 3 +- .../DBAL/Events/OracleSessionInitTest.php | 5 +- .../Tests/DBAL/Events/SQLSessionInitTest.php | 3 +- .../InvalidArgumentExceptionTest.php | 19 +- .../Tests/DBAL/Functional/BlobTest.php | 30 +- .../Tests/DBAL/Functional/ConnectionTest.php | 152 +++--- .../Tests/DBAL/Functional/DataAccessTest.php | 210 ++++---- .../Functional/Driver/AbstractDriverTest.php | 13 +- .../Driver/IBMDB2/DB2DriverTest.php | 2 +- .../Driver/IBMDB2/DB2StatementTest.php | 4 +- .../Driver/Mysqli/ConnectionTest.php | 7 +- .../Functional/Driver/Mysqli/DriverTest.php | 2 +- .../Functional/Driver/OCI8/DriverTest.php | 2 +- .../Driver/OCI8/OCI8ConnectionTest.php | 12 +- .../Functional/Driver/OCI8/StatementTest.php | 7 +- .../Functional/Driver/PDOConnectionTest.php | 6 +- .../Functional/Driver/PDOMySql/DriverTest.php | 2 +- .../Driver/PDOOracle/DriverTest.php | 2 +- .../Functional/Driver/PDOPgSql/DriverTest.php | 12 +- .../Driver/PDOPgsqlConnectionTest.php | 10 +- .../Driver/PDOSqlite/DriverTest.php | 2 +- .../Driver/PDOSqlsrv/DriverTest.php | 4 +- .../Driver/SQLAnywhere/ConnectionTest.php | 6 +- .../Driver/SQLAnywhere/DriverTest.php | 10 +- .../Driver/SQLAnywhere/StatementTest.php | 6 +- .../Functional/Driver/SQLSrv/DriverTest.php | 2 +- .../Driver/SQLSrv/StatementTest.php | 4 +- .../Tests/DBAL/Functional/ExceptionTest.php | 88 ++-- .../Functional/LikeWildcardsEscapingTest.php | 4 +- .../Tests/DBAL/Functional/LoggingTest.php | 25 +- .../Functional/MasterSlaveConnectionTest.php | 13 +- .../DBAL/Functional/ModifyLimitQueryTest.php | 80 +-- .../DBAL/Functional/NamedParametersTest.php | 26 +- .../DBAL/Functional/PDOStatementTest.php | 10 +- .../Platform/DateExpressionTest.php | 8 +- .../Tests/DBAL/Functional/PortabilityTest.php | 10 +- .../Tests/DBAL/Functional/ResultCacheTest.php | 36 +- .../Schema/Db2SchemaManagerTest.php | 9 +- .../Schema/DrizzleSchemaManagerTest.php | 13 +- .../Schema/MySqlSchemaManagerTest.php | 108 ++-- .../Schema/OracleSchemaManagerTest.php | 57 +-- .../Schema/PostgreSqlSchemaManagerTest.php | 174 ++++--- .../Schema/SQLAnywhereSchemaManagerTest.php | 16 +- .../Schema/SQLServerSchemaManagerTest.php | 40 +- .../SchemaManagerFunctionalTestCase.php | 460 +++++++++--------- .../Schema/SqliteSchemaManagerTest.php | 64 +-- .../Tests/DBAL/Functional/StatementTest.php | 72 +-- .../DBAL/Functional/TableGeneratorTest.php | 10 +- .../DBAL/Functional/TemporaryTableTest.php | 52 +- .../DBAL/Functional/Ticket/DBAL168Test.php | 6 +- .../DBAL/Functional/Ticket/DBAL202Test.php | 24 +- .../DBAL/Functional/Ticket/DBAL421Test.php | 8 +- .../DBAL/Functional/Ticket/DBAL461Test.php | 6 +- .../DBAL/Functional/Ticket/DBAL510Test.php | 6 +- .../DBAL/Functional/Ticket/DBAL630Test.php | 54 +- .../DBAL/Functional/Ticket/DBAL752Test.php | 6 +- .../DBAL/Functional/TypeConversionTest.php | 10 +- .../DBAL/Functional/Types/BinaryTest.php | 8 +- .../Tests/DBAL/Functional/WriteTest.php | 110 ++--- .../Tests/DBAL/Mocks/MockPlatform.php | 27 +- .../TypeConversionPerformanceTest.php | 2 +- .../AbstractMySQLPlatformTestCase.php | 182 +++---- .../Platforms/AbstractPlatformTestCase.php | 275 ++++++----- .../AbstractPostgreSqlPlatformTestCase.php | 148 +++--- .../AbstractSQLServerPlatformTestCase.php | 302 ++++++------ .../Tests/DBAL/Platforms/DB2PlatformTest.php | 222 ++++----- .../Platforms/MariaDb1027PlatformTest.php | 8 +- .../DBAL/Platforms/MySQL57PlatformTest.php | 8 +- .../DBAL/Platforms/MySqlPlatformTest.php | 4 +- .../DBAL/Platforms/OraclePlatformTest.php | 156 +++--- .../Platforms/PostgreSQL100PlatformTest.php | 2 +- .../Platforms/PostgreSQL91PlatformTest.php | 6 +- .../Platforms/PostgreSQL92PlatformTest.php | 16 +- .../Platforms/PostgreSQL94PlatformTest.php | 8 +- .../DBAL/Platforms/PostgreSqlPlatformTest.php | 2 +- .../Platforms/SQLAnywhere11PlatformTest.php | 4 +- .../Platforms/SQLAnywhere12PlatformTest.php | 32 +- .../Platforms/SQLAnywhere16PlatformTest.php | 8 +- .../Platforms/SQLAnywherePlatformTest.php | 367 +++++++------- .../Platforms/SQLServer2008PlatformTest.php | 2 +- .../Platforms/SQLServer2012PlatformTest.php | 70 +-- .../DBAL/Platforms/SQLServerPlatformTest.php | 4 +- .../DBAL/Platforms/SqlitePlatformTest.php | 131 ++--- .../Tests/DBAL/Portability/StatementTest.php | 5 +- .../Expression/ExpressionBuilderTest.php | 3 +- .../Tests/DBAL/Query/QueryBuilderTest.php | 7 +- .../Tests/DBAL/SQLParserUtilsTest.php | 3 +- .../Tests/DBAL/Schema/ComparatorTest.php | 47 +- .../DBAL/Schema/ForeignKeyConstraintTest.php | 7 +- .../DBAL/Schema/MySqlInheritCharsetTest.php | 5 +- .../DBAL/Schema/MySqlSchemaManagerTest.php | 11 +- .../Tests/DBAL/Schema/SchemaDiffTest.php | 21 +- .../Doctrine/Tests/DBAL/Schema/SchemaTest.php | 21 +- .../SingleDatabaseSynchronizerTest.php | 21 +- .../Tests/DBAL/Schema/TableDiffTest.php | 3 +- .../Doctrine/Tests/DBAL/Schema/TableTest.php | 51 +- .../Visitor/CreateSchemaSqlCollectorTest.php | 8 +- .../Visitor/DropSchemaSqlCollectorTest.php | 16 +- .../Schema/Visitor/SchemaSqlCollectorTest.php | 5 +- .../Sharding/PoolingShardConnectionTest.php | 84 ++-- .../DBAL/Sharding/PoolingShardManagerTest.php | 18 +- .../SQLAzure/MultiTenantVisitorTest.php | 17 - .../SQLAzure/SQLAzureShardManagerTest.php | 25 +- .../MultiTenantShardChoserTest.php | 20 +- tests/Doctrine/Tests/DBAL/StatementTest.php | 18 +- .../DBAL/Tools/Console/RunSqlCommandTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/ArrayTest.php | 21 +- .../Tests/DBAL/Types/BaseDateTypeTestCase.php | 5 +- .../Doctrine/Tests/DBAL/Types/BooleanTest.php | 14 +- .../DBAL/Types/ConversionExceptionTest.php | 6 +- tests/Doctrine/Tests/DBAL/Types/DateTest.php | 5 +- .../Tests/DBAL/Types/DateTimeTest.php | 3 +- .../Tests/DBAL/Types/DateTimeTzTest.php | 3 +- .../Doctrine/Tests/DBAL/Types/DecimalTest.php | 12 +- tests/Doctrine/Tests/DBAL/Types/FloatTest.php | 16 +- .../Tests/DBAL/Types/GuidTypeTest.php | 20 +- .../Doctrine/Tests/DBAL/Types/IntegerTest.php | 14 +- tests/Doctrine/Tests/DBAL/Types/JsonTest.php | 3 +- .../Doctrine/Tests/DBAL/Types/ObjectTest.php | 21 +- .../Tests/DBAL/Types/SmallIntTest.php | 14 +- .../Doctrine/Tests/DBAL/Types/StringTest.php | 24 +- tests/Doctrine/Tests/DBAL/Types/TimeTest.php | 3 +- .../Tests/DBAL/Types/VarDateTimeTest.php | 28 +- tests/Doctrine/Tests/DBAL/UtilTest.php | 6 +- .../Doctrine/Tests/DbalFunctionalTestCase.php | 32 +- .../Tests/DbalPerformanceTestListener.php | 2 +- tests/Doctrine/Tests/Mocks/ConnectionMock.php | 28 +- .../Tests/Mocks/DatabasePlatformMock.php | 47 +- tests/Doctrine/Tests/Mocks/DriverMock.php | 23 +- tests/Doctrine/Tests/Mocks/TaskMock.php | 84 ---- tests/Doctrine/Tests/Types/CommentedType.php | 9 + tests/Doctrine/Tests/Types/MySqlPointType.php | 9 + 150 files changed, 2747 insertions(+), 2668 deletions(-) delete mode 100644 tests/Doctrine/Tests/Mocks/TaskMock.php diff --git a/tests/Doctrine/Tests/DBAL/ConfigurationTest.php b/tests/Doctrine/Tests/DBAL/ConfigurationTest.php index 851f973e66e..8310ea15c66 100644 --- a/tests/Doctrine/Tests/DBAL/ConfigurationTest.php +++ b/tests/Doctrine/Tests/DBAL/ConfigurationTest.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\DBAL; diff --git a/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/ConnectionTest.php index dfb908f40f4..52e95cfc528 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -12,6 +12,8 @@ use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\Connection as DriverConnection; +use Doctrine\DBAL\Driver\Statement; +use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Events; use Doctrine\DBAL\Exception\InvalidArgumentException; use Doctrine\DBAL\FetchMode; @@ -21,6 +23,7 @@ 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; use Exception; @@ -35,7 +38,7 @@ class ConnectionTest extends DbalTestCase { /** @var Connection */ - protected $_conn = null; + private $connection; /** @var string[] */ protected $params = [ @@ -48,7 +51,7 @@ class ConnectionTest extends DbalTestCase protected function setUp() { - $this->_conn = \Doctrine\DBAL\DriverManager::getConnection($this->params); + $this->connection = DriverManager::getConnection($this->params); } public function getExecuteUpdateMockConnection() @@ -69,73 +72,73 @@ public function getExecuteUpdateMockConnection() public function testIsConnected() { - self::assertFalse($this->_conn->isConnected()); + self::assertFalse($this->connection->isConnected()); } public function testNoTransactionActiveByDefault() { - self::assertFalse($this->_conn->isTransactionActive()); + self::assertFalse($this->connection->isTransactionActive()); } - public function testCommitWithNoActiveTransaction_ThrowsException() + public function testCommitWithNoActiveTransactionThrowsException() { $this->expectException(ConnectionException::class); - $this->_conn->commit(); + $this->connection->commit(); } - public function testRollbackWithNoActiveTransaction_ThrowsException() + public function testRollbackWithNoActiveTransactionThrowsException() { $this->expectException(ConnectionException::class); - $this->_conn->rollBack(); + $this->connection->rollBack(); } - public function testSetRollbackOnlyNoActiveTransaction_ThrowsException() + public function testSetRollbackOnlyNoActiveTransactionThrowsException() { $this->expectException(ConnectionException::class); - $this->_conn->setRollbackOnly(); + $this->connection->setRollbackOnly(); } - public function testIsRollbackOnlyNoActiveTransaction_ThrowsException() + public function testIsRollbackOnlyNoActiveTransactionThrowsException() { $this->expectException(ConnectionException::class); - $this->_conn->isRollbackOnly(); + $this->connection->isRollbackOnly(); } public function testGetConfiguration() { - $config = $this->_conn->getConfiguration(); + $config = $this->connection->getConfiguration(); - self::assertInstanceOf('Doctrine\DBAL\Configuration', $config); + self::assertInstanceOf(Configuration::class, $config); } public function testGetHost() { - self::assertEquals('localhost', $this->_conn->getHost()); + self::assertEquals('localhost', $this->connection->getHost()); } public function testGetPort() { - self::assertEquals('1234', $this->_conn->getPort()); + self::assertEquals('1234', $this->connection->getPort()); } public function testGetUsername() { - self::assertEquals('root', $this->_conn->getUsername()); + self::assertEquals('root', $this->connection->getUsername()); } public function testGetPassword() { - self::assertEquals('password', $this->_conn->getPassword()); + self::assertEquals('password', $this->connection->getPassword()); } public function testGetDriver() { - self::assertInstanceOf('Doctrine\DBAL\Driver\PDOMySql\Driver', $this->_conn->getDriver()); + self::assertInstanceOf(\Doctrine\DBAL\Driver\PDOMySql\Driver::class, $this->connection->getDriver()); } public function testGetEventManager() { - self::assertInstanceOf('Doctrine\Common\EventManager', $this->_conn->getEventManager()); + self::assertInstanceOf(EventManager::class, $this->connection->getEventManager()); } public function testConnectDispatchEvent() @@ -148,7 +151,7 @@ public function testConnectDispatchEvent() $eventManager = new EventManager(); $eventManager->addEventListener([Events::postConnect], $listenerMock); - $driverMock = $this->createMock('Doctrine\DBAL\Driver'); + $driverMock = $this->createMock(Driver::class); $driverMock->expects($this->at(0)) ->method('connect'); $platform = new Mocks\MockPlatform(); @@ -161,7 +164,7 @@ public function testEventManagerPassedToPlatform() { $driverMock = new DriverMock(); $connection = new Connection($this->params, $driverMock); - self::assertInstanceOf('Doctrine\Common\EventManager', $connection->getDatabasePlatform()->getEventManager()); + self::assertInstanceOf(EventManager::class, $connection->getDatabasePlatform()->getEventManager()); self::assertSame($connection->getEventManager(), $connection->getDatabasePlatform()->getEventManager()); } @@ -175,12 +178,12 @@ public function testDriverExceptionIsWrapped($method) $this->expectException(DBALException::class); $this->expectExceptionMessage("An exception occurred while executing 'MUUHAAAAHAAAA':\n\nSQLSTATE[HY000]: General error: 1 near \"MUUHAAAAHAAAA\""); - $con = \Doctrine\DBAL\DriverManager::getConnection(array( + $connection = DriverManager::getConnection([ 'driver' => 'pdo_sqlite', 'memory' => true, - )); + ]); - $con->$method('MUUHAAAAHAAAA'); + $connection->$method('MUUHAAAAHAAAA'); } public function getQueryMethods() @@ -202,8 +205,8 @@ public function getQueryMethods() public function testEchoSQLLogger() { $logger = new EchoSQLLogger(); - $this->_conn->getConfiguration()->setSQLLogger($logger); - self::assertSame($logger, $this->_conn->getConfiguration()->getSQLLogger()); + $this->connection->getConfiguration()->setSQLLogger($logger); + self::assertSame($logger, $this->connection->getConfiguration()->getSQLLogger()); } /** @@ -214,8 +217,8 @@ public function testEchoSQLLogger() public function testDebugSQLStack() { $logger = new DebugStack(); - $this->_conn->getConfiguration()->setSQLLogger($logger); - self::assertSame($logger, $this->_conn->getConfiguration()->getSQLLogger()); + $this->connection->getConfiguration()->setSQLLogger($logger); + self::assertSame($logger, $this->connection->getConfiguration()->getSQLLogger()); } /** @@ -223,7 +226,7 @@ public function testDebugSQLStack() */ public function testIsAutoCommit() { - self::assertTrue($this->_conn->isAutoCommit()); + self::assertTrue($this->connection->isAutoCommit()); } /** @@ -231,10 +234,10 @@ public function testIsAutoCommit() */ public function testSetAutoCommit() { - $this->_conn->setAutoCommit(false); - self::assertFalse($this->_conn->isAutoCommit()); - $this->_conn->setAutoCommit(0); - self::assertFalse($this->_conn->isAutoCommit()); + $this->connection->setAutoCommit(false); + self::assertFalse($this->connection->isAutoCommit()); + $this->connection->setAutoCommit(0); + self::assertFalse($this->connection->isAutoCommit()); } /** @@ -242,7 +245,7 @@ public function testSetAutoCommit() */ public function testConnectStartsTransactionInNoAutoCommitMode() { - $driverMock = $this->createMock('Doctrine\DBAL\Driver'); + $driverMock = $this->createMock(Driver::class); $driverMock->expects($this->any()) ->method('connect') ->will($this->returnValue( @@ -264,7 +267,7 @@ public function testConnectStartsTransactionInNoAutoCommitMode() */ public function testCommitStartsTransactionInNoAutoCommitMode() { - $driverMock = $this->createMock('Doctrine\DBAL\Driver'); + $driverMock = $this->createMock(Driver::class); $driverMock->expects($this->any()) ->method('connect') ->will($this->returnValue( @@ -284,7 +287,7 @@ public function testCommitStartsTransactionInNoAutoCommitMode() */ public function testRollBackStartsTransactionInNoAutoCommitMode() { - $driverMock = $this->createMock('Doctrine\DBAL\Driver'); + $driverMock = $this->createMock(Driver::class); $driverMock->expects($this->any()) ->method('connect') ->will($this->returnValue( @@ -304,7 +307,7 @@ public function testRollBackStartsTransactionInNoAutoCommitMode() */ public function testSwitchingAutoCommitModeCommitsAllCurrentTransactions() { - $driverMock = $this->createMock('Doctrine\DBAL\Driver'); + $driverMock = $this->createMock(Driver::class); $driverMock->expects($this->any()) ->method('connect') ->will($this->returnValue( @@ -501,7 +504,7 @@ public function testFetchAssoc() $types = [ParameterType::INTEGER]; $result = []; - $driverMock = $this->createMock('Doctrine\DBAL\Driver'); + $driverMock = $this->createMock(Driver::class); $driverMock->expects($this->any()) ->method('connect') @@ -509,7 +512,7 @@ public function testFetchAssoc() $this->createMock(DriverConnection::class) )); - $driverStatementMock = $this->createMock('Doctrine\Tests\Mocks\DriverStatementMock'); + $driverStatementMock = $this->createMock(DriverStatementMock::class); $driverStatementMock->expects($this->once()) ->method('fetch') @@ -517,7 +520,7 @@ public function testFetchAssoc() ->will($this->returnValue($result)); /** @var PHPUnit_Framework_MockObject_MockObject|Connection $conn */ - $conn = $this->getMockBuilder('Doctrine\DBAL\Connection') + $conn = $this->getMockBuilder(Connection::class) ->setMethods(['executeQuery']) ->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock]) ->getMock(); @@ -537,7 +540,7 @@ public function testFetchArray() $types = [ParameterType::INTEGER]; $result = []; - $driverMock = $this->createMock('Doctrine\DBAL\Driver'); + $driverMock = $this->createMock(Driver::class); $driverMock->expects($this->any()) ->method('connect') @@ -545,7 +548,7 @@ public function testFetchArray() $this->createMock(DriverConnection::class) )); - $driverStatementMock = $this->createMock('Doctrine\Tests\Mocks\DriverStatementMock'); + $driverStatementMock = $this->createMock(DriverStatementMock::class); $driverStatementMock->expects($this->once()) ->method('fetch') @@ -553,7 +556,7 @@ public function testFetchArray() ->will($this->returnValue($result)); /** @var PHPUnit_Framework_MockObject_MockObject|Connection $conn */ - $conn = $this->getMockBuilder('Doctrine\DBAL\Connection') + $conn = $this->getMockBuilder(Connection::class) ->setMethods(['executeQuery']) ->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock]) ->getMock(); @@ -574,7 +577,7 @@ public function testFetchColumn() $column = 0; $result = []; - $driverMock = $this->createMock('Doctrine\DBAL\Driver'); + $driverMock = $this->createMock(Driver::class); $driverMock->expects($this->any()) ->method('connect') @@ -582,7 +585,7 @@ public function testFetchColumn() $this->createMock(DriverConnection::class) )); - $driverStatementMock = $this->createMock('Doctrine\Tests\Mocks\DriverStatementMock'); + $driverStatementMock = $this->createMock(DriverStatementMock::class); $driverStatementMock->expects($this->once()) ->method('fetchColumn') @@ -590,7 +593,7 @@ public function testFetchColumn() ->will($this->returnValue($result)); /** @var PHPUnit_Framework_MockObject_MockObject|Connection $conn */ - $conn = $this->getMockBuilder('Doctrine\DBAL\Connection') + $conn = $this->getMockBuilder(Connection::class) ->setMethods(['executeQuery']) ->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock]) ->getMock(); @@ -606,7 +609,7 @@ public function testFetchColumn() public function testConnectionIsClosedButNotUnset() { // mock Connection, and make connect() purposefully do nothing - $connection = $this->getMockBuilder('Doctrine\DBAL\Connection') + $connection = $this->getMockBuilder(Connection::class) ->disableOriginalConstructor() ->setMethods(['connect']) ->getMock(); @@ -633,7 +636,7 @@ public function testFetchAll() $types = [ParameterType::INTEGER]; $result = []; - $driverMock = $this->createMock('Doctrine\DBAL\Driver'); + $driverMock = $this->createMock(Driver::class); $driverMock->expects($this->any()) ->method('connect') @@ -641,14 +644,14 @@ public function testFetchAll() $this->createMock(DriverConnection::class) )); - $driverStatementMock = $this->createMock('Doctrine\Tests\Mocks\DriverStatementMock'); + $driverStatementMock = $this->createMock(DriverStatementMock::class); $driverStatementMock->expects($this->once()) ->method('fetchAll') ->will($this->returnValue($result)); /** @var PHPUnit_Framework_MockObject_MockObject|Connection $conn */ - $conn = $this->getMockBuilder('Doctrine\DBAL\Connection') + $conn = $this->getMockBuilder(Connection::class) ->setMethods(['executeQuery']) ->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock]) ->getMock(); @@ -665,7 +668,7 @@ public function testConnectionDoesNotMaintainTwoReferencesToExternalPDO() { $params['pdo'] = new stdClass(); - $driverMock = $this->createMock('Doctrine\DBAL\Driver'); + $driverMock = $this->createMock(Driver::class); $conn = new Connection($params, $driverMock); @@ -676,7 +679,7 @@ public function testPassingExternalPDOMeansConnectionIsConnected() { $params['pdo'] = new stdClass(); - $driverMock = $this->createMock('Doctrine\DBAL\Driver'); + $driverMock = $this->createMock(Driver::class); $conn = new Connection($params, $driverMock); @@ -686,8 +689,8 @@ public function testPassingExternalPDOMeansConnectionIsConnected() public function testCallingDeleteWithNoDeletionCriteriaResultsInInvalidArgumentException() { /** @var Driver $driver */ - $driver = $this->createMock('Doctrine\DBAL\Driver'); - $pdoMock = $this->createMock('Doctrine\DBAL\Driver\Connection'); + $driver = $this->createMock(Driver::class); + $pdoMock = $this->createMock(\Doctrine\DBAL\Driver\Connection::class); // should never execute queries with invalid arguments $pdoMock->expects($this->never())->method('exec'); @@ -715,16 +718,16 @@ public function dataCallConnectOnce() */ public function testCallConnectOnce($method, $params) { - $driverMock = $this->createMock('Doctrine\DBAL\Driver'); - $pdoMock = $this->createMock('Doctrine\DBAL\Driver\Connection'); + $driverMock = $this->createMock(Driver::class); + $pdoMock = $this->createMock(\Doctrine\DBAL\Driver\Connection::class); $platformMock = new Mocks\MockPlatform(); - $stmtMock = $this->createMock('Doctrine\DBAL\Driver\Statement'); + $stmtMock = $this->createMock(Statement::class); $pdoMock->expects($this->any()) ->method('prepare') ->will($this->returnValue($stmtMock)); - $conn = $this->getMockBuilder('Doctrine\DBAL\Connection') + $conn = $this->getMockBuilder(Connection::class) ->setConstructorArgs([['pdo' => $pdoMock, 'platform' => $platformMock], $driverMock]) ->setMethods(['connect']) ->getMock(); @@ -740,13 +743,13 @@ public function testCallConnectOnce($method, $params) public function testPlatformDetectionIsTriggerOnlyOnceOnRetrievingPlatform() { /** @var VersionAwarePlatformDriverMock|PHPUnit_Framework_MockObject_MockObject $driverMock */ - $driverMock = $this->createMock('Doctrine\Tests\Mocks\VersionAwarePlatformDriverMock'); + $driverMock = $this->createMock(VersionAwarePlatformDriverMock::class); /** @var ServerInfoAwareConnectionMock|PHPUnit_Framework_MockObject_MockObject $driverConnectionMock */ - $driverConnectionMock = $this->createMock('Doctrine\Tests\Mocks\ServerInfoAwareConnectionMock'); + $driverConnectionMock = $this->createMock(ServerInfoAwareConnectionMock::class); /** @var AbstractPlatform|PHPUnit_Framework_MockObject_MockObject $platformMock */ - $platformMock = $this->getMockForAbstractClass('Doctrine\DBAL\Platforms\AbstractPlatform'); + $platformMock = $this->getMockForAbstractClass(AbstractPlatform::class); $connection = new Connection([], $driverMock); diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractDB2DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractDB2DriverTest.php index 3b6b9773c06..e6a54060c71 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractDB2DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractDB2DriverTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\DBAL\Driver; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver\AbstractDB2Driver; use Doctrine\DBAL\Platforms\DB2Platform; use Doctrine\DBAL\Schema\DB2SchemaManager; @@ -10,7 +11,7 @@ class AbstractDB2DriverTest extends AbstractDriverTest { protected function createDriver() { - return $this->getMockForAbstractClass('Doctrine\DBAL\Driver\AbstractDB2Driver'); + return $this->getMockForAbstractClass(AbstractDB2Driver::class); } protected function createPlatform() diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php index 9eda7f8de77..0475ea11b89 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php @@ -4,8 +4,25 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver; -use Doctrine\DBAL\Driver\DriverException; +use Doctrine\DBAL\Driver\DriverException as DriverExceptionInterface; use Doctrine\DBAL\Driver\ExceptionConverterDriver; +use Doctrine\DBAL\Exception\ConnectionException; +use Doctrine\DBAL\Exception\ConstraintViolationException; +use Doctrine\DBAL\Exception\DatabaseObjectExistsException; +use Doctrine\DBAL\Exception\DatabaseObjectNotFoundException; +use Doctrine\DBAL\Exception\DeadlockException; +use Doctrine\DBAL\Exception\DriverException; +use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException; +use Doctrine\DBAL\Exception\InvalidFieldNameException; +use Doctrine\DBAL\Exception\LockWaitTimeoutException; +use Doctrine\DBAL\Exception\NonUniqueFieldNameException; +use Doctrine\DBAL\Exception\NotNullConstraintViolationException; +use Doctrine\DBAL\Exception\ReadOnlyException; +use Doctrine\DBAL\Exception\ServerException; +use Doctrine\DBAL\Exception\SyntaxErrorException; +use Doctrine\DBAL\Exception\TableExistsException; +use Doctrine\DBAL\Exception\TableNotFoundException; +use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\VersionAwarePlatformDriver; @@ -16,23 +33,23 @@ abstract class AbstractDriverTest extends DbalTestCase { - public const EXCEPTION_CONNECTION = 'Doctrine\DBAL\Exception\ConnectionException'; - public const EXCEPTION_CONSTRAINT_VIOLATION = 'Doctrine\DBAL\Exception\ConstraintViolationException'; - public const EXCEPTION_DATABASE_OBJECT_EXISTS = 'Doctrine\DBAL\Exception\DatabaseObjectExistsException'; - public const EXCEPTION_DATABASE_OBJECT_NOT_FOUND = 'Doctrine\DBAL\Exception\DatabaseObjectNotFoundException'; - public const EXCEPTION_DRIVER = 'Doctrine\DBAL\Exception\DriverException'; - public const EXCEPTION_FOREIGN_KEY_CONSTRAINT_VIOLATION = 'Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException'; - public const EXCEPTION_INVALID_FIELD_NAME = 'Doctrine\DBAL\Exception\InvalidFieldNameException'; - public const EXCEPTION_NON_UNIQUE_FIELD_NAME = 'Doctrine\DBAL\Exception\NonUniqueFieldNameException'; - public const EXCEPTION_NOT_NULL_CONSTRAINT_VIOLATION = 'Doctrine\DBAL\Exception\NotNullConstraintViolationException'; - public const EXCEPTION_READ_ONLY = 'Doctrine\DBAL\Exception\ReadOnlyException'; - public const EXCEPTION_SERVER = 'Doctrine\DBAL\Exception\ServerException'; - public const EXCEPTION_SYNTAX_ERROR = 'Doctrine\DBAL\Exception\SyntaxErrorException'; - public const EXCEPTION_TABLE_EXISTS = 'Doctrine\DBAL\Exception\TableExistsException'; - public const EXCEPTION_TABLE_NOT_FOUND = 'Doctrine\DBAL\Exception\TableNotFoundException'; - public const EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION = 'Doctrine\DBAL\Exception\UniqueConstraintViolationException'; - public const EXCEPTION_DEADLOCK = 'Doctrine\DBAL\Exception\DeadlockException'; - public const EXCEPTION_LOCK_WAIT_TIMEOUT = 'Doctrine\DBAL\Exception\LockWaitTimeoutException'; + public const EXCEPTION_CONNECTION = ConnectionException::class; + public const EXCEPTION_CONSTRAINT_VIOLATION = ConstraintViolationException::class; + public const EXCEPTION_DATABASE_OBJECT_EXISTS = DatabaseObjectExistsException::class; + public const EXCEPTION_DATABASE_OBJECT_NOT_FOUND = DatabaseObjectNotFoundException::class; + public const EXCEPTION_DRIVER = DriverException::class; + public const EXCEPTION_FOREIGN_KEY_CONSTRAINT_VIOLATION = ForeignKeyConstraintViolationException::class; + public const EXCEPTION_INVALID_FIELD_NAME = InvalidFieldNameException::class; + public const EXCEPTION_NON_UNIQUE_FIELD_NAME = NonUniqueFieldNameException::class; + public const EXCEPTION_NOT_NULL_CONSTRAINT_VIOLATION = NotNullConstraintViolationException::class; + public const EXCEPTION_READ_ONLY = ReadOnlyException::class; + public const EXCEPTION_SERVER = ServerException::class; + public const EXCEPTION_SYNTAX_ERROR = SyntaxErrorException::class; + public const EXCEPTION_TABLE_EXISTS = TableExistsException::class; + public const EXCEPTION_TABLE_NOT_FOUND = TableNotFoundException::class; + public const EXCEPTION_UNIQUE_CONSTRAINT_VIOLATION = UniqueConstraintViolationException::class; + public const EXCEPTION_DEADLOCK = DeadlockException::class; + public const EXCEPTION_LOCK_WAIT_TIMEOUT = LockWaitTimeoutException::class; /** * The driver mock under test. @@ -66,7 +83,7 @@ public function testConvertsException() ); } - $driverException = new class extends Exception implements DriverException + $driverException = new class extends Exception implements DriverExceptionInterface { public function __construct() { @@ -215,7 +232,7 @@ abstract protected function createSchemaManager(Connection $connection); protected function getConnectionMock() { - return $this->getMockBuilder('Doctrine\DBAL\Connection') + return $this->getMockBuilder(Connection::class) ->disableOriginalConstructor() ->getMock(); } @@ -238,7 +255,7 @@ private function getExceptionConversions() foreach ($errors as $error) { $driverException = new class ($error[0], $error[1], $error[2]) extends Exception - implements DriverException + implements DriverExceptionInterface { /** @var mixed */ private $errorCode; diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php index ebeb81d160f..cde381653a9 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php @@ -3,11 +3,13 @@ namespace Doctrine\Tests\DBAL\Driver; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver\AbstractMySQLDriver; 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 { @@ -21,7 +23,7 @@ public function testReturnsDatabaseName() 'password' => 'bar', ]; - $statement = $this->createMock('Doctrine\Tests\Mocks\DriverResultStatementMock'); + $statement = $this->createMock(DriverResultStatementMock::class); $statement->expects($this->once()) ->method('fetchColumn') @@ -42,7 +44,7 @@ public function testReturnsDatabaseName() protected function createDriver() { - return $this->getMockForAbstractClass('Doctrine\DBAL\Driver\AbstractMySQLDriver'); + return $this->getMockForAbstractClass(AbstractMySQLDriver::class); } protected function createPlatform() @@ -55,6 +57,9 @@ protected function createSchemaManager(Connection $connection) return new MySqlSchemaManager($connection); } + /** + * @return mixed[][] + */ protected function getDatabasePlatformsForVersions() : array { return [ diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriverTest.php index a427f12c945..d88040e10a7 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriverTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\DBAL\Driver; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver\AbstractOracleDriver; use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Schema\OracleSchemaManager; @@ -46,7 +47,7 @@ public function testReturnsDatabaseNameWithConnectDescriptor() protected function createDriver() { - return $this->getMockForAbstractClass('Doctrine\DBAL\Driver\AbstractOracleDriver'); + return $this->getMockForAbstractClass(AbstractOracleDriver::class); } protected function createPlatform() diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractPostgreSQLDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractPostgreSQLDriverTest.php index 9c9bcd5c354..d1159c80308 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractPostgreSQLDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractPostgreSQLDriverTest.php @@ -3,9 +3,14 @@ namespace Doctrine\Tests\DBAL\Driver; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver\AbstractPostgreSQLDriver; 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 { @@ -19,7 +24,7 @@ public function testReturnsDatabaseName() 'password' => 'bar', ]; - $statement = $this->createMock('Doctrine\Tests\Mocks\DriverResultStatementMock'); + $statement = $this->createMock(DriverResultStatementMock::class); $statement->expects($this->once()) ->method('fetchColumn') @@ -40,7 +45,7 @@ public function testReturnsDatabaseName() protected function createDriver() { - return $this->getMockForAbstractClass('Doctrine\DBAL\Driver\AbstractPostgreSQLDriver'); + return $this->getMockForAbstractClass(AbstractPostgreSQLDriver::class); } protected function createPlatform() @@ -56,18 +61,18 @@ protected function createSchemaManager(Connection $connection) protected function getDatabasePlatformsForVersions() { return [ - ['9.0.9', 'Doctrine\DBAL\Platforms\PostgreSqlPlatform'], - ['9.1', 'Doctrine\DBAL\Platforms\PostgreSQL91Platform'], - ['9.1.0', 'Doctrine\DBAL\Platforms\PostgreSQL91Platform'], - ['9.1.1', 'Doctrine\DBAL\Platforms\PostgreSQL91Platform'], - ['9.1.9', 'Doctrine\DBAL\Platforms\PostgreSQL91Platform'], - ['9.2', 'Doctrine\DBAL\Platforms\PostgreSQL92Platform'], - ['9.2.0', 'Doctrine\DBAL\Platforms\PostgreSQL92Platform'], - ['9.2.1', 'Doctrine\DBAL\Platforms\PostgreSQL92Platform'], - ['9.3.6', 'Doctrine\DBAL\Platforms\PostgreSQL92Platform'], - ['9.4', 'Doctrine\DBAL\Platforms\PostgreSQL94Platform'], - ['9.4.0', 'Doctrine\DBAL\Platforms\PostgreSQL94Platform'], - ['9.4.1', 'Doctrine\DBAL\Platforms\PostgreSQL94Platform'], + ['9.0.9', PostgreSqlPlatform::class], + ['9.1', PostgreSQL91Platform::class], + ['9.1.0', PostgreSQL91Platform::class], + ['9.1.1', PostgreSQL91Platform::class], + ['9.1.9', PostgreSQL91Platform::class], + ['9.2', PostgreSQL92Platform::class], + ['9.2.0', PostgreSQL92Platform::class], + ['9.2.1', PostgreSQL92Platform::class], + ['9.3.6', PostgreSQL92Platform::class], + ['9.4', PostgreSQL94Platform::class], + ['9.4.0', PostgreSQL94Platform::class], + ['9.4.1', PostgreSQL94Platform::class], ['10', PostgreSQL100Platform::class], ]; } diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLAnywhereDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLAnywhereDriverTest.php index 53480e7d82a..cbd23505bae 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLAnywhereDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLAnywhereDriverTest.php @@ -3,14 +3,18 @@ namespace Doctrine\Tests\DBAL\Driver; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver\AbstractSQLAnywhereDriver; +use Doctrine\DBAL\Platforms\SQLAnywhere11Platform; use Doctrine\DBAL\Platforms\SQLAnywhere12Platform; +use Doctrine\DBAL\Platforms\SQLAnywhere16Platform; +use Doctrine\DBAL\Platforms\SQLAnywherePlatform; use Doctrine\DBAL\Schema\SQLAnywhereSchemaManager; class AbstractSQLAnywhereDriverTest extends AbstractDriverTest { protected function createDriver() { - return $this->getMockForAbstractClass('Doctrine\DBAL\Driver\AbstractSQLAnywhereDriver'); + return $this->getMockForAbstractClass(AbstractSQLAnywhereDriver::class); } protected function createPlatform() @@ -26,35 +30,35 @@ protected function createSchemaManager(Connection $connection) protected function getDatabasePlatformsForVersions() { return [ - ['10', 'Doctrine\DBAL\Platforms\SQLAnywherePlatform'], - ['10.0', 'Doctrine\DBAL\Platforms\SQLAnywherePlatform'], - ['10.0.0', 'Doctrine\DBAL\Platforms\SQLAnywherePlatform'], - ['10.0.0.0', 'Doctrine\DBAL\Platforms\SQLAnywherePlatform'], - ['10.1.2.3', 'Doctrine\DBAL\Platforms\SQLAnywherePlatform'], - ['10.9.9.9', 'Doctrine\DBAL\Platforms\SQLAnywherePlatform'], - ['11', 'Doctrine\DBAL\Platforms\SQLAnywhere11Platform'], - ['11.0', 'Doctrine\DBAL\Platforms\SQLAnywhere11Platform'], - ['11.0.0', 'Doctrine\DBAL\Platforms\SQLAnywhere11Platform'], - ['11.0.0.0', 'Doctrine\DBAL\Platforms\SQLAnywhere11Platform'], - ['11.1.2.3', 'Doctrine\DBAL\Platforms\SQLAnywhere11Platform'], - ['11.9.9.9', 'Doctrine\DBAL\Platforms\SQLAnywhere11Platform'], - ['12', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'], - ['12.0', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'], - ['12.0.0', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'], - ['12.0.0.0', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'], - ['12.1.2.3', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'], - ['12.9.9.9', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'], - ['13', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'], - ['14', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'], - ['15', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'], - ['15.9.9.9', 'Doctrine\DBAL\Platforms\SQLAnywhere12Platform'], - ['16', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'], - ['16.0', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'], - ['16.0.0', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'], - ['16.0.0.0', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'], - ['16.1.2.3', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'], - ['16.9.9.9', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'], - ['17', 'Doctrine\DBAL\Platforms\SQLAnywhere16Platform'], + ['10', SQLAnywherePlatform::class], + ['10.0', SQLAnywherePlatform::class], + ['10.0.0', SQLAnywherePlatform::class], + ['10.0.0.0', SQLAnywherePlatform::class], + ['10.1.2.3', SQLAnywherePlatform::class], + ['10.9.9.9', SQLAnywherePlatform::class], + ['11', SQLAnywhere11Platform::class], + ['11.0', SQLAnywhere11Platform::class], + ['11.0.0', SQLAnywhere11Platform::class], + ['11.0.0.0', SQLAnywhere11Platform::class], + ['11.1.2.3', SQLAnywhere11Platform::class], + ['11.9.9.9', SQLAnywhere11Platform::class], + ['12', SQLAnywhere12Platform::class], + ['12.0', SQLAnywhere12Platform::class], + ['12.0.0', SQLAnywhere12Platform::class], + ['12.0.0.0', SQLAnywhere12Platform::class], + ['12.1.2.3', SQLAnywhere12Platform::class], + ['12.9.9.9', SQLAnywhere12Platform::class], + ['13', SQLAnywhere12Platform::class], + ['14', SQLAnywhere12Platform::class], + ['15', SQLAnywhere12Platform::class], + ['15.9.9.9', SQLAnywhere12Platform::class], + ['16', SQLAnywhere16Platform::class], + ['16.0', SQLAnywhere16Platform::class], + ['16.0.0', SQLAnywhere16Platform::class], + ['16.0.0.0', SQLAnywhere16Platform::class], + ['16.1.2.3', SQLAnywhere16Platform::class], + ['16.9.9.9', SQLAnywhere16Platform::class], + ['17', SQLAnywhere16Platform::class], ]; } diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLServerDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLServerDriverTest.php index 31e72a661af..48fb3b29f3e 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLServerDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLServerDriverTest.php @@ -3,14 +3,18 @@ namespace Doctrine\Tests\DBAL\Driver; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver\AbstractSQLServerDriver; +use Doctrine\DBAL\Platforms\SQLServer2005Platform; use Doctrine\DBAL\Platforms\SQLServer2008Platform; +use Doctrine\DBAL\Platforms\SQLServer2012Platform; +use Doctrine\DBAL\Platforms\SQLServerPlatform; use Doctrine\DBAL\Schema\SQLServerSchemaManager; class AbstractSQLServerDriverTest extends AbstractDriverTest { protected function createDriver() { - return $this->getMockForAbstractClass('Doctrine\DBAL\Driver\AbstractSQLServerDriver'); + return $this->getMockForAbstractClass(AbstractSQLServerDriver::class); } protected function createPlatform() @@ -26,32 +30,32 @@ protected function createSchemaManager(Connection $connection) protected function getDatabasePlatformsForVersions() { return [ - ['9', 'Doctrine\DBAL\Platforms\SQLServerPlatform'], - ['9.00', 'Doctrine\DBAL\Platforms\SQLServerPlatform'], - ['9.00.0', 'Doctrine\DBAL\Platforms\SQLServerPlatform'], - ['9.00.1398', 'Doctrine\DBAL\Platforms\SQLServerPlatform'], - ['9.00.1398.99', 'Doctrine\DBAL\Platforms\SQLServerPlatform'], - ['9.00.1399', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'], - ['9.00.1399.0', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'], - ['9.00.1399.99', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'], - ['9.00.1400', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'], - ['9.10', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'], - ['9.10.9999', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'], - ['10.00.1599', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'], - ['10.00.1599.99', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'], - ['10.00.1600', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'], - ['10.00.1600.0', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'], - ['10.00.1600.99', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'], - ['10.00.1601', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'], - ['10.10', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'], - ['10.10.9999', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'], - ['11.00.2099', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'], - ['11.00.2099.99', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'], - ['11.00.2100', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'], - ['11.00.2100.0', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'], - ['11.00.2100.99', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'], - ['11.00.2101', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'], - ['12', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'], + ['9', SQLServerPlatform::class], + ['9.00', SQLServerPlatform::class], + ['9.00.0', SQLServerPlatform::class], + ['9.00.1398', SQLServerPlatform::class], + ['9.00.1398.99', SQLServerPlatform::class], + ['9.00.1399', SQLServer2005Platform::class], + ['9.00.1399.0', SQLServer2005Platform::class], + ['9.00.1399.99', SQLServer2005Platform::class], + ['9.00.1400', SQLServer2005Platform::class], + ['9.10', SQLServer2005Platform::class], + ['9.10.9999', SQLServer2005Platform::class], + ['10.00.1599', SQLServer2005Platform::class], + ['10.00.1599.99', SQLServer2005Platform::class], + ['10.00.1600', SQLServer2008Platform::class], + ['10.00.1600.0', SQLServer2008Platform::class], + ['10.00.1600.99', SQLServer2008Platform::class], + ['10.00.1601', SQLServer2008Platform::class], + ['10.10', SQLServer2008Platform::class], + ['10.10.9999', SQLServer2008Platform::class], + ['11.00.2099', SQLServer2008Platform::class], + ['11.00.2099.99', SQLServer2008Platform::class], + ['11.00.2100', SQLServer2012Platform::class], + ['11.00.2100.0', SQLServer2012Platform::class], + ['11.00.2100.99', SQLServer2012Platform::class], + ['11.00.2101', SQLServer2012Platform::class], + ['12', SQLServer2012Platform::class], ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLiteDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLiteDriverTest.php index 96f3b6b9d64..d92aa5d0d8d 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLiteDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLiteDriverTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\DBAL\Driver; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver\AbstractSQLiteDriver; use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Schema\SqliteSchemaManager; @@ -28,7 +29,7 @@ public function testReturnsDatabaseName() protected function createDriver() { - return $this->getMockForAbstractClass('Doctrine\DBAL\Driver\AbstractSQLiteDriver'); + return $this->getMockForAbstractClass(AbstractSQLiteDriver::class); } protected function createPlatform() diff --git a/tests/Doctrine/Tests/DBAL/Driver/DrizzlePDOMySql/DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/DrizzlePDOMySql/DriverTest.php index 004043c2051..520a732a0c3 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/DrizzlePDOMySql/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/DrizzlePDOMySql/DriverTest.php @@ -35,12 +35,15 @@ protected function createSchemaManager(Connection $connection) return new DrizzleSchemaManager($connection); } + /** + * @return mixed[][] + */ protected function getDatabasePlatformsForVersions() : array { return [ - ['foo', 'Doctrine\DBAL\Platforms\DrizzlePlatform'], - ['bar', 'Doctrine\DBAL\Platforms\DrizzlePlatform'], - ['baz', 'Doctrine\DBAL\Platforms\DrizzlePlatform'], + ['foo', DrizzlePlatform::class], + ['bar', DrizzlePlatform::class], + ['baz', DrizzlePlatform::class], ]; } } diff --git a/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2ConnectionTest.php index eaebefb728c..a60772295a6 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2ConnectionTest.php @@ -24,7 +24,7 @@ protected function setUp() parent::setUp(); - $this->connectionMock = $this->getMockBuilder('Doctrine\DBAL\Driver\IBMDB2\DB2Connection') + $this->connectionMock = $this->getMockBuilder(DB2Connection::class) ->disableOriginalConstructor() ->getMockForAbstractClass(); } diff --git a/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php index b0b34309f28..9bd3172dd1d 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php @@ -28,7 +28,7 @@ protected function setUp() parent::setUp(); - if (! $this->_conn->getDatabasePlatform() instanceof MySqlPlatform) { + if (! $this->connection->getDatabasePlatform() instanceof MySqlPlatform) { $this->markTestSkipped('MySQL only test.'); } diff --git a/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8ConnectionTest.php index b8141a84f2a..0628738400e 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8ConnectionTest.php @@ -24,7 +24,7 @@ protected function setUp() parent::setUp(); - $this->connectionMock = $this->getMockBuilder('Doctrine\DBAL\Driver\OCI8\OCI8Connection') + $this->connectionMock = $this->getMockBuilder(OCI8Connection::class) ->disableOriginalConstructor() ->getMockForAbstractClass(); } diff --git a/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php b/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php index 103b7ab57d7..b51f3bf2f5b 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8StatementTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Driver\OCI8; +use Doctrine\DBAL\Driver\OCI8\OCI8Connection; use Doctrine\DBAL\Driver\OCI8\OCI8Exception; use Doctrine\DBAL\Driver\OCI8\OCI8Statement; use Doctrine\Tests\DbalTestCase; @@ -28,12 +29,14 @@ protected function setUp() * * The expected exception is due to oci_execute failing due to no valid connection. * + * @param mixed[] $params + * * @dataProvider executeDataProvider * @expectedException \Doctrine\DBAL\Driver\OCI8\OCI8Exception */ public function testExecute(array $params) { - $statement = $this->getMockBuilder('\Doctrine\DBAL\Driver\OCI8\OCI8Statement') + $statement = $this->getMockBuilder(OCI8Statement::class) ->setMethods(['bindValue', 'errorInfo']) ->disableOriginalConstructor() ->getMock(); @@ -59,7 +62,7 @@ public function testExecute(array $params) // 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('\Doctrine\DBAL\Driver\OCI8\OCI8Connection') + $conn = $this->getMockBuilder(OCI8Connection::class) ->setMethods(['getExecuteMode']) ->disableOriginalConstructor() ->getMock(); diff --git a/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php index 3f1c3efa1f8..a6ac2456b64 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Driver\PDOPgSql; +use Doctrine\DBAL\Driver\PDOConnection; use Doctrine\DBAL\Driver\PDOPgSql\Driver; use Doctrine\Tests\DBAL\Driver\AbstractPostgreSQLDriverTest; use PDO; @@ -32,7 +33,7 @@ public function testConnectionDisablesPreparesOnPhp56() $GLOBALS['db_password'] ); - self::assertInstanceOf('Doctrine\DBAL\Driver\PDOConnection', $connection); + self::assertInstanceOf(PDOConnection::class, $connection); try { self::assertTrue($connection->getAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES)); @@ -59,7 +60,7 @@ public function testConnectionDoesNotDisablePreparesOnPhp56WhenAttributeDefined( [PDO::PGSQL_ATTR_DISABLE_PREPARES => false] ); - self::assertInstanceOf('Doctrine\DBAL\Driver\PDOConnection', $connection); + self::assertInstanceOf(PDOConnection::class, $connection); try { self::assertNotSame(true, $connection->getAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES)); @@ -86,7 +87,7 @@ public function testConnectionDisablePreparesOnPhp56WhenDisablePreparesIsExplici [PDO::PGSQL_ATTR_DISABLE_PREPARES => true] ); - self::assertInstanceOf('Doctrine\DBAL\Driver\PDOConnection', $connection); + self::assertInstanceOf(PDOConnection::class, $connection); try { self::assertTrue($connection->getAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES)); diff --git a/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/SQLAnywhereConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/SQLAnywhereConnectionTest.php index 49bc5d05a16..d70d36396ba 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/SQLAnywhereConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/SQLAnywhereConnectionTest.php @@ -24,7 +24,7 @@ protected function setUp() parent::setUp(); - $this->connectionMock = $this->getMockBuilder('Doctrine\DBAL\Driver\SQLAnywhere\SQLAnywhereConnection') + $this->connectionMock = $this->getMockBuilder(SQLAnywhereConnection::class) ->disableOriginalConstructor() ->getMockForAbstractClass(); } diff --git a/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/SQLSrvConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/SQLSrvConnectionTest.php index 9e467cca01f..b0e32708428 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/SQLSrvConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/SQLSrvConnectionTest.php @@ -24,7 +24,7 @@ protected function setUp() parent::setUp(); - $this->connectionMock = $this->getMockBuilder('Doctrine\DBAL\Driver\SQLSrv\SQLSrvConnection') + $this->connectionMock = $this->getMockBuilder(SQLSrvConnection::class) ->disableOriginalConstructor() ->getMockForAbstractClass(); } diff --git a/tests/Doctrine/Tests/DBAL/Events/MysqlSessionInitTest.php b/tests/Doctrine/Tests/DBAL/Events/MysqlSessionInitTest.php index 981851a6b9e..0f9be11edda 100644 --- a/tests/Doctrine/Tests/DBAL/Events/MysqlSessionInitTest.php +++ b/tests/Doctrine/Tests/DBAL/Events/MysqlSessionInitTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Events; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\Event\ConnectionEventArgs; use Doctrine\DBAL\Event\Listeners\MysqlSessionInit; use Doctrine\DBAL\Events; @@ -11,7 +12,7 @@ class MysqlSessionInitTest extends DbalTestCase { public function testPostConnect() { - $connectionMock = $this->createMock('Doctrine\DBAL\Connection'); + $connectionMock = $this->createMock(Connection::class); $connectionMock->expects($this->once()) ->method('executeUpdate') ->with($this->equalTo('SET NAMES foo COLLATE bar')); diff --git a/tests/Doctrine/Tests/DBAL/Events/OracleSessionInitTest.php b/tests/Doctrine/Tests/DBAL/Events/OracleSessionInitTest.php index b86af27fc3f..2ea510a0543 100644 --- a/tests/Doctrine/Tests/DBAL/Events/OracleSessionInitTest.php +++ b/tests/Doctrine/Tests/DBAL/Events/OracleSessionInitTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Events; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\Event\ConnectionEventArgs; use Doctrine\DBAL\Event\Listeners\OracleSessionInit; use Doctrine\DBAL\Events; @@ -12,7 +13,7 @@ class OracleSessionInitTest extends DbalTestCase { public function testPostConnect() { - $connectionMock = $this->createMock('Doctrine\DBAL\Connection'); + $connectionMock = $this->createMock(Connection::class); $connectionMock->expects($this->once()) ->method('executeUpdate') ->with($this->isType('string')); @@ -29,7 +30,7 @@ public function testPostConnect() */ public function testPostConnectQuotesSessionParameterValues($name, $value) { - $connectionMock = $this->getMockBuilder('Doctrine\DBAL\Connection') + $connectionMock = $this->getMockBuilder(Connection::class) ->disableOriginalConstructor() ->getMock(); $connectionMock->expects($this->once()) diff --git a/tests/Doctrine/Tests/DBAL/Events/SQLSessionInitTest.php b/tests/Doctrine/Tests/DBAL/Events/SQLSessionInitTest.php index bf74e5180ae..f42458de74d 100644 --- a/tests/Doctrine/Tests/DBAL/Events/SQLSessionInitTest.php +++ b/tests/Doctrine/Tests/DBAL/Events/SQLSessionInitTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Events; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\Event\ConnectionEventArgs; use Doctrine\DBAL\Event\Listeners\SQLSessionInit; use Doctrine\DBAL\Events; @@ -14,7 +15,7 @@ class SQLSessionInitTest extends DbalTestCase { public function testPostConnect() { - $connectionMock = $this->createMock('Doctrine\DBAL\Connection'); + $connectionMock = $this->createMock(Connection::class); $connectionMock->expects($this->once()) ->method('exec') ->with($this->equalTo("SET SEARCH_PATH TO foo, public, TIMEZONE TO 'Europe/Berlin'")); diff --git a/tests/Doctrine/Tests/DBAL/Exception/InvalidArgumentExceptionTest.php b/tests/Doctrine/Tests/DBAL/Exception/InvalidArgumentExceptionTest.php index c2e7c7ec29a..54cfea89596 100644 --- a/tests/Doctrine/Tests/DBAL/Exception/InvalidArgumentExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Exception/InvalidArgumentExceptionTest.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\DBAL\Exception; @@ -33,7 +16,7 @@ public function testFromEmptyCriteria() { $exception = InvalidArgumentException::fromEmptyCriteria(); - self::assertInstanceOf('Doctrine\DBAL\Exception\InvalidArgumentException', $exception); + self::assertInstanceOf(InvalidArgumentException::class, $exception); self::assertSame('Empty criteria was used, expected non-empty criteria', $exception->getMessage()); } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php b/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php index 66332ed20ba..779f33254b5 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php @@ -23,7 +23,7 @@ protected function setUp() { parent::setUp(); - if ($this->_conn->getDriver() instanceof PDOSQLSrvDriver) { + if ($this->connection->getDriver() instanceof PDOSQLSrvDriver) { $this->markTestSkipped('This test does not work on pdo_sqlsrv driver due to a bug. See: http://social.msdn.microsoft.com/Forums/sqlserver/en-US/5a755bdd-41e9-45cb-9166-c9da4475bb94/how-to-set-null-for-varbinarymax-using-bindvalue-using-pdosqlsrv?forum=sqldriverforphp'); } @@ -34,13 +34,13 @@ protected function setUp() $table->addColumn('blobfield', 'blob'); $table->setPrimaryKey(['id']); - $sm = $this->_conn->getSchemaManager(); + $sm = $this->connection->getSchemaManager(); $sm->dropAndCreateTable($table); } public function testInsert() { - $ret = $this->_conn->insert('blob_table', [ + $ret = $this->connection->insert('blob_table', [ 'id' => 1, 'clobfield' => 'test', 'blobfield' => 'test', @@ -55,14 +55,14 @@ public function testInsert() public function testInsertProcessesStream() { - if (in_array($this->_conn->getDatabasePlatform()->getName(), ['oracle', 'db2'], true)) { + if (in_array($this->connection->getDatabasePlatform()->getName(), ['oracle', 'db2'], true)) { // https://github.com/doctrine/dbal/issues/3288 for DB2 // https://github.com/doctrine/dbal/issues/3290 for Oracle $this->markTestIncomplete('Platform does not support stream resources as parameters'); } $longBlob = str_repeat('x', 4 * 8192); // send 4 chunks - $this->_conn->insert('blob_table', [ + $this->connection->insert('blob_table', [ 'id' => 1, 'clobfield' => 'ignored', 'blobfield' => fopen('data://text/plain,' . $longBlob, 'r'), @@ -77,7 +77,7 @@ public function testInsertProcessesStream() public function testSelect() { - $this->_conn->insert('blob_table', [ + $this->connection->insert('blob_table', [ 'id' => 1, 'clobfield' => 'test', 'blobfield' => 'test', @@ -92,7 +92,7 @@ public function testSelect() public function testUpdate() { - $this->_conn->insert('blob_table', [ + $this->connection->insert('blob_table', [ 'id' => 1, 'clobfield' => 'test', 'blobfield' => 'test', @@ -102,7 +102,7 @@ public function testUpdate() ParameterType::LARGE_OBJECT, ]); - $this->_conn->update('blob_table', ['blobfield' => 'test2'], ['id' => 1], [ + $this->connection->update('blob_table', ['blobfield' => 'test2'], ['id' => 1], [ ParameterType::LARGE_OBJECT, ParameterType::INTEGER, ]); @@ -112,13 +112,13 @@ public function testUpdate() public function testUpdateProcessesStream() { - if (in_array($this->_conn->getDatabasePlatform()->getName(), ['oracle', 'db2'], true)) { + if (in_array($this->connection->getDatabasePlatform()->getName(), ['oracle', 'db2'], true)) { // https://github.com/doctrine/dbal/issues/3288 for DB2 // https://github.com/doctrine/dbal/issues/3290 for Oracle $this->markTestIncomplete('Platform does not support stream resources as parameters'); } - $this->_conn->insert('blob_table', [ + $this->connection->insert('blob_table', [ 'id' => 1, 'clobfield' => 'ignored', 'blobfield' => 'test', @@ -128,7 +128,7 @@ public function testUpdateProcessesStream() ParameterType::LARGE_OBJECT, ]); - $this->_conn->update('blob_table', [ + $this->connection->update('blob_table', [ 'id' => 1, 'blobfield' => fopen('data://text/plain,test2', 'r'), ], ['id' => 1], [ @@ -141,13 +141,13 @@ public function testUpdateProcessesStream() public function testBindParamProcessesStream() { - if (in_array($this->_conn->getDatabasePlatform()->getName(), ['oracle', 'db2'], true)) { + if (in_array($this->connection->getDatabasePlatform()->getName(), ['oracle', 'db2'], true)) { // https://github.com/doctrine/dbal/issues/3288 for DB2 // https://github.com/doctrine/dbal/issues/3290 for Oracle $this->markTestIncomplete('Platform does not support stream resources as parameters'); } - $stmt = $this->_conn->prepare("INSERT INTO blob_table(id, clobfield, blobfield) VALUES (1, 'ignored', ?)"); + $stmt = $this->connection->prepare("INSERT INTO blob_table(id, clobfield, blobfield) VALUES (1, 'ignored', ?)"); $stream = null; $stmt->bindParam(1, $stream, ParameterType::LARGE_OBJECT); @@ -162,11 +162,11 @@ public function testBindParamProcessesStream() private function assertBlobContains($text) { - $rows = $this->_conn->query('SELECT blobfield FROM blob_table')->fetchAll(FetchMode::COLUMN); + $rows = $this->connection->query('SELECT blobfield FROM blob_table')->fetchAll(FetchMode::COLUMN); self::assertCount(1, $rows); - $blobValue = Type::getType('blob')->convertToPHPValue($rows[0], $this->_conn->getDatabasePlatform()); + $blobValue = Type::getType('blob')->convertToPHPValue($rows[0], $this->connection->getDatabasePlatform()); self::assertInternalType('resource', $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 c6cca6d8e68..b9d03d5e66c 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php @@ -4,6 +4,7 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\ConnectionException; +use Doctrine\DBAL\Driver\Connection as DriverConnection; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; @@ -31,204 +32,204 @@ protected function tearDown() public function testGetWrappedConnection() { - self::assertInstanceOf('Doctrine\DBAL\Driver\Connection', $this->_conn->getWrappedConnection()); + self::assertInstanceOf(DriverConnection::class, $this->connection->getWrappedConnection()); } public function testCommitWithRollbackOnlyThrowsException() { - $this->_conn->beginTransaction(); - $this->_conn->setRollbackOnly(); + $this->connection->beginTransaction(); + $this->connection->setRollbackOnly(); $this->expectException(ConnectionException::class); - $this->_conn->commit(); + $this->connection->commit(); } public function testTransactionNestingBehavior() { try { - $this->_conn->beginTransaction(); - self::assertEquals(1, $this->_conn->getTransactionNestingLevel()); + $this->connection->beginTransaction(); + self::assertEquals(1, $this->connection->getTransactionNestingLevel()); try { - $this->_conn->beginTransaction(); - self::assertEquals(2, $this->_conn->getTransactionNestingLevel()); + $this->connection->beginTransaction(); + self::assertEquals(2, $this->connection->getTransactionNestingLevel()); throw new Exception(); - $this->_conn->commit(); // never reached + $this->connection->commit(); // never reached } catch (Throwable $e) { - $this->_conn->rollBack(); - self::assertEquals(1, $this->_conn->getTransactionNestingLevel()); + $this->connection->rollBack(); + self::assertEquals(1, $this->connection->getTransactionNestingLevel()); //no rethrow } - self::assertTrue($this->_conn->isRollbackOnly()); + self::assertTrue($this->connection->isRollbackOnly()); - $this->_conn->commit(); // should throw exception + $this->connection->commit(); // should throw exception $this->fail('Transaction commit after failed nested transaction should fail.'); } catch (ConnectionException $e) { - self::assertEquals(1, $this->_conn->getTransactionNestingLevel()); - $this->_conn->rollBack(); - self::assertEquals(0, $this->_conn->getTransactionNestingLevel()); + self::assertEquals(1, $this->connection->getTransactionNestingLevel()); + $this->connection->rollBack(); + self::assertEquals(0, $this->connection->getTransactionNestingLevel()); } } public function testTransactionNestingBehaviorWithSavepoints() { - if (!$this->_conn->getDatabasePlatform()->supportsSavepoints()) { + if (! $this->connection->getDatabasePlatform()->supportsSavepoints()) { $this->markTestSkipped('This test requires the platform to support savepoints.'); } - $this->_conn->setNestTransactionsWithSavepoints(true); + $this->connection->setNestTransactionsWithSavepoints(true); try { - $this->_conn->beginTransaction(); - self::assertEquals(1, $this->_conn->getTransactionNestingLevel()); + $this->connection->beginTransaction(); + self::assertEquals(1, $this->connection->getTransactionNestingLevel()); try { - $this->_conn->beginTransaction(); - self::assertEquals(2, $this->_conn->getTransactionNestingLevel()); - $this->_conn->beginTransaction(); - self::assertEquals(3, $this->_conn->getTransactionNestingLevel()); - $this->_conn->commit(); - self::assertEquals(2, $this->_conn->getTransactionNestingLevel()); + $this->connection->beginTransaction(); + self::assertEquals(2, $this->connection->getTransactionNestingLevel()); + $this->connection->beginTransaction(); + self::assertEquals(3, $this->connection->getTransactionNestingLevel()); + $this->connection->commit(); + self::assertEquals(2, $this->connection->getTransactionNestingLevel()); throw new Exception(); - $this->_conn->commit(); // never reached + $this->connection->commit(); // never reached } catch (Throwable $e) { - $this->_conn->rollBack(); - self::assertEquals(1, $this->_conn->getTransactionNestingLevel()); + $this->connection->rollBack(); + self::assertEquals(1, $this->connection->getTransactionNestingLevel()); //no rethrow } - self::assertFalse($this->_conn->isRollbackOnly()); + self::assertFalse($this->connection->isRollbackOnly()); try { - $this->_conn->setNestTransactionsWithSavepoints(false); + $this->connection->setNestTransactionsWithSavepoints(false); $this->fail('Should not be able to disable savepoints in usage for nested transactions inside an open transaction.'); } catch (ConnectionException $e) { - self::assertTrue($this->_conn->getNestTransactionsWithSavepoints()); + self::assertTrue($this->connection->getNestTransactionsWithSavepoints()); } - $this->_conn->commit(); // should not throw exception + $this->connection->commit(); // should not throw exception } catch (ConnectionException $e) { $this->fail('Transaction commit after failed nested transaction should not fail when using savepoints.'); - $this->_conn->rollBack(); + $this->connection->rollBack(); } } public function testTransactionNestingBehaviorCantBeChangedInActiveTransaction() { - if (!$this->_conn->getDatabasePlatform()->supportsSavepoints()) { + if (! $this->connection->getDatabasePlatform()->supportsSavepoints()) { $this->markTestSkipped('This test requires the platform to support savepoints.'); } - $this->_conn->beginTransaction(); + $this->connection->beginTransaction(); $this->expectException(ConnectionException::class); - $this->_conn->setNestTransactionsWithSavepoints(true); + $this->connection->setNestTransactionsWithSavepoints(true); } public function testSetNestedTransactionsThroughSavepointsNotSupportedThrowsException() { - if ($this->_conn->getDatabasePlatform()->supportsSavepoints()) { + if ($this->connection->getDatabasePlatform()->supportsSavepoints()) { $this->markTestSkipped('This test requires the platform not to support savepoints.'); } $this->expectException(ConnectionException::class); $this->expectExceptionMessage('Savepoints are not supported by this driver.'); - $this->_conn->setNestTransactionsWithSavepoints(true); + $this->connection->setNestTransactionsWithSavepoints(true); } public function testCreateSavepointsNotSupportedThrowsException() { - if ($this->_conn->getDatabasePlatform()->supportsSavepoints()) { + if ($this->connection->getDatabasePlatform()->supportsSavepoints()) { $this->markTestSkipped('This test requires the platform not to support savepoints.'); } $this->expectException(ConnectionException::class); $this->expectExceptionMessage('Savepoints are not supported by this driver.'); - $this->_conn->createSavepoint('foo'); + $this->connection->createSavepoint('foo'); } public function testReleaseSavepointsNotSupportedThrowsException() { - if ($this->_conn->getDatabasePlatform()->supportsSavepoints()) { + if ($this->connection->getDatabasePlatform()->supportsSavepoints()) { $this->markTestSkipped('This test requires the platform not to support savepoints.'); } $this->expectException(ConnectionException::class); $this->expectExceptionMessage('Savepoints are not supported by this driver.'); - $this->_conn->releaseSavepoint('foo'); + $this->connection->releaseSavepoint('foo'); } public function testRollbackSavepointsNotSupportedThrowsException() { - if ($this->_conn->getDatabasePlatform()->supportsSavepoints()) { + if ($this->connection->getDatabasePlatform()->supportsSavepoints()) { $this->markTestSkipped('This test requires the platform not to support savepoints.'); } $this->expectException(ConnectionException::class); $this->expectExceptionMessage('Savepoints are not supported by this driver.'); - $this->_conn->rollbackSavepoint('foo'); + $this->connection->rollbackSavepoint('foo'); } public function testTransactionBehaviorWithRollback() { try { - $this->_conn->beginTransaction(); - self::assertEquals(1, $this->_conn->getTransactionNestingLevel()); + $this->connection->beginTransaction(); + self::assertEquals(1, $this->connection->getTransactionNestingLevel()); throw new Exception(); - $this->_conn->commit(); // never reached + $this->connection->commit(); // never reached } catch (Throwable $e) { - self::assertEquals(1, $this->_conn->getTransactionNestingLevel()); - $this->_conn->rollBack(); - self::assertEquals(0, $this->_conn->getTransactionNestingLevel()); + self::assertEquals(1, $this->connection->getTransactionNestingLevel()); + $this->connection->rollBack(); + self::assertEquals(0, $this->connection->getTransactionNestingLevel()); } } public function testTransactionBehaviour() { try { - $this->_conn->beginTransaction(); - self::assertEquals(1, $this->_conn->getTransactionNestingLevel()); - $this->_conn->commit(); + $this->connection->beginTransaction(); + self::assertEquals(1, $this->connection->getTransactionNestingLevel()); + $this->connection->commit(); } catch (Throwable $e) { - $this->_conn->rollBack(); - self::assertEquals(0, $this->_conn->getTransactionNestingLevel()); + $this->connection->rollBack(); + self::assertEquals(0, $this->connection->getTransactionNestingLevel()); } - self::assertEquals(0, $this->_conn->getTransactionNestingLevel()); + self::assertEquals(0, $this->connection->getTransactionNestingLevel()); } public function testTransactionalWithException() { try { - $this->_conn->transactional(static function($conn) { + $this->connection->transactional(static function ($conn) { /** @var Connection $conn */ $conn->executeQuery($conn->getDatabasePlatform()->getDummySelectSQL()); throw new RuntimeException('Ooops!'); }); $this->fail('Expected exception'); } catch (RuntimeException $expected) { - self::assertEquals(0, $this->_conn->getTransactionNestingLevel()); + self::assertEquals(0, $this->connection->getTransactionNestingLevel()); } } public function testTransactionalWithThrowable() { try { - $this->_conn->transactional(static function($conn) { + $this->connection->transactional(static function ($conn) { /** @var Connection $conn */ $conn->executeQuery($conn->getDatabasePlatform()->getDummySelectSQL()); throw new Error('Ooops!'); }); $this->fail('Expected exception'); } catch (Error $expected) { - self::assertEquals(0, $this->_conn->getTransactionNestingLevel()); + self::assertEquals(0, $this->connection->getTransactionNestingLevel()); } } public function testTransactional() { - $res = $this->_conn->transactional(static function($conn) { + $res = $this->connection->transactional(static function ($conn) { /** @var Connection $conn */ $conn->executeQuery($conn->getDatabasePlatform()->getDummySelectSQL()); }); @@ -238,7 +239,7 @@ public function testTransactional() public function testTransactionalReturnValue() { - $res = $this->_conn->transactional(static function() { + $res = $this->connection->transactional(static function () { return 42; }); @@ -251,15 +252,15 @@ public function testTransactionalReturnValue() public function testQuote() { self::assertEquals( - $this->_conn->quote('foo', Type::STRING), - $this->_conn->quote('foo', ParameterType::STRING) + $this->connection->quote('foo', Type::STRING), + $this->connection->quote('foo', ParameterType::STRING) ); } public function testPingDoesTriggersConnect() { - self::assertTrue($this->_conn->ping()); - self::assertTrue($this->_conn->isConnected()); + self::assertTrue($this->connection->ping()); + self::assertTrue($this->connection->isConnected()); } /** @@ -267,17 +268,17 @@ public function testPingDoesTriggersConnect() */ public function testConnectWithoutExplicitDatabaseName() { - if (in_array($this->_conn->getDatabasePlatform()->getName(), array('oracle', 'db2'), true)) { + if (in_array($this->connection->getDatabasePlatform()->getName(), ['oracle', 'db2'], true)) { $this->markTestSkipped('Platform does not support connecting without database name.'); } - $params = $this->_conn->getParams(); + $params = $this->connection->getParams(); unset($params['dbname']); $connection = DriverManager::getConnection( $params, - $this->_conn->getConfiguration(), - $this->_conn->getEventManager() + $this->connection->getConfiguration(), + $this->connection->getEventManager() ); self::assertTrue($connection->connect()); @@ -290,17 +291,18 @@ public function testConnectWithoutExplicitDatabaseName() */ public function testDeterminesDatabasePlatformWhenConnectingToNonExistentDatabase() { - if (in_array($this->_conn->getDatabasePlatform()->getName(), ['oracle', 'db2'], true)) { + if (in_array($this->connection->getDatabasePlatform()->getName(), ['oracle', 'db2'], true)) { $this->markTestSkipped('Platform does not support connecting without database name.'); } - $params = $this->_conn->getParams(); + $params = $this->connection->getParams(); + $params['dbname'] = 'foo_bar'; $connection = DriverManager::getConnection( $params, - $this->_conn->getConfiguration(), - $this->_conn->getEventManager() + $this->connection->getConfiguration(), + $this->connection->getEventManager() ); self::assertInstanceOf(AbstractPlatform::class, $connection->getDatabasePlatform()); diff --git a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php index e688a5f0604..9f6fcbfd75b 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php @@ -4,12 +4,15 @@ use DateTime; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver\Mysqli\Driver as MySQLiDriver; +use Doctrine\DBAL\Driver\SQLSrv\Driver as SQLSrvDriver; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Platforms\TrimMode; use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\Table; +use Doctrine\DBAL\Statement; use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DbalFunctionalTestCase; use const CASE_LOWER; @@ -23,6 +26,7 @@ use function is_numeric; use function json_encode; use function property_exists; +use function sprintf; use function strtotime; class DataAccessTest extends DbalFunctionalTestCase @@ -45,18 +49,18 @@ protected function setUp() $table->addColumn('test_datetime', 'datetime', ['notnull' => false]); $table->setPrimaryKey(['test_int']); - $sm = $this->_conn->getSchemaManager(); + $sm = $this->connection->getSchemaManager(); $sm->createTable($table); - $this->_conn->insert('fetch_table', array('test_int' => 1, 'test_string' => 'foo', 'test_datetime' => '2010-01-01 10:10:10')); + $this->connection->insert('fetch_table', ['test_int' => 1, 'test_string' => 'foo', 'test_datetime' => '2010-01-01 10:10:10']); self::$generated = true; } public function testPrepareWithBindValue() { $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; - $stmt = $this->_conn->prepare($sql); - self::assertInstanceOf('Doctrine\DBAL\Statement', $stmt); + $stmt = $this->connection->prepare($sql); + self::assertInstanceOf(Statement::class, $stmt); $stmt->bindValue(1, 1); $stmt->bindValue(2, 'foo'); @@ -73,8 +77,8 @@ public function testPrepareWithBindParam() $paramStr = 'foo'; $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; - $stmt = $this->_conn->prepare($sql); - self::assertInstanceOf('Doctrine\DBAL\Statement', $stmt); + $stmt = $this->connection->prepare($sql); + self::assertInstanceOf(Statement::class, $stmt); $stmt->bindParam(1, $paramInt); $stmt->bindParam(2, $paramStr); @@ -91,8 +95,8 @@ public function testPrepareWithFetchAll() $paramStr = 'foo'; $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; - $stmt = $this->_conn->prepare($sql); - self::assertInstanceOf('Doctrine\DBAL\Statement', $stmt); + $stmt = $this->connection->prepare($sql); + self::assertInstanceOf(Statement::class, $stmt); $stmt->bindParam(1, $paramInt); $stmt->bindParam(2, $paramStr); @@ -112,8 +116,8 @@ public function testPrepareWithFetchAllBoth() $paramStr = 'foo'; $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; - $stmt = $this->_conn->prepare($sql); - self::assertInstanceOf('Doctrine\DBAL\Statement', $stmt); + $stmt = $this->connection->prepare($sql); + self::assertInstanceOf(Statement::class, $stmt); $stmt->bindParam(1, $paramInt); $stmt->bindParam(2, $paramStr); @@ -130,8 +134,8 @@ public function testPrepareWithFetchColumn() $paramStr = 'foo'; $sql = 'SELECT test_int FROM fetch_table WHERE test_int = ? AND test_string = ?'; - $stmt = $this->_conn->prepare($sql); - self::assertInstanceOf('Doctrine\DBAL\Statement', $stmt); + $stmt = $this->connection->prepare($sql); + self::assertInstanceOf(Statement::class, $stmt); $stmt->bindParam(1, $paramInt); $stmt->bindParam(2, $paramStr); @@ -147,8 +151,8 @@ public function testPrepareWithIterator() $paramStr = 'foo'; $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; - $stmt = $this->_conn->prepare($sql); - self::assertInstanceOf('Doctrine\DBAL\Statement', $stmt); + $stmt = $this->connection->prepare($sql); + self::assertInstanceOf(Statement::class, $stmt); $stmt->bindParam(1, $paramInt); $stmt->bindParam(2, $paramStr); @@ -169,10 +173,13 @@ public function testPrepareWithQuoted() $paramInt = 1; $paramStr = 'foo'; - $sql = "SELECT test_int, test_string FROM " . $this->_conn->quoteIdentifier($table) . " ". - "WHERE test_int = " . $this->_conn->quote($paramInt) . " AND test_string = " . $this->_conn->quote($paramStr); - $stmt = $this->_conn->prepare($sql); - self::assertInstanceOf('Doctrine\DBAL\Statement', $stmt); + $stmt = $this->connection->prepare(sprintf( + 'SELECT test_int, test_string FROM %s WHERE test_int = %s AND test_string = %s', + $this->connection->quoteIdentifier($table), + $this->connection->quote($paramInt), + $this->connection->quote($paramStr) + )); + self::assertInstanceOf(Statement::class, $stmt); } public function testPrepareWithExecuteParams() @@ -181,8 +188,8 @@ public function testPrepareWithExecuteParams() $paramStr = 'foo'; $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; - $stmt = $this->_conn->prepare($sql); - self::assertInstanceOf('Doctrine\DBAL\Statement', $stmt); + $stmt = $this->connection->prepare($sql); + self::assertInstanceOf(Statement::class, $stmt); $stmt->execute([$paramInt, $paramStr]); $row = $stmt->fetch(FetchMode::ASSOCIATIVE); @@ -194,7 +201,7 @@ public function testPrepareWithExecuteParams() public function testFetchAll() { $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; - $data = $this->_conn->fetchAll($sql, array(1, 'foo')); + $data = $this->connection->fetchAll($sql, [1, 'foo']); self::assertCount(1, $data); @@ -215,7 +222,7 @@ public function testFetchAllWithTypes() $datetime = new DateTime($datetimeString); $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; - $data = $this->_conn->fetchAll($sql, [1, $datetime], [ParameterType::STRING, Type::DATETIME]); + $data = $this->connection->fetchAll($sql, [1, $datetime], [ParameterType::STRING, Type::DATETIME]); self::assertCount(1, $data); @@ -233,21 +240,21 @@ public function testFetchAllWithTypes() */ public function testFetchAllWithMissingTypes() { - if ($this->_conn->getDriver() instanceof \Doctrine\DBAL\Driver\Mysqli\Driver || - $this->_conn->getDriver() instanceof \Doctrine\DBAL\Driver\SQLSrv\Driver) { + if ($this->connection->getDriver() instanceof MySQLiDriver || + $this->connection->getDriver() instanceof SQLSrvDriver) { $this->markTestSkipped('mysqli and sqlsrv actually supports this'); } $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 = ?'; - $data = $this->_conn->fetchAll($sql, [1, $datetime]); + $this->connection->fetchAll($sql, [1, $datetime]); } public function testFetchBoth() { $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; - $row = $this->_conn->executeQuery($sql, [1, 'foo'])->fetch(FetchMode::MIXED); + $row = $this->connection->executeQuery($sql, [1, 'foo'])->fetch(FetchMode::MIXED); self::assertNotFalse($row); @@ -262,14 +269,14 @@ public function testFetchBoth() public function testFetchNoResult() { self::assertFalse( - $this->_conn->executeQuery('SELECT test_int FROM fetch_table WHERE test_int = ?', [-1])->fetch() + $this->connection->executeQuery('SELECT test_int FROM fetch_table WHERE test_int = ?', [-1])->fetch() ); } public function testFetchAssoc() { $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; - $row = $this->_conn->fetchAssoc($sql, array(1, 'foo')); + $row = $this->connection->fetchAssoc($sql, [1, 'foo']); self::assertNotFalse($row); @@ -285,7 +292,7 @@ public function testFetchAssocWithTypes() $datetime = new DateTime($datetimeString); $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; - $row = $this->_conn->fetchAssoc($sql, [1, $datetime], [ParameterType::STRING, Type::DATETIME]); + $row = $this->connection->fetchAssoc($sql, [1, $datetime], [ParameterType::STRING, Type::DATETIME]); self::assertNotFalse($row); @@ -300,21 +307,21 @@ public function testFetchAssocWithTypes() */ public function testFetchAssocWithMissingTypes() { - if ($this->_conn->getDriver() instanceof \Doctrine\DBAL\Driver\Mysqli\Driver || - $this->_conn->getDriver() instanceof \Doctrine\DBAL\Driver\SQLSrv\Driver) { + if ($this->connection->getDriver() instanceof MySQLiDriver || + $this->connection->getDriver() instanceof SQLSrvDriver) { $this->markTestSkipped('mysqli and sqlsrv actually supports this'); } $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->_conn->fetchAssoc($sql, array(1, $datetime)); + $this->connection->fetchAssoc($sql, [1, $datetime]); } public function testFetchArray() { $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; - $row = $this->_conn->fetchArray($sql, array(1, 'foo')); + $row = $this->connection->fetchArray($sql, [1, 'foo']); self::assertEquals(1, $row[0]); self::assertEquals('foo', $row[1]); @@ -326,7 +333,7 @@ public function testFetchArrayWithTypes() $datetime = new DateTime($datetimeString); $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; - $row = $this->_conn->fetchArray($sql, [1, $datetime], [ParameterType::STRING, Type::DATETIME]); + $row = $this->connection->fetchArray($sql, [1, $datetime], [ParameterType::STRING, Type::DATETIME]); self::assertNotFalse($row); @@ -341,26 +348,26 @@ public function testFetchArrayWithTypes() */ public function testFetchArrayWithMissingTypes() { - if ($this->_conn->getDriver() instanceof \Doctrine\DBAL\Driver\Mysqli\Driver || - $this->_conn->getDriver() instanceof \Doctrine\DBAL\Driver\SQLSrv\Driver) { + if ($this->connection->getDriver() instanceof MySQLiDriver || + $this->connection->getDriver() instanceof SQLSrvDriver) { $this->markTestSkipped('mysqli and sqlsrv actually supports this'); } $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->_conn->fetchArray($sql, [1, $datetime]); + $row = $this->connection->fetchArray($sql, [1, $datetime]); } public function testFetchColumn() { $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; - $testInt = $this->_conn->fetchColumn($sql, [1, 'foo'], 0); + $testInt = $this->connection->fetchColumn($sql, [1, 'foo'], 0); self::assertEquals(1, $testInt); $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; - $testString = $this->_conn->fetchColumn($sql, [1, 'foo'], 1); + $testString = $this->connection->fetchColumn($sql, [1, 'foo'], 1); self::assertEquals('foo', $testString); } @@ -371,7 +378,7 @@ public function testFetchColumnWithTypes() $datetime = new DateTime($datetimeString); $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; - $column = $this->_conn->fetchColumn($sql, [1, $datetime], 1, [ParameterType::STRING, Type::DATETIME]); + $column = $this->connection->fetchColumn($sql, [1, $datetime], 1, [ParameterType::STRING, Type::DATETIME]); self::assertNotFalse($column); @@ -383,15 +390,15 @@ public function testFetchColumnWithTypes() */ public function testFetchColumnWithMissingTypes() { - if ($this->_conn->getDriver() instanceof \Doctrine\DBAL\Driver\Mysqli\Driver || - $this->_conn->getDriver() instanceof \Doctrine\DBAL\Driver\SQLSrv\Driver) { + if ($this->connection->getDriver() instanceof MySQLiDriver || + $this->connection->getDriver() instanceof SQLSrvDriver) { $this->markTestSkipped('mysqli and sqlsrv actually supports this'); } $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->_conn->fetchColumn($sql, [1, $datetime], 1); + $column = $this->connection->fetchColumn($sql, [1, $datetime], 1); } /** @@ -400,7 +407,7 @@ public function testFetchColumnWithMissingTypes() public function testExecuteQueryBindDateTimeType() { $sql = 'SELECT count(*) AS c FROM fetch_table WHERE test_datetime = ?'; - $stmt = $this->_conn->executeQuery( + $stmt = $this->connection->executeQuery( $sql, [1 => new DateTime('2010-01-01 10:10:10')], [1 => Type::DATETIME] @@ -417,7 +424,7 @@ public function testExecuteUpdateBindDateTimeType() $datetime = new DateTime('2010-02-02 20:20:20'); $sql = 'INSERT INTO fetch_table (test_int, test_string, test_datetime) VALUES (?, ?, ?)'; - $affectedRows = $this->_conn->executeUpdate($sql, [ + $affectedRows = $this->connection->executeUpdate($sql, [ 1 => 50, 2 => 'foo', 3 => $datetime, @@ -428,7 +435,7 @@ public function testExecuteUpdateBindDateTimeType() ]); self::assertEquals(1, $affectedRows); - self::assertEquals(1, $this->_conn->executeQuery( + self::assertEquals(1, $this->connection->executeQuery( 'SELECT count(*) AS c FROM fetch_table WHERE test_datetime = ?', [1 => $datetime], [1 => Type::DATETIME] @@ -441,7 +448,7 @@ public function testExecuteUpdateBindDateTimeType() public function testPrepareQueryBindValueDateTimeType() { $sql = 'SELECT count(*) AS c FROM fetch_table WHERE test_datetime = ?'; - $stmt = $this->_conn->prepare($sql); + $stmt = $this->connection->prepare($sql); $stmt->bindValue(1, new DateTime('2010-01-01 10:10:10'), Type::DATETIME); $stmt->execute(); @@ -454,10 +461,10 @@ public function testPrepareQueryBindValueDateTimeType() public function testNativeArrayListSupport() { for ($i = 100; $i < 110; $i++) { - $this->_conn->insert('fetch_table', ['test_int' => $i, 'test_string' => 'foo' . $i, 'test_datetime' => '2010-01-01 10:10:10']); + $this->connection->insert('fetch_table', ['test_int' => $i, 'test_string' => 'foo' . $i, 'test_datetime' => '2010-01-01 10:10:10']); } - $stmt = $this->_conn->executeQuery( + $stmt = $this->connection->executeQuery( 'SELECT test_int FROM fetch_table WHERE test_int IN (?)', [[100, 101, 102, 103, 104]], [Connection::PARAM_INT_ARRAY] @@ -467,7 +474,7 @@ public function testNativeArrayListSupport() self::assertCount(5, $data); self::assertEquals([[100], [101], [102], [103], [104]], $data); - $stmt = $this->_conn->executeQuery( + $stmt = $this->connection->executeQuery( 'SELECT test_int FROM fetch_table WHERE test_string IN (?)', [['foo100', 'foo101', 'foo102', 'foo103', 'foo104']], [Connection::PARAM_STR_ARRAY] @@ -484,10 +491,10 @@ public function testNativeArrayListSupport() public function testTrimExpression($value, $position, $char, $expectedResult) { $sql = 'SELECT ' . - $this->_conn->getDatabasePlatform()->getTrimExpression($value, $position, $char) . ' AS trimmed ' . + $this->connection->getDatabasePlatform()->getTrimExpression($value, $position, $char) . ' AS trimmed ' . 'FROM fetch_table'; - $row = $this->_conn->fetchAssoc($sql); + $row = $this->connection->fetchAssoc($sql); $row = array_change_key_case($row, CASE_LOWER); self::assertEquals($expectedResult, $row['trimmed']); @@ -540,7 +547,7 @@ public function getTrimExpressionData() */ public function testDateArithmetics() { - $p = $this->_conn->getDatabasePlatform(); + $p = $this->connection->getDatabasePlatform(); $sql = 'SELECT '; $sql .= $p->getDateAddSecondsExpression('test_datetime', 1) . ' AS add_seconds, '; $sql .= $p->getDateSubSecondsExpression('test_datetime', 1) . ' AS sub_seconds, '; @@ -560,7 +567,7 @@ public function testDateArithmetics() $sql .= $p->getDateSubYearsExpression('test_datetime', 6) . ' AS sub_years '; $sql .= 'FROM fetch_table'; - $row = $this->_conn->fetchAssoc($sql); + $row = $this->connection->fetchAssoc($sql); $row = array_change_key_case($row, CASE_LOWER); self::assertEquals('2010-01-01 10:10:11', date('Y-m-d H:i:s', strtotime($row['add_seconds'])), 'Adding second should end up on 2010-01-01 10:10:11'); @@ -583,7 +590,7 @@ public function testDateArithmetics() public function testSqliteDateArithmeticWithDynamicInterval() { - $platform = $this->_conn->getDatabasePlatform(); + $platform = $this->connection->getDatabasePlatform(); if (! $platform instanceof SqlitePlatform) { $this->markTestSkipped('test is for sqlite only'); @@ -595,23 +602,23 @@ public function testSqliteDateArithmeticWithDynamicInterval() $table->setPrimaryKey(['test_date']); /** @var AbstractSchemaManager $sm */ - $sm = $this->_conn->getSchemaManager(); + $sm = $this->connection->getSchemaManager(); $sm->createTable($table); - $this->_conn->insert('fetch_table_date_math', ['test_date' => '2010-01-01', 'test_days' => 10]); - $this->_conn->insert('fetch_table_date_math', ['test_date' => '2010-06-01', 'test_days' => 20]); + $this->connection->insert('fetch_table_date_math', ['test_date' => '2010-01-01', 'test_days' => 10]); + $this->connection->insert('fetch_table_date_math', ['test_date' => '2010-06-01', 'test_days' => 20]); $sql = 'SELECT COUNT(*) FROM fetch_table_date_math WHERE '; $sql .= $platform->getDateSubDaysExpression('test_date', 'test_days') . " < '2010-05-12'"; - $rowCount = $this->_conn->fetchColumn($sql, [], 0); + $rowCount = $this->connection->fetchColumn($sql, [], 0); $this->assertEquals(1, $rowCount); } public function testLocateExpression() { - $platform = $this->_conn->getDatabasePlatform(); + $platform = $this->connection->getDatabasePlatform(); $sql = 'SELECT '; $sql .= $platform->getLocateExpression('test_string', "'oo'") . ' AS locate1, '; @@ -625,7 +632,7 @@ public function testLocateExpression() $sql .= $platform->getLocateExpression('test_string', "'oo'", 3) . ' AS locate9 '; $sql .= 'FROM fetch_table'; - $row = $this->_conn->fetchAssoc($sql); + $row = $this->connection->fetchAssoc($sql); $row = array_change_key_case($row, CASE_LOWER); self::assertEquals(2, $row['locate1']); @@ -641,8 +648,8 @@ public function testLocateExpression() public function testQuoteSQLInjection() { - $sql = 'SELECT * FROM fetch_table WHERE test_string = ' . $this->_conn->quote("bar' OR '1'='1"); - $rows = $this->_conn->fetchAll($sql); + $sql = 'SELECT * FROM fetch_table WHERE test_string = ' . $this->connection->quote("bar' OR '1'='1"); + $rows = $this->connection->fetchAll($sql); self::assertCount(0, $rows, 'no result should be returned, otherwise SQL injection is possible'); } @@ -652,8 +659,8 @@ public function testQuoteSQLInjection() */ public function testBitComparisonExpressionSupport() { - $this->_conn->exec('DELETE FROM fetch_table'); - $platform = $this->_conn->getDatabasePlatform(); + $this->connection->exec('DELETE FROM fetch_table'); + $platform = $this->connection->getDatabasePlatform(); $bitmap = []; for ($i = 2; $i < 9; $i += 2) { @@ -661,7 +668,7 @@ public function testBitComparisonExpressionSupport() 'bit_or' => ($i | 2), 'bit_and' => ($i & 2), ]; - $this->_conn->insert('fetch_table', [ + $this->connection->insert('fetch_table', [ 'test_int' => $i, 'test_string' => json_encode($bitmap[$i]), 'test_datetime' => '2010-01-01 10:10:10', @@ -675,7 +682,7 @@ public function testBitComparisonExpressionSupport() $sql[] = $platform->getBitAndComparisonExpression('test_int', 2) . ' AS bit_and '; $sql[] = 'FROM fetch_table'; - $stmt = $this->_conn->executeQuery(implode(PHP_EOL, $sql)); + $stmt = $this->connection->executeQuery(implode(PHP_EOL, $sql)); $data = $stmt->fetchAll(FetchMode::ASSOCIATIVE); self::assertCount(4, $data); @@ -700,7 +707,7 @@ public function testBitComparisonExpressionSupport() public function testSetDefaultFetchMode() { - $stmt = $this->_conn->query('SELECT * FROM fetch_table'); + $stmt = $this->connection->query('SELECT * FROM fetch_table'); $stmt->setFetchMode(FetchMode::NUMERIC); $row = array_keys($stmt->fetch()); @@ -717,7 +724,7 @@ public function testFetchAllStyleObject() $this->setupFixture(); $sql = 'SELECT test_int, test_string, test_datetime FROM fetch_table'; - $stmt = $this->_conn->prepare($sql); + $stmt = $this->connection->prepare($sql); $stmt->execute(); @@ -749,16 +756,16 @@ public function testFetchAllSupportFetchClass() $this->setupFixture(); $sql = 'SELECT test_int, test_string, test_datetime FROM fetch_table'; - $stmt = $this->_conn->prepare($sql); + $stmt = $this->connection->prepare($sql); $stmt->execute(); $results = $stmt->fetchAll( FetchMode::CUSTOM_OBJECT, - __NAMESPACE__ . '\\MyFetchClass' + MyFetchClass::class ); self::assertCount(1, $results); - self::assertInstanceOf(__NAMESPACE__ . '\\MyFetchClass', $results[0]); + self::assertInstanceOf(MyFetchClass::class, $results[0]); self::assertEquals(1, $results[0]->test_int); self::assertEquals('foo', $results[0]->test_string); @@ -771,13 +778,13 @@ public function testFetchAllSupportFetchClass() public function testFetchAllStyleColumn() { $sql = 'DELETE FROM fetch_table'; - $this->_conn->executeUpdate($sql); + $this->connection->executeUpdate($sql); - $this->_conn->insert('fetch_table', ['test_int' => 1, 'test_string' => 'foo']); - $this->_conn->insert('fetch_table', ['test_int' => 10, 'test_string' => 'foo']); + $this->connection->insert('fetch_table', ['test_int' => 1, 'test_string' => 'foo']); + $this->connection->insert('fetch_table', ['test_int' => 10, 'test_string' => 'foo']); $sql = 'SELECT test_int FROM fetch_table'; - $rows = $this->_conn->query($sql)->fetchAll(FetchMode::COLUMN); + $rows = $this->connection->query($sql)->fetchAll(FetchMode::COLUMN); self::assertEquals([1, 10], $rows); } @@ -791,13 +798,13 @@ public function testSetFetchModeClassFetchAll() $this->setupFixture(); $sql = 'SELECT * FROM fetch_table'; - $stmt = $this->_conn->query($sql); - $stmt->setFetchMode(FetchMode::CUSTOM_OBJECT, __NAMESPACE__ . '\\MyFetchClass'); + $stmt = $this->connection->query($sql); + $stmt->setFetchMode(FetchMode::CUSTOM_OBJECT, MyFetchClass::class); $results = $stmt->fetchAll(); self::assertCount(1, $results); - self::assertInstanceOf(__NAMESPACE__ . '\\MyFetchClass', $results[0]); + self::assertInstanceOf(MyFetchClass::class, $results[0]); self::assertEquals(1, $results[0]->test_int); self::assertEquals('foo', $results[0]->test_string); @@ -813,8 +820,8 @@ public function testSetFetchModeClassFetch() $this->setupFixture(); $sql = 'SELECT * FROM fetch_table'; - $stmt = $this->_conn->query($sql); - $stmt->setFetchMode(FetchMode::CUSTOM_OBJECT, __NAMESPACE__ . '\\MyFetchClass'); + $stmt = $this->connection->query($sql); + $stmt->setFetchMode(FetchMode::CUSTOM_OBJECT, MyFetchClass::class); $results = []; while ($row = $stmt->fetch()) { @@ -822,7 +829,7 @@ public function testSetFetchModeClassFetch() } self::assertCount(1, $results); - self::assertInstanceOf(__NAMESPACE__ . '\\MyFetchClass', $results[0]); + self::assertInstanceOf(MyFetchClass::class, $results[0]); self::assertEquals(1, $results[0]->test_int); self::assertEquals('foo', $results[0]->test_string); @@ -834,11 +841,11 @@ public function testSetFetchModeClassFetch() */ public function testEmptyFetchColumnReturnsFalse() { - $this->_conn->beginTransaction(); - $this->_conn->exec('DELETE FROM fetch_table'); - self::assertFalse($this->_conn->fetchColumn('SELECT test_int FROM fetch_table')); - self::assertFalse($this->_conn->query('SELECT test_int FROM fetch_table')->fetchColumn()); - $this->_conn->rollBack(); + $this->connection->beginTransaction(); + $this->connection->exec('DELETE FROM fetch_table'); + self::assertFalse($this->connection->fetchColumn('SELECT test_int FROM fetch_table')); + self::assertFalse($this->connection->query('SELECT test_int FROM fetch_table')->fetchColumn()); + $this->connection->rollBack(); } /** @@ -847,7 +854,7 @@ public function testEmptyFetchColumnReturnsFalse() public function testSetFetchModeOnDbalStatement() { $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; - $stmt = $this->_conn->executeQuery($sql, [1, 'foo']); + $stmt = $this->connection->executeQuery($sql, [1, 'foo']); $stmt->setFetchMode(FetchMode::NUMERIC); $row = $stmt->fetch(); @@ -863,7 +870,7 @@ public function testSetFetchModeOnDbalStatement() public function testEmptyParameters() { $sql = 'SELECT * FROM fetch_table WHERE test_int IN (?)'; - $stmt = $this->_conn->executeQuery($sql, [[]], [Connection::PARAM_INT_ARRAY]); + $stmt = $this->connection->executeQuery($sql, [[]], [Connection::PARAM_INT_ARRAY]); $rows = $stmt->fetchAll(); self::assertEquals([], $rows); @@ -874,13 +881,13 @@ public function testEmptyParameters() */ public function testFetchColumnNullValue() { - $this->_conn->executeUpdate( + $this->connection->executeUpdate( 'INSERT INTO fetch_table (test_int, test_string) VALUES (?, ?)', [2, 'foo'] ); self::assertNull( - $this->_conn->fetchColumn('SELECT test_datetime FROM fetch_table WHERE test_int = ?', [2]) + $this->connection->fetchColumn('SELECT test_datetime FROM fetch_table WHERE test_int = ?', [2]) ); } @@ -889,14 +896,14 @@ public function testFetchColumnNullValue() */ public function testFetchColumnNonExistingIndex() { - if ($this->_conn->getDriver()->getName() === 'pdo_sqlsrv') { + if ($this->connection->getDriver()->getName() === 'pdo_sqlsrv') { $this->markTestSkipped( 'Test does not work for pdo_sqlsrv driver as it throws a fatal error for a non-existing column index.' ); } self::assertNull( - $this->_conn->fetchColumn('SELECT test_int FROM fetch_table WHERE test_int = ?', [1], 1) + $this->connection->fetchColumn('SELECT test_int FROM fetch_table WHERE test_int = ?', [1], 1) ); } @@ -906,14 +913,14 @@ public function testFetchColumnNonExistingIndex() public function testFetchColumnNoResult() { self::assertFalse( - $this->_conn->fetchColumn('SELECT test_int FROM fetch_table WHERE test_int = ?', [-1]) + $this->connection->fetchColumn('SELECT test_int FROM fetch_table WHERE test_int = ?', [-1]) ); } private function setupFixture() { - $this->_conn->exec('DELETE FROM fetch_table'); - $this->_conn->insert('fetch_table', [ + $this->connection->exec('DELETE FROM fetch_table'); + $this->connection->insert('fetch_table', [ 'test_int' => 1, 'test_string' => 'foo', 'test_datetime' => '2010-01-01 10:10:10', @@ -925,7 +932,7 @@ private function skipOci8AndMysqli() if (isset($GLOBALS['db_type']) && $GLOBALS['db_type'] === 'oci8') { $this->markTestSkipped('Not supported by OCI8'); } - if ($this->_conn->getDriver()->getName() !== 'mysqli') { + if ($this->connection->getDriver()->getName() !== 'mysqli') { return; } @@ -935,5 +942,12 @@ private function skipOci8AndMysqli() class MyFetchClass { - public $test_int, $test_string, $test_datetime; + /** @var int */ + public $test_int; + + /** @var string */ + public $test_string; + + /** @var string */ + public $test_datetime; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php index a013a7706a8..738c259d5c0 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/AbstractDriverTest.php @@ -4,6 +4,7 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver; +use Doctrine\DBAL\Driver\Connection as DriverConnection; use Doctrine\Tests\DbalFunctionalTestCase; abstract class AbstractDriverTest extends DbalFunctionalTestCase @@ -27,7 +28,7 @@ protected function setUp() */ public function testConnectsWithoutDatabaseNameParameter() { - $params = $this->_conn->getParams(); + $params = $this->connection->getParams(); unset($params['dbname']); $user = $params['user'] ?? null; @@ -35,7 +36,7 @@ public function testConnectsWithoutDatabaseNameParameter() $connection = $this->driver->connect($params, $user, $password); - self::assertInstanceOf('Doctrine\DBAL\Driver\Connection', $connection); + self::assertInstanceOf(DriverConnection::class, $connection); } /** @@ -43,14 +44,14 @@ public function testConnectsWithoutDatabaseNameParameter() */ public function testReturnsDatabaseNameWithoutDatabaseNameParameter() { - $params = $this->_conn->getParams(); + $params = $this->connection->getParams(); unset($params['dbname']); $connection = new Connection( $params, - $this->_conn->getDriver(), - $this->_conn->getConfiguration(), - $this->_conn->getEventManager() + $this->connection->getDriver(), + $this->connection->getConfiguration(), + $this->connection->getEventManager() ); self::assertSame( diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2DriverTest.php index cb39d81135c..82da6090b7e 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2DriverTest.php @@ -16,7 +16,7 @@ protected function setUp() parent::setUp(); - if ($this->_conn->getDriver() instanceof DB2Driver) { + if ($this->connection->getDriver() instanceof DB2Driver) { return; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2StatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2StatementTest.php index 13226c32613..6c2ec6a9ca6 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2StatementTest.php @@ -19,7 +19,7 @@ protected function setUp() parent::setUp(); - if ($this->_conn->getDriver() instanceof DB2Driver) { + if ($this->connection->getDriver() instanceof DB2Driver) { return; } @@ -28,7 +28,7 @@ protected function setUp() public function testExecutionErrorsAreNotSuppressed() { - $stmt = $this->_conn->prepare('SELECT * FROM SYSIBM.SYSDUMMY1 WHERE \'foo\' = ?'); + $stmt = $this->connection->prepare('SELECT * FROM SYSIBM.SYSDUMMY1 WHERE \'foo\' = ?'); // unwrap the statement to prevent the wrapper from handling the PHPUnit-originated exception $wrappedStmt = $stmt->getWrappedStatement(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php index 591fff5a13e..8c274e1cbb2 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php @@ -18,7 +18,7 @@ protected function setUp() parent::setUp(); - if ($this->_conn->getDriver() instanceof Driver) { + if ($this->connection->getDriver() instanceof Driver) { return; } @@ -35,7 +35,7 @@ public function testDriverOptions() $driverOptions = [MYSQLI_OPT_CONNECT_TIMEOUT => 1]; $connection = $this->getConnection($driverOptions); - self::assertInstanceOf('\Doctrine\DBAL\Driver\Mysqli\MysqliConnection', $connection); + self::assertInstanceOf(MysqliConnection::class, $connection); } /** @@ -52,6 +52,9 @@ public function testPing() self::assertTrue($conn->ping()); } + /** + * @param mixed[] $driverOptions + */ private function getConnection(array $driverOptions) { 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 da9ee0b5e5b..d7f02a40306 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/DriverTest.php @@ -16,7 +16,7 @@ protected function setUp() parent::setUp(); - if ($this->_conn->getDriver() instanceof Driver) { + if ($this->connection->getDriver() instanceof Driver) { return; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/DriverTest.php index a5776b75c68..a781b31007d 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/DriverTest.php @@ -16,7 +16,7 @@ protected function setUp() parent::setUp(); - if ($this->_conn->getDriver() instanceof Driver) { + if ($this->connection->getDriver() instanceof Driver) { return; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/OCI8ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/OCI8ConnectionTest.php index cba1041129e..1c3226852d6 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/OCI8ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/OCI8ConnectionTest.php @@ -21,11 +21,11 @@ protected function setUp() parent::setUp(); - if (! $this->_conn->getDriver() instanceof Driver) { + if (! $this->connection->getDriver() instanceof Driver) { $this->markTestSkipped('oci8 only test.'); } - $this->driverConnection = $this->_conn->getWrappedConnection(); + $this->driverConnection = $this->connection->getWrappedConnection(); } /** @@ -33,8 +33,8 @@ protected function setUp() */ public function testLastInsertIdAcceptsFqn() { - $platform = $this->_conn->getDatabasePlatform(); - $schemaManager = $this->_conn->getSchemaManager(); + $platform = $this->connection->getDatabasePlatform(); + $schemaManager = $this->connection->getSchemaManager(); $table = new Table('DBAL2595'); $table->addColumn('id', 'integer', ['autoincrement' => true]); @@ -42,9 +42,9 @@ public function testLastInsertIdAcceptsFqn() $schemaManager->dropAndCreateTable($table); - $this->_conn->executeUpdate('INSERT INTO DBAL2595 (foo) VALUES (1)'); + $this->connection->executeUpdate('INSERT INTO DBAL2595 (foo) VALUES (1)'); - $schema = $this->_conn->getDatabase(); + $schema = $this->connection->getDatabase(); $sequence = $platform->getIdentitySequenceName($schema . '.DBAL2595', 'id'); self::assertSame(1, $this->driverConnection->lastInsertId($sequence)); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/StatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/StatementTest.php index f9ddce6f11c..db6a4d552ca 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/StatementTest.php @@ -16,7 +16,7 @@ protected function setUp() parent::setUp(); - if ($this->_conn->getDriver() instanceof Driver) { + if ($this->connection->getDriver() instanceof Driver) { return; } @@ -24,13 +24,16 @@ protected function setUp() } /** + * @param mixed[] $params + * @param mixed[] $expected + * * @dataProvider queryConversionProvider */ public function testQueryConversion($query, array $params, array $expected) { self::assertEquals( $expected, - $this->_conn->executeQuery($query, $params)->fetch() + $this->connection->executeQuery($query, $params)->fetch() ); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php index b5eebb92da3..214f90700c1 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php @@ -25,7 +25,7 @@ protected function setUp() parent::setUp(); - $this->driverConnection = $this->_conn->getWrappedConnection(); + $this->driverConnection = $this->connection->getWrappedConnection(); if ($this->driverConnection instanceof PDOConnection) { return; @@ -68,7 +68,7 @@ public function testThrowsWrappedExceptionOnExec() */ public function testThrowsWrappedExceptionOnPrepare() { - if ($this->_conn->getDriver()->getName() === 'pdo_sqlsrv') { + if ($this->connection->getDriver()->getName() === 'pdo_sqlsrv') { $this->markTestSkipped('pdo_sqlsrv does not allow setting PDO::ATTR_EMULATE_PREPARES at connection level.'); } @@ -86,7 +86,7 @@ public function testThrowsWrappedExceptionOnPrepare() sprintf( 'The PDO adapter %s does not check the query to be prepared server-side, ' . 'so no assertions can be made.', - $this->_conn->getDriver()->getName() + $this->connection->getDriver()->getName() ) ); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOMySql/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOMySql/DriverTest.php index 462f5941fa2..cb0f9633201 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOMySql/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOMySql/DriverTest.php @@ -16,7 +16,7 @@ protected function setUp() parent::setUp(); - if ($this->_conn->getDriver() instanceof Driver) { + if ($this->connection->getDriver() instanceof Driver) { return; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOOracle/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOOracle/DriverTest.php index 0fcba6d6431..604fbc8b123 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOOracle/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOOracle/DriverTest.php @@ -16,7 +16,7 @@ protected function setUp() parent::setUp(); - if ($this->_conn->getDriver() instanceof Driver) { + if ($this->connection->getDriver() instanceof Driver) { return; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgSql/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgSql/DriverTest.php index 7c595c9c7df..289621c5eba 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgSql/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgSql/DriverTest.php @@ -21,7 +21,7 @@ protected function setUp() parent::setUp(); - if ($this->_conn->getDriver() instanceof Driver) { + if ($this->connection->getDriver() instanceof Driver) { return; } @@ -33,15 +33,15 @@ protected function setUp() */ public function testDatabaseParameters($databaseName, $defaultDatabaseName, $expectedDatabaseName) { - $params = $this->_conn->getParams(); + $params = $this->connection->getParams(); $params['dbname'] = $databaseName; $params['default_dbname'] = $defaultDatabaseName; $connection = new Connection( $params, - $this->_conn->getDriver(), - $this->_conn->getConfiguration(), - $this->_conn->getEventManager() + $this->connection->getDriver(), + $this->connection->getConfiguration(), + $this->connection->getEventManager() ); self::assertSame( @@ -70,7 +70,7 @@ public function getDatabaseParameter() */ public function testConnectsWithApplicationNameParameter() { - $parameters = $this->_conn->getParams(); + $parameters = $this->connection->getParams(); $parameters['application_name'] = 'doctrine'; $user = $parameters['user'] ?? null; diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgsqlConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgsqlConnectionTest.php index 16021c3ea24..0893bed2e70 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgsqlConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgsqlConnectionTest.php @@ -18,7 +18,7 @@ protected function setUp() parent::setUp(); - if ($this->_conn->getDatabasePlatform() instanceof PostgreSqlPlatform) { + if ($this->connection->getDatabasePlatform() instanceof PostgreSqlPlatform) { return; } @@ -34,13 +34,13 @@ protected function setUp() */ public function testConnectsWithValidCharsetOption($charset) { - $params = $this->_conn->getParams(); + $params = $this->connection->getParams(); $params['charset'] = $charset; $connection = DriverManager::getConnection( $params, - $this->_conn->getConfiguration(), - $this->_conn->getEventManager() + $this->connection->getConfiguration(), + $this->connection->getEventManager() ); self::assertEquals( @@ -51,7 +51,7 @@ public function testConnectsWithValidCharsetOption($charset) } /** - * @return array + * @return mixed[][] */ public function getValidCharsets() { diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlite/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlite/DriverTest.php index e6ad8639552..36978d4b4fd 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlite/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlite/DriverTest.php @@ -16,7 +16,7 @@ protected function setUp() parent::setUp(); - if ($this->_conn->getDriver() instanceof Driver) { + if ($this->connection->getDriver() instanceof Driver) { return; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php index e9d224f8e0f..f125eab3515 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php @@ -18,7 +18,7 @@ protected function setUp() parent::setUp(); - if ($this->_conn->getDriver() instanceof Driver) { + if ($this->connection->getDriver() instanceof Driver) { return; } @@ -46,7 +46,7 @@ protected function getDatabaseNameForConnectionWithoutDatabaseNameParameter() */ protected function getConnection(array $driverOptions) : Connection { - return $this->_conn->getDriver()->connect( + return $this->connection->getDriver()->connect( [ 'host' => $GLOBALS['db_host'], 'port' => $GLOBALS['db_port'], diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/ConnectionTest.php index d94fb91df7d..63253a84408 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/ConnectionTest.php @@ -17,7 +17,7 @@ protected function setUp() parent::setUp(); - if ($this->_conn->getDriver() instanceof Driver) { + if ($this->connection->getDriver() instanceof Driver) { return; } @@ -26,7 +26,7 @@ protected function setUp() public function testNonPersistentConnection() { - $params = $this->_conn->getParams(); + $params = $this->connection->getParams(); $params['persistent'] = false; $conn = DriverManager::getConnection($params); @@ -38,7 +38,7 @@ public function testNonPersistentConnection() public function testPersistentConnection() { - $params = $this->_conn->getParams(); + $params = $this->connection->getParams(); $params['persistent'] = true; $conn = DriverManager::getConnection($params); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/DriverTest.php index 1dbe8eebee7..07d0189a88d 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/DriverTest.php @@ -17,7 +17,7 @@ protected function setUp() parent::setUp(); - if ($this->_conn->getDriver() instanceof Driver) { + if ($this->connection->getDriver() instanceof Driver) { return; } @@ -26,14 +26,14 @@ protected function setUp() public function testReturnsDatabaseNameWithoutDatabaseNameParameter() { - $params = $this->_conn->getParams(); + $params = $this->connection->getParams(); unset($params['dbname']); $connection = new Connection( $params, - $this->_conn->getDriver(), - $this->_conn->getConfiguration(), - $this->_conn->getEventManager() + $this->connection->getDriver(), + $this->connection->getConfiguration(), + $this->connection->getEventManager() ); // SQL Anywhere has no "default" database. The name of the default database diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/StatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/StatementTest.php index 1e2debe949f..3cf5c282ea0 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLAnywhere/StatementTest.php @@ -17,7 +17,7 @@ protected function setUp() parent::setUp(); - if ($this->_conn->getDriver() instanceof Driver) { + if ($this->connection->getDriver() instanceof Driver) { return; } @@ -26,7 +26,7 @@ protected function setUp() public function testNonPersistentStatement() { - $params = $this->_conn->getParams(); + $params = $this->connection->getParams(); $params['persistent'] = false; $conn = DriverManager::getConnection($params); @@ -41,7 +41,7 @@ public function testNonPersistentStatement() public function testPersistentStatement() { - $params = $this->_conn->getParams(); + $params = $this->connection->getParams(); $params['persistent'] = true; $conn = DriverManager::getConnection($params); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/DriverTest.php index 4ea3c9bc143..b09d7339fc9 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/DriverTest.php @@ -16,7 +16,7 @@ protected function setUp() parent::setUp(); - if ($this->_conn->getDriver() instanceof Driver) { + if ($this->connection->getDriver() instanceof Driver) { return; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/StatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/StatementTest.php index b6b325f23b4..38df9cb5181 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/StatementTest.php @@ -17,7 +17,7 @@ protected function setUp() parent::setUp(); - if ($this->_conn->getDriver() instanceof Driver) { + if ($this->connection->getDriver() instanceof Driver) { return; } @@ -27,7 +27,7 @@ protected function setUp() public function testFailureToPrepareResultsInException() { // use the driver connection directly to avoid having exception wrapped - $stmt = $this->_conn->getWrappedConnection()->prepare(null); + $stmt = $this->connection->getWrappedConnection()->prepare(null); // it's impossible to prepare the statement without bound variables for SQL Server, // so the preparation happens before the first execution when variables are already in place diff --git a/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php b/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php index a2e1ca901e3..e420000ba58 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php @@ -24,7 +24,7 @@ protected function setUp() { parent::setUp(); - if ($this->_conn->getDriver() instanceof ExceptionConverterDriver) { + if ($this->connection->getDriver() instanceof ExceptionConverterDriver) { return; } @@ -37,12 +37,12 @@ public function testPrimaryConstraintViolationException() $table->addColumn('id', 'integer', []); $table->setPrimaryKey(['id']); - $this->_conn->getSchemaManager()->createTable($table); + $this->connection->getSchemaManager()->createTable($table); - $this->_conn->insert('duplicatekey_table', ['id' => 1]); + $this->connection->insert('duplicatekey_table', ['id' => 1]); $this->expectException(Exception\UniqueConstraintViolationException::class); - $this->_conn->insert('duplicatekey_table', ['id' => 1]); + $this->connection->insert('duplicatekey_table', ['id' => 1]); } public function testTableNotFoundException() @@ -50,12 +50,12 @@ public function testTableNotFoundException() $sql = 'SELECT * FROM unknown_table'; $this->expectException(Exception\TableNotFoundException::class); - $this->_conn->executeQuery($sql); + $this->connection->executeQuery($sql); } public function testTableExistsException() { - $schemaManager = $this->_conn->getSchemaManager(); + $schemaManager = $this->connection->getSchemaManager(); $table = new Table('alreadyexist_table'); $table->addColumn('id', 'integer', []); $table->setPrimaryKey(['id']); @@ -67,15 +67,15 @@ public function testTableExistsException() public function testForeignKeyConstraintViolationExceptionOnInsert() { - if (! $this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { + if (! $this->connection->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped('Only fails on platforms with foreign key constraints.'); } $this->setUpForeignKeyConstraintViolationExceptionTest(); try { - $this->_conn->insert('constraint_error_table', ['id' => 1]); - $this->_conn->insert('owning_table', ['id' => 1, 'constraint_id' => 1]); + $this->connection->insert('constraint_error_table', ['id' => 1]); + $this->connection->insert('owning_table', ['id' => 1, 'constraint_id' => 1]); } catch (Throwable $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); @@ -85,7 +85,7 @@ public function testForeignKeyConstraintViolationExceptionOnInsert() $this->expectException(Exception\ForeignKeyConstraintViolationException::class); try { - $this->_conn->insert('owning_table', ['id' => 2, 'constraint_id' => 2]); + $this->connection->insert('owning_table', ['id' => 2, 'constraint_id' => 2]); } catch (Exception\ForeignKeyConstraintViolationException $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); @@ -101,15 +101,15 @@ public function testForeignKeyConstraintViolationExceptionOnInsert() public function testForeignKeyConstraintViolationExceptionOnUpdate() { - if (! $this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { + if (! $this->connection->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped('Only fails on platforms with foreign key constraints.'); } $this->setUpForeignKeyConstraintViolationExceptionTest(); try { - $this->_conn->insert('constraint_error_table', ['id' => 1]); - $this->_conn->insert('owning_table', ['id' => 1, 'constraint_id' => 1]); + $this->connection->insert('constraint_error_table', ['id' => 1]); + $this->connection->insert('owning_table', ['id' => 1, 'constraint_id' => 1]); } catch (Throwable $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); @@ -119,7 +119,7 @@ public function testForeignKeyConstraintViolationExceptionOnUpdate() $this->expectException(Exception\ForeignKeyConstraintViolationException::class); try { - $this->_conn->update('constraint_error_table', ['id' => 2], ['id' => 1]); + $this->connection->update('constraint_error_table', ['id' => 2], ['id' => 1]); } catch (Exception\ForeignKeyConstraintViolationException $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); @@ -135,15 +135,15 @@ public function testForeignKeyConstraintViolationExceptionOnUpdate() public function testForeignKeyConstraintViolationExceptionOnDelete() { - if (! $this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { + if (! $this->connection->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped('Only fails on platforms with foreign key constraints.'); } $this->setUpForeignKeyConstraintViolationExceptionTest(); try { - $this->_conn->insert('constraint_error_table', ['id' => 1]); - $this->_conn->insert('owning_table', ['id' => 1, 'constraint_id' => 1]); + $this->connection->insert('constraint_error_table', ['id' => 1]); + $this->connection->insert('owning_table', ['id' => 1, 'constraint_id' => 1]); } catch (Throwable $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); @@ -153,7 +153,7 @@ public function testForeignKeyConstraintViolationExceptionOnDelete() $this->expectException(Exception\ForeignKeyConstraintViolationException::class); try { - $this->_conn->delete('constraint_error_table', ['id' => 1]); + $this->connection->delete('constraint_error_table', ['id' => 1]); } catch (Exception\ForeignKeyConstraintViolationException $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); @@ -169,7 +169,7 @@ public function testForeignKeyConstraintViolationExceptionOnDelete() public function testForeignKeyConstraintViolationExceptionOnTruncate() { - $platform = $this->_conn->getDatabasePlatform(); + $platform = $this->connection->getDatabasePlatform(); if (! $platform->supportsForeignKeyConstraints()) { $this->markTestSkipped('Only fails on platforms with foreign key constraints.'); @@ -178,8 +178,8 @@ public function testForeignKeyConstraintViolationExceptionOnTruncate() $this->setUpForeignKeyConstraintViolationExceptionTest(); try { - $this->_conn->insert('constraint_error_table', ['id' => 1]); - $this->_conn->insert('owning_table', ['id' => 1, 'constraint_id' => 1]); + $this->connection->insert('constraint_error_table', ['id' => 1]); + $this->connection->insert('owning_table', ['id' => 1, 'constraint_id' => 1]); } catch (Throwable $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); @@ -189,7 +189,7 @@ public function testForeignKeyConstraintViolationExceptionOnTruncate() $this->expectException(Exception\ForeignKeyConstraintViolationException::class); try { - $this->_conn->executeUpdate($platform->getTruncateTableSQL('constraint_error_table')); + $this->connection->executeUpdate($platform->getTruncateTableSQL('constraint_error_table')); } catch (Exception\ForeignKeyConstraintViolationException $exception) { $this->tearDownForeignKeyConstraintViolationExceptionTest(); @@ -212,12 +212,12 @@ public function testNotNullConstraintViolationException() $table->addColumn('value', 'integer', ['notnull' => true]); $table->setPrimaryKey(['id']); - foreach ($schema->toSql($this->_conn->getDatabasePlatform()) as $sql) { - $this->_conn->exec($sql); + foreach ($schema->toSql($this->connection->getDatabasePlatform()) as $sql) { + $this->connection->exec($sql); } $this->expectException(Exception\NotNullConstraintViolationException::class); - $this->_conn->insert('notnull_table', ['id' => 1, 'value' => null]); + $this->connection->insert('notnull_table', ['id' => 1, 'value' => null]); } public function testInvalidFieldNameException() @@ -227,12 +227,12 @@ public function testInvalidFieldNameException() $table = $schema->createTable('bad_fieldname_table'); $table->addColumn('id', 'integer', []); - foreach ($schema->toSql($this->_conn->getDatabasePlatform()) as $sql) { - $this->_conn->exec($sql); + foreach ($schema->toSql($this->connection->getDatabasePlatform()) as $sql) { + $this->connection->exec($sql); } $this->expectException(Exception\InvalidFieldNameException::class); - $this->_conn->insert('bad_fieldname_table', ['name' => 5]); + $this->connection->insert('bad_fieldname_table', ['name' => 5]); } public function testNonUniqueFieldNameException() @@ -245,13 +245,13 @@ public function testNonUniqueFieldNameException() $table2 = $schema->createTable('ambiguous_list_table_2'); $table2->addColumn('id', 'integer'); - foreach ($schema->toSql($this->_conn->getDatabasePlatform()) as $sql) { - $this->_conn->exec($sql); + foreach ($schema->toSql($this->connection->getDatabasePlatform()) as $sql) { + $this->connection->exec($sql); } $sql = 'SELECT id FROM ambiguous_list_table, ambiguous_list_table_2'; $this->expectException(Exception\NonUniqueFieldNameException::class); - $this->_conn->executeQuery($sql); + $this->connection->executeQuery($sql); } public function testUniqueConstraintViolationException() @@ -262,13 +262,13 @@ public function testUniqueConstraintViolationException() $table->addColumn('id', 'integer'); $table->addUniqueIndex(['id']); - foreach ($schema->toSql($this->_conn->getDatabasePlatform()) as $sql) { - $this->_conn->exec($sql); + foreach ($schema->toSql($this->connection->getDatabasePlatform()) as $sql) { + $this->connection->exec($sql); } - $this->_conn->insert('unique_field_table', ['id' => 5]); + $this->connection->insert('unique_field_table', ['id' => 5]); $this->expectException(Exception\UniqueConstraintViolationException::class); - $this->_conn->insert('unique_field_table', ['id' => 5]); + $this->connection->insert('unique_field_table', ['id' => 5]); } public function testSyntaxErrorException() @@ -277,11 +277,11 @@ public function testSyntaxErrorException() $table->addColumn('id', 'integer', []); $table->setPrimaryKey(['id']); - $this->_conn->getSchemaManager()->createTable($table); + $this->connection->getSchemaManager()->createTable($table); $sql = 'SELECT id FRO syntax_error_table'; $this->expectException(Exception\SyntaxErrorException::class); - $this->_conn->executeQuery($sql); + $this->connection->executeQuery($sql); } /** @@ -289,7 +289,7 @@ public function testSyntaxErrorException() */ public function testConnectionExceptionSqLite($mode, $exceptionClass) { - if ($this->_conn->getDatabasePlatform()->getName() !== 'sqlite') { + if ($this->connection->getDatabasePlatform()->getName() !== 'sqlite') { $this->markTestSkipped('Only fails this way on sqlite'); } @@ -333,19 +333,19 @@ public function getSqLiteOpenConnection() */ public function testConnectionException($params) { - if ($this->_conn->getDatabasePlatform()->getName() === 'sqlite') { + if ($this->connection->getDatabasePlatform()->getName() === 'sqlite') { $this->markTestSkipped('Only skipped if platform is not sqlite'); } - if ($this->_conn->getDatabasePlatform()->getName() === 'drizzle') { + if ($this->connection->getDatabasePlatform()->getName() === 'drizzle') { $this->markTestSkipped('Drizzle does not always support authentication'); } - if ($this->_conn->getDatabasePlatform()->getName() === 'postgresql' && isset($params['password'])) { + if ($this->connection->getDatabasePlatform()->getName() === 'postgresql' && isset($params['password'])) { $this->markTestSkipped('Does not work on Travis'); } - $defaultParams = $this->_conn->getParams(); + $defaultParams = $this->connection->getParams(); $params = array_merge($defaultParams, $params); $conn = DriverManager::getConnection($params); @@ -372,7 +372,7 @@ public function getConnectionParams() private function setUpForeignKeyConstraintViolationExceptionTest() { - $schemaManager = $this->_conn->getSchemaManager(); + $schemaManager = $this->connection->getSchemaManager(); $table = new Table('constraint_error_table'); $table->addColumn('id', 'integer', []); @@ -390,7 +390,7 @@ private function setUpForeignKeyConstraintViolationExceptionTest() private function tearDownForeignKeyConstraintViolationExceptionTest() { - $schemaManager = $this->_conn->getSchemaManager(); + $schemaManager = $this->connection->getSchemaManager(); $schemaManager->dropTable('owning_table'); $schemaManager->dropTable('constraint_error_table'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/LikeWildcardsEscapingTest.php b/tests/Doctrine/Tests/DBAL/Functional/LikeWildcardsEscapingTest.php index 59306f153fd..e172816f2af 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/LikeWildcardsEscapingTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/LikeWildcardsEscapingTest.php @@ -11,8 +11,8 @@ public function testFetchLikeExpressionResult() : void { $string = '_25% off_ your next purchase \o/ [$̲̅(̲̅5̲̅)̲̅$̲̅] (^̮^)'; $escapeChar = '!'; - $databasePlatform = $this->_conn->getDatabasePlatform(); - $stmt = $this->_conn->prepare( + $databasePlatform = $this->connection->getDatabasePlatform(); + $stmt = $this->connection->prepare( $databasePlatform->getDummySelectSQL( sprintf( "(CASE WHEN '%s' LIKE '%s' ESCAPE '%s' THEN 1 ELSE 0 END)", diff --git a/tests/Doctrine/Tests/DBAL/Functional/LoggingTest.php b/tests/Doctrine/Tests/DBAL/Functional/LoggingTest.php index 8ba5daa0669..99ca533e742 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/LoggingTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/LoggingTest.php @@ -2,53 +2,54 @@ namespace Doctrine\Tests\DBAL\Functional; +use Doctrine\DBAL\Logging\SQLLogger; use Doctrine\Tests\DbalFunctionalTestCase; class LoggingTest extends DbalFunctionalTestCase { public function testLogExecuteQuery() { - $sql = $this->_conn->getDatabasePlatform()->getDummySelectSQL(); + $sql = $this->connection->getDatabasePlatform()->getDummySelectSQL(); - $logMock = $this->createMock('Doctrine\DBAL\Logging\SQLLogger'); + $logMock = $this->createMock(SQLLogger::class); $logMock->expects($this->at(0)) ->method('startQuery') ->with($this->equalTo($sql), $this->equalTo([]), $this->equalTo([])); $logMock->expects($this->at(1)) ->method('stopQuery'); - $this->_conn->getConfiguration()->setSQLLogger($logMock); - $this->_conn->executeQuery($sql, []); + $this->connection->getConfiguration()->setSQLLogger($logMock); + $this->connection->executeQuery($sql, []); } public function testLogExecuteUpdate() { $this->markTestSkipped('Test breaks MySQL but works on all other platforms (Unbuffered Queries stuff).'); - $sql = $this->_conn->getDatabasePlatform()->getDummySelectSQL(); + $sql = $this->connection->getDatabasePlatform()->getDummySelectSQL(); - $logMock = $this->createMock('Doctrine\DBAL\Logging\SQLLogger'); + $logMock = $this->createMock(SQLLogger::class); $logMock->expects($this->at(0)) ->method('startQuery') ->with($this->equalTo($sql), $this->equalTo([]), $this->equalTo([])); $logMock->expects($this->at(1)) ->method('stopQuery'); - $this->_conn->getConfiguration()->setSQLLogger($logMock); - $this->_conn->executeUpdate($sql, []); + $this->connection->getConfiguration()->setSQLLogger($logMock); + $this->connection->executeUpdate($sql, []); } public function testLogPrepareExecute() { - $sql = $this->_conn->getDatabasePlatform()->getDummySelectSQL(); + $sql = $this->connection->getDatabasePlatform()->getDummySelectSQL(); - $logMock = $this->createMock('Doctrine\DBAL\Logging\SQLLogger'); + $logMock = $this->createMock(SQLLogger::class); $logMock->expects($this->once()) ->method('startQuery') ->with($this->equalTo($sql), $this->equalTo([])); $logMock->expects($this->at(1)) ->method('stopQuery'); - $this->_conn->getConfiguration()->setSQLLogger($logMock); + $this->connection->getConfiguration()->setSQLLogger($logMock); - $stmt = $this->_conn->prepare($sql); + $stmt = $this->connection->prepare($sql); $stmt->execute(); } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php index af894cf147c..81747c3a996 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php @@ -24,7 +24,7 @@ protected function setUp() { parent::setUp(); - $platformName = $this->_conn->getDatabasePlatform()->getName(); + $platformName = $this->connection->getDatabasePlatform()->getName(); // This is a MySQL specific test, skip other vendors. if ($platformName !== 'mysql') { @@ -37,13 +37,13 @@ protected function setUp() $table->addColumn('test_int', 'integer'); $table->setPrimaryKey(['test_int']); - $sm = $this->_conn->getSchemaManager(); + $sm = $this->connection->getSchemaManager(); $sm->createTable($table); } catch (Throwable $e) { } - $this->_conn->executeUpdate('DELETE FROM master_slave_table'); - $this->_conn->insert('master_slave_table', ['test_int' => 1]); + $this->connection->executeUpdate('DELETE FROM master_slave_table'); + $this->connection->insert('master_slave_table', ['test_int' => 1]); } private function createMasterSlaveConnection(bool $keepSlave = false) : MasterSlaveConnection @@ -51,9 +51,12 @@ private function createMasterSlaveConnection(bool $keepSlave = false) : MasterSl return DriverManager::getConnection($this->createMasterSlaveConnectionParams($keepSlave)); } + /** + * @return mixed[] + */ private function createMasterSlaveConnectionParams(bool $keepSlave = false) : array { - $params = $this->_conn->getParams(); + $params = $this->connection->getParams(); $params['master'] = $params; $params['slaves'] = [$params, $params]; $params['keepSlave'] = $keepSlave; diff --git a/tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php b/tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php index b68aeaef8b3..87f326abdca 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ModifyLimitQueryTest.php @@ -29,21 +29,21 @@ protected function setUp() $table2->addColumn('test_int', 'integer'); $table2->setPrimaryKey(['id']); - $sm = $this->_conn->getSchemaManager(); + $sm = $this->connection->getSchemaManager(); $sm->createTable($table); $sm->createTable($table2); self::$tableCreated = true; } - $this->_conn->exec($this->_conn->getDatabasePlatform()->getTruncateTableSQL('modify_limit_table')); - $this->_conn->exec($this->_conn->getDatabasePlatform()->getTruncateTableSQL('modify_limit_table2')); + $this->connection->exec($this->connection->getDatabasePlatform()->getTruncateTableSQL('modify_limit_table')); + $this->connection->exec($this->connection->getDatabasePlatform()->getTruncateTableSQL('modify_limit_table2')); } public function testModifyLimitQuerySimpleQuery() { - $this->_conn->insert('modify_limit_table', ['test_int' => 1]); - $this->_conn->insert('modify_limit_table', ['test_int' => 2]); - $this->_conn->insert('modify_limit_table', ['test_int' => 3]); - $this->_conn->insert('modify_limit_table', ['test_int' => 4]); + $this->connection->insert('modify_limit_table', ['test_int' => 1]); + $this->connection->insert('modify_limit_table', ['test_int' => 2]); + $this->connection->insert('modify_limit_table', ['test_int' => 3]); + $this->connection->insert('modify_limit_table', ['test_int' => 4]); $sql = 'SELECT * FROM modify_limit_table ORDER BY test_int ASC'; @@ -55,14 +55,14 @@ public function testModifyLimitQuerySimpleQuery() public function testModifyLimitQueryJoinQuery() { - $this->_conn->insert('modify_limit_table', ['test_int' => 1]); - $this->_conn->insert('modify_limit_table', ['test_int' => 2]); + $this->connection->insert('modify_limit_table', ['test_int' => 1]); + $this->connection->insert('modify_limit_table', ['test_int' => 2]); - $this->_conn->insert('modify_limit_table2', ['test_int' => 1]); - $this->_conn->insert('modify_limit_table2', ['test_int' => 1]); - $this->_conn->insert('modify_limit_table2', ['test_int' => 1]); - $this->_conn->insert('modify_limit_table2', ['test_int' => 2]); - $this->_conn->insert('modify_limit_table2', ['test_int' => 2]); + $this->connection->insert('modify_limit_table2', ['test_int' => 1]); + $this->connection->insert('modify_limit_table2', ['test_int' => 1]); + $this->connection->insert('modify_limit_table2', ['test_int' => 1]); + $this->connection->insert('modify_limit_table2', ['test_int' => 2]); + $this->connection->insert('modify_limit_table2', ['test_int' => 2]); $sql = 'SELECT modify_limit_table.test_int FROM modify_limit_table INNER JOIN modify_limit_table2 ON modify_limit_table.test_int = modify_limit_table2.test_int ORDER BY modify_limit_table.test_int DESC'; @@ -73,10 +73,10 @@ public function testModifyLimitQueryJoinQuery() public function testModifyLimitQueryNonDeterministic() { - $this->_conn->insert('modify_limit_table', ['test_int' => 1]); - $this->_conn->insert('modify_limit_table', ['test_int' => 2]); - $this->_conn->insert('modify_limit_table', ['test_int' => 3]); - $this->_conn->insert('modify_limit_table', ['test_int' => 4]); + $this->connection->insert('modify_limit_table', ['test_int' => 1]); + $this->connection->insert('modify_limit_table', ['test_int' => 2]); + $this->connection->insert('modify_limit_table', ['test_int' => 3]); + $this->connection->insert('modify_limit_table', ['test_int' => 4]); $sql = 'SELECT * FROM modify_limit_table'; @@ -87,14 +87,14 @@ public function testModifyLimitQueryNonDeterministic() public function testModifyLimitQueryGroupBy() { - $this->_conn->insert('modify_limit_table', ['test_int' => 1]); - $this->_conn->insert('modify_limit_table', ['test_int' => 2]); + $this->connection->insert('modify_limit_table', ['test_int' => 1]); + $this->connection->insert('modify_limit_table', ['test_int' => 2]); - $this->_conn->insert('modify_limit_table2', ['test_int' => 1]); - $this->_conn->insert('modify_limit_table2', ['test_int' => 1]); - $this->_conn->insert('modify_limit_table2', ['test_int' => 1]); - $this->_conn->insert('modify_limit_table2', ['test_int' => 2]); - $this->_conn->insert('modify_limit_table2', ['test_int' => 2]); + $this->connection->insert('modify_limit_table2', ['test_int' => 1]); + $this->connection->insert('modify_limit_table2', ['test_int' => 1]); + $this->connection->insert('modify_limit_table2', ['test_int' => 1]); + $this->connection->insert('modify_limit_table2', ['test_int' => 2]); + $this->connection->insert('modify_limit_table2', ['test_int' => 2]); $sql = 'SELECT modify_limit_table.test_int FROM modify_limit_table ' . 'INNER JOIN modify_limit_table2 ON modify_limit_table.test_int = modify_limit_table2.test_int ' . @@ -107,10 +107,10 @@ public function testModifyLimitQueryGroupBy() public function testModifyLimitQuerySubSelect() { - $this->_conn->insert('modify_limit_table', ['test_int' => 1]); - $this->_conn->insert('modify_limit_table', ['test_int' => 2]); - $this->_conn->insert('modify_limit_table', ['test_int' => 3]); - $this->_conn->insert('modify_limit_table', ['test_int' => 4]); + $this->connection->insert('modify_limit_table', ['test_int' => 1]); + $this->connection->insert('modify_limit_table', ['test_int' => 2]); + $this->connection->insert('modify_limit_table', ['test_int' => 3]); + $this->connection->insert('modify_limit_table', ['test_int' => 4]); $sql = 'SELECT modify_limit_table.*, (SELECT COUNT(*) FROM modify_limit_table) AS cnt FROM modify_limit_table ORDER BY test_int DESC'; @@ -121,10 +121,10 @@ public function testModifyLimitQuerySubSelect() public function testModifyLimitQueryFromSubSelect() { - $this->_conn->insert('modify_limit_table', ['test_int' => 1]); - $this->_conn->insert('modify_limit_table', ['test_int' => 2]); - $this->_conn->insert('modify_limit_table', ['test_int' => 3]); - $this->_conn->insert('modify_limit_table', ['test_int' => 4]); + $this->connection->insert('modify_limit_table', ['test_int' => 1]); + $this->connection->insert('modify_limit_table', ['test_int' => 2]); + $this->connection->insert('modify_limit_table', ['test_int' => 3]); + $this->connection->insert('modify_limit_table', ['test_int' => 4]); $sql = 'SELECT * FROM (SELECT * FROM modify_limit_table) sub ORDER BY test_int DESC'; @@ -135,9 +135,9 @@ public function testModifyLimitQueryFromSubSelect() public function testModifyLimitQueryLineBreaks() { - $this->_conn->insert('modify_limit_table', ['test_int' => 1]); - $this->_conn->insert('modify_limit_table', ['test_int' => 2]); - $this->_conn->insert('modify_limit_table', ['test_int' => 3]); + $this->connection->insert('modify_limit_table', ['test_int' => 1]); + $this->connection->insert('modify_limit_table', ['test_int' => 2]); + $this->connection->insert('modify_limit_table', ['test_int' => 3]); $sql = <<_conn->insert('modify_limit_table', ['test_int' => 1]); - $this->_conn->insert('modify_limit_table', ['test_int' => 2]); + $this->connection->insert('modify_limit_table', ['test_int' => 1]); + $this->connection->insert('modify_limit_table', ['test_int' => 2]); $sql = 'SELECT test_int FROM modify_limit_table ORDER BY test_int ASC'; @@ -165,9 +165,9 @@ public function testModifyLimitQueryZeroOffsetNoLimit() public function assertLimitResult($expectedResults, $sql, $limit, $offset, $deterministic = true) { - $p = $this->_conn->getDatabasePlatform(); + $p = $this->connection->getDatabasePlatform(); $data = []; - foreach ($this->_conn->fetchAll($p->modifyLimitQuery($sql, $limit, $offset)) as $row) { + foreach ($this->connection->fetchAll($p->modifyLimitQuery($sql, $limit, $offset)) as $row) { $row = array_change_key_case($row, CASE_LOWER); $data[] = $row['test_int']; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/NamedParametersTest.php b/tests/Doctrine/Tests/DBAL/Functional/NamedParametersTest.php index cbe56ef9bfc..fec2e5944d6 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/NamedParametersTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/NamedParametersTest.php @@ -151,7 +151,7 @@ protected function setUp() { parent::setUp(); - if ($this->_conn->getSchemaManager()->tablesExist('ddc1372_foobar')) { + if ($this->connection->getSchemaManager()->tablesExist('ddc1372_foobar')) { return; } @@ -162,35 +162,35 @@ protected function setUp() $table->addColumn('bar', 'string'); $table->setPrimaryKey(['id']); - $sm = $this->_conn->getSchemaManager(); + $sm = $this->connection->getSchemaManager(); $sm->createTable($table); - $this->_conn->insert('ddc1372_foobar', [ + $this->connection->insert('ddc1372_foobar', [ 'id' => 1, 'foo' => 1, 'bar' => 1, ]); - $this->_conn->insert('ddc1372_foobar', [ + $this->connection->insert('ddc1372_foobar', [ 'id' => 2, 'foo' => 1, 'bar' => 2, ]); - $this->_conn->insert('ddc1372_foobar', [ + $this->connection->insert('ddc1372_foobar', [ 'id' => 3, 'foo' => 1, 'bar' => 3, ]); - $this->_conn->insert('ddc1372_foobar', [ + $this->connection->insert('ddc1372_foobar', [ 'id' => 4, 'foo' => 1, 'bar' => 4, ]); - $this->_conn->insert('ddc1372_foobar', [ + $this->connection->insert('ddc1372_foobar', [ 'id' => 5, 'foo' => 2, 'bar' => 1, ]); - $this->_conn->insert('ddc1372_foobar', [ + $this->connection->insert('ddc1372_foobar', [ 'id' => 6, 'foo' => 2, 'bar' => 2, @@ -201,16 +201,16 @@ protected function setUp() } /** - * @param string $query - * @param array $params - * @param array $types - * @param array $expected + * @param string $query + * @param mixed[] $params + * @param int[] $types + * @param int[] $expected * * @dataProvider ticketProvider */ public function testTicket($query, $params, $types, $expected) { - $stmt = $this->_conn->executeQuery($query, $params, $types); + $stmt = $this->connection->executeQuery($query, $params, $types); $result = $stmt->fetchAll(FetchMode::ASSOCIATIVE); foreach ($result as $k => $v) { diff --git a/tests/Doctrine/Tests/DBAL/Functional/PDOStatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/PDOStatementTest.php index dd2c61b8fe3..ce859827d83 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/PDOStatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/PDOStatementTest.php @@ -18,14 +18,14 @@ protected function setUp() parent::setUp(); - if (! $this->_conn->getWrappedConnection() instanceof PDOConnection) { + if (! $this->connection->getWrappedConnection() instanceof PDOConnection) { $this->markTestSkipped('PDO-only test'); } $table = new Table('stmt_test'); $table->addColumn('id', 'integer'); $table->addColumn('name', 'text'); - $this->_conn->getSchemaManager()->dropAndCreateTable($table); + $this->connection->getSchemaManager()->dropAndCreateTable($table); } /** @@ -34,16 +34,16 @@ protected function setUp() */ public function testPDOSpecificModeIsAccepted() { - $this->_conn->insert('stmt_test', [ + $this->connection->insert('stmt_test', [ 'id' => 1, 'name' => 'Alice', ]); - $this->_conn->insert('stmt_test', [ + $this->connection->insert('stmt_test', [ 'id' => 2, 'name' => 'Bob', ]); - $data = $this->_conn->query('SELECT id, name FROM stmt_test ORDER BY id') + $data = $this->connection->query('SELECT id, name FROM stmt_test ORDER BY id') ->fetchAll(PDO::FETCH_KEY_PAIR); self::assertSame([ diff --git a/tests/Doctrine/Tests/DBAL/Functional/Platform/DateExpressionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Platform/DateExpressionTest.php index 46a5efc1aae..5c1789e192d 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Platform/DateExpressionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Platform/DateExpressionTest.php @@ -17,16 +17,16 @@ public function testDifference(string $date1, string $date2, int $expected) : vo $table = new Table('date_expr_test'); $table->addColumn('date1', 'datetime'); $table->addColumn('date2', 'datetime'); - $this->_conn->getSchemaManager()->dropAndCreateTable($table); - $this->_conn->insert('date_expr_test', [ + $this->connection->getSchemaManager()->dropAndCreateTable($table); + $this->connection->insert('date_expr_test', [ 'date1' => $date1, 'date2' => $date2, ]); - $platform = $this->_conn->getDatabasePlatform(); + $platform = $this->connection->getDatabasePlatform(); $sql = sprintf('SELECT %s FROM date_expr_test', $platform->getDateDiffExpression('date1', 'date2')); - $diff = $this->_conn->query($sql)->fetchColumn(); + $diff = $this->connection->query($sql)->fetchColumn(); self::assertEquals($expected, $diff); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php b/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php index 32a43664d6e..b120823eefb 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php @@ -4,6 +4,7 @@ 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; @@ -41,13 +42,13 @@ private function getPortableConnection( $case = ColumnCase::LOWER ) { if (! $this->portableConnection) { - $params = $this->_conn->getParams(); + $params = $this->connection->getParams(); $params['wrapperClass'] = ConnectionPortability::class; $params['portability'] = $portabilityMode; $params['fetch_case'] = $case; - $this->portableConnection = DriverManager::getConnection($params, $this->_conn->getConfiguration(), $this->_conn->getEventManager()); + $this->portableConnection = DriverManager::getConnection($params, $this->connection->getConfiguration(), $this->connection->getEventManager()); try { /** @var AbstractSchemaManager $sm */ @@ -145,7 +146,7 @@ public function testPortabilityPdoSqlServer() $portability = ConnectionPortability::PORTABILITY_SQLSRV; $params = ['portability' => $portability]; - $driverMock = $this->getMockBuilder('Doctrine\\DBAL\\Driver\\PDOSqlsrv\\Driver') + $driverMock = $this->getMockBuilder(Driver::class) ->setMethods(['connect']) ->getMock(); @@ -161,6 +162,9 @@ public function testPortabilityPdoSqlServer() } /** + * @param string $field + * @param mixed[] $expected + * * @dataProvider fetchAllColumnProvider */ public function testFetchAllColumn($field, array $expected) diff --git a/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php b/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php index cb32a94252c..ae4259da91f 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php @@ -35,14 +35,14 @@ protected function setUp() $table->addColumn('test_string', 'string', ['notnull' => false]); $table->setPrimaryKey(['test_int']); - $sm = $this->_conn->getSchemaManager(); + $sm = $this->connection->getSchemaManager(); $sm->createTable($table); foreach ($this->expectedResult as $row) { - $this->_conn->insert('caching', $row); + $this->connection->insert('caching', $row); } - $config = $this->_conn->getConfiguration(); + $config = $this->connection->getConfiguration(); $config->setSQLLogger($this->sqlLogger = new DebugStack()); $cache = new ArrayCache(); @@ -51,7 +51,7 @@ protected function setUp() protected function tearDown() { - $this->_conn->getSchemaManager()->dropTable('caching'); + $this->connection->getSchemaManager()->dropTable('caching'); parent::tearDown(); } @@ -100,13 +100,13 @@ public function testMixingFetch() foreach ($this->expectedResult as $v) { $numExpectedResult[] = array_values($v); } - $stmt = $this->_conn->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); + $stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); $data = $this->hydrateStmt($stmt, FetchMode::ASSOCIATIVE); self::assertEquals($this->expectedResult, $data); - $stmt = $this->_conn->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); + $stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); $data = $this->hydrateStmt($stmt, FetchMode::NUMERIC); @@ -122,10 +122,10 @@ public function testIteratorFetch() public function assertStandardAndIteratorFetchAreEqual($fetchMode) { - $stmt = $this->_conn->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); + $stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); $data = $this->hydrateStmt($stmt, $fetchMode); - $stmt = $this->_conn->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); + $stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); $data_iterator = $this->hydrateStmtIterator($stmt, $fetchMode); self::assertEquals($data, $data_iterator); @@ -133,7 +133,7 @@ public function assertStandardAndIteratorFetchAreEqual($fetchMode) public function testDontCloseNoCache() { - $stmt = $this->_conn->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); + $stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); $data = []; @@ -141,7 +141,7 @@ public function testDontCloseNoCache() $data[] = $row; } - $stmt = $this->_conn->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); + $stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); $data = []; @@ -154,12 +154,12 @@ public function testDontCloseNoCache() public function testDontFinishNoCache() { - $stmt = $this->_conn->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); + $stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); $stmt->fetch(FetchMode::ASSOCIATIVE); $stmt->closeCursor(); - $stmt = $this->_conn->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); + $stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); $this->hydrateStmt($stmt, FetchMode::NUMERIC); @@ -168,13 +168,13 @@ public function testDontFinishNoCache() public function assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, $fetchMode) { - $stmt = $this->_conn->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); + $stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); self::assertEquals(2, $stmt->columnCount()); $data = $this->hydrateStmt($stmt, $fetchMode); self::assertEquals($expectedResult, $data); - $stmt = $this->_conn->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); + $stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey')); self::assertEquals(2, $stmt->columnCount()); $data = $this->hydrateStmt($stmt, $fetchMode); @@ -184,10 +184,10 @@ public function assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, public function testEmptyResultCache() { - $stmt = $this->_conn->executeQuery('SELECT * FROM caching WHERE test_int > 500', [], [], new QueryCacheProfile(10, 'emptycachekey')); + $stmt = $this->connection->executeQuery('SELECT * FROM caching WHERE test_int > 500', [], [], new QueryCacheProfile(10, 'emptycachekey')); $data = $this->hydrateStmt($stmt); - $stmt = $this->_conn->executeQuery('SELECT * FROM caching WHERE test_int > 500', [], [], new QueryCacheProfile(10, 'emptycachekey')); + $stmt = $this->connection->executeQuery('SELECT * FROM caching WHERE test_int > 500', [], [], new QueryCacheProfile(10, 'emptycachekey')); $data = $this->hydrateStmt($stmt); self::assertCount(1, $this->sqlLogger->queries, 'just one dbal hit'); @@ -195,11 +195,11 @@ public function testEmptyResultCache() public function testChangeCacheImpl() { - $stmt = $this->_conn->executeQuery('SELECT * FROM caching WHERE test_int > 500', [], [], new QueryCacheProfile(10, 'emptycachekey')); + $stmt = $this->connection->executeQuery('SELECT * FROM caching WHERE test_int > 500', [], [], new QueryCacheProfile(10, 'emptycachekey')); $data = $this->hydrateStmt($stmt); $secondCache = new ArrayCache(); - $stmt = $this->_conn->executeQuery('SELECT * FROM caching WHERE test_int > 500', [], [], new QueryCacheProfile(10, 'emptycachekey', $secondCache)); + $stmt = $this->connection->executeQuery('SELECT * FROM caching WHERE test_int > 500', [], [], new QueryCacheProfile(10, 'emptycachekey', $secondCache)); $data = $this->hydrateStmt($stmt); self::assertCount(2, $this->sqlLogger->queries, 'two hits'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/Db2SchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/Db2SchemaManagerTest.php index bb1f46d2787..102fd1bb495 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/Db2SchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/Db2SchemaManagerTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\DBAL\Functional\Schema; use Doctrine\DBAL\Schema\Table; +use Doctrine\DBAL\Types\BooleanType; class Db2SchemaManagerTest extends SchemaManagerFunctionalTestCase { @@ -15,12 +16,12 @@ public function testGetBooleanColumn() $table->addColumn('bool', 'boolean'); $table->addColumn('bool_commented', 'boolean', ['comment' => "That's a comment"]); - $this->_sm->createTable($table); + $this->schemaManager->createTable($table); - $columns = $this->_sm->listTableColumns('boolean_column_test'); + $columns = $this->schemaManager->listTableColumns('boolean_column_test'); - self::assertInstanceOf('Doctrine\DBAL\Types\BooleanType', $columns['bool']->getType()); - self::assertInstanceOf('Doctrine\DBAL\Types\BooleanType', $columns['bool_commented']->getType()); + self::assertInstanceOf(BooleanType::class, $columns['bool']->getType()); + self::assertInstanceOf(BooleanType::class, $columns['bool_commented']->getType()); self::assertNull($columns['bool']->getComment()); self::assertSame("That's a comment", $columns['bool_commented']->getComment()); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/DrizzleSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/DrizzleSchemaManagerTest.php index bbc1b5a5fdd..070e2173d63 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/DrizzleSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/DrizzleSchemaManagerTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\DBAL\Functional\Schema; use Doctrine\DBAL\Schema\Table; +use Doctrine\DBAL\Types\BinaryType; class DrizzleSchemaManagerTest extends SchemaManagerFunctionalTestCase { @@ -16,14 +17,14 @@ public function testListTableWithBinary() $table->addColumn('column_binary', 'binary', ['fixed' => true]); $table->setPrimaryKey(['id']); - $this->_sm->createTable($table); + $this->schemaManager->createTable($table); - $table = $this->_sm->listTableDetails($tableName); + $table = $this->schemaManager->listTableDetails($tableName); - self::assertInstanceOf('Doctrine\DBAL\Types\BinaryType', $table->getColumn('column_varbinary')->getType()); + self::assertInstanceOf(BinaryType::class, $table->getColumn('column_varbinary')->getType()); self::assertFalse($table->getColumn('column_varbinary')->getFixed()); - self::assertInstanceOf('Doctrine\DBAL\Types\BinaryType', $table->getColumn('column_binary')->getType()); + self::assertInstanceOf(BinaryType::class, $table->getColumn('column_binary')->getType()); self::assertFalse($table->getColumn('column_binary')->getFixed()); } @@ -35,9 +36,9 @@ public function testColumnCollation() $table->addColumn('text', 'text'); $table->addColumn('foo', 'text')->setPlatformOption('collation', 'utf8_swedish_ci'); $table->addColumn('bar', 'text')->setPlatformOption('collation', 'utf8_general_ci'); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); - $columns = $this->_sm->listTableColumns('test_collation'); + $columns = $this->schemaManager->listTableColumns('test_collation'); self::assertArrayNotHasKey('collation', $columns['id']->getPlatformOptions()); self::assertEquals('utf8_unicode_ci', $columns['text']->getPlatformOption('collation')); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php index 80a89e29541..7dd9409b30c 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php @@ -11,6 +11,7 @@ use Doctrine\DBAL\Types\Type; use Doctrine\Tests\Types\MySqlPointType; use function implode; +use function sprintf; class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase { @@ -31,15 +32,15 @@ public function testSwitchPrimaryKeyColumns() $tableOld->addColumn('foo_id', 'integer'); $tableOld->addColumn('bar_id', 'integer'); - $this->_sm->createTable($tableOld); - $tableFetched = $this->_sm->listTableDetails('switch_primary_key_columns'); + $this->schemaManager->createTable($tableOld); + $tableFetched = $this->schemaManager->listTableDetails('switch_primary_key_columns'); $tableNew = clone $tableFetched; $tableNew->setPrimaryKey(['bar_id', 'foo_id']); $comparator = new Comparator(); - $this->_sm->alterTable($comparator->diffTable($tableFetched, $tableNew)); + $this->schemaManager->alterTable($comparator->diffTable($tableFetched, $tableNew)); - $table = $this->_sm->listTableDetails('switch_primary_key_columns'); + $table = $this->schemaManager->listTableDetails('switch_primary_key_columns'); $primaryKey = $table->getPrimaryKeyColumns(); self::assertCount(2, $primaryKey); @@ -61,8 +62,8 @@ public function testDiffTableBug() $table->addUniqueIndex(['route', 'locale', 'attribute']); $table->addIndex(['localized_value']); // this is much more selective than the unique index - $this->_sm->createTable($table); - $tableFetched = $this->_sm->listTableDetails('diffbug_routing_translations'); + $this->schemaManager->createTable($table); + $tableFetched = $this->schemaManager->listTableDetails('diffbug_routing_translations'); $comparator = new Comparator(); $diff = $comparator->diffTable($tableFetched, $table); @@ -80,9 +81,9 @@ public function testFulltextIndex() $index = $table->getIndex('f_index'); $index->addFlag('fulltext'); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); - $indexes = $this->_sm->listTableIndexes('fulltext_index'); + $indexes = $this->schemaManager->listTableIndexes('fulltext_index'); self::assertArrayHasKey('f_index', $indexes); self::assertTrue($indexes['f_index']->hasFlag('fulltext')); } @@ -97,9 +98,9 @@ public function testSpatialIndex() $index = $table->getIndex('s_index'); $index->addFlag('spatial'); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); - $indexes = $this->_sm->listTableIndexes('spatial_index'); + $indexes = $this->schemaManager->listTableIndexes('spatial_index'); self::assertArrayHasKey('s_index', $indexes); self::assertTrue($indexes['s_index']->hasFlag('spatial')); } @@ -114,7 +115,7 @@ public function testAlterTableAddPrimaryKey() $table->addColumn('foo', 'integer'); $table->addIndex(['id'], 'idx_id'); - $this->_sm->createTable($table); + $this->schemaManager->createTable($table); $comparator = new Comparator(); $diffTable = clone $table; @@ -122,9 +123,9 @@ public function testAlterTableAddPrimaryKey() $diffTable->dropIndex('idx_id'); $diffTable->setPrimaryKey(['id']); - $this->_sm->alterTable($comparator->diffTable($table, $diffTable)); + $this->schemaManager->alterTable($comparator->diffTable($table, $diffTable)); - $table = $this->_sm->listTableDetails('alter_table_add_pk'); + $table = $this->schemaManager->listTableDetails('alter_table_add_pk'); self::assertFalse($table->hasIndex('idx_id')); self::assertTrue($table->hasPrimaryKey()); @@ -140,7 +141,7 @@ public function testDropPrimaryKeyWithAutoincrementColumn() $table->addColumn('foo', 'integer'); $table->setPrimaryKey(['id', 'foo']); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); $diffTable = clone $table; @@ -148,9 +149,9 @@ public function testDropPrimaryKeyWithAutoincrementColumn() $comparator = new Comparator(); - $this->_sm->alterTable($comparator->diffTable($table, $diffTable)); + $this->schemaManager->alterTable($comparator->diffTable($table, $diffTable)); - $table = $this->_sm->listTableDetails('drop_primary_key'); + $table = $this->schemaManager->listTableDetails('drop_primary_key'); self::assertFalse($table->hasPrimaryKey()); self::assertFalse($table->getColumn('id')->getAutoincrement()); @@ -161,7 +162,7 @@ public function testDropPrimaryKeyWithAutoincrementColumn() */ public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() { - if ($this->_sm->getDatabasePlatform() instanceof MariaDb1027Platform) { + if ($this->schemaManager->getDatabasePlatform() instanceof MariaDb1027Platform) { $this->markTestSkipped( 'MariaDb102Platform supports default values for BLOB and TEXT columns and will propagate values' ); @@ -173,9 +174,9 @@ public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() $table->addColumn('def_blob', 'blob', ['default' => 'def']); $table->addColumn('def_blob_null', 'blob', ['notnull' => false, 'default' => 'def']); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); - $onlineTable = $this->_sm->listTableDetails('text_blob_default_value'); + $onlineTable = $this->schemaManager->listTableDetails('text_blob_default_value'); self::assertNull($onlineTable->getColumn('def_text')->getDefault()); self::assertNull($onlineTable->getColumn('def_text_null')->getDefault()); @@ -186,9 +187,9 @@ public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() $comparator = new Comparator(); - $this->_sm->alterTable($comparator->diffTable($table, $onlineTable)); + $this->schemaManager->alterTable($comparator->diffTable($table, $onlineTable)); - $onlineTable = $this->_sm->listTableDetails('text_blob_default_value'); + $onlineTable = $this->schemaManager->listTableDetails('text_blob_default_value'); self::assertNull($onlineTable->getColumn('def_text')->getDefault()); self::assertNull($onlineTable->getColumn('def_text_null')->getDefault()); @@ -207,9 +208,9 @@ public function testColumnCollation() $table->addColumn('text', 'text'); $table->addColumn('foo', 'text')->setPlatformOption('collation', 'latin1_swedish_ci'); $table->addColumn('bar', 'text')->setPlatformOption('collation', 'utf8_general_ci'); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); - $columns = $this->_sm->listTableColumns('test_collation'); + $columns = $this->schemaManager->listTableColumns('test_collation'); self::assertArrayNotHasKey('collation', $columns['id']->getPlatformOptions()); self::assertEquals('latin1_swedish_ci', $columns['text']->getPlatformOption('collation')); @@ -235,11 +236,11 @@ public function testListLobTypeColumns() $table->addColumn('col_mediumblob', 'blob', ['length' => MySqlPlatform::LENGTH_LIMIT_MEDIUMBLOB]); $table->addColumn('col_longblob', 'blob'); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); - $platform = $this->_sm->getDatabasePlatform(); + $platform = $this->schemaManager->getDatabasePlatform(); $offlineColumns = $table->getColumns(); - $onlineColumns = $this->_sm->listTableColumns($tableName); + $onlineColumns = $this->schemaManager->listTableColumns($tableName); self::assertSame( $platform->getClobTypeDeclarationSQL($offlineColumns['col_tinytext']->toArray()), @@ -284,9 +285,9 @@ public function testDiffListGuidTableColumn() $offlineTable = new Table('list_guid_table_column'); $offlineTable->addColumn('col_guid', 'guid'); - $this->_sm->dropAndCreateTable($offlineTable); + $this->schemaManager->dropAndCreateTable($offlineTable); - $onlineTable = $this->_sm->listTableDetails('list_guid_table_column'); + $onlineTable = $this->schemaManager->listTableDetails('list_guid_table_column'); $comparator = new Comparator(); @@ -307,9 +308,9 @@ public function testListDecimalTypeColumns() $table->addColumn('col', 'decimal'); $table->addColumn('col_unsigned', 'decimal', ['unsigned' => true]); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); - $columns = $this->_sm->listTableColumns($tableName); + $columns = $this->schemaManager->listTableColumns($tableName); self::assertArrayHasKey('col', $columns); self::assertArrayHasKey('col_unsigned', $columns); @@ -328,9 +329,9 @@ public function testListFloatTypeColumns() $table->addColumn('col', 'float'); $table->addColumn('col_unsigned', 'float', ['unsigned' => true]); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); - $columns = $this->_sm->listTableColumns($tableName); + $columns = $this->schemaManager->listTableColumns($tableName); self::assertArrayHasKey('col', $columns); self::assertArrayHasKey('col_unsigned', $columns); @@ -342,16 +343,16 @@ public function testJsonColumnType() : void { $table = new Table('test_mysql_json'); $table->addColumn('col_json', 'json'); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); - $columns = $this->_sm->listTableColumns('test_mysql_json'); + $columns = $this->schemaManager->listTableColumns('test_mysql_json'); - self::assertSame(TYPE::JSON, $columns['col_json']->getType()->getName()); + self::assertSame(Type::JSON, $columns['col_json']->getType()->getName()); } public function testColumnDefaultCurrentTimestamp() : void { - $platform = $this->_sm->getDatabasePlatform(); + $platform = $this->schemaManager->getDatabasePlatform(); $table = new Table('test_column_defaults_current_timestamp'); @@ -360,9 +361,9 @@ public function testColumnDefaultCurrentTimestamp() : void $table->addColumn('col_datetime', 'datetime', ['notnull' => true, 'default' => $currentTimeStampSql]); $table->addColumn('col_datetime_nullable', 'datetime', ['default' => $currentTimeStampSql]); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); - $onlineTable = $this->_sm->listTableDetails('test_column_defaults_current_timestamp'); + $onlineTable = $this->schemaManager->listTableDetails('test_column_defaults_current_timestamp'); self::assertSame($currentTimeStampSql, $onlineTable->getColumn('col_datetime')->getDefault()); self::assertSame($currentTimeStampSql, $onlineTable->getColumn('col_datetime_nullable')->getDefault()); @@ -376,7 +377,7 @@ public function testColumnDefaultsAreValid() { $table = new Table('test_column_defaults_are_valid'); - $currentTimeStampSql = $this->_sm->getDatabasePlatform()->getCurrentTimestampSQL(); + $currentTimeStampSql = $this->schemaManager->getDatabasePlatform()->getCurrentTimestampSQL(); $table->addColumn('col_datetime', 'datetime', ['default' => $currentTimeStampSql]); $table->addColumn('col_datetime_null', 'datetime', ['notnull' => false, 'default' => null]); $table->addColumn('col_int', 'integer', ['default' => 1]); @@ -385,13 +386,13 @@ public function testColumnDefaultsAreValid() $table->addColumn('col_decimal', 'decimal', ['scale' => 3, 'precision' => 6, 'default' => -2.3]); $table->addColumn('col_date', 'date', ['default' => '2012-12-12']); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); - $this->_conn->executeUpdate( + $this->connection->executeUpdate( 'INSERT INTO test_column_defaults_are_valid () VALUES()' ); - $row = $this->_conn->fetchAssoc( + $row = $this->connection->fetchAssoc( 'SELECT *, DATEDIFF(CURRENT_TIMESTAMP(), col_datetime) as diff_seconds FROM test_column_defaults_are_valid' ); @@ -417,11 +418,11 @@ public function testColumnDefaultsAreValid() */ public function testColumnDefaultValuesCurrentTimeAndDate() : void { - if (! $this->_sm->getDatabasePlatform() instanceof MariaDb1027Platform) { + if (! $this->schemaManager->getDatabasePlatform() instanceof MariaDb1027Platform) { $this->markTestSkipped('Only relevant for MariaDb102Platform.'); } - $platform = $this->_sm->getDatabasePlatform(); + $platform = $this->schemaManager->getDatabasePlatform(); $table = new Table('test_column_defaults_current_time_and_date'); @@ -433,9 +434,9 @@ public function testColumnDefaultValuesCurrentTimeAndDate() : void $table->addColumn('col_date', 'date', ['default' => $currentDateSql]); $table->addColumn('col_time', 'time', ['default' => $currentTimeSql]); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); - $onlineTable = $this->_sm->listTableDetails('test_column_defaults_current_time_and_date'); + $onlineTable = $this->schemaManager->listTableDetails('test_column_defaults_current_time_and_date'); self::assertSame($currentTimestampSql, $onlineTable->getColumn('col_datetime')->getDefault()); self::assertSame($currentDateSql, $onlineTable->getColumn('col_date')->getDefault()); @@ -456,8 +457,8 @@ public function testColumnDefaultValuesCurrentTimeAndDate() : void */ public function testEnsureDefaultsAreUnescapedFromSchemaIntrospection() : void { - $platform = $this->_sm->getDatabasePlatform(); - $this->_conn->query('DROP TABLE IF EXISTS test_column_defaults_with_create'); + $platform = $this->schemaManager->getDatabasePlatform(); + $this->connection->query('DROP TABLE IF EXISTS test_column_defaults_with_create'); $escapeSequences = [ "\\0", // An ASCII NUL (X'00') character @@ -477,11 +478,12 @@ public function testEnsureDefaultsAreUnescapedFromSchemaIntrospection() : void $default = implode('+', $escapeSequences); - $sql = "CREATE TABLE test_column_defaults_with_create( - col1 VARCHAR(255) NULL DEFAULT {$platform->quoteStringLiteral($default)} - )"; - $this->_conn->query($sql); - $onlineTable = $this->_sm->listTableDetails('test_column_defaults_with_create'); + $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()); } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php index bc9327677f2..33d1131eadc 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php @@ -4,6 +4,7 @@ use Doctrine\DBAL\Schema; use Doctrine\DBAL\Schema\Table; +use Doctrine\DBAL\Types\BinaryType; use Doctrine\DBAL\Types\Type; use Doctrine\Tests\TestUtil; use function array_map; @@ -28,13 +29,13 @@ protected function setUp() public function testRenameTable() { - $this->_sm->tryMethod('DropTable', 'list_tables_test'); - $this->_sm->tryMethod('DropTable', 'list_tables_test_new_name'); + $this->schemaManager->tryMethod('DropTable', 'list_tables_test'); + $this->schemaManager->tryMethod('DropTable', 'list_tables_test_new_name'); $this->createTestTable('list_tables_test'); - $this->_sm->renameTable('list_tables_test', 'list_tables_test_new_name'); + $this->schemaManager->renameTable('list_tables_test', 'list_tables_test_new_name'); - $tables = $this->_sm->listTables(); + $tables = $this->schemaManager->listTables(); self::assertHasTable($tables, 'list_tables_test_new_name'); } @@ -49,14 +50,14 @@ public function testListTableWithBinary() $table->addColumn('column_binary', 'binary', ['fixed' => true]); $table->setPrimaryKey(['id']); - $this->_sm->createTable($table); + $this->schemaManager->createTable($table); - $table = $this->_sm->listTableDetails($tableName); + $table = $this->schemaManager->listTableDetails($tableName); - self::assertInstanceOf('Doctrine\DBAL\Types\BinaryType', $table->getColumn('column_varbinary')->getType()); + self::assertInstanceOf(BinaryType::class, $table->getColumn('column_varbinary')->getType()); self::assertFalse($table->getColumn('column_varbinary')->getFixed()); - self::assertInstanceOf('Doctrine\DBAL\Types\BinaryType', $table->getColumn('column_binary')->getType()); + self::assertInstanceOf(BinaryType::class, $table->getColumn('column_binary')->getType()); self::assertFalse($table->getColumn('column_binary')->getFixed()); } @@ -75,9 +76,9 @@ public function testAlterTableColumnNotNull() $table->addColumn('bar', 'string'); $table->setPrimaryKey(['id']); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); - $columns = $this->_sm->listTableColumns($tableName); + $columns = $this->schemaManager->listTableColumns($tableName); self::assertTrue($columns['id']->getNotnull()); self::assertTrue($columns['foo']->getNotnull()); @@ -87,9 +88,9 @@ public function testAlterTableColumnNotNull() $diffTable->changeColumn('foo', ['notnull' => false]); $diffTable->changeColumn('bar', ['length' => 1024]); - $this->_sm->alterTable($comparator->diffTable($table, $diffTable)); + $this->schemaManager->alterTable($comparator->diffTable($table, $diffTable)); - $columns = $this->_sm->listTableColumns($tableName); + $columns = $this->schemaManager->listTableColumns($tableName); self::assertTrue($columns['id']->getNotnull()); self::assertFalse($columns['foo']->getNotnull()); @@ -103,7 +104,7 @@ public function testListDatabases() $sm->dropAndCreateDatabase('c##test_create_database'); - $databases = $this->_sm->listDatabases(); + $databases = $this->schemaManager->listDatabases(); $databases = array_map('strtolower', $databases); self::assertContains('c##test_create_database', $databases); @@ -145,16 +146,16 @@ public function testListTableDetailsWithDifferentIdentifierQuotingRequirements() ); $offlineForeignTable->setPrimaryKey(['id']); - $this->_sm->tryMethod('dropTable', $foreignTableName); - $this->_sm->tryMethod('dropTable', $primaryTableName); + $this->schemaManager->tryMethod('dropTable', $foreignTableName); + $this->schemaManager->tryMethod('dropTable', $primaryTableName); - $this->_sm->createTable($offlinePrimaryTable); - $this->_sm->createTable($offlineForeignTable); + $this->schemaManager->createTable($offlinePrimaryTable); + $this->schemaManager->createTable($offlineForeignTable); - $onlinePrimaryTable = $this->_sm->listTableDetails($primaryTableName); - $onlineForeignTable = $this->_sm->listTableDetails($foreignTableName); + $onlinePrimaryTable = $this->schemaManager->listTableDetails($primaryTableName); + $onlineForeignTable = $this->schemaManager->listTableDetails($foreignTableName); - $platform = $this->_sm->getDatabasePlatform(); + $platform = $this->schemaManager->getDatabasePlatform(); // Primary table assertions self::assertSame($primaryTableName, $onlinePrimaryTable->getQuotedName($platform)); @@ -223,13 +224,13 @@ public function testListTableDetailsWithDifferentIdentifierQuotingRequirements() public function testListTableColumnsSameTableNamesInDifferentSchemas() { $table = $this->createListTableColumns(); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); $otherTable = new Table($table->getName()); $otherTable->addColumn('id', Type::STRING); TestUtil::getTempConnection()->getSchemaManager()->dropAndCreateTable($otherTable); - $columns = $this->_sm->listTableColumns($table->getName(), $this->_conn->getUsername()); + $columns = $this->schemaManager->listTableColumns($table->getName(), $this->connection->getUsername()); self::assertCount(7, $columns); } @@ -239,16 +240,16 @@ public function testListTableColumnsSameTableNamesInDifferentSchemas() public function testListTableIndexesPrimaryKeyConstraintNameDiffersFromIndexName() { $table = new Table('list_table_indexes_pk_id_test'); - $table->setSchemaConfig($this->_sm->createSchemaConfig()); + $table->setSchemaConfig($this->schemaManager->createSchemaConfig()); $table->addColumn('id', 'integer', ['notnull' => true]); $table->addUniqueIndex(['id'], 'id_unique_index'); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); // Adding a primary key on already indexed columns // Oracle will reuse the unique index, which cause a constraint name differing from the index name - $this->_sm->createConstraint(new Schema\Index('id_pk_id_index', ['id'], true, true), 'list_table_indexes_pk_id_test'); + $this->schemaManager->createConstraint(new Schema\Index('id_pk_id_index', ['id'], true, true), 'list_table_indexes_pk_id_test'); - $tableIndexes = $this->_sm->listTableIndexes('list_table_indexes_pk_id_test'); + $tableIndexes = $this->schemaManager->listTableIndexes('list_table_indexes_pk_id_test'); self::assertArrayHasKey('primary', $tableIndexes, 'listTableIndexes() has to return a "primary" array key.'); self::assertEquals(['id'], array_map('strtolower', $tableIndexes['primary']->getColumns())); @@ -266,9 +267,9 @@ public function testListTableDateTypeColumns() $table->addColumn('col_datetime', 'datetime'); $table->addColumn('col_datetimetz', 'datetimetz'); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); - $columns = $this->_sm->listTableColumns('tbl_date'); + $columns = $this->schemaManager->listTableColumns('tbl_date'); self::assertSame('date', $columns['col_date']->getType()->getName()); self::assertSame('datetime', $columns['col_datetime']->getType()->getName()); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php index 4dc76ba1da0..e007eabda2a 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php @@ -9,6 +9,8 @@ use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; +use Doctrine\DBAL\Types\BlobType; +use Doctrine\DBAL\Types\DecimalType; use Doctrine\DBAL\Types\Type; use function array_map; use function array_pop; @@ -21,11 +23,11 @@ protected function tearDown() { parent::tearDown(); - if (! $this->_conn) { + if (! $this->connection) { return; } - $this->_conn->getConfiguration()->setFilterSchemaAssetsExpression(null); + $this->connection->getConfiguration()->setFilterSchemaAssetsExpression(null); } /** @@ -33,9 +35,9 @@ protected function tearDown() */ public function testGetSearchPath() { - $params = $this->_conn->getParams(); + $params = $this->connection->getParams(); - $paths = $this->_sm->getSchemaSearchPaths(); + $paths = $this->schemaManager->getSchemaSearchPaths(); self::assertEquals([$params['user'], 'public'], $paths); } @@ -44,7 +46,7 @@ public function testGetSearchPath() */ public function testGetSchemaNames() { - $names = $this->_sm->getSchemaNames(); + $names = $this->schemaManager->getSchemaNames(); self::assertInternalType('array', $names); self::assertNotEmpty($names); @@ -57,19 +59,19 @@ public function testGetSchemaNames() public function testSupportDomainTypeFallback() { $createDomainTypeSQL = 'CREATE DOMAIN MyMoney AS DECIMAL(18,2)'; - $this->_conn->exec($createDomainTypeSQL); + $this->connection->exec($createDomainTypeSQL); $createTableSQL = 'CREATE TABLE domain_type_test (id INT PRIMARY KEY, value MyMoney)'; - $this->_conn->exec($createTableSQL); + $this->connection->exec($createTableSQL); - $table = $this->_conn->getSchemaManager()->listTableDetails('domain_type_test'); - self::assertInstanceOf('Doctrine\DBAL\Types\DecimalType', $table->getColumn('value')->getType()); + $table = $this->connection->getSchemaManager()->listTableDetails('domain_type_test'); + self::assertInstanceOf(DecimalType::class, $table->getColumn('value')->getType()); - Type::addType('MyMoney', 'Doctrine\Tests\DBAL\Functional\Schema\MoneyType'); - $this->_conn->getDatabasePlatform()->registerDoctrineTypeMapping('MyMoney', 'MyMoney'); + Type::addType('MyMoney', MoneyType::class); + $this->connection->getDatabasePlatform()->registerDoctrineTypeMapping('MyMoney', 'MyMoney'); - $table = $this->_conn->getSchemaManager()->listTableDetails('domain_type_test'); - self::assertInstanceOf('Doctrine\Tests\DBAL\Functional\Schema\MoneyType', $table->getColumn('value')->getType()); + $table = $this->connection->getSchemaManager()->listTableDetails('domain_type_test'); + self::assertInstanceOf(MoneyType::class, $table->getColumn('value')->getType()); } /** @@ -80,8 +82,8 @@ public function testDetectsAutoIncrement() $autoincTable = new Table('autoinc_table'); $column = $autoincTable->addColumn('id', 'integer'); $column->setAutoincrement(true); - $this->_sm->createTable($autoincTable); - $autoincTable = $this->_sm->listTableDetails('autoinc_table'); + $this->schemaManager->createTable($autoincTable); + $autoincTable = $this->schemaManager->listTableDetails('autoinc_table'); self::assertTrue($autoincTable->getColumn('id')->getAutoincrement()); } @@ -93,8 +95,8 @@ public function testAlterTableAutoIncrementAdd() { $tableFrom = new Table('autoinc_table_add'); $column = $tableFrom->addColumn('id', 'integer'); - $this->_sm->createTable($tableFrom); - $tableFrom = $this->_sm->listTableDetails('autoinc_table_add'); + $this->schemaManager->createTable($tableFrom); + $tableFrom = $this->schemaManager->listTableDetails('autoinc_table_add'); self::assertFalse($tableFrom->getColumn('id')->getAutoincrement()); $tableTo = new Table('autoinc_table_add'); @@ -103,15 +105,15 @@ public function testAlterTableAutoIncrementAdd() $c = new Comparator(); $diff = $c->diffTable($tableFrom, $tableTo); - $sql = $this->_conn->getDatabasePlatform()->getAlterTableSQL($diff); + $sql = $this->connection->getDatabasePlatform()->getAlterTableSQL($diff); self::assertEquals([ 'CREATE SEQUENCE autoinc_table_add_id_seq', "SELECT setval('autoinc_table_add_id_seq', (SELECT MAX(id) FROM autoinc_table_add))", "ALTER TABLE autoinc_table_add ALTER id SET DEFAULT nextval('autoinc_table_add_id_seq')", ], $sql); - $this->_sm->alterTable($diff); - $tableFinal = $this->_sm->listTableDetails('autoinc_table_add'); + $this->schemaManager->alterTable($diff); + $tableFinal = $this->schemaManager->listTableDetails('autoinc_table_add'); self::assertTrue($tableFinal->getColumn('id')->getAutoincrement()); } @@ -123,8 +125,8 @@ public function testAlterTableAutoIncrementDrop() $tableFrom = new Table('autoinc_table_drop'); $column = $tableFrom->addColumn('id', 'integer'); $column->setAutoincrement(true); - $this->_sm->createTable($tableFrom); - $tableFrom = $this->_sm->listTableDetails('autoinc_table_drop'); + $this->schemaManager->createTable($tableFrom); + $tableFrom = $this->schemaManager->listTableDetails('autoinc_table_drop'); self::assertTrue($tableFrom->getColumn('id')->getAutoincrement()); $tableTo = new Table('autoinc_table_drop'); @@ -132,11 +134,11 @@ public function testAlterTableAutoIncrementDrop() $c = new Comparator(); $diff = $c->diffTable($tableFrom, $tableTo); - self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $diff, 'There should be a difference and not false being returned from the table comparison'); - self::assertEquals(['ALTER TABLE autoinc_table_drop ALTER id DROP DEFAULT'], $this->_conn->getDatabasePlatform()->getAlterTableSQL($diff)); + self::assertInstanceOf(TableDiff::class, $diff, 'There should be a difference and not false being returned from the table comparison'); + self::assertEquals(['ALTER TABLE autoinc_table_drop ALTER id DROP DEFAULT'], $this->connection->getDatabasePlatform()->getAlterTableSQL($diff)); - $this->_sm->alterTable($diff); - $tableFinal = $this->_sm->listTableDetails('autoinc_table_drop'); + $this->schemaManager->alterTable($diff); + $tableFinal = $this->schemaManager->listTableDetails('autoinc_table_drop'); self::assertFalse($tableFinal->getColumn('id')->getAutoincrement()); } @@ -145,7 +147,7 @@ public function testAlterTableAutoIncrementDrop() */ public function testTableWithSchema() { - $this->_conn->exec('CREATE SCHEMA nested'); + $this->connection->exec('CREATE SCHEMA nested'); $nestedRelatedTable = new Table('nested.schemarelated'); $column = $nestedRelatedTable->addColumn('id', 'integer'); @@ -158,13 +160,13 @@ public function testTableWithSchema() $nestedSchemaTable->setPrimaryKey(['id']); $nestedSchemaTable->addUnnamedForeignKeyConstraint($nestedRelatedTable, ['id'], ['id']); - $this->_sm->createTable($nestedRelatedTable); - $this->_sm->createTable($nestedSchemaTable); + $this->schemaManager->createTable($nestedRelatedTable); + $this->schemaManager->createTable($nestedSchemaTable); - $tables = $this->_sm->listTableNames(); + $tables = $this->schemaManager->listTableNames(); self::assertContains('nested.schematable', $tables, 'The table should be detected with its non-public schema.'); - $nestedSchemaTable = $this->_sm->listTableDetails('nested.schematable'); + $nestedSchemaTable = $this->schemaManager->listTableDetails('nested.schematable'); self::assertTrue($nestedSchemaTable->hasColumn('id')); self::assertEquals(['id'], $nestedSchemaTable->getPrimaryKey()->getColumns()); @@ -181,19 +183,19 @@ public function testTableWithSchema() public function testReturnQuotedAssets() { $sql = 'create table dbal91_something ( id integer CONSTRAINT id_something PRIMARY KEY NOT NULL ,"table" integer );'; - $this->_conn->exec($sql); + $this->connection->exec($sql); $sql = 'ALTER TABLE dbal91_something ADD CONSTRAINT something_input FOREIGN KEY( "table" ) REFERENCES dbal91_something ON UPDATE CASCADE;'; - $this->_conn->exec($sql); + $this->connection->exec($sql); - $table = $this->_sm->listTableDetails('dbal91_something'); + $table = $this->schemaManager->listTableDetails('dbal91_something'); self::assertEquals( [ 'CREATE TABLE dbal91_something (id INT NOT NULL, "table" INT DEFAULT NULL, PRIMARY KEY(id))', 'CREATE INDEX IDX_A9401304ECA7352B ON dbal91_something ("table")', ], - $this->_conn->getDatabasePlatform()->getCreateTableSQL($table) + $this->connection->getDatabasePlatform()->getCreateTableSQL($table) ); } @@ -204,23 +206,23 @@ public function testFilterSchemaExpression() { $testTable = new Table('dbal204_test_prefix'); $column = $testTable->addColumn('id', 'integer'); - $this->_sm->createTable($testTable); + $this->schemaManager->createTable($testTable); $testTable = new Table('dbal204_without_prefix'); $column = $testTable->addColumn('id', 'integer'); - $this->_sm->createTable($testTable); + $this->schemaManager->createTable($testTable); - $this->_conn->getConfiguration()->setFilterSchemaAssetsExpression('#^dbal204_#'); - $names = $this->_sm->listTableNames(); + $this->connection->getConfiguration()->setFilterSchemaAssetsExpression('#^dbal204_#'); + $names = $this->schemaManager->listTableNames(); self::assertCount(2, $names); - $this->_conn->getConfiguration()->setFilterSchemaAssetsExpression('#^dbal204_test#'); - $names = $this->_sm->listTableNames(); + $this->connection->getConfiguration()->setFilterSchemaAssetsExpression('#^dbal204_test#'); + $names = $this->schemaManager->listTableNames(); self::assertCount(1, $names); } public function testListForeignKeys() { - if (! $this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { + if (! $this->connection->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped('Does not support foreign key constraints.'); } @@ -228,25 +230,25 @@ public function testListForeignKeys() $foreignKeys = []; $fkTable = $this->getTestTable('test_create_fk1'); for ($i = 0; $i < count($fkOptions); $i++) { - $fkTable->addColumn("foreign_key_test$i", 'integer'); + $fkTable->addColumn('foreign_key_test' . $i, 'integer'); $foreignKeys[] = new ForeignKeyConstraint( - ["foreign_key_test$i"], + ['foreign_key_test' . $i], 'test_create_fk2', ['id'], - "foreign_key_test_$i" . '_fk', + 'foreign_key_test' . $i . '_fk', ['onDelete' => $fkOptions[$i]] ); } - $this->_sm->dropAndCreateTable($fkTable); + $this->schemaManager->dropAndCreateTable($fkTable); $this->createTestTable('test_create_fk2'); foreach ($foreignKeys as $foreignKey) { - $this->_sm->createForeignKey($foreignKey, 'test_create_fk1'); + $this->schemaManager->createForeignKey($foreignKey, 'test_create_fk1'); } - $fkeys = $this->_sm->listTableForeignKeys('test_create_fk1'); + $fkeys = $this->schemaManager->listTableForeignKeys('test_create_fk1'); self::assertEquals(count($foreignKeys), count($fkeys), "Table 'test_create_fk1' has to have " . count($foreignKeys) . ' foreign keys.'); for ($i = 0; $i < count($fkeys); $i++) { - self::assertEquals(["foreign_key_test$i"], array_map('strtolower', $fkeys[$i]->getLocalColumns())); + self::assertEquals(['foreign_key_test' . $i], array_map('strtolower', $fkeys[$i]->getLocalColumns())); self::assertEquals(['id'], array_map('strtolower', $fkeys[$i]->getForeignColumns())); self::assertEquals('test_create_fk2', strtolower($fkeys[0]->getForeignTableName())); if ($foreignKeys[$i]->getOption('onDelete') === 'NO ACTION') { @@ -267,9 +269,9 @@ public function testDefaultValueCharacterVarying() $testTable->addColumn('def', 'string', ['default' => 'foo']); $testTable->setPrimaryKey(['id']); - $this->_sm->createTable($testTable); + $this->schemaManager->createTable($testTable); - $databaseTable = $this->_sm->listTableDetails($testTable->getName()); + $databaseTable = $this->schemaManager->listTableDetails($testTable->getName()); self::assertEquals('foo', $databaseTable->getColumn('def')->getDefault()); } @@ -283,9 +285,9 @@ public function testBooleanDefault() $table->addColumn('id', 'integer'); $table->addColumn('checked', 'boolean', ['default' => false]); - $this->_sm->createTable($table); + $this->schemaManager->createTable($table); - $databaseTable = $this->_sm->listTableDetails($table->getName()); + $databaseTable = $this->schemaManager->listTableDetails($table->getName()); $c = new Comparator(); $diff = $c->diffTable($table, $databaseTable); @@ -303,14 +305,14 @@ public function testListTableWithBinary() $table->addColumn('column_binary', 'binary', ['fixed' => true]); $table->setPrimaryKey(['id']); - $this->_sm->createTable($table); + $this->schemaManager->createTable($table); - $table = $this->_sm->listTableDetails($tableName); + $table = $this->schemaManager->listTableDetails($tableName); - self::assertInstanceOf('Doctrine\DBAL\Types\BlobType', $table->getColumn('column_varbinary')->getType()); + self::assertInstanceOf(BlobType::class, $table->getColumn('column_varbinary')->getType()); self::assertFalse($table->getColumn('column_varbinary')->getFixed()); - self::assertInstanceOf('Doctrine\DBAL\Types\BlobType', $table->getColumn('column_binary')->getType()); + self::assertInstanceOf(BlobType::class, $table->getColumn('column_binary')->getType()); self::assertFalse($table->getColumn('column_binary')->getFixed()); } @@ -323,9 +325,9 @@ public function testListQuotedTable() $offlineTable->setPrimaryKey(['id']); $offlineTable->addForeignKeyConstraint($offlineTable, ['fk'], ['id']); - $this->_sm->dropAndCreateTable($offlineTable); + $this->schemaManager->dropAndCreateTable($offlineTable); - $onlineTable = $this->_sm->listTableDetails('"user"'); + $onlineTable = $this->schemaManager->listTableDetails('"user"'); $comparator = new Schema\Comparator(); @@ -341,13 +343,13 @@ public function testListTablesExcludesViews() $view = new Schema\View($name, $sql); - $this->_sm->dropAndCreateView($view); + $this->schemaManager->dropAndCreateView($view); - $tables = $this->_sm->listTables(); + $tables = $this->schemaManager->listTables(); $foundTable = false; foreach ($tables as $table) { - self::assertInstanceOf('Doctrine\DBAL\Schema\Table', $table, 'No Table instance was found in tables array.'); + self::assertInstanceOf(Table::class, $table, 'No Table instance was found in tables array.'); if (strtolower($table->getName()) !== 'list_tables_excludes_views_test_view') { continue; } @@ -369,9 +371,9 @@ public function testPartialIndexes() $offlineTable->addColumn('email', 'string'); $offlineTable->addUniqueIndex(['id', 'name'], 'simple_partial_index', ['where' => '(id IS NULL)']); - $this->_sm->dropAndCreateTable($offlineTable); + $this->schemaManager->dropAndCreateTable($offlineTable); - $onlineTable = $this->_sm->listTableDetails('person'); + $onlineTable = $this->schemaManager->listTableDetails('person'); $comparator = new Schema\Comparator(); @@ -386,22 +388,25 @@ public function testPartialIndexes() */ public function testJsonbColumn(string $type) : void { - if (! $this->_sm->getDatabasePlatform() instanceof PostgreSQL94Platform) { + if (! $this->schemaManager->getDatabasePlatform() instanceof PostgreSQL94Platform) { $this->markTestSkipped('Requires PostgresSQL 9.4+'); return; } $table = new Schema\Table('test_jsonb'); $table->addColumn('foo', $type)->setPlatformOption('jsonb', true); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); /** @var Schema\Column[] $columns */ - $columns = $this->_sm->listTableColumns('test_jsonb'); + $columns = $this->schemaManager->listTableColumns('test_jsonb'); self::assertSame($type, $columns['foo']->getType()->getName()); self::assertTrue(true, $columns['foo']->getPlatformOption('jsonb')); } + /** + * @return mixed[][] + */ public function jsonbColumnTypeProvider() : array { return [ @@ -423,9 +428,9 @@ public function testListNegativeColumnDefaultValue() $table->addColumn('col_decimal', 'decimal', ['default' => -1.1]); $table->addColumn('col_string', 'string', ['default' => '(-1)']); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); - $columns = $this->_sm->listTableColumns('test_default_negative'); + $columns = $this->schemaManager->listTableColumns('test_default_negative'); self::assertEquals(-1, $columns['col_smallint']->getDefault()); self::assertEquals(-1, $columns['col_integer']->getDefault()); @@ -435,6 +440,9 @@ public function testListNegativeColumnDefaultValue() self::assertEquals('(-1)', $columns['col_string']->getDefault()); } + /** + * @return mixed[][] + */ public static function serialTypes() : array { return [ @@ -449,14 +457,14 @@ public static function serialTypes() : array */ public function testAutoIncrementCreatesSerialDataTypesWithoutADefaultValue(string $type) : void { - $tableName = "test_serial_type_$type"; + $tableName = 'test_serial_type_' . $type; $table = new Schema\Table($tableName); $table->addColumn('id', $type, ['autoincrement' => true, 'notnull' => false]); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); - $columns = $this->_sm->listTableColumns($tableName); + $columns = $this->schemaManager->listTableColumns($tableName); self::assertNull($columns['id']->getDefault()); } @@ -467,14 +475,14 @@ public function testAutoIncrementCreatesSerialDataTypesWithoutADefaultValue(stri */ public function testAutoIncrementCreatesSerialDataTypesWithoutADefaultValueEvenWhenDefaultIsSet(string $type) : void { - $tableName = "test_serial_type_with_default_$type"; + $tableName = 'test_serial_type_with_default_' . $type; $table = new Schema\Table($tableName); $table->addColumn('id', $type, ['autoincrement' => true, 'notnull' => false, 'default' => 1]); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); - $columns = $this->_sm->listTableColumns($tableName); + $columns = $this->schemaManager->listTableColumns($tableName); self::assertNull($columns['id']->getDefault()); } @@ -488,8 +496,8 @@ public function testAlterTableAutoIncrementIntToBigInt(string $from, string $to, $tableFrom = new Table('autoinc_type_modification'); $column = $tableFrom->addColumn('id', $from); $column->setAutoincrement(true); - $this->_sm->dropAndCreateTable($tableFrom); - $tableFrom = $this->_sm->listTableDetails('autoinc_type_modification'); + $this->schemaManager->dropAndCreateTable($tableFrom); + $tableFrom = $this->schemaManager->listTableDetails('autoinc_type_modification'); self::assertTrue($tableFrom->getColumn('id')->getAutoincrement()); $tableTo = new Table('autoinc_type_modification'); @@ -499,13 +507,16 @@ public function testAlterTableAutoIncrementIntToBigInt(string $from, string $to, $c = new Comparator(); $diff = $c->diffTable($tableFrom, $tableTo); self::assertInstanceOf(TableDiff::class, $diff, 'There should be a difference and not false being returned from the table comparison'); - self::assertSame(['ALTER TABLE autoinc_type_modification ALTER id TYPE ' . $expected], $this->_conn->getDatabasePlatform()->getAlterTableSQL($diff)); + self::assertSame(['ALTER TABLE autoinc_type_modification ALTER id TYPE ' . $expected], $this->connection->getDatabasePlatform()->getAlterTableSQL($diff)); - $this->_sm->alterTable($diff); - $tableFinal = $this->_sm->listTableDetails('autoinc_type_modification'); + $this->schemaManager->alterTable($diff); + $tableFinal = $this->schemaManager->listTableDetails('autoinc_type_modification'); self::assertTrue($tableFinal->getColumn('id')->getAutoincrement()); } + /** + * @return mixed[][] + */ public function autoIncrementTypeMigrations() : array { return [ @@ -522,6 +533,9 @@ public function getName() return 'MyMoney'; } + /** + * {@inheritDoc} + */ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { return 'MyMoney'; diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php index 5c68a19bcfd..f48c5157256 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php @@ -17,12 +17,12 @@ public function testCreateAndListViews() $view = new View($name, $sql); - $this->_sm->dropAndCreateView($view); + $this->schemaManager->dropAndCreateView($view); - $views = $this->_sm->listViews(); + $views = $this->schemaManager->listViews(); self::assertCount(1, $views, 'Database has to have one view.'); - self::assertInstanceOf('Doctrine\DBAL\Schema\View', $views[$name]); + self::assertInstanceOf(View::class, $views[$name]); self::assertEquals($name, $views[$name]->getName()); self::assertEquals($sql, $views[$name]->getSql()); } @@ -30,13 +30,13 @@ public function testCreateAndListViews() public function testDropAndCreateAdvancedIndex() { $table = $this->getTestTable('test_create_advanced_index'); - $this->_sm->dropAndCreateTable($table); - $this->_sm->dropAndCreateIndex( + $this->schemaManager->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateIndex( new Index('test', ['test'], true, false, ['clustered', 'with_nulls_not_distinct', 'for_olap_workload']), $table->getName() ); - $tableIndexes = $this->_sm->listTableIndexes('test_create_advanced_index'); + $tableIndexes = $this->schemaManager->listTableIndexes('test_create_advanced_index'); self::assertInternalType('array', $tableIndexes); self::assertEquals('test', $tableIndexes['test']->getName()); self::assertEquals(['test'], $tableIndexes['test']->getColumns()); @@ -54,9 +54,9 @@ public function testListTableColumnsWithFixedStringTypeColumn() $table->addColumn('test', 'string', ['fixed' => true]); $table->setPrimaryKey(['id']); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); - $columns = $this->_sm->listTableColumns('list_table_columns_char'); + $columns = $this->schemaManager->listTableColumns('list_table_columns_char'); self::assertArrayHasKey('test', $columns); self::assertTrue($columns['test']->getFixed()); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php index 218c11292be..cb7f37f15d5 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php @@ -25,12 +25,12 @@ public function testDropColumnConstraints() $table->addColumn('id', 'integer'); $table->addColumn('todrop', 'decimal', ['default' => 10.2]); - $this->_sm->createTable($table); + $this->schemaManager->createTable($table); $diff = new TableDiff('sqlsrv_drop_column', [], [], [new Column('todrop', Type::getType('decimal'))]); - $this->_sm->alterTable($diff); + $this->schemaManager->alterTable($diff); - $columns = $this->_sm->listTableColumns('sqlsrv_drop_column'); + $columns = $this->schemaManager->listTableColumns('sqlsrv_drop_column'); self::assertCount(1, $columns); } @@ -39,22 +39,22 @@ public function testColumnCollation() $table = new Table($tableName = 'test_collation'); $column = $table->addColumn($columnName = 'test', 'string'); - $this->_sm->dropAndCreateTable($table); - $columns = $this->_sm->listTableColumns($tableName); + $this->schemaManager->dropAndCreateTable($table); + $columns = $this->schemaManager->listTableColumns($tableName); self::assertTrue($columns[$columnName]->hasPlatformOption('collation')); // SQL Server should report a default collation on the column $column->setPlatformOption('collation', $collation = 'Icelandic_CS_AS'); - $this->_sm->dropAndCreateTable($table); - $columns = $this->_sm->listTableColumns($tableName); + $this->schemaManager->dropAndCreateTable($table); + $columns = $this->schemaManager->listTableColumns($tableName); self::assertEquals($collation, $columns[$columnName]->getPlatformOption('collation')); } public function testDefaultConstraints() { - $platform = $this->_sm->getDatabasePlatform(); + $platform = $this->schemaManager->getDatabasePlatform(); $table = new Table('sqlsrv_default_constraints'); $table->addColumn('no_default', 'string'); $table->addColumn('df_integer', 'integer', ['default' => 666]); @@ -66,8 +66,8 @@ public function testDefaultConstraints() $table->addColumn('df_current_date', 'date', ['default' => $platform->getCurrentDateSQL()]); $table->addColumn('df_current_time', 'time', ['default' => $platform->getCurrentTimeSQL()]); - $this->_sm->createTable($table); - $columns = $this->_sm->listTableColumns('sqlsrv_default_constraints'); + $this->schemaManager->createTable($table); + $columns = $this->schemaManager->listTableColumns('sqlsrv_default_constraints'); self::assertNull($columns['no_default']->getDefault()); self::assertEquals(666, $columns['df_integer']->getDefault()); @@ -122,8 +122,8 @@ public function testDefaultConstraints() ['default' => 'column to rename'] ); - $this->_sm->alterTable($diff); - $columns = $this->_sm->listTableColumns('sqlsrv_default_constraints'); + $this->schemaManager->alterTable($diff); + $columns = $this->schemaManager->listTableColumns('sqlsrv_default_constraints'); self::assertNull($columns['no_default']->getDefault()); self::assertEquals('CURRENT_TIMESTAMP', $columns['df_current_timestamp']->getDefault()); @@ -160,8 +160,8 @@ public function testDefaultConstraints() $table ); - $this->_sm->alterTable($diff); - $columns = $this->_sm->listTableColumns('sqlsrv_default_constraints'); + $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()); @@ -187,9 +187,9 @@ public function testColumnComments() $table->addColumn('commented_type_with_comment', 'array', ['comment' => 'Doctrine array type.']); $table->setPrimaryKey(['id']); - $this->_sm->createTable($table); + $this->schemaManager->createTable($table); - $columns = $this->_sm->listTableColumns('sqlsrv_column_comment'); + $columns = $this->schemaManager->listTableColumns('sqlsrv_column_comment'); self::assertCount(12, $columns); self::assertNull($columns['id']->getComment()); self::assertNull($columns['comment_null']->getComment()); @@ -303,9 +303,9 @@ public function testColumnComments() $tableDiff->removedColumns['comment_integer_0'] = new Column('comment_integer_0', Type::getType('integer'), ['comment' => 0]); - $this->_sm->alterTable($tableDiff); + $this->schemaManager->alterTable($tableDiff); - $columns = $this->_sm->listTableColumns('sqlsrv_column_comment'); + $columns = $this->schemaManager->listTableColumns('sqlsrv_column_comment'); self::assertCount(23, $columns); self::assertEquals('primary', $columns['id']->getComment()); self::assertNull($columns['comment_null']->getComment()); @@ -345,9 +345,9 @@ public function testPkOrdering() $table->addColumn('colA', 'integer', ['notnull' => true]); $table->addColumn('colB', 'integer', ['notnull' => true]); $table->setPrimaryKey(['colB', 'colA']); - $this->_sm->createTable($table); + $this->schemaManager->createTable($table); - $indexes = $this->_sm->listTableIndexes('sqlsrv_pk_ordering'); + $indexes = $this->schemaManager->listTableIndexes('sqlsrv_pk_ordering'); self::assertCount(1, $indexes); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index 0a20f5ca4d9..425039fa023 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -4,6 +4,7 @@ use Doctrine\Common\EventManager; use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\Events; use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Schema\AbstractAsset; @@ -18,6 +19,15 @@ use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Schema\View; +use Doctrine\DBAL\Types\ArrayType; +use Doctrine\DBAL\Types\BinaryType; +use Doctrine\DBAL\Types\DateIntervalType; +use Doctrine\DBAL\Types\DateTimeType; +use Doctrine\DBAL\Types\DecimalType; +use Doctrine\DBAL\Types\IntegerType; +use Doctrine\DBAL\Types\ObjectType; +use Doctrine\DBAL\Types\StringType; +use Doctrine\DBAL\Types\TextType; use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DbalFunctionalTestCase; use function array_filter; @@ -39,7 +49,7 @@ class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase { /** @var AbstractSchemaManager */ - protected $_sm; + protected $schemaManager; protected function getPlatformName() { @@ -55,11 +65,11 @@ protected function setUp() $dbms = $this->getPlatformName(); - if ($this->_conn->getDatabasePlatform()->getName() !== $dbms) { + if ($this->connection->getDatabasePlatform()->getName() !== $dbms) { $this->markTestSkipped(static::class . ' requires the use of ' . $dbms); } - $this->_sm = $this->_conn->getSchemaManager(); + $this->schemaManager = $this->connection->getSchemaManager(); } @@ -67,12 +77,12 @@ protected function tearDown() { parent::tearDown(); - $this->_sm->tryMethod('dropTable', 'testschema.my_table_in_namespace'); + $this->schemaManager->tryMethod('dropTable', 'testschema.my_table_in_namespace'); //TODO: SchemaDiff does not drop removed namespaces? try { //sql server versions below 2016 do not support 'IF EXISTS' so we have to catch the exception here - $this->_conn->exec('DROP SCHEMA testschema'); + $this->connection->exec('DROP SCHEMA testschema'); } catch (DBALException $e) { return; } @@ -84,21 +94,21 @@ protected function tearDown() */ public function testDropsDatabaseWithActiveConnections() { - if (! $this->_sm->getDatabasePlatform()->supportsCreateDropDatabase()) { + if (! $this->schemaManager->getDatabasePlatform()->supportsCreateDropDatabase()) { $this->markTestSkipped('Cannot drop Database client side with this Driver.'); } - $this->_sm->dropAndCreateDatabase('test_drop_database'); + $this->schemaManager->dropAndCreateDatabase('test_drop_database'); - $knownDatabases = $this->_sm->listDatabases(); - if ($this->_conn->getDatabasePlatform() instanceof OraclePlatform) { + $knownDatabases = $this->schemaManager->listDatabases(); + if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) { self::assertContains('TEST_DROP_DATABASE', $knownDatabases); } else { self::assertContains('test_drop_database', $knownDatabases); } - $params = $this->_conn->getParams(); - if ($this->_conn->getDatabasePlatform() instanceof OraclePlatform) { + $params = $this->connection->getParams(); + if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) { $params['user'] = 'test_drop_database'; } else { $params['dbname'] = 'test_drop_database'; @@ -107,13 +117,13 @@ public function testDropsDatabaseWithActiveConnections() $user = $params['user'] ?? null; $password = $params['password'] ?? null; - $connection = $this->_conn->getDriver()->connect($params, $user, $password); + $connection = $this->connection->getDriver()->connect($params, $user, $password); - self::assertInstanceOf('Doctrine\DBAL\Driver\Connection', $connection); + self::assertInstanceOf(Connection::class, $connection); - $this->_sm->dropDatabase('test_drop_database'); + $this->schemaManager->dropDatabase('test_drop_database'); - self::assertNotContains('test_drop_database', $this->_sm->listDatabases()); + self::assertNotContains('test_drop_database', $this->schemaManager->listDatabases()); } /** @@ -121,17 +131,20 @@ public function testDropsDatabaseWithActiveConnections() */ public function testDropAndCreateSequence() { - if (! $this->_conn->getDatabasePlatform()->supportsSequences()) { - $this->markTestSkipped($this->_conn->getDriver()->getName() . ' does not support sequences.'); + if (! $this->connection->getDatabasePlatform()->supportsSequences()) { + $this->markTestSkipped($this->connection->getDriver()->getName() . ' does not support sequences.'); } $name = 'dropcreate_sequences_test_seq'; - $this->_sm->dropAndCreateSequence(new Sequence($name, 20, 10)); + $this->schemaManager->dropAndCreateSequence(new Sequence($name, 20, 10)); - self::assertTrue($this->hasElementWithName($this->_sm->listSequences(), $name)); + self::assertTrue($this->hasElementWithName($this->schemaManager->listSequences(), $name)); } + /** + * @param AbstractAsset[] $items + */ private function hasElementWithName(array $items, string $name) : bool { $filteredList = array_filter( @@ -146,14 +159,14 @@ static function (AbstractAsset $item) use ($name) : bool { public function testListSequences() { - if (! $this->_conn->getDatabasePlatform()->supportsSequences()) { - $this->markTestSkipped($this->_conn->getDriver()->getName() . ' does not support sequences.'); + if (! $this->connection->getDatabasePlatform()->supportsSequences()) { + $this->markTestSkipped($this->connection->getDriver()->getName() . ' does not support sequences.'); } $sequence = new Sequence('list_sequences_test_seq', 20, 10); - $this->_sm->createSequence($sequence); + $this->schemaManager->createSequence($sequence); - $sequences = $this->_sm->listSequences(); + $sequences = $this->schemaManager->listSequences(); self::assertInternalType('array', $sequences, 'listSequences() should return an array.'); @@ -174,12 +187,12 @@ public function testListSequences() public function testListDatabases() { - if (! $this->_sm->getDatabasePlatform()->supportsCreateDropDatabase()) { + if (! $this->schemaManager->getDatabasePlatform()->supportsCreateDropDatabase()) { $this->markTestSkipped('Cannot drop Database client side with this Driver.'); } - $this->_sm->dropAndCreateDatabase('test_create_database'); - $databases = $this->_sm->listDatabases(); + $this->schemaManager->dropAndCreateDatabase('test_create_database'); + $databases = $this->schemaManager->listDatabases(); $databases = array_map('strtolower', $databases); @@ -191,18 +204,18 @@ public function testListDatabases() */ public function testListNamespaceNames() { - if (! $this->_sm->getDatabasePlatform()->supportsSchemas()) { + if (! $this->schemaManager->getDatabasePlatform()->supportsSchemas()) { $this->markTestSkipped('Platform does not support schemas.'); } // Currently dropping schemas is not supported, so we have to workaround here. - $namespaces = $this->_sm->listNamespaceNames(); + $namespaces = $this->schemaManager->listNamespaceNames(); $namespaces = array_map('strtolower', $namespaces); if (! in_array('test_create_schema', $namespaces)) { - $this->_conn->executeUpdate($this->_sm->getDatabasePlatform()->getCreateSchemaSQL('test_create_schema')); + $this->connection->executeUpdate($this->schemaManager->getDatabasePlatform()->getCreateSchemaSQL('test_create_schema')); - $namespaces = $this->_sm->listNamespaceNames(); + $namespaces = $this->schemaManager->listNamespaceNames(); $namespaces = array_map('strtolower', $namespaces); } @@ -212,14 +225,14 @@ public function testListNamespaceNames() public function testListTables() { $this->createTestTable('list_tables_test'); - $tables = $this->_sm->listTables(); + $tables = $this->schemaManager->listTables(); self::assertInternalType('array', $tables); self::assertTrue(count($tables) > 0, "List Tables has to find at least one table named 'list_tables_test'."); $foundTable = false; foreach ($tables as $table) { - self::assertInstanceOf('Doctrine\DBAL\Schema\Table', $table); + self::assertInstanceOf(Table::class, $table); if (strtolower($table->getName()) !== 'list_tables_test') { continue; } @@ -253,15 +266,15 @@ public function testListTableColumns() { $table = $this->createListTableColumns(); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); - $columns = $this->_sm->listTableColumns('list_table_columns'); + $columns = $this->schemaManager->listTableColumns('list_table_columns'); $columnsKeys = array_keys($columns); self::assertArrayHasKey('id', $columns); self::assertEquals(0, array_search('id', $columnsKeys)); self::assertEquals('id', strtolower($columns['id']->getname())); - self::assertInstanceOf('Doctrine\DBAL\Types\IntegerType', $columns['id']->gettype()); + self::assertInstanceOf(IntegerType::class, $columns['id']->gettype()); self::assertEquals(false, $columns['id']->getunsigned()); self::assertEquals(true, $columns['id']->getnotnull()); self::assertEquals(null, $columns['id']->getdefault()); @@ -270,7 +283,7 @@ public function testListTableColumns() self::assertArrayHasKey('test', $columns); self::assertEquals(1, array_search('test', $columnsKeys)); self::assertEquals('test', strtolower($columns['test']->getname())); - self::assertInstanceOf('Doctrine\DBAL\Types\StringType', $columns['test']->gettype()); + self::assertInstanceOf(StringType::class, $columns['test']->gettype()); self::assertEquals(255, $columns['test']->getlength()); self::assertEquals(false, $columns['test']->getfixed()); self::assertEquals(false, $columns['test']->getnotnull()); @@ -279,7 +292,7 @@ public function testListTableColumns() self::assertEquals('foo', strtolower($columns['foo']->getname())); self::assertEquals(2, array_search('foo', $columnsKeys)); - self::assertInstanceOf('Doctrine\DBAL\Types\TextType', $columns['foo']->gettype()); + self::assertInstanceOf(TextType::class, $columns['foo']->gettype()); self::assertEquals(false, $columns['foo']->getunsigned()); self::assertEquals(false, $columns['foo']->getfixed()); self::assertEquals(true, $columns['foo']->getnotnull()); @@ -288,7 +301,7 @@ public function testListTableColumns() self::assertEquals('bar', strtolower($columns['bar']->getname())); self::assertEquals(3, array_search('bar', $columnsKeys)); - self::assertInstanceOf('Doctrine\DBAL\Types\DecimalType', $columns['bar']->gettype()); + self::assertInstanceOf(DecimalType::class, $columns['bar']->gettype()); self::assertEquals(null, $columns['bar']->getlength()); self::assertEquals(10, $columns['bar']->getprecision()); self::assertEquals(4, $columns['bar']->getscale()); @@ -300,7 +313,7 @@ public function testListTableColumns() self::assertEquals('baz1', strtolower($columns['baz1']->getname())); self::assertEquals(4, array_search('baz1', $columnsKeys)); - self::assertInstanceOf('Doctrine\DBAL\Types\DateTimeType', $columns['baz1']->gettype()); + 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()); @@ -330,12 +343,12 @@ public function testListTableColumnsWithFixedStringColumn() $table = new Table($tableName); $table->addColumn('column_char', 'string', ['fixed' => true, 'length' => 2]); - $this->_sm->createTable($table); + $this->schemaManager->createTable($table); - $columns = $this->_sm->listTableColumns($tableName); + $columns = $this->schemaManager->listTableColumns($tableName); self::assertArrayHasKey('column_char', $columns); - self::assertInstanceOf('Doctrine\DBAL\Types\StringType', $columns['column_char']->getType()); + self::assertInstanceOf(StringType::class, $columns['column_char']->getType()); self::assertTrue($columns['column_char']->getFixed()); self::assertSame(2, $columns['column_char']->getLength()); } @@ -344,7 +357,7 @@ public function testListTableColumnsDispatchEvent() { $table = $this->createListTableColumns(); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); $listenerMock = $this ->getMockBuilder('ListTableColumnsDispatchEventListener') @@ -354,16 +367,16 @@ public function testListTableColumnsDispatchEvent() ->expects($this->exactly(7)) ->method('onSchemaColumnDefinition'); - $oldEventManager = $this->_sm->getDatabasePlatform()->getEventManager(); + $oldEventManager = $this->schemaManager->getDatabasePlatform()->getEventManager(); $eventManager = new EventManager(); $eventManager->addEventListener([Events::onSchemaColumnDefinition], $listenerMock); - $this->_sm->getDatabasePlatform()->setEventManager($eventManager); + $this->schemaManager->getDatabasePlatform()->setEventManager($eventManager); - $this->_sm->listTableColumns('list_table_columns'); + $this->schemaManager->listTableColumns('list_table_columns'); - $this->_sm->getDatabasePlatform()->setEventManager($oldEventManager); + $this->schemaManager->getDatabasePlatform()->setEventManager($oldEventManager); } public function testListTableIndexesDispatchEvent() @@ -372,7 +385,7 @@ public function testListTableIndexesDispatchEvent() $table->addUniqueIndex(['test'], 'test_index_name'); $table->addIndex(['id', 'test'], 'test_composite_idx'); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); $listenerMock = $this ->getMockBuilder('ListTableIndexesDispatchEventListener') @@ -382,27 +395,27 @@ public function testListTableIndexesDispatchEvent() ->expects($this->exactly(3)) ->method('onSchemaIndexDefinition'); - $oldEventManager = $this->_sm->getDatabasePlatform()->getEventManager(); + $oldEventManager = $this->schemaManager->getDatabasePlatform()->getEventManager(); $eventManager = new EventManager(); $eventManager->addEventListener([Events::onSchemaIndexDefinition], $listenerMock); - $this->_sm->getDatabasePlatform()->setEventManager($eventManager); + $this->schemaManager->getDatabasePlatform()->setEventManager($eventManager); - $this->_sm->listTableIndexes('list_table_indexes_test'); + $this->schemaManager->listTableIndexes('list_table_indexes_test'); - $this->_sm->getDatabasePlatform()->setEventManager($oldEventManager); + $this->schemaManager->getDatabasePlatform()->setEventManager($oldEventManager); } public function testDiffListTableColumns() { - if ($this->_sm->getDatabasePlatform()->getName() === 'oracle') { + 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).'); } $offlineTable = $this->createListTableColumns(); - $this->_sm->dropAndCreateTable($offlineTable); - $onlineTable = $this->_sm->listTableDetails('list_table_columns'); + $this->schemaManager->dropAndCreateTable($offlineTable); + $onlineTable = $this->schemaManager->listTableDetails('list_table_columns'); $comparator = new Comparator(); $diff = $comparator->diffTable($offlineTable, $onlineTable); @@ -416,9 +429,9 @@ public function testListTableIndexes() $table->addUniqueIndex(['test'], 'test_index_name'); $table->addIndex(['id', 'test'], 'test_composite_idx'); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); - $tableIndexes = $this->_sm->listTableIndexes('list_table_indexes_test'); + $tableIndexes = $this->schemaManager->listTableIndexes('list_table_indexes_test'); self::assertEquals(3, count($tableIndexes)); @@ -442,10 +455,10 @@ public function testDropAndCreateIndex() { $table = $this->getTestTable('test_create_index'); $table->addUniqueIndex(['test'], 'test'); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); - $this->_sm->dropAndCreateIndex($table->getIndex('test'), $table); - $tableIndexes = $this->_sm->listTableIndexes('test_create_index'); + $this->schemaManager->dropAndCreateIndex($table->getIndex('test'), $table); + $tableIndexes = $this->schemaManager->listTableIndexes('test_create_index'); self::assertInternalType('array', $tableIndexes); self::assertEquals('test', strtolower($tableIndexes['test']->getName())); @@ -456,25 +469,25 @@ public function testDropAndCreateIndex() public function testCreateTableWithForeignKeys() { - if (! $this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) { + if (! $this->schemaManager->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped('Platform does not support foreign keys.'); } $tableB = $this->getTestTable('test_foreign'); - $this->_sm->dropAndCreateTable($tableB); + $this->schemaManager->dropAndCreateTable($tableB); $tableA = $this->getTestTable('test_create_fk'); $tableA->addForeignKeyConstraint('test_foreign', ['foreign_key_test'], ['id']); - $this->_sm->dropAndCreateTable($tableA); + $this->schemaManager->dropAndCreateTable($tableA); - $fkTable = $this->_sm->listTableDetails('test_create_fk'); + $fkTable = $this->schemaManager->listTableDetails('test_create_fk'); $fkConstraints = $fkTable->getForeignKeys(); self::assertEquals(1, count($fkConstraints), "Table 'test_create_fk1' has to have one foreign key."); $fkConstraint = current($fkConstraints); - self::assertInstanceOf('\Doctrine\DBAL\Schema\ForeignKeyConstraint', $fkConstraint); + self::assertInstanceOf(ForeignKeyConstraint::class, $fkConstraint); self::assertEquals('test_foreign', strtolower($fkConstraint->getForeignTableName())); self::assertEquals(['foreign_key_test'], array_map('strtolower', $fkConstraint->getColumns())); self::assertEquals(['id'], array_map('strtolower', $fkConstraint->getForeignColumns())); @@ -484,7 +497,7 @@ public function testCreateTableWithForeignKeys() public function testListForeignKeys() { - if (! $this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { + if (! $this->connection->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped('Does not support foreign key constraints.'); } @@ -499,13 +512,13 @@ public function testListForeignKeys() ['onDelete' => 'CASCADE'] ); - $this->_sm->createForeignKey($foreignKey, 'test_create_fk1'); + $this->schemaManager->createForeignKey($foreignKey, 'test_create_fk1'); - $fkeys = $this->_sm->listTableForeignKeys('test_create_fk1'); + $fkeys = $this->schemaManager->listTableForeignKeys('test_create_fk1'); self::assertEquals(1, count($fkeys), "Table 'test_create_fk1' has to have one foreign key."); - self::assertInstanceOf('Doctrine\DBAL\Schema\ForeignKeyConstraint', $fkeys[0]); + self::assertInstanceOf(ForeignKeyConstraint::class, $fkeys[0]); self::assertEquals(['foreign_key_test'], array_map('strtolower', $fkeys[0]->getLocalColumns())); self::assertEquals(['id'], array_map('strtolower', $fkeys[0]->getForeignColumns())); self::assertEquals('test_create_fk2', strtolower($fkeys[0]->getForeignTableName())); @@ -526,20 +539,20 @@ public function testCreateSchema() { $this->createTestTable('test_table'); - $schema = $this->_sm->createSchema(); + $schema = $this->schemaManager->createSchema(); self::assertTrue($schema->hasTable('test_table')); } public function testAlterTableScenario() { - if (! $this->_sm->getDatabasePlatform()->supportsAlterTable()) { + if (! $this->schemaManager->getDatabasePlatform()->supportsAlterTable()) { $this->markTestSkipped('Alter Table is not supported by this platform.'); } $alterTable = $this->createTestTable('alter_table'); $this->createTestTable('alter_table_foreign'); - $table = $this->_sm->listTableDetails('alter_table'); + $table = $this->schemaManager->listTableDetails('alter_table'); self::assertTrue($table->hasColumn('id')); self::assertTrue($table->hasColumn('test')); self::assertTrue($table->hasColumn('foreign_key_test')); @@ -551,9 +564,9 @@ public function testAlterTableScenario() $tableDiff->addedColumns['foo'] = new Column('foo', Type::getType('integer')); $tableDiff->removedColumns['test'] = $table->getColumn('test'); - $this->_sm->alterTable($tableDiff); + $this->schemaManager->alterTable($tableDiff); - $table = $this->_sm->listTableDetails('alter_table'); + $table = $this->schemaManager->listTableDetails('alter_table'); self::assertFalse($table->hasColumn('test')); self::assertTrue($table->hasColumn('foo')); @@ -561,9 +574,9 @@ public function testAlterTableScenario() $tableDiff->fromTable = $table; $tableDiff->addedIndexes[] = new Index('foo_idx', ['foo']); - $this->_sm->alterTable($tableDiff); + $this->schemaManager->alterTable($tableDiff); - $table = $this->_sm->listTableDetails('alter_table'); + $table = $this->schemaManager->listTableDetails('alter_table'); self::assertEquals(2, count($table->getIndexes())); self::assertTrue($table->hasIndex('foo_idx')); self::assertEquals(['foo'], array_map('strtolower', $table->getIndex('foo_idx')->getColumns())); @@ -574,9 +587,9 @@ public function testAlterTableScenario() $tableDiff->fromTable = $table; $tableDiff->changedIndexes[] = new Index('foo_idx', ['foo', 'foreign_key_test']); - $this->_sm->alterTable($tableDiff); + $this->schemaManager->alterTable($tableDiff); - $table = $this->_sm->listTableDetails('alter_table'); + $table = $this->schemaManager->listTableDetails('alter_table'); self::assertEquals(2, count($table->getIndexes())); self::assertTrue($table->hasIndex('foo_idx')); self::assertEquals(['foo', 'foreign_key_test'], array_map('strtolower', $table->getIndex('foo_idx')->getColumns())); @@ -585,9 +598,9 @@ public function testAlterTableScenario() $tableDiff->fromTable = $table; $tableDiff->renamedIndexes['foo_idx'] = new Index('bar_idx', ['foo', 'foreign_key_test']); - $this->_sm->alterTable($tableDiff); + $this->schemaManager->alterTable($tableDiff); - $table = $this->_sm->listTableDetails('alter_table'); + $table = $this->schemaManager->listTableDetails('alter_table'); self::assertEquals(2, count($table->getIndexes())); self::assertTrue($table->hasIndex('bar_idx')); self::assertFalse($table->hasIndex('foo_idx')); @@ -601,13 +614,13 @@ public function testAlterTableScenario() $fk = new ForeignKeyConstraint(['foreign_key_test'], 'alter_table_foreign', ['id']); $tableDiff->addedForeignKeys[] = $fk; - $this->_sm->alterTable($tableDiff); - $table = $this->_sm->listTableDetails('alter_table'); + $this->schemaManager->alterTable($tableDiff); + $table = $this->schemaManager->listTableDetails('alter_table'); // dont check for index size here, some platforms automatically add indexes for foreign keys. self::assertFalse($table->hasIndex('bar_idx')); - if (! $this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) { + if (! $this->schemaManager->getDatabasePlatform()->supportsForeignKeyConstraints()) { return; } @@ -622,7 +635,7 @@ public function testAlterTableScenario() public function testTableInNamespace() { - if (! $this->_sm->getDatabasePlatform()->supportsSchemas()) { + if (! $this->schemaManager->getDatabasePlatform()->supportsSchemas()) { $this->markTestSkipped('Schema definition is not supported by this platform.'); } @@ -630,23 +643,23 @@ public function testTableInNamespace() $diff = new SchemaDiff(); $diff->newNamespaces[] = 'testschema'; - foreach ($diff->toSql($this->_sm->getDatabasePlatform()) as $sql) { - $this->_conn->exec($sql); + foreach ($diff->toSql($this->schemaManager->getDatabasePlatform()) as $sql) { + $this->connection->exec($sql); } //test if table is create in namespace $this->createTestTable('testschema.my_table_in_namespace'); - self::assertContains('testschema.my_table_in_namespace', $this->_sm->listTableNames()); + self::assertContains('testschema.my_table_in_namespace', $this->schemaManager->listTableNames()); //tables without namespace should be created in default namespace //default namespaces are ignored in table listings $this->createTestTable('my_table_not_in_namespace'); - self::assertContains('my_table_not_in_namespace', $this->_sm->listTableNames()); + self::assertContains('my_table_not_in_namespace', $this->schemaManager->listTableNames()); } public function testCreateAndListViews() { - if (! $this->_sm->getDatabasePlatform()->supportsViews()) { + if (! $this->schemaManager->getDatabasePlatform()->supportsViews()) { $this->markTestSkipped('Views is not supported by this platform.'); } @@ -657,25 +670,25 @@ public function testCreateAndListViews() $view = new View($name, $sql); - $this->_sm->dropAndCreateView($view); + $this->schemaManager->dropAndCreateView($view); - self::assertTrue($this->hasElementWithName($this->_sm->listViews(), $name)); + self::assertTrue($this->hasElementWithName($this->schemaManager->listViews(), $name)); } public function testAutoincrementDetection() { - if (! $this->_sm->getDatabasePlatform()->supportsIdentityColumns()) { + if (! $this->schemaManager->getDatabasePlatform()->supportsIdentityColumns()) { $this->markTestSkipped('This test is only supported on platforms that have autoincrement'); } $table = new Table('test_autoincrement'); - $table->setSchemaConfig($this->_sm->createSchemaConfig()); + $table->setSchemaConfig($this->schemaManager->createSchemaConfig()); $table->addColumn('id', 'integer', ['autoincrement' => true]); $table->setPrimaryKey(['id']); - $this->_sm->createTable($table); + $this->schemaManager->createTable($table); - $inferredTable = $this->_sm->listTableDetails('test_autoincrement'); + $inferredTable = $this->schemaManager->listTableDetails('test_autoincrement'); self::assertTrue($inferredTable->hasColumn('id')); self::assertTrue($inferredTable->getColumn('id')->getAutoincrement()); } @@ -685,19 +698,19 @@ public function testAutoincrementDetection() */ public function testAutoincrementDetectionMulticolumns() { - if (! $this->_sm->getDatabasePlatform()->supportsIdentityColumns()) { + if (! $this->schemaManager->getDatabasePlatform()->supportsIdentityColumns()) { $this->markTestSkipped('This test is only supported on platforms that have autoincrement'); } $table = new Table('test_not_autoincrement'); - $table->setSchemaConfig($this->_sm->createSchemaConfig()); + $table->setSchemaConfig($this->schemaManager->createSchemaConfig()); $table->addColumn('id', 'integer'); $table->addColumn('other_id', 'integer'); $table->setPrimaryKey(['id', 'other_id']); - $this->_sm->createTable($table); + $this->schemaManager->createTable($table); - $inferredTable = $this->_sm->listTableDetails('test_not_autoincrement'); + $inferredTable = $this->schemaManager->listTableDetails('test_not_autoincrement'); self::assertTrue($inferredTable->hasColumn('id')); self::assertFalse($inferredTable->getColumn('id')->getAutoincrement()); } @@ -707,7 +720,7 @@ public function testAutoincrementDetectionMulticolumns() */ public function testUpdateSchemaWithForeignKeyRenaming() { - if (! $this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) { + if (! $this->schemaManager->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped('This test is only supported on platforms that have foreign keys.'); } @@ -716,18 +729,18 @@ public function testUpdateSchemaWithForeignKeyRenaming() $table->setPrimaryKey(['id']); $tableFK = new Table('test_fk_rename'); - $tableFK->setSchemaConfig($this->_sm->createSchemaConfig()); + $tableFK->setSchemaConfig($this->schemaManager->createSchemaConfig()); $tableFK->addColumn('id', 'integer'); $tableFK->addColumn('fk_id', 'integer'); $tableFK->setPrimaryKey(['id']); $tableFK->addIndex(['fk_id'], 'fk_idx'); $tableFK->addForeignKeyConstraint('test_fk_base', ['fk_id'], ['id']); - $this->_sm->createTable($table); - $this->_sm->createTable($tableFK); + $this->schemaManager->createTable($table); + $this->schemaManager->createTable($tableFK); $tableFKNew = new Table('test_fk_rename'); - $tableFKNew->setSchemaConfig($this->_sm->createSchemaConfig()); + $tableFKNew->setSchemaConfig($this->schemaManager->createSchemaConfig()); $tableFKNew->addColumn('id', 'integer'); $tableFKNew->addColumn('rename_fk_id', 'integer'); $tableFKNew->setPrimaryKey(['id']); @@ -737,9 +750,9 @@ public function testUpdateSchemaWithForeignKeyRenaming() $c = new Comparator(); $tableDiff = $c->diffTable($tableFK, $tableFKNew); - $this->_sm->alterTable($tableDiff); + $this->schemaManager->alterTable($tableDiff); - $table = $this->_sm->listTableDetails('test_fk_rename'); + $table = $this->schemaManager->listTableDetails('test_fk_rename'); $foreignKeys = $table->getForeignKeys(); self::assertTrue($table->hasColumn('rename_fk_id')); @@ -752,7 +765,7 @@ public function testUpdateSchemaWithForeignKeyRenaming() */ public function testRenameIndexUsedInForeignKeyConstraint() { - if (! $this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) { + if (! $this->schemaManager->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped('This test is only supported on platforms that have foreign keys.'); } @@ -771,17 +784,17 @@ public function testRenameIndexUsedInForeignKeyConstraint() 'fk_constraint' ); - $this->_sm->dropAndCreateTable($primaryTable); - $this->_sm->dropAndCreateTable($foreignTable); + $this->schemaManager->dropAndCreateTable($primaryTable); + $this->schemaManager->dropAndCreateTable($foreignTable); $foreignTable2 = clone $foreignTable; $foreignTable2->renameIndex('rename_index_fk_idx', 'renamed_index_fk_idx'); $comparator = new Comparator(); - $this->_sm->alterTable($comparator->diffTable($foreignTable, $foreignTable2)); + $this->schemaManager->alterTable($comparator->diffTable($foreignTable, $foreignTable2)); - $foreignTable = $this->_sm->listTableDetails('test_rename_index_foreign'); + $foreignTable = $this->schemaManager->listTableDetails('test_rename_index_foreign'); self::assertFalse($foreignTable->hasIndex('rename_index_fk_idx')); self::assertTrue($foreignTable->hasIndex('renamed_index_fk_idx')); @@ -793,9 +806,9 @@ public function testRenameIndexUsedInForeignKeyConstraint() */ public function testGetColumnComment() { - if (! $this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && - ! $this->_conn->getDatabasePlatform()->supportsCommentOnStatement() && - $this->_conn->getDatabasePlatform()->getName() !== 'mssql') { + if (! $this->connection->getDatabasePlatform()->supportsInlineColumnComments() && + ! $this->connection->getDatabasePlatform()->supportsCommentOnStatement() && + $this->connection->getDatabasePlatform()->getName() !== 'mssql') { $this->markTestSkipped('Database does not support column comments.'); } @@ -803,9 +816,9 @@ public function testGetColumnComment() $table->addColumn('id', 'integer', ['comment' => 'This is a comment']); $table->setPrimaryKey(['id']); - $this->_sm->createTable($table); + $this->schemaManager->createTable($table); - $columns = $this->_sm->listTableColumns('column_comment_test'); + $columns = $this->schemaManager->listTableColumns('column_comment_test'); self::assertEquals(1, count($columns)); self::assertEquals('This is a comment', $columns['id']->getComment()); @@ -825,9 +838,9 @@ public function testGetColumnComment() ) ); - $this->_sm->alterTable($tableDiff); + $this->schemaManager->alterTable($tableDiff); - $columns = $this->_sm->listTableColumns('column_comment_test'); + $columns = $this->schemaManager->listTableColumns('column_comment_test'); self::assertEquals(1, count($columns)); self::assertEmpty($columns['id']->getComment()); } @@ -837,9 +850,9 @@ public function testGetColumnComment() */ public function testAutomaticallyAppendCommentOnMarkedColumns() { - if (! $this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && - ! $this->_conn->getDatabasePlatform()->supportsCommentOnStatement() && - $this->_conn->getDatabasePlatform()->getName() !== 'mssql') { + if (! $this->connection->getDatabasePlatform()->supportsInlineColumnComments() && + ! $this->connection->getDatabasePlatform()->supportsCommentOnStatement() && + $this->connection->getDatabasePlatform()->getName() !== 'mssql') { $this->markTestSkipped('Database does not support column comments.'); } @@ -849,15 +862,15 @@ public function testAutomaticallyAppendCommentOnMarkedColumns() $table->addColumn('arr', 'array', ['comment' => 'This is a comment']); $table->setPrimaryKey(['id']); - $this->_sm->createTable($table); + $this->schemaManager->createTable($table); - $columns = $this->_sm->listTableColumns('column_comment_test2'); + $columns = $this->schemaManager->listTableColumns('column_comment_test2'); self::assertEquals(3, count($columns)); self::assertEquals('This is a comment', $columns['id']->getComment()); self::assertEquals('This is a comment', $columns['obj']->getComment(), 'The Doctrine2 Typehint should be stripped from comment.'); - self::assertInstanceOf('Doctrine\DBAL\Types\ObjectType', $columns['obj']->getType(), 'The Doctrine2 should be detected from comment hint.'); + self::assertInstanceOf(ObjectType::class, $columns['obj']->getType(), 'The Doctrine2 should be detected from comment hint.'); self::assertEquals('This is a comment', $columns['arr']->getComment(), 'The Doctrine2 Typehint should be stripped from comment.'); - self::assertInstanceOf('Doctrine\DBAL\Types\ArrayType', $columns['arr']->getType(), 'The Doctrine2 should be detected from comment hint.'); + self::assertInstanceOf(ArrayType::class, $columns['arr']->getType(), 'The Doctrine2 should be detected from comment hint.'); } /** @@ -865,9 +878,9 @@ public function testAutomaticallyAppendCommentOnMarkedColumns() */ public function testCommentHintOnDateIntervalTypeColumn() { - if (! $this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && - ! $this->_conn->getDatabasePlatform()->supportsCommentOnStatement() && - $this->_conn->getDatabasePlatform()->getName() !== 'mssql') { + if (! $this->connection->getDatabasePlatform()->supportsInlineColumnComments() && + ! $this->connection->getDatabasePlatform()->supportsCommentOnStatement() && + $this->connection->getDatabasePlatform()->getName() !== 'mssql') { $this->markTestSkipped('Database does not support column comments.'); } @@ -876,13 +889,13 @@ public function testCommentHintOnDateIntervalTypeColumn() $table->addColumn('date_interval', 'dateinterval', ['comment' => 'This is a comment']); $table->setPrimaryKey(['id']); - $this->_sm->createTable($table); + $this->schemaManager->createTable($table); - $columns = $this->_sm->listTableColumns('column_dateinterval_comment'); + $columns = $this->schemaManager->listTableColumns('column_dateinterval_comment'); self::assertEquals(2, count($columns)); self::assertEquals('This is a comment', $columns['id']->getComment()); self::assertEquals('This is a comment', $columns['date_interval']->getComment(), 'The Doctrine2 Typehint should be stripped from comment.'); - self::assertInstanceOf('Doctrine\DBAL\Types\DateIntervalType', $columns['date_interval']->getType(), 'The Doctrine2 should be detected from comment hint.'); + self::assertInstanceOf(DateIntervalType::class, $columns['date_interval']->getType(), 'The Doctrine2 should be detected from comment hint.'); } /** @@ -896,7 +909,7 @@ public function testChangeColumnsTypeWithDefaultValue() $table->addColumn('col_int', 'smallint', ['default' => 666]); $table->addColumn('col_string', 'string', ['default' => 'foo']); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); $tableDiff = new TableDiff($tableName); $tableDiff->fromTable = $table; @@ -914,14 +927,14 @@ public function testChangeColumnsTypeWithDefaultValue() new Column('col_string', Type::getType('string'), ['default' => 'foo']) ); - $this->_sm->alterTable($tableDiff); + $this->schemaManager->alterTable($tableDiff); - $columns = $this->_sm->listTableColumns($tableName); + $columns = $this->schemaManager->listTableColumns($tableName); - self::assertInstanceOf('Doctrine\DBAL\Types\IntegerType', $columns['col_int']->getType()); + self::assertInstanceOf(IntegerType::class, $columns['col_int']->getType()); self::assertEquals(666, $columns['col_int']->getDefault()); - self::assertInstanceOf('Doctrine\DBAL\Types\StringType', $columns['col_string']->getType()); + self::assertInstanceOf(StringType::class, $columns['col_string']->getType()); self::assertEquals('foo', $columns['col_string']->getDefault()); } @@ -935,9 +948,9 @@ public function testListTableWithBlob() $table->addColumn('binarydata', 'blob', []); $table->setPrimaryKey(['id']); - $this->_sm->createTable($table); + $this->schemaManager->createTable($table); - $created = $this->_sm->listTableDetails('test_blob_table'); + $created = $this->schemaManager->listTableDetails('test_blob_table'); self::assertTrue($created->hasColumn('id')); self::assertTrue($created->hasColumn('binarydata')); @@ -945,18 +958,18 @@ public function testListTableWithBlob() } /** - * @param string $name - * @param array $data + * @param string $name + * @param mixed[] $data * * @return Table */ - protected function createTestTable($name = 'test_table', $data = []) + protected function createTestTable($name = 'test_table', array $data = []) { $options = $data['options'] ?? []; $table = $this->getTestTable($name, $options); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); return $table; } @@ -964,7 +977,7 @@ protected function createTestTable($name = 'test_table', $data = []) protected function getTestTable($name, $options = []) { $table = new Table($name, [], [], [], false, $options); - $table->setSchemaConfig($this->_sm->createSchemaConfig()); + $table->setSchemaConfig($this->schemaManager->createSchemaConfig()); $table->addColumn('id', 'integer', ['notnull' => true]); $table->setPrimaryKey(['id']); $table->addColumn('test', 'string', ['length' => 255]); @@ -975,7 +988,7 @@ protected function getTestTable($name, $options = []) protected function getTestCompositeTable($name) { $table = new Table($name, [], [], [], false, []); - $table->setSchemaConfig($this->_sm->createSchemaConfig()); + $table->setSchemaConfig($this->schemaManager->createSchemaConfig()); $table->addColumn('id', 'integer', ['notnull' => true]); $table->addColumn('other_id', 'integer', ['notnull' => true]); $table->setPrimaryKey(['id', 'other_id']); @@ -987,7 +1000,7 @@ protected function assertHasTable($tables, $tableName) { $foundTable = false; foreach ($tables as $table) { - self::assertInstanceOf('Doctrine\DBAL\Schema\Table', $table, 'No Table instance was found in tables array.'); + self::assertInstanceOf(Table::class, $table, 'No Table instance was found in tables array.'); if (strtolower($table->getName()) !== 'list_tables_test_new_name') { continue; } @@ -999,12 +1012,12 @@ protected function assertHasTable($tables, $tableName) public function testListForeignKeysComposite() { - if (! $this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) { + if (! $this->connection->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped('Does not support foreign key constraints.'); } - $this->_sm->createTable($this->getTestTable('test_create_fk3')); - $this->_sm->createTable($this->getTestCompositeTable('test_create_fk4')); + $this->schemaManager->createTable($this->getTestTable('test_create_fk3')); + $this->schemaManager->createTable($this->getTestCompositeTable('test_create_fk4')); $foreignKey = new ForeignKeyConstraint( ['id', 'foreign_key_test'], @@ -1013,13 +1026,13 @@ public function testListForeignKeysComposite() 'foreign_key_test_fk2' ); - $this->_sm->createForeignKey($foreignKey, 'test_create_fk3'); + $this->schemaManager->createForeignKey($foreignKey, 'test_create_fk3'); - $fkeys = $this->_sm->listTableForeignKeys('test_create_fk3'); + $fkeys = $this->schemaManager->listTableForeignKeys('test_create_fk3'); self::assertEquals(1, count($fkeys), "Table 'test_create_fk3' has to have one foreign key."); - self::assertInstanceOf('Doctrine\DBAL\Schema\ForeignKeyConstraint', $fkeys[0]); + self::assertInstanceOf(ForeignKeyConstraint::class, $fkeys[0]); self::assertEquals(['id', 'foreign_key_test'], array_map('strtolower', $fkeys[0]->getLocalColumns())); self::assertEquals(['id', 'other_id'], array_map('strtolower', $fkeys[0]->getForeignColumns())); } @@ -1040,9 +1053,9 @@ public function testColumnDefaultLifecycle() $table->addColumn('column7', 'integer', ['default' => 0]); $table->setPrimaryKey(['id']); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); - $columns = $this->_sm->listTableColumns('col_def_lifecycle'); + $columns = $this->schemaManager->listTableColumns('col_def_lifecycle'); self::assertNull($columns['id']->getDefault()); self::assertNull($columns['column1']->getDefault()); @@ -1065,9 +1078,9 @@ public function testColumnDefaultLifecycle() $comparator = new Comparator(); - $this->_sm->alterTable($comparator->diffTable($table, $diffTable)); + $this->schemaManager->alterTable($comparator->diffTable($table, $diffTable)); - $columns = $this->_sm->listTableColumns('col_def_lifecycle'); + $columns = $this->schemaManager->listTableColumns('col_def_lifecycle'); self::assertSame('', $columns['column1']->getDefault()); self::assertNull($columns['column2']->getDefault()); @@ -1088,24 +1101,24 @@ public function testListTableWithBinary() $table->addColumn('column_binary', 'binary', ['fixed' => true]); $table->setPrimaryKey(['id']); - $this->_sm->createTable($table); + $this->schemaManager->createTable($table); - $table = $this->_sm->listTableDetails($tableName); + $table = $this->schemaManager->listTableDetails($tableName); - self::assertInstanceOf('Doctrine\DBAL\Types\BinaryType', $table->getColumn('column_varbinary')->getType()); + self::assertInstanceOf(BinaryType::class, $table->getColumn('column_varbinary')->getType()); self::assertFalse($table->getColumn('column_varbinary')->getFixed()); - self::assertInstanceOf('Doctrine\DBAL\Types\BinaryType', $table->getColumn('column_binary')->getType()); + self::assertInstanceOf(BinaryType::class, $table->getColumn('column_binary')->getType()); self::assertTrue($table->getColumn('column_binary')->getFixed()); } public function testListTableDetailsWithFullQualifiedTableName() { - if (! $this->_sm->getDatabasePlatform()->supportsSchemas()) { + if (! $this->schemaManager->getDatabasePlatform()->supportsSchemas()) { $this->markTestSkipped('Test only works on platforms that support schemas.'); } - $defaultSchemaName = $this->_sm->getDatabasePlatform()->getDefaultSchemaName(); + $defaultSchemaName = $this->schemaManager->getDatabasePlatform()->getDefaultSchemaName(); $primaryTableName = 'primary_table'; $foreignTableName = 'foreign_table'; @@ -1113,7 +1126,7 @@ public function testListTableDetailsWithFullQualifiedTableName() $table->addColumn('id', 'integer', ['autoincrement' => true]); $table->setPrimaryKey(['id']); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); $table = new Table($primaryTableName); $table->addColumn('id', 'integer', ['autoincrement' => true]); @@ -1123,27 +1136,27 @@ public function testListTableDetailsWithFullQualifiedTableName() $table->addIndex(['bar']); $table->setPrimaryKey(['id']); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); self::assertEquals( - $this->_sm->listTableColumns($primaryTableName), - $this->_sm->listTableColumns($defaultSchemaName . '.' . $primaryTableName) + $this->schemaManager->listTableColumns($primaryTableName), + $this->schemaManager->listTableColumns($defaultSchemaName . '.' . $primaryTableName) ); self::assertEquals( - $this->_sm->listTableIndexes($primaryTableName), - $this->_sm->listTableIndexes($defaultSchemaName . '.' . $primaryTableName) + $this->schemaManager->listTableIndexes($primaryTableName), + $this->schemaManager->listTableIndexes($defaultSchemaName . '.' . $primaryTableName) ); self::assertEquals( - $this->_sm->listTableForeignKeys($primaryTableName), - $this->_sm->listTableForeignKeys($defaultSchemaName . '.' . $primaryTableName) + $this->schemaManager->listTableForeignKeys($primaryTableName), + $this->schemaManager->listTableForeignKeys($defaultSchemaName . '.' . $primaryTableName) ); } public function testCommentStringsAreQuoted() { - if (! $this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && - ! $this->_conn->getDatabasePlatform()->supportsCommentOnStatement() && - $this->_conn->getDatabasePlatform()->getName() !== 'mssql') { + if (! $this->connection->getDatabasePlatform()->supportsInlineColumnComments() && + ! $this->connection->getDatabasePlatform()->supportsCommentOnStatement() && + $this->connection->getDatabasePlatform()->getName() !== 'mssql') { $this->markTestSkipped('Database does not support column comments.'); } @@ -1151,15 +1164,15 @@ public function testCommentStringsAreQuoted() $table->addColumn('id', 'integer', ['comment' => "It's a comment with a quote"]); $table->setPrimaryKey(['id']); - $this->_sm->createTable($table); + $this->schemaManager->createTable($table); - $columns = $this->_sm->listTableColumns('my_table'); + $columns = $this->schemaManager->listTableColumns('my_table'); self::assertEquals("It's a comment with a quote", $columns['id']->getComment()); } public function testCommentNotDuplicated() { - if (! $this->_conn->getDatabasePlatform()->supportsInlineColumnComments()) { + if (! $this->connection->getDatabasePlatform()->supportsInlineColumnComments()) { $this->markTestSkipped('Database does not support column comments.'); } @@ -1169,11 +1182,11 @@ public function testCommentNotDuplicated() 'notnull' => true, 'comment' => 'expected+column+comment', ]; - $columnDefinition = substr($this->_conn->getDatabasePlatform()->getColumnDeclarationSQL('id', $options), strlen('id') + 1); + $columnDefinition = substr($this->connection->getDatabasePlatform()->getColumnDeclarationSQL('id', $options), strlen('id') + 1); $table = new Table('my_table'); $table->addColumn('id', 'integer', ['columnDefinition' => $columnDefinition, 'comment' => 'unexpected_column_comment']); - $sql = $this->_conn->getDatabasePlatform()->getCreateTableSQL($table); + $sql = $this->connection->getDatabasePlatform()->getCreateTableSQL($table); self::assertContains('expected+column+comment', $sql[0]); self::assertNotContains('unexpected_column_comment', $sql[0]); @@ -1185,9 +1198,9 @@ public function testCommentNotDuplicated() */ public function testAlterColumnComment($comment1, $expectedComment1, $comment2, $expectedComment2) { - if (! $this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && - ! $this->_conn->getDatabasePlatform()->supportsCommentOnStatement() && - $this->_conn->getDatabasePlatform()->getName() !== 'mssql') { + if (! $this->connection->getDatabasePlatform()->supportsInlineColumnComments() && + ! $this->connection->getDatabasePlatform()->supportsCommentOnStatement() && + $this->connection->getDatabasePlatform()->getName() !== 'mssql') { $this->markTestSkipped('Database does not support column comments.'); } @@ -1196,9 +1209,9 @@ public function testAlterColumnComment($comment1, $expectedComment1, $comment2, $offlineTable->addColumn('comment2', 'integer', ['comment' => $comment2]); $offlineTable->addColumn('no_comment1', 'integer'); $offlineTable->addColumn('no_comment2', 'integer'); - $this->_sm->dropAndCreateTable($offlineTable); + $this->schemaManager->dropAndCreateTable($offlineTable); - $onlineTable = $this->_sm->listTableDetails('alter_column_comment_test'); + $onlineTable = $this->schemaManager->listTableDetails('alter_column_comment_test'); self::assertSame($expectedComment1, $onlineTable->getColumn('comment1')->getComment()); self::assertSame($expectedComment2, $onlineTable->getColumn('comment2')->getComment()); @@ -1214,11 +1227,11 @@ public function testAlterColumnComment($comment1, $expectedComment1, $comment2, $tableDiff = $comparator->diffTable($offlineTable, $onlineTable); - self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); + self::assertInstanceOf(TableDiff::class, $tableDiff); - $this->_sm->alterTable($tableDiff); + $this->schemaManager->alterTable($tableDiff); - $onlineTable = $this->_sm->listTableDetails('alter_column_comment_test'); + $onlineTable = $this->schemaManager->listTableDetails('alter_column_comment_test'); self::assertSame($expectedComment2, $onlineTable->getColumn('comment1')->getComment()); self::assertSame($expectedComment1, $onlineTable->getColumn('comment2')->getComment()); @@ -1249,7 +1262,7 @@ public function getAlterColumnComment() */ public function testDoesNotListIndexesImplicitlyCreatedByForeignKeys() { - if (! $this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) { + if (! $this->schemaManager->getDatabasePlatform()->supportsForeignKeyConstraints()) { $this->markTestSkipped('This test is only supported on platforms that have foreign keys.'); } @@ -1264,10 +1277,10 @@ public function testDoesNotListIndexesImplicitlyCreatedByForeignKeys() $foreignTable->addForeignKeyConstraint('test_list_index_impl_primary', ['fk1'], ['id']); $foreignTable->addForeignKeyConstraint('test_list_index_impl_primary', ['fk2'], ['id']); - $this->_sm->dropAndCreateTable($primaryTable); - $this->_sm->dropAndCreateTable($foreignTable); + $this->schemaManager->dropAndCreateTable($primaryTable); + $this->schemaManager->dropAndCreateTable($foreignTable); - $indexes = $this->_sm->listTableIndexes('test_list_index_impl_foreign'); + $indexes = $this->schemaManager->listTableIndexes('test_list_index_impl_foreign'); self::assertCount(2, $indexes); self::assertArrayHasKey('explicit_fk1_idx', $indexes); @@ -1279,11 +1292,11 @@ public function testDoesNotListIndexesImplicitlyCreatedByForeignKeys() */ public function removeJsonArrayTable() : void { - if (! $this->_sm->tablesExist(['json_array_test'])) { + if (! $this->schemaManager->tablesExist(['json_array_test'])) { return; } - $this->_sm->dropTable('json_array_test'); + $this->schemaManager->dropTable('json_array_test'); } /** @@ -1295,10 +1308,10 @@ public function testComparatorShouldReturnFalseWhenLegacyJsonArrayColumnHasComme $table = new Table('json_array_test'); $table->addColumn('parameters', 'json_array'); - $this->_sm->createTable($table); + $this->schemaManager->createTable($table); $comparator = new Comparator(); - $tableDiff = $comparator->diffTable($this->_sm->listTableDetails('json_array_test'), $table); + $tableDiff = $comparator->diffTable($this->schemaManager->listTableDetails('json_array_test'), $table); self::assertFalse($tableDiff); } @@ -1309,20 +1322,20 @@ public function testComparatorShouldReturnFalseWhenLegacyJsonArrayColumnHasComme */ public function testComparatorShouldModifyOnlyTheCommentWhenUpdatingFromJsonArrayTypeOnLegacyPlatforms() : void { - if ($this->_sm->getDatabasePlatform()->hasNativeJsonType()) { + if ($this->schemaManager->getDatabasePlatform()->hasNativeJsonType()) { $this->markTestSkipped('This test is only supported on platforms that do not have native JSON type.'); } $table = new Table('json_array_test'); $table->addColumn('parameters', 'json_array'); - $this->_sm->createTable($table); + $this->schemaManager->createTable($table); $table = new Table('json_array_test'); $table->addColumn('parameters', 'json'); $comparator = new Comparator(); - $tableDiff = $comparator->diffTable($this->_sm->listTableDetails('json_array_test'), $table); + $tableDiff = $comparator->diffTable($this->schemaManager->listTableDetails('json_array_test'), $table); self::assertInstanceOf(TableDiff::class, $tableDiff); @@ -1337,17 +1350,17 @@ public function testComparatorShouldModifyOnlyTheCommentWhenUpdatingFromJsonArra */ public function testComparatorShouldAddCommentToLegacyJsonArrayTypeThatDoesNotHaveIt() : void { - if (! $this->_sm->getDatabasePlatform()->hasNativeJsonType()) { + if (! $this->schemaManager->getDatabasePlatform()->hasNativeJsonType()) { $this->markTestSkipped('This test is only supported on platforms that have native JSON type.'); } - $this->_conn->executeQuery('CREATE TABLE json_array_test (parameters JSON NOT NULL)'); + $this->connection->executeQuery('CREATE TABLE json_array_test (parameters JSON NOT NULL)'); $table = new Table('json_array_test'); $table->addColumn('parameters', 'json_array'); $comparator = new Comparator(); - $tableDiff = $comparator->diffTable($this->_sm->listTableDetails('json_array_test'), $table); + $tableDiff = $comparator->diffTable($this->schemaManager->listTableDetails('json_array_test'), $table); self::assertInstanceOf(TableDiff::class, $tableDiff); self::assertSame(['comment'], $tableDiff->changedColumns['parameters']->changedProperties); @@ -1359,17 +1372,17 @@ public function testComparatorShouldAddCommentToLegacyJsonArrayTypeThatDoesNotHa */ public function testComparatorShouldReturnAllChangesWhenUsingLegacyJsonArrayType() : void { - if (! $this->_sm->getDatabasePlatform()->hasNativeJsonType()) { + if (! $this->schemaManager->getDatabasePlatform()->hasNativeJsonType()) { $this->markTestSkipped('This test is only supported on platforms that have native JSON type.'); } - $this->_conn->executeQuery('CREATE TABLE json_array_test (parameters JSON DEFAULT NULL)'); + $this->connection->executeQuery('CREATE TABLE json_array_test (parameters JSON DEFAULT NULL)'); $table = new Table('json_array_test'); $table->addColumn('parameters', 'json_array'); $comparator = new Comparator(); - $tableDiff = $comparator->diffTable($this->_sm->listTableDetails('json_array_test'), $table); + $tableDiff = $comparator->diffTable($this->schemaManager->listTableDetails('json_array_test'), $table); self::assertInstanceOf(TableDiff::class, $tableDiff); self::assertSame(['notnull', 'comment'], $tableDiff->changedColumns['parameters']->changedProperties); @@ -1381,17 +1394,17 @@ public function testComparatorShouldReturnAllChangesWhenUsingLegacyJsonArrayType */ public function testComparatorShouldReturnAllChangesWhenUsingLegacyJsonArrayTypeEvenWhenPlatformHasJsonSupport() : void { - if (! $this->_sm->getDatabasePlatform()->hasNativeJsonType()) { + if (! $this->schemaManager->getDatabasePlatform()->hasNativeJsonType()) { $this->markTestSkipped('This test is only supported on platforms that have native JSON type.'); } - $this->_conn->executeQuery('CREATE TABLE json_array_test (parameters JSON DEFAULT NULL)'); + $this->connection->executeQuery('CREATE TABLE json_array_test (parameters JSON DEFAULT NULL)'); $table = new Table('json_array_test'); $table->addColumn('parameters', 'json_array'); $comparator = new Comparator(); - $tableDiff = $comparator->diffTable($this->_sm->listTableDetails('json_array_test'), $table); + $tableDiff = $comparator->diffTable($this->schemaManager->listTableDetails('json_array_test'), $table); self::assertInstanceOf(TableDiff::class, $tableDiff); self::assertSame(['notnull', 'comment'], $tableDiff->changedColumns['parameters']->changedProperties); @@ -1403,17 +1416,17 @@ public function testComparatorShouldReturnAllChangesWhenUsingLegacyJsonArrayType */ public function testComparatorShouldNotAddCommentToJsonTypeSinceItIsTheDefaultNow() : void { - if (! $this->_sm->getDatabasePlatform()->hasNativeJsonType()) { + if (! $this->schemaManager->getDatabasePlatform()->hasNativeJsonType()) { $this->markTestSkipped('This test is only supported on platforms that have native JSON type.'); } - $this->_conn->executeQuery('CREATE TABLE json_test (parameters JSON NOT NULL)'); + $this->connection->executeQuery('CREATE TABLE json_test (parameters JSON NOT NULL)'); $table = new Table('json_test'); $table->addColumn('parameters', 'json'); $comparator = new Comparator(); - $tableDiff = $comparator->diffTable($this->_sm->listTableDetails('json_test'), $table); + $tableDiff = $comparator->diffTable($this->schemaManager->listTableDetails('json_test'), $table); self::assertFalse($tableDiff); } @@ -1424,11 +1437,14 @@ public function testComparatorShouldNotAddCommentToJsonTypeSinceItIsTheDefaultNo */ public function testExtractDoctrineTypeFromComment(string $comment, string $expected, string $currentType) : void { - $result = $this->_sm->extractDoctrineTypeFromComment($comment, $currentType); + $result = $this->schemaManager->extractDoctrineTypeFromComment($comment, $currentType); self::assertSame($expected, $result); } + /** + * @return string[][] + */ public function commentsProvider() : array { $currentType = 'current type'; @@ -1445,7 +1461,7 @@ public function commentsProvider() : array public function testCreateAndListSequences() : void { - if (! $this->_sm->getDatabasePlatform()->supportsSequences()) { + if (! $this->schemaManager->getDatabasePlatform()->supportsSequences()) { self::markTestSkipped('This test is only supported on platforms that support sequences.'); } @@ -1458,12 +1474,12 @@ public function testCreateAndListSequences() : void $sequence1 = new Sequence($sequence1Name, $sequence1AllocationSize, $sequence1InitialValue); $sequence2 = new Sequence($sequence2Name, $sequence2AllocationSize, $sequence2InitialValue); - $this->_sm->createSequence($sequence1); - $this->_sm->createSequence($sequence2); + $this->schemaManager->createSequence($sequence1); + $this->schemaManager->createSequence($sequence2); /** @var Sequence[] $actualSequences */ $actualSequences = []; - foreach ($this->_sm->listSequences() as $sequence) { + foreach ($this->schemaManager->listSequences() as $sequence) { $actualSequences[$sequence->getName()] = $sequence; } @@ -1484,7 +1500,7 @@ public function testCreateAndListSequences() : void */ public function testComparisonWithAutoDetectedSequenceDefinition() : void { - if (! $this->_sm->getDatabasePlatform()->supportsSequences()) { + if (! $this->schemaManager->getDatabasePlatform()->supportsSequences()) { self::markTestSkipped('This test is only supported on platforms that support sequences.'); } @@ -1493,11 +1509,11 @@ public function testComparisonWithAutoDetectedSequenceDefinition() : void $sequenceInitialValue = 10; $sequence = new Sequence($sequenceName, $sequenceAllocationSize, $sequenceInitialValue); - $this->_sm->dropAndCreateSequence($sequence); + $this->schemaManager->dropAndCreateSequence($sequence); $createdSequence = array_values( array_filter( - $this->_sm->listSequences(), + $this->schemaManager->listSequences(), static function (Sequence $sequence) use ($sequenceName) : bool { return strcasecmp($sequence->getName(), $sequenceName) === 0; } @@ -1521,19 +1537,19 @@ public function testPrimaryKeyAutoIncrement() $table->addColumn('id', 'integer', ['autoincrement' => true]); $table->addColumn('text', 'string'); $table->setPrimaryKey(['id']); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); - $this->_conn->insert('test_pk_auto_increment', ['text' => '1']); + $this->connection->insert('test_pk_auto_increment', ['text' => '1']); - $query = $this->_conn->query('SELECT id FROM test_pk_auto_increment WHERE text = \'1\''); + $query = $this->connection->query('SELECT id FROM test_pk_auto_increment WHERE text = \'1\''); $query->execute(); $lastUsedIdBeforeDelete = (int) $query->fetchColumn(); - $this->_conn->query('DELETE FROM test_pk_auto_increment'); + $this->connection->query('DELETE FROM test_pk_auto_increment'); - $this->_conn->insert('test_pk_auto_increment', ['text' => '2']); + $this->connection->insert('test_pk_auto_increment', ['text' => '2']); - $query = $this->_conn->query('SELECT id FROM test_pk_auto_increment WHERE text = \'2\''); + $query = $this->connection->query('SELECT id FROM test_pk_auto_increment WHERE text = \'2\''); $query->execute(); $lastUsedIdAfterDelete = (int) $query->fetchColumn(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php index ca42061b695..659e6d8dff2 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php @@ -2,8 +2,10 @@ namespace Doctrine\Tests\DBAL\Functional\Schema; +use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\Schema; use Doctrine\DBAL\Schema\Table; +use Doctrine\DBAL\Types\BlobType; use Doctrine\DBAL\Types\Type; use SQLite3; use function array_map; @@ -20,16 +22,16 @@ class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase */ public function testListDatabases() { - $this->_sm->listDatabases(); + $this->schemaManager->listDatabases(); } public function testCreateAndDropDatabase() { $path = dirname(__FILE__) . '/test_create_and_drop_sqlite_database.sqlite'; - $this->_sm->createDatabase($path); + $this->schemaManager->createDatabase($path); self::assertFileExists($path); - $this->_sm->dropDatabase($path); + $this->schemaManager->dropDatabase($path); self::assertFileNotExists($path); } @@ -38,21 +40,21 @@ public function testCreateAndDropDatabase() */ public function testDropsDatabaseWithActiveConnections() { - $this->_sm->dropAndCreateDatabase('test_drop_database'); + $this->schemaManager->dropAndCreateDatabase('test_drop_database'); self::assertFileExists('test_drop_database'); - $params = $this->_conn->getParams(); + $params = $this->connection->getParams(); $params['dbname'] = 'test_drop_database'; $user = $params['user'] ?? null; $password = $params['password'] ?? null; - $connection = $this->_conn->getDriver()->connect($params, $user, $password); + $connection = $this->connection->getDriver()->connect($params, $user, $password); - self::assertInstanceOf('Doctrine\DBAL\Driver\Connection', $connection); + self::assertInstanceOf(Connection::class, $connection); - $this->_sm->dropDatabase('test_drop_database'); + $this->schemaManager->dropDatabase('test_drop_database'); self::assertFileNotExists('test_drop_database'); @@ -62,9 +64,9 @@ public function testDropsDatabaseWithActiveConnections() public function testRenameTable() { $this->createTestTable('oldname'); - $this->_sm->renameTable('oldname', 'newname'); + $this->schemaManager->renameTable('oldname', 'newname'); - $tables = $this->_sm->listTableNames(); + $tables = $this->schemaManager->listTableNames(); self::assertContains('newname', $tables); self::assertNotContains('oldname', $tables); } @@ -79,7 +81,7 @@ public function createListTableColumns() public function testListForeignKeysFromExistingDatabase() { - $this->_conn->exec(<<connection->exec(<<_sm->listTableForeignKeys('user')); + self::assertEquals($expected, $this->schemaManager->listTableForeignKeys('user')); } public function testColumnCollation() @@ -124,9 +126,9 @@ public function testColumnCollation() $table->addColumn('text', 'text'); $table->addColumn('foo', 'text')->setPlatformOption('collation', 'BINARY'); $table->addColumn('bar', 'text')->setPlatformOption('collation', 'NOCASE'); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); - $columns = $this->_sm->listTableColumns('test_collation'); + $columns = $this->schemaManager->listTableColumns('test_collation'); self::assertArrayNotHasKey('collation', $columns['id']->getPlatformOptions()); self::assertEquals('BINARY', $columns['text']->getPlatformOption('collation')); @@ -144,14 +146,14 @@ public function testListTableWithBinary() $table->addColumn('column_binary', 'binary', ['fixed' => true]); $table->setPrimaryKey(['id']); - $this->_sm->createTable($table); + $this->schemaManager->createTable($table); - $table = $this->_sm->listTableDetails($tableName); + $table = $this->schemaManager->listTableDetails($tableName); - self::assertInstanceOf('Doctrine\DBAL\Types\BlobType', $table->getColumn('column_varbinary')->getType()); + self::assertInstanceOf(BlobType::class, $table->getColumn('column_varbinary')->getType()); self::assertFalse($table->getColumn('column_varbinary')->getFixed()); - self::assertInstanceOf('Doctrine\DBAL\Types\BlobType', $table->getColumn('column_binary')->getType()); + self::assertInstanceOf(BlobType::class, $table->getColumn('column_binary')->getType()); self::assertFalse($table->getColumn('column_binary')->getFixed()); } @@ -165,7 +167,7 @@ public function testNonDefaultPKOrder() if (version_compare($version['versionString'], '3.7.16', '<')) { $this->markTestSkipped('This version of sqlite doesn\'t return the order of the Primary Key.'); } - $this->_conn->exec(<<connection->exec(<<_sm->listTableIndexes('non_default_pk_order'); + $tableIndexes = $this->schemaManager->listTableIndexes('non_default_pk_order'); self::assertCount(1, $tableIndexes); @@ -194,9 +196,9 @@ public function testListTableColumnsWithWhitespacesInTypeDeclarations() ) SQL; - $this->_conn->exec($sql); + $this->connection->exec($sql); - $columns = $this->_sm->listTableColumns('dbal_1779'); + $columns = $this->schemaManager->listTableColumns('dbal_1779'); self::assertCount(2, $columns); @@ -222,21 +224,21 @@ public function testDiffListIntegerAutoincrementTableColumns($integerType, $unsi $offlineTable->addColumn('id', $integerType, ['autoincrement' => true, 'unsigned' => $unsigned]); $offlineTable->setPrimaryKey(['id']); - $this->_sm->dropAndCreateTable($offlineTable); + $this->schemaManager->dropAndCreateTable($offlineTable); - $onlineTable = $this->_sm->listTableDetails($tableName); + $onlineTable = $this->schemaManager->listTableDetails($tableName); $comparator = new Schema\Comparator(); $diff = $comparator->diffTable($offlineTable, $onlineTable); if ($expectedComparatorDiff) { - self::assertEmpty($this->_sm->getDatabasePlatform()->getAlterTableSQL($diff)); + self::assertEmpty($this->schemaManager->getDatabasePlatform()->getAlterTableSQL($diff)); } else { self::assertFalse($diff); } } /** - * @return array + * @return mixed[][] */ public function getDiffListIntegerAutoincrementTableColumnsData() { @@ -259,15 +261,15 @@ public function testPrimaryKeyNoAutoIncrement() $table->addColumn('id', 'integer'); $table->addColumn('text', 'text'); $table->setPrimaryKey(['id']); - $this->_sm->dropAndCreateTable($table); + $this->schemaManager->dropAndCreateTable($table); - $this->_conn->insert('test_pk_auto_increment', ['text' => '1']); + $this->connection->insert('test_pk_auto_increment', ['text' => '1']); - $this->_conn->query('DELETE FROM test_pk_auto_increment'); + $this->connection->query('DELETE FROM test_pk_auto_increment'); - $this->_conn->insert('test_pk_auto_increment', ['text' => '2']); + $this->connection->insert('test_pk_auto_increment', ['text' => '2']); - $query = $this->_conn->query('SELECT id FROM test_pk_auto_increment WHERE text = "2"'); + $query = $this->connection->query('SELECT id FROM test_pk_auto_increment WHERE text = "2"'); $query->execute(); $lastUsedIdAfterDelete = (int) $query->fetchColumn(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/StatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/StatementTest.php index 7c8585c3f77..7aa374b461b 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/StatementTest.php @@ -20,15 +20,15 @@ protected function setUp() $table = new Table('stmt_test'); $table->addColumn('id', 'integer'); $table->addColumn('name', 'text', ['notnull' => false]); - $this->_conn->getSchemaManager()->dropAndCreateTable($table); + $this->connection->getSchemaManager()->dropAndCreateTable($table); } public function testStatementIsReusableAfterClosingCursor() { - $this->_conn->insert('stmt_test', ['id' => 1]); - $this->_conn->insert('stmt_test', ['id' => 2]); + $this->connection->insert('stmt_test', ['id' => 1]); + $this->connection->insert('stmt_test', ['id' => 2]); - $stmt = $this->_conn->prepare('SELECT id FROM stmt_test ORDER BY id'); + $stmt = $this->connection->prepare('SELECT id FROM stmt_test ORDER BY id'); $stmt->execute(); @@ -46,7 +46,7 @@ public function testStatementIsReusableAfterClosingCursor() public function testReuseStatementWithLongerResults() { - $sm = $this->_conn->getSchemaManager(); + $sm = $this->connection->getSchemaManager(); $table = new Table('stmt_longer_results'); $table->addColumn('param', 'string'); $table->addColumn('val', 'text'); @@ -56,9 +56,9 @@ public function testReuseStatementWithLongerResults() 'param' => 'param1', 'val' => 'X', ]; - $this->_conn->insert('stmt_longer_results', $row1); + $this->connection->insert('stmt_longer_results', $row1); - $stmt = $this->_conn->prepare('SELECT param, val FROM stmt_longer_results ORDER BY param'); + $stmt = $this->connection->prepare('SELECT param, val FROM stmt_longer_results ORDER BY param'); $stmt->execute(); self::assertArraySubset([ ['param1', 'X'], @@ -68,7 +68,7 @@ public function testReuseStatementWithLongerResults() 'param' => 'param2', 'val' => 'A bit longer value', ]; - $this->_conn->insert('stmt_longer_results', $row2); + $this->connection->insert('stmt_longer_results', $row2); $stmt->execute(); self::assertArraySubset([ @@ -83,7 +83,7 @@ public function testFetchLongBlob() // but is still not enough to store a LONGBLOB of the max possible size $this->iniSet('memory_limit', '4G'); - $sm = $this->_conn->getSchemaManager(); + $sm = $this->connection->getSchemaManager(); $table = new Table('stmt_long_blob'); $table->addColumn('contents', 'blob', ['length' => 0xFFFFFFFF]); $sm->createTable($table); @@ -105,15 +105,15 @@ public function testFetchLongBlob() EOF ); - $this->_conn->insert('stmt_long_blob', ['contents' => $contents], [ParameterType::LARGE_OBJECT]); + $this->connection->insert('stmt_long_blob', ['contents' => $contents], [ParameterType::LARGE_OBJECT]); - $stmt = $this->_conn->prepare('SELECT contents FROM stmt_long_blob'); + $stmt = $this->connection->prepare('SELECT contents FROM stmt_long_blob'); $stmt->execute(); $stream = Type::getType('blob') ->convertToPHPValue( $stmt->fetchColumn(), - $this->_conn->getDatabasePlatform() + $this->connection->getDatabasePlatform() ); self::assertSame($contents, stream_get_contents($stream)); @@ -121,27 +121,27 @@ public function testFetchLongBlob() public function testIncompletelyFetchedStatementDoesNotBlockConnection() { - $this->_conn->insert('stmt_test', ['id' => 1]); - $this->_conn->insert('stmt_test', ['id' => 2]); + $this->connection->insert('stmt_test', ['id' => 1]); + $this->connection->insert('stmt_test', ['id' => 2]); - $stmt1 = $this->_conn->prepare('SELECT id FROM stmt_test'); + $stmt1 = $this->connection->prepare('SELECT id FROM stmt_test'); $stmt1->execute(); $stmt1->fetch(); $stmt1->execute(); // fetching only one record out of two $stmt1->fetch(); - $stmt2 = $this->_conn->prepare('SELECT id FROM stmt_test WHERE id = ?'); + $stmt2 = $this->connection->prepare('SELECT id FROM stmt_test WHERE id = ?'); $stmt2->execute([1]); self::assertEquals(1, $stmt2->fetchColumn()); } public function testReuseStatementAfterClosingCursor() { - $this->_conn->insert('stmt_test', ['id' => 1]); - $this->_conn->insert('stmt_test', ['id' => 2]); + $this->connection->insert('stmt_test', ['id' => 1]); + $this->connection->insert('stmt_test', ['id' => 2]); - $stmt = $this->_conn->prepare('SELECT id FROM stmt_test WHERE id = ?'); + $stmt = $this->connection->prepare('SELECT id FROM stmt_test WHERE id = ?'); $stmt->execute([1]); $id = $stmt->fetchColumn(); @@ -156,10 +156,10 @@ public function testReuseStatementAfterClosingCursor() public function testReuseStatementWithParameterBoundByReference() { - $this->_conn->insert('stmt_test', ['id' => 1]); - $this->_conn->insert('stmt_test', ['id' => 2]); + $this->connection->insert('stmt_test', ['id' => 1]); + $this->connection->insert('stmt_test', ['id' => 2]); - $stmt = $this->_conn->prepare('SELECT id FROM stmt_test WHERE id = ?'); + $stmt = $this->connection->prepare('SELECT id FROM stmt_test WHERE id = ?'); $stmt->bindParam(1, $id); $id = 1; @@ -173,10 +173,10 @@ public function testReuseStatementWithParameterBoundByReference() public function testReuseStatementWithReboundValue() { - $this->_conn->insert('stmt_test', ['id' => 1]); - $this->_conn->insert('stmt_test', ['id' => 2]); + $this->connection->insert('stmt_test', ['id' => 1]); + $this->connection->insert('stmt_test', ['id' => 2]); - $stmt = $this->_conn->prepare('SELECT id FROM stmt_test WHERE id = ?'); + $stmt = $this->connection->prepare('SELECT id FROM stmt_test WHERE id = ?'); $stmt->bindValue(1, 1); $stmt->execute(); @@ -189,10 +189,10 @@ public function testReuseStatementWithReboundValue() public function testReuseStatementWithReboundParam() { - $this->_conn->insert('stmt_test', ['id' => 1]); - $this->_conn->insert('stmt_test', ['id' => 2]); + $this->connection->insert('stmt_test', ['id' => 1]); + $this->connection->insert('stmt_test', ['id' => 2]); - $stmt = $this->_conn->prepare('SELECT id FROM stmt_test WHERE id = ?'); + $stmt = $this->connection->prepare('SELECT id FROM stmt_test WHERE id = ?'); $x = 1; $stmt->bindParam(1, $x); @@ -210,14 +210,14 @@ public function testReuseStatementWithReboundParam() */ public function testFetchFromNonExecutedStatement(callable $fetch, $expected) { - $stmt = $this->_conn->prepare('SELECT id FROM stmt_test'); + $stmt = $this->connection->prepare('SELECT id FROM stmt_test'); self::assertSame($expected, $fetch($stmt)); } public function testCloseCursorOnNonExecutedStatement() { - $stmt = $this->_conn->prepare('SELECT id FROM stmt_test'); + $stmt = $this->connection->prepare('SELECT id FROM stmt_test'); self::assertTrue($stmt->closeCursor()); } @@ -227,7 +227,7 @@ public function testCloseCursorOnNonExecutedStatement() */ public function testCloseCursorAfterCursorEnd() { - $stmt = $this->_conn->prepare('SELECT name FROM stmt_test'); + $stmt = $this->connection->prepare('SELECT name FROM stmt_test'); $stmt->execute(); $stmt->fetch(); @@ -240,7 +240,7 @@ public function testCloseCursorAfterCursorEnd() */ public function testFetchFromNonExecutedStatementWithClosedCursor(callable $fetch, $expected) { - $stmt = $this->_conn->prepare('SELECT id FROM stmt_test'); + $stmt = $this->connection->prepare('SELECT id FROM stmt_test'); $stmt->closeCursor(); self::assertSame($expected, $fetch($stmt)); @@ -251,9 +251,9 @@ public function testFetchFromNonExecutedStatementWithClosedCursor(callable $fetc */ public function testFetchFromExecutedStatementWithClosedCursor(callable $fetch, $expected) { - $this->_conn->insert('stmt_test', ['id' => 1]); + $this->connection->insert('stmt_test', ['id' => 1]); - $stmt = $this->_conn->prepare('SELECT id FROM stmt_test'); + $stmt = $this->connection->prepare('SELECT id FROM stmt_test'); $stmt->execute(); $stmt->closeCursor(); @@ -286,9 +286,9 @@ static function (Statement $stmt) { public function testFetchInColumnMode() : void { - $platform = $this->_conn->getDatabasePlatform(); + $platform = $this->connection->getDatabasePlatform(); $query = $platform->getDummySelectSQL(); - $result = $this->_conn->executeQuery($query)->fetch(FetchMode::COLUMN); + $result = $this->connection->executeQuery($query)->fetch(FetchMode::COLUMN); self::assertEquals(1, $result); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/TableGeneratorTest.php b/tests/Doctrine/Tests/DBAL/Functional/TableGeneratorTest.php index 182a337f295..f62b992015c 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/TableGeneratorTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/TableGeneratorTest.php @@ -20,7 +20,7 @@ protected function setUp() { parent::setUp(); - $platform = $this->_conn->getDatabasePlatform(); + $platform = $this->connection->getDatabasePlatform(); if ($platform->getName() === 'sqlite') { $this->markTestSkipped('TableGenerator does not work with SQLite'); } @@ -31,11 +31,11 @@ protected function setUp() $schema->visit($visitor); foreach ($schema->toSql($platform) as $sql) { - $this->_conn->exec($sql); + $this->connection->exec($sql); } } catch (Throwable $e) { } - $this->generator = new TableGenerator($this->_conn); + $this->generator = new TableGenerator($this->connection); } public function testNextVal() @@ -51,9 +51,9 @@ public function testNextVal() public function testNextValNotAffectedByOuterTransactions() { - $this->_conn->beginTransaction(); + $this->connection->beginTransaction(); $id1 = $this->generator->nextValue('tbl1'); - $this->_conn->rollBack(); + $this->connection->rollBack(); $id2 = $this->generator->nextValue('tbl1'); self::assertGreaterThan(0, $id1, 'First id has to be larger than 0'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/TemporaryTableTest.php b/tests/Doctrine/Tests/DBAL/Functional/TemporaryTableTest.php index 5ef755ee4da..87a776c7e06 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/TemporaryTableTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/TemporaryTableTest.php @@ -13,17 +13,17 @@ protected function setUp() { parent::setUp(); try { - $this->_conn->exec($this->_conn->getDatabasePlatform()->getDropTableSQL('nontemporary')); + $this->connection->exec($this->connection->getDatabasePlatform()->getDropTableSQL('nontemporary')); } catch (Throwable $e) { } } protected function tearDown() { - if ($this->_conn) { + if ($this->connection) { try { - $tempTable = $this->_conn->getDatabasePlatform()->getTemporaryTableName('my_temporary'); - $this->_conn->exec($this->_conn->getDatabasePlatform()->getDropTemporaryTableSQL($tempTable)); + $tempTable = $this->connection->getDatabasePlatform()->getTemporaryTableName('my_temporary'); + $this->connection->exec($this->connection->getDatabasePlatform()->getDropTemporaryTableSQL($tempTable)); } catch (Throwable $e) { } } @@ -38,33 +38,33 @@ protected function tearDown() */ public function testDropTemporaryTableNotAutoCommitTransaction() { - if ($this->_conn->getDatabasePlatform()->getName() === 'sqlanywhere' || - $this->_conn->getDatabasePlatform()->getName() === 'oracle') { + if ($this->connection->getDatabasePlatform()->getName() === 'sqlanywhere' || + $this->connection->getDatabasePlatform()->getName() === 'oracle') { $this->markTestSkipped('Test does not work on Oracle and SQL Anywhere.'); } - $platform = $this->_conn->getDatabasePlatform(); + $platform = $this->connection->getDatabasePlatform(); $columnDefinitions = ['id' => ['type' => Type::getType('integer'), 'notnull' => true]]; $tempTable = $platform->getTemporaryTableName('my_temporary'); $createTempTableSQL = $platform->getCreateTemporaryTableSnippetSQL() . ' ' . $tempTable . ' (' . $platform->getColumnDeclarationListSQL($columnDefinitions) . ')'; - $this->_conn->executeUpdate($createTempTableSQL); + $this->connection->executeUpdate($createTempTableSQL); $table = new Table('nontemporary'); $table->addColumn('id', 'integer'); $table->setPrimaryKey(['id']); - $this->_conn->getSchemaManager()->createTable($table); + $this->connection->getSchemaManager()->createTable($table); - $this->_conn->beginTransaction(); - $this->_conn->insert('nontemporary', ['id' => 1]); - $this->_conn->exec($platform->getDropTemporaryTableSQL($tempTable)); - $this->_conn->insert('nontemporary', ['id' => 2]); + $this->connection->beginTransaction(); + $this->connection->insert('nontemporary', ['id' => 1]); + $this->connection->exec($platform->getDropTemporaryTableSQL($tempTable)); + $this->connection->insert('nontemporary', ['id' => 2]); - $this->_conn->rollBack(); + $this->connection->rollBack(); - $rows = $this->_conn->fetchAll('SELECT * FROM nontemporary'); + $rows = $this->connection->fetchAll('SELECT * FROM nontemporary'); self::assertEquals([], $rows, 'In an event of an error this result has one row, because of an implicit commit.'); } @@ -75,12 +75,12 @@ public function testDropTemporaryTableNotAutoCommitTransaction() */ public function testCreateTemporaryTableNotAutoCommitTransaction() { - if ($this->_conn->getDatabasePlatform()->getName() === 'sqlanywhere' || - $this->_conn->getDatabasePlatform()->getName() === 'oracle') { + if ($this->connection->getDatabasePlatform()->getName() === 'sqlanywhere' || + $this->connection->getDatabasePlatform()->getName() === 'oracle') { $this->markTestSkipped('Test does not work on Oracle and SQL Anywhere.'); } - $platform = $this->_conn->getDatabasePlatform(); + $platform = $this->connection->getDatabasePlatform(); $columnDefinitions = ['id' => ['type' => Type::getType('integer'), 'notnull' => true]]; $tempTable = $platform->getTemporaryTableName('my_temporary'); @@ -91,22 +91,22 @@ public function testCreateTemporaryTableNotAutoCommitTransaction() $table->addColumn('id', 'integer'); $table->setPrimaryKey(['id']); - $this->_conn->getSchemaManager()->createTable($table); + $this->connection->getSchemaManager()->createTable($table); - $this->_conn->beginTransaction(); - $this->_conn->insert('nontemporary', ['id' => 1]); + $this->connection->beginTransaction(); + $this->connection->insert('nontemporary', ['id' => 1]); - $this->_conn->exec($createTempTableSQL); - $this->_conn->insert('nontemporary', ['id' => 2]); + $this->connection->exec($createTempTableSQL); + $this->connection->insert('nontemporary', ['id' => 2]); - $this->_conn->rollBack(); + $this->connection->rollBack(); try { - $this->_conn->exec($platform->getDropTemporaryTableSQL($tempTable)); + $this->connection->exec($platform->getDropTemporaryTableSQL($tempTable)); } catch (Throwable $e) { } - $rows = $this->_conn->fetchAll('SELECT * FROM nontemporary'); + $rows = $this->connection->fetchAll('SELECT * FROM nontemporary'); self::assertEquals([], $rows, 'In an event of an error this result has one row, because of an implicit commit.'); } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL168Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL168Test.php index b43da19b52d..b18b6cbdaf5 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL168Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL168Test.php @@ -12,7 +12,7 @@ class DBAL168Test extends DbalFunctionalTestCase { public function testDomainsTable() { - if ($this->_conn->getDatabasePlatform()->getName() !== 'postgresql') { + if ($this->connection->getDatabasePlatform()->getName() !== 'postgresql') { $this->markTestSkipped('PostgreSQL only test'); } @@ -22,8 +22,8 @@ public function testDomainsTable() $table->setPrimaryKey(['id']); $table->addForeignKeyConstraint('domains', ['parent_id'], ['id']); - $this->_conn->getSchemaManager()->createTable($table); - $table = $this->_conn->getSchemaManager()->listTableDetails('domains'); + $this->connection->getSchemaManager()->createTable($table); + $table = $this->connection->getSchemaManager()->listTableDetails('domains'); self::assertEquals('domains', $table->getName()); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL202Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL202Test.php index 63d93ffafa7..1adf993250f 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL202Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL202Test.php @@ -14,38 +14,38 @@ protected function setUp() { parent::setUp(); - if ($this->_conn->getDatabasePlatform()->getName() !== 'oracle') { + if ($this->connection->getDatabasePlatform()->getName() !== 'oracle') { $this->markTestSkipped('OCI8 only test'); } - if ($this->_conn->getSchemaManager()->tablesExist('DBAL202')) { - $this->_conn->exec('DELETE FROM DBAL202'); + if ($this->connection->getSchemaManager()->tablesExist('DBAL202')) { + $this->connection->exec('DELETE FROM DBAL202'); } else { $table = new Table('DBAL202'); $table->addColumn('id', 'integer'); $table->setPrimaryKey(['id']); - $this->_conn->getSchemaManager()->createTable($table); + $this->connection->getSchemaManager()->createTable($table); } } public function testStatementRollback() { - $stmt = $this->_conn->prepare('INSERT INTO DBAL202 VALUES (8)'); - $this->_conn->beginTransaction(); + $stmt = $this->connection->prepare('INSERT INTO DBAL202 VALUES (8)'); + $this->connection->beginTransaction(); $stmt->execute(); - $this->_conn->rollBack(); + $this->connection->rollBack(); - self::assertEquals(0, $this->_conn->query('SELECT COUNT(1) FROM DBAL202')->fetchColumn()); + self::assertEquals(0, $this->connection->query('SELECT COUNT(1) FROM DBAL202')->fetchColumn()); } public function testStatementCommit() { - $stmt = $this->_conn->prepare('INSERT INTO DBAL202 VALUES (8)'); - $this->_conn->beginTransaction(); + $stmt = $this->connection->prepare('INSERT INTO DBAL202 VALUES (8)'); + $this->connection->beginTransaction(); $stmt->execute(); - $this->_conn->commit(); + $this->connection->commit(); - self::assertEquals(1, $this->_conn->query('SELECT COUNT(1) FROM DBAL202')->fetchColumn()); + self::assertEquals(1, $this->connection->query('SELECT COUNT(1) FROM DBAL202')->fetchColumn()); } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php index b44e7542489..af41670690a 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php @@ -15,7 +15,7 @@ protected function setUp() { parent::setUp(); - $platform = $this->_conn->getDatabasePlatform()->getName(); + $platform = $this->connection->getDatabasePlatform()->getName(); if (in_array($platform, ['mysql', 'sqlite'])) { return; } @@ -25,7 +25,7 @@ protected function setUp() public function testGuidShouldMatchPattern() { - $guid = $this->_conn->query($this->getSelectGuidSql())->fetchColumn(); + $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'; self::assertEquals(1, preg_match($pattern, $guid), 'GUID does not match pattern'); } @@ -36,7 +36,7 @@ public function testGuidShouldMatchPattern() */ public function testGuidShouldBeRandom() { - $statement = $this->_conn->prepare($this->getSelectGuidSql()); + $statement = $this->connection->prepare($this->getSelectGuidSql()); $guids = []; for ($i = 0; $i < 99; $i++) { @@ -51,6 +51,6 @@ public function testGuidShouldBeRandom() private function getSelectGuidSql() { - return 'SELECT ' . $this->_conn->getDatabasePlatform()->getGuidExpression(); + 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 2298898d74d..a9dbdb1e109 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL461Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL461Test.php @@ -2,6 +2,8 @@ namespace Doctrine\Tests\DBAL\Functional\Ticket; +use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\SQLServerSchemaManager; use Doctrine\DBAL\Types\DecimalType; use PHPUnit\Framework\TestCase; @@ -14,8 +16,8 @@ class DBAL461Test extends TestCase { public function testIssue() { - $conn = $this->createMock('Doctrine\DBAL\Connection'); - $platform = $this->getMockForAbstractClass('Doctrine\DBAL\Platforms\AbstractPlatform'); + $conn = $this->createMock(Connection::class); + $platform = $this->getMockForAbstractClass(AbstractPlatform::class); $platform->registerDoctrineTypeMapping('numeric', 'decimal'); $schemaManager = new SQLServerSchemaManager($conn, $platform); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL510Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL510Test.php index 208db06d19b..fa98ecb3eca 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL510Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL510Test.php @@ -15,7 +15,7 @@ protected function setUp() { parent::setUp(); - if ($this->_conn->getDatabasePlatform()->getName() === 'postgresql') { + if ($this->connection->getDatabasePlatform()->getName() === 'postgresql') { return; } @@ -28,9 +28,9 @@ public function testSearchPathSchemaChanges() $table->addColumn('id', 'integer'); $table->setPrimaryKey(['id']); - $this->_conn->getSchemaManager()->createTable($table); + $this->connection->getSchemaManager()->createTable($table); - $onlineTable = $this->_conn->getSchemaManager()->listTableDetails('dbal510tbl'); + $onlineTable = $this->connection->getSchemaManager()->listTableDetails('dbal510tbl'); $comparator = new Comparator(); $diff = $comparator->diffTable($onlineTable, $table); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php index 0709ffd5632..827a9124277 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php @@ -20,15 +20,15 @@ protected function setUp() { parent::setUp(); - $platform = $this->_conn->getDatabasePlatform()->getName(); + $platform = $this->connection->getDatabasePlatform()->getName(); if (! in_array($platform, ['postgresql'])) { $this->markTestSkipped('Currently restricted to PostgreSQL'); } try { - $this->_conn->exec('CREATE TABLE dbal630 (id SERIAL, bool_col BOOLEAN NOT NULL);'); - $this->_conn->exec('CREATE TABLE dbal630_allow_nulls (id SERIAL, bool_col BOOLEAN);'); + $this->connection->exec('CREATE TABLE dbal630 (id SERIAL, bool_col BOOLEAN NOT NULL);'); + $this->connection->exec('CREATE TABLE dbal630_allow_nulls (id SERIAL, bool_col BOOLEAN);'); } catch (DBALException $e) { } $this->running = true; @@ -37,7 +37,7 @@ protected function setUp() protected function tearDown() { if ($this->running) { - $this->_conn->getWrappedConnection()->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); + $this->connection->getWrappedConnection()->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); } parent::tearDown(); @@ -45,45 +45,45 @@ protected function tearDown() public function testBooleanConversionSqlLiteral() { - $this->_conn->executeUpdate('INSERT INTO dbal630 (bool_col) VALUES(false)'); - $id = $this->_conn->lastInsertId('dbal630_id_seq'); + $this->connection->executeUpdate('INSERT INTO dbal630 (bool_col) VALUES(false)'); + $id = $this->connection->lastInsertId('dbal630_id_seq'); self::assertNotEmpty($id); - $row = $this->_conn->fetchAssoc('SELECT bool_col FROM dbal630 WHERE id = ?', [$id]); + $row = $this->connection->fetchAssoc('SELECT bool_col FROM dbal630 WHERE id = ?', [$id]); self::assertFalse($row['bool_col']); } public function testBooleanConversionBoolParamRealPrepares() { - $this->_conn->executeUpdate( + $this->connection->executeUpdate( 'INSERT INTO dbal630 (bool_col) VALUES(?)', ['false'], [ParameterType::BOOLEAN] ); - $id = $this->_conn->lastInsertId('dbal630_id_seq'); + $id = $this->connection->lastInsertId('dbal630_id_seq'); self::assertNotEmpty($id); - $row = $this->_conn->fetchAssoc('SELECT bool_col FROM dbal630 WHERE id = ?', [$id]); + $row = $this->connection->fetchAssoc('SELECT bool_col FROM dbal630 WHERE id = ?', [$id]); self::assertFalse($row['bool_col']); } public function testBooleanConversionBoolParamEmulatedPrepares() { - $this->_conn->getWrappedConnection()->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); + $this->connection->getWrappedConnection()->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); - $platform = $this->_conn->getDatabasePlatform(); + $platform = $this->connection->getDatabasePlatform(); - $stmt = $this->_conn->prepare('INSERT INTO dbal630 (bool_col) VALUES(?)'); + $stmt = $this->connection->prepare('INSERT INTO dbal630 (bool_col) VALUES(?)'); $stmt->bindValue(1, $platform->convertBooleansToDatabaseValue('false'), ParameterType::BOOLEAN); $stmt->execute(); - $id = $this->_conn->lastInsertId('dbal630_id_seq'); + $id = $this->connection->lastInsertId('dbal630_id_seq'); self::assertNotEmpty($id); - $row = $this->_conn->fetchAssoc('SELECT bool_col FROM dbal630 WHERE id = ?', [$id]); + $row = $this->connection->fetchAssoc('SELECT bool_col FROM dbal630 WHERE id = ?', [$id]); self::assertFalse($row['bool_col']); } @@ -95,19 +95,19 @@ public function testBooleanConversionNullParamEmulatedPrepares( $statementValue, $databaseConvertedValue ) { - $this->_conn->getWrappedConnection()->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); + $this->connection->getWrappedConnection()->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); - $platform = $this->_conn->getDatabasePlatform(); + $platform = $this->connection->getDatabasePlatform(); - $stmt = $this->_conn->prepare('INSERT INTO dbal630_allow_nulls (bool_col) VALUES(?)'); + $stmt = $this->connection->prepare('INSERT INTO dbal630_allow_nulls (bool_col) VALUES(?)'); $stmt->bindValue(1, $platform->convertBooleansToDatabaseValue($statementValue)); $stmt->execute(); - $id = $this->_conn->lastInsertId('dbal630_allow_nulls_id_seq'); + $id = $this->connection->lastInsertId('dbal630_allow_nulls_id_seq'); self::assertNotEmpty($id); - $row = $this->_conn->fetchAssoc('SELECT bool_col FROM dbal630_allow_nulls WHERE id = ?', [$id]); + $row = $this->connection->fetchAssoc('SELECT bool_col FROM dbal630_allow_nulls WHERE id = ?', [$id]); self::assertSame($databaseConvertedValue, $row['bool_col']); } @@ -119,11 +119,11 @@ public function testBooleanConversionNullParamEmulatedPreparesWithBooleanTypeInB $statementValue, $databaseConvertedValue ) { - $this->_conn->getWrappedConnection()->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); + $this->connection->getWrappedConnection()->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); - $platform = $this->_conn->getDatabasePlatform(); + $platform = $this->connection->getDatabasePlatform(); - $stmt = $this->_conn->prepare('INSERT INTO dbal630_allow_nulls (bool_col) VALUES(?)'); + $stmt = $this->connection->prepare('INSERT INTO dbal630_allow_nulls (bool_col) VALUES(?)'); $stmt->bindValue( 1, $platform->convertBooleansToDatabaseValue($statementValue), @@ -131,11 +131,11 @@ public function testBooleanConversionNullParamEmulatedPreparesWithBooleanTypeInB ); $stmt->execute(); - $id = $this->_conn->lastInsertId('dbal630_allow_nulls_id_seq'); + $id = $this->connection->lastInsertId('dbal630_allow_nulls_id_seq'); self::assertNotEmpty($id); - $row = $this->_conn->fetchAssoc('SELECT bool_col FROM dbal630_allow_nulls WHERE id = ?', [$id]); + $row = $this->connection->fetchAssoc('SELECT bool_col FROM dbal630_allow_nulls WHERE id = ?', [$id]); self::assertSame($databaseConvertedValue, $row['bool_col']); } @@ -143,7 +143,7 @@ public function testBooleanConversionNullParamEmulatedPreparesWithBooleanTypeInB /** * Boolean conversion mapping provider * - * @return array + * @return mixed[][] */ public function booleanTypeConversionUsingBooleanTypeProvider() { @@ -158,7 +158,7 @@ public function booleanTypeConversionUsingBooleanTypeProvider() /** * Boolean conversion mapping provider * - * @return array + * @return mixed[][] */ public function booleanTypeConversionWithoutPdoTypeProvider() { diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL752Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL752Test.php index 393e3457eed..ee0bce44e08 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL752Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL752Test.php @@ -14,7 +14,7 @@ protected function setUp() { parent::setUp(); - $platform = $this->_conn->getDatabasePlatform()->getName(); + $platform = $this->connection->getDatabasePlatform()->getName(); if (in_array($platform, ['sqlite'])) { return; @@ -25,7 +25,7 @@ protected function setUp() public function testUnsignedIntegerDetection() { - $this->_conn->exec(<<connection->exec(<<_conn->getSchemaManager(); + $schemaManager = $this->connection->getSchemaManager(); $fetchedTable = $schemaManager->listTableDetails('dbal752_unsigneds'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php b/tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php index 289d5c7fd9a..333e7364088 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php @@ -21,7 +21,7 @@ protected function setUp() parent::setUp(); /** @var AbstractSchemaManager $sm */ - $sm = $this->_conn->getSchemaManager(); + $sm = $this->connection->getSchemaManager(); $table = new Table('type_conversion'); $table->addColumn('id', 'integer', ['notnull' => false]); @@ -42,7 +42,7 @@ protected function setUp() $table->setPrimaryKey(['id']); try { - $this->_conn->getSchemaManager()->createTable($table); + $this->connection->getSchemaManager()->createTable($table); } catch (Throwable $e) { } } @@ -83,12 +83,12 @@ public function testIdempotentDataConversion($type, $originalValue, $expectedPhp { $columnName = 'test_' . $type; $typeInstance = Type::getType($type); - $insertionValue = $typeInstance->convertToDatabaseValue($originalValue, $this->_conn->getDatabasePlatform()); + $insertionValue = $typeInstance->convertToDatabaseValue($originalValue, $this->connection->getDatabasePlatform()); - $this->_conn->insert('type_conversion', ['id' => ++self::$typeCounter, $columnName => $insertionValue]); + $this->connection->insert('type_conversion', ['id' => ++self::$typeCounter, $columnName => $insertionValue]); $sql = 'SELECT ' . $columnName . ' FROM type_conversion WHERE id = ' . self::$typeCounter; - $actualDbValue = $typeInstance->convertToPHPValue($this->_conn->fetchColumn($sql), $this->_conn->getDatabasePlatform()); + $actualDbValue = $typeInstance->convertToPHPValue($this->connection->fetchColumn($sql), $this->connection->getDatabasePlatform()); if ($originalValue instanceof DateTime) { self::assertInstanceOf($expectedPhpType, $actualDbValue, 'The expected type from the conversion to and back from the database should be ' . $expectedPhpType); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Types/BinaryTest.php b/tests/Doctrine/Tests/DBAL/Functional/Types/BinaryTest.php index f4e6ff1a84d..d17d5250072 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Types/BinaryTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Types/BinaryTest.php @@ -27,7 +27,7 @@ protected function setUp() $table->addColumn('val', 'binary', ['length' => 64]); $table->setPrimaryKey(['id']); - $sm = $this->_conn->getSchemaManager(); + $sm = $this->connection->getSchemaManager(); $sm->dropAndCreateTable($table); } @@ -40,7 +40,7 @@ public function testInsertAndSelect() $value2 = random_bytes(64); /** @see https://bugs.php.net/bug.php?id=76322 */ - if ($this->_conn->getDriver() instanceof DB2Driver) { + if ($this->connection->getDriver() instanceof DB2Driver) { $value1 = str_replace("\x00", "\xFF", $value1); $value2 = str_replace("\x00", "\xFF", $value2); } @@ -54,7 +54,7 @@ public function testInsertAndSelect() private function insert(string $id, string $value) : void { - $result = $this->_conn->insert('binary_table', [ + $result = $this->connection->insert('binary_table', [ 'id' => $id, 'val' => $value, ], [ @@ -67,7 +67,7 @@ private function insert(string $id, string $value) : void private function select(string $id) { - $value = $this->_conn->fetchColumn( + $value = $this->connection->fetchColumn( 'SELECT val FROM binary_table WHERE id = ?', [$id], 0, diff --git a/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php b/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php index 60c32fe9615..039fed14f8e 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php @@ -27,10 +27,10 @@ protected function setUp() $table->addColumn('test_string', 'string', ['notnull' => false]); $table->setPrimaryKey(['id']); - $this->_conn->getSchemaManager()->createTable($table); + $this->connection->getSchemaManager()->createTable($table); } catch (Throwable $e) { } - $this->_conn->executeUpdate('DELETE FROM write_table'); + $this->connection->executeUpdate('DELETE FROM write_table'); } /** @@ -39,16 +39,16 @@ protected function setUp() public function testExecuteUpdateFirstTypeIsNull() { $sql = 'INSERT INTO write_table (test_string, test_int) VALUES (?, ?)'; - $this->_conn->executeUpdate($sql, ['text', 1111], [null, ParameterType::INTEGER]); + $this->connection->executeUpdate($sql, ['text', 1111], [null, ParameterType::INTEGER]); $sql = 'SELECT * FROM write_table WHERE test_string = ? AND test_int = ?'; - self::assertTrue((bool) $this->_conn->fetchColumn($sql, ['text', 1111])); + self::assertTrue((bool) $this->connection->fetchColumn($sql, ['text', 1111])); } public function testExecuteUpdate() { - $sql = 'INSERT INTO write_table (test_int) VALUES ( ' . $this->_conn->quote(1) . ')'; - $affected = $this->_conn->executeUpdate($sql); + $sql = 'INSERT INTO write_table (test_int) VALUES ( ' . $this->connection->quote(1) . ')'; + $affected = $this->connection->executeUpdate($sql); self::assertEquals(1, $affected, 'executeUpdate() should return the number of affected rows!'); } @@ -56,7 +56,7 @@ public function testExecuteUpdate() public function testExecuteUpdateWithTypes() { $sql = 'INSERT INTO write_table (test_int, test_string) VALUES (?, ?)'; - $affected = $this->_conn->executeUpdate( + $affected = $this->connection->executeUpdate( $sql, [1, 'foo'], [ParameterType::INTEGER, ParameterType::STRING] @@ -68,7 +68,7 @@ public function testExecuteUpdateWithTypes() public function testPrepareRowCountReturnsAffectedRows() { $sql = 'INSERT INTO write_table (test_int, test_string) VALUES (?, ?)'; - $stmt = $this->_conn->prepare($sql); + $stmt = $this->connection->prepare($sql); $stmt->bindValue(1, 1); $stmt->bindValue(2, 'foo'); @@ -80,7 +80,7 @@ public function testPrepareRowCountReturnsAffectedRows() public function testPrepareWithPdoTypes() { $sql = 'INSERT INTO write_table (test_int, test_string) VALUES (?, ?)'; - $stmt = $this->_conn->prepare($sql); + $stmt = $this->connection->prepare($sql); $stmt->bindValue(1, 1, ParameterType::INTEGER); $stmt->bindValue(2, 'foo', ParameterType::STRING); @@ -92,7 +92,7 @@ public function testPrepareWithPdoTypes() public function testPrepareWithDbalTypes() { $sql = 'INSERT INTO write_table (test_int, test_string) VALUES (?, ?)'; - $stmt = $this->_conn->prepare($sql); + $stmt = $this->connection->prepare($sql); $stmt->bindValue(1, 1, Type::getType('integer')); $stmt->bindValue(2, 'foo', Type::getType('string')); @@ -104,7 +104,7 @@ public function testPrepareWithDbalTypes() public function testPrepareWithDbalTypeNames() { $sql = 'INSERT INTO write_table (test_int, test_string) VALUES (?, ?)'; - $stmt = $this->_conn->prepare($sql); + $stmt = $this->connection->prepare($sql); $stmt->bindValue(1, 1, 'integer'); $stmt->bindValue(2, 'foo', 'string'); @@ -115,8 +115,8 @@ public function testPrepareWithDbalTypeNames() public function insertRows() { - self::assertEquals(1, $this->_conn->insert('write_table', ['test_int' => 1, 'test_string' => 'foo'])); - self::assertEquals(1, $this->_conn->insert('write_table', ['test_int' => 2, 'test_string' => 'bar'])); + 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() @@ -128,30 +128,30 @@ public function testDelete() { $this->insertRows(); - self::assertEquals(1, $this->_conn->delete('write_table', ['test_int' => 2])); - self::assertCount(1, $this->_conn->fetchAll('SELECT * FROM write_table')); + self::assertEquals(1, $this->connection->delete('write_table', ['test_int' => 2])); + self::assertCount(1, $this->connection->fetchAll('SELECT * FROM write_table')); - self::assertEquals(1, $this->_conn->delete('write_table', ['test_int' => 1])); - self::assertCount(0, $this->_conn->fetchAll('SELECT * FROM write_table')); + self::assertEquals(1, $this->connection->delete('write_table', ['test_int' => 1])); + self::assertCount(0, $this->connection->fetchAll('SELECT * FROM write_table')); } public function testUpdate() { $this->insertRows(); - self::assertEquals(1, $this->_conn->update('write_table', ['test_string' => 'bar'], ['test_string' => 'foo'])); - self::assertEquals(2, $this->_conn->update('write_table', ['test_string' => 'baz'], ['test_string' => 'bar'])); - self::assertEquals(0, $this->_conn->update('write_table', ['test_string' => 'baz'], ['test_string' => 'bar'])); + self::assertEquals(1, $this->connection->update('write_table', ['test_string' => 'bar'], ['test_string' => 'foo'])); + self::assertEquals(2, $this->connection->update('write_table', ['test_string' => 'baz'], ['test_string' => 'bar'])); + self::assertEquals(0, $this->connection->update('write_table', ['test_string' => 'baz'], ['test_string' => 'bar'])); } public function testLastInsertId() { - if (! $this->_conn->getDatabasePlatform()->prefersIdentityColumns()) { + if (! $this->connection->getDatabasePlatform()->prefersIdentityColumns()) { $this->markTestSkipped('Test only works on platforms with identity columns.'); } - self::assertEquals(1, $this->_conn->insert('write_table', ['test_int' => 2, 'test_string' => 'bar'])); - $num = $this->_conn->lastInsertId(); + self::assertEquals(1, $this->connection->insert('write_table', ['test_int' => 2, 'test_string' => 'bar'])); + $num = $this->connection->lastInsertId(); self::assertNotNull($num, 'LastInsertId() should not be null.'); self::assertGreaterThan(0, $num, 'LastInsertId() should be non-negative number.'); @@ -159,25 +159,25 @@ public function testLastInsertId() public function testLastInsertIdSequence() { - if (! $this->_conn->getDatabasePlatform()->supportsSequences()) { + if (! $this->connection->getDatabasePlatform()->supportsSequences()) { $this->markTestSkipped('Test only works on platforms with sequences.'); } $sequence = new Sequence('write_table_id_seq'); try { - $this->_conn->getSchemaManager()->createSequence($sequence); + $this->connection->getSchemaManager()->createSequence($sequence); } catch (Throwable $e) { } - $sequences = $this->_conn->getSchemaManager()->listSequences(); + $sequences = $this->connection->getSchemaManager()->listSequences(); self::assertCount(1, array_filter($sequences, static function ($sequence) { return strtolower($sequence->getName()) === 'write_table_id_seq'; })); - $stmt = $this->_conn->query($this->_conn->getDatabasePlatform()->getSequenceNextValSQL('write_table_id_seq')); + $stmt = $this->connection->query($this->connection->getDatabasePlatform()->getSequenceNextValSQL('write_table_id_seq')); $nextSequenceVal = $stmt->fetchColumn(); - $lastInsertId = $this->_conn->lastInsertId('write_table_id_seq'); + $lastInsertId = $this->connection->lastInsertId('write_table_id_seq'); self::assertGreaterThan(0, $lastInsertId); self::assertEquals($nextSequenceVal, $lastInsertId); @@ -185,11 +185,11 @@ public function testLastInsertIdSequence() public function testLastInsertIdNoSequenceGiven() { - if (! $this->_conn->getDatabasePlatform()->supportsSequences() || $this->_conn->getDatabasePlatform()->supportsIdentityColumns()) { + 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."); } - self::assertFalse($this->_conn->lastInsertId(null)); + self::assertFalse($this->connection->lastInsertId(null)); } /** @@ -199,15 +199,15 @@ public function testInsertWithKeyValueTypes() { $testString = new DateTime('2013-04-14 10:10:10'); - $this->_conn->insert( + $this->connection->insert( 'write_table', ['test_int' => '30', 'test_string' => $testString], ['test_string' => 'datetime', 'test_int' => 'integer'] ); - $data = $this->_conn->fetchColumn('SELECT test_string FROM write_table WHERE test_int = 30'); + $data = $this->connection->fetchColumn('SELECT test_string FROM write_table WHERE test_int = 30'); - self::assertEquals($testString->format($this->_conn->getDatabasePlatform()->getDateTimeFormatString()), $data); + self::assertEquals($testString->format($this->connection->getDatabasePlatform()->getDateTimeFormatString()), $data); } /** @@ -217,7 +217,7 @@ public function testUpdateWithKeyValueTypes() { $testString = new DateTime('2013-04-14 10:10:10'); - $this->_conn->insert( + $this->connection->insert( 'write_table', ['test_int' => '30', 'test_string' => $testString], ['test_string' => 'datetime', 'test_int' => 'integer'] @@ -225,16 +225,16 @@ public function testUpdateWithKeyValueTypes() $testString = new DateTime('2013-04-15 10:10:10'); - $this->_conn->update( + $this->connection->update( 'write_table', ['test_string' => $testString], ['test_int' => '30'], ['test_string' => 'datetime', 'test_int' => 'integer'] ); - $data = $this->_conn->fetchColumn('SELECT test_string FROM write_table WHERE test_int = 30'); + $data = $this->connection->fetchColumn('SELECT test_string FROM write_table WHERE test_int = 30'); - self::assertEquals($testString->format($this->_conn->getDatabasePlatform()->getDateTimeFormatString()), $data); + self::assertEquals($testString->format($this->connection->getDatabasePlatform()->getDateTimeFormatString()), $data); } /** @@ -243,22 +243,22 @@ public function testUpdateWithKeyValueTypes() public function testDeleteWithKeyValueTypes() { $val = new DateTime('2013-04-14 10:10:10'); - $this->_conn->insert( + $this->connection->insert( 'write_table', ['test_int' => '30', 'test_string' => $val], ['test_string' => 'datetime', 'test_int' => 'integer'] ); - $this->_conn->delete('write_table', ['test_int' => 30, 'test_string' => $val], ['test_string' => 'datetime', 'test_int' => 'integer']); + $this->connection->delete('write_table', ['test_int' => 30, 'test_string' => $val], ['test_string' => 'datetime', 'test_int' => 'integer']); - $data = $this->_conn->fetchColumn('SELECT test_string FROM write_table WHERE test_int = 30'); + $data = $this->connection->fetchColumn('SELECT test_string FROM write_table WHERE test_int = 30'); self::assertFalse($data); } public function testEmptyIdentityInsert() { - $platform = $this->_conn->getDatabasePlatform(); + $platform = $this->connection->getDatabasePlatform(); if (! ($platform->supportsIdentityColumns() || $platform->usesSequenceEmulatedIdentityColumns())) { $this->markTestSkipped( @@ -271,12 +271,12 @@ public function testEmptyIdentityInsert() $table->setPrimaryKey(['id']); try { - $this->_conn->getSchemaManager()->dropTable($table->getQuotedName($platform)); + $this->connection->getSchemaManager()->dropTable($table->getQuotedName($platform)); } catch (Throwable $e) { } foreach ($platform->getCreateTableSQL($table) as $sql) { - $this->_conn->exec($sql); + $this->connection->exec($sql); } $seqName = $platform->usesSequenceEmulatedIdentityColumns() @@ -285,13 +285,13 @@ public function testEmptyIdentityInsert() $sql = $platform->getEmptyIdentityInsertSQL('test_empty_identity', 'id'); - $this->_conn->exec($sql); + $this->connection->exec($sql); - $firstId = $this->_conn->lastInsertId($seqName); + $firstId = $this->connection->lastInsertId($seqName); - $this->_conn->exec($sql); + $this->connection->exec($sql); - $secondId = $this->_conn->lastInsertId($seqName); + $secondId = $this->connection->lastInsertId($seqName); self::assertGreaterThan($firstId, $secondId); } @@ -301,38 +301,38 @@ public function testEmptyIdentityInsert() */ public function testUpdateWhereIsNull() { - $this->_conn->insert( + $this->connection->insert( 'write_table', ['test_int' => '30', 'test_string' => null], ['test_string' => 'string', 'test_int' => 'integer'] ); - $data = $this->_conn->fetchAll('SELECT * FROM write_table WHERE test_int = 30'); + $data = $this->connection->fetchAll('SELECT * FROM write_table WHERE test_int = 30'); self::assertCount(1, $data); - $this->_conn->update('write_table', ['test_int' => 10], ['test_string' => null], ['test_string' => 'string', 'test_int' => 'integer']); + $this->connection->update('write_table', ['test_int' => 10], ['test_string' => null], ['test_string' => 'string', 'test_int' => 'integer']); - $data = $this->_conn->fetchAll('SELECT * FROM write_table WHERE test_int = 30'); + $data = $this->connection->fetchAll('SELECT * FROM write_table WHERE test_int = 30'); self::assertCount(0, $data); } public function testDeleteWhereIsNull() { - $this->_conn->insert( + $this->connection->insert( 'write_table', ['test_int' => '30', 'test_string' => null], ['test_string' => 'string', 'test_int' => 'integer'] ); - $data = $this->_conn->fetchAll('SELECT * FROM write_table WHERE test_int = 30'); + $data = $this->connection->fetchAll('SELECT * FROM write_table WHERE test_int = 30'); self::assertCount(1, $data); - $this->_conn->delete('write_table', ['test_string' => null], ['test_string' => 'string']); + $this->connection->delete('write_table', ['test_string' => null], ['test_string' => 'string']); - $data = $this->_conn->fetchAll('SELECT * FROM write_table WHERE test_int = 30'); + $data = $this->connection->fetchAll('SELECT * FROM write_table WHERE test_int = 30'); self::assertCount(0, $data); } diff --git a/tests/Doctrine/Tests/DBAL/Mocks/MockPlatform.php b/tests/Doctrine/Tests/DBAL/Mocks/MockPlatform.php index cb6ec18df32..6a3f3d8e376 100644 --- a/tests/Doctrine/Tests/DBAL/Mocks/MockPlatform.php +++ b/tests/Doctrine/Tests/DBAL/Mocks/MockPlatform.php @@ -8,34 +8,59 @@ class MockPlatform extends AbstractPlatform { /** - * Gets the SQL Snippet used to declare a BLOB column type. + * {@inheritDoc} */ public function getBlobTypeDeclarationSQL(array $field) { throw DBALException::notSupported(__METHOD__); } + /** + * {@inheritDoc} + */ public function getBooleanTypeDeclarationSQL(array $columnDef) { } + + /** + * {@inheritDoc} + */ public function getIntegerTypeDeclarationSQL(array $columnDef) { } + + /** + * {@inheritDoc} + */ public function getBigIntTypeDeclarationSQL(array $columnDef) { } + + /** + * {@inheritDoc} + */ public function getSmallIntTypeDeclarationSQL(array $columnDef) { } + + /** + * {@inheritDoc} + */ public function _getCommonIntegerTypeDeclarationSQL(array $columnDef) { } + /** + * {@inheritDoc} + */ public function getVarcharTypeDeclarationSQL(array $field) { return 'DUMMYVARCHAR()'; } + /** + * {@inheritDoc} + */ public function getClobTypeDeclarationSQL(array $field) { return 'DUMMYCLOB'; diff --git a/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php b/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php index e60bace5dca..c4efa1b8377 100644 --- a/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php +++ b/tests/Doctrine/Tests/DBAL/Performance/TypeConversionPerformanceTest.php @@ -23,7 +23,7 @@ public function testDateTimeTypeConversionPerformance($count) { $value = new DateTime(); $type = Type::getType('datetime'); - $platform = $this->_conn->getDatabasePlatform(); + $platform = $this->connection->getDatabasePlatform(); $this->startTiming(); for ($i = 0; $i < $count; $i++) { $type->convertToDatabaseValue($value, $platform); diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php index 3b81ef680c6..63148215f22 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php @@ -15,7 +15,7 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase { public function testModifyLimitQueryWitoutLimit() { - $sql = $this->_platform->modifyLimitQuery('SELECT n FROM Foo', null, 10); + $sql = $this->platform->modifyLimitQuery('SELECT n FROM Foo', null, 10); self::assertEquals('SELECT n FROM Foo LIMIT 18446744073709551615 OFFSET 10', $sql); } @@ -24,7 +24,7 @@ public function testGenerateMixedCaseTableCreate() $table = new Table('Foo'); $table->addColumn('Bar', 'integer'); - $sql = $this->_platform->getCreateTableSQL($table); + $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)); } @@ -45,54 +45,54 @@ public function getGenerateAlterTableSql() public function testGeneratesSqlSnippets() { - 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'); + 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() { self::assertEquals( 'SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED', - $this->_platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_UNCOMMITTED), + $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_UNCOMMITTED), '' ); self::assertEquals( 'SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED', - $this->_platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_COMMITTED) + $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_COMMITTED) ); self::assertEquals( 'SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ', - $this->_platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::REPEATABLE_READ) + $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::REPEATABLE_READ) ); self::assertEquals( 'SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE', - $this->_platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::SERIALIZABLE) + $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::SERIALIZABLE) ); } public function testGeneratesDDLSnippets() { - self::assertEquals('SHOW DATABASES', $this->_platform->getListDatabasesSQL()); - 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')); + self::assertEquals('SHOW DATABASES', $this->platform->getListDatabasesSQL()); + 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 testGeneratesTypeDeclarationForIntegers() { self::assertEquals( 'INT', - $this->_platform->getIntegerTypeDeclarationSQL([]) + $this->platform->getIntegerTypeDeclarationSQL([]) ); self::assertEquals( 'INT AUTO_INCREMENT', - $this->_platform->getIntegerTypeDeclarationSQL(['autoincrement' => true]) + $this->platform->getIntegerTypeDeclarationSQL(['autoincrement' => true]) ); self::assertEquals( 'INT AUTO_INCREMENT', - $this->_platform->getIntegerTypeDeclarationSQL( + $this->platform->getIntegerTypeDeclarationSQL( ['autoincrement' => true, 'primary' => true] ) ); @@ -102,35 +102,35 @@ public function testGeneratesTypeDeclarationForStrings() { self::assertEquals( 'CHAR(10)', - $this->_platform->getVarcharTypeDeclarationSQL( + $this->platform->getVarcharTypeDeclarationSQL( ['length' => 10, 'fixed' => true] ) ); self::assertEquals( 'VARCHAR(50)', - $this->_platform->getVarcharTypeDeclarationSQL(['length' => 50]), + $this->platform->getVarcharTypeDeclarationSQL(['length' => 50]), 'Variable string declaration is not correct' ); self::assertEquals( 'VARCHAR(255)', - $this->_platform->getVarcharTypeDeclarationSQL([]), + $this->platform->getVarcharTypeDeclarationSQL([]), 'Long string declaration is not correct' ); } public function testPrefersIdentityColumns() { - self::assertTrue($this->_platform->prefersIdentityColumns()); + self::assertTrue($this->platform->prefersIdentityColumns()); } public function testSupportsIdentityColumns() { - self::assertTrue($this->_platform->supportsIdentityColumns()); + self::assertTrue($this->platform->supportsIdentityColumns()); } public function testDoesSupportSavePoints() { - self::assertTrue($this->_platform->supportsSavepoints()); + self::assertTrue($this->platform->supportsSavepoints()); } public function getGenerateIndexSql() @@ -166,7 +166,7 @@ public function testUniquePrimaryKey() $c = new Comparator(); $diff = $c->diffTable($oldTable, $keyTable); - $sql = $this->_platform->getAlterTableSQL($diff); + $sql = $this->platform->getAlterTableSQL($diff); self::assertEquals([ 'ALTER TABLE foo ADD PRIMARY KEY (bar)', @@ -176,13 +176,13 @@ public function testUniquePrimaryKey() public function testModifyLimitQuery() { - $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0); + $sql = $this->platform->modifyLimitQuery('SELECT * FROM user', 10, 0); self::assertEquals('SELECT * FROM user LIMIT 10', $sql); } public function testModifyLimitQueryWithEmptyOffset() { - $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10); + $sql = $this->platform->modifyLimitQuery('SELECT * FROM user', 10); self::assertEquals('SELECT * FROM user LIMIT 10', $sql); } @@ -191,9 +191,9 @@ public function testModifyLimitQueryWithEmptyOffset() */ public function testGetDateTimeTypeDeclarationSql() { - self::assertEquals('DATETIME', $this->_platform->getDateTimeTypeDeclarationSQL(['version' => false])); - self::assertEquals('TIMESTAMP', $this->_platform->getDateTimeTypeDeclarationSQL(['version' => true])); - self::assertEquals('DATETIME', $this->_platform->getDateTimeTypeDeclarationSQL([])); + 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() @@ -220,11 +220,11 @@ public function testChangeIndexWithForeignKeys() $unique = new Index('uniq', ['col'], true); $diff = new TableDiff('test', [], [], [], [$unique], [], [$index]); - $sql = $this->_platform->getAlterTableSQL($diff); + $sql = $this->platform->getAlterTableSQL($diff); self::assertEquals(['ALTER TABLE test DROP INDEX idx, ADD UNIQUE INDEX uniq (col)'], $sql); $diff = new TableDiff('test', [], [], [], [$index], [], [$unique]); - $sql = $this->_platform->getAlterTableSQL($diff); + $sql = $this->platform->getAlterTableSQL($diff); self::assertEquals(['ALTER TABLE test DROP INDEX uniq, ADD INDEX idx (col)'], $sql); } @@ -263,7 +263,7 @@ public function testCreateTableWithFulltextIndex() $index = $table->getIndex('fulltext_text'); $index->addFlag('fulltext'); - $sql = $this->_platform->getCreateTableSQL($table); + $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); } @@ -277,32 +277,32 @@ public function testCreateTableWithSpatialIndex() $index = $table->getIndex('spatial_text'); $index->addFlag('spatial'); - $sql = $this->_platform->getCreateTableSQL($table); + $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); } public function testClobTypeDeclarationSQL() { - self::assertEquals('TINYTEXT', $this->_platform->getClobTypeDeclarationSQL(['length' => 1])); - self::assertEquals('TINYTEXT', $this->_platform->getClobTypeDeclarationSQL(['length' => 255])); - self::assertEquals('TEXT', $this->_platform->getClobTypeDeclarationSQL(['length' => 256])); - self::assertEquals('TEXT', $this->_platform->getClobTypeDeclarationSQL(['length' => 65535])); - self::assertEquals('MEDIUMTEXT', $this->_platform->getClobTypeDeclarationSQL(['length' => 65536])); - self::assertEquals('MEDIUMTEXT', $this->_platform->getClobTypeDeclarationSQL(['length' => 16777215])); - self::assertEquals('LONGTEXT', $this->_platform->getClobTypeDeclarationSQL(['length' => 16777216])); - self::assertEquals('LONGTEXT', $this->_platform->getClobTypeDeclarationSQL([])); + self::assertEquals('TINYTEXT', $this->platform->getClobTypeDeclarationSQL(['length' => 1])); + self::assertEquals('TINYTEXT', $this->platform->getClobTypeDeclarationSQL(['length' => 255])); + self::assertEquals('TEXT', $this->platform->getClobTypeDeclarationSQL(['length' => 256])); + self::assertEquals('TEXT', $this->platform->getClobTypeDeclarationSQL(['length' => 65535])); + self::assertEquals('MEDIUMTEXT', $this->platform->getClobTypeDeclarationSQL(['length' => 65536])); + self::assertEquals('MEDIUMTEXT', $this->platform->getClobTypeDeclarationSQL(['length' => 16777215])); + self::assertEquals('LONGTEXT', $this->platform->getClobTypeDeclarationSQL(['length' => 16777216])); + self::assertEquals('LONGTEXT', $this->platform->getClobTypeDeclarationSQL([])); } public function testBlobTypeDeclarationSQL() { - self::assertEquals('TINYBLOB', $this->_platform->getBlobTypeDeclarationSQL(['length' => 1])); - self::assertEquals('TINYBLOB', $this->_platform->getBlobTypeDeclarationSQL(['length' => 255])); - self::assertEquals('BLOB', $this->_platform->getBlobTypeDeclarationSQL(['length' => 256])); - self::assertEquals('BLOB', $this->_platform->getBlobTypeDeclarationSQL(['length' => 65535])); - self::assertEquals('MEDIUMBLOB', $this->_platform->getBlobTypeDeclarationSQL(['length' => 65536])); - self::assertEquals('MEDIUMBLOB', $this->_platform->getBlobTypeDeclarationSQL(['length' => 16777215])); - self::assertEquals('LONGBLOB', $this->_platform->getBlobTypeDeclarationSQL(['length' => 16777216])); - self::assertEquals('LONGBLOB', $this->_platform->getBlobTypeDeclarationSQL([])); + self::assertEquals('TINYBLOB', $this->platform->getBlobTypeDeclarationSQL(['length' => 1])); + self::assertEquals('TINYBLOB', $this->platform->getBlobTypeDeclarationSQL(['length' => 255])); + self::assertEquals('BLOB', $this->platform->getBlobTypeDeclarationSQL(['length' => 256])); + self::assertEquals('BLOB', $this->platform->getBlobTypeDeclarationSQL(['length' => 65535])); + self::assertEquals('MEDIUMBLOB', $this->platform->getBlobTypeDeclarationSQL(['length' => 65536])); + self::assertEquals('MEDIUMBLOB', $this->platform->getBlobTypeDeclarationSQL(['length' => 16777215])); + self::assertEquals('LONGBLOB', $this->platform->getBlobTypeDeclarationSQL(['length' => 16777216])); + self::assertEquals('LONGBLOB', $this->platform->getBlobTypeDeclarationSQL([])); } /** @@ -323,7 +323,7 @@ public function testAlterTableAddPrimaryKey() self::assertEquals( ['DROP INDEX idx_id ON alter_table_add_pk', 'ALTER TABLE alter_table_add_pk ADD PRIMARY KEY (id)'], - $this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) + $this->platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) ); } @@ -349,7 +349,7 @@ public function testAlterPrimaryKeyWithAutoincrementColumn() 'ALTER TABLE alter_primary_key DROP PRIMARY KEY', 'ALTER TABLE alter_primary_key ADD PRIMARY KEY (foo)', ], - $this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) + $this->platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) ); } @@ -374,7 +374,7 @@ public function testDropPrimaryKeyWithAutoincrementColumn() 'ALTER TABLE drop_primary_key MODIFY id INT NOT NULL', 'ALTER TABLE drop_primary_key DROP PRIMARY KEY', ], - $this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) + $this->platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) ); } @@ -401,7 +401,7 @@ public function testDropNonAutoincrementColumnFromCompositePrimaryKeyWithAutoinc 'ALTER TABLE tbl DROP PRIMARY KEY', 'ALTER TABLE tbl ADD PRIMARY KEY (id)', ], - $this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) + $this->platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) ); } @@ -428,7 +428,7 @@ public function testAddNonAutoincrementColumnToPrimaryKeyWithAutoincrementColumn 'ALTER TABLE tbl DROP PRIMARY KEY', 'ALTER TABLE tbl ADD PRIMARY KEY (id, foo)', ], - $this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) + $this->platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) ); } @@ -448,7 +448,7 @@ public function testAddAutoIncrementPrimaryKey() $c = new Comparator(); $diff = $c->diffTable($oldTable, $keyTable); - $sql = $this->_platform->getAlterTableSQL($diff); + $sql = $this->platform->getAlterTableSQL($diff); self::assertEquals(['ALTER TABLE foo ADD id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)'], $sql); } @@ -458,7 +458,7 @@ public function testNamedPrimaryKey() $diff = new TableDiff('mytable'); $diff->changedIndexes['foo_index'] = new Index('foo_index', ['foo'], true, true); - $sql = $this->_platform->getAlterTableSQL($diff); + $sql = $this->platform->getAlterTableSQL($diff); self::assertEquals([ 'ALTER TABLE mytable DROP PRIMARY KEY', @@ -486,17 +486,17 @@ public function testAlterPrimaryKeyWithNewColumn() 'ALTER TABLE yolo ADD pkc2 INT NOT NULL', 'ALTER TABLE yolo ADD PRIMARY KEY (pkc1, pkc2)', ], - $this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) + $this->platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) ); } public function testInitializesDoctrineTypeMappings() { - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('binary')); - self::assertSame('binary', $this->_platform->getDoctrineTypeMapping('binary')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('binary')); + self::assertSame('binary', $this->platform->getDoctrineTypeMapping('binary')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('varbinary')); - self::assertSame('binary', $this->_platform->getDoctrineTypeMapping('varbinary')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('varbinary')); + self::assertSame('binary', $this->platform->getDoctrineTypeMapping('varbinary')); } protected function getBinaryMaxLength() @@ -506,13 +506,13 @@ protected function getBinaryMaxLength() public function testReturnsBinaryTypeDeclarationSQL() { - self::assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL([])); - self::assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 0])); - self::assertSame('VARBINARY(65535)', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 65535])); + self::assertSame('VARBINARY(255)', $this->platform->getBinaryTypeDeclarationSQL([])); + self::assertSame('VARBINARY(255)', $this->platform->getBinaryTypeDeclarationSQL(['length' => 0])); + self::assertSame('VARBINARY(65535)', $this->platform->getBinaryTypeDeclarationSQL(['length' => 65535])); - self::assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true])); - self::assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 0])); - self::assertSame('BINARY(65535)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 65535])); + self::assertSame('BINARY(255)', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true])); + self::assertSame('BINARY(255)', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 0])); + self::assertSame('BINARY(65535)', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 65535])); } /** @@ -523,13 +523,13 @@ public function testReturnsBinaryTypeDeclarationSQL() */ public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() { - self::assertSame('MEDIUMBLOB', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 65536])); - self::assertSame('MEDIUMBLOB', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 16777215])); - self::assertSame('LONGBLOB', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 16777216])); + self::assertSame('MEDIUMBLOB', $this->platform->getBinaryTypeDeclarationSQL(['length' => 65536])); + self::assertSame('MEDIUMBLOB', $this->platform->getBinaryTypeDeclarationSQL(['length' => 16777215])); + self::assertSame('LONGBLOB', $this->platform->getBinaryTypeDeclarationSQL(['length' => 16777216])); - self::assertSame('MEDIUMBLOB', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 65536])); - self::assertSame('MEDIUMBLOB', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 16777215])); - self::assertSame('LONGBLOB', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 16777216])); + self::assertSame('MEDIUMBLOB', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 65536])); + self::assertSame('MEDIUMBLOB', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 16777215])); + self::assertSame('LONGBLOB', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 16777216])); } public function testDoesNotPropagateForeignKeyCreationForNonSupportingEngines() @@ -543,7 +543,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 = MyISAM'], - $this->_platform->getCreateTableSQL( + $this->platform->getCreateTableSQL( $table, AbstractPlatform::CREATE_INDEXES|AbstractPlatform::CREATE_FOREIGNKEYS ) @@ -557,7 +557,7 @@ public function testDoesNotPropagateForeignKeyCreationForNonSupportingEngines() '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( + $this->platform->getCreateTableSQL( $table, AbstractPlatform::CREATE_INDEXES|AbstractPlatform::CREATE_FOREIGNKEYS ) @@ -583,7 +583,7 @@ public function testDoesNotPropagateForeignKeyAlterationForNonSupportingEngines( $tableDiff->changedForeignKeys = $changedForeignKeys; $tableDiff->removedForeignKeys = $removedForeignKeys; - self::assertEmpty($this->_platform->getAlterTableSQL($tableDiff)); + self::assertEmpty($this->platform->getAlterTableSQL($tableDiff)); $table->addOption('engine', 'InnoDB'); @@ -600,7 +600,7 @@ public function testDoesNotPropagateForeignKeyAlterationForNonSupportingEngines( 'ALTER TABLE foreign_table ADD CONSTRAINT fk_add FOREIGN KEY (fk_id) REFERENCES foo (id)', 'ALTER TABLE foreign_table ADD CONSTRAINT fk_change FOREIGN KEY (fk_id) REFERENCES bar (id)', ], - $this->_platform->getAlterTableSQL($tableDiff) + $this->platform->getAlterTableSQL($tableDiff) ); } @@ -672,7 +672,7 @@ public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() 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'], - $this->_platform->getCreateTableSQL($table) + $this->platform->getCreateTableSQL($table) ); $diffTable = clone $table; @@ -683,7 +683,7 @@ public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() $comparator = new Comparator(); - self::assertEmpty($this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable))); + self::assertEmpty($this->platform->getAlterTableSQL($comparator->diffTable($table, $diffTable))); } /** @@ -724,7 +724,7 @@ protected function getQuotedAlterTableChangeColumnLengthSQL() */ public function testReturnsGuidTypeDeclarationSQL() { - self::assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL([])); + self::assertSame('CHAR(36)', $this->platform->getGuidTypeDeclarationSQL([])); } /** @@ -842,7 +842,7 @@ public function getGeneratesFloatDeclarationSQL() */ public function testQuotesTableNameInListTableIndexesSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableIndexesSQL("Foo'Bar\\", 'foo_db'), '', true); + self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\", 'foo_db'), '', true); } /** @@ -850,7 +850,7 @@ public function testQuotesTableNameInListTableIndexesSQL() */ public function testQuotesDatabaseNameInListTableIndexesSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableIndexesSQL('foo_table', "Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableIndexesSQL('foo_table', "Foo'Bar\\"), '', true); } /** @@ -858,7 +858,7 @@ public function testQuotesDatabaseNameInListTableIndexesSQL() */ public function testQuotesDatabaseNameInListViewsSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListViewsSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\\\'", $this->platform->getListViewsSQL("Foo'Bar\\"), '', true); } /** @@ -866,7 +866,7 @@ public function testQuotesDatabaseNameInListViewsSQL() */ public function testQuotesTableNameInListTableForeignKeysSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true); } /** @@ -874,7 +874,7 @@ public function testQuotesTableNameInListTableForeignKeysSQL() */ public function testQuotesDatabaseNameInListTableForeignKeysSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableForeignKeysSQL('foo_table', "Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableForeignKeysSQL('foo_table', "Foo'Bar\\"), '', true); } /** @@ -882,7 +882,7 @@ public function testQuotesDatabaseNameInListTableForeignKeysSQL() */ public function testQuotesTableNameInListTableColumnsSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableColumnsSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableColumnsSQL("Foo'Bar\\"), '', true); } /** @@ -890,16 +890,16 @@ public function testQuotesTableNameInListTableColumnsSQL() */ public function testQuotesDatabaseNameInListTableColumnsSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableColumnsSQL('foo_table', "Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableColumnsSQL('foo_table', "Foo'Bar\\"), '', true); } public function testListTableForeignKeysSQLEvaluatesDatabase() { - $sql = $this->_platform->getListTableForeignKeysSQL('foo'); + $sql = $this->platform->getListTableForeignKeysSQL('foo'); self::assertContains('DATABASE()', $sql); - $sql = $this->_platform->getListTableForeignKeysSQL('foo', 'bar'); + $sql = $this->platform->getListTableForeignKeysSQL('foo', 'bar'); self::assertContains('bar', $sql); self::assertNotContains('DATABASE()', $sql); @@ -907,14 +907,14 @@ public function testListTableForeignKeysSQLEvaluatesDatabase() public function testSupportsColumnCollation() : void { - self::assertTrue($this->_platform->supportsColumnCollation()); + self::assertTrue($this->platform->supportsColumnCollation()); } public function testColumnCollationDeclarationSQL() : void { self::assertSame( 'COLLATE ascii_general_ci', - $this->_platform->getColumnCollationDeclarationSQL('ascii_general_ci') + $this->platform->getColumnCollationDeclarationSQL('ascii_general_ci') ); } @@ -926,7 +926,7 @@ public function testGetCreateTableSQLWithColumnCollation() : void 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'], - $this->_platform->getCreateTableSQL($table), + $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/Platforms/AbstractPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php index 9b303a6e76e..8fee20fede2 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php @@ -3,8 +3,10 @@ namespace Doctrine\Tests\DBAL\Platforms; use Doctrine\Common\EventManager; +use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Events; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\Keywords\KeywordList; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ColumnDiff; use Doctrine\DBAL\Schema\Comparator; @@ -23,13 +25,13 @@ abstract class AbstractPlatformTestCase extends DbalTestCase { /** @var AbstractPlatform */ - protected $_platform; + protected $platform; abstract public function createPlatform(); protected function setUp() { - $this->_platform = $this->createPlatform(); + $this->platform = $this->createPlatform(); } /** @@ -37,14 +39,14 @@ protected function setUp() */ public function testQuoteIdentifier() { - if ($this->_platform->getName() === 'mssql') { + if ($this->platform->getName() === 'mssql') { $this->markTestSkipped('Not working this way on mssql.'); } - $c = $this->_platform->getIdentifierQuoteCharacter(); - self::assertEquals($c . 'test' . $c, $this->_platform->quoteIdentifier('test')); - self::assertEquals($c . 'test' . $c . '.' . $c . 'test' . $c, $this->_platform->quoteIdentifier('test.test')); - self::assertEquals(str_repeat($c, 4), $this->_platform->quoteIdentifier($c)); + $c = $this->platform->getIdentifierQuoteCharacter(); + self::assertEquals($c . 'test' . $c, $this->platform->quoteIdentifier('test')); + self::assertEquals($c . 'test' . $c . '.' . $c . 'test' . $c, $this->platform->quoteIdentifier('test.test')); + self::assertEquals(str_repeat($c, 4), $this->platform->quoteIdentifier($c)); } /** @@ -52,14 +54,14 @@ public function testQuoteIdentifier() */ public function testQuoteSingleIdentifier() { - if ($this->_platform->getName() === 'mssql') { + if ($this->platform->getName() === 'mssql') { $this->markTestSkipped('Not working this way on mssql.'); } - $c = $this->_platform->getIdentifierQuoteCharacter(); - self::assertEquals($c . 'test' . $c, $this->_platform->quoteSingleIdentifier('test')); - self::assertEquals($c . 'test.test' . $c, $this->_platform->quoteSingleIdentifier('test.test')); - self::assertEquals(str_repeat($c, 4), $this->_platform->quoteSingleIdentifier($c)); + $c = $this->platform->getIdentifierQuoteCharacter(); + self::assertEquals($c . 'test' . $c, $this->platform->quoteSingleIdentifier('test')); + self::assertEquals($c . 'test.test' . $c, $this->platform->quoteSingleIdentifier('test.test')); + self::assertEquals(str_repeat($c, 4), $this->platform->quoteSingleIdentifier($c)); } /** @@ -68,11 +70,11 @@ public function testQuoteSingleIdentifier() */ public function testReturnsForeignKeyReferentialActionSQL($action, $expectedSQL) { - self::assertSame($expectedSQL, $this->_platform->getForeignKeyReferentialActionSQL($action)); + self::assertSame($expectedSQL, $this->platform->getForeignKeyReferentialActionSQL($action)); } /** - * @return array + * @return string[][] */ public function getReturnsForeignKeyReferentialActionSQL() { @@ -89,25 +91,25 @@ public function getReturnsForeignKeyReferentialActionSQL() public function testGetInvalidForeignKeyReferentialActionSQL() { $this->expectException('InvalidArgumentException'); - $this->_platform->getForeignKeyReferentialActionSQL('unknown'); + $this->platform->getForeignKeyReferentialActionSQL('unknown'); } public function testGetUnknownDoctrineMappingType() { - $this->expectException('Doctrine\DBAL\DBALException'); - $this->_platform->getDoctrineTypeMapping('foobar'); + $this->expectException(DBALException::class); + $this->platform->getDoctrineTypeMapping('foobar'); } public function testRegisterDoctrineMappingType() { - $this->_platform->registerDoctrineTypeMapping('foo', 'integer'); - self::assertEquals('integer', $this->_platform->getDoctrineTypeMapping('foo')); + $this->platform->registerDoctrineTypeMapping('foo', 'integer'); + self::assertEquals('integer', $this->platform->getDoctrineTypeMapping('foo')); } public function testRegisterUnknownDoctrineMappingType() { - $this->expectException('Doctrine\DBAL\DBALException'); - $this->_platform->registerDoctrineTypeMapping('foo', 'bar'); + $this->expectException(DBALException::class); + $this->platform->registerDoctrineTypeMapping('foo', 'bar'); } /** @@ -120,9 +122,9 @@ public function testRegistersCommentedDoctrineMappingTypeImplicitly() } $type = Type::getType('my_commented'); - $this->_platform->registerDoctrineTypeMapping('foo', 'my_commented'); + $this->platform->registerDoctrineTypeMapping('foo', 'my_commented'); - self::assertTrue($this->_platform->isCommentedDoctrineType($type)); + self::assertTrue($this->platform->isCommentedDoctrineType($type)); } /** @@ -131,7 +133,7 @@ public function testRegistersCommentedDoctrineMappingTypeImplicitly() */ public function testIsCommentedDoctrineType(Type $type, $commented) { - self::assertSame($commented, $this->_platform->isCommentedDoctrineType($type)); + self::assertSame($commented, $this->platform->isCommentedDoctrineType($type)); } public function getIsCommentedDoctrineType() @@ -145,7 +147,7 @@ public function getIsCommentedDoctrineType() $data[$typeName] = [ $type, - $type->requiresSQLCommentHint($this->_platform), + $type->requiresSQLCommentHint($this->platform), ]; } @@ -156,8 +158,8 @@ public function testCreateWithNoColumns() { $table = new Table('test'); - $this->expectException('Doctrine\DBAL\DBALException'); - $sql = $this->_platform->getCreateTableSQL($table); + $this->expectException(DBALException::class); + $sql = $this->platform->getCreateTableSQL($table); } public function testGeneratesTableCreationSql() @@ -167,7 +169,7 @@ public function testGeneratesTableCreationSql() $table->addColumn('test', 'string', ['notnull' => false, 'length' => 255]); $table->setPrimaryKey(['id']); - $sql = $this->_platform->getCreateTableSQL($table); + $sql = $this->platform->getCreateTableSQL($table); self::assertEquals($this->getGenerateTableSql(), $sql[0]); } @@ -180,7 +182,7 @@ public function testGenerateTableWithMultiColumnUniqueIndex() $table->addColumn('bar', 'string', ['notnull' => false, 'length' => 255]); $table->addUniqueIndex(['foo', 'bar']); - $sql = $this->_platform->getCreateTableSQL($table); + $sql = $this->platform->getCreateTableSQL($table); self::assertEquals($this->getGenerateTableWithMultiColumnUniqueIndexSql(), $sql); } @@ -192,7 +194,7 @@ public function testGeneratesIndexCreationSql() self::assertEquals( $this->getGenerateIndexSql(), - $this->_platform->getCreateIndexSQL($indexDef, 'mytable') + $this->platform->getCreateIndexSQL($indexDef, 'mytable') ); } @@ -202,7 +204,7 @@ public function testGeneratesUniqueIndexCreationSql() { $indexDef = new Index('index_name', ['test', 'test2'], true); - $sql = $this->_platform->getCreateIndexSQL($indexDef, 'test'); + $sql = $this->platform->getCreateIndexSQL($indexDef, 'test'); self::assertEquals($this->getGenerateUniqueIndexSql(), $sql); } @@ -219,14 +221,14 @@ public function testGeneratesPartialIndexesSqlOnlyWhenSupportingPartialIndexes() $actuals = []; if ($this->supportsInlineIndexDeclaration()) { - $actuals[] = $this->_platform->getIndexDeclarationSQL('name', $indexDef); + $actuals[] = $this->platform->getIndexDeclarationSQL('name', $indexDef); } - $actuals[] = $this->_platform->getUniqueConstraintDeclarationSQL('name', $uniqueIndex); - $actuals[] = $this->_platform->getCreateIndexSQL($indexDef, 'table'); + $actuals[] = $this->platform->getUniqueConstraintDeclarationSQL('name', $uniqueIndex); + $actuals[] = $this->platform->getCreateIndexSQL($indexDef, 'table'); foreach ($actuals as $actual) { - if ($this->_platform->supportsPartialIndexes()) { + if ($this->platform->supportsPartialIndexes()) { self::assertStringEndsWith($expected, $actual, 'WHERE clause should be present'); } else { self::assertStringEndsNotWith($expected, $actual, 'WHERE clause should NOT be present'); @@ -238,7 +240,7 @@ public function testGeneratesForeignKeyCreationSql() { $fk = new ForeignKeyConstraint(['fk_name_id'], 'other_table', ['id'], ''); - $sql = $this->_platform->getCreateForeignKeySQL($fk, 'test'); + $sql = $this->platform->getCreateForeignKeySQL($fk, 'test'); self::assertEquals($sql, $this->getGenerateForeignKeySql()); } @@ -247,15 +249,15 @@ abstract public function getGenerateForeignKeySql(); public function testGeneratesConstraintCreationSql() { $idx = new Index('constraint_name', ['test'], true, false); - $sql = $this->_platform->getCreateConstraintSQL($idx, 'test'); + $sql = $this->platform->getCreateConstraintSQL($idx, 'test'); self::assertEquals($this->getGenerateConstraintUniqueIndexSql(), $sql); $pk = new Index('constraint_name', ['test'], true, true); - $sql = $this->_platform->getCreateConstraintSQL($pk, 'test'); + $sql = $this->platform->getCreateConstraintSQL($pk, 'test'); self::assertEquals($this->getGenerateConstraintPrimaryIndexSql(), $sql); $fk = new ForeignKeyConstraint(['fk_name'], 'foreign', ['id'], 'constraint_fk'); - $sql = $this->_platform->getCreateConstraintSQL($fk, 'test'); + $sql = $this->platform->getCreateConstraintSQL($fk, 'test'); self::assertEquals($this->getGenerateConstraintForeignKeySql($fk), $sql); } @@ -263,14 +265,14 @@ public function testGeneratesForeignKeySqlOnlyWhenSupportingForeignKeys() { $fk = new ForeignKeyConstraint(['fk_name'], 'foreign', ['id'], 'constraint_fk'); - if ($this->_platform->supportsForeignKeyConstraints()) { + if ($this->platform->supportsForeignKeyConstraints()) { self::assertInternalType( 'string', - $this->_platform->getCreateForeignKeySQL($fk, 'test') + $this->platform->getCreateForeignKeySQL($fk, 'test') ); } else { - $this->expectException('Doctrine\DBAL\DBALException'); - $this->_platform->getCreateForeignKeySQL($fk, 'test'); + $this->expectException(DBALException::class); + $this->platform->getCreateForeignKeySQL($fk, 'test'); } } @@ -284,7 +286,7 @@ protected function getBitAndComparisonExpressionSql($value1, $value2) */ public function testGeneratesBitAndComparisonExpressionSql() { - $sql = $this->_platform->getBitAndComparisonExpression(2, 4); + $sql = $this->platform->getBitAndComparisonExpression(2, 4); self::assertEquals($this->getBitAndComparisonExpressionSql(2, 4), $sql); } @@ -298,7 +300,7 @@ protected function getBitOrComparisonExpressionSql($value1, $value2) */ public function testGeneratesBitOrComparisonExpressionSql() { - $sql = $this->_platform->getBitOrComparisonExpression(2, 4); + $sql = $this->platform->getBitOrComparisonExpression(2, 4); self::assertEquals($this->getBitOrComparisonExpressionSql(2, 4), $sql); } @@ -314,9 +316,12 @@ public function getGenerateConstraintPrimaryIndexSql() public function getGenerateConstraintForeignKeySql(ForeignKeyConstraint $fk) { - $quotedForeignTable = $fk->getQuotedForeignTableName($this->_platform); + $quotedForeignTable = $fk->getQuotedForeignTableName($this->platform); - return "ALTER TABLE test ADD CONSTRAINT constraint_fk FOREIGN KEY (fk_name) REFERENCES $quotedForeignTable (id)"; + return sprintf( + 'ALTER TABLE test ADD CONSTRAINT constraint_fk FOREIGN KEY (fk_name) REFERENCES %s (id)', + $quotedForeignTable + ); } abstract public function getGenerateAlterTableSql(); @@ -356,7 +361,7 @@ public function testGeneratesTableAlterationSql() ['type', 'notnull', 'default'] ); - $sql = $this->_platform->getAlterTableSQL($tableDiff); + $sql = $this->platform->getAlterTableSQL($tableDiff); self::assertEquals($expectedSql, $sql); } @@ -364,7 +369,7 @@ public function testGeneratesTableAlterationSql() public function testGetCustomColumnDeclarationSql() { $field = ['columnDefinition' => 'MEDIUMINT(6) UNSIGNED']; - self::assertEquals('foo MEDIUMINT(6) UNSIGNED', $this->_platform->getColumnDeclarationSQL('foo', $field)); + self::assertEquals('foo MEDIUMINT(6) UNSIGNED', $this->platform->getColumnDeclarationSQL('foo', $field)); } public function testGetCreateTableSqlDispatchEvent() @@ -382,13 +387,13 @@ public function testGetCreateTableSqlDispatchEvent() $eventManager = new EventManager(); $eventManager->addEventListener([Events::onSchemaCreateTable, Events::onSchemaCreateTableColumn], $listenerMock); - $this->_platform->setEventManager($eventManager); + $this->platform->setEventManager($eventManager); $table = new Table('test'); $table->addColumn('foo', 'string', ['notnull' => false, 'length' => 255]); $table->addColumn('bar', 'string', ['notnull' => false, 'length' => 255]); - $this->_platform->getCreateTableSQL($table); + $this->platform->getCreateTableSQL($table); } public function testGetDropTableSqlDispatchEvent() @@ -403,9 +408,9 @@ public function testGetDropTableSqlDispatchEvent() $eventManager = new EventManager(); $eventManager->addEventListener([Events::onSchemaDropTable], $listenerMock); - $this->_platform->setEventManager($eventManager); + $this->platform->setEventManager($eventManager); - $this->_platform->getDropTableSQL('TABLE'); + $this->platform->getDropTableSQL('TABLE'); } public function testGetAlterTableSqlDispatchEvent() @@ -447,7 +452,7 @@ public function testGetAlterTableSqlDispatchEvent() ]; $eventManager->addEventListener($events, $listenerMock); - $this->_platform->setEventManager($eventManager); + $this->platform->setEventManager($eventManager); $table = new Table('mytable'); $table->addColumn('removed', 'integer'); @@ -469,7 +474,7 @@ public function testGetAlterTableSqlDispatchEvent() ); $tableDiff->renamedColumns['renamed'] = new Column('renamed2', Type::getType('integer'), []); - $this->_platform->getAlterTableSQL($tableDiff); + $this->platform->getAlterTableSQL($tableDiff); } /** @@ -481,7 +486,7 @@ public function testCreateTableColumnComments() $table->addColumn('id', 'integer', ['comment' => 'This is a comment']); $table->setPrimaryKey(['id']); - self::assertEquals($this->getCreateTableColumnCommentsSQL(), $this->_platform->getCreateTableSQL($table)); + self::assertEquals($this->getCreateTableColumnCommentsSQL(), $this->platform->getCreateTableSQL($table)); } /** @@ -509,7 +514,7 @@ public function testAlterTableColumnComments() ['comment'] ); - self::assertEquals($this->getAlterTableColumnCommentsSQL(), $this->_platform->getAlterTableSQL($tableDiff)); + self::assertEquals($this->getAlterTableColumnCommentsSQL(), $this->platform->getAlterTableSQL($tableDiff)); } public function testCreateTableColumnTypeComments() @@ -519,7 +524,7 @@ public function testCreateTableColumnTypeComments() $table->addColumn('data', 'array'); $table->setPrimaryKey(['id']); - self::assertEquals($this->getCreateTableColumnTypeCommentsSQL(), $this->_platform->getCreateTableSQL($table)); + self::assertEquals($this->getCreateTableColumnTypeCommentsSQL(), $this->platform->getCreateTableSQL($table)); } public function getCreateTableColumnCommentsSQL() @@ -545,7 +550,7 @@ public function testGetDefaultValueDeclarationSQL() 'default' => 'non_timestamp', ]; - self::assertEquals(" DEFAULT 'non_timestamp'", $this->_platform->getDefaultValueDeclarationSQL($field)); + self::assertEquals(" DEFAULT 'non_timestamp'", $this->platform->getDefaultValueDeclarationSQL($field)); } /** @@ -557,12 +562,12 @@ public function testGetDefaultValueDeclarationSQLDateTime() : void foreach (['datetime', 'datetimetz', 'datetime_immutable', 'datetimetz_immutable'] as $type) { $field = [ 'type' => Type::getType($type), - 'default' => $this->_platform->getCurrentTimestampSQL(), + 'default' => $this->platform->getCurrentTimestampSQL(), ]; self::assertSame( - ' DEFAULT ' . $this->_platform->getCurrentTimestampSQL(), - $this->_platform->getDefaultValueDeclarationSQL($field) + ' DEFAULT ' . $this->platform->getCurrentTimestampSQL(), + $this->platform->getDefaultValueDeclarationSQL($field) ); } } @@ -577,7 +582,7 @@ public function testGetDefaultValueDeclarationSQLForIntegerTypes() self::assertEquals( ' DEFAULT 1', - $this->_platform->getDefaultValueDeclarationSQL($field) + $this->platform->getDefaultValueDeclarationSQL($field) ); } } @@ -587,7 +592,7 @@ public function testGetDefaultValueDeclarationSQLForIntegerTypes() */ public function testGetDefaultValueDeclarationSQLForDateType() : void { - $currentDateSql = $this->_platform->getCurrentDateSQL(); + $currentDateSql = $this->platform->getCurrentDateSQL(); foreach (['date', 'date_immutable'] as $type) { $field = [ 'type' => Type::getType($type), @@ -596,7 +601,7 @@ public function testGetDefaultValueDeclarationSQLForDateType() : void self::assertSame( ' DEFAULT ' . $currentDateSql, - $this->_platform->getDefaultValueDeclarationSQL($field) + $this->platform->getDefaultValueDeclarationSQL($field) ); } } @@ -606,8 +611,8 @@ public function testGetDefaultValueDeclarationSQLForDateType() : void */ public function testKeywordList() { - $keywordList = $this->_platform->getReservedKeywordsList(); - self::assertInstanceOf('Doctrine\DBAL\Platforms\Keywords\KeywordList', $keywordList); + $keywordList = $this->platform->getReservedKeywordsList(); + self::assertInstanceOf(KeywordList::class, $keywordList); self::assertTrue($keywordList->isKeyword('table')); } @@ -621,7 +626,7 @@ public function testQuotedColumnInPrimaryKeyPropagation() $table->addColumn('create', 'string'); $table->setPrimaryKey(['create']); - $sql = $this->_platform->getCreateTableSQL($table); + $sql = $this->platform->getCreateTableSQL($table); self::assertEquals($this->getQuotedColumnInPrimaryKeySQL(), $sql); } @@ -639,7 +644,7 @@ public function testQuotedColumnInIndexPropagation() $table->addColumn('create', 'string'); $table->addIndex(['create']); - $sql = $this->_platform->getCreateTableSQL($table); + $sql = $this->platform->getCreateTableSQL($table); self::assertEquals($this->getQuotedColumnInIndexSQL(), $sql); } @@ -649,7 +654,7 @@ public function testQuotedNameInIndexSQL() $table->addColumn('column1', 'string'); $table->addIndex(['column1'], '`key`'); - $sql = $this->_platform->getCreateTableSQL($table); + $sql = $this->platform->getCreateTableSQL($table); self::assertEquals($this->getQuotedNameInIndexSQL(), $sql); } @@ -687,7 +692,7 @@ public function testQuotedColumnInForeignKeyPropagation() $table->addForeignKeyConstraint($foreignTable, ['create', 'foo', '`bar`'], ['create', 'bar', '`foo-bar`'], [], 'FK_WITH_INTENDED_QUOTATION'); - $sql = $this->_platform->getCreateTableSQL($table, AbstractPlatform::CREATE_FOREIGNKEYS); + $sql = $this->platform->getCreateTableSQL($table, AbstractPlatform::CREATE_FOREIGNKEYS); self::assertEquals($this->getQuotedColumnInForeignKeySQL(), $sql); } @@ -700,7 +705,7 @@ public function testQuotesReservedKeywordInUniqueConstraintDeclarationSQL() self::assertSame( $this->getQuotesReservedKeywordInUniqueConstraintDeclarationSQL(), - $this->_platform->getUniqueConstraintDeclarationSQL('select', $index) + $this->platform->getUniqueConstraintDeclarationSQL('select', $index) ); } @@ -716,7 +721,7 @@ public function testQuotesReservedKeywordInTruncateTableSQL() { self::assertSame( $this->getQuotesReservedKeywordInTruncateTableSQL(), - $this->_platform->getTruncateTableSQL('select') + $this->platform->getTruncateTableSQL('select') ); } @@ -733,12 +738,12 @@ public function testQuotesReservedKeywordInIndexDeclarationSQL() $index = new Index('select', ['foo']); if (! $this->supportsInlineIndexDeclaration()) { - $this->expectException('Doctrine\DBAL\DBALException'); + $this->expectException(DBALException::class); } self::assertSame( $this->getQuotesReservedKeywordInIndexDeclarationSQL(), - $this->_platform->getIndexDeclarationSQL('select', $index) + $this->platform->getIndexDeclarationSQL('select', $index) ); } @@ -757,7 +762,7 @@ protected function supportsInlineIndexDeclaration() public function testSupportsCommentOnStatement() { - self::assertSame($this->supportsCommentOnStatement(), $this->_platform->supportsCommentOnStatement()); + self::assertSame($this->supportsCommentOnStatement(), $this->platform->supportsCommentOnStatement()); } /** @@ -773,7 +778,7 @@ protected function supportsCommentOnStatement() */ public function testGetCreateSchemaSQL() { - $this->_platform->getCreateSchemaSQL('schema'); + $this->platform->getCreateSchemaSQL('schema'); } /** @@ -793,8 +798,8 @@ public function testAlterTableChangeQuotedColumn() ); self::assertContains( - $this->_platform->quoteIdentifier('select'), - implode(';', $this->_platform->getAlterTableSQL($tableDiff)) + $this->platform->quoteIdentifier('select'), + implode(';', $this->platform->getAlterTableSQL($tableDiff)) ); } @@ -803,7 +808,7 @@ public function testAlterTableChangeQuotedColumn() */ public function testUsesSequenceEmulatedIdentityColumns() { - self::assertFalse($this->_platform->usesSequenceEmulatedIdentityColumns()); + self::assertFalse($this->platform->usesSequenceEmulatedIdentityColumns()); } /** @@ -812,12 +817,12 @@ public function testUsesSequenceEmulatedIdentityColumns() */ public function testReturnsIdentitySequenceName() { - $this->_platform->getIdentitySequenceName('mytable', 'mycolumn'); + $this->platform->getIdentitySequenceName('mytable', 'mycolumn'); } public function testReturnsBinaryDefaultLength() { - self::assertSame($this->getBinaryDefaultLength(), $this->_platform->getBinaryDefaultLength()); + self::assertSame($this->getBinaryDefaultLength(), $this->platform->getBinaryDefaultLength()); } protected function getBinaryDefaultLength() @@ -827,7 +832,7 @@ protected function getBinaryDefaultLength() public function testReturnsBinaryMaxLength() { - self::assertSame($this->getBinaryMaxLength(), $this->_platform->getBinaryMaxLength()); + self::assertSame($this->getBinaryMaxLength(), $this->platform->getBinaryMaxLength()); } protected function getBinaryMaxLength() @@ -840,7 +845,7 @@ protected function getBinaryMaxLength() */ public function testReturnsBinaryTypeDeclarationSQL() { - $this->_platform->getBinaryTypeDeclarationSQL([]); + $this->platform->getBinaryTypeDeclarationSQL([]); } public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() @@ -853,7 +858,7 @@ public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() */ public function hasNativeJsonType() { - self::assertFalse($this->_platform->hasNativeJsonType()); + self::assertFalse($this->platform->hasNativeJsonType()); } /** @@ -868,8 +873,8 @@ public function testReturnsJsonTypeDeclarationSQL() ]; self::assertSame( - $this->_platform->getClobTypeDeclarationSQL($column), - $this->_platform->getJsonTypeDeclarationSQL($column) + $this->platform->getClobTypeDeclarationSQL($column), + $this->platform->getJsonTypeDeclarationSQL($column) ); } @@ -888,7 +893,7 @@ public function testAlterTableRenameIndex() self::assertSame( $this->getAlterTableRenameIndexSQL(), - $this->_platform->getAlterTableSQL($tableDiff) + $this->platform->getAlterTableSQL($tableDiff) ); } @@ -919,7 +924,7 @@ public function testQuotesAlterTableRenameIndex() self::assertSame( $this->getQuotedAlterTableRenameIndexSQL(), - $this->_platform->getAlterTableSQL($tableDiff) + $this->platform->getAlterTableSQL($tableDiff) ); } @@ -973,14 +978,14 @@ public function testQuotesAlterTableRenameColumn() self::assertEquals( $this->getQuotedAlterTableRenameColumnSQL(), - $this->_platform->getAlterTableSQL($comparator->diffTable($fromTable, $toTable)) + $this->platform->getAlterTableSQL($comparator->diffTable($fromTable, $toTable)) ); } /** * Returns SQL statements for {@link testQuotesAlterTableRenameColumn}. * - * @return array + * @return string[] * * @group DBAL-835 */ @@ -1015,14 +1020,14 @@ public function testQuotesAlterTableChangeColumnLength() self::assertEquals( $this->getQuotedAlterTableChangeColumnLengthSQL(), - $this->_platform->getAlterTableSQL($comparator->diffTable($fromTable, $toTable)) + $this->platform->getAlterTableSQL($comparator->diffTable($fromTable, $toTable)) ); } /** * Returns SQL statements for {@link testQuotesAlterTableChangeColumnLength}. * - * @return array + * @return string[] * * @group DBAL-835 */ @@ -1043,7 +1048,7 @@ public function testAlterTableRenameIndexInSchema() self::assertSame( $this->getAlterTableRenameIndexInSchemaSQL(), - $this->_platform->getAlterTableSQL($tableDiff) + $this->platform->getAlterTableSQL($tableDiff) ); } @@ -1074,7 +1079,7 @@ public function testQuotesAlterTableRenameIndexInSchema() self::assertSame( $this->getQuotedAlterTableRenameIndexInSchemaSQL(), - $this->_platform->getAlterTableSQL($tableDiff) + $this->platform->getAlterTableSQL($tableDiff) ); } @@ -1096,9 +1101,9 @@ protected function getQuotedAlterTableRenameIndexInSchemaSQL() */ public function testQuotesDropForeignKeySQL() { - if (! $this->_platform->supportsForeignKeyConstraints()) { + if (! $this->platform->supportsForeignKeyConstraints()) { $this->markTestSkipped( - sprintf('%s does not support foreign key constraints.', get_class($this->_platform)) + sprintf('%s does not support foreign key constraints.', get_class($this->platform)) ); } @@ -1108,8 +1113,8 @@ public function testQuotesDropForeignKeySQL() $foreignKey = new ForeignKeyConstraint([], 'foo', [], 'select'); $expectedSql = $this->getQuotesDropForeignKeySQL(); - self::assertSame($expectedSql, $this->_platform->getDropForeignKeySQL($foreignKeyName, $tableName)); - self::assertSame($expectedSql, $this->_platform->getDropForeignKeySQL($foreignKey, $table)); + self::assertSame($expectedSql, $this->platform->getDropForeignKeySQL($foreignKeyName, $tableName)); + self::assertSame($expectedSql, $this->platform->getDropForeignKeySQL($foreignKey, $table)); } protected function getQuotesDropForeignKeySQL() @@ -1128,8 +1133,8 @@ public function testQuotesDropConstraintSQL() $constraint = new ForeignKeyConstraint([], 'foo', [], 'select'); $expectedSql = $this->getQuotesDropConstraintSQL(); - self::assertSame($expectedSql, $this->_platform->getDropConstraintSQL($constraintName, $tableName)); - self::assertSame($expectedSql, $this->_platform->getDropConstraintSQL($constraint, $table)); + self::assertSame($expectedSql, $this->platform->getDropConstraintSQL($constraintName, $tableName)); + self::assertSame($expectedSql, $this->platform->getDropConstraintSQL($constraint, $table)); } protected function getQuotesDropConstraintSQL() @@ -1144,7 +1149,7 @@ protected function getStringLiteralQuoteCharacter() public function testGetStringLiteralQuoteCharacter() { - self::assertSame($this->getStringLiteralQuoteCharacter(), $this->_platform->getStringLiteralQuoteCharacter()); + self::assertSame($this->getStringLiteralQuoteCharacter(), $this->platform->getStringLiteralQuoteCharacter()); } protected function getQuotedCommentOnColumnSQLWithoutQuoteCharacter() @@ -1156,7 +1161,7 @@ public function testGetCommentOnColumnSQLWithoutQuoteCharacter() { self::assertEquals( $this->getQuotedCommentOnColumnSQLWithoutQuoteCharacter(), - $this->_platform->getCommentOnColumnSQL('mytable', 'id', 'This is a comment') + $this->platform->getCommentOnColumnSQL('mytable', 'id', 'This is a comment') ); } @@ -1171,14 +1176,14 @@ public function testGetCommentOnColumnSQLWithQuoteCharacter() self::assertEquals( $this->getQuotedCommentOnColumnSQLWithQuoteCharacter(), - $this->_platform->getCommentOnColumnSQL('mytable', 'id', 'It' . $c . 's a quote !') + $this->platform->getCommentOnColumnSQL('mytable', 'id', 'It' . $c . 's a quote !') ); } /** * @see testGetCommentOnColumnSQL * - * @return array + * @return string[] */ abstract protected function getCommentOnColumnSQL(); @@ -1190,9 +1195,9 @@ public function testGetCommentOnColumnSQL() self::assertSame( $this->getCommentOnColumnSQL(), [ - $this->_platform->getCommentOnColumnSQL('foo', 'bar', 'comment'), // regular identifiers - $this->_platform->getCommentOnColumnSQL('`Foo`', '`BAR`', 'comment'), // explicitly quoted identifiers - $this->_platform->getCommentOnColumnSQL('select', 'from', 'comment'), // reserved keyword identifiers + $this->platform->getCommentOnColumnSQL('foo', 'bar', 'comment'), // regular identifiers + $this->platform->getCommentOnColumnSQL('`Foo`', '`BAR`', 'comment'), // explicitly quoted identifiers + $this->platform->getCommentOnColumnSQL('select', 'from', 'comment'), // reserved keyword identifiers ] ); } @@ -1203,11 +1208,11 @@ public function testGetCommentOnColumnSQL() */ public function testGeneratesInlineColumnCommentSQL($comment, $expectedSql) { - if (! $this->_platform->supportsInlineColumnComments()) { - $this->markTestSkipped(sprintf('%s does not support inline column comments.', get_class($this->_platform))); + if (! $this->platform->supportsInlineColumnComments()) { + $this->markTestSkipped(sprintf('%s does not support inline column comments.', get_class($this->platform))); } - self::assertSame($expectedSql, $this->_platform->getInlineColumnCommentSQL($comment)); + self::assertSame($expectedSql, $this->platform->getInlineColumnCommentSQL($comment)); } public function getGeneratesInlineColumnCommentSQL() @@ -1265,15 +1270,15 @@ protected function getQuotedStringLiteralQuoteCharacter() */ public function testThrowsExceptionOnGeneratingInlineColumnCommentSQLIfUnsupported() { - if ($this->_platform->supportsInlineColumnComments()) { - $this->markTestSkipped(sprintf('%s supports inline column comments.', get_class($this->_platform))); + if ($this->platform->supportsInlineColumnComments()) { + $this->markTestSkipped(sprintf('%s supports inline column comments.', get_class($this->platform))); } - $this->expectException('Doctrine\DBAL\DBALException'); + $this->expectException(DBALException::class); $this->expectExceptionMessage("Operation 'Doctrine\\DBAL\\Platforms\\AbstractPlatform::getInlineColumnCommentSQL' is not supported by platform."); $this->expectExceptionCode(0); - $this->_platform->getInlineColumnCommentSQL('unsupported'); + $this->platform->getInlineColumnCommentSQL('unsupported'); } public function testQuoteStringLiteral() @@ -1282,15 +1287,15 @@ public function testQuoteStringLiteral() self::assertEquals( $this->getQuotedStringLiteralWithoutQuoteCharacter(), - $this->_platform->quoteStringLiteral('No quote') + $this->platform->quoteStringLiteral('No quote') ); self::assertEquals( $this->getQuotedStringLiteralWithQuoteCharacter(), - $this->_platform->quoteStringLiteral('It' . $c . 's a quote') + $this->platform->quoteStringLiteral('It' . $c . 's a quote') ); self::assertEquals( $this->getQuotedStringLiteralQuoteCharacter(), - $this->_platform->quoteStringLiteral($c) + $this->platform->quoteStringLiteral($c) ); } @@ -1300,7 +1305,7 @@ public function testQuoteStringLiteral() */ public function testReturnsGuidTypeDeclarationSQL() { - $this->_platform->getGuidTypeDeclarationSQL([]); + $this->platform->getGuidTypeDeclarationSQL([]); } /** @@ -1323,11 +1328,11 @@ public function testGeneratesAlterTableRenameColumnSQL() ['notnull' => true, 'default' => 666, 'comment' => 'rename test'] ); - self::assertSame($this->getAlterTableRenameColumnSQL(), $this->_platform->getAlterTableSQL($tableDiff)); + self::assertSame($this->getAlterTableRenameColumnSQL(), $this->platform->getAlterTableSQL($tableDiff)); } /** - * @return array + * @return string[] */ abstract public function getAlterTableRenameColumnSQL(); @@ -1364,12 +1369,12 @@ public function testQuotesTableIdentifiersInAlterTableSQL() self::assertSame( $this->getQuotesTableIdentifiersInAlterTableSQL(), - $this->_platform->getAlterTableSQL($tableDiff) + $this->platform->getAlterTableSQL($tableDiff) ); } /** - * @return array + * @return string[] */ abstract protected function getQuotesTableIdentifiersInAlterTableSQL(); @@ -1394,7 +1399,7 @@ public function testAlterStringToFixedString() ['fixed'] ); - $sql = $this->_platform->getAlterTableSQL($tableDiff); + $sql = $this->platform->getAlterTableSQL($tableDiff); $expectedSql = $this->getAlterStringToFixedStringSQL(); @@ -1402,7 +1407,7 @@ public function testAlterStringToFixedString() } /** - * @return array + * @return string[] */ abstract protected function getAlterStringToFixedStringSQL(); @@ -1430,26 +1435,28 @@ public function testGeneratesAlterTableRenameIndexUsedByForeignKeySQL() self::assertSame( $this->getGeneratesAlterTableRenameIndexUsedByForeignKeySQL(), - $this->_platform->getAlterTableSQL($tableDiff) + $this->platform->getAlterTableSQL($tableDiff) ); } /** - * @return array + * @return string[] */ abstract protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL(); /** + * @param mixed[] $column + * * @group DBAL-1082 * @dataProvider getGeneratesDecimalTypeDeclarationSQL */ public function testGeneratesDecimalTypeDeclarationSQL(array $column, $expectedSql) { - self::assertSame($expectedSql, $this->_platform->getDecimalTypeDeclarationSQL($column)); + self::assertSame($expectedSql, $this->platform->getDecimalTypeDeclarationSQL($column)); } /** - * @return array + * @return mixed[] */ public function getGeneratesDecimalTypeDeclarationSQL() { @@ -1464,16 +1471,18 @@ public function getGeneratesDecimalTypeDeclarationSQL() } /** + * @param mixed[] $column + * * @group DBAL-1082 * @dataProvider getGeneratesFloatDeclarationSQL */ public function testGeneratesFloatDeclarationSQL(array $column, $expectedSql) { - self::assertSame($expectedSql, $this->_platform->getFloatDeclarationSQL($column)); + self::assertSame($expectedSql, $this->platform->getFloatDeclarationSQL($column)); } /** - * @return array + * @return mixed[] */ public function getGeneratesFloatDeclarationSQL() { @@ -1491,7 +1500,7 @@ public function testItEscapesStringsForLike() : void { self::assertSame( '\_25\% off\_ your next purchase \\\\o/', - $this->_platform->escapeStringForLike('_25% off_ your next purchase \o/', '\\') + $this->platform->escapeStringForLike('_25% off_ your next purchase \o/', '\\') ); } @@ -1501,7 +1510,7 @@ public function testZeroOffsetWithoutLimitIsIgnored() : void self::assertSame( $query, - $this->_platform->modifyLimitQuery($query, null, 0) + $this->platform->modifyLimitQuery($query, null, 0) ); } } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php index 06b1604912b..5c0da268107 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 function sprintf; abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCase { @@ -63,7 +64,7 @@ public function testGeneratesForeignKeySqlForNonStandardOptions() ); self::assertEquals( 'CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE', - $this->_platform->getForeignKeyDeclarationSQL($foreignKey) + $this->platform->getForeignKeyDeclarationSQL($foreignKey) ); $foreignKey = new ForeignKeyConstraint( @@ -75,7 +76,7 @@ public function testGeneratesForeignKeySqlForNonStandardOptions() ); self::assertEquals( 'CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) MATCH full NOT DEFERRABLE INITIALLY IMMEDIATE', - $this->_platform->getForeignKeyDeclarationSQL($foreignKey) + $this->platform->getForeignKeyDeclarationSQL($foreignKey) ); $foreignKey = new ForeignKeyConstraint( @@ -87,7 +88,7 @@ public function testGeneratesForeignKeySqlForNonStandardOptions() ); self::assertEquals( 'CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) DEFERRABLE INITIALLY IMMEDIATE', - $this->_platform->getForeignKeyDeclarationSQL($foreignKey) + $this->platform->getForeignKeyDeclarationSQL($foreignKey) ); $foreignKey = new ForeignKeyConstraint( @@ -99,7 +100,7 @@ public function testGeneratesForeignKeySqlForNonStandardOptions() ); self::assertEquals( 'CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) NOT DEFERRABLE INITIALLY DEFERRED', - $this->_platform->getForeignKeyDeclarationSQL($foreignKey) + $this->platform->getForeignKeyDeclarationSQL($foreignKey) ); $foreignKey = new ForeignKeyConstraint( @@ -111,7 +112,7 @@ public function testGeneratesForeignKeySqlForNonStandardOptions() ); self::assertEquals( 'CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) NOT DEFERRABLE INITIALLY DEFERRED', - $this->_platform->getForeignKeyDeclarationSQL($foreignKey) + $this->platform->getForeignKeyDeclarationSQL($foreignKey) ); $foreignKey = new ForeignKeyConstraint( @@ -123,44 +124,44 @@ public function testGeneratesForeignKeySqlForNonStandardOptions() ); self::assertEquals( 'CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) MATCH full DEFERRABLE INITIALLY DEFERRED', - $this->_platform->getForeignKeyDeclarationSQL($foreignKey) + $this->platform->getForeignKeyDeclarationSQL($foreignKey) ); } public function testGeneratesSqlSnippets() { - self::assertEquals('SIMILAR TO', $this->_platform->getRegexpExpression(), 'Regular expression operator is not correct'); - 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'); - self::assertEquals('SUBSTRING(column FROM 5)', $this->_platform->getSubstringExpression('column', 5), 'Substring expression without length is not correct'); - self::assertEquals('SUBSTRING(column FROM 1 FOR 5)', $this->_platform->getSubstringExpression('column', 1, 5), 'Substring expression with length is not correct'); + self::assertEquals('SIMILAR TO', $this->platform->getRegexpExpression(), 'Regular expression operator is not correct'); + 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'); + self::assertEquals('SUBSTRING(column FROM 5)', $this->platform->getSubstringExpression('column', 5), 'Substring expression without length is not correct'); + self::assertEquals('SUBSTRING(column FROM 1 FOR 5)', $this->platform->getSubstringExpression('column', 1, 5), 'Substring expression with length is not correct'); } public function testGeneratesTransactionCommands() { self::assertEquals( 'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ UNCOMMITTED', - $this->_platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_UNCOMMITTED) + $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_UNCOMMITTED) ); self::assertEquals( 'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ COMMITTED', - $this->_platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_COMMITTED) + $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_COMMITTED) ); self::assertEquals( 'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL REPEATABLE READ', - $this->_platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::REPEATABLE_READ) + $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::REPEATABLE_READ) ); self::assertEquals( 'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL SERIALIZABLE', - $this->_platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::SERIALIZABLE) + $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::SERIALIZABLE) ); } public function testGeneratesDDLSnippets() { - 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')); + 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() @@ -169,9 +170,12 @@ public function testGenerateTableWithAutoincrement() $column = $table->addColumn('id', 'integer'); $column->setAutoincrement(true); - self::assertEquals(['CREATE TABLE autoinc_table (id SERIAL NOT NULL)'], $this->_platform->getCreateTableSQL($table)); + self::assertEquals(['CREATE TABLE autoinc_table (id SERIAL NOT NULL)'], $this->platform->getCreateTableSQL($table)); } + /** + * @return string[][] + */ public static function serialTypes() : array { return [ @@ -191,9 +195,9 @@ public function testGenerateTableWithAutoincrementDoesNotSetDefault(string $type $column->setAutoIncrement(true); $column->setNotNull(false); - $sql = $this->_platform->getCreateTableSQL($table); + $sql = $this->platform->getCreateTableSQL($table); - self::assertEquals(["CREATE TABLE autoinc_table_notnull (id $definition)"], $sql); + self::assertEquals([sprintf('CREATE TABLE autoinc_table_notnull (id %s)', $definition)], $sql); } /** @@ -207,9 +211,9 @@ public function testCreateTableWithAutoincrementAndNotNullAddsConstraint(string $column->setAutoIncrement(true); $column->setNotNull(true); - $sql = $this->_platform->getCreateTableSQL($table); + $sql = $this->platform->getCreateTableSQL($table); - self::assertEquals(["CREATE TABLE autoinc_table_notnull_enabled (id $definition NOT NULL)"], $sql); + self::assertEquals([sprintf('CREATE TABLE autoinc_table_notnull_enabled (id %s NOT NULL)', $definition)], $sql); } /** @@ -218,7 +222,7 @@ public function testCreateTableWithAutoincrementAndNotNullAddsConstraint(string */ public function testGetDefaultValueDeclarationSQLIgnoresTheDefaultKeyWhenTheFieldIsSerial(string $type) : void { - $sql = $this->_platform->getDefaultValueDeclarationSQL( + $sql = $this->platform->getDefaultValueDeclarationSQL( [ 'autoincrement' => true, 'type' => Type::getType($type), @@ -233,15 +237,15 @@ public function testGeneratesTypeDeclarationForIntegers() { self::assertEquals( 'INT', - $this->_platform->getIntegerTypeDeclarationSQL([]) + $this->platform->getIntegerTypeDeclarationSQL([]) ); self::assertEquals( 'SERIAL', - $this->_platform->getIntegerTypeDeclarationSQL(['autoincrement' => true]) + $this->platform->getIntegerTypeDeclarationSQL(['autoincrement' => true]) ); self::assertEquals( 'SERIAL', - $this->_platform->getIntegerTypeDeclarationSQL( + $this->platform->getIntegerTypeDeclarationSQL( ['autoincrement' => true, 'primary' => true] ) ); @@ -251,18 +255,18 @@ public function testGeneratesTypeDeclarationForStrings() { self::assertEquals( 'CHAR(10)', - $this->_platform->getVarcharTypeDeclarationSQL( + $this->platform->getVarcharTypeDeclarationSQL( ['length' => 10, 'fixed' => true] ) ); self::assertEquals( 'VARCHAR(50)', - $this->_platform->getVarcharTypeDeclarationSQL(['length' => 50]), + $this->platform->getVarcharTypeDeclarationSQL(['length' => 50]), 'Variable string declaration is not correct' ); self::assertEquals( 'VARCHAR(255)', - $this->_platform->getVarcharTypeDeclarationSQL([]), + $this->platform->getVarcharTypeDeclarationSQL([]), 'Long string declaration is not correct' ); } @@ -277,41 +281,41 @@ public function testGeneratesSequenceSqlCommands() $sequence = new Sequence('myseq', 20, 1); self::assertEquals( 'CREATE SEQUENCE myseq INCREMENT BY 20 MINVALUE 1 START 1', - $this->_platform->getCreateSequenceSQL($sequence) + $this->platform->getCreateSequenceSQL($sequence) ); self::assertEquals( 'DROP SEQUENCE myseq CASCADE', - $this->_platform->getDropSequenceSQL('myseq') + $this->platform->getDropSequenceSQL('myseq') ); self::assertEquals( "SELECT NEXTVAL('myseq')", - $this->_platform->getSequenceNextValSQL('myseq') + $this->platform->getSequenceNextValSQL('myseq') ); } public function testDoesNotPreferIdentityColumns() { - self::assertFalse($this->_platform->prefersIdentityColumns()); + self::assertFalse($this->platform->prefersIdentityColumns()); } public function testPrefersSequences() { - self::assertTrue($this->_platform->prefersSequences()); + self::assertTrue($this->platform->prefersSequences()); } public function testSupportsIdentityColumns() { - self::assertTrue($this->_platform->supportsIdentityColumns()); + self::assertTrue($this->platform->supportsIdentityColumns()); } public function testSupportsSavePoints() { - self::assertTrue($this->_platform->supportsSavepoints()); + self::assertTrue($this->platform->supportsSavepoints()); } public function testSupportsSequences() { - self::assertTrue($this->_platform->supportsSequences()); + self::assertTrue($this->platform->supportsSequences()); } /** @@ -324,13 +328,13 @@ protected function supportsCommentOnStatement() public function testModifyLimitQuery() { - $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0); + $sql = $this->platform->modifyLimitQuery('SELECT * FROM user', 10, 0); self::assertEquals('SELECT * FROM user LIMIT 10', $sql); } public function testModifyLimitQueryWithEmptyOffset() { - $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10); + $sql = $this->platform->modifyLimitQuery('SELECT * FROM user', 10); self::assertEquals('SELECT * FROM user LIMIT 10', $sql); } @@ -485,7 +489,7 @@ public function testThrowsExceptionWithInvalidBooleanLiteral() public function testGetCreateSchemaSQL() { $schemaName = 'schema'; - $sql = $this->_platform->getCreateSchemaSQL($schemaName); + $sql = $this->platform->getCreateSchemaSQL($schemaName); self::assertEquals('CREATE SCHEMA ' . $schemaName, $sql); } @@ -537,7 +541,7 @@ public function testAlterDecimalPrecisionScale() ['precision', 'scale'] ); - $sql = $this->_platform->getAlterTableSQL($tableDiff); + $sql = $this->platform->getAlterTableSQL($tableDiff); $expectedSql = [ 'ALTER TABLE mytable ALTER dloo1 TYPE NUMERIC(16, 6)', @@ -564,7 +568,7 @@ public function testDroppingConstraintsBeforeColumns() $comparator = new Comparator(); $tableDiff = $comparator->diffTable($oldTable, $newTable); - $sql = $this->_platform->getAlterTableSQL($tableDiff); + $sql = $this->platform->getAlterTableSQL($tableDiff); $expectedSql = [ 'ALTER TABLE mytable DROP CONSTRAINT FK_6B2BD609727ACA70', @@ -580,7 +584,7 @@ public function testDroppingConstraintsBeforeColumns() */ public function testUsesSequenceEmulatedIdentityColumns() { - self::assertTrue($this->_platform->usesSequenceEmulatedIdentityColumns()); + self::assertTrue($this->platform->usesSequenceEmulatedIdentityColumns()); } /** @@ -588,7 +592,7 @@ public function testUsesSequenceEmulatedIdentityColumns() */ public function testReturnsIdentitySequenceName() { - self::assertSame('mytable_mycolumn_seq', $this->_platform->getIdentitySequenceName('mytable', 'mycolumn')); + self::assertSame('mytable_mycolumn_seq', $this->platform->getIdentitySequenceName('mytable', 'mycolumn')); } /** @@ -598,7 +602,7 @@ public function testReturnsIdentitySequenceName() public function testCreateSequenceWithCache($cacheSize, $expectedSql) { $sequence = new Sequence('foo', 1, 1, $cacheSize); - self::assertContains($expectedSql, $this->_platform->getCreateSequenceSQL($sequence)); + self::assertContains($expectedSql, $this->platform->getCreateSequenceSQL($sequence)); } public function dataCreateSequenceWithCache() @@ -620,13 +624,13 @@ protected function getBinaryMaxLength() public function testReturnsBinaryTypeDeclarationSQL() { - self::assertSame('BYTEA', $this->_platform->getBinaryTypeDeclarationSQL([])); - self::assertSame('BYTEA', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 0])); - self::assertSame('BYTEA', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 9999999])); + self::assertSame('BYTEA', $this->platform->getBinaryTypeDeclarationSQL([])); + self::assertSame('BYTEA', $this->platform->getBinaryTypeDeclarationSQL(['length' => 0])); + self::assertSame('BYTEA', $this->platform->getBinaryTypeDeclarationSQL(['length' => 9999999])); - self::assertSame('BYTEA', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true])); - self::assertSame('BYTEA', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 0])); - self::assertSame('BYTEA', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 9999999])); + self::assertSame('BYTEA', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true])); + self::assertSame('BYTEA', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 0])); + self::assertSame('BYTEA', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 9999999])); } public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType() @@ -646,7 +650,7 @@ public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType() // VARBINARY -> BINARY // BINARY -> VARBINARY // BLOB -> VARBINARY - self::assertEmpty($this->_platform->getAlterTableSQL($comparator->diffTable($table1, $table2))); + self::assertEmpty($this->platform->getAlterTableSQL($comparator->diffTable($table1, $table2))); $table2 = new Table('mytable'); $table2->addColumn('column_varbinary', 'binary', ['length' => 42]); @@ -656,7 +660,7 @@ public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType() // VARBINARY -> VARBINARY with changed length // BINARY -> BLOB // BLOB -> BINARY - self::assertEmpty($this->_platform->getAlterTableSQL($comparator->diffTable($table1, $table2))); + self::assertEmpty($this->platform->getAlterTableSQL($comparator->diffTable($table1, $table2))); $table2 = new Table('mytable'); $table2->addColumn('column_varbinary', 'blob'); @@ -666,7 +670,7 @@ public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType() // VARBINARY -> BLOB // BINARY -> BINARY with changed length // BLOB -> BLOB - self::assertEmpty($this->_platform->getAlterTableSQL($comparator->diffTable($table1, $table2))); + self::assertEmpty($this->platform->getAlterTableSQL($comparator->diffTable($table1, $table2))); } /** @@ -691,7 +695,7 @@ protected function getQuotedAlterTableRenameIndexSQL() /** * PostgreSQL boolean strings provider * - * @return array + * @return mixed[] */ public function pgBooleanProvider() { @@ -778,7 +782,7 @@ public function testGetNullCommentOnColumnSQL() { self::assertEquals( 'COMMENT ON COLUMN mytable.id IS NULL', - $this->_platform->getCommentOnColumnSQL('mytable', 'id', null) + $this->platform->getCommentOnColumnSQL('mytable', 'id', null) ); } @@ -787,7 +791,7 @@ public function testGetNullCommentOnColumnSQL() */ public function testReturnsGuidTypeDeclarationSQL() { - self::assertSame('UUID', $this->_platform->getGuidTypeDeclarationSQL([])); + self::assertSame('UUID', $this->platform->getGuidTypeDeclarationSQL([])); } /** @@ -842,10 +846,10 @@ public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() $tableDiff = $comparator->diffTable($table1, $table2); - self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); + self::assertInstanceOf(TableDiff::class, $tableDiff); self::assertSame( ['COMMENT ON COLUMN "foo"."bar" IS \'baz\''], - $this->_platform->getAlterTableSQL($tableDiff) + $this->platform->getAlterTableSQL($tableDiff) ); } @@ -894,8 +898,8 @@ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() */ public function testInitializesTsvectorTypeMapping() { - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('tsvector')); - self::assertEquals('text', $this->_platform->getDoctrineTypeMapping('tsvector')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('tsvector')); + self::assertEquals('text', $this->platform->getDoctrineTypeMapping('tsvector')); } /** @@ -905,7 +909,7 @@ public function testReturnsDisallowDatabaseConnectionsSQL() { self::assertSame( "UPDATE pg_database SET datallowconn = 'false' WHERE datname = 'foo'", - $this->_platform->getDisallowDatabaseConnectionsSQL('foo') + $this->platform->getDisallowDatabaseConnectionsSQL('foo') ); } @@ -916,7 +920,7 @@ public function testReturnsCloseActiveDatabaseConnectionsSQL() { self::assertSame( "SELECT pg_terminate_backend(procpid) FROM pg_stat_activity WHERE datname = 'foo'", - $this->_platform->getCloseActiveDatabaseConnectionsSQL('foo') + $this->platform->getCloseActiveDatabaseConnectionsSQL('foo') ); } @@ -925,7 +929,7 @@ public function testReturnsCloseActiveDatabaseConnectionsSQL() */ public function testQuotesTableNameInListTableForeignKeysSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true); } /** @@ -935,7 +939,7 @@ public function testQuotesSchemaNameInListTableForeignKeysSQL() { self::assertContains( "'Foo''Bar\\\\'", - $this->_platform->getListTableForeignKeysSQL("Foo'Bar\\.baz_table"), + $this->platform->getListTableForeignKeysSQL("Foo'Bar\\.baz_table"), '', true ); @@ -946,7 +950,7 @@ public function testQuotesSchemaNameInListTableForeignKeysSQL() */ public function testQuotesTableNameInListTableConstraintsSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true); } /** @@ -954,7 +958,7 @@ public function testQuotesTableNameInListTableConstraintsSQL() */ public function testQuotesTableNameInListTableIndexesSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableIndexesSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\"), '', true); } /** @@ -964,7 +968,7 @@ public function testQuotesSchemaNameInListTableIndexesSQL() { self::assertContains( "'Foo''Bar\\\\'", - $this->_platform->getListTableIndexesSQL("Foo'Bar\\.baz_table"), + $this->platform->getListTableIndexesSQL("Foo'Bar\\.baz_table"), '', true ); @@ -975,7 +979,7 @@ public function testQuotesSchemaNameInListTableIndexesSQL() */ public function testQuotesTableNameInListTableColumnsSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableColumnsSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableColumnsSQL("Foo'Bar\\"), '', true); } /** @@ -985,7 +989,7 @@ public function testQuotesSchemaNameInListTableColumnsSQL() { self::assertContains( "'Foo''Bar\\\\'", - $this->_platform->getListTableColumnsSQL("Foo'Bar\\.baz_table"), + $this->platform->getListTableColumnsSQL("Foo'Bar\\.baz_table"), '', true ); @@ -998,7 +1002,7 @@ public function testQuotesDatabaseNameInCloseActiveDatabaseConnectionsSQL() { self::assertContains( "'Foo''Bar\\\\'", - $this->_platform->getCloseActiveDatabaseConnectionsSQL("Foo'Bar\\"), + $this->platform->getCloseActiveDatabaseConnectionsSQL("Foo'Bar\\"), '', true ); diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php index ef75fa7dfe6..1341c9e8819 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php @@ -52,35 +52,35 @@ public function getGenerateAlterTableSql() */ public function testDoesNotSupportRegexp() { - $this->_platform->getRegexpExpression(); + $this->platform->getRegexpExpression(); } public function testGeneratesSqlSnippets() { - self::assertEquals('CONVERT(date, GETDATE())', $this->_platform->getCurrentDateSQL()); - self::assertEquals('CONVERT(time, GETDATE())', $this->_platform->getCurrentTimeSQL()); - self::assertEquals('CURRENT_TIMESTAMP', $this->_platform->getCurrentTimestampSQL()); - 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'); + self::assertEquals('CONVERT(date, GETDATE())', $this->platform->getCurrentDateSQL()); + self::assertEquals('CONVERT(time, GETDATE())', $this->platform->getCurrentTimeSQL()); + self::assertEquals('CURRENT_TIMESTAMP', $this->platform->getCurrentTimestampSQL()); + 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() { self::assertEquals( 'SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED', - $this->_platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_UNCOMMITTED) + $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_UNCOMMITTED) ); self::assertEquals( 'SET TRANSACTION ISOLATION LEVEL READ COMMITTED', - $this->_platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_COMMITTED) + $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_COMMITTED) ); self::assertEquals( 'SET TRANSACTION ISOLATION LEVEL REPEATABLE READ', - $this->_platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::REPEATABLE_READ) + $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::REPEATABLE_READ) ); self::assertEquals( 'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE', - $this->_platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::SERIALIZABLE) + $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::SERIALIZABLE) ); } @@ -88,25 +88,25 @@ public function testGeneratesDDLSnippets() { $dropDatabaseExpectation = 'DROP DATABASE foobar'; - self::assertEquals('SELECT * FROM sys.databases', $this->_platform->getListDatabasesSQL()); - self::assertEquals('CREATE DATABASE foobar', $this->_platform->getCreateDatabaseSQL('foobar')); - self::assertEquals($dropDatabaseExpectation, $this->_platform->getDropDatabaseSQL('foobar')); - self::assertEquals('DROP TABLE foobar', $this->_platform->getDropTableSQL('foobar')); + self::assertEquals('SELECT * FROM sys.databases', $this->platform->getListDatabasesSQL()); + self::assertEquals('CREATE DATABASE foobar', $this->platform->getCreateDatabaseSQL('foobar')); + self::assertEquals($dropDatabaseExpectation, $this->platform->getDropDatabaseSQL('foobar')); + self::assertEquals('DROP TABLE foobar', $this->platform->getDropTableSQL('foobar')); } public function testGeneratesTypeDeclarationForIntegers() { self::assertEquals( 'INT', - $this->_platform->getIntegerTypeDeclarationSQL([]) + $this->platform->getIntegerTypeDeclarationSQL([]) ); self::assertEquals( 'INT IDENTITY', - $this->_platform->getIntegerTypeDeclarationSQL(['autoincrement' => true]) + $this->platform->getIntegerTypeDeclarationSQL(['autoincrement' => true]) ); self::assertEquals( 'INT IDENTITY', - $this->_platform->getIntegerTypeDeclarationSQL( + $this->platform->getIntegerTypeDeclarationSQL( ['autoincrement' => true, 'primary' => true] ) ); @@ -116,50 +116,50 @@ public function testGeneratesTypeDeclarationsForStrings() { self::assertEquals( 'NCHAR(10)', - $this->_platform->getVarcharTypeDeclarationSQL( + $this->platform->getVarcharTypeDeclarationSQL( ['length' => 10, 'fixed' => true] ) ); self::assertEquals( 'NVARCHAR(50)', - $this->_platform->getVarcharTypeDeclarationSQL(['length' => 50]), + $this->platform->getVarcharTypeDeclarationSQL(['length' => 50]), 'Variable string declaration is not correct' ); self::assertEquals( 'NVARCHAR(255)', - $this->_platform->getVarcharTypeDeclarationSQL([]), + $this->platform->getVarcharTypeDeclarationSQL([]), 'Long string declaration is not correct' ); - self::assertSame('VARCHAR(MAX)', $this->_platform->getClobTypeDeclarationSQL([])); + self::assertSame('VARCHAR(MAX)', $this->platform->getClobTypeDeclarationSQL([])); self::assertSame( 'VARCHAR(MAX)', - $this->_platform->getClobTypeDeclarationSQL(['length' => 5, 'fixed' => true]) + $this->platform->getClobTypeDeclarationSQL(['length' => 5, 'fixed' => true]) ); } public function testPrefersIdentityColumns() { - self::assertTrue($this->_platform->prefersIdentityColumns()); + self::assertTrue($this->platform->prefersIdentityColumns()); } public function testSupportsIdentityColumns() { - self::assertTrue($this->_platform->supportsIdentityColumns()); + self::assertTrue($this->platform->supportsIdentityColumns()); } public function testSupportsCreateDropDatabase() { - self::assertTrue($this->_platform->supportsCreateDropDatabase()); + self::assertTrue($this->platform->supportsCreateDropDatabase()); } public function testSupportsSchemas() { - self::assertTrue($this->_platform->supportsSchemas()); + self::assertTrue($this->platform->supportsSchemas()); } public function testDoesNotSupportSavePoints() { - self::assertTrue($this->_platform->supportsSavepoints()); + self::assertTrue($this->platform->supportsSavepoints()); } public function getGenerateIndexSql() @@ -181,7 +181,7 @@ public function testModifyLimitQuery() { $querySql = 'SELECT * FROM user'; $alteredSql = 'SELECT TOP 10 * FROM user'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10, 0); + $sql = $this->platform->modifyLimitQuery($querySql, 10, 0); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } @@ -189,19 +189,19 @@ public function testModifyLimitQueryWithEmptyOffset() { $querySql = 'SELECT * FROM user'; $alteredSql = 'SELECT TOP 10 * FROM user'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } public function testModifyLimitQueryWithOffset() { - if (! $this->_platform->supportsLimitOffset()) { - $this->markTestSkipped(sprintf('Platform "%s" does not support offsets in result limiting.', $this->_platform->getName())); + if (! $this->platform->supportsLimitOffset()) { + $this->markTestSkipped(sprintf('Platform "%s" does not support offsets in result limiting.', $this->platform->getName())); } $querySql = 'SELECT * FROM user ORDER BY username DESC'; $alteredSql = 'SELECT TOP 15 * FROM user ORDER BY username DESC'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10, 5); + $sql = $this->platform->modifyLimitQuery($querySql, 10, 5); $this->expectCteWithMinAndMaxRowNums($alteredSql, 6, 15, $sql); } @@ -210,7 +210,7 @@ public function testModifyLimitQueryWithAscOrderBy() { $querySql = 'SELECT * FROM user ORDER BY username ASC'; $alteredSql = 'SELECT TOP 10 * FROM user ORDER BY username ASC'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } @@ -219,7 +219,7 @@ public function testModifyLimitQueryWithLowercaseOrderBy() { $querySql = 'SELECT * FROM user order by username'; $alteredSql = 'SELECT TOP 10 * FROM user order by username'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } @@ -227,7 +227,7 @@ public function testModifyLimitQueryWithDescOrderBy() { $querySql = 'SELECT * FROM user ORDER BY username DESC'; $alteredSql = 'SELECT TOP 10 * FROM user ORDER BY username DESC'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } @@ -235,7 +235,7 @@ public function testModifyLimitQueryWithMultipleOrderBy() { $querySql = 'SELECT * FROM user ORDER BY username DESC, usereamil ASC'; $alteredSql = 'SELECT TOP 10 * FROM user ORDER BY username DESC, usereamil ASC'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } @@ -243,7 +243,7 @@ public function testModifyLimitQueryWithSubSelect() { $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'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } @@ -251,34 +251,34 @@ public function testModifyLimitQueryWithSubSelectAndOrder() { $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'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); $querySql = 'SELECT * FROM (SELECT u.id, u.name ORDER BY u.name DESC) dctrn_result'; $alteredSql = 'SELECT TOP 10 * FROM (SELECT u.id, u.name) dctrn_result'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } public function testModifyLimitQueryWithSubSelectAndMultipleOrder() { - if (! $this->_platform->supportsLimitOffset()) { - $this->markTestSkipped(sprintf('Platform "%s" does not support offsets in result limiting.', $this->_platform->getName())); + if (! $this->platform->supportsLimitOffset()) { + $this->markTestSkipped(sprintf('Platform "%s" does not support offsets in result limiting.', $this->platform->getName())); } $querySql = 'SELECT * FROM (SELECT u.id as uid, u.name as uname ORDER BY u.name DESC, id ASC) dctrn_result'; $alteredSql = 'SELECT TOP 15 * FROM (SELECT u.id as uid, u.name as uname) dctrn_result'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10, 5); + $sql = $this->platform->modifyLimitQuery($querySql, 10, 5); $this->expectCteWithMinAndMaxRowNums($alteredSql, 6, 15, $sql); $querySql = 'SELECT * FROM (SELECT u.id uid, u.name uname ORDER BY u.name DESC, id ASC) dctrn_result'; $alteredSql = 'SELECT TOP 15 * FROM (SELECT u.id uid, u.name uname) dctrn_result'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10, 5); + $sql = $this->platform->modifyLimitQuery($querySql, 10, 5); $this->expectCteWithMinAndMaxRowNums($alteredSql, 6, 15, $sql); $querySql = 'SELECT * FROM (SELECT u.id, u.name ORDER BY u.name DESC, id ASC) dctrn_result'; $alteredSql = 'SELECT TOP 15 * FROM (SELECT u.id, u.name) dctrn_result'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10, 5); + $sql = $this->platform->modifyLimitQuery($querySql, 10, 5); $this->expectCteWithMinAndMaxRowNums($alteredSql, 6, 15, $sql); } @@ -286,7 +286,7 @@ public function testModifyLimitQueryWithFromColumnNames() { $querySql = 'SELECT a.fromFoo, fromBar FROM foo'; $alteredSql = 'SELECT TOP 10 a.fromFoo, fromBar FROM foo'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } @@ -305,7 +305,7 @@ public function testModifyLimitQueryWithExtraLongQuery() $alteredSql .= 'AND (table2.column2 = table7.column7) AND (table2.column2 = table8.column8) AND (table3.column3 = table4.column4) AND (table3.column3 = table5.column5) AND (table3.column3 = table6.column6) AND (table3.column3 = table7.column7) AND (table3.column3 = table8.column8) AND (table4.column4 = table5.column5) AND (table4.column4 = table6.column6) AND (table4.column4 = table7.column7) AND (table4.column4 = table8.column8) '; $alteredSql .= 'AND (table5.column5 = table6.column6) AND (table5.column5 = table7.column7) AND (table5.column5 = table8.column8) AND (table6.column6 = table7.column7) AND (table6.column6 = table8.column8) AND (table7.column7 = table8.column8)'; - $sql = $this->_platform->modifyLimitQuery($query, 10); + $sql = $this->platform->modifyLimitQuery($query, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } @@ -314,13 +314,13 @@ public function testModifyLimitQueryWithExtraLongQuery() */ public function testModifyLimitQueryWithOrderByClause() { - if (! $this->_platform->supportsLimitOffset()) { - $this->markTestSkipped(sprintf('Platform "%s" does not support offsets in result limiting.', $this->_platform->getName())); + if (! $this->platform->supportsLimitOffset()) { + $this->markTestSkipped(sprintf('Platform "%s" does not support offsets in result limiting.', $this->platform->getName())); } $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'; $alteredSql = 'SELECT TOP 15 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'; - $actual = $this->_platform->modifyLimitQuery($sql, 10, 5); + $actual = $this->platform->modifyLimitQuery($sql, 10, 5); $this->expectCteWithMinAndMaxRowNums($alteredSql, 6, 15, $actual); } @@ -344,7 +344,7 @@ public function testModifyLimitQueryWithSubSelectInSelectList() '(SELECT (SELECT COUNT(*) FROM login l WHERE l.profile_id = p.id) FROM profile p WHERE p.user_id = u.id) login_count ' . 'FROM user u ' . "WHERE u.status = 'disabled'"; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } @@ -354,8 +354,8 @@ public function testModifyLimitQueryWithSubSelectInSelectList() */ public function testModifyLimitQueryWithSubSelectInSelectListAndOrderByClause() { - if (! $this->_platform->supportsLimitOffset()) { - $this->markTestSkipped(sprintf('Platform "%s" does not support offsets in result limiting.', $this->_platform->getName())); + if (! $this->platform->supportsLimitOffset()) { + $this->markTestSkipped(sprintf('Platform "%s" does not support offsets in result limiting.', $this->platform->getName())); } $querySql = 'SELECT ' . @@ -374,7 +374,7 @@ public function testModifyLimitQueryWithSubSelectInSelectListAndOrderByClause() 'FROM user u ' . "WHERE u.status = 'disabled' " . 'ORDER BY u.username DESC'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10, 5); + $sql = $this->platform->modifyLimitQuery($querySql, 10, 5); $this->expectCteWithMinAndMaxRowNums($alteredSql, 6, 15, $sql); } @@ -395,7 +395,7 @@ public function testModifyLimitQueryWithAggregateFunctionInOrderByClause() 'FROM operator_model_operator ' . 'GROUP BY code ' . 'ORDER BY MAX(heading_id) DESC'; - $sql = $this->_platform->modifyLimitQuery($querySql, 1, 0); + $sql = $this->platform->modifyLimitQuery($querySql, 1, 0); $this->expectCteWithMaxRowNum($alteredSql, 1, $sql); } @@ -419,7 +419,7 @@ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromBas . 'LEFT JOIN join_table t2 ON t1.id = t2.table_id' . ') dctrn_result ' . 'ORDER BY id_0 ASC'; - $sql = $this->_platform->modifyLimitQuery($querySql, 5); + $sql = $this->platform->modifyLimitQuery($querySql, 5); $this->expectCteWithMaxRowNum($alteredSql, 5, $sql); } @@ -443,7 +443,7 @@ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromJoi . 'LEFT JOIN join_table t2 ON t1.id = t2.table_id' . ') dctrn_result ' . 'ORDER BY name_1 ASC'; - $sql = $this->_platform->modifyLimitQuery($querySql, 5); + $sql = $this->platform->modifyLimitQuery($querySql, 5); $this->expectCteWithMaxRowNum($alteredSql, 5, $sql); } @@ -467,7 +467,7 @@ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnsFromBo . 'LEFT JOIN join_table t2 ON t1.id = t2.table_id' . ') dctrn_result ' . 'ORDER BY name_1 ASC, foo_2 DESC'; - $sql = $this->_platform->modifyLimitQuery($querySql, 5); + $sql = $this->platform->modifyLimitQuery($querySql, 5); $this->expectCteWithMaxRowNum($alteredSql, 5, $sql); } @@ -478,7 +478,7 @@ public function testModifyLimitSubquerySimple() . 'FROM key_table k0_ WHERE (k0_.where_field IN (1))) dctrn_result'; $alteredSql = 'SELECT DISTINCT TOP 20 id_0 FROM (SELECT k0_.id AS id_0, k0_.field AS field_1 ' . 'FROM key_table k0_ WHERE (k0_.where_field IN (1))) dctrn_result'; - $sql = $this->_platform->modifyLimitQuery($querySql, 20); + $sql = $this->platform->modifyLimitQuery($querySql, 20); $this->expectCteWithMaxRowNum($alteredSql, 20, $sql); } @@ -487,9 +487,9 @@ public function testModifyLimitSubquerySimple() */ public function testQuoteIdentifier() { - self::assertEquals('[fo][o]', $this->_platform->quoteIdentifier('fo]o')); - self::assertEquals('[test]', $this->_platform->quoteIdentifier('test')); - self::assertEquals('[test].[test]', $this->_platform->quoteIdentifier('test.test')); + self::assertEquals('[fo][o]', $this->platform->quoteIdentifier('fo]o')); + self::assertEquals('[test]', $this->platform->quoteIdentifier('test')); + self::assertEquals('[test].[test]', $this->platform->quoteIdentifier('test.test')); } /** @@ -497,9 +497,9 @@ public function testQuoteIdentifier() */ public function testQuoteSingleIdentifier() { - self::assertEquals('[fo][o]', $this->_platform->quoteSingleIdentifier('fo]o')); - self::assertEquals('[test]', $this->_platform->quoteSingleIdentifier('test')); - self::assertEquals('[test.test]', $this->_platform->quoteSingleIdentifier('test.test')); + self::assertEquals('[fo][o]', $this->platform->quoteSingleIdentifier('fo]o')); + self::assertEquals('[test]', $this->platform->quoteSingleIdentifier('test')); + self::assertEquals('[test.test]', $this->platform->quoteSingleIdentifier('test.test')); } /** @@ -509,7 +509,7 @@ public function testCreateClusteredIndex() { $idx = new Index('idx', ['id']); $idx->addFlag('clustered'); - self::assertEquals('CREATE CLUSTERED INDEX idx ON tbl (id)', $this->_platform->getCreateIndexSQL($idx, 'tbl')); + self::assertEquals('CREATE CLUSTERED INDEX idx ON tbl (id)', $this->platform->getCreateIndexSQL($idx, 'tbl')); } /** @@ -522,7 +522,7 @@ public function testCreateNonClusteredPrimaryKeyInTable() $table->setPrimaryKey(['id']); $table->getIndex('primary')->addFlag('nonclustered'); - self::assertEquals(['CREATE TABLE tbl (id INT NOT NULL, PRIMARY KEY NONCLUSTERED (id))'], $this->_platform->getCreateTableSQL($table)); + self::assertEquals(['CREATE TABLE tbl (id INT NOT NULL, PRIMARY KEY NONCLUSTERED (id))'], $this->platform->getCreateTableSQL($table)); } /** @@ -532,13 +532,13 @@ public function testCreateNonClusteredPrimaryKey() { $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')); + self::assertEquals('ALTER TABLE tbl ADD PRIMARY KEY NONCLUSTERED (id)', $this->platform->getCreatePrimaryKeySQL($idx, 'tbl')); } public function testAlterAddPrimaryKey() { $idx = new Index('idx', ['id'], false, true); - self::assertEquals('ALTER TABLE tbl ADD PRIMARY KEY (id)', $this->_platform->getCreateIndexSQL($idx, 'tbl')); + self::assertEquals('ALTER TABLE tbl ADD PRIMARY KEY (id)', $this->platform->getCreateIndexSQL($idx, 'tbl')); } protected function getQuotedColumnInPrimaryKeySQL() @@ -575,7 +575,7 @@ protected function getQuotedColumnInForeignKeySQL() public function testGetCreateSchemaSQL() { $schemaName = 'schema'; - $sql = $this->_platform->getCreateSchemaSQL($schemaName); + $sql = $this->platform->getCreateSchemaSQL($schemaName); self::assertEquals('CREATE SCHEMA ' . $schemaName, $sql); } @@ -590,7 +590,7 @@ public function testCreateTableWithSchemaColumnComments() "EXEC sp_addextendedproperty N'MS_Description', N'This is a comment', N'SCHEMA', 'testschema', N'TABLE', 'test', N'COLUMN', id", ]; - self::assertEquals($expectedSql, $this->_platform->getCreateTableSQL($table)); + self::assertEquals($expectedSql, $this->platform->getCreateTableSQL($table)); } public function testAlterTableWithSchemaColumnComments() @@ -603,7 +603,7 @@ public function testAlterTableWithSchemaColumnComments() "EXEC sp_addextendedproperty N'MS_Description', N'A comment', N'SCHEMA', 'testschema', N'TABLE', 'mytable', N'COLUMN', quota", ]; - self::assertEquals($expectedSql, $this->_platform->getAlterTableSQL($tableDiff)); + self::assertEquals($expectedSql, $this->platform->getAlterTableSQL($tableDiff)); } public function testAlterTableWithSchemaDropColumnComments() @@ -618,7 +618,7 @@ public function testAlterTableWithSchemaDropColumnComments() $expectedSql = ["EXEC sp_dropextendedproperty N'MS_Description', N'SCHEMA', 'testschema', N'TABLE', 'mytable', N'COLUMN', quota"]; - self::assertEquals($expectedSql, $this->_platform->getAlterTableSQL($tableDiff)); + self::assertEquals($expectedSql, $this->platform->getAlterTableSQL($tableDiff)); } public function testAlterTableWithSchemaUpdateColumnComments() @@ -633,7 +633,7 @@ public function testAlterTableWithSchemaUpdateColumnComments() $expectedSql = ["EXEC sp_updateextendedproperty N'MS_Description', N'B comment', N'SCHEMA', 'testschema', N'TABLE', 'mytable', N'COLUMN', quota"]; - self::assertEquals($expectedSql, $this->_platform->getAlterTableSQL($tableDiff)); + self::assertEquals($expectedSql, $this->platform->getAlterTableSQL($tableDiff)); } /** @@ -705,7 +705,7 @@ public function testGeneratesCreateTableSQLWithColumnComments() "EXEC sp_addextendedproperty N'MS_Description', N'Doctrine array type.(DC2Type:array)', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', commented_type_with_comment", "EXEC sp_addextendedproperty N'MS_Description', N'O''Reilly', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', comment_with_string_literal_char", ], - $this->_platform->getCreateTableSQL($table) + $this->platform->getCreateTableSQL($table) ); } @@ -888,7 +888,7 @@ public function testGeneratesAlterTableSQLWithColumnComments() "EXEC sp_updateextendedproperty N'MS_Description', N'(DC2Type:array)', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', commented_type_with_comment", "EXEC sp_updateextendedproperty N'MS_Description', N'''', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', comment_with_string_literal_char", ], - $this->_platform->getAlterTableSQL($tableDiff) + $this->platform->getAlterTableSQL($tableDiff) ); } @@ -897,80 +897,80 @@ public function testGeneratesAlterTableSQLWithColumnComments() */ public function testInitializesDoctrineTypeMappings() { - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('bigint')); - self::assertSame('bigint', $this->_platform->getDoctrineTypeMapping('bigint')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('bigint')); + self::assertSame('bigint', $this->platform->getDoctrineTypeMapping('bigint')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('numeric')); - self::assertSame('decimal', $this->_platform->getDoctrineTypeMapping('numeric')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('numeric')); + self::assertSame('decimal', $this->platform->getDoctrineTypeMapping('numeric')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('bit')); - self::assertSame('boolean', $this->_platform->getDoctrineTypeMapping('bit')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('bit')); + self::assertSame('boolean', $this->platform->getDoctrineTypeMapping('bit')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('smallint')); - self::assertSame('smallint', $this->_platform->getDoctrineTypeMapping('smallint')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('smallint')); + self::assertSame('smallint', $this->platform->getDoctrineTypeMapping('smallint')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('decimal')); - self::assertSame('decimal', $this->_platform->getDoctrineTypeMapping('decimal')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('decimal')); + self::assertSame('decimal', $this->platform->getDoctrineTypeMapping('decimal')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('smallmoney')); - self::assertSame('integer', $this->_platform->getDoctrineTypeMapping('smallmoney')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('smallmoney')); + self::assertSame('integer', $this->platform->getDoctrineTypeMapping('smallmoney')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('int')); - self::assertSame('integer', $this->_platform->getDoctrineTypeMapping('int')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('int')); + self::assertSame('integer', $this->platform->getDoctrineTypeMapping('int')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('tinyint')); - self::assertSame('smallint', $this->_platform->getDoctrineTypeMapping('tinyint')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('tinyint')); + self::assertSame('smallint', $this->platform->getDoctrineTypeMapping('tinyint')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('money')); - self::assertSame('integer', $this->_platform->getDoctrineTypeMapping('money')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('money')); + self::assertSame('integer', $this->platform->getDoctrineTypeMapping('money')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('float')); - self::assertSame('float', $this->_platform->getDoctrineTypeMapping('float')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('float')); + self::assertSame('float', $this->platform->getDoctrineTypeMapping('float')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('real')); - self::assertSame('float', $this->_platform->getDoctrineTypeMapping('real')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('real')); + self::assertSame('float', $this->platform->getDoctrineTypeMapping('real')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('double')); - self::assertSame('float', $this->_platform->getDoctrineTypeMapping('double')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('double')); + self::assertSame('float', $this->platform->getDoctrineTypeMapping('double')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('double precision')); - self::assertSame('float', $this->_platform->getDoctrineTypeMapping('double precision')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('double precision')); + self::assertSame('float', $this->platform->getDoctrineTypeMapping('double precision')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('smalldatetime')); - self::assertSame('datetime', $this->_platform->getDoctrineTypeMapping('smalldatetime')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('smalldatetime')); + self::assertSame('datetime', $this->platform->getDoctrineTypeMapping('smalldatetime')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('datetime')); - self::assertSame('datetime', $this->_platform->getDoctrineTypeMapping('datetime')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('datetime')); + self::assertSame('datetime', $this->platform->getDoctrineTypeMapping('datetime')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('char')); - self::assertSame('string', $this->_platform->getDoctrineTypeMapping('char')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('char')); + self::assertSame('string', $this->platform->getDoctrineTypeMapping('char')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('varchar')); - self::assertSame('string', $this->_platform->getDoctrineTypeMapping('varchar')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('varchar')); + self::assertSame('string', $this->platform->getDoctrineTypeMapping('varchar')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('text')); - self::assertSame('text', $this->_platform->getDoctrineTypeMapping('text')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('text')); + self::assertSame('text', $this->platform->getDoctrineTypeMapping('text')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('nchar')); - self::assertSame('string', $this->_platform->getDoctrineTypeMapping('nchar')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('nchar')); + self::assertSame('string', $this->platform->getDoctrineTypeMapping('nchar')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('nvarchar')); - self::assertSame('string', $this->_platform->getDoctrineTypeMapping('nvarchar')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('nvarchar')); + self::assertSame('string', $this->platform->getDoctrineTypeMapping('nvarchar')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('ntext')); - self::assertSame('text', $this->_platform->getDoctrineTypeMapping('ntext')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('ntext')); + self::assertSame('text', $this->platform->getDoctrineTypeMapping('ntext')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('binary')); - self::assertSame('binary', $this->_platform->getDoctrineTypeMapping('binary')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('binary')); + self::assertSame('binary', $this->platform->getDoctrineTypeMapping('binary')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('varbinary')); - self::assertSame('binary', $this->_platform->getDoctrineTypeMapping('varbinary')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('varbinary')); + self::assertSame('binary', $this->platform->getDoctrineTypeMapping('varbinary')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('image')); - self::assertSame('blob', $this->_platform->getDoctrineTypeMapping('image')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('image')); + self::assertSame('blob', $this->platform->getDoctrineTypeMapping('image')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('uniqueidentifier')); - self::assertSame('guid', $this->_platform->getDoctrineTypeMapping('uniqueidentifier')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('uniqueidentifier')); + self::assertSame('guid', $this->platform->getDoctrineTypeMapping('uniqueidentifier')); } protected function getBinaryMaxLength() @@ -980,13 +980,13 @@ protected function getBinaryMaxLength() public function testReturnsBinaryTypeDeclarationSQL() { - self::assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL([])); - self::assertSame('VARBINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 0])); - self::assertSame('VARBINARY(8000)', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 8000])); + self::assertSame('VARBINARY(255)', $this->platform->getBinaryTypeDeclarationSQL([])); + self::assertSame('VARBINARY(255)', $this->platform->getBinaryTypeDeclarationSQL(['length' => 0])); + self::assertSame('VARBINARY(8000)', $this->platform->getBinaryTypeDeclarationSQL(['length' => 8000])); - self::assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true])); - self::assertSame('BINARY(255)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 0])); - self::assertSame('BINARY(8000)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 8000])); + self::assertSame('BINARY(255)', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true])); + self::assertSame('BINARY(255)', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 0])); + self::assertSame('BINARY(8000)', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 8000])); } /** @@ -995,8 +995,8 @@ public function testReturnsBinaryTypeDeclarationSQL() */ public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() { - self::assertSame('VARBINARY(MAX)', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 8001])); - self::assertSame('VARBINARY(MAX)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 8001])); + self::assertSame('VARBINARY(MAX)', $this->platform->getBinaryTypeDeclarationSQL(['length' => 8001])); + self::assertSame('VARBINARY(MAX)', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 8001])); } /** @@ -1045,7 +1045,7 @@ public function testChangeColumnsTypeWithDefaultValue() new Column('col_string', Type::getType('string'), ['default' => 666]) ); - $expected = $this->_platform->getAlterTableSQL($tableDiff); + $expected = $this->platform->getAlterTableSQL($tableDiff); self::assertSame( $expected, @@ -1121,7 +1121,7 @@ protected function getQuotesDropConstraintSQL() */ public function testGeneratesIdentifierNamesInDefaultConstraintDeclarationSQL($table, $column, $expectedSql) { - self::assertSame($expectedSql, $this->_platform->getDefaultConstraintDeclarationSQL($table, $column)); + self::assertSame($expectedSql, $this->platform->getDefaultConstraintDeclarationSQL($table, $column)); } public function getGeneratesIdentifierNamesInDefaultConstraintDeclarationSQL() @@ -1144,7 +1144,7 @@ public function getGeneratesIdentifierNamesInDefaultConstraintDeclarationSQL() */ public function testGeneratesIdentifierNamesInCreateTableSQL($table, $expectedSql) { - self::assertSame($expectedSql, $this->_platform->getCreateTableSQL($table)); + self::assertSame($expectedSql, $this->platform->getCreateTableSQL($table)); } public function getGeneratesIdentifierNamesInCreateTableSQL() @@ -1191,7 +1191,7 @@ public function getGeneratesIdentifierNamesInCreateTableSQL() */ public function testGeneratesIdentifierNamesInAlterTableSQL($tableDiff, $expectedSql) { - self::assertSame($expectedSql, $this->_platform->getAlterTableSQL($tableDiff)); + self::assertSame($expectedSql, $this->platform->getAlterTableSQL($tableDiff)); } public function getGeneratesIdentifierNamesInAlterTableSQL() @@ -1301,7 +1301,7 @@ public function getGeneratesIdentifierNamesInAlterTableSQL() */ public function testReturnsGuidTypeDeclarationSQL() { - self::assertSame('UNIQUEIDENTIFIER', $this->_platform->getGuidTypeDeclarationSQL([])); + self::assertSame('UNIQUEIDENTIFIER', $this->platform->getGuidTypeDeclarationSQL([])); } /** @@ -1409,12 +1409,12 @@ public function testModifyLimitQueryWithTopNSubQueryWithOrderBy() { $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)'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); $querySql = 'SELECT * FROM test t WHERE t.id = (SELECT TOP 1 t2.id FROM test t2 ORDER BY t2.data DESC) ORDER BY t.data2 DESC'; $alteredSql = 'SELECT TOP 10 * FROM test t WHERE t.id = (SELECT TOP 1 t2.id FROM test t2 ORDER BY t2.data DESC) ORDER BY t.data2 DESC'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->platform->modifyLimitQuery($querySql, 10); $this->expectCteWithMaxRowNum($alteredSql, 10, $sql); } @@ -1423,7 +1423,7 @@ public function testModifyLimitQueryWithTopNSubQueryWithOrderBy() */ public function testQuotesTableNameInListTableColumnsSQL() { - self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableColumnsSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->platform->getListTableColumnsSQL("Foo'Bar\\"), '', true); } /** @@ -1433,7 +1433,7 @@ public function testQuotesSchemaNameInListTableColumnsSQL() { self::assertContains( "'Foo''Bar\\'", - $this->_platform->getListTableColumnsSQL("Foo'Bar\\.baz_table"), + $this->platform->getListTableColumnsSQL("Foo'Bar\\.baz_table"), '', true ); @@ -1444,7 +1444,7 @@ public function testQuotesSchemaNameInListTableColumnsSQL() */ public function testQuotesTableNameInListTableForeignKeysSQL() { - self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true); } /** @@ -1454,7 +1454,7 @@ public function testQuotesSchemaNameInListTableForeignKeysSQL() { self::assertContains( "'Foo''Bar\\'", - $this->_platform->getListTableForeignKeysSQL("Foo'Bar\\.baz_table"), + $this->platform->getListTableForeignKeysSQL("Foo'Bar\\.baz_table"), '', true ); @@ -1465,7 +1465,7 @@ public function testQuotesSchemaNameInListTableForeignKeysSQL() */ public function testQuotesTableNameInListTableIndexesSQL() { - self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableIndexesSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\"), '', true); } /** @@ -1475,7 +1475,7 @@ public function testQuotesSchemaNameInListTableIndexesSQL() { self::assertContains( "'Foo''Bar\\'", - $this->_platform->getListTableIndexesSQL("Foo'Bar\\.baz_table"), + $this->platform->getListTableIndexesSQL("Foo'Bar\\.baz_table"), '', true ); @@ -1486,7 +1486,7 @@ public function testQuotesSchemaNameInListTableIndexesSQL() */ public function testGetDefaultValueDeclarationSQLForDateType() : void { - $currentDateSql = $this->_platform->getCurrentDateSQL(); + $currentDateSql = $this->platform->getCurrentDateSQL(); foreach (['date', 'date_immutable'] as $type) { $field = [ 'type' => Type::getType($type), @@ -1495,21 +1495,21 @@ public function testGetDefaultValueDeclarationSQLForDateType() : void self::assertSame( " DEFAULT '" . $currentDateSql . "'", - $this->_platform->getDefaultValueDeclarationSQL($field) + $this->platform->getDefaultValueDeclarationSQL($field) ); } } public function testSupportsColumnCollation() : void { - self::assertTrue($this->_platform->supportsColumnCollation()); + self::assertTrue($this->platform->supportsColumnCollation()); } public function testColumnCollationDeclarationSQL() : void { self::assertSame( 'COLLATE Latin1_General_CS_AS_KS_WS', - $this->_platform->getColumnCollationDeclarationSQL('Latin1_General_CS_AS_KS_WS') + $this->platform->getColumnCollationDeclarationSQL('Latin1_General_CS_AS_KS_WS') ); } @@ -1521,7 +1521,7 @@ public function testGetCreateTableSQLWithColumnCollation() : void self::assertSame( ['CREATE TABLE foo (no_collation NVARCHAR(255) NOT NULL, column_collation NVARCHAR(255) COLLATE Latin1_General_CS_AS_KS_WS NOT NULL)'], - $this->_platform->getCreateTableSQL($table), + $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/Platforms/DB2PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php index 841021b9653..ce2b7df42a8 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php @@ -14,7 +14,7 @@ class DB2PlatformTest extends AbstractPlatformTestCase { /** @var DB2Platform */ - protected $_platform; + protected $platform; public function createPlatform() { @@ -137,7 +137,7 @@ public function getCreateTableColumnTypeCommentsSQL() public function testHasCorrectPlatformName() { - self::assertEquals('db2', $this->_platform->getName()); + self::assertEquals('db2', $this->platform->getName()); } public function testGeneratesCreateTableSQLWithCommonIndexes() @@ -155,7 +155,7 @@ public function testGeneratesCreateTableSQLWithCommonIndexes() 'CREATE INDEX IDX_D87F7E0C5E237E06 ON test (name)', 'CREATE INDEX composite_idx ON test (id, name)', ], - $this->_platform->getCreateTableSQL($table) + $this->platform->getCreateTableSQL($table) ); } @@ -181,7 +181,7 @@ public function testGeneratesCreateTableSQLWithForeignKeyConstraints() 'ALTER TABLE test ADD CONSTRAINT FK_D87F7E0C177612A38E7F4319 FOREIGN KEY (fk_1, fk_2) REFERENCES foreign_table (pk_1, pk_2)', 'ALTER TABLE test ADD CONSTRAINT named_fk FOREIGN KEY (fk_1, fk_2) REFERENCES foreign_table2 (pk_1, pk_2)', ], - $this->_platform->getCreateTableSQL($table, AbstractPlatform::CREATE_FOREIGNKEYS) + $this->platform->getCreateTableSQL($table, AbstractPlatform::CREATE_FOREIGNKEYS) ); } @@ -195,7 +195,7 @@ public function testGeneratesCreateTableSQLWithCheckConstraints() self::assertEquals( ['CREATE TABLE test (id INTEGER NOT NULL, check_max INTEGER NOT NULL, check_min INTEGER NOT NULL, PRIMARY KEY(id), CHECK (check_max <= 10), CHECK (check_min >= 10))'], - $this->_platform->getCreateTableSQL($table) + $this->platform->getCreateTableSQL($table) ); } @@ -208,71 +208,71 @@ public function testGeneratesColumnTypesDeclarationSQL() 'autoincrement' => true, ]; - self::assertEquals('VARCHAR(255)', $this->_platform->getVarcharTypeDeclarationSQL([])); - self::assertEquals('VARCHAR(10)', $this->_platform->getVarcharTypeDeclarationSQL(['length' => 10])); - self::assertEquals('CHAR(254)', $this->_platform->getVarcharTypeDeclarationSQL(['fixed' => true])); - self::assertEquals('CHAR(10)', $this->_platform->getVarcharTypeDeclarationSQL($fullColumnDef)); - - self::assertEquals('SMALLINT', $this->_platform->getSmallIntTypeDeclarationSQL([])); - self::assertEquals('SMALLINT', $this->_platform->getSmallIntTypeDeclarationSQL(['unsigned' => true])); - self::assertEquals('SMALLINT GENERATED BY DEFAULT AS IDENTITY', $this->_platform->getSmallIntTypeDeclarationSQL($fullColumnDef)); - self::assertEquals('INTEGER', $this->_platform->getIntegerTypeDeclarationSQL([])); - self::assertEquals('INTEGER', $this->_platform->getIntegerTypeDeclarationSQL(['unsigned' => true])); - self::assertEquals('INTEGER GENERATED BY DEFAULT AS IDENTITY', $this->_platform->getIntegerTypeDeclarationSQL($fullColumnDef)); - self::assertEquals('BIGINT', $this->_platform->getBigIntTypeDeclarationSQL([])); - self::assertEquals('BIGINT', $this->_platform->getBigIntTypeDeclarationSQL(['unsigned' => true])); - self::assertEquals('BIGINT GENERATED BY DEFAULT AS IDENTITY', $this->_platform->getBigIntTypeDeclarationSQL($fullColumnDef)); - self::assertEquals('BLOB(1M)', $this->_platform->getBlobTypeDeclarationSQL($fullColumnDef)); - self::assertEquals('SMALLINT', $this->_platform->getBooleanTypeDeclarationSQL($fullColumnDef)); - self::assertEquals('CLOB(1M)', $this->_platform->getClobTypeDeclarationSQL($fullColumnDef)); - self::assertEquals('DATE', $this->_platform->getDateTypeDeclarationSQL($fullColumnDef)); - self::assertEquals('TIMESTAMP(0) WITH DEFAULT', $this->_platform->getDateTimeTypeDeclarationSQL(['version' => true])); - self::assertEquals('TIMESTAMP(0)', $this->_platform->getDateTimeTypeDeclarationSQL($fullColumnDef)); - self::assertEquals('TIME', $this->_platform->getTimeTypeDeclarationSQL($fullColumnDef)); + self::assertEquals('VARCHAR(255)', $this->platform->getVarcharTypeDeclarationSQL([])); + self::assertEquals('VARCHAR(10)', $this->platform->getVarcharTypeDeclarationSQL(['length' => 10])); + self::assertEquals('CHAR(254)', $this->platform->getVarcharTypeDeclarationSQL(['fixed' => true])); + self::assertEquals('CHAR(10)', $this->platform->getVarcharTypeDeclarationSQL($fullColumnDef)); + + self::assertEquals('SMALLINT', $this->platform->getSmallIntTypeDeclarationSQL([])); + self::assertEquals('SMALLINT', $this->platform->getSmallIntTypeDeclarationSQL(['unsigned' => true])); + self::assertEquals('SMALLINT GENERATED BY DEFAULT AS IDENTITY', $this->platform->getSmallIntTypeDeclarationSQL($fullColumnDef)); + self::assertEquals('INTEGER', $this->platform->getIntegerTypeDeclarationSQL([])); + self::assertEquals('INTEGER', $this->platform->getIntegerTypeDeclarationSQL(['unsigned' => true])); + self::assertEquals('INTEGER GENERATED BY DEFAULT AS IDENTITY', $this->platform->getIntegerTypeDeclarationSQL($fullColumnDef)); + self::assertEquals('BIGINT', $this->platform->getBigIntTypeDeclarationSQL([])); + self::assertEquals('BIGINT', $this->platform->getBigIntTypeDeclarationSQL(['unsigned' => true])); + self::assertEquals('BIGINT GENERATED BY DEFAULT AS IDENTITY', $this->platform->getBigIntTypeDeclarationSQL($fullColumnDef)); + self::assertEquals('BLOB(1M)', $this->platform->getBlobTypeDeclarationSQL($fullColumnDef)); + self::assertEquals('SMALLINT', $this->platform->getBooleanTypeDeclarationSQL($fullColumnDef)); + self::assertEquals('CLOB(1M)', $this->platform->getClobTypeDeclarationSQL($fullColumnDef)); + self::assertEquals('DATE', $this->platform->getDateTypeDeclarationSQL($fullColumnDef)); + self::assertEquals('TIMESTAMP(0) WITH DEFAULT', $this->platform->getDateTimeTypeDeclarationSQL(['version' => true])); + self::assertEquals('TIMESTAMP(0)', $this->platform->getDateTimeTypeDeclarationSQL($fullColumnDef)); + self::assertEquals('TIME', $this->platform->getTimeTypeDeclarationSQL($fullColumnDef)); } public function testInitializesDoctrineTypeMappings() { - $this->_platform->initializeDoctrineTypeMappings(); + $this->platform->initializeDoctrineTypeMappings(); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('smallint')); - self::assertSame('smallint', $this->_platform->getDoctrineTypeMapping('smallint')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('smallint')); + self::assertSame('smallint', $this->platform->getDoctrineTypeMapping('smallint')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('bigint')); - self::assertSame('bigint', $this->_platform->getDoctrineTypeMapping('bigint')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('bigint')); + self::assertSame('bigint', $this->platform->getDoctrineTypeMapping('bigint')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('integer')); - self::assertSame('integer', $this->_platform->getDoctrineTypeMapping('integer')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('integer')); + self::assertSame('integer', $this->platform->getDoctrineTypeMapping('integer')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('time')); - self::assertSame('time', $this->_platform->getDoctrineTypeMapping('time')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('time')); + self::assertSame('time', $this->platform->getDoctrineTypeMapping('time')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('date')); - self::assertSame('date', $this->_platform->getDoctrineTypeMapping('date')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('date')); + self::assertSame('date', $this->platform->getDoctrineTypeMapping('date')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('varchar')); - self::assertSame('string', $this->_platform->getDoctrineTypeMapping('varchar')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('varchar')); + self::assertSame('string', $this->platform->getDoctrineTypeMapping('varchar')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('character')); - self::assertSame('string', $this->_platform->getDoctrineTypeMapping('character')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('character')); + self::assertSame('string', $this->platform->getDoctrineTypeMapping('character')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('clob')); - self::assertSame('text', $this->_platform->getDoctrineTypeMapping('clob')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('clob')); + self::assertSame('text', $this->platform->getDoctrineTypeMapping('clob')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('blob')); - self::assertSame('blob', $this->_platform->getDoctrineTypeMapping('blob')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('blob')); + self::assertSame('blob', $this->platform->getDoctrineTypeMapping('blob')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('decimal')); - self::assertSame('decimal', $this->_platform->getDoctrineTypeMapping('decimal')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('decimal')); + self::assertSame('decimal', $this->platform->getDoctrineTypeMapping('decimal')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('double')); - self::assertSame('float', $this->_platform->getDoctrineTypeMapping('double')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('double')); + self::assertSame('float', $this->platform->getDoctrineTypeMapping('double')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('real')); - self::assertSame('float', $this->_platform->getDoctrineTypeMapping('real')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('real')); + self::assertSame('float', $this->platform->getDoctrineTypeMapping('real')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('timestamp')); - self::assertSame('datetime', $this->_platform->getDoctrineTypeMapping('timestamp')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('timestamp')); + self::assertSame('datetime', $this->platform->getDoctrineTypeMapping('timestamp')); } public function getIsCommentedDoctrineType() @@ -286,22 +286,22 @@ public function getIsCommentedDoctrineType() public function testGeneratesDDLSnippets() { - self::assertEquals('CREATE DATABASE foobar', $this->_platform->getCreateDatabaseSQL('foobar')); - self::assertEquals('DROP DATABASE foobar', $this->_platform->getDropDatabaseSQL('foobar')); - self::assertEquals('DECLARE GLOBAL TEMPORARY TABLE', $this->_platform->getCreateTemporaryTableSnippetSQL()); - self::assertEquals('TRUNCATE foobar IMMEDIATE', $this->_platform->getTruncateTableSQL('foobar')); - self::assertEquals('TRUNCATE foobar IMMEDIATE', $this->_platform->getTruncateTableSQL('foobar'), true); + self::assertEquals('CREATE DATABASE foobar', $this->platform->getCreateDatabaseSQL('foobar')); + self::assertEquals('DROP DATABASE foobar', $this->platform->getDropDatabaseSQL('foobar')); + self::assertEquals('DECLARE GLOBAL TEMPORARY TABLE', $this->platform->getCreateTemporaryTableSnippetSQL()); + self::assertEquals('TRUNCATE foobar IMMEDIATE', $this->platform->getTruncateTableSQL('foobar')); + self::assertEquals('TRUNCATE foobar IMMEDIATE', $this->platform->getTruncateTableSQL('foobar'), true); $viewSql = 'SELECT * FROM footable'; - self::assertEquals('CREATE VIEW fooview AS ' . $viewSql, $this->_platform->getCreateViewSQL('fooview', $viewSql)); - self::assertEquals('DROP VIEW fooview', $this->_platform->getDropViewSQL('fooview')); + self::assertEquals('CREATE VIEW fooview AS ' . $viewSql, $this->platform->getCreateViewSQL('fooview', $viewSql)); + self::assertEquals('DROP VIEW fooview', $this->platform->getDropViewSQL('fooview')); } public function testGeneratesCreateUnnamedPrimaryKeySQL() { self::assertEquals( 'ALTER TABLE foo ADD PRIMARY KEY (a, b)', - $this->_platform->getCreatePrimaryKeySQL( + $this->platform->getCreatePrimaryKeySQL( new Index('any_pk_name', ['a', 'b'], true, true), 'foo' ) @@ -310,89 +310,89 @@ public function testGeneratesCreateUnnamedPrimaryKeySQL() public function testGeneratesSQLSnippets() { - self::assertEquals('CURRENT DATE', $this->_platform->getCurrentDateSQL()); - self::assertEquals('CURRENT TIME', $this->_platform->getCurrentTimeSQL()); - self::assertEquals('CURRENT TIMESTAMP', $this->_platform->getCurrentTimestampSQL()); - self::assertEquals("'1987/05/02' + 4 DAY", $this->_platform->getDateAddDaysExpression("'1987/05/02'", 4)); - self::assertEquals("'1987/05/02' + 12 HOUR", $this->_platform->getDateAddHourExpression("'1987/05/02'", 12)); - self::assertEquals("'1987/05/02' + 2 MINUTE", $this->_platform->getDateAddMinutesExpression("'1987/05/02'", 2)); - self::assertEquals("'1987/05/02' + 102 MONTH", $this->_platform->getDateAddMonthExpression("'1987/05/02'", 102)); - self::assertEquals("'1987/05/02' + 15 MONTH", $this->_platform->getDateAddQuartersExpression("'1987/05/02'", 5)); - self::assertEquals("'1987/05/02' + 1 SECOND", $this->_platform->getDateAddSecondsExpression("'1987/05/02'", 1)); - self::assertEquals("'1987/05/02' + 21 DAY", $this->_platform->getDateAddWeeksExpression("'1987/05/02'", 3)); - self::assertEquals("'1987/05/02' + 10 YEAR", $this->_platform->getDateAddYearsExpression("'1987/05/02'", 10)); - self::assertEquals("DAYS('1987/05/02') - DAYS('1987/04/01')", $this->_platform->getDateDiffExpression("'1987/05/02'", "'1987/04/01'")); - self::assertEquals("'1987/05/02' - 4 DAY", $this->_platform->getDateSubDaysExpression("'1987/05/02'", 4)); - self::assertEquals("'1987/05/02' - 12 HOUR", $this->_platform->getDateSubHourExpression("'1987/05/02'", 12)); - self::assertEquals("'1987/05/02' - 2 MINUTE", $this->_platform->getDateSubMinutesExpression("'1987/05/02'", 2)); - self::assertEquals("'1987/05/02' - 102 MONTH", $this->_platform->getDateSubMonthExpression("'1987/05/02'", 102)); - self::assertEquals("'1987/05/02' - 15 MONTH", $this->_platform->getDateSubQuartersExpression("'1987/05/02'", 5)); - self::assertEquals("'1987/05/02' - 1 SECOND", $this->_platform->getDateSubSecondsExpression("'1987/05/02'", 1)); - self::assertEquals("'1987/05/02' - 21 DAY", $this->_platform->getDateSubWeeksExpression("'1987/05/02'", 3)); - self::assertEquals("'1987/05/02' - 10 YEAR", $this->_platform->getDateSubYearsExpression("'1987/05/02'", 10)); - self::assertEquals(' WITH RR USE AND KEEP UPDATE LOCKS', $this->_platform->getForUpdateSQL()); - self::assertEquals('LOCATE(substring_column, string_column)', $this->_platform->getLocateExpression('string_column', 'substring_column')); - self::assertEquals('LOCATE(substring_column, string_column)', $this->_platform->getLocateExpression('string_column', 'substring_column')); - self::assertEquals('LOCATE(substring_column, string_column, 1)', $this->_platform->getLocateExpression('string_column', 'substring_column', 1)); - self::assertEquals('SUBSTR(column, 5)', $this->_platform->getSubstringExpression('column', 5)); - self::assertEquals('SUBSTR(column, 5, 2)', $this->_platform->getSubstringExpression('column', 5, 2)); + self::assertEquals('CURRENT DATE', $this->platform->getCurrentDateSQL()); + self::assertEquals('CURRENT TIME', $this->platform->getCurrentTimeSQL()); + self::assertEquals('CURRENT TIMESTAMP', $this->platform->getCurrentTimestampSQL()); + self::assertEquals("'1987/05/02' + 4 DAY", $this->platform->getDateAddDaysExpression("'1987/05/02'", 4)); + self::assertEquals("'1987/05/02' + 12 HOUR", $this->platform->getDateAddHourExpression("'1987/05/02'", 12)); + self::assertEquals("'1987/05/02' + 2 MINUTE", $this->platform->getDateAddMinutesExpression("'1987/05/02'", 2)); + self::assertEquals("'1987/05/02' + 102 MONTH", $this->platform->getDateAddMonthExpression("'1987/05/02'", 102)); + self::assertEquals("'1987/05/02' + 15 MONTH", $this->platform->getDateAddQuartersExpression("'1987/05/02'", 5)); + self::assertEquals("'1987/05/02' + 1 SECOND", $this->platform->getDateAddSecondsExpression("'1987/05/02'", 1)); + self::assertEquals("'1987/05/02' + 21 DAY", $this->platform->getDateAddWeeksExpression("'1987/05/02'", 3)); + self::assertEquals("'1987/05/02' + 10 YEAR", $this->platform->getDateAddYearsExpression("'1987/05/02'", 10)); + self::assertEquals("DAYS('1987/05/02') - DAYS('1987/04/01')", $this->platform->getDateDiffExpression("'1987/05/02'", "'1987/04/01'")); + self::assertEquals("'1987/05/02' - 4 DAY", $this->platform->getDateSubDaysExpression("'1987/05/02'", 4)); + self::assertEquals("'1987/05/02' - 12 HOUR", $this->platform->getDateSubHourExpression("'1987/05/02'", 12)); + self::assertEquals("'1987/05/02' - 2 MINUTE", $this->platform->getDateSubMinutesExpression("'1987/05/02'", 2)); + self::assertEquals("'1987/05/02' - 102 MONTH", $this->platform->getDateSubMonthExpression("'1987/05/02'", 102)); + self::assertEquals("'1987/05/02' - 15 MONTH", $this->platform->getDateSubQuartersExpression("'1987/05/02'", 5)); + self::assertEquals("'1987/05/02' - 1 SECOND", $this->platform->getDateSubSecondsExpression("'1987/05/02'", 1)); + self::assertEquals("'1987/05/02' - 21 DAY", $this->platform->getDateSubWeeksExpression("'1987/05/02'", 3)); + self::assertEquals("'1987/05/02' - 10 YEAR", $this->platform->getDateSubYearsExpression("'1987/05/02'", 10)); + self::assertEquals(' WITH RR USE AND KEEP UPDATE LOCKS', $this->platform->getForUpdateSQL()); + self::assertEquals('LOCATE(substring_column, string_column)', $this->platform->getLocateExpression('string_column', 'substring_column')); + self::assertEquals('LOCATE(substring_column, string_column)', $this->platform->getLocateExpression('string_column', 'substring_column')); + self::assertEquals('LOCATE(substring_column, string_column, 1)', $this->platform->getLocateExpression('string_column', 'substring_column', 1)); + self::assertEquals('SUBSTR(column, 5)', $this->platform->getSubstringExpression('column', 5)); + self::assertEquals('SUBSTR(column, 5, 2)', $this->platform->getSubstringExpression('column', 5, 2)); } public function testModifiesLimitQuery() { self::assertEquals( 'SELECT * FROM user', - $this->_platform->modifyLimitQuery('SELECT * FROM user', null, null) + $this->platform->modifyLimitQuery('SELECT * FROM user', null, null) ); self::assertEquals( 'SELECT db22.* FROM (SELECT db21.*, ROW_NUMBER() OVER() AS DC_ROWNUM FROM (SELECT * FROM user) db21) db22 WHERE db22.DC_ROWNUM <= 10', - $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0) + $this->platform->modifyLimitQuery('SELECT * FROM user', 10, 0) ); self::assertEquals( 'SELECT db22.* FROM (SELECT db21.*, ROW_NUMBER() OVER() AS DC_ROWNUM FROM (SELECT * FROM user) db21) db22 WHERE db22.DC_ROWNUM <= 10', - $this->_platform->modifyLimitQuery('SELECT * FROM user', 10) + $this->platform->modifyLimitQuery('SELECT * FROM user', 10) ); self::assertEquals( 'SELECT db22.* FROM (SELECT db21.*, ROW_NUMBER() OVER() AS DC_ROWNUM FROM (SELECT * FROM user) db21) db22 WHERE db22.DC_ROWNUM >= 6 AND db22.DC_ROWNUM <= 15', - $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 5) + $this->platform->modifyLimitQuery('SELECT * FROM user', 10, 5) ); self::assertEquals( 'SELECT db22.* FROM (SELECT db21.*, ROW_NUMBER() OVER() AS DC_ROWNUM FROM (SELECT * FROM user) db21) db22 WHERE db22.DC_ROWNUM >= 6 AND db22.DC_ROWNUM <= 5', - $this->_platform->modifyLimitQuery('SELECT * FROM user', 0, 5) + $this->platform->modifyLimitQuery('SELECT * FROM user', 0, 5) ); } public function testPrefersIdentityColumns() { - self::assertTrue($this->_platform->prefersIdentityColumns()); + self::assertTrue($this->platform->prefersIdentityColumns()); } public function testSupportsIdentityColumns() { - self::assertTrue($this->_platform->supportsIdentityColumns()); + self::assertTrue($this->platform->supportsIdentityColumns()); } public function testDoesNotSupportSavePoints() { - self::assertFalse($this->_platform->supportsSavepoints()); + self::assertFalse($this->platform->supportsSavepoints()); } public function testDoesNotSupportReleasePoints() { - self::assertFalse($this->_platform->supportsReleaseSavepoints()); + self::assertFalse($this->platform->supportsReleaseSavepoints()); } public function testDoesNotSupportCreateDropDatabase() { - self::assertFalse($this->_platform->supportsCreateDropDatabase()); + self::assertFalse($this->platform->supportsCreateDropDatabase()); } public function testReturnsSQLResultCasing() { - self::assertSame('COL', $this->_platform->getSQLResultCasing('cOl')); + self::assertSame('COL', $this->platform->getSQLResultCasing('cOl')); } protected function getBinaryDefaultLength() @@ -407,12 +407,12 @@ protected function getBinaryMaxLength() public function testReturnsBinaryTypeDeclarationSQL() { - self::assertSame('VARCHAR(1) FOR BIT DATA', $this->_platform->getBinaryTypeDeclarationSQL([])); - self::assertSame('VARCHAR(255) FOR BIT DATA', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 0])); - self::assertSame('VARCHAR(32704) FOR BIT DATA', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 32704])); + self::assertSame('VARCHAR(1) FOR BIT DATA', $this->platform->getBinaryTypeDeclarationSQL([])); + self::assertSame('VARCHAR(255) FOR BIT DATA', $this->platform->getBinaryTypeDeclarationSQL(['length' => 0])); + self::assertSame('VARCHAR(32704) FOR BIT DATA', $this->platform->getBinaryTypeDeclarationSQL(['length' => 32704])); - self::assertSame('CHAR(1) FOR BIT DATA', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true])); - self::assertSame('CHAR(254) FOR BIT DATA', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 0])); + self::assertSame('CHAR(1) FOR BIT DATA', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true])); + self::assertSame('CHAR(254) FOR BIT DATA', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 0])); } /** @@ -421,8 +421,8 @@ public function testReturnsBinaryTypeDeclarationSQL() */ public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() { - self::assertSame('BLOB(1M)', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 32705])); - self::assertSame('BLOB(1M)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 32705])); + self::assertSame('BLOB(1M)', $this->platform->getBinaryTypeDeclarationSQL(['length' => 32705])); + self::assertSame('BLOB(1M)', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 32705])); } /** @@ -494,7 +494,7 @@ protected function getQuotedAlterTableRenameIndexInSchemaSQL() */ public function testReturnsGuidTypeDeclarationSQL() { - self::assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL([])); + self::assertSame('CHAR(36)', $this->platform->getGuidTypeDeclarationSQL([])); } /** @@ -555,11 +555,11 @@ public function testGeneratesAlterColumnSQL($changedProperty, Column $column, $e $expectedSQL[] = "CALL SYSPROC.ADMIN_CMD ('REORG TABLE foo')"; - self::assertSame($expectedSQL, $this->_platform->getAlterTableSQL($tableDiff)); + self::assertSame($expectedSQL, $this->platform->getAlterTableSQL($tableDiff)); } /** - * @return array + * @return mixed[] */ public function getGeneratesAlterColumnSQL() { @@ -686,7 +686,7 @@ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() */ public function testQuotesTableNameInListTableColumnsSQL() { - self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableColumnsSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->platform->getListTableColumnsSQL("Foo'Bar\\"), '', true); } /** @@ -694,7 +694,7 @@ public function testQuotesTableNameInListTableColumnsSQL() */ public function testQuotesTableNameInListTableIndexesSQL() { - self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableIndexesSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\"), '', true); } /** @@ -702,6 +702,6 @@ public function testQuotesTableNameInListTableIndexesSQL() */ public function testQuotesTableNameInListTableForeignKeysSQL() { - self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true); } } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/MariaDb1027PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/MariaDb1027PlatformTest.php index 95938f477c1..7171ad714d6 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/MariaDb1027PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/MariaDb1027PlatformTest.php @@ -17,7 +17,7 @@ public function createPlatform() : MariaDb1027Platform public function testHasNativeJsonType() : void { - self::assertFalse($this->_platform->hasNativeJsonType()); + self::assertFalse($this->platform->hasNativeJsonType()); } /** @@ -27,13 +27,13 @@ public function testHasNativeJsonType() : void */ public function testReturnsJsonTypeDeclarationSQL() : void { - self::assertSame('LONGTEXT', $this->_platform->getJsonTypeDeclarationSQL([])); + self::assertSame('LONGTEXT', $this->platform->getJsonTypeDeclarationSQL([])); } public function testInitializesJsonTypeMapping() : void { - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('json')); - self::assertSame(Type::JSON, $this->_platform->getDoctrineTypeMapping('json')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('json')); + self::assertSame(Type::JSON, $this->platform->getDoctrineTypeMapping('json')); } /** diff --git a/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php index bef9aa6a545..52d7ca0708b 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php @@ -17,18 +17,18 @@ public function createPlatform() public function testHasNativeJsonType() { - self::assertTrue($this->_platform->hasNativeJsonType()); + self::assertTrue($this->platform->hasNativeJsonType()); } public function testReturnsJsonTypeDeclarationSQL() { - self::assertSame('JSON', $this->_platform->getJsonTypeDeclarationSQL([])); + self::assertSame('JSON', $this->platform->getJsonTypeDeclarationSQL([])); } public function testInitializesJsonTypeMapping() { - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('json')); - self::assertSame(Type::JSON, $this->_platform->getDoctrineTypeMapping('json')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('json')); + self::assertSame(Type::JSON, $this->platform->getDoctrineTypeMapping('json')); } /** diff --git a/tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php index 3372ef94051..ec1f3181581 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php @@ -9,14 +9,14 @@ class MySqlPlatformTest extends AbstractMySQLPlatformTestCase { public function createPlatform() { - return new MysqlPlatform(); + return new MySqlPlatform(); } public function testHasCorrectDefaultTransactionIsolationLevel() { self::assertEquals( TransactionIsolationLevel::REPEATABLE_READ, - $this->_platform->getDefaultTransactionIsolationLevel() + $this->platform->getDefaultTransactionIsolationLevel() ); } } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php index da210021a85..5af2b0cf571 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php @@ -15,6 +15,7 @@ use Doctrine\DBAL\Types\Type; use function array_walk; use function preg_replace; +use function sprintf; use function strtoupper; use function uniqid; @@ -101,32 +102,32 @@ public function getGenerateAlterTableSql() */ public function testRLike() { - self::assertEquals('RLIKE', $this->_platform->getRegexpExpression(), 'Regular expression operator is not correct'); + self::assertEquals('RLIKE', $this->platform->getRegexpExpression(), 'Regular expression operator is not correct'); } public function testGeneratesSqlSnippets() { - 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'); + 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() { self::assertEquals( 'SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED', - $this->_platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_UNCOMMITTED) + $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_UNCOMMITTED) ); self::assertEquals( 'SET TRANSACTION ISOLATION LEVEL READ COMMITTED', - $this->_platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_COMMITTED) + $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_COMMITTED) ); self::assertEquals( 'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE', - $this->_platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::REPEATABLE_READ) + $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::REPEATABLE_READ) ); self::assertEquals( 'SET TRANSACTION ISOLATION LEVEL SERIALIZABLE', - $this->_platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::SERIALIZABLE) + $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::SERIALIZABLE) ); } @@ -135,32 +136,32 @@ public function testGeneratesTransactionsCommands() */ public function testCreateDatabaseThrowsException() { - self::assertEquals('CREATE DATABASE foobar', $this->_platform->getCreateDatabaseSQL('foobar')); + self::assertEquals('CREATE DATABASE foobar', $this->platform->getCreateDatabaseSQL('foobar')); } public function testDropDatabaseThrowsException() { - self::assertEquals('DROP USER foobar CASCADE', $this->_platform->getDropDatabaseSQL('foobar')); + self::assertEquals('DROP USER foobar CASCADE', $this->platform->getDropDatabaseSQL('foobar')); } public function testDropTable() { - self::assertEquals('DROP TABLE foobar', $this->_platform->getDropTableSQL('foobar')); + self::assertEquals('DROP TABLE foobar', $this->platform->getDropTableSQL('foobar')); } public function testGeneratesTypeDeclarationForIntegers() { self::assertEquals( 'NUMBER(10)', - $this->_platform->getIntegerTypeDeclarationSQL([]) + $this->platform->getIntegerTypeDeclarationSQL([]) ); self::assertEquals( 'NUMBER(10)', - $this->_platform->getIntegerTypeDeclarationSQL(['autoincrement' => true]) + $this->platform->getIntegerTypeDeclarationSQL(['autoincrement' => true]) ); self::assertEquals( 'NUMBER(10)', - $this->_platform->getIntegerTypeDeclarationSQL( + $this->platform->getIntegerTypeDeclarationSQL( ['autoincrement' => true, 'primary' => true] ) ); @@ -170,35 +171,35 @@ public function testGeneratesTypeDeclarationsForStrings() { self::assertEquals( 'CHAR(10)', - $this->_platform->getVarcharTypeDeclarationSQL( + $this->platform->getVarcharTypeDeclarationSQL( ['length' => 10, 'fixed' => true] ) ); self::assertEquals( 'VARCHAR2(50)', - $this->_platform->getVarcharTypeDeclarationSQL(['length' => 50]), + $this->platform->getVarcharTypeDeclarationSQL(['length' => 50]), 'Variable string declaration is not correct' ); self::assertEquals( 'VARCHAR2(255)', - $this->_platform->getVarcharTypeDeclarationSQL([]), + $this->platform->getVarcharTypeDeclarationSQL([]), 'Long string declaration is not correct' ); } public function testPrefersIdentityColumns() { - self::assertFalse($this->_platform->prefersIdentityColumns()); + self::assertFalse($this->platform->prefersIdentityColumns()); } public function testSupportsIdentityColumns() { - self::assertFalse($this->_platform->supportsIdentityColumns()); + self::assertFalse($this->platform->supportsIdentityColumns()); } public function testSupportsSavePoints() { - self::assertTrue($this->_platform->supportsSavepoints()); + self::assertTrue($this->platform->supportsSavepoints()); } /** @@ -225,6 +226,8 @@ public function getGenerateForeignKeySql() } /** + * @param mixed[] $options + * * @group DBAL-1097 * @dataProvider getGeneratesAdvancedForeignKeyOptionsSQLData */ @@ -232,11 +235,11 @@ public function testGeneratesAdvancedForeignKeyOptionsSQL(array $options, $expec { $foreignKey = new ForeignKeyConstraint(['foo'], 'foreign_table', ['bar'], null, $options); - self::assertSame($expectedSql, $this->_platform->getAdvancedForeignKeyOptionsSQL($foreignKey)); + self::assertSame($expectedSql, $this->platform->getAdvancedForeignKeyOptionsSQL($foreignKey)); } /** - * @return array + * @return mixed[] */ public function getGeneratesAdvancedForeignKeyOptionsSQLData() { @@ -266,37 +269,37 @@ public function getReturnsForeignKeyReferentialActionSQL() public function testModifyLimitQuery() { - $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0); + $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() { - $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10); + $sql = $this->platform->modifyLimitQuery('SELECT * FROM user', 10); self::assertEquals('SELECT a.* FROM (SELECT * FROM user) a WHERE ROWNUM <= 10', $sql); } public function testModifyLimitQueryWithNonEmptyOffset() { - $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 10); + $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() { - $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', null, 10); + $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() { - $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user ORDER BY username ASC', 10); + $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() { - $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user ORDER BY username DESC', 10); + $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); } @@ -308,12 +311,31 @@ public function testGenerateTableWithAutoincrement() $column = $table->addColumn($columnName, 'integer'); $column->setAutoincrement(true); $targets = [ - "CREATE TABLE {$tableName} ({$columnName} NUMBER(10) NOT NULL)", - "DECLARE constraints_Count NUMBER; BEGIN SELECT COUNT(CONSTRAINT_NAME) INTO constraints_Count FROM USER_CONSTRAINTS WHERE TABLE_NAME = '{$tableName}' AND CONSTRAINT_TYPE = 'P'; IF constraints_Count = 0 OR constraints_Count = '' THEN EXECUTE IMMEDIATE 'ALTER TABLE {$tableName} ADD CONSTRAINT {$tableName}_AI_PK PRIMARY KEY ({$columnName})'; END IF; END;", - "CREATE SEQUENCE {$tableName}_SEQ START WITH 1 MINVALUE 1 INCREMENT BY 1", - "CREATE TRIGGER {$tableName}_AI_PK BEFORE INSERT ON {$tableName} FOR EACH ROW DECLARE last_Sequence NUMBER; last_InsertID NUMBER; BEGIN SELECT {$tableName}_SEQ.NEXTVAL INTO :NEW.{$columnName} FROM DUAL; IF (:NEW.{$columnName} IS NULL OR :NEW.{$columnName} = 0) THEN SELECT {$tableName}_SEQ.NEXTVAL INTO :NEW.{$columnName} FROM DUAL; ELSE SELECT NVL(Last_Number, 0) INTO last_Sequence FROM User_Sequences WHERE Sequence_Name = '{$tableName}_SEQ'; SELECT :NEW.{$columnName} INTO last_InsertID FROM DUAL; WHILE (last_InsertID > last_Sequence) LOOP SELECT {$tableName}_SEQ.NEXTVAL INTO last_Sequence FROM DUAL; END LOOP; END IF; END;", + sprintf('CREATE TABLE %s (%s NUMBER(10) NOT NULL)', $tableName, $columnName), + sprintf( + "DECLARE constraints_Count NUMBER; BEGIN SELECT COUNT(CONSTRAINT_NAME) INTO constraints_Count FROM USER_CONSTRAINTS WHERE TABLE_NAME = '%s' AND CONSTRAINT_TYPE = 'P'; IF constraints_Count = 0 OR constraints_Count = '' THEN EXECUTE IMMEDIATE 'ALTER TABLE %s ADD CONSTRAINT %s_AI_PK PRIMARY KEY (%s)'; END IF; END;", + $tableName, + $tableName, + $tableName, + $columnName + ), + sprintf('CREATE SEQUENCE %s_SEQ START WITH 1 MINVALUE 1 INCREMENT BY 1', $tableName), + sprintf( + "CREATE TRIGGER %s_AI_PK BEFORE INSERT ON %s FOR EACH ROW DECLARE last_Sequence NUMBER; last_InsertID NUMBER; BEGIN SELECT %s_SEQ.NEXTVAL INTO :NEW.%s FROM DUAL; IF (:NEW.%s IS NULL OR :NEW.%s = 0) THEN SELECT %s_SEQ.NEXTVAL INTO :NEW.%s FROM DUAL; ELSE SELECT NVL(Last_Number, 0) INTO last_Sequence FROM User_Sequences WHERE Sequence_Name = '%s_SEQ'; SELECT :NEW.%s INTO last_InsertID FROM DUAL; WHILE (last_InsertID > last_Sequence) LOOP SELECT %s_SEQ.NEXTVAL INTO last_Sequence FROM DUAL; END LOOP; END IF; END;", + $tableName, + $tableName, + $tableName, + $columnName, + $columnName, + $columnName, + $tableName, + $columnName, + $tableName, + $columnName, + $tableName + ), ]; - $statements = $this->_platform->getCreateTableSQL($table); + $statements = $this->platform->getCreateTableSQL($table); //strip all the whitespace from the statements array_walk($statements, static function (&$value) { $value = preg_replace('/\s+/', ' ', $value); @@ -429,7 +451,7 @@ public function testAlterTableNotNULL() ); $expectedSql = ["ALTER TABLE mytable MODIFY (foo VARCHAR2(255) DEFAULT 'bla', baz VARCHAR2(255) DEFAULT 'bla' NOT NULL, metar VARCHAR2(2000) DEFAULT NULL NULL)"]; - self::assertEquals($expectedSql, $this->_platform->getAlterTableSQL($tableDiff)); + self::assertEquals($expectedSql, $this->platform->getAlterTableSQL($tableDiff)); } /** @@ -437,14 +459,14 @@ public function testAlterTableNotNULL() */ public function testInitializesDoctrineTypeMappings() { - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('long raw')); - self::assertSame('blob', $this->_platform->getDoctrineTypeMapping('long raw')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('long raw')); + self::assertSame('blob', $this->platform->getDoctrineTypeMapping('long raw')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('raw')); - self::assertSame('binary', $this->_platform->getDoctrineTypeMapping('raw')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('raw')); + self::assertSame('binary', $this->platform->getDoctrineTypeMapping('raw')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('date')); - self::assertSame('date', $this->_platform->getDoctrineTypeMapping('date')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('date')); + self::assertSame('date', $this->platform->getDoctrineTypeMapping('date')); } protected function getBinaryMaxLength() @@ -454,13 +476,13 @@ protected function getBinaryMaxLength() public function testReturnsBinaryTypeDeclarationSQL() { - self::assertSame('RAW(255)', $this->_platform->getBinaryTypeDeclarationSQL([])); - self::assertSame('RAW(2000)', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 0])); - self::assertSame('RAW(2000)', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 2000])); + self::assertSame('RAW(255)', $this->platform->getBinaryTypeDeclarationSQL([])); + self::assertSame('RAW(2000)', $this->platform->getBinaryTypeDeclarationSQL(['length' => 0])); + self::assertSame('RAW(2000)', $this->platform->getBinaryTypeDeclarationSQL(['length' => 2000])); - self::assertSame('RAW(255)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true])); - self::assertSame('RAW(2000)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 0])); - self::assertSame('RAW(2000)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 2000])); + self::assertSame('RAW(255)', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true])); + self::assertSame('RAW(2000)', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 0])); + self::assertSame('RAW(2000)', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 2000])); } /** @@ -469,8 +491,8 @@ public function testReturnsBinaryTypeDeclarationSQL() */ public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() { - self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 2001])); - self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 2001])); + self::assertSame('BLOB', $this->platform->getBinaryTypeDeclarationSQL(['length' => 2001])); + self::assertSame('BLOB', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 2001])); } public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType() @@ -487,7 +509,7 @@ public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType() // VARBINARY -> BINARY // BINARY -> VARBINARY - self::assertEmpty($this->_platform->getAlterTableSQL($comparator->diffTable($table1, $table2))); + self::assertEmpty($this->platform->getAlterTableSQL($comparator->diffTable($table1, $table2))); } /** @@ -495,7 +517,7 @@ public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType() */ public function testUsesSequenceEmulatedIdentityColumns() { - self::assertTrue($this->_platform->usesSequenceEmulatedIdentityColumns()); + self::assertTrue($this->platform->usesSequenceEmulatedIdentityColumns()); } /** @@ -504,10 +526,10 @@ public function testUsesSequenceEmulatedIdentityColumns() */ public function testReturnsIdentitySequenceName() { - self::assertSame('MYTABLE_SEQ', $this->_platform->getIdentitySequenceName('mytable', 'mycolumn')); - self::assertSame('"mytable_SEQ"', $this->_platform->getIdentitySequenceName('"mytable"', 'mycolumn')); - self::assertSame('MYTABLE_SEQ', $this->_platform->getIdentitySequenceName('mytable', '"mycolumn"')); - self::assertSame('"mytable_SEQ"', $this->_platform->getIdentitySequenceName('"mytable"', '"mycolumn"')); + self::assertSame('MYTABLE_SEQ', $this->platform->getIdentitySequenceName('mytable', 'mycolumn')); + self::assertSame('"mytable_SEQ"', $this->platform->getIdentitySequenceName('"mytable"', 'mycolumn')); + self::assertSame('MYTABLE_SEQ', $this->platform->getIdentitySequenceName('mytable', '"mycolumn"')); + self::assertSame('"mytable_SEQ"', $this->platform->getIdentitySequenceName('"mytable"', '"mycolumn"')); } /** @@ -517,7 +539,7 @@ public function testReturnsIdentitySequenceName() public function testCreateSequenceWithCache($cacheSize, $expectedSql) { $sequence = new Sequence('foo', 1, 1, $cacheSize); - self::assertContains($expectedSql, $this->_platform->getCreateSequenceSQL($sequence)); + self::assertContains($expectedSql, $this->platform->getCreateSequenceSQL($sequence)); } public function dataCreateSequenceWithCache() @@ -603,7 +625,7 @@ protected function getQuotesDropForeignKeySQL() */ public function testReturnsGuidTypeDeclarationSQL() { - self::assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL([])); + self::assertSame('CHAR(36)', $this->platform->getGuidTypeDeclarationSQL([])); } /** @@ -620,7 +642,7 @@ public function getAlterTableRenameColumnSQL() */ public function testReturnsDropAutoincrementSQL($table, $expectedSql) { - self::assertSame($expectedSql, $this->_platform->getDropAutoincrementSql($table)); + self::assertSame($expectedSql, $this->platform->getDropAutoincrementSql($table)); } public function getReturnsDropAutoincrementSQL() @@ -695,10 +717,10 @@ public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() $tableDiff = $comparator->diffTable($table1, $table2); - self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); + self::assertInstanceOf(TableDiff::class, $tableDiff); self::assertSame( ['COMMENT ON COLUMN "foo"."bar" IS \'baz\''], - $this->_platform->getAlterTableSQL($tableDiff) + $this->platform->getAlterTableSQL($tableDiff) ); } @@ -710,9 +732,9 @@ public function testQuotedTableNames() // assert tabel self::assertTrue($table->isQuoted()); self::assertEquals('test', $table->getName()); - self::assertEquals('"test"', $table->getQuotedName($this->_platform)); + self::assertEquals('"test"', $table->getQuotedName($this->platform)); - $sql = $this->_platform->getCreateTableSQL($table); + $sql = $this->platform->getCreateTableSQL($table); self::assertEquals('CREATE TABLE "test" ("id" NUMBER(10) NOT NULL)', $sql[0]); self::assertEquals('CREATE SEQUENCE "test_SEQ" START WITH 1 MINVALUE 1 INCREMENT BY 1', $sql[2]); $createTriggerStatement = <<_platform->getListTableColumnsSQL('"test"', $database)); + self::assertEquals($expectedSql, $this->platform->getListTableColumnsSQL('"test"', $database)); } public function getReturnsGetListTableColumnsSQL() @@ -844,7 +866,7 @@ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() */ public function testQuotesDatabaseNameInListSequencesSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListSequencesSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\\\'", $this->platform->getListSequencesSQL("Foo'Bar\\"), '', true); } /** @@ -852,7 +874,7 @@ public function testQuotesDatabaseNameInListSequencesSQL() */ public function testQuotesTableNameInListTableIndexesSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableIndexesSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\"), '', true); } /** @@ -860,7 +882,7 @@ public function testQuotesTableNameInListTableIndexesSQL() */ public function testQuotesTableNameInListTableForeignKeysSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true); } /** @@ -868,7 +890,7 @@ public function testQuotesTableNameInListTableForeignKeysSQL() */ public function testQuotesTableNameInListTableConstraintsSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true); } /** @@ -876,7 +898,7 @@ public function testQuotesTableNameInListTableConstraintsSQL() */ public function testQuotesTableNameInListTableColumnsSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableColumnsSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableColumnsSQL("Foo'Bar\\"), '', true); } /** @@ -884,6 +906,6 @@ public function testQuotesTableNameInListTableColumnsSQL() */ public function testQuotesDatabaseNameInListTableColumnsSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableColumnsSQL('foo_table', "Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableColumnsSQL('foo_table', "Foo'Bar\\"), '', true); } } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL100PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL100PlatformTest.php index 987628de218..df30fc471f0 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL100PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL100PlatformTest.php @@ -27,7 +27,7 @@ public function testGetListSequencesSQL() : void WHERE sequence_catalog = 'test_db' AND sequence_schema NOT LIKE 'pg\_%' AND sequence_schema != 'information_schema'", - $this->_platform->getListSequencesSQL('test_db') + $this->platform->getListSequencesSQL('test_db') ); } } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL91PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL91PlatformTest.php index 0fc2403af79..ec62ac8b026 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL91PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL91PlatformTest.php @@ -14,14 +14,14 @@ public function createPlatform() public function testSupportsColumnCollation() : void { - self::assertTrue($this->_platform->supportsColumnCollation()); + self::assertTrue($this->platform->supportsColumnCollation()); } public function testColumnCollationDeclarationSQL() : void { self::assertSame( 'COLLATE "en_US.UTF-8"', - $this->_platform->getColumnCollationDeclarationSQL('en_US.UTF-8') + $this->platform->getColumnCollationDeclarationSQL('en_US.UTF-8') ); } @@ -33,7 +33,7 @@ public function testGetCreateTableSQLWithColumnCollation() : void self::assertSame( ['CREATE TABLE foo (no_collation VARCHAR(255) NOT NULL, column_collation VARCHAR(255) NOT NULL COLLATE "en_US.UTF-8")'], - $this->_platform->getCreateTableSQL($table), + $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/Platforms/PostgreSQL92PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL92PlatformTest.php index 48297877125..fb36beb334a 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL92PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL92PlatformTest.php @@ -20,7 +20,7 @@ public function createPlatform() */ public function testHasNativeJsonType() { - self::assertTrue($this->_platform->hasNativeJsonType()); + self::assertTrue($this->platform->hasNativeJsonType()); } /** @@ -28,24 +28,24 @@ public function testHasNativeJsonType() */ public function testReturnsJsonTypeDeclarationSQL() { - self::assertSame('JSON', $this->_platform->getJsonTypeDeclarationSQL([])); + self::assertSame('JSON', $this->platform->getJsonTypeDeclarationSQL([])); } public function testReturnsSmallIntTypeDeclarationSQL() { self::assertSame( 'SMALLSERIAL', - $this->_platform->getSmallIntTypeDeclarationSQL(['autoincrement' => true]) + $this->platform->getSmallIntTypeDeclarationSQL(['autoincrement' => true]) ); self::assertSame( 'SMALLINT', - $this->_platform->getSmallIntTypeDeclarationSQL(['autoincrement' => false]) + $this->platform->getSmallIntTypeDeclarationSQL(['autoincrement' => false]) ); self::assertSame( 'SMALLINT', - $this->_platform->getSmallIntTypeDeclarationSQL([]) + $this->platform->getSmallIntTypeDeclarationSQL([]) ); } @@ -54,8 +54,8 @@ public function testReturnsSmallIntTypeDeclarationSQL() */ public function testInitializesJsonTypeMapping() { - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('json')); - self::assertEquals(Type::JSON, $this->_platform->getDoctrineTypeMapping('json')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('json')); + self::assertEquals(Type::JSON, $this->platform->getDoctrineTypeMapping('json')); } /** @@ -65,7 +65,7 @@ public function testReturnsCloseActiveDatabaseConnectionsSQL() { self::assertSame( "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'foo'", - $this->_platform->getCloseActiveDatabaseConnectionsSQL('foo') + $this->platform->getCloseActiveDatabaseConnectionsSQL('foo') ); } } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL94PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL94PlatformTest.php index 673a724ecdc..ed118aec406 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL94PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL94PlatformTest.php @@ -18,14 +18,14 @@ public function createPlatform() public function testReturnsJsonTypeDeclarationSQL() { parent::testReturnsJsonTypeDeclarationSQL(); - self::assertSame('JSON', $this->_platform->getJsonTypeDeclarationSQL(['jsonb' => false])); - self::assertSame('JSONB', $this->_platform->getJsonTypeDeclarationSQL(['jsonb' => true])); + self::assertSame('JSON', $this->platform->getJsonTypeDeclarationSQL(['jsonb' => false])); + self::assertSame('JSONB', $this->platform->getJsonTypeDeclarationSQL(['jsonb' => true])); } public function testInitializesJsonTypeMapping() { parent::testInitializesJsonTypeMapping(); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('jsonb')); - self::assertEquals(Type::JSON, $this->_platform->getDoctrineTypeMapping('jsonb')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('jsonb')); + self::assertEquals(Type::JSON, $this->platform->getDoctrineTypeMapping('jsonb')); } } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php index 4022eb0ff04..b45a152ab0a 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php @@ -13,6 +13,6 @@ public function createPlatform() public function testSupportsPartialIndexes() { - self::assertTrue($this->_platform->supportsPartialIndexes()); + self::assertTrue($this->platform->supportsPartialIndexes()); } } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere11PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere11PlatformTest.php index c384d16de45..7e91777d6ef 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere11PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere11PlatformTest.php @@ -7,7 +7,7 @@ class SQLAnywhere11PlatformTest extends SQLAnywherePlatformTest { /** @var SQLAnywhere11Platform */ - protected $_platform; + protected $platform; public function createPlatform() { @@ -21,6 +21,6 @@ public function testDoesNotSupportRegexp() public function testGeneratesRegularExpressionSQLSnippet() { - self::assertEquals('REGEXP', $this->_platform->getRegexpExpression()); + 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 4219c9d0514..7cbb2c69bb8 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere12PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere12PlatformTest.php @@ -9,7 +9,7 @@ class SQLAnywhere12PlatformTest extends SQLAnywhere11PlatformTest { /** @var SQLAnywhere12Platform */ - protected $_platform; + protected $platform; public function createPlatform() { @@ -23,7 +23,7 @@ public function testDoesNotSupportSequences() public function testSupportsSequences() { - self::assertTrue($this->_platform->supportsSequences()); + self::assertTrue($this->platform->supportsSequences()); } public function testGeneratesSequenceSqlCommands() @@ -31,27 +31,27 @@ public function testGeneratesSequenceSqlCommands() $sequence = new Sequence('myseq', 20, 1); self::assertEquals( 'CREATE SEQUENCE myseq INCREMENT BY 20 START WITH 1 MINVALUE 1', - $this->_platform->getCreateSequenceSQL($sequence) + $this->platform->getCreateSequenceSQL($sequence) ); self::assertEquals( 'ALTER SEQUENCE myseq INCREMENT BY 20', - $this->_platform->getAlterSequenceSQL($sequence) + $this->platform->getAlterSequenceSQL($sequence) ); self::assertEquals( 'DROP SEQUENCE myseq', - $this->_platform->getDropSequenceSQL('myseq') + $this->platform->getDropSequenceSQL('myseq') ); self::assertEquals( 'DROP SEQUENCE myseq', - $this->_platform->getDropSequenceSQL($sequence) + $this->platform->getDropSequenceSQL($sequence) ); self::assertEquals( 'SELECT myseq.NEXTVAL', - $this->_platform->getSequenceNextValSQL('myseq') + $this->platform->getSequenceNextValSQL('myseq') ); self::assertEquals( 'SELECT sequence_name, increment_by, start_with, min_value FROM SYS.SYSSEQUENCE', - $this->_platform->getListSequencesSQL(null) + $this->platform->getListSequencesSQL(null) ); } @@ -59,7 +59,7 @@ public function testGeneratesDateTimeTzColumnTypeDeclarationSQL() { self::assertEquals( 'TIMESTAMP WITH TIME ZONE', - $this->_platform->getDateTimeTzTypeDeclarationSQL([ + $this->platform->getDateTimeTzTypeDeclarationSQL([ 'length' => 10, 'fixed' => true, 'unsigned' => true, @@ -70,20 +70,20 @@ public function testGeneratesDateTimeTzColumnTypeDeclarationSQL() public function testHasCorrectDateTimeTzFormatString() { - self::assertEquals('Y-m-d H:i:s.uP', $this->_platform->getDateTimeTzFormatString()); + self::assertEquals('Y-m-d H:i:s.uP', $this->platform->getDateTimeTzFormatString()); } public function testInitializesDateTimeTzTypeMapping() { - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('timestamp with time zone')); - self::assertEquals('datetime', $this->_platform->getDoctrineTypeMapping('timestamp with time zone')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('timestamp with time zone')); + self::assertEquals('datetime', $this->platform->getDoctrineTypeMapping('timestamp with time zone')); } public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() { self::assertEquals( 'CREATE VIRTUAL UNIQUE CLUSTERED INDEX fooindex ON footable (a, b) WITH NULLS NOT DISTINCT FOR OLAP WORKLOAD', - $this->_platform->getCreateIndexSQL( + $this->platform->getCreateIndexSQL( new Index( 'fooindex', ['a', 'b'], @@ -96,7 +96,7 @@ public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() ); self::assertEquals( 'CREATE VIRTUAL CLUSTERED INDEX fooindex ON footable (a, b) FOR OLAP WORKLOAD', - $this->_platform->getCreateIndexSQL( + $this->platform->getCreateIndexSQL( new Index( 'fooindex', ['a', 'b'], @@ -111,7 +111,7 @@ public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() // WITH NULLS NOT DISTINCT clause not available on primary indexes. self::assertEquals( 'ALTER TABLE footable ADD PRIMARY KEY (a, b)', - $this->_platform->getCreateIndexSQL( + $this->platform->getCreateIndexSQL( new Index( 'fooindex', ['a', 'b'], @@ -126,7 +126,7 @@ public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() // WITH NULLS NOT DISTINCT clause not available on non-unique indexes. self::assertEquals( 'CREATE INDEX fooindex ON footable (a, b)', - $this->_platform->getCreateIndexSQL( + $this->platform->getCreateIndexSQL( new Index( 'fooindex', ['a', 'b'], diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere16PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere16PlatformTest.php index bbf99527f65..9692ffb1f76 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere16PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere16PlatformTest.php @@ -16,7 +16,7 @@ public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() { self::assertEquals( 'CREATE UNIQUE INDEX fooindex ON footable (a, b) WITH NULLS DISTINCT', - $this->_platform->getCreateIndexSQL( + $this->platform->getCreateIndexSQL( new Index( 'fooindex', ['a', 'b'], @@ -31,7 +31,7 @@ public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() // WITH NULLS DISTINCT clause not available on primary indexes. self::assertEquals( 'ALTER TABLE footable ADD PRIMARY KEY (a, b)', - $this->_platform->getCreateIndexSQL( + $this->platform->getCreateIndexSQL( new Index( 'fooindex', ['a', 'b'], @@ -46,7 +46,7 @@ public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() // WITH NULLS DISTINCT clause not available on non-unique indexes. self::assertEquals( 'CREATE INDEX fooindex ON footable (a, b)', - $this->_platform->getCreateIndexSQL( + $this->platform->getCreateIndexSQL( new Index( 'fooindex', ['a', 'b'], @@ -65,7 +65,7 @@ public function testThrowsExceptionOnInvalidWithNullsNotDistinctIndexOptions() { $this->expectException('UnexpectedValueException'); - $this->_platform->getCreateIndexSQL( + $this->platform->getCreateIndexSQL( new Index( 'fooindex', ['a', 'b'], diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php index 7c6d161c371..294b9836e2e 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Platforms; +use Doctrine\DBAL\DBALException; use Doctrine\DBAL\LockMode; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\SQLAnywherePlatform; @@ -9,12 +10,14 @@ use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ColumnDiff; use Doctrine\DBAL\Schema\Comparator; +use Doctrine\DBAL\Schema\Constraint; use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\TransactionIsolationLevel; use Doctrine\DBAL\Types\Type; +use InvalidArgumentException; use function mt_rand; use function strlen; use function substr; @@ -22,7 +25,7 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase { /** @var SQLAnywherePlatform */ - protected $_platform; + protected $platform; public function createPlatform() { @@ -119,7 +122,7 @@ public function getCreateTableColumnTypeCommentsSQL() public function testHasCorrectPlatformName() { - self::assertEquals('sqlanywhere', $this->_platform->getName()); + self::assertEquals('sqlanywhere', $this->platform->getName()); } public function testGeneratesCreateTableSQLWithCommonIndexes() @@ -137,7 +140,7 @@ public function testGeneratesCreateTableSQLWithCommonIndexes() 'CREATE INDEX IDX_D87F7E0C5E237E06 ON test (name)', 'CREATE INDEX composite_idx ON test (id, name)', ], - $this->_platform->getCreateTableSQL($table) + $this->platform->getCreateTableSQL($table) ); } @@ -162,7 +165,7 @@ public function testGeneratesCreateTableSQLWithForeignKeyConstraints() 'CONSTRAINT FK_D87F7E0C177612A38E7F4319 FOREIGN KEY (fk_1, fk_2) REFERENCES foreign_table (pk_1, pk_2), ' . 'CONSTRAINT named_fk FOREIGN KEY (fk_1, fk_2) REFERENCES foreign_table2 (pk_1, pk_2))', ], - $this->_platform->getCreateTableSQL($table, AbstractPlatform::CREATE_FOREIGNKEYS) + $this->platform->getCreateTableSQL($table, AbstractPlatform::CREATE_FOREIGNKEYS) ); } @@ -176,7 +179,7 @@ public function testGeneratesCreateTableSQLWithCheckConstraints() self::assertEquals( ['CREATE TABLE test (id INT NOT NULL, check_max INT NOT NULL, check_min INT NOT NULL, PRIMARY KEY (id), CHECK (check_max <= 10), CHECK (check_min >= 10))'], - $this->_platform->getCreateTableSQL($table) + $this->platform->getCreateTableSQL($table) ); } @@ -195,7 +198,7 @@ public function testGeneratesTableAlterationWithRemovedColumnCommentSql() self::assertEquals( ['COMMENT ON COLUMN mytable.foo IS NULL'], - $this->_platform->getAlterTableSQL($tableDiff) + $this->platform->getAlterTableSQL($tableDiff) ); } @@ -207,7 +210,7 @@ public function testAppendsLockHint($lockMode, $lockHint) $fromClause = 'FROM users'; $expectedResult = $fromClause . $lockHint; - self::assertSame($expectedResult, $this->_platform->appendLockHint($fromClause, $lockMode)); + self::assertSame($expectedResult, $this->platform->appendLockHint($fromClause, $lockMode)); } public function getLockHints() @@ -225,12 +228,12 @@ public function getLockHints() public function testHasCorrectMaxIdentifierLength() { - self::assertEquals(128, $this->_platform->getMaxIdentifierLength()); + self::assertEquals(128, $this->platform->getMaxIdentifierLength()); } public function testFixesSchemaElementNames() { - $maxIdentifierLength = $this->_platform->getMaxIdentifierLength(); + $maxIdentifierLength = $this->platform->getMaxIdentifierLength(); $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $schemaElementName = ''; @@ -242,11 +245,11 @@ public function testFixesSchemaElementNames() self::assertEquals( $fixedSchemaElementName, - $this->_platform->fixSchemaElementName($schemaElementName) + $this->platform->fixSchemaElementName($schemaElementName) ); self::assertEquals( $fixedSchemaElementName, - $this->_platform->fixSchemaElementName($fixedSchemaElementName) + $this->platform->fixSchemaElementName($fixedSchemaElementName) ); } @@ -259,67 +262,67 @@ public function testGeneratesColumnTypesDeclarationSQL() 'autoincrement' => true, ]; - self::assertEquals('SMALLINT', $this->_platform->getSmallIntTypeDeclarationSQL([])); - self::assertEquals('UNSIGNED SMALLINT', $this->_platform->getSmallIntTypeDeclarationSQL(['unsigned' => true])); - self::assertEquals('UNSIGNED SMALLINT IDENTITY', $this->_platform->getSmallIntTypeDeclarationSQL($fullColumnDef)); - self::assertEquals('INT', $this->_platform->getIntegerTypeDeclarationSQL([])); - self::assertEquals('UNSIGNED INT', $this->_platform->getIntegerTypeDeclarationSQL(['unsigned' => true])); - self::assertEquals('UNSIGNED INT IDENTITY', $this->_platform->getIntegerTypeDeclarationSQL($fullColumnDef)); - self::assertEquals('BIGINT', $this->_platform->getBigIntTypeDeclarationSQL([])); - self::assertEquals('UNSIGNED BIGINT', $this->_platform->getBigIntTypeDeclarationSQL(['unsigned' => true])); - self::assertEquals('UNSIGNED BIGINT IDENTITY', $this->_platform->getBigIntTypeDeclarationSQL($fullColumnDef)); - self::assertEquals('LONG BINARY', $this->_platform->getBlobTypeDeclarationSQL($fullColumnDef)); - self::assertEquals('BIT', $this->_platform->getBooleanTypeDeclarationSQL($fullColumnDef)); - self::assertEquals('TEXT', $this->_platform->getClobTypeDeclarationSQL($fullColumnDef)); - self::assertEquals('DATE', $this->_platform->getDateTypeDeclarationSQL($fullColumnDef)); - self::assertEquals('DATETIME', $this->_platform->getDateTimeTypeDeclarationSQL($fullColumnDef)); - self::assertEquals('TIME', $this->_platform->getTimeTypeDeclarationSQL($fullColumnDef)); - self::assertEquals('UNIQUEIDENTIFIER', $this->_platform->getGuidTypeDeclarationSQL($fullColumnDef)); - - self::assertEquals(1, $this->_platform->getVarcharDefaultLength()); - self::assertEquals(32767, $this->_platform->getVarcharMaxLength()); + self::assertEquals('SMALLINT', $this->platform->getSmallIntTypeDeclarationSQL([])); + self::assertEquals('UNSIGNED SMALLINT', $this->platform->getSmallIntTypeDeclarationSQL(['unsigned' => true])); + self::assertEquals('UNSIGNED SMALLINT IDENTITY', $this->platform->getSmallIntTypeDeclarationSQL($fullColumnDef)); + self::assertEquals('INT', $this->platform->getIntegerTypeDeclarationSQL([])); + self::assertEquals('UNSIGNED INT', $this->platform->getIntegerTypeDeclarationSQL(['unsigned' => true])); + self::assertEquals('UNSIGNED INT IDENTITY', $this->platform->getIntegerTypeDeclarationSQL($fullColumnDef)); + self::assertEquals('BIGINT', $this->platform->getBigIntTypeDeclarationSQL([])); + self::assertEquals('UNSIGNED BIGINT', $this->platform->getBigIntTypeDeclarationSQL(['unsigned' => true])); + self::assertEquals('UNSIGNED BIGINT IDENTITY', $this->platform->getBigIntTypeDeclarationSQL($fullColumnDef)); + self::assertEquals('LONG BINARY', $this->platform->getBlobTypeDeclarationSQL($fullColumnDef)); + self::assertEquals('BIT', $this->platform->getBooleanTypeDeclarationSQL($fullColumnDef)); + self::assertEquals('TEXT', $this->platform->getClobTypeDeclarationSQL($fullColumnDef)); + self::assertEquals('DATE', $this->platform->getDateTypeDeclarationSQL($fullColumnDef)); + self::assertEquals('DATETIME', $this->platform->getDateTimeTypeDeclarationSQL($fullColumnDef)); + self::assertEquals('TIME', $this->platform->getTimeTypeDeclarationSQL($fullColumnDef)); + self::assertEquals('UNIQUEIDENTIFIER', $this->platform->getGuidTypeDeclarationSQL($fullColumnDef)); + + self::assertEquals(1, $this->platform->getVarcharDefaultLength()); + self::assertEquals(32767, $this->platform->getVarcharMaxLength()); } public function testHasNativeGuidType() { - self::assertTrue($this->_platform->hasNativeGuidType()); + self::assertTrue($this->platform->hasNativeGuidType()); } public function testGeneratesDDLSnippets() { - self::assertEquals("CREATE DATABASE 'foobar'", $this->_platform->getCreateDatabaseSQL('foobar')); - self::assertEquals("CREATE DATABASE 'foobar'", $this->_platform->getCreateDatabaseSQL('"foobar"')); - self::assertEquals("CREATE DATABASE 'create'", $this->_platform->getCreateDatabaseSQL('create')); - self::assertEquals("DROP DATABASE 'foobar'", $this->_platform->getDropDatabaseSQL('foobar')); - self::assertEquals("DROP DATABASE 'foobar'", $this->_platform->getDropDatabaseSQL('"foobar"')); - self::assertEquals("DROP DATABASE 'create'", $this->_platform->getDropDatabaseSQL('create')); - self::assertEquals('CREATE GLOBAL TEMPORARY TABLE', $this->_platform->getCreateTemporaryTableSnippetSQL()); - self::assertEquals("START DATABASE 'foobar' AUTOSTOP OFF", $this->_platform->getStartDatabaseSQL('foobar')); - self::assertEquals("START DATABASE 'foobar' AUTOSTOP OFF", $this->_platform->getStartDatabaseSQL('"foobar"')); - self::assertEquals("START DATABASE 'create' AUTOSTOP OFF", $this->_platform->getStartDatabaseSQL('create')); - self::assertEquals('STOP DATABASE "foobar" UNCONDITIONALLY', $this->_platform->getStopDatabaseSQL('foobar')); - self::assertEquals('STOP DATABASE "foobar" UNCONDITIONALLY', $this->_platform->getStopDatabaseSQL('"foobar"')); - self::assertEquals('STOP DATABASE "create" UNCONDITIONALLY', $this->_platform->getStopDatabaseSQL('create')); - self::assertEquals('TRUNCATE TABLE foobar', $this->_platform->getTruncateTableSQL('foobar')); - self::assertEquals('TRUNCATE TABLE foobar', $this->_platform->getTruncateTableSQL('foobar'), true); + self::assertEquals("CREATE DATABASE 'foobar'", $this->platform->getCreateDatabaseSQL('foobar')); + self::assertEquals("CREATE DATABASE 'foobar'", $this->platform->getCreateDatabaseSQL('"foobar"')); + self::assertEquals("CREATE DATABASE 'create'", $this->platform->getCreateDatabaseSQL('create')); + self::assertEquals("DROP DATABASE 'foobar'", $this->platform->getDropDatabaseSQL('foobar')); + self::assertEquals("DROP DATABASE 'foobar'", $this->platform->getDropDatabaseSQL('"foobar"')); + self::assertEquals("DROP DATABASE 'create'", $this->platform->getDropDatabaseSQL('create')); + self::assertEquals('CREATE GLOBAL TEMPORARY TABLE', $this->platform->getCreateTemporaryTableSnippetSQL()); + self::assertEquals("START DATABASE 'foobar' AUTOSTOP OFF", $this->platform->getStartDatabaseSQL('foobar')); + self::assertEquals("START DATABASE 'foobar' AUTOSTOP OFF", $this->platform->getStartDatabaseSQL('"foobar"')); + self::assertEquals("START DATABASE 'create' AUTOSTOP OFF", $this->platform->getStartDatabaseSQL('create')); + self::assertEquals('STOP DATABASE "foobar" UNCONDITIONALLY', $this->platform->getStopDatabaseSQL('foobar')); + self::assertEquals('STOP DATABASE "foobar" UNCONDITIONALLY', $this->platform->getStopDatabaseSQL('"foobar"')); + self::assertEquals('STOP DATABASE "create" UNCONDITIONALLY', $this->platform->getStopDatabaseSQL('create')); + self::assertEquals('TRUNCATE TABLE foobar', $this->platform->getTruncateTableSQL('foobar')); + self::assertEquals('TRUNCATE TABLE foobar', $this->platform->getTruncateTableSQL('foobar'), true); $viewSql = 'SELECT * FROM footable'; - self::assertEquals('CREATE VIEW fooview AS ' . $viewSql, $this->_platform->getCreateViewSQL('fooview', $viewSql)); - self::assertEquals('DROP VIEW fooview', $this->_platform->getDropViewSQL('fooview')); + self::assertEquals('CREATE VIEW fooview AS ' . $viewSql, $this->platform->getCreateViewSQL('fooview', $viewSql)); + self::assertEquals('DROP VIEW fooview', $this->platform->getDropViewSQL('fooview')); } public function testGeneratesPrimaryKeyDeclarationSQL() { self::assertEquals( 'CONSTRAINT pk PRIMARY KEY CLUSTERED (a, b)', - $this->_platform->getPrimaryKeyDeclarationSQL( + $this->platform->getPrimaryKeyDeclarationSQL( new Index(null, ['a', 'b'], true, true, ['clustered']), 'pk' ) ); self::assertEquals( 'PRIMARY KEY (a, b)', - $this->_platform->getPrimaryKeyDeclarationSQL( + $this->platform->getPrimaryKeyDeclarationSQL( new Index(null, ['a', 'b'], true, true) ) ); @@ -327,23 +330,23 @@ public function testGeneratesPrimaryKeyDeclarationSQL() public function testCannotGeneratePrimaryKeyDeclarationSQLWithEmptyColumns() { - $this->expectException('\InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); - $this->_platform->getPrimaryKeyDeclarationSQL(new Index('pk', [], true, true)); + $this->platform->getPrimaryKeyDeclarationSQL(new Index('pk', [], true, true)); } public function testGeneratesCreateUnnamedPrimaryKeySQL() { self::assertEquals( 'ALTER TABLE foo ADD PRIMARY KEY CLUSTERED (a, b)', - $this->_platform->getCreatePrimaryKeySQL( + $this->platform->getCreatePrimaryKeySQL( new Index('pk', ['a', 'b'], true, true, ['clustered']), 'foo' ) ); self::assertEquals( 'ALTER TABLE foo ADD PRIMARY KEY (a, b)', - $this->_platform->getCreatePrimaryKeySQL( + $this->platform->getCreatePrimaryKeySQL( new Index('any_pk_name', ['a', 'b'], true, true), new Table('foo') ) @@ -354,22 +357,22 @@ public function testGeneratesUniqueConstraintDeclarationSQL() { self::assertEquals( 'CONSTRAINT unique_constraint UNIQUE CLUSTERED (a, b)', - $this->_platform->getUniqueConstraintDeclarationSQL( + $this->platform->getUniqueConstraintDeclarationSQL( 'unique_constraint', new Index(null, ['a', 'b'], true, false, ['clustered']) ) ); self::assertEquals( 'UNIQUE (a, b)', - $this->_platform->getUniqueConstraintDeclarationSQL(null, new Index(null, ['a', 'b'], true, false)) + $this->platform->getUniqueConstraintDeclarationSQL(null, new Index(null, ['a', 'b'], true, false)) ); } public function testCannotGenerateUniqueConstraintDeclarationSQLWithEmptyColumns() { - $this->expectException('\InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); - $this->_platform->getUniqueConstraintDeclarationSQL('constr', new Index('constr', [], true)); + $this->platform->getUniqueConstraintDeclarationSQL('constr', new Index('constr', [], true)); } public function testGeneratesForeignKeyConstraintsWithAdvancedPlatformOptionsSQL() @@ -379,7 +382,7 @@ public function testGeneratesForeignKeyConstraintsWithAdvancedPlatformOptionsSQL 'NOT NULL FOREIGN KEY (a, b) ' . 'REFERENCES foreign_table (c, d) ' . 'MATCH UNIQUE SIMPLE ON UPDATE CASCADE ON DELETE SET NULL CHECK ON COMMIT CLUSTERED FOR OLAP WORKLOAD', - $this->_platform->getForeignKeyDeclarationSQL( + $this->platform->getForeignKeyDeclarationSQL( new ForeignKeyConstraint(['a', 'b'], 'foreign_table', ['c', 'd'], 'fk', [ 'notnull' => true, 'match' => SQLAnywherePlatform::FOREIGN_KEY_MATCH_SIMPLE_UNIQUE, @@ -393,7 +396,7 @@ public function testGeneratesForeignKeyConstraintsWithAdvancedPlatformOptionsSQL ); self::assertEquals( 'FOREIGN KEY (a, b) REFERENCES foreign_table (c, d)', - $this->_platform->getForeignKeyDeclarationSQL( + $this->platform->getForeignKeyDeclarationSQL( new ForeignKeyConstraint(['a', 'b'], 'foreign_table', ['c', 'd']) ) ); @@ -401,56 +404,56 @@ public function testGeneratesForeignKeyConstraintsWithAdvancedPlatformOptionsSQL public function testGeneratesForeignKeyMatchClausesSQL() { - self::assertEquals('SIMPLE', $this->_platform->getForeignKeyMatchClauseSQL(1)); - self::assertEquals('FULL', $this->_platform->getForeignKeyMatchClauseSQL(2)); - self::assertEquals('UNIQUE SIMPLE', $this->_platform->getForeignKeyMatchClauseSQL(129)); - self::assertEquals('UNIQUE FULL', $this->_platform->getForeignKeyMatchClauseSQL(130)); + self::assertEquals('SIMPLE', $this->platform->getForeignKeyMatchClauseSQL(1)); + self::assertEquals('FULL', $this->platform->getForeignKeyMatchClauseSQL(2)); + self::assertEquals('UNIQUE SIMPLE', $this->platform->getForeignKeyMatchClauseSQL(129)); + self::assertEquals('UNIQUE FULL', $this->platform->getForeignKeyMatchClauseSQL(130)); } public function testCannotGenerateInvalidForeignKeyMatchClauseSQL() { - $this->expectException('\InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); - $this->_platform->getForeignKeyMatchCLauseSQL(3); + $this->platform->getForeignKeyMatchCLauseSQL(3); } public function testCannotGenerateForeignKeyConstraintSQLWithEmptyLocalColumns() { - $this->expectException('\InvalidArgumentException'); - $this->_platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint([], 'foreign_tbl', ['c', 'd'])); + $this->expectException(InvalidArgumentException::class); + $this->platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint([], 'foreign_tbl', ['c', 'd'])); } public function testCannotGenerateForeignKeyConstraintSQLWithEmptyForeignColumns() { - $this->expectException('\InvalidArgumentException'); - $this->_platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint(['a', 'b'], 'foreign_tbl', [])); + $this->expectException(InvalidArgumentException::class); + $this->platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint(['a', 'b'], 'foreign_tbl', [])); } public function testCannotGenerateForeignKeyConstraintSQLWithEmptyForeignTableName() { - $this->expectException('\InvalidArgumentException'); - $this->_platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint(['a', 'b'], '', ['c', 'd'])); + $this->expectException(InvalidArgumentException::class); + $this->platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint(['a', 'b'], '', ['c', 'd'])); } public function testCannotGenerateCommonIndexWithCreateConstraintSQL() { - $this->expectException('\InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); - $this->_platform->getCreateConstraintSQL(new Index('fooindex', []), new Table('footable')); + $this->platform->getCreateConstraintSQL(new Index('fooindex', []), new Table('footable')); } public function testCannotGenerateCustomConstraintWithCreateConstraintSQL() { - $this->expectException('\InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); - $this->_platform->getCreateConstraintSQL($this->createMock('\Doctrine\DBAL\Schema\Constraint'), 'footable'); + $this->platform->getCreateConstraintSQL($this->createMock(Constraint::class), 'footable'); } public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() { self::assertEquals( 'CREATE VIRTUAL UNIQUE CLUSTERED INDEX fooindex ON footable (a, b) FOR OLAP WORKLOAD', - $this->_platform->getCreateIndexSQL( + $this->platform->getCreateIndexSQL( new Index( 'fooindex', ['a', 'b'], @@ -465,18 +468,18 @@ public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() public function testDoesNotSupportIndexDeclarationInCreateAlterTableStatements() { - $this->expectException('\Doctrine\DBAL\DBALException'); + $this->expectException(DBALException::class); - $this->_platform->getIndexDeclarationSQL('index', new Index('index', [])); + $this->platform->getIndexDeclarationSQL('index', new Index('index', [])); } public function testGeneratesDropIndexSQL() { $index = new Index('fooindex', []); - self::assertEquals('DROP INDEX fooindex', $this->_platform->getDropIndexSQL($index)); - self::assertEquals('DROP INDEX footable.fooindex', $this->_platform->getDropIndexSQL($index, 'footable')); - self::assertEquals('DROP INDEX footable.fooindex', $this->_platform->getDropIndexSQL( + self::assertEquals('DROP INDEX fooindex', $this->platform->getDropIndexSQL($index)); + self::assertEquals('DROP INDEX footable.fooindex', $this->platform->getDropIndexSQL($index, 'footable')); + self::assertEquals('DROP INDEX footable.fooindex', $this->platform->getDropIndexSQL( $index, new Table('footable') )); @@ -484,97 +487,97 @@ public function testGeneratesDropIndexSQL() public function testCannotGenerateDropIndexSQLWithInvalidIndexParameter() { - $this->expectException('\InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); - $this->_platform->getDropIndexSQL(['index'], 'table'); + $this->platform->getDropIndexSQL(['index'], 'table'); } public function testCannotGenerateDropIndexSQLWithInvalidTableParameter() { - $this->expectException('\InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); - $this->_platform->getDropIndexSQL('index', ['table']); + $this->platform->getDropIndexSQL('index', ['table']); } public function testGeneratesSQLSnippets() { - self::assertEquals('STRING(column1, "string1", column2, "string2")', $this->_platform->getConcatExpression( + self::assertEquals('STRING(column1, "string1", column2, "string2")', $this->platform->getConcatExpression( 'column1', '"string1"', 'column2', '"string2"' )); - self::assertEquals('CURRENT DATE', $this->_platform->getCurrentDateSQL()); - self::assertEquals('CURRENT TIME', $this->_platform->getCurrentTimeSQL()); - self::assertEquals('CURRENT TIMESTAMP', $this->_platform->getCurrentTimestampSQL()); - self::assertEquals("DATEADD(DAY, 4, '1987/05/02')", $this->_platform->getDateAddDaysExpression("'1987/05/02'", 4)); - self::assertEquals("DATEADD(HOUR, 12, '1987/05/02')", $this->_platform->getDateAddHourExpression("'1987/05/02'", 12)); - self::assertEquals("DATEADD(MINUTE, 2, '1987/05/02')", $this->_platform->getDateAddMinutesExpression("'1987/05/02'", 2)); - self::assertEquals("DATEADD(MONTH, 102, '1987/05/02')", $this->_platform->getDateAddMonthExpression("'1987/05/02'", 102)); - self::assertEquals("DATEADD(QUARTER, 5, '1987/05/02')", $this->_platform->getDateAddQuartersExpression("'1987/05/02'", 5)); - self::assertEquals("DATEADD(SECOND, 1, '1987/05/02')", $this->_platform->getDateAddSecondsExpression("'1987/05/02'", 1)); - self::assertEquals("DATEADD(WEEK, 3, '1987/05/02')", $this->_platform->getDateAddWeeksExpression("'1987/05/02'", 3)); - self::assertEquals("DATEADD(YEAR, 10, '1987/05/02')", $this->_platform->getDateAddYearsExpression("'1987/05/02'", 10)); - self::assertEquals("DATEDIFF(day, '1987/04/01', '1987/05/02')", $this->_platform->getDateDiffExpression("'1987/05/02'", "'1987/04/01'")); - self::assertEquals("DATEADD(DAY, -1 * 4, '1987/05/02')", $this->_platform->getDateSubDaysExpression("'1987/05/02'", 4)); - self::assertEquals("DATEADD(HOUR, -1 * 12, '1987/05/02')", $this->_platform->getDateSubHourExpression("'1987/05/02'", 12)); - self::assertEquals("DATEADD(MINUTE, -1 * 2, '1987/05/02')", $this->_platform->getDateSubMinutesExpression("'1987/05/02'", 2)); - self::assertEquals("DATEADD(MONTH, -1 * 102, '1987/05/02')", $this->_platform->getDateSubMonthExpression("'1987/05/02'", 102)); - self::assertEquals("DATEADD(QUARTER, -1 * 5, '1987/05/02')", $this->_platform->getDateSubQuartersExpression("'1987/05/02'", 5)); - self::assertEquals("DATEADD(SECOND, -1 * 1, '1987/05/02')", $this->_platform->getDateSubSecondsExpression("'1987/05/02'", 1)); - self::assertEquals("DATEADD(WEEK, -1 * 3, '1987/05/02')", $this->_platform->getDateSubWeeksExpression("'1987/05/02'", 3)); - self::assertEquals("DATEADD(YEAR, -1 * 10, '1987/05/02')", $this->_platform->getDateSubYearsExpression("'1987/05/02'", 10)); - self::assertEquals('Y-m-d H:i:s.u', $this->_platform->getDateTimeFormatString()); - self::assertEquals('H:i:s.u', $this->_platform->getTimeFormatString()); - self::assertEquals('', $this->_platform->getForUpdateSQL()); - self::assertEquals('NEWID()', $this->_platform->getGuidExpression()); - self::assertEquals('LOCATE(string_column, substring_column)', $this->_platform->getLocateExpression('string_column', 'substring_column')); - self::assertEquals('LOCATE(string_column, substring_column, 1)', $this->_platform->getLocateExpression('string_column', 'substring_column', 1)); - self::assertEquals("HASH(column, 'MD5')", $this->_platform->getMd5Expression('column')); - self::assertEquals('SUBSTRING(column, 5)', $this->_platform->getSubstringExpression('column', 5)); - self::assertEquals('SUBSTRING(column, 5, 2)', $this->_platform->getSubstringExpression('column', 5, 2)); - self::assertEquals('GLOBAL TEMPORARY', $this->_platform->getTemporaryTableSQL()); + self::assertEquals('CURRENT DATE', $this->platform->getCurrentDateSQL()); + self::assertEquals('CURRENT TIME', $this->platform->getCurrentTimeSQL()); + self::assertEquals('CURRENT TIMESTAMP', $this->platform->getCurrentTimestampSQL()); + self::assertEquals("DATEADD(DAY, 4, '1987/05/02')", $this->platform->getDateAddDaysExpression("'1987/05/02'", 4)); + self::assertEquals("DATEADD(HOUR, 12, '1987/05/02')", $this->platform->getDateAddHourExpression("'1987/05/02'", 12)); + self::assertEquals("DATEADD(MINUTE, 2, '1987/05/02')", $this->platform->getDateAddMinutesExpression("'1987/05/02'", 2)); + self::assertEquals("DATEADD(MONTH, 102, '1987/05/02')", $this->platform->getDateAddMonthExpression("'1987/05/02'", 102)); + self::assertEquals("DATEADD(QUARTER, 5, '1987/05/02')", $this->platform->getDateAddQuartersExpression("'1987/05/02'", 5)); + self::assertEquals("DATEADD(SECOND, 1, '1987/05/02')", $this->platform->getDateAddSecondsExpression("'1987/05/02'", 1)); + self::assertEquals("DATEADD(WEEK, 3, '1987/05/02')", $this->platform->getDateAddWeeksExpression("'1987/05/02'", 3)); + self::assertEquals("DATEADD(YEAR, 10, '1987/05/02')", $this->platform->getDateAddYearsExpression("'1987/05/02'", 10)); + self::assertEquals("DATEDIFF(day, '1987/04/01', '1987/05/02')", $this->platform->getDateDiffExpression("'1987/05/02'", "'1987/04/01'")); + self::assertEquals("DATEADD(DAY, -1 * 4, '1987/05/02')", $this->platform->getDateSubDaysExpression("'1987/05/02'", 4)); + self::assertEquals("DATEADD(HOUR, -1 * 12, '1987/05/02')", $this->platform->getDateSubHourExpression("'1987/05/02'", 12)); + self::assertEquals("DATEADD(MINUTE, -1 * 2, '1987/05/02')", $this->platform->getDateSubMinutesExpression("'1987/05/02'", 2)); + self::assertEquals("DATEADD(MONTH, -1 * 102, '1987/05/02')", $this->platform->getDateSubMonthExpression("'1987/05/02'", 102)); + self::assertEquals("DATEADD(QUARTER, -1 * 5, '1987/05/02')", $this->platform->getDateSubQuartersExpression("'1987/05/02'", 5)); + self::assertEquals("DATEADD(SECOND, -1 * 1, '1987/05/02')", $this->platform->getDateSubSecondsExpression("'1987/05/02'", 1)); + self::assertEquals("DATEADD(WEEK, -1 * 3, '1987/05/02')", $this->platform->getDateSubWeeksExpression("'1987/05/02'", 3)); + self::assertEquals("DATEADD(YEAR, -1 * 10, '1987/05/02')", $this->platform->getDateSubYearsExpression("'1987/05/02'", 10)); + self::assertEquals('Y-m-d H:i:s.u', $this->platform->getDateTimeFormatString()); + self::assertEquals('H:i:s.u', $this->platform->getTimeFormatString()); + self::assertEquals('', $this->platform->getForUpdateSQL()); + self::assertEquals('NEWID()', $this->platform->getGuidExpression()); + self::assertEquals('LOCATE(string_column, substring_column)', $this->platform->getLocateExpression('string_column', 'substring_column')); + self::assertEquals('LOCATE(string_column, substring_column, 1)', $this->platform->getLocateExpression('string_column', 'substring_column', 1)); + self::assertEquals("HASH(column, 'MD5')", $this->platform->getMd5Expression('column')); + self::assertEquals('SUBSTRING(column, 5)', $this->platform->getSubstringExpression('column', 5)); + self::assertEquals('SUBSTRING(column, 5, 2)', $this->platform->getSubstringExpression('column', 5, 2)); + self::assertEquals('GLOBAL TEMPORARY', $this->platform->getTemporaryTableSQL()); self::assertEquals( 'LTRIM(column)', - $this->_platform->getTrimExpression('column', TrimMode::LEADING) + $this->platform->getTrimExpression('column', TrimMode::LEADING) ); self::assertEquals( 'RTRIM(column)', - $this->_platform->getTrimExpression('column', TrimMode::TRAILING) + $this->platform->getTrimExpression('column', TrimMode::TRAILING) ); self::assertEquals( 'TRIM(column)', - $this->_platform->getTrimExpression('column') + $this->platform->getTrimExpression('column') ); self::assertEquals( 'TRIM(column)', - $this->_platform->getTrimExpression('column', TrimMode::UNSPECIFIED) + $this->platform->getTrimExpression('column', TrimMode::UNSPECIFIED) ); self::assertEquals( "SUBSTR(column, PATINDEX('%[^' + c + ']%', column))", - $this->_platform->getTrimExpression('column', TrimMode::LEADING, 'c') + $this->platform->getTrimExpression('column', TrimMode::LEADING, 'c') ); self::assertEquals( "REVERSE(SUBSTR(REVERSE(column), PATINDEX('%[^' + c + ']%', REVERSE(column))))", - $this->_platform->getTrimExpression('column', TrimMode::TRAILING, 'c') + $this->platform->getTrimExpression('column', TrimMode::TRAILING, 'c') ); self::assertEquals( "REVERSE(SUBSTR(REVERSE(SUBSTR(column, PATINDEX('%[^' + c + ']%', column))), PATINDEX('%[^' + c + ']%', " . "REVERSE(SUBSTR(column, PATINDEX('%[^' + c + ']%', column))))))", - $this->_platform->getTrimExpression('column', null, 'c') + $this->platform->getTrimExpression('column', null, 'c') ); self::assertEquals( "REVERSE(SUBSTR(REVERSE(SUBSTR(column, PATINDEX('%[^' + c + ']%', column))), PATINDEX('%[^' + c + ']%', " . "REVERSE(SUBSTR(column, PATINDEX('%[^' + c + ']%', column))))))", - $this->_platform->getTrimExpression('column', TrimMode::UNSPECIFIED, 'c') + $this->platform->getTrimExpression('column', TrimMode::UNSPECIFIED, 'c') ); } public function testDoesNotSupportRegexp() { - $this->expectException('\Doctrine\DBAL\DBALException'); + $this->expectException(DBALException::class); - $this->_platform->getRegexpExpression(); + $this->platform->getRegexpExpression(); } public function testHasCorrectDateTimeTzFormatString() @@ -582,14 +585,14 @@ public function testHasCorrectDateTimeTzFormatString() // 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 // equals the normal date time format so that it corresponds to the declaration SQL equality (datetimetz -> datetime). - self::assertEquals($this->_platform->getDateTimeFormatString(), $this->_platform->getDateTimeTzFormatString()); + self::assertEquals($this->platform->getDateTimeFormatString(), $this->platform->getDateTimeTzFormatString()); } public function testHasCorrectDefaultTransactionIsolationLevel() { self::assertEquals( TransactionIsolationLevel::READ_UNCOMMITTED, - $this->_platform->getDefaultTransactionIsolationLevel() + $this->platform->getDefaultTransactionIsolationLevel() ); } @@ -597,34 +600,34 @@ public function testGeneratesTransactionsCommands() { self::assertEquals( 'SET TEMPORARY OPTION isolation_level = 0', - $this->_platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_UNCOMMITTED) + $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_UNCOMMITTED) ); self::assertEquals( 'SET TEMPORARY OPTION isolation_level = 1', - $this->_platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_COMMITTED) + $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_COMMITTED) ); self::assertEquals( 'SET TEMPORARY OPTION isolation_level = 2', - $this->_platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::REPEATABLE_READ) + $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::REPEATABLE_READ) ); self::assertEquals( 'SET TEMPORARY OPTION isolation_level = 3', - $this->_platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::SERIALIZABLE) + $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::SERIALIZABLE) ); } public function testCannotGenerateTransactionCommandWithInvalidIsolationLevel() { - $this->expectException('\InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); - $this->_platform->getSetTransactionIsolationSQL('invalid_transaction_isolation_level'); + $this->platform->getSetTransactionIsolationSQL('invalid_transaction_isolation_level'); } public function testModifiesLimitQuery() { self::assertEquals( 'SELECT TOP 10 * FROM user', - $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0) + $this->platform->modifyLimitQuery('SELECT * FROM user', 10, 0) ); } @@ -632,7 +635,7 @@ public function testModifiesLimitQueryWithEmptyOffset() { self::assertEquals( 'SELECT TOP 10 * FROM user', - $this->_platform->modifyLimitQuery('SELECT * FROM user', 10) + $this->platform->modifyLimitQuery('SELECT * FROM user', 10) ); } @@ -640,11 +643,11 @@ public function testModifiesLimitQueryWithOffset() { self::assertEquals( 'SELECT TOP 10 START AT 6 * FROM user', - $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 5) + $this->platform->modifyLimitQuery('SELECT * FROM user', 10, 5) ); self::assertEquals( 'SELECT TOP ALL START AT 6 * FROM user', - $this->_platform->modifyLimitQuery('SELECT * FROM user', 0, 5) + $this->platform->modifyLimitQuery('SELECT * FROM user', 0, 5) ); } @@ -652,110 +655,110 @@ public function testModifiesLimitQueryWithSubSelect() { self::assertEquals( 'SELECT TOP 10 * FROM (SELECT u.id as uid, u.name as uname FROM user) AS doctrine_tbl', - $this->_platform->modifyLimitQuery('SELECT * FROM (SELECT u.id as uid, u.name as uname FROM user) AS doctrine_tbl', 10) + $this->platform->modifyLimitQuery('SELECT * FROM (SELECT u.id as uid, u.name as uname FROM user) AS doctrine_tbl', 10) ); } public function testPrefersIdentityColumns() { - self::assertTrue($this->_platform->prefersIdentityColumns()); + self::assertTrue($this->platform->prefersIdentityColumns()); } public function testDoesNotPreferSequences() { - self::assertFalse($this->_platform->prefersSequences()); + self::assertFalse($this->platform->prefersSequences()); } public function testSupportsIdentityColumns() { - self::assertTrue($this->_platform->supportsIdentityColumns()); + self::assertTrue($this->platform->supportsIdentityColumns()); } public function testSupportsPrimaryConstraints() { - self::assertTrue($this->_platform->supportsPrimaryConstraints()); + self::assertTrue($this->platform->supportsPrimaryConstraints()); } public function testSupportsForeignKeyConstraints() { - self::assertTrue($this->_platform->supportsForeignKeyConstraints()); + self::assertTrue($this->platform->supportsForeignKeyConstraints()); } public function testSupportsForeignKeyOnUpdate() { - self::assertTrue($this->_platform->supportsForeignKeyOnUpdate()); + self::assertTrue($this->platform->supportsForeignKeyOnUpdate()); } public function testSupportsAlterTable() { - self::assertTrue($this->_platform->supportsAlterTable()); + self::assertTrue($this->platform->supportsAlterTable()); } public function testSupportsTransactions() { - self::assertTrue($this->_platform->supportsTransactions()); + self::assertTrue($this->platform->supportsTransactions()); } public function testSupportsSchemas() { - self::assertFalse($this->_platform->supportsSchemas()); + self::assertFalse($this->platform->supportsSchemas()); } public function testSupportsIndexes() { - self::assertTrue($this->_platform->supportsIndexes()); + self::assertTrue($this->platform->supportsIndexes()); } public function testSupportsCommentOnStatement() { - self::assertTrue($this->_platform->supportsCommentOnStatement()); + self::assertTrue($this->platform->supportsCommentOnStatement()); } public function testSupportsSavePoints() { - self::assertTrue($this->_platform->supportsSavepoints()); + self::assertTrue($this->platform->supportsSavepoints()); } public function testSupportsReleasePoints() { - self::assertTrue($this->_platform->supportsReleaseSavepoints()); + self::assertTrue($this->platform->supportsReleaseSavepoints()); } public function testSupportsCreateDropDatabase() { - self::assertTrue($this->_platform->supportsCreateDropDatabase()); + self::assertTrue($this->platform->supportsCreateDropDatabase()); } public function testSupportsGettingAffectedRows() { - self::assertTrue($this->_platform->supportsGettingAffectedRows()); + self::assertTrue($this->platform->supportsGettingAffectedRows()); } public function testDoesNotSupportSequences() { - self::assertFalse($this->_platform->supportsSequences()); + self::assertFalse($this->platform->supportsSequences()); } public function testDoesNotSupportInlineColumnComments() { - self::assertFalse($this->_platform->supportsInlineColumnComments()); + self::assertFalse($this->platform->supportsInlineColumnComments()); } public function testCannotEmulateSchemas() { - self::assertFalse($this->_platform->canEmulateSchemas()); + self::assertFalse($this->platform->canEmulateSchemas()); } public function testInitializesDoctrineTypeMappings() { - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('integer')); - self::assertSame('integer', $this->_platform->getDoctrineTypeMapping('integer')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('integer')); + self::assertSame('integer', $this->platform->getDoctrineTypeMapping('integer')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('binary')); - self::assertSame('binary', $this->_platform->getDoctrineTypeMapping('binary')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('binary')); + self::assertSame('binary', $this->platform->getDoctrineTypeMapping('binary')); - self::assertTrue($this->_platform->hasDoctrineTypeMappingFor('varbinary')); - self::assertSame('binary', $this->_platform->getDoctrineTypeMapping('varbinary')); + self::assertTrue($this->platform->hasDoctrineTypeMappingFor('varbinary')); + self::assertSame('binary', $this->platform->getDoctrineTypeMapping('varbinary')); } protected function getBinaryDefaultLength() @@ -770,13 +773,13 @@ protected function getBinaryMaxLength() public function testReturnsBinaryTypeDeclarationSQL() { - self::assertSame('VARBINARY(1)', $this->_platform->getBinaryTypeDeclarationSQL([])); - self::assertSame('VARBINARY(1)', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 0])); - self::assertSame('VARBINARY(32767)', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 32767])); + self::assertSame('VARBINARY(1)', $this->platform->getBinaryTypeDeclarationSQL([])); + self::assertSame('VARBINARY(1)', $this->platform->getBinaryTypeDeclarationSQL(['length' => 0])); + self::assertSame('VARBINARY(32767)', $this->platform->getBinaryTypeDeclarationSQL(['length' => 32767])); - self::assertSame('BINARY(1)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true])); - self::assertSame('BINARY(1)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 0])); - self::assertSame('BINARY(32767)', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 32767])); + self::assertSame('BINARY(1)', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true])); + self::assertSame('BINARY(1)', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 0])); + self::assertSame('BINARY(32767)', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 32767])); } /** @@ -785,8 +788,8 @@ public function testReturnsBinaryTypeDeclarationSQL() */ public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() { - self::assertSame('LONG BINARY', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 32768])); - self::assertSame('LONG BINARY', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 32768])); + self::assertSame('LONG BINARY', $this->platform->getBinaryTypeDeclarationSQL(['length' => 32768])); + self::assertSame('LONG BINARY', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 32768])); } /** @@ -858,7 +861,7 @@ protected function getQuotedAlterTableRenameIndexInSchemaSQL() */ public function testReturnsGuidTypeDeclarationSQL() { - self::assertSame('UNIQUEIDENTIFIER', $this->_platform->getGuidTypeDeclarationSQL([])); + self::assertSame('UNIQUEIDENTIFIER', $this->platform->getGuidTypeDeclarationSQL([])); } /** @@ -909,10 +912,10 @@ public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() $tableDiff = $comparator->diffTable($table1, $table2); - self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); + self::assertInstanceOf(TableDiff::class, $tableDiff); self::assertSame( ['COMMENT ON COLUMN "foo"."bar" IS \'baz\''], - $this->_platform->getAlterTableSQL($tableDiff) + $this->platform->getAlterTableSQL($tableDiff) ); } @@ -986,7 +989,7 @@ public function testQuotesSchemaNameInListTableColumnsSQL() { self::assertContains( "'Foo''Bar\\'", - $this->_platform->getListTableColumnsSQL("Foo'Bar\\.baz_table"), + $this->platform->getListTableColumnsSQL("Foo'Bar\\.baz_table"), '', true ); @@ -997,7 +1000,7 @@ public function testQuotesSchemaNameInListTableColumnsSQL() */ public function testQuotesTableNameInListTableConstraintsSQL() { - self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true); } /** @@ -1007,7 +1010,7 @@ public function testQuotesSchemaNameInListTableConstraintsSQL() { self::assertContains( "'Foo''Bar\\'", - $this->_platform->getListTableConstraintsSQL("Foo'Bar\\.baz_table"), + $this->platform->getListTableConstraintsSQL("Foo'Bar\\.baz_table"), '', true ); @@ -1018,7 +1021,7 @@ public function testQuotesSchemaNameInListTableConstraintsSQL() */ public function testQuotesTableNameInListTableForeignKeysSQL() { - self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true); } /** @@ -1028,7 +1031,7 @@ public function testQuotesSchemaNameInListTableForeignKeysSQL() { self::assertContains( "'Foo''Bar\\'", - $this->_platform->getListTableForeignKeysSQL("Foo'Bar\\.baz_table"), + $this->platform->getListTableForeignKeysSQL("Foo'Bar\\.baz_table"), '', true ); @@ -1039,7 +1042,7 @@ public function testQuotesSchemaNameInListTableForeignKeysSQL() */ public function testQuotesTableNameInListTableIndexesSQL() { - self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableIndexesSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\"), '', true); } /** @@ -1049,7 +1052,7 @@ public function testQuotesSchemaNameInListTableIndexesSQL() { self::assertContains( "'Foo''Bar\\'", - $this->_platform->getListTableIndexesSQL("Foo'Bar\\.baz_table"), + $this->platform->getListTableIndexesSQL("Foo'Bar\\.baz_table"), '', true ); diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2008PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2008PlatformTest.php index 024bf65de93..3083ab7b606 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2008PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2008PlatformTest.php @@ -13,6 +13,6 @@ public function createPlatform() public function testGeneratesTypeDeclarationForDateTimeTz() { - self::assertEquals('DATETIMEOFFSET(6)', $this->_platform->getDateTimeTzTypeDeclarationSQL([])); + 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 00dcdf24cb6..b908c427c28 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php @@ -15,12 +15,12 @@ public function createPlatform() public function testSupportsSequences() { - self::assertTrue($this->_platform->supportsSequences()); + self::assertTrue($this->platform->supportsSequences()); } public function testDoesNotPreferSequences() { - self::assertFalse($this->_platform->prefersSequences()); + self::assertFalse($this->platform->prefersSequences()); } public function testGeneratesSequenceSqlCommands() @@ -28,95 +28,95 @@ public function testGeneratesSequenceSqlCommands() $sequence = new Sequence('myseq', 20, 1); self::assertEquals( 'CREATE SEQUENCE myseq START WITH 1 INCREMENT BY 20 MINVALUE 1', - $this->_platform->getCreateSequenceSQL($sequence) + $this->platform->getCreateSequenceSQL($sequence) ); self::assertEquals( 'ALTER SEQUENCE myseq INCREMENT BY 20', - $this->_platform->getAlterSequenceSQL($sequence) + $this->platform->getAlterSequenceSQL($sequence) ); self::assertEquals( 'DROP SEQUENCE myseq', - $this->_platform->getDropSequenceSQL('myseq') + $this->platform->getDropSequenceSQL('myseq') ); self::assertEquals( 'SELECT NEXT VALUE FOR myseq', - $this->_platform->getSequenceNextValSQL('myseq') + $this->platform->getSequenceNextValSQL('myseq') ); } public function testModifyLimitQuery() { - $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0); + $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() { - $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10); + $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() { - $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user ORDER BY username DESC', 10, 5); + $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() { - $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user ORDER BY username ASC', 10); + $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() { - $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user order by username', 10); + $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() { - $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user ORDER BY username DESC', 10); + $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() { - $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user ORDER BY username DESC, usereamil ASC', 10); + $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() { - $sql = $this->_platform->modifyLimitQuery('SELECT * FROM (SELECT u.id as uid, u.name as uname) dctrn_result', 10); + $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() { - $sql = $this->_platform->modifyLimitQuery('SELECT * FROM (SELECT u.id as uid, u.name as uname) dctrn_result ORDER BY uname DESC', 10); + $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); - $sql = $this->_platform->modifyLimitQuery('SELECT * FROM (SELECT u.id, u.name) dctrn_result ORDER BY name DESC', 10); + $sql = $this->platform->modifyLimitQuery('SELECT * FROM (SELECT u.id, u.name) dctrn_result ORDER BY name DESC', 10); 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() { - $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); + $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); - $sql = $this->_platform->modifyLimitQuery('SELECT * FROM (SELECT u.id uid, u.name uname) dctrn_result ORDER BY uname DESC, uid ASC', 10, 5); + $sql = $this->platform->modifyLimitQuery('SELECT * FROM (SELECT u.id uid, u.name uname) dctrn_result ORDER BY uname DESC, uid ASC', 10, 5); self::assertEquals('SELECT * FROM (SELECT u.id uid, u.name uname) dctrn_result ORDER BY uname DESC, uid ASC OFFSET 5 ROWS FETCH NEXT 10 ROWS ONLY', $sql); - $sql = $this->_platform->modifyLimitQuery('SELECT * FROM (SELECT u.id, u.name) dctrn_result ORDER BY name DESC, id ASC', 10, 5); + $sql = $this->platform->modifyLimitQuery('SELECT * FROM (SELECT u.id, u.name) dctrn_result ORDER BY name DESC, id ASC', 10, 5); 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() { - $sql = $this->_platform->modifyLimitQuery('SELECT a.fromFoo, fromBar FROM foo', 10); + $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); } @@ -130,7 +130,7 @@ public function testModifyLimitQueryWithExtraLongQuery() $query .= 'AND (table2.column2 = table7.column7) AND (table2.column2 = table8.column8) AND (table3.column3 = table4.column4) AND (table3.column3 = table5.column5) AND (table3.column3 = table6.column6) AND (table3.column3 = table7.column7) AND (table3.column3 = table8.column8) AND (table4.column4 = table5.column5) AND (table4.column4 = table6.column6) AND (table4.column4 = table7.column7) AND (table4.column4 = table8.column8) '; $query .= 'AND (table5.column5 = table6.column6) AND (table5.column5 = table7.column7) AND (table5.column5 = table8.column8) AND (table6.column6 = table7.column7) AND (table6.column6 = table8.column8) AND (table7.column7 = table8.column8)'; - $sql = $this->_platform->modifyLimitQuery($query, 10); + $sql = $this->platform->modifyLimitQuery($query, 10); $expected = '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 '; $expected .= '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) '; @@ -148,7 +148,7 @@ public function testModifyLimitQueryWithOrderByClause() { $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'; - $actual = $this->_platform->modifyLimitQuery($sql, 10, 5); + $actual = $this->platform->modifyLimitQuery($sql, 10, 5); self::assertEquals($expected, $actual); } @@ -158,7 +158,7 @@ public function testModifyLimitQueryWithOrderByClause() */ public function testModifyLimitQueryWithSubSelectInSelectList() { - $sql = $this->_platform->modifyLimitQuery( + $sql = $this->platform->modifyLimitQuery( 'SELECT ' . 'u.id, ' . '(u.foo/2) foodiv, ' . @@ -188,7 +188,7 @@ public function testModifyLimitQueryWithSubSelectInSelectList() */ public function testModifyLimitQueryWithSubSelectInSelectListAndOrderByClause() { - $sql = $this->_platform->modifyLimitQuery( + $sql = $this->platform->modifyLimitQuery( 'SELECT ' . 'u.id, ' . '(u.foo/2) foodiv, ' . @@ -220,7 +220,7 @@ public function testModifyLimitQueryWithSubSelectInSelectListAndOrderByClause() */ public function testModifyLimitQueryWithAggregateFunctionInOrderByClause() { - $sql = $this->_platform->modifyLimitQuery( + $sql = $this->platform->modifyLimitQuery( 'SELECT ' . 'MAX(heading_id) aliased, ' . 'code ' . @@ -245,7 +245,7 @@ public function testModifyLimitQueryWithAggregateFunctionInOrderByClause() public function testModifyLimitQueryWithFromSubquery() { - $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); + $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); $expected = 'SELECT DISTINCT id_0 FROM (SELECT k0_.id AS id_0 FROM key_measure k0_ WHERE (k0_.id_zone in(2))) dctrn_result ORDER BY 1 OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY'; @@ -254,7 +254,7 @@ public function testModifyLimitQueryWithFromSubquery() public function testModifyLimitQueryWithFromSubqueryAndOrder() { - $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); + $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); $expected = '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 OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY'; @@ -263,7 +263,7 @@ public function testModifyLimitQueryWithFromSubqueryAndOrder() public function testModifyLimitQueryWithComplexOrderByExpression() { - $sql = $this->_platform->modifyLimitQuery('SELECT * FROM table ORDER BY (table.x * table.y) DESC', 10); + $sql = $this->platform->modifyLimitQuery('SELECT * FROM table ORDER BY (table.x * table.y) DESC', 10); $expected = 'SELECT * FROM table ORDER BY (table.x * table.y) DESC OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY'; @@ -290,7 +290,7 @@ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromBas . 'LEFT JOIN join_table t2 ON t1.id = t2.table_id' . ') dctrn_result ' . 'ORDER BY id_0 ASC OFFSET 0 ROWS FETCH NEXT 5 ROWS ONLY'; - $sql = $this->_platform->modifyLimitQuery($querySql, 5); + $sql = $this->platform->modifyLimitQuery($querySql, 5); self::assertEquals($alteredSql, $sql); } @@ -313,7 +313,7 @@ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromJoi . 'LEFT JOIN join_table t2 ON t1.id = t2.table_id' . ') dctrn_result ' . 'ORDER BY name_1 ASC OFFSET 0 ROWS FETCH NEXT 5 ROWS ONLY'; - $sql = $this->_platform->modifyLimitQuery($querySql, 5); + $sql = $this->platform->modifyLimitQuery($querySql, 5); self::assertEquals($alteredSql, $sql); } @@ -336,7 +336,7 @@ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnsFromBo . 'LEFT JOIN join_table t2 ON t1.id = t2.table_id' . ') dctrn_result ' . 'ORDER BY name_1 ASC, foo_2 DESC OFFSET 0 ROWS FETCH NEXT 5 ROWS ONLY'; - $sql = $this->_platform->modifyLimitQuery($querySql, 5); + $sql = $this->platform->modifyLimitQuery($querySql, 5); self::assertEquals($alteredSql, $sql); } @@ -347,7 +347,7 @@ public function testModifyLimitSubquerySimple() . 'FROM key_table k0_ WHERE (k0_.where_field IN (1))) dctrn_result'; $alteredSql = 'SELECT DISTINCT id_0 FROM (SELECT k0_.id AS id_0, k0_.field AS field_1 ' . 'FROM key_table k0_ WHERE (k0_.where_field IN (1))) dctrn_result ORDER BY 1 OFFSET 0 ROWS FETCH NEXT 20 ROWS ONLY'; - $sql = $this->_platform->modifyLimitQuery($querySql, 20); + $sql = $this->platform->modifyLimitQuery($querySql, 20); self::assertEquals($alteredSql, $sql); } @@ -355,12 +355,12 @@ public function testModifyLimitQueryWithTopNSubQueryWithOrderBy() { $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'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->platform->modifyLimitQuery($querySql, 10); self::assertEquals($expectedSql, $sql); $querySql = 'SELECT * FROM test t WHERE t.id = (SELECT TOP 1 t2.id FROM test t2 ORDER BY t2.data DESC) ORDER BY t.data2 DESC'; $expectedSql = 'SELECT * FROM test t WHERE t.id = (SELECT TOP 1 t2.id FROM test t2 ORDER BY t2.data DESC) ORDER BY t.data2 DESC OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY'; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->platform->modifyLimitQuery($querySql, 10); self::assertEquals($expectedSql, $sql); } @@ -368,7 +368,7 @@ public function testModifyLimitQueryWithNewlineBeforeOrderBy() { $querySql = "SELECT * FROM test\nORDER BY col DESC"; $expectedSql = "SELECT * FROM test\nORDER BY col DESC OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY"; - $sql = $this->_platform->modifyLimitQuery($querySql, 10); + $sql = $this->platform->modifyLimitQuery($querySql, 10); self::assertEquals($expectedSql, $sql); } } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php index eeaf5171bf3..ed2842813aa 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php @@ -21,7 +21,7 @@ public function testAppendsLockHint($lockMode, $lockHint) $fromClause = 'FROM users'; $expectedResult = $fromClause . $lockHint; - self::assertSame($expectedResult, $this->_platform->appendLockHint($fromClause, $lockMode)); + self::assertSame($expectedResult, $this->platform->appendLockHint($fromClause, $lockMode)); } /** @@ -30,7 +30,7 @@ public function testAppendsLockHint($lockMode, $lockHint) */ public function testScrubInnerOrderBy($query, $limit, $offset, $expectedResult) { - self::assertSame($expectedResult, $this->_platform->modifyLimitQuery($query, $limit, $offset)); + self::assertSame($expectedResult, $this->platform->modifyLimitQuery($query, $limit, $offset)); } public function getLockHints() diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php index 67abba9fca5..f2e12ae7b22 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php @@ -32,41 +32,41 @@ public function getGenerateTableWithMultiColumnUniqueIndexSql() public function testGeneratesSqlSnippets() { - 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'); + 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() { self::assertEquals( 'PRAGMA read_uncommitted = 0', - $this->_platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_UNCOMMITTED) + $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_UNCOMMITTED) ); self::assertEquals( 'PRAGMA read_uncommitted = 1', - $this->_platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_COMMITTED) + $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_COMMITTED) ); self::assertEquals( 'PRAGMA read_uncommitted = 1', - $this->_platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::REPEATABLE_READ) + $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::REPEATABLE_READ) ); self::assertEquals( 'PRAGMA read_uncommitted = 1', - $this->_platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::SERIALIZABLE) + $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::SERIALIZABLE) ); } public function testPrefersIdentityColumns() { - self::assertTrue($this->_platform->prefersIdentityColumns()); + self::assertTrue($this->platform->prefersIdentityColumns()); } public function testIgnoresUnsignedIntegerDeclarationForAutoIncrementalIntegers() { self::assertSame( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getIntegerTypeDeclarationSQL(['autoincrement' => true, 'unsigned' => true]) + $this->platform->getIntegerTypeDeclarationSQL(['autoincrement' => true, 'unsigned' => true]) ); } @@ -78,25 +78,25 @@ public function testGeneratesTypeDeclarationForTinyIntegers() { self::assertEquals( 'TINYINT', - $this->_platform->getTinyIntTypeDeclarationSQL([]) + $this->platform->getTinyIntTypeDeclarationSQL([]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getTinyIntTypeDeclarationSQL(['autoincrement' => true]) + $this->platform->getTinyIntTypeDeclarationSQL(['autoincrement' => true]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getTinyIntTypeDeclarationSQL( + $this->platform->getTinyIntTypeDeclarationSQL( ['autoincrement' => true, 'primary' => true] ) ); self::assertEquals( 'TINYINT', - $this->_platform->getTinyIntTypeDeclarationSQL(['unsigned' => false]) + $this->platform->getTinyIntTypeDeclarationSQL(['unsigned' => false]) ); self::assertEquals( 'TINYINT UNSIGNED', - $this->_platform->getTinyIntTypeDeclarationSQL(['unsigned' => true]) + $this->platform->getTinyIntTypeDeclarationSQL(['unsigned' => true]) ); } @@ -108,29 +108,29 @@ public function testGeneratesTypeDeclarationForSmallIntegers() { self::assertEquals( 'SMALLINT', - $this->_platform->getSmallIntTypeDeclarationSQL([]) + $this->platform->getSmallIntTypeDeclarationSQL([]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getSmallIntTypeDeclarationSQL(['autoincrement' => true]) + $this->platform->getSmallIntTypeDeclarationSQL(['autoincrement' => true]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getTinyIntTypeDeclarationSQL(['autoincrement' => true, 'unsigned' => true]) + $this->platform->getTinyIntTypeDeclarationSQL(['autoincrement' => true, 'unsigned' => true]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getSmallIntTypeDeclarationSQL( + $this->platform->getSmallIntTypeDeclarationSQL( ['autoincrement' => true, 'primary' => true] ) ); self::assertEquals( 'SMALLINT', - $this->_platform->getSmallIntTypeDeclarationSQL(['unsigned' => false]) + $this->platform->getSmallIntTypeDeclarationSQL(['unsigned' => false]) ); self::assertEquals( 'SMALLINT UNSIGNED', - $this->_platform->getSmallIntTypeDeclarationSQL(['unsigned' => true]) + $this->platform->getSmallIntTypeDeclarationSQL(['unsigned' => true]) ); } @@ -142,29 +142,29 @@ public function testGeneratesTypeDeclarationForMediumIntegers() { self::assertEquals( 'MEDIUMINT', - $this->_platform->getMediumIntTypeDeclarationSQL([]) + $this->platform->getMediumIntTypeDeclarationSQL([]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getMediumIntTypeDeclarationSQL(['autoincrement' => true]) + $this->platform->getMediumIntTypeDeclarationSQL(['autoincrement' => true]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getMediumIntTypeDeclarationSQL(['autoincrement' => true, 'unsigned' => true]) + $this->platform->getMediumIntTypeDeclarationSQL(['autoincrement' => true, 'unsigned' => true]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getMediumIntTypeDeclarationSQL( + $this->platform->getMediumIntTypeDeclarationSQL( ['autoincrement' => true, 'primary' => true] ) ); self::assertEquals( 'MEDIUMINT', - $this->_platform->getMediumIntTypeDeclarationSQL(['unsigned' => false]) + $this->platform->getMediumIntTypeDeclarationSQL(['unsigned' => false]) ); self::assertEquals( 'MEDIUMINT UNSIGNED', - $this->_platform->getMediumIntTypeDeclarationSQL(['unsigned' => true]) + $this->platform->getMediumIntTypeDeclarationSQL(['unsigned' => true]) ); } @@ -172,29 +172,29 @@ public function testGeneratesTypeDeclarationForIntegers() { self::assertEquals( 'INTEGER', - $this->_platform->getIntegerTypeDeclarationSQL([]) + $this->platform->getIntegerTypeDeclarationSQL([]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getIntegerTypeDeclarationSQL(['autoincrement' => true]) + $this->platform->getIntegerTypeDeclarationSQL(['autoincrement' => true]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getIntegerTypeDeclarationSQL(['autoincrement' => true, 'unsigned' => true]) + $this->platform->getIntegerTypeDeclarationSQL(['autoincrement' => true, 'unsigned' => true]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getIntegerTypeDeclarationSQL( + $this->platform->getIntegerTypeDeclarationSQL( ['autoincrement' => true, 'primary' => true] ) ); self::assertEquals( 'INTEGER', - $this->_platform->getIntegerTypeDeclarationSQL(['unsigned' => false]) + $this->platform->getIntegerTypeDeclarationSQL(['unsigned' => false]) ); self::assertEquals( 'INTEGER UNSIGNED', - $this->_platform->getIntegerTypeDeclarationSQL(['unsigned' => true]) + $this->platform->getIntegerTypeDeclarationSQL(['unsigned' => true]) ); } @@ -206,29 +206,29 @@ public function testGeneratesTypeDeclarationForBigIntegers() { self::assertEquals( 'BIGINT', - $this->_platform->getBigIntTypeDeclarationSQL([]) + $this->platform->getBigIntTypeDeclarationSQL([]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getBigIntTypeDeclarationSQL(['autoincrement' => true]) + $this->platform->getBigIntTypeDeclarationSQL(['autoincrement' => true]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getBigIntTypeDeclarationSQL(['autoincrement' => true, 'unsigned' => true]) + $this->platform->getBigIntTypeDeclarationSQL(['autoincrement' => true, 'unsigned' => true]) ); self::assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', - $this->_platform->getBigIntTypeDeclarationSQL( + $this->platform->getBigIntTypeDeclarationSQL( ['autoincrement' => true, 'primary' => true] ) ); self::assertEquals( 'BIGINT', - $this->_platform->getBigIntTypeDeclarationSQL(['unsigned' => false]) + $this->platform->getBigIntTypeDeclarationSQL(['unsigned' => false]) ); self::assertEquals( 'BIGINT UNSIGNED', - $this->_platform->getBigIntTypeDeclarationSQL(['unsigned' => true]) + $this->platform->getBigIntTypeDeclarationSQL(['unsigned' => true]) ); } @@ -236,18 +236,18 @@ public function testGeneratesTypeDeclarationForStrings() { self::assertEquals( 'CHAR(10)', - $this->_platform->getVarcharTypeDeclarationSQL( + $this->platform->getVarcharTypeDeclarationSQL( ['length' => 10, 'fixed' => true] ) ); self::assertEquals( 'VARCHAR(50)', - $this->_platform->getVarcharTypeDeclarationSQL(['length' => 50]), + $this->platform->getVarcharTypeDeclarationSQL(['length' => 50]), 'Variable string declaration is not correct' ); self::assertEquals( 'VARCHAR(255)', - $this->_platform->getVarcharTypeDeclarationSQL([]), + $this->platform->getVarcharTypeDeclarationSQL([]), 'Long string declaration is not correct' ); } @@ -285,19 +285,19 @@ public function getGenerateForeignKeySql() public function testModifyLimitQuery() { - $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0); + $sql = $this->platform->modifyLimitQuery('SELECT * FROM user', 10, 0); self::assertEquals('SELECT * FROM user LIMIT 10', $sql); } public function testModifyLimitQueryWithEmptyOffset() { - $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10); + $sql = $this->platform->modifyLimitQuery('SELECT * FROM user', 10); self::assertEquals('SELECT * FROM user LIMIT 10', $sql); } public function testModifyLimitQueryWithOffsetAndEmptyLimit() { - $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', null, 10); + $sql = $this->platform->modifyLimitQuery('SELECT * FROM user', null, 10); self::assertEquals('SELECT * FROM user LIMIT -1 OFFSET 10', $sql); } @@ -322,7 +322,7 @@ public function testGenerateTableSqlShouldNotAutoQuotePrimaryKey() $table->addColumn('"like"', 'integer', ['notnull' => true, 'autoincrement' => true]); $table->setPrimaryKey(['"like"']); - $createTableSQL = $this->_platform->getCreateTableSQL($table); + $createTableSQL = $this->platform->getCreateTableSQL($table); self::assertEquals( 'CREATE TABLE test ("like" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)', $createTableSQL[0] @@ -340,7 +340,7 @@ public function testAlterTableAddColumns() 'ALTER TABLE user ADD COLUMN count INTEGER DEFAULT 1', ]; - self::assertEquals($expected, $this->_platform->getAlterTableSQL($diff)); + self::assertEquals($expected, $this->platform->getAlterTableSQL($diff)); } /** @@ -350,9 +350,10 @@ public function testAlterTableAddComplexColumns(TableDiff $diff) : void { $this->expectException(DBALException::class); - $this->_platform->getAlterTableSQL($diff); + $this->platform->getAlterTableSQL($diff); } + /** @return mixed[] */ public function complexDiffProvider() : array { $date = new TableDiff('user'); @@ -392,7 +393,7 @@ public function testCreateTableWithDeferredForeignKeys() 'CREATE INDEX IDX_8D93D6493D8E604F ON user (parent)', ]; - self::assertEquals($sql, $this->_platform->getCreateTableSQL($table)); + self::assertEquals($sql, $this->platform->getCreateTableSQL($table)); } public function testAlterTable() @@ -436,7 +437,7 @@ public function testAlterTable() 'CREATE INDEX IDX_8D93D6495A8A6C8D ON client (comment)', ]; - self::assertEquals($sql, $this->_platform->getAlterTableSQL($diff)); + self::assertEquals($sql, $this->platform->getAlterTableSQL($diff)); } protected function getQuotedColumnInPrimaryKeySQL() @@ -483,13 +484,13 @@ protected function getBinaryMaxLength() public function testReturnsBinaryTypeDeclarationSQL() { - self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL([])); - self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 0])); - self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(['length' => 9999999])); + self::assertSame('BLOB', $this->platform->getBinaryTypeDeclarationSQL([])); + self::assertSame('BLOB', $this->platform->getBinaryTypeDeclarationSQL(['length' => 0])); + self::assertSame('BLOB', $this->platform->getBinaryTypeDeclarationSQL(['length' => 9999999])); - self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true])); - self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 0])); - self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 9999999])); + self::assertSame('BLOB', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true])); + self::assertSame('BLOB', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 0])); + self::assertSame('BLOB', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 9999999])); } /** @@ -593,7 +594,7 @@ public function testQuotesAlterTableRenameIndexInSchema() */ public function testReturnsGuidTypeDeclarationSQL() { - self::assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL([])); + self::assertSame('CHAR(36)', $this->platform->getGuidTypeDeclarationSQL([])); } /** @@ -726,7 +727,7 @@ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() */ public function testQuotesTableNameInListTableConstraintsSQL() { - self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true); } /** @@ -734,7 +735,7 @@ public function testQuotesTableNameInListTableConstraintsSQL() */ public function testQuotesTableNameInListTableColumnsSQL() { - self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableColumnsSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->platform->getListTableColumnsSQL("Foo'Bar\\"), '', true); } /** @@ -742,7 +743,7 @@ public function testQuotesTableNameInListTableColumnsSQL() */ public function testQuotesTableNameInListTableIndexesSQL() { - self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableIndexesSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\"), '', true); } /** @@ -750,29 +751,29 @@ public function testQuotesTableNameInListTableIndexesSQL() */ public function testQuotesTableNameInListTableForeignKeysSQL() { - self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true); } public function testDateAddStaticNumberOfDays() { - self::assertSame("DATE(rentalBeginsOn,'+12 DAY')", $this->_platform->getDateAddDaysExpression('rentalBeginsOn', 12)); + self::assertSame("DATE(rentalBeginsOn,'+12 DAY')", $this->platform->getDateAddDaysExpression('rentalBeginsOn', 12)); } public function testDateAddNumberOfDaysFromColumn() { - self::assertSame("DATE(rentalBeginsOn,'+' || duration || ' DAY')", $this->_platform->getDateAddDaysExpression('rentalBeginsOn', 'duration')); + self::assertSame("DATE(rentalBeginsOn,'+' || duration || ' DAY')", $this->platform->getDateAddDaysExpression('rentalBeginsOn', 'duration')); } public function testSupportsColumnCollation() : void { - self::assertTrue($this->_platform->supportsColumnCollation()); + self::assertTrue($this->platform->supportsColumnCollation()); } public function testColumnCollationDeclarationSQL() : void { self::assertSame( 'COLLATE NOCASE', - $this->_platform->getColumnCollationDeclarationSQL('NOCASE') + $this->platform->getColumnCollationDeclarationSQL('NOCASE') ); } @@ -784,7 +785,7 @@ public function testGetCreateTableSQLWithColumnCollation() : void self::assertSame( ['CREATE TABLE foo (no_collation VARCHAR(255) NOT NULL, column_collation VARCHAR(255) NOT NULL COLLATE NOCASE)'], - $this->_platform->getCreateTableSQL($table), + $this->platform->getCreateTableSQL($table), 'Column "no_collation" will use the default collation (BINARY) and "column_collation" overwrites the collation on this column' ); } diff --git a/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php b/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php index 5a783ef6415..88676130a52 100644 --- a/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php @@ -7,6 +7,7 @@ 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 function iterator_to_array; @@ -161,7 +162,7 @@ public function testRowCount() */ protected function createConnection() { - return $this->getMockBuilder('Doctrine\DBAL\Portability\Connection') + return $this->getMockBuilder(Connection::class) ->disableOriginalConstructor() ->getMock(); } @@ -179,6 +180,6 @@ protected function createStatement(\Doctrine\DBAL\Driver\Statement $wrappedState */ protected function createWrappedStatement() { - return $this->createMock('Doctrine\Tests\Mocks\DriverStatementMock'); + return $this->createMock(DriverStatementMock::class); } } diff --git a/tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php b/tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php index 1fe2ac97416..efa173829c3 100644 --- a/tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php +++ b/tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Query\Expression; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\Query\Expression\CompositeExpression; use Doctrine\DBAL\Query\Expression\ExpressionBuilder; use Doctrine\Tests\DbalTestCase; @@ -16,7 +17,7 @@ class ExpressionBuilderTest extends DbalTestCase protected function setUp() { - $conn = $this->createMock('Doctrine\DBAL\Connection'); + $conn = $this->createMock(Connection::class); $this->expr = new ExpressionBuilder($conn); diff --git a/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php b/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php index 1bbb61e8a06..fdd28d87847 100644 --- a/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php +++ b/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Query\Expression\ExpressionBuilder; use Doctrine\DBAL\Query\QueryBuilder; +use Doctrine\DBAL\Query\QueryException; use Doctrine\Tests\DbalTestCase; /** @@ -18,7 +19,7 @@ class QueryBuilderTest extends DbalTestCase protected function setUp() { - $this->conn = $this->createMock('Doctrine\DBAL\Connection'); + $this->conn = $this->createMock(Connection::class); $expressionBuilder = new ExpressionBuilder($this->conn); @@ -650,7 +651,7 @@ public function testReferenceJoinFromJoin() ->innerJoin('nt', 'node', 'n', 'nt.node = n.id') ->where('nt.lang = :lang AND n.deleted != 1'); - $this->expectException('Doctrine\DBAL\Query\QueryException'); + $this->expectException(QueryException::class); $this->expectExceptionMessage("The given alias 'invalid' is not part of any FROM or JOIN clause table. The currently registered aliases are: news, nv."); self::assertEquals('', $qb->getSQL()); } @@ -893,7 +894,7 @@ public function testJoinWithNonUniqueAliasThrowsException() ->from('table_a', 'a') ->join('a', 'table_b', 'a', 'a.fk_b = a.id'); - $this->expectException('Doctrine\DBAL\Query\QueryException'); + $this->expectException(QueryException::class); $this->expectExceptionMessage("The given alias 'a' is not unique in FROM and JOIN clause table. The currently registered aliases are: a."); $qb->getSQL(); diff --git a/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php b/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php index 09b518dcf21..68d3cbcedd3 100644 --- a/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php +++ b/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php @@ -5,6 +5,7 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\SQLParserUtils; +use Doctrine\DBAL\SQLParserUtilsException; use Doctrine\Tests\DbalTestCase; /** @@ -460,7 +461,7 @@ public function dataQueryWithMissingParameters() */ public function testExceptionIsThrownForMissingParam($query, $params, $types = []) { - $this->expectException('Doctrine\DBAL\SQLParserUtilsException'); + $this->expectException(SQLParserUtilsException::class); $this->expectExceptionMessage('Value for :param not found in params array. Params array key should be "param"'); SQLParserUtils::expandListParameters($query, $params, $types); diff --git a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php index b0b27d09d79..43431ea9f9d 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\DBAL\Schema; @@ -203,7 +186,7 @@ public function testCompareNewField() self::assertEquals($expected, Comparator::compareSchemas($schema1, $schema2)); } - public function testCompareChangedColumns_ChangeType() + public function testCompareChangedColumnsChangeType() { $column1 = new Column('charfield1', Type::getType('string')); $column2 = new Column('charfield1', Type::getType('integer')); @@ -213,7 +196,7 @@ public function testCompareChangedColumns_ChangeType() self::assertEquals([], $c->diffColumn($column1, $column1)); } - public function testCompareChangedColumns_ChangeCustomSchemaOption() + public function testCompareChangedColumnsChangeCustomSchemaOption() { $column1 = new Column('charfield1', Type::getType('string')); $column2 = new Column('charfield1', Type::getType('string')); @@ -229,7 +212,7 @@ public function testCompareChangedColumns_ChangeCustomSchemaOption() self::assertEquals([], $c->diffColumn($column1, $column1)); } - public function testCompareChangeColumns_MultipleNewColumnsRename() + public function testCompareChangeColumnsMultipleNewColumnsRename() { $tableA = new Table('foo'); $tableA->addColumn('datefield1', 'datetime'); @@ -523,7 +506,7 @@ public function testTableAddForeignKey() $c = new Comparator(); $tableDiff = $c->diffTable($table1, $table2); - self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); + self::assertInstanceOf(TableDiff::class, $tableDiff); self::assertCount(1, $tableDiff->addedForeignKeys); } @@ -542,7 +525,7 @@ public function testTableRemoveForeignKey() $c = new Comparator(); $tableDiff = $c->diffTable($table2, $table1); - self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); + self::assertInstanceOf(TableDiff::class, $tableDiff); self::assertCount(1, $tableDiff->removedForeignKeys); } @@ -562,7 +545,7 @@ public function testTableUpdateForeignKey() $c = new Comparator(); $tableDiff = $c->diffTable($table1, $table2); - self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); + self::assertInstanceOf(TableDiff::class, $tableDiff); self::assertCount(1, $tableDiff->changedForeignKeys); } @@ -585,7 +568,7 @@ public function testMovedForeignKeyForeignTable() $c = new Comparator(); $tableDiff = $c->diffTable($table1, $table2); - self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); + self::assertInstanceOf(TableDiff::class, $tableDiff); self::assertCount(1, $tableDiff->changedForeignKeys); } @@ -680,7 +663,7 @@ public function testCompareForeignKeyBasedOnPropertiesNotName() self::assertFalse($tableDiff); } - public function testCompareForeignKey_RestrictNoAction_AreTheSame() + public function testCompareForeignKeyRestrictNoActionAreTheSame() { $fk1 = new ForeignKeyConstraint(['foo'], 'bar', ['baz'], 'fk1', ['onDelete' => 'NO ACTION']); $fk2 = new ForeignKeyConstraint(['foo'], 'bar', ['baz'], 'fk1', ['onDelete' => 'RESTRICT']); @@ -692,7 +675,7 @@ public function testCompareForeignKey_RestrictNoAction_AreTheSame() /** * @group DBAL-492 */ - public function testCompareForeignKeyNamesUnqualified_AsNoSchemaInformationIsAvailable() + public function testCompareForeignKeyNamesUnqualifiedAsNoSchemaInformationIsAvailable() { $fk1 = new ForeignKeyConstraint(['foo'], 'foo.bar', ['baz'], 'fk1'); $fk2 = new ForeignKeyConstraint(['foo'], 'baz.bar', ['baz'], 'fk1'); @@ -811,7 +794,7 @@ public function testDetectChangeIdentifierType() $c = new Comparator(); $tableDiff = $c->diffTable($tableA, $tableB); - self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); + self::assertInstanceOf(TableDiff::class, $tableDiff); self::assertArrayHasKey('id', $tableDiff->changedColumns); } @@ -837,7 +820,7 @@ public function testDiff() $c = new Comparator(); $tableDiff = $c->diffTable($table, $newtable); - self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); + self::assertInstanceOf(TableDiff::class, $tableDiff); self::assertEquals(['twitterid', 'displayname'], array_keys($tableDiff->renamedColumns)); self::assertEquals(['logged_in_at'], array_keys($tableDiff->addedColumns)); self::assertCount(0, $tableDiff->removedColumns); @@ -853,7 +836,7 @@ public function testChangedSequence() $sequence = $schema->createSequence('baz'); $schemaNew = clone $schema; - /* @var $schemaNew Schema */ + /** @var Schema $schemaNew */ $schemaNew->getSequence('baz')->setAllocationSize(20); $c = new Comparator(); @@ -987,6 +970,7 @@ public function testAutoIncrementSequences() /** * Check that added autoincrement sequence is not populated in newSequences + * * @group DBAL-562 */ public function testAutoIncrementNoSequences() @@ -1170,10 +1154,10 @@ public function testComplexDiffColumn() public function testComparesNamespaces() { $comparator = new Comparator(); - $fromSchema = $this->getMockBuilder('Doctrine\DBAL\Schema\Schema') + $fromSchema = $this->getMockBuilder(Schema::class) ->setMethods(['getNamespaces', 'hasNamespace']) ->getMock(); - $toSchema = $this->getMockBuilder('Doctrine\DBAL\Schema\Schema') + $toSchema = $this->getMockBuilder(Schema::class) ->setMethods(['getNamespaces', 'hasNamespace']) ->getMock(); @@ -1230,7 +1214,6 @@ public function testCompareGuidColumns() /** * @group DBAL-1009 - * * @dataProvider getCompareColumnComments */ public function testCompareColumnComments($comment1, $comment2, $equals) diff --git a/tests/Doctrine/Tests/DBAL/Schema/ForeignKeyConstraintTest.php b/tests/Doctrine/Tests/DBAL/Schema/ForeignKeyConstraintTest.php index 10bd92d52e6..2c317fc5dea 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ForeignKeyConstraintTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ForeignKeyConstraintTest.php @@ -3,11 +3,14 @@ namespace Doctrine\Tests\DBAL\Schema; use Doctrine\DBAL\Schema\ForeignKeyConstraint; +use Doctrine\DBAL\Schema\Index; use PHPUnit\Framework\TestCase; class ForeignKeyConstraintTest extends TestCase { /** + * @param string[] $indexColumns + * * @group DBAL-1062 * @dataProvider getIntersectsIndexColumnsData */ @@ -15,7 +18,7 @@ public function testIntersectsIndexColumns(array $indexColumns, $expectedResult) { $foreignKey = new ForeignKeyConstraint(['foo', 'bar'], 'foreign_table', ['fk_foo', 'fk_bar']); - $index = $this->getMockBuilder('Doctrine\DBAL\Schema\Index') + $index = $this->getMockBuilder(Index::class) ->disableOriginalConstructor() ->getMock(); $index->expects($this->once()) @@ -26,7 +29,7 @@ public function testIntersectsIndexColumns(array $indexColumns, $expectedResult) } /** - * @return array + * @return mixed[] */ public function getIntersectsIndexColumnsData() { diff --git a/tests/Doctrine/Tests/DBAL/Schema/MySqlInheritCharsetTest.php b/tests/Doctrine/Tests/DBAL/Schema/MySqlInheritCharsetTest.php index 9ae399c7a04..b9c0f1d73ec 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/MySqlInheritCharsetTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/MySqlInheritCharsetTest.php @@ -7,6 +7,7 @@ use Doctrine\Common\EventManager; use Doctrine\DBAL\Configuration; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver; use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\MySqlSchemaManager; @@ -37,7 +38,7 @@ public function testInheritTableOptionsFromDatabase() : void public function testTableOptions() : void { $eventManager = new EventManager(); - $driverMock = $this->createMock('Doctrine\DBAL\Driver'); + $driverMock = $this->createMock(Driver::class); $platform = new MySqlPlatform(); // default, no overrides @@ -72,7 +73,7 @@ public function testTableOptions() : void private function getTableOptionsForOverride(array $overrideOptions = []) : array { $eventManager = new EventManager(); - $driverMock = $this->createMock('Doctrine\DBAL\Driver'); + $driverMock = $this->createMock(Driver::class); $platform = new MySqlPlatform(); $connOptions = array_merge(['platform' => $platform], $overrideOptions); $conn = new Connection($connOptions, $driverMock, new Configuration(), $eventManager); diff --git a/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php index 2a3837140c0..737a8223812 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php @@ -5,7 +5,10 @@ use Doctrine\Common\EventManager; use Doctrine\DBAL\Configuration; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver; +use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Schema\AbstractSchemaManager; +use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\MySqlSchemaManager; use PHPUnit\Framework\TestCase; use function array_map; @@ -21,9 +24,9 @@ class MySqlSchemaManagerTest extends TestCase protected function setUp() { $eventManager = new EventManager(); - $driverMock = $this->createMock('Doctrine\DBAL\Driver'); - $platform = $this->createMock('Doctrine\DBAL\Platforms\MySqlPlatform'); - $this->conn = $this->getMockBuilder('Doctrine\DBAL\Connection') + $driverMock = $this->createMock(Driver::class); + $platform = $this->createMock(MySqlPlatform::class); + $this->conn = $this->getMockBuilder(Connection::class) ->setMethods(['fetchAll']) ->setConstructorArgs([['platform' => $platform], $driverMock, new Configuration(), $eventManager]) ->getMock(); @@ -36,7 +39,7 @@ public function testCompositeForeignKeys() $fkeys = $this->manager->listTableForeignKeys('dummy'); self::assertCount(1, $fkeys, 'Table has to have one foreign key.'); - self::assertInstanceOf('Doctrine\DBAL\Schema\ForeignKeyConstraint', $fkeys[0]); + self::assertInstanceOf(ForeignKeyConstraint::class, $fkeys[0]); self::assertEquals(['column_1', 'column_2', 'column_3'], array_map('strtolower', $fkeys[0]->getLocalColumns())); self::assertEquals(['column_1', 'column_2', 'column_3'], array_map('strtolower', $fkeys[0]->getForeignColumns())); } diff --git a/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php b/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php index b25f81601be..8a6d9575bce 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php @@ -7,6 +7,7 @@ use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; +use Doctrine\Tests\DBAL\Mocks\MockPlatform; use PHPUnit\Framework\TestCase; class SchemaDiffTest extends TestCase @@ -37,7 +38,7 @@ public function testSchemaDiffToSaveSql() public function createPlatform($unsafe = false) { - $platform = $this->createMock('Doctrine\Tests\DBAL\Mocks\MockPlatform'); + $platform = $this->createMock(MockPlatform::class); $platform->expects($this->exactly(1)) ->method('getCreateSchemaSQL') ->with('foo_ns') @@ -45,41 +46,41 @@ public function createPlatform($unsafe = false) if ($unsafe) { $platform->expects($this->exactly(1)) ->method('getDropSequenceSql') - ->with($this->isInstanceOf('Doctrine\DBAL\Schema\Sequence')) + ->with($this->isInstanceOf(Sequence::class)) ->will($this->returnValue('drop_seq')); } $platform->expects($this->exactly(1)) ->method('getAlterSequenceSql') - ->with($this->isInstanceOf('Doctrine\DBAL\Schema\Sequence')) + ->with($this->isInstanceOf(Sequence::class)) ->will($this->returnValue('alter_seq')); $platform->expects($this->exactly(1)) ->method('getCreateSequenceSql') - ->with($this->isInstanceOf('Doctrine\DBAL\Schema\Sequence')) + ->with($this->isInstanceOf(Sequence::class)) ->will($this->returnValue('create_seq')); if ($unsafe) { $platform->expects($this->exactly(1)) ->method('getDropTableSql') - ->with($this->isInstanceOf('Doctrine\DBAL\Schema\Table')) + ->with($this->isInstanceOf(Table::class)) ->will($this->returnValue('drop_table')); } $platform->expects($this->exactly(1)) ->method('getCreateTableSql') - ->with($this->isInstanceOf('Doctrine\DBAL\Schema\Table')) + ->with($this->isInstanceOf(Table::class)) ->will($this->returnValue(['create_table'])); $platform->expects($this->exactly(1)) ->method('getCreateForeignKeySQL') - ->with($this->isInstanceOf('Doctrine\DBAL\Schema\ForeignKeyConstraint')) + ->with($this->isInstanceOf(ForeignKeyConstraint::class)) ->will($this->returnValue('create_foreign_key')); $platform->expects($this->exactly(1)) ->method('getAlterTableSql') - ->with($this->isInstanceOf('Doctrine\DBAL\Schema\TableDiff')) + ->with($this->isInstanceOf(TableDiff::class)) ->will($this->returnValue(['alter_table'])); if ($unsafe) { $platform->expects($this->exactly(1)) ->method('getDropForeignKeySql') ->with( - $this->isInstanceOf('Doctrine\DBAL\Schema\ForeignKeyConstraint'), - $this->isInstanceOf('Doctrine\DBAL\Schema\Table') + $this->isInstanceOf(ForeignKeyConstraint::class), + $this->isInstanceOf(Table::class) ) ->will($this->returnValue('drop_orphan_fk')); } diff --git a/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php b/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php index c9bad262d74..f7254c97cb7 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php @@ -4,8 +4,11 @@ use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\SchemaConfig; +use Doctrine\DBAL\Schema\SchemaException; use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Table; +use Doctrine\DBAL\Schema\Visitor\AbstractVisitor; +use Doctrine\DBAL\Schema\Visitor\Visitor; use PHPUnit\Framework\TestCase; use function current; use function strlen; @@ -43,7 +46,7 @@ public function testTableMatchingCaseInsensitive() public function testGetUnknownTableThrowsException() { - $this->expectException('Doctrine\DBAL\Schema\SchemaException'); + $this->expectException(SchemaException::class); $schema = new Schema(); $schema->getTable('unknown'); @@ -51,7 +54,7 @@ public function testGetUnknownTableThrowsException() public function testCreateTableTwiceThrowsException() { - $this->expectException('Doctrine\DBAL\Schema\SchemaException'); + $this->expectException(SchemaException::class); $tableName = 'foo'; $table = new Table($tableName); @@ -94,7 +97,7 @@ public function testCreateTable() $table = $schema->createTable('foo'); - self::assertInstanceOf('Doctrine\DBAL\Schema\Table', $table); + self::assertInstanceOf(Table::class, $table); self::assertEquals('foo', $table->getName()); self::assertTrue($schema->hasTable('foo')); } @@ -106,7 +109,7 @@ public function testAddSequences() $schema = new Schema([], [$sequence]); self::assertTrue($schema->hasSequence('a_seq')); - self::assertInstanceOf('Doctrine\DBAL\Schema\Sequence', $schema->getSequence('a_seq')); + self::assertInstanceOf(Sequence::class, $schema->getSequence('a_seq')); $sequences = $schema->getSequences(); self::assertArrayHasKey('public.a_seq', $sequences); @@ -128,7 +131,7 @@ public function testSequenceAccessCaseInsensitive() public function testGetUnknownSequenceThrowsException() { - $this->expectException('Doctrine\DBAL\Schema\SchemaException'); + $this->expectException(SchemaException::class); $schema = new Schema(); $schema->getSequence('unknown'); @@ -144,7 +147,7 @@ public function testCreateSequence() self::assertEquals(20, $sequence->getInitialValue()); self::assertTrue($schema->hasSequence('a_seq')); - self::assertInstanceOf('Doctrine\DBAL\Schema\Sequence', $schema->getSequence('a_seq')); + self::assertInstanceOf(Sequence::class, $schema->getSequence('a_seq')); $sequences = $schema->getSequences(); self::assertArrayHasKey('public.a_seq', $sequences); @@ -162,7 +165,7 @@ public function testDropSequence() public function testAddSequenceTwiceThrowsException() { - $this->expectException('Doctrine\DBAL\Schema\SchemaException'); + $this->expectException(SchemaException::class); $sequence = new Sequence('a_seq', 1, 1); @@ -352,7 +355,7 @@ public function testCreatesNamespaceThroughAddingSequenceImplicitly() public function testVisitsVisitor() { $schema = new Schema(); - $visitor = $this->createMock('Doctrine\DBAL\Schema\Visitor\Visitor'); + $visitor = $this->createMock(Visitor::class); $schema->createNamespace('foo'); $schema->createNamespace('bar'); @@ -398,7 +401,7 @@ public function testVisitsVisitor() public function testVisitsNamespaceVisitor() { $schema = new Schema(); - $visitor = $this->createMock('Doctrine\DBAL\Schema\Visitor\AbstractVisitor'); + $visitor = $this->createMock(AbstractVisitor::class); $schema->createNamespace('foo'); $schema->createNamespace('bar'); diff --git a/tests/Doctrine/Tests/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php b/tests/Doctrine/Tests/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php index 442c283ef59..cedc3583137 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php @@ -1,24 +1,8 @@ . - */ namespace Doctrine\Tests\DBAL\Schema\Synchronizer; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Synchronizer\SingleDatabaseSynchronizer; @@ -29,7 +13,10 @@ */ class SingleDatabaseSynchronizerTest extends TestCase { + /** @var Connection */ private $conn; + + /** @var SingleDatabaseSynchronizer */ private $synchronizer; protected function setUp() diff --git a/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php b/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php index 097c9e2f1e1..80b9ef7b2c2 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\DBAL\Schema; use Doctrine\DBAL\Schema\Identifier; +use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; use Doctrine\Tests\DBAL\Mocks\MockPlatform; use PHPUnit\Framework\TestCase; @@ -25,7 +26,7 @@ public function testReturnsName() public function testPrefersNameFromTableObject() { $platformMock = new MockPlatform(); - $tableMock = $this->getMockBuilder('Doctrine\DBAL\Schema\Table') + $tableMock = $this->getMockBuilder(Table::class) ->disableOriginalConstructor() ->getMock(); diff --git a/tests/Doctrine/Tests/DBAL/Schema/TableTest.php b/tests/Doctrine/Tests/DBAL/Schema/TableTest.php index 09cc4662f48..ac5fead5bcf 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/TableTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/TableTest.php @@ -8,6 +8,7 @@ use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\Index; +use Doctrine\DBAL\Schema\SchemaException; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DbalTestCase; @@ -41,8 +42,8 @@ public function testColumns() self::assertTrue($table->hasColumn('bar')); self::assertFalse($table->hasColumn('baz')); - self::assertInstanceOf('Doctrine\DBAL\Schema\Column', $table->getColumn('foo')); - self::assertInstanceOf('Doctrine\DBAL\Schema\Column', $table->getColumn('bar')); + self::assertInstanceOf(Column::class, $table->getColumn('foo')); + self::assertInstanceOf(Column::class, $table->getColumn('bar')); self::assertCount(2, $table->getColumns()); } @@ -92,7 +93,7 @@ public function testDropColumn() public function testGetUnknownColumnThrowsException() { - $this->expectException('Doctrine\DBAL\Schema\SchemaException'); + $this->expectException(SchemaException::class); $table = new Table('foo', [], [], []); $table->getColumn('unknown'); @@ -100,7 +101,7 @@ public function testGetUnknownColumnThrowsException() public function testAddColumnTwiceThrowsException() { - $this->expectException('Doctrine\DBAL\Schema\SchemaException'); + $this->expectException(SchemaException::class); $type = Type::getType('integer'); $columns = []; @@ -156,14 +157,14 @@ public function testAddIndexes() self::assertTrue($table->hasIndex('bar_idx')); self::assertFalse($table->hasIndex('some_idx')); - self::assertInstanceOf('Doctrine\DBAL\Schema\Index', $table->getPrimaryKey()); - self::assertInstanceOf('Doctrine\DBAL\Schema\Index', $table->getIndex('the_primary')); - self::assertInstanceOf('Doctrine\DBAL\Schema\Index', $table->getIndex('bar_idx')); + self::assertInstanceOf(Index::class, $table->getPrimaryKey()); + self::assertInstanceOf(Index::class, $table->getIndex('the_primary')); + self::assertInstanceOf(Index::class, $table->getIndex('bar_idx')); } public function testGetUnknownIndexThrowsException() { - $this->expectException('Doctrine\DBAL\Schema\SchemaException'); + $this->expectException(SchemaException::class); $table = new Table('foo', [], [], []); $table->getIndex('unknownIndex'); @@ -171,7 +172,7 @@ public function testGetUnknownIndexThrowsException() public function testAddTwoPrimaryThrowsException() { - $this->expectException('Doctrine\DBAL\Schema\SchemaException'); + $this->expectException(SchemaException::class); $type = Type::getType('integer'); $columns = [new Column('foo', $type), new Column('bar', $type)]; @@ -184,7 +185,7 @@ public function testAddTwoPrimaryThrowsException() public function testAddTwoIndexesWithSameNameThrowsException() { - $this->expectException('Doctrine\DBAL\Schema\SchemaException'); + $this->expectException(SchemaException::class); $type = Type::getType('integer'); $columns = [new Column('foo', $type), new Column('bar', $type)]; @@ -222,7 +223,7 @@ public function testBuilderSetPrimaryKey() $table->setPrimaryKey(['bar']); self::assertTrue($table->hasIndex('primary')); - self::assertInstanceOf('Doctrine\DBAL\Schema\Index', $table->getPrimaryKey()); + self::assertInstanceOf(Index::class, $table->getPrimaryKey()); self::assertTrue($table->getIndex('primary')->isUnique()); self::assertTrue($table->getIndex('primary')->isPrimary()); } @@ -253,7 +254,7 @@ public function testBuilderAddIndex() public function testBuilderAddIndexWithInvalidNameThrowsException() { - $this->expectException('Doctrine\DBAL\Schema\SchemaException'); + $this->expectException(SchemaException::class); $table = new Table('foo'); $table->addColumn('bar', 'integer'); @@ -262,7 +263,7 @@ public function testBuilderAddIndexWithInvalidNameThrowsException() public function testBuilderAddIndexWithUnknownColumnThrowsException() { - $this->expectException('Doctrine\DBAL\Schema\SchemaException'); + $this->expectException(SchemaException::class); $table = new Table('foo'); $table->addIndex(['bar'], 'invalidName'); @@ -276,9 +277,9 @@ public function testBuilderOptions() self::assertEquals('bar', $table->getOption('foo')); } - public function testAddForeignKeyConstraint_UnknownLocalColumn_ThrowsException() + public function testAddForeignKeyConstraintUnknownLocalColumnThrowsException() { - $this->expectException('Doctrine\DBAL\Schema\SchemaException'); + $this->expectException(SchemaException::class); $table = new Table('foo'); $table->addColumn('id', 'integer'); @@ -289,9 +290,9 @@ public function testAddForeignKeyConstraint_UnknownLocalColumn_ThrowsException() $table->addForeignKeyConstraint($foreignTable, ['foo'], ['id']); } - public function testAddForeignKeyConstraint_UnknownForeignColumn_ThrowsException() + public function testAddForeignKeyConstraintUnknownForeignColumnThrowsException() { - $this->expectException('Doctrine\DBAL\Schema\SchemaException'); + $this->expectException(SchemaException::class); $table = new Table('foo'); $table->addColumn('id', 'integer'); @@ -316,7 +317,7 @@ public function testAddForeignKeyConstraint() self::assertCount(1, $constraints); $constraint = current($constraints); - self::assertInstanceOf('Doctrine\DBAL\Schema\ForeignKeyConstraint', $constraint); + self::assertInstanceOf(ForeignKeyConstraint::class, $constraint); self::assertTrue($constraint->hasOption('foo')); self::assertEquals('bar', $constraint->getOption('foo')); @@ -334,7 +335,7 @@ public function testAddIndexWithCaseSensitiveColumnProblem() self::assertTrue($table->getIndex('my_idx')->spansColumns(['id'])); } - public function testAddPrimaryKey_ColumnsAreExplicitlySetToNotNull() + public function testAddPrimaryKeyColumnsAreExplicitlySetToNotNull() { $table = new Table('foo'); $column = $table->addColumn('id', 'integer', ['notnull' => false]); @@ -822,18 +823,18 @@ public function testNormalizesColumnNames($assetName) self::assertTrue($table->hasColumn($assetName)); self::assertTrue($table->hasColumn('foo')); - self::assertInstanceOf('Doctrine\DBAL\Schema\Column', $table->getColumn($assetName)); - self::assertInstanceOf('Doctrine\DBAL\Schema\Column', $table->getColumn('foo')); + self::assertInstanceOf(Column::class, $table->getColumn($assetName)); + self::assertInstanceOf(Column::class, $table->getColumn('foo')); self::assertTrue($table->hasIndex($assetName)); self::assertTrue($table->hasIndex('foo')); - self::assertInstanceOf('Doctrine\DBAL\Schema\Index', $table->getIndex($assetName)); - self::assertInstanceOf('Doctrine\DBAL\Schema\Index', $table->getIndex('foo')); + self::assertInstanceOf(Index::class, $table->getIndex($assetName)); + self::assertInstanceOf(Index::class, $table->getIndex('foo')); self::assertTrue($table->hasForeignKey($assetName)); self::assertTrue($table->hasForeignKey('foo')); - self::assertInstanceOf('Doctrine\DBAL\Schema\ForeignKeyConstraint', $table->getForeignKey($assetName)); - self::assertInstanceOf('Doctrine\DBAL\Schema\ForeignKeyConstraint', $table->getForeignKey('foo')); + self::assertInstanceOf(ForeignKeyConstraint::class, $table->getForeignKey($assetName)); + self::assertInstanceOf(ForeignKeyConstraint::class, $table->getForeignKey('foo')); $table->renameIndex($assetName, $assetName); self::assertTrue($table->hasIndex($assetName)); diff --git a/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php b/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php index f94e1c1d019..e64b4c523f3 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php @@ -25,7 +25,7 @@ protected function setUp() { parent::setUp(); - $this->platformMock = $this->getMockBuilder('Doctrine\DBAL\Platforms\AbstractPlatform') + $this->platformMock = $this->getMockBuilder(AbstractPlatform::class) ->setMethods( [ 'getCreateForeignKeySQL', @@ -134,7 +134,7 @@ public function testResetsQueries() */ private function createForeignKeyConstraintMock() { - return $this->getMockBuilder('Doctrine\DBAL\Schema\ForeignKeyConstraint') + return $this->getMockBuilder(ForeignKeyConstraint::class) ->disableOriginalConstructor() ->getMock(); } @@ -144,7 +144,7 @@ private function createForeignKeyConstraintMock() */ private function createSequenceMock() { - return $this->getMockBuilder('Doctrine\DBAL\Schema\Sequence') + return $this->getMockBuilder(Sequence::class) ->disableOriginalConstructor() ->getMock(); } @@ -154,7 +154,7 @@ private function createSequenceMock() */ private function createTableMock() { - return $this->getMockBuilder('Doctrine\DBAL\Schema\Table') + return $this->getMockBuilder(Table::class) ->disableOriginalConstructor() ->getMock(); } diff --git a/tests/Doctrine/Tests/DBAL/Schema/Visitor/DropSchemaSqlCollectorTest.php b/tests/Doctrine/Tests/DBAL/Schema/Visitor/DropSchemaSqlCollectorTest.php index c65996cab7b..b2aff283871 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Visitor/DropSchemaSqlCollectorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Visitor/DropSchemaSqlCollectorTest.php @@ -2,6 +2,10 @@ namespace Doctrine\Tests\DBAL\Schema\Visitor; +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Schema\ForeignKeyConstraint; +use Doctrine\DBAL\Schema\SchemaException; +use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector; use PHPUnit\Framework\TestCase; @@ -18,7 +22,7 @@ public function testGetQueriesUsesAcceptedForeignKeys() $keyConstraintOne = $this->getStubKeyConstraint('first'); $keyConstraintTwo = $this->getStubKeyConstraint('second'); - $platform = $this->getMockBuilder('Doctrine\DBAL\Platforms\AbstractPlatform') + $platform = $this->getMockBuilder(AbstractPlatform::class) ->setMethods(['getDropForeignKeySQL']) ->getMockForAbstractClass(); @@ -43,7 +47,7 @@ public function testGetQueriesUsesAcceptedForeignKeys() private function getTableMock() { - return $this->getMockWithoutArguments('Doctrine\DBAL\Schema\Table'); + return $this->getMockWithoutArguments(Table::class); } private function getMockWithoutArguments($className) @@ -53,7 +57,7 @@ private function getMockWithoutArguments($className) private function getStubKeyConstraint($name) { - $constraint = $this->getMockWithoutArguments('Doctrine\DBAL\Schema\ForeignKeyConstraint'); + $constraint = $this->getMockWithoutArguments(ForeignKeyConstraint::class); $constraint->expects($this->any()) ->method('getName') @@ -70,13 +74,13 @@ private function getStubKeyConstraint($name) return $constraint; } - public function testGivenForeignKeyWithZeroLength_acceptForeignKeyThrowsException() + public function testGivenForeignKeyWithZeroLengthAcceptForeignKeyThrowsException() { $collector = new DropSchemaSqlCollector( - $this->getMockForAbstractClass('Doctrine\DBAL\Platforms\AbstractPlatform') + $this->getMockForAbstractClass(AbstractPlatform::class) ); - $this->expectException('Doctrine\DBAL\Schema\SchemaException'); + $this->expectException(SchemaException::class); $collector->acceptForeignKey($this->getTableMock(), $this->getStubKeyConstraint('')); } } diff --git a/tests/Doctrine/Tests/DBAL/Schema/Visitor/SchemaSqlCollectorTest.php b/tests/Doctrine/Tests/DBAL/Schema/Visitor/SchemaSqlCollectorTest.php index d326a817c0d..4ebfd1cac54 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Visitor/SchemaSqlCollectorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Visitor/SchemaSqlCollectorTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Schema\Visitor; +use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Schema\Schema; use PHPUnit\Framework\TestCase; @@ -9,7 +10,7 @@ class SchemaSqlCollectorTest extends TestCase { public function testCreateSchema() { - $platformMock = $this->getMockBuilder('Doctrine\DBAL\Platforms\MySqlPlatform') + $platformMock = $this->getMockBuilder(MySqlPlatform::class) ->setMethods(['getCreateTableSql', 'getCreateSequenceSql', 'getCreateForeignKeySql']) ->getMock(); $platformMock->expects($this->exactly(2)) @@ -31,7 +32,7 @@ public function testCreateSchema() public function testDropSchema() { - $platformMock = $this->getMockBuilder('Doctrine\DBAL\Platforms\MySqlPlatform') + $platformMock = $this->getMockBuilder(MySqlPlatform::class) ->setMethods(['getDropTableSql', 'getDropSequenceSql', 'getDropForeignKeySql']) ->getMock(); $platformMock->expects($this->exactly(2)) diff --git a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php index 0eafb7eae01..4985605c60d 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php @@ -1,27 +1,13 @@ . - */ namespace Doctrine\Tests\DBAL\Sharding; use Doctrine\DBAL\DriverManager; +use Doctrine\DBAL\Sharding\PoolingShardConnection; use Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser; +use Doctrine\DBAL\Sharding\ShardingException; use PHPUnit\Framework\TestCase; +use stdClass; /** * @requires extension pdo_sqlite @@ -31,14 +17,14 @@ class PoolingShardConnectionTest extends TestCase public function testConnect() { $conn = DriverManager::getConnection([ - 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'wrapperClass' => PoolingShardConnection::class, 'driver' => 'pdo_sqlite', 'global' => ['memory' => true], 'shards' => [ ['id' => 1, 'memory' => true], ['id' => 2, 'memory' => true], ], - 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', + 'shardChoser' => MultiTenantShardChoser::class, ]); self::assertFalse($conn->isConnected(0)); @@ -68,13 +54,13 @@ public function testNoGlobalServerException() $this->expectExceptionMessage("Connection Parameters require 'global' and 'shards' configurations."); DriverManager::getConnection([ - 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'wrapperClass' => PoolingShardConnection::class, 'driver' => 'pdo_sqlite', 'shards' => [ ['id' => 1, 'memory' => true], ['id' => 2, 'memory' => true], ], - 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', + 'shardChoser' => MultiTenantShardChoser::class, ]); } @@ -84,10 +70,10 @@ public function testNoShardsServersException() $this->expectExceptionMessage("Connection Parameters require 'global' and 'shards' configurations."); DriverManager::getConnection([ - 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'wrapperClass' => PoolingShardConnection::class, 'driver' => 'pdo_sqlite', 'global' => ['memory' => true], - 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', + 'shardChoser' => MultiTenantShardChoser::class, ]); } @@ -97,7 +83,7 @@ public function testNoShardsChoserException() $this->expectExceptionMessage("Missing Shard Choser configuration 'shardChoser'"); DriverManager::getConnection([ - 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'wrapperClass' => PoolingShardConnection::class, 'driver' => 'pdo_sqlite', 'global' => ['memory' => true], 'shards' => [ @@ -113,14 +99,14 @@ public function testShardChoserWrongInstance() $this->expectExceptionMessage("The 'shardChoser' configuration is not a valid instance of Doctrine\DBAL\Sharding\ShardChoser\ShardChoser"); DriverManager::getConnection([ - 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'wrapperClass' => PoolingShardConnection::class, 'driver' => 'pdo_sqlite', 'global' => ['memory' => true], 'shards' => [ ['id' => 1, 'memory' => true], ['id' => 2, 'memory' => true], ], - 'shardChoser' => new \stdClass(), + 'shardChoser' => new stdClass(), ]); } @@ -130,13 +116,13 @@ public function testShardNonNumericId() $this->expectExceptionMessage('Shard Id has to be a non-negative number.'); DriverManager::getConnection([ - 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'wrapperClass' => PoolingShardConnection::class, 'driver' => 'pdo_sqlite', 'global' => ['memory' => true], 'shards' => [ ['id' => 'foo', 'memory' => true], ], - 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', + 'shardChoser' => MultiTenantShardChoser::class, ]); } @@ -146,13 +132,13 @@ public function testShardMissingId() $this->expectExceptionMessage("Missing 'id' for one configured shard. Please specify a unique shard-id."); DriverManager::getConnection([ - 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'wrapperClass' => PoolingShardConnection::class, 'driver' => 'pdo_sqlite', 'global' => ['memory' => true], 'shards' => [ ['memory' => true], ], - 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', + 'shardChoser' => MultiTenantShardChoser::class, ]); } @@ -162,32 +148,32 @@ public function testDuplicateShardId() $this->expectExceptionMessage('Shard 1 is duplicated in the configuration.'); DriverManager::getConnection([ - 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'wrapperClass' => PoolingShardConnection::class, 'driver' => 'pdo_sqlite', 'global' => ['memory' => true], 'shards' => [ ['id' => 1, 'memory' => true], ['id' => 1, 'memory' => true], ], - 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', + 'shardChoser' => MultiTenantShardChoser::class, ]); } public function testSwitchShardWithOpenTransactionException() { $conn = DriverManager::getConnection([ - 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'wrapperClass' => PoolingShardConnection::class, 'driver' => 'pdo_sqlite', 'global' => ['memory' => true], 'shards' => [ ['id' => 1, 'memory' => true], ], - 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', + 'shardChoser' => MultiTenantShardChoser::class, ]); $conn->beginTransaction(); - $this->expectException('Doctrine\DBAL\Sharding\ShardingException'); + $this->expectException(ShardingException::class); $this->expectExceptionMessage('Cannot switch shard when transaction is active.'); $conn->connect(1); } @@ -195,13 +181,13 @@ public function testSwitchShardWithOpenTransactionException() public function testGetActiveShardId() { $conn = DriverManager::getConnection([ - 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'wrapperClass' => PoolingShardConnection::class, 'driver' => 'pdo_sqlite', 'global' => ['memory' => true], 'shards' => [ ['id' => 1, 'memory' => true], ], - 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', + 'shardChoser' => MultiTenantShardChoser::class, ]); self::assertNull($conn->getActiveShardId()); @@ -219,17 +205,17 @@ public function testGetActiveShardId() public function testGetParamsOverride() { $conn = DriverManager::getConnection([ - 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'wrapperClass' => PoolingShardConnection::class, 'driver' => 'pdo_sqlite', 'global' => ['memory' => true, 'host' => 'localhost'], 'shards' => [ ['id' => 1, 'memory' => true, 'host' => 'foo'], ], - 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', + 'shardChoser' => MultiTenantShardChoser::class, ]); self::assertEquals([ - 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'wrapperClass' => PoolingShardConnection::class, 'driver' => 'pdo_sqlite', 'global' => ['memory' => true, 'host' => 'localhost'], 'shards' => [ @@ -242,7 +228,7 @@ public function testGetParamsOverride() $conn->connect(1); self::assertEquals([ - 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'wrapperClass' => PoolingShardConnection::class, 'driver' => 'pdo_sqlite', 'global' => ['memory' => true, 'host' => 'localhost'], 'shards' => [ @@ -258,14 +244,14 @@ public function testGetParamsOverride() public function testGetHostOverride() { $conn = DriverManager::getConnection([ - 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'wrapperClass' => PoolingShardConnection::class, 'driver' => 'pdo_sqlite', 'host' => 'localhost', 'global' => ['memory' => true], 'shards' => [ ['id' => 1, 'memory' => true, 'host' => 'foo'], ], - 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', + 'shardChoser' => MultiTenantShardChoser::class, ]); self::assertEquals('localhost', $conn->getHost()); @@ -277,14 +263,14 @@ public function testGetHostOverride() public function testGetPortOverride() { $conn = DriverManager::getConnection([ - 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'wrapperClass' => PoolingShardConnection::class, 'driver' => 'pdo_sqlite', 'port' => 3306, 'global' => ['memory' => true], 'shards' => [ ['id' => 1, 'memory' => true, 'port' => 3307], ], - 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', + 'shardChoser' => MultiTenantShardChoser::class, ]); self::assertEquals(3306, $conn->getPort()); @@ -296,14 +282,14 @@ public function testGetPortOverride() public function testGetUsernameOverride() { $conn = DriverManager::getConnection([ - 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'wrapperClass' => PoolingShardConnection::class, 'driver' => 'pdo_sqlite', 'user' => 'foo', 'global' => ['memory' => true], 'shards' => [ ['id' => 1, 'memory' => true, 'user' => 'bar'], ], - 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', + 'shardChoser' => MultiTenantShardChoser::class, ]); self::assertEquals('foo', $conn->getUsername()); @@ -315,14 +301,14 @@ public function testGetUsernameOverride() public function testGetPasswordOverride() { $conn = DriverManager::getConnection([ - 'wrapperClass' => 'Doctrine\DBAL\Sharding\PoolingShardConnection', + 'wrapperClass' => PoolingShardConnection::class, 'driver' => 'pdo_sqlite', 'password' => 'foo', 'global' => ['memory' => true], 'shards' => [ ['id' => 1, 'memory' => true, 'password' => 'bar'], ], - 'shardChoser' => 'Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser', + 'shardChoser' => MultiTenantShardChoser::class, ]); self::assertEquals('foo', $conn->getPassword()); diff --git a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php index cc5809effab..fc1b1ddb0c7 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php @@ -18,14 +18,16 @@ */ namespace Doctrine\Tests\DBAL\Sharding; +use Doctrine\DBAL\Sharding\PoolingShardConnection; use Doctrine\DBAL\Sharding\PoolingShardManager; +use Doctrine\DBAL\Sharding\ShardChoser\ShardChoser; use PHPUnit\Framework\TestCase; class PoolingShardManagerTest extends TestCase { private function createConnectionMock() { - return $this->getMockBuilder('Doctrine\DBAL\Sharding\PoolingShardConnection') + return $this->getMockBuilder(PoolingShardConnection::class) ->setMethods(['connect', 'getParams', 'fetchAll']) ->disableOriginalConstructor() ->getMock(); @@ -33,7 +35,7 @@ private function createConnectionMock() private function createPassthroughShardChoser() { - $mock = $this->createMock('Doctrine\DBAL\Sharding\ShardChoser\ShardChoser'); + $mock = $this->createMock(ShardChoser::class); $mock->expects($this->any()) ->method('pickShard') ->will($this->returnCallback(static function ($value) { @@ -42,14 +44,12 @@ private function createPassthroughShardChoser() return $mock; } - private function createStaticShardChoser() + private function createStaticShardChooser() { - $mock = $this->createMock('Doctrine\DBAL\Sharding\ShardChoser\ShardChoser'); + $mock = $this->createMock(ShardChoser::class); $mock->expects($this->any()) ->method('pickShard') - ->will($this->returnCallback(static function ($value) { - return 1; - })); + ->willReturn(1); return $mock; } @@ -130,10 +130,10 @@ public function testQueryAllWithStaticShardChoser() $conn = $this->createConnectionMock(); $conn->expects($this->at(0))->method('getParams')->will($this->returnValue( - ['shards' => [ ['id' => 1], ['id' => 2] ], 'shardChoser' => $this->createStaticShardChoser()] + ['shards' => [ ['id' => 1], ['id' => 2] ], 'shardChoser' => $this->createStaticShardChooser()] )); $conn->expects($this->at(1))->method('getParams')->will($this->returnValue( - ['shards' => [ ['id' => 1], ['id' => 2] ], 'shardChoser' => $this->createStaticShardChoser()] + ['shards' => [ ['id' => 1], ['id' => 2] ], 'shardChoser' => $this->createStaticShardChooser()] )); $conn->expects($this->at(2))->method('connect')->with($this->equalTo(1)); $conn->expects($this->at(3)) diff --git a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/MultiTenantVisitorTest.php b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/MultiTenantVisitorTest.php index d49831e907d..94634dadb69 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/MultiTenantVisitorTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/MultiTenantVisitorTest.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\Tests\DBAL\Sharding\SQLAzure; diff --git a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php index 04dc31723ef..edc88d376c9 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php @@ -2,6 +2,8 @@ namespace Doctrine\Tests\DBAL\Sharding\SQLAzure; +use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Sharding\ShardingException; use Doctrine\DBAL\Sharding\SQLAzure\SQLAzureShardManager; use PHPUnit\Framework\TestCase; @@ -9,28 +11,28 @@ class SQLAzureShardManagerTest extends TestCase { public function testNoFederationName() { - $this->expectException('Doctrine\DBAL\Sharding\ShardingException'); + $this->expectException(ShardingException::class); $this->expectExceptionMessage('SQLAzure requires a federation name to be set during sharding configuration.'); $conn = $this->createConnection(['sharding' => ['distributionKey' => 'abc', 'distributionType' => 'integer']]); - $sm = new SQLAzureShardManager($conn); + new SQLAzureShardManager($conn); } public function testNoDistributionKey() { - $this->expectException('Doctrine\DBAL\Sharding\ShardingException'); + $this->expectException(ShardingException::class); $this->expectExceptionMessage('SQLAzure requires a distribution key to be set during sharding configuration.'); $conn = $this->createConnection(['sharding' => ['federationName' => 'abc', 'distributionType' => 'integer']]); - $sm = new SQLAzureShardManager($conn); + new SQLAzureShardManager($conn); } public function testNoDistributionType() { - $this->expectException('Doctrine\DBAL\Sharding\ShardingException'); + $this->expectException(ShardingException::class); $conn = $this->createConnection(['sharding' => ['federationName' => 'abc', 'distributionKey' => 'foo']]); - $sm = new SQLAzureShardManager($conn); + new SQLAzureShardManager($conn); } public function testGetDefaultDistributionValue() @@ -46,7 +48,7 @@ public function testSelectGlobalTransactionActive() $conn = $this->createConnection(['sharding' => ['federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer']]); $conn->expects($this->at(1))->method('isTransactionActive')->will($this->returnValue(true)); - $this->expectException('Doctrine\DBAL\Sharding\ShardingException'); + $this->expectException(ShardingException::class); $this->expectExceptionMessage('Cannot switch shard during an active transaction.'); $sm = new SQLAzureShardManager($conn); @@ -68,7 +70,7 @@ public function testSelectShard() $conn = $this->createConnection(['sharding' => ['federationName' => 'abc', 'distributionKey' => 'foo', 'distributionType' => 'integer']]); $conn->expects($this->at(1))->method('isTransactionActive')->will($this->returnValue(true)); - $this->expectException('Doctrine\DBAL\Sharding\ShardingException'); + $this->expectException(ShardingException::class); $this->expectExceptionMessage('Cannot switch shard during an active transaction.'); $sm = new SQLAzureShardManager($conn); @@ -82,16 +84,19 @@ 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('Doctrine\DBAL\Sharding\ShardingException'); + $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 + */ private function createConnection(array $params) { - $conn = $this->getMockBuilder('Doctrine\DBAL\Connection') + $conn = $this->getMockBuilder(Connection::class) ->setMethods(['getParams', 'exec', 'isTransactionActive']) ->disableOriginalConstructor() ->getMock(); diff --git a/tests/Doctrine/Tests/DBAL/Sharding/ShardChoser/MultiTenantShardChoserTest.php b/tests/Doctrine/Tests/DBAL/Sharding/ShardChoser/MultiTenantShardChoserTest.php index d3eaf32ccfa..0c78b5c1771 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/ShardChoser/MultiTenantShardChoserTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/ShardChoser/MultiTenantShardChoserTest.php @@ -1,24 +1,8 @@ . - */ namespace Doctrine\Tests\DBAL\Sharding\ShardChoser; +use Doctrine\DBAL\Sharding\PoolingShardConnection; use Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser; use PHPUnit\Framework\TestCase; @@ -35,7 +19,7 @@ public function testPickShard() private function createConnectionMock() { - return $this->getMockBuilder('Doctrine\DBAL\Sharding\PoolingShardConnection') + return $this->getMockBuilder(PoolingShardConnection::class) ->setMethods(['connect', 'getParams', 'fetchAll']) ->disableOriginalConstructor() ->getMock(); diff --git a/tests/Doctrine/Tests/DBAL/StatementTest.php b/tests/Doctrine/Tests/DBAL/StatementTest.php index 88559c07ceb..7f18b20936a 100644 --- a/tests/Doctrine/Tests/DBAL/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/StatementTest.php @@ -4,6 +4,8 @@ use Doctrine\DBAL\Configuration; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver; +use Doctrine\DBAL\Driver\Connection as DriverConnection; use Doctrine\DBAL\Logging\SQLLogger; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Statement; @@ -25,28 +27,28 @@ class StatementTest extends DbalTestCase protected function setUp() { - $this->pdoStatement = $this->getMockBuilder('\PDOStatement') + $this->pdoStatement = $this->getMockBuilder(PDOStatement::class) ->setMethods(['execute', 'bindParam', 'bindValue']) ->getMock(); $platform = new MockPlatform(); - $driverConnection = $this->createMock('\Doctrine\DBAL\Driver\Connection'); + $driverConnection = $this->createMock(DriverConnection::class); $driverConnection->expects($this->any()) ->method('prepare') ->will($this->returnValue($this->pdoStatement)); - $driver = $this->createMock('\Doctrine\DBAL\Driver'); + $driver = $this->createMock(Driver::class); $constructorArgs = [ ['platform' => $platform], $driver, ]; - $this->conn = $this->getMockBuilder('\Doctrine\DBAL\Connection') + $this->conn = $this->getMockBuilder(Connection::class) ->setConstructorArgs($constructorArgs) ->getMock(); $this->conn->expects($this->atLeastOnce()) ->method('getWrappedConnection') ->will($this->returnValue($driverConnection)); - $this->configuration = $this->createMock('\Doctrine\DBAL\Configuration'); + $this->configuration = $this->createMock(Configuration::class); $this->conn->expects($this->any()) ->method('getConfiguration') ->will($this->returnValue($this->configuration)); @@ -65,7 +67,7 @@ public function testExecuteCallsLoggerStartQueryWithParametersWhenValuesBound() $types = [$name => $type]; $sql = ''; - $logger = $this->createMock('\Doctrine\DBAL\Logging\SQLLogger'); + $logger = $this->createMock(SQLLogger::class); $logger->expects($this->once()) ->method('startQuery') ->with($this->equalTo($sql), $this->equalTo($values), $this->equalTo($types)); @@ -87,7 +89,7 @@ public function testExecuteCallsLoggerStartQueryWithParametersWhenParamsPassedTo $types = []; $sql = ''; - $logger = $this->createMock('\Doctrine\DBAL\Logging\SQLLogger'); + $logger = $this->createMock(SQLLogger::class); $logger->expects($this->once()) ->method('startQuery') ->with($this->equalTo($sql), $this->equalTo($values), $this->equalTo($types)); @@ -127,7 +129,7 @@ public function testExecuteCallsStartQueryWithTheParametersBoundViaBindParam() */ public function testExecuteCallsLoggerStopQueryOnException() { - $logger = $this->createMock('\Doctrine\DBAL\Logging\SQLLogger'); + $logger = $this->createMock(SQLLogger::class); $this->configuration->expects($this->once()) ->method('getSQLLogger') diff --git a/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php b/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php index 84907e09316..a85efd0a88c 100644 --- a/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php +++ b/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php @@ -29,7 +29,7 @@ protected function setUp() $this->command = $application->find('dbal:run-sql'); $this->commandTester = new CommandTester($this->command); - $this->connectionMock = $this->createMock('\Doctrine\DBAL\Connection'); + $this->connectionMock = $this->createMock(Connection::class); $this->connectionMock->method('fetchAll') ->willReturn([[1]]); $this->connectionMock->method('executeUpdate') diff --git a/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php b/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php index b536c0c1d21..ecb4155f74f 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\DBAL\Types; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; use Doctrine\Tests\DbalTestCase; @@ -11,22 +12,22 @@ class ArrayTest extends DbalTestCase { /** @var AbstractPlatform */ - protected $_platform; + private $platform; /** @var Type */ - protected $_type; + private $type; protected function setUp() { - $this->_platform = new MockPlatform(); - $this->_type = Type::getType('array'); + $this->platform = new MockPlatform(); + $this->type = Type::getType('array'); } public function testArrayConvertsToDatabaseValue() { self::assertInternalType( 'string', - $this->_type->convertToDatabaseValue([], $this->_platform) + $this->type->convertToDatabaseValue([], $this->platform) ); } @@ -34,20 +35,20 @@ public function testArrayConvertsToPHPValue() { self::assertInternalType( 'array', - $this->_type->convertToPHPValue(serialize([]), $this->_platform) + $this->type->convertToPHPValue(serialize([]), $this->platform) ); } public function testConversionFailure() { - $this->expectException('Doctrine\DBAL\Types\ConversionException'); + $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); + $this->type->convertToPHPValue('abcdefg', $this->platform); } public function testNullConversion() { - self::assertNull($this->_type->convertToPHPValue(null, $this->_platform)); + self::assertNull($this->type->convertToPHPValue(null, $this->platform)); } /** @@ -55,6 +56,6 @@ public function testNullConversion() */ public function testFalseConversion() { - self::assertFalse($this->_type->convertToPHPValue(serialize(false), $this->_platform)); + 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 985c06605c5..8140cf6d109 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php @@ -4,6 +4,7 @@ use DateTime; use DateTimeImmutable; +use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; use PHPUnit\Framework\TestCase; @@ -30,7 +31,7 @@ protected function setUp() $this->platform = new MockPlatform(); $this->currentTimezone = date_default_timezone_get(); - self::assertInstanceOf('Doctrine\DBAL\Types\Type', $this->type); + self::assertInstanceOf(Type::class, $this->type); } /** @@ -53,7 +54,7 @@ public function testDateConvertsToDatabaseValue() */ public function testInvalidTypeConversionToDatabaseValue($value) { - $this->expectException('Doctrine\DBAL\Types\ConversionException'); + $this->expectException(ConversionException::class); $this->type->convertToDatabaseValue($value, $this->platform); } diff --git a/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php b/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php index 21b043d1c70..a7e3377107a 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php @@ -9,29 +9,29 @@ class BooleanTest extends DbalTestCase { /** @var MockPlatform */ - protected $_platform; + private $platform; /** @var Type */ - protected $_type; + private $type; protected function setUp() { - $this->_platform = new MockPlatform(); - $this->_type = Type::getType('boolean'); + $this->platform = new MockPlatform(); + $this->type = Type::getType('boolean'); } public function testBooleanConvertsToDatabaseValue() { - self::assertInternalType('integer', $this->_type->convertToDatabaseValue(1, $this->_platform)); + self::assertInternalType('integer', $this->type->convertToDatabaseValue(1, $this->platform)); } public function testBooleanConvertsToPHPValue() { - self::assertInternalType('bool', $this->_type->convertToPHPValue(0, $this->_platform)); + self::assertInternalType('bool', $this->type->convertToPHPValue(0, $this->platform)); } public function testBooleanNullConvertsToPHPValue() { - self::assertNull($this->_type->convertToPHPValue(null, $this->_platform)); + 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 2740e708e10..f0183ef854c 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php @@ -19,7 +19,7 @@ public function testConversionFailedInvalidTypeWithScalar($scalarValue) { $exception = ConversionException::conversionFailedInvalidType($scalarValue, 'foo', ['bar', 'baz']); - self::assertInstanceOf('Doctrine\DBAL\Types\ConversionException', $exception); + self::assertInstanceOf(ConversionException::class, $exception); self::assertRegExp( '/^Could not convert PHP value \'.*\' of type \'(string|boolean|float|double|integer)\' to type \'foo\'. ' . 'Expected one of the following types: bar, baz$/', @@ -35,7 +35,7 @@ public function testConversionFailedInvalidTypeWithNonScalar($nonScalar) { $exception = ConversionException::conversionFailedInvalidType($nonScalar, 'foo', ['bar', 'baz']); - self::assertInstanceOf('Doctrine\DBAL\Types\ConversionException', $exception); + self::assertInstanceOf(ConversionException::class, $exception); self::assertRegExp( '/^Could not convert PHP value of type \'(.*)\' to type \'foo\'. ' . 'Expected one of the following types: bar, baz$/', @@ -49,7 +49,7 @@ public function testConversionFailedFormatPreservesPreviousException() $exception = ConversionException::conversionFailedFormat('foo', 'bar', 'baz', $previous); - self::assertInstanceOf('Doctrine\DBAL\Types\ConversionException', $exception); + self::assertInstanceOf(ConversionException::class, $exception); self::assertSame($previous, $exception->getPrevious()); } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTest.php index 6b41eab3c50..a8c7327b337 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\DBAL\Types; use DateTime; +use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; use function date_default_timezone_set; @@ -34,7 +35,7 @@ public function testDateResetsNonDatePartsToZeroUnixTimeValues() self::assertEquals('00:00:00', $date->format('H:i:s')); } - public function testDateRests_SummerTimeAffection() + public function testDateRestsSummerTimeAffection() { date_default_timezone_set('Europe/Berlin'); @@ -49,7 +50,7 @@ public function testDateRests_SummerTimeAffection() public function testInvalidDateFormatConversion() { - $this->expectException('Doctrine\DBAL\Types\ConversionException'); + $this->expectException(ConversionException::class); $this->type->convertToPHPValue('abcdefg', $this->platform); } } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php index d104f83a835..7d571f80eb2 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\DBAL\Types; use DateTime; +use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; class DateTimeTest extends BaseDateTypeTestCase @@ -37,7 +38,7 @@ public function testDateTimeConvertsToPHPValue() public function testInvalidDateTimeFormatConversion() { - $this->expectException('Doctrine\DBAL\Types\ConversionException'); + $this->expectException(ConversionException::class); $this->type->convertToPHPValue('abcdefg', $this->platform); } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php index 8f97ff83167..4b6c8fb208f 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\DBAL\Types; use DateTime; +use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; class DateTimeTzTest extends BaseDateTypeTestCase @@ -37,7 +38,7 @@ public function testDateTimeConvertsToPHPValue() public function testInvalidDateFormatConversion() { - $this->expectException('Doctrine\DBAL\Types\ConversionException'); + $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 aedb6c98bb6..3d1164afbfb 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php @@ -9,24 +9,24 @@ class DecimalTest extends DbalTestCase { /** @var MockPlatform */ - protected $_platform; + private $platform; /** @var Type */ - protected $_type; + private $type; protected function setUp() { - $this->_platform = new MockPlatform(); - $this->_type = Type::getType('decimal'); + $this->platform = new MockPlatform(); + $this->type = Type::getType('decimal'); } public function testDecimalConvertsToPHPValue() { - self::assertInternalType('string', $this->_type->convertToPHPValue('5.5', $this->_platform)); + self::assertInternalType('string', $this->type->convertToPHPValue('5.5', $this->platform)); } public function testDecimalNullConvertsToPHPValue() { - self::assertNull($this->_type->convertToPHPValue(null, $this->_platform)); + 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 e3fc70a8be9..e68bf0bc46f 100644 --- a/tests/Doctrine/Tests/DBAL/Types/FloatTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/FloatTest.php @@ -9,34 +9,34 @@ class FloatTest extends DbalTestCase { /** @var MockPlatform */ - protected $_platform; + private $platform; /** @var Type */ - protected $_type; + private $type; protected function setUp() { - $this->_platform = new MockPlatform(); - $this->_type = Type::getType('float'); + $this->platform = new MockPlatform(); + $this->type = Type::getType('float'); } public function testFloatConvertsToPHPValue() { - self::assertInternalType('float', $this->_type->convertToPHPValue('5.5', $this->_platform)); + self::assertInternalType('float', $this->type->convertToPHPValue('5.5', $this->platform)); } public function testFloatNullConvertsToPHPValue() { - self::assertNull($this->_type->convertToPHPValue(null, $this->_platform)); + self::assertNull($this->type->convertToPHPValue(null, $this->platform)); } public function testFloatConvertToDatabaseValue() { - self::assertInternalType('float', $this->_type->convertToDatabaseValue(5.5, $this->_platform)); + self::assertInternalType('float', $this->type->convertToDatabaseValue(5.5, $this->platform)); } public function testFloatNullConvertToDatabaseValue() { - self::assertNull($this->_type->convertToDatabaseValue(null, $this->_platform)); + 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 439e9de7168..978cfd50fb7 100644 --- a/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php @@ -10,37 +10,37 @@ class GuidTypeTest extends DbalTestCase { /** @var MockPlatform */ - protected $_platform; + private $platform; /** @var Type */ - protected $_type; + private $type; protected function setUp() { - $this->_platform = new MockPlatform(); - $this->_type = Type::getType('guid'); + $this->platform = new MockPlatform(); + $this->type = Type::getType('guid'); } public function testConvertToPHPValue() { - self::assertInternalType('string', $this->_type->convertToPHPValue('foo', $this->_platform)); - self::assertInternalType('string', $this->_type->convertToPHPValue('', $this->_platform)); + self::assertInternalType('string', $this->type->convertToPHPValue('foo', $this->platform)); + self::assertInternalType('string', $this->type->convertToPHPValue('', $this->platform)); } public function testNullConversion() { - self::assertNull($this->_type->convertToPHPValue(null, $this->_platform)); + self::assertNull($this->type->convertToPHPValue(null, $this->platform)); } public function testNativeGuidSupport() { - self::assertTrue($this->_type->requiresSQLCommentHint($this->_platform)); + self::assertTrue($this->type->requiresSQLCommentHint($this->platform)); - $mock = $this->createMock(get_class($this->_platform)); + $mock = $this->createMock(get_class($this->platform)); $mock->expects($this->any()) ->method('hasNativeGuidType') ->will($this->returnValue(true)); - self::assertFalse($this->_type->requiresSQLCommentHint($mock)); + self::assertFalse($this->type->requiresSQLCommentHint($mock)); } } diff --git a/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php b/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php index 07fda0d8165..848ff05dfc8 100644 --- a/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php @@ -9,25 +9,25 @@ class IntegerTest extends DbalTestCase { /** @var MockPlatform */ - protected $_platform; + private $platform; /** @var Type */ - protected $_type; + private $type; protected function setUp() { - $this->_platform = new MockPlatform(); - $this->_type = Type::getType('integer'); + $this->platform = new MockPlatform(); + $this->type = Type::getType('integer'); } public function testIntegerConvertsToPHPValue() { - self::assertInternalType('integer', $this->_type->convertToPHPValue('1', $this->_platform)); - self::assertInternalType('integer', $this->_type->convertToPHPValue('0', $this->_platform)); + self::assertInternalType('integer', $this->type->convertToPHPValue('1', $this->platform)); + self::assertInternalType('integer', $this->type->convertToPHPValue('0', $this->platform)); } public function testIntegerNullConvertsToPHPValue() { - self::assertNull($this->_type->convertToPHPValue(null, $this->_platform)); + self::assertNull($this->type->convertToPHPValue(null, $this->platform)); } } diff --git a/tests/Doctrine/Tests/DBAL/Types/JsonTest.php b/tests/Doctrine/Tests/DBAL/Types/JsonTest.php index 18ef77a6394..4f204a8baec 100644 --- a/tests/Doctrine/Tests/DBAL/Types/JsonTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/JsonTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\DBAL\Types; use Doctrine\DBAL\ParameterType; +use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\JsonType; use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; @@ -65,7 +66,7 @@ public function testJsonStringConvertsToPHPValue() /** @dataProvider providerFailure */ public function testConversionFailure($data) { - $this->expectException('Doctrine\DBAL\Types\ConversionException'); + $this->expectException(ConversionException::class); $this->type->convertToPHPValue($data, $this->platform); } diff --git a/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php b/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php index 7f1794e0d0c..858004b73f4 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Types; +use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DBAL\Mocks\MockPlatform; use Doctrine\Tests\DbalTestCase; @@ -11,37 +12,37 @@ class ObjectTest extends DbalTestCase { /** @var MockPlatform */ - protected $_platform; + private $platform; /** @var Type */ - protected $_type; + private $type; protected function setUp() { - $this->_platform = new MockPlatform(); - $this->_type = Type::getType('object'); + $this->platform = new MockPlatform(); + $this->type = Type::getType('object'); } public function testObjectConvertsToDatabaseValue() { - self::assertInternalType('string', $this->_type->convertToDatabaseValue(new stdClass(), $this->_platform)); + self::assertInternalType('string', $this->type->convertToDatabaseValue(new stdClass(), $this->platform)); } public function testObjectConvertsToPHPValue() { - self::assertInternalType('object', $this->_type->convertToPHPValue(serialize(new stdClass()), $this->_platform)); + self::assertInternalType('object', $this->type->convertToPHPValue(serialize(new stdClass()), $this->platform)); } public function testConversionFailure() { - $this->expectException('Doctrine\DBAL\Types\ConversionException'); + $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); + $this->type->convertToPHPValue('abcdefg', $this->platform); } public function testNullConversion() { - self::assertNull($this->_type->convertToPHPValue(null, $this->_platform)); + self::assertNull($this->type->convertToPHPValue(null, $this->platform)); } /** @@ -49,6 +50,6 @@ public function testNullConversion() */ public function testFalseConversion() { - self::assertFalse($this->_type->convertToPHPValue(serialize(false), $this->_platform)); + 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 3d4770a9c43..4a453421b36 100644 --- a/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php @@ -9,25 +9,25 @@ class SmallIntTest extends DbalTestCase { /** @var MockPlatform */ - protected $_platform; + private $platform; /** @var Type */ - protected $_type; + private $type; protected function setUp() { - $this->_platform = new MockPlatform(); - $this->_type = Type::getType('smallint'); + $this->platform = new MockPlatform(); + $this->type = Type::getType('smallint'); } public function testSmallIntConvertsToPHPValue() { - self::assertInternalType('integer', $this->_type->convertToPHPValue('1', $this->_platform)); - self::assertInternalType('integer', $this->_type->convertToPHPValue('0', $this->_platform)); + self::assertInternalType('integer', $this->type->convertToPHPValue('1', $this->platform)); + self::assertInternalType('integer', $this->type->convertToPHPValue('0', $this->platform)); } public function testSmallIntNullConvertsToPHPValue() { - self::assertNull($this->_type->convertToPHPValue(null, $this->_platform)); + 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 b19dff22683..74716e4f23c 100644 --- a/tests/Doctrine/Tests/DBAL/Types/StringTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/StringTest.php @@ -9,42 +9,42 @@ class StringTest extends DbalTestCase { /** @var MockPlatform */ - protected $_platform; + private $platform; /** @var Type */ - protected $_type; + private $type; protected function setUp() { - $this->_platform = new MockPlatform(); - $this->_type = Type::getType('string'); + $this->platform = new MockPlatform(); + $this->type = Type::getType('string'); } public function testReturnsSqlDeclarationFromPlatformVarchar() { - self::assertEquals('DUMMYVARCHAR()', $this->_type->getSqlDeclaration([], $this->_platform)); + self::assertEquals('DUMMYVARCHAR()', $this->type->getSqlDeclaration([], $this->platform)); } public function testReturnsDefaultLengthFromPlatformVarchar() { - self::assertEquals(255, $this->_type->getDefaultLength($this->_platform)); + self::assertEquals(255, $this->type->getDefaultLength($this->platform)); } public function testConvertToPHPValue() { - self::assertInternalType('string', $this->_type->convertToPHPValue('foo', $this->_platform)); - self::assertInternalType('string', $this->_type->convertToPHPValue('', $this->_platform)); + self::assertInternalType('string', $this->type->convertToPHPValue('foo', $this->platform)); + self::assertInternalType('string', $this->type->convertToPHPValue('', $this->platform)); } public function testNullConversion() { - self::assertNull($this->_type->convertToPHPValue(null, $this->_platform)); + self::assertNull($this->type->convertToPHPValue(null, $this->platform)); } public function testSQLConversion() { - 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)); - self::assertEquals('t.foo', $this->_type->convertToPHPValueSQL('t.foo', $this->_platform)); + 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)); + self::assertEquals('t.foo', $this->type->convertToPHPValueSQL('t.foo', $this->platform)); } } diff --git a/tests/Doctrine/Tests/DBAL/Types/TimeTest.php b/tests/Doctrine/Tests/DBAL/Types/TimeTest.php index f55d50e7ad7..c2cd766b1c3 100644 --- a/tests/Doctrine/Tests/DBAL/Types/TimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/TimeTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Types; +use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; class TimeTest extends BaseDateTypeTestCase @@ -31,7 +32,7 @@ public function testDateFieldResetInPHPValue() public function testInvalidTimeFormatConversion() { - $this->expectException('Doctrine\DBAL\Types\ConversionException'); + $this->expectException(ConversionException::class); $this->type->convertToPHPValue('abcdefg', $this->platform); } } diff --git a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php index a4e5139d266..2322aa474fe 100644 --- a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php @@ -3,33 +3,35 @@ namespace Doctrine\Tests\DBAL\Types; use DateTime; +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; class VarDateTimeTest extends DbalTestCase { /** @var MockPlatform */ - protected $_platform; + private $platform; /** @var Type */ - protected $_type; + private $type; protected function setUp() { - $this->_platform = new MockPlatform(); + $this->platform = new MockPlatform(); if (! Type::hasType('vardatetime')) { - Type::addType('vardatetime', 'Doctrine\DBAL\Types\VarDateTimeType'); + Type::addType('vardatetime', VarDateTimeType::class); } - $this->_type = Type::getType('vardatetime'); + $this->type = Type::getType('vardatetime'); } public function testDateTimeConvertsToDatabaseValue() { $date = new DateTime('1985-09-01 10:10:10'); - $expected = $date->format($this->_platform->getDateTimeTzFormatString()); - $actual = $this->_type->convertToDatabaseValue($date, $this->_platform); + $expected = $date->format($this->platform->getDateTimeTzFormatString()); + $actual = $this->type->convertToDatabaseValue($date, $this->platform); self::assertEquals($expected, $actual); } @@ -37,7 +39,7 @@ public function testDateTimeConvertsToDatabaseValue() public function testDateTimeConvertsToPHPValue() { // Birthday of jwage and also birthday of Doctrine. Send him a present ;) - $date = $this->_type->convertToPHPValue('1985-09-01 00:00:00', $this->_platform); + $date = $this->type->convertToPHPValue('1985-09-01 00:00:00', $this->platform); self::assertInstanceOf('DateTime', $date); self::assertEquals('1985-09-01 00:00:00', $date->format('Y-m-d H:i:s')); self::assertEquals('000000', $date->format('u')); @@ -45,13 +47,13 @@ public function testDateTimeConvertsToPHPValue() public function testInvalidDateTimeFormatConversion() { - $this->expectException('Doctrine\DBAL\Types\ConversionException'); - $this->_type->convertToPHPValue('abcdefg', $this->_platform); + $this->expectException(ConversionException::class); + $this->type->convertToPHPValue('abcdefg', $this->platform); } public function testConversionWithMicroseconds() { - $date = $this->_type->convertToPHPValue('1985-09-01 00:00:00.123456', $this->_platform); + $date = $this->type->convertToPHPValue('1985-09-01 00:00:00.123456', $this->platform); self::assertInstanceOf('DateTime', $date); self::assertEquals('1985-09-01 00:00:00', $date->format('Y-m-d H:i:s')); self::assertEquals('123456', $date->format('u')); @@ -59,12 +61,12 @@ public function testConversionWithMicroseconds() public function testNullConversion() { - self::assertNull($this->_type->convertToPHPValue(null, $this->_platform)); + self::assertNull($this->type->convertToPHPValue(null, $this->platform)); } public function testConvertDateTimeToPHPValue() { $date = new DateTime('now'); - self::assertSame($date, $this->_type->convertToPHPValue($date, $this->_platform)); + 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 2c94e29555d..e7800fceba3 100644 --- a/tests/Doctrine/Tests/DBAL/UtilTest.php +++ b/tests/Doctrine/Tests/DBAL/UtilTest.php @@ -64,9 +64,9 @@ public static function dataConvertPositionalToNamedParameters() } /** - * @param string $inputSQL - * @param string $expectedOutputSQL - * @param array $expectedOutputParamsMap + * @param string $inputSQL + * @param string $expectedOutputSQL + * @param mixed[] $expectedOutputParamsMap * * @dataProvider dataConvertPositionalToNamedParameters */ diff --git a/tests/Doctrine/Tests/DbalFunctionalTestCase.php b/tests/Doctrine/Tests/DbalFunctionalTestCase.php index 9fabe2d8101..77cfd8d6900 100644 --- a/tests/Doctrine/Tests/DbalFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DbalFunctionalTestCase.php @@ -25,39 +25,39 @@ class DbalFunctionalTestCase extends DbalTestCase * * @var Connection */ - private static $_sharedConn; + private static $sharedConnection; /** @var Connection */ - protected $_conn; + protected $connection; /** @var DebugStack */ - protected $_sqlLoggerStack; + protected $sqlLoggerStack; protected function resetSharedConn() { - if (! self::$_sharedConn) { + if (! self::$sharedConnection) { return; } - self::$_sharedConn->close(); - self::$_sharedConn = null; + self::$sharedConnection->close(); + self::$sharedConnection = null; } protected function setUp() { - if (! isset(self::$_sharedConn)) { - self::$_sharedConn = TestUtil::getConnection(); + if (! isset(self::$sharedConnection)) { + self::$sharedConnection = TestUtil::getConnection(); } - $this->_conn = self::$_sharedConn; + $this->connection = self::$sharedConnection; - $this->_sqlLoggerStack = new DebugStack(); - $this->_conn->getConfiguration()->setSQLLogger($this->_sqlLoggerStack); + $this->sqlLoggerStack = new DebugStack(); + $this->connection->getConfiguration()->setSQLLogger($this->sqlLoggerStack); } protected function tearDown() { - while ($this->_conn->isTransactionActive()) { - $this->_conn->rollBack(); + while ($this->connection->isTransactionActive()) { + $this->connection->rollBack(); } } @@ -67,10 +67,10 @@ protected function onNotSuccessfulTest(Throwable $t) throw $t; } - if (isset($this->_sqlLoggerStack->queries) && count($this->_sqlLoggerStack->queries)) { + if (isset($this->sqlLoggerStack->queries) && count($this->sqlLoggerStack->queries)) { $queries = ''; - $i = count($this->_sqlLoggerStack->queries); - foreach (array_reverse($this->_sqlLoggerStack->queries) as $query) { + $i = count($this->sqlLoggerStack->queries); + foreach (array_reverse($this->sqlLoggerStack->queries) as $query) { $params = array_map(static function ($p) { if (is_object($p)) { return get_class($p); diff --git a/tests/Doctrine/Tests/DbalPerformanceTestListener.php b/tests/Doctrine/Tests/DbalPerformanceTestListener.php index 06e8ce77e96..e9265c0f35f 100644 --- a/tests/Doctrine/Tests/DbalPerformanceTestListener.php +++ b/tests/Doctrine/Tests/DbalPerformanceTestListener.php @@ -30,7 +30,7 @@ public function endTest(Test $test, float $time) : void } // we identify perf tests by class, method, and dataset - $class = str_replace('Doctrine\Tests\DBAL\Performance\\', '', get_class($test)); + $class = str_replace('\\Doctrine\\Tests\\DBAL\\Performance\\', '', get_class($test)); if (! isset($this->timings[$class])) { $this->timings[$class] = []; diff --git a/tests/Doctrine/Tests/Mocks/ConnectionMock.php b/tests/Doctrine/Tests/Mocks/ConnectionMock.php index 989b063adc6..157584f09f7 100644 --- a/tests/Doctrine/Tests/Mocks/ConnectionMock.php +++ b/tests/Doctrine/Tests/Mocks/ConnectionMock.php @@ -8,34 +8,40 @@ class ConnectionMock extends Connection { /** @var DatabasePlatformMock */ - private $_platformMock; + private $platformMock; /** @var int */ - private $_lastInsertId = 0; + private $lastInsertId = 0; /** @var string[][] */ - private $_inserts = array(); + private $inserts = []; + /** + * {@inheritDoc} + */ public function __construct(array $params, $driver, $config = null, $eventManager = null) { - $this->_platformMock = new DatabasePlatformMock(); + $this->platformMock = new DatabasePlatformMock(); parent::__construct($params, $driver, $config, $eventManager); } public function getDatabasePlatform() { - return $this->_platformMock; + return $this->platformMock; } + /** + * {@inheritDoc} + */ public function insert($tableName, array $data, array $types = []) { - $this->_inserts[$tableName][] = $data; + $this->inserts[$tableName][] = $data; } public function lastInsertId($seqName = null) { - return $this->_lastInsertId; + return $this->lastInsertId; } public function quote($input, $type = null) @@ -48,17 +54,17 @@ public function quote($input, $type = null) public function setLastInsertId($id) { - $this->_lastInsertId = $id; + $this->lastInsertId = $id; } public function getInserts() { - return $this->_inserts; + return $this->inserts; } public function reset() { - $this->_inserts = []; - $this->_lastInsertId = 0; + $this->inserts = []; + $this->lastInsertId = 0; } } diff --git a/tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php b/tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php index 231d6dbc5dc..690809e308a 100644 --- a/tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php +++ b/tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php @@ -8,72 +8,96 @@ class DatabasePlatformMock extends AbstractPlatform { /** @var string */ - private $_sequenceNextValSql = ''; + private $sequenceNextValSql = ''; /** @var bool */ - private $_prefersIdentityColumns = true; + private $prefersIdentityColumns = true; /** @var bool */ - private $_prefersSequences = false; + private $prefersSequences = false; public function prefersIdentityColumns() { - return $this->_prefersIdentityColumns; + return $this->prefersIdentityColumns; } public function prefersSequences() { - return $this->_prefersSequences; + return $this->prefersSequences; } public function getSequenceNextValSQL($sequenceName) { - return $this->_sequenceNextValSql; + 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 */ - public function setPrefersIdentityColumns($bool) + /** + * @param bool $prefersIdentityColumns + */ + public function setPrefersIdentityColumns($prefersIdentityColumns) { - $this->_prefersIdentityColumns = $bool; + $this->prefersIdentityColumns = $prefersIdentityColumns; } public function setPrefersSequences($bool) { - $this->_prefersSequences = $bool; + $this->prefersSequences = $bool; } public function setSequenceNextValSql($sql) { - $this->_sequenceNextValSql = $sql; + $this->sequenceNextValSql = $sql; } public function getName() @@ -86,8 +110,9 @@ protected function initializeDoctrineTypeMappings() protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) { } + /** - * Gets the SQL Snippet used to declare a BLOB column type. + * {@inheritDoc} */ public function getBlobTypeDeclarationSQL(array $field) { diff --git a/tests/Doctrine/Tests/Mocks/DriverMock.php b/tests/Doctrine/Tests/Mocks/DriverMock.php index 432bb9135ac..9b5f4245472 100644 --- a/tests/Doctrine/Tests/Mocks/DriverMock.php +++ b/tests/Doctrine/Tests/Mocks/DriverMock.php @@ -11,11 +11,14 @@ class DriverMock implements Driver { /** @var DatabasePlatformMock */ - private $_platformMock; + private $platformMock; /** @var AbstractSchemaManager */ - private $_schemaManagerMock; + private $schemaManagerMock; + /** + * {@inheritDoc} + */ public function connect(array $params, $username = null, $password = null, array $driverOptions = []) { return new DriverConnectionMock(); @@ -23,31 +26,29 @@ public function connect(array $params, $username = null, $password = null, array public function getDatabasePlatform() { - if (! $this->_platformMock) { - $this->_platformMock = new DatabasePlatformMock(); + if (! $this->platformMock) { + $this->platformMock = new DatabasePlatformMock(); } - return $this->_platformMock; + return $this->platformMock; } public function getSchemaManager(Connection $conn) { - if ($this->_schemaManagerMock === null) { + if ($this->schemaManagerMock === null) { return new SchemaManagerMock($conn); } - return $this->_schemaManagerMock; + return $this->schemaManagerMock; } - /* MOCK API */ - public function setDatabasePlatform(AbstractPlatform $platform) { - $this->_platformMock = $platform; + $this->platformMock = $platform; } public function setSchemaManager(AbstractSchemaManager $sm) { - $this->_schemaManagerMock = $sm; + $this->schemaManagerMock = $sm; } public function getName() diff --git a/tests/Doctrine/Tests/Mocks/TaskMock.php b/tests/Doctrine/Tests/Mocks/TaskMock.php deleted file mode 100644 index 4502703d9ac..00000000000 --- a/tests/Doctrine/Tests/Mocks/TaskMock.php +++ /dev/null @@ -1,84 +0,0 @@ -. - */ - -namespace Doctrine\Tests\Mocks; - -use Doctrine\Common\Cli\AbstractNamespace; - -/** - * TaskMock used for testing the CLI interface. - * @author Nils Adermann - */ -class TaskMock extends \Doctrine\Common\Cli\Tasks\AbstractTask -{ - /** - * Since instances of this class can be created elsewhere all instances - * register themselves in this array for later inspection. - * - * @var array(TaskMock) - */ - static public $instances = array(); - - /** - * @var int - */ - private $runCounter = 0; - - /** - * Constructor of Task Mock Object. - * Makes sure the object can be inspected later. - * - * @param AbstractNamespace CLI Namespace, passed to parent constructor - */ - function __construct(AbstractNamespace $namespace) - { - self::$instances[] = $this; - - parent::__construct($namespace); - } - - /** - * Returns the number of times run() was called on this object. - * - * @return int - */ - public function getRunCounter() - { - return $this->runCounter; - } - - /* Mock API */ - - /** - * Method invoked by CLI to run task. - */ - public function run() - { - $this->runCounter++; - } - - /** - * Method supposed to generate the CLI Task Documentation - */ - public function buildDocumentation() - { - } -} diff --git a/tests/Doctrine/Tests/Types/CommentedType.php b/tests/Doctrine/Tests/Types/CommentedType.php index f5c1fdb1b27..cbe98b2324b 100644 --- a/tests/Doctrine/Tests/Types/CommentedType.php +++ b/tests/Doctrine/Tests/Types/CommentedType.php @@ -8,16 +8,25 @@ class CommentedType extends Type { + /** + * {@inheritDoc} + */ public function getName() { return 'my_commented'; } + /** + * {@inheritDoc} + */ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { return strtoupper($this->getName()); } + /** + * {@inheritDoc} + */ public function requiresSQLCommentHint(AbstractPlatform $platform) { return true; diff --git a/tests/Doctrine/Tests/Types/MySqlPointType.php b/tests/Doctrine/Tests/Types/MySqlPointType.php index 7e95418bc18..f4740769b8b 100644 --- a/tests/Doctrine/Tests/Types/MySqlPointType.php +++ b/tests/Doctrine/Tests/Types/MySqlPointType.php @@ -8,16 +8,25 @@ class MySqlPointType extends Type { + /** + * {@inheritDoc} + */ public function getName() { return 'point'; } + /** + * {@inheritDoc} + */ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { return strtoupper($this->getName()); } + /** + * {@inheritDoc} + */ public function getMappedDatabaseTypes(AbstractPlatform $platform) { return ['point']; From 9d513ca01c520f8ca02614183278f121d2180c6e Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 28 Sep 2018 08:59:46 -0700 Subject: [PATCH 29/76] Temporarily excluded failing sniff See https://github.com/squizlabs/PHP_CodeSniffer/issues/2165 --- phpcs.xml.dist | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 7385edd063d..2367364b58f 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -35,4 +35,9 @@ tests/Doctrine/Tests/DBAL/Tools/TestAsset/* + + + + tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php + From ba4c9a25de51457254240b75da1555d01c6a8bb1 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sat, 29 Sep 2018 12:54:18 -0700 Subject: [PATCH 30/76] Removed license headers --- lib/Doctrine/DBAL/Cache/ArrayStatement.php | 17 ----------------- lib/Doctrine/DBAL/Cache/CacheException.php | 17 ----------------- lib/Doctrine/DBAL/Cache/QueryCacheProfile.php | 17 ----------------- .../DBAL/Cache/ResultCacheStatement.php | 17 ----------------- lib/Doctrine/DBAL/Configuration.php | 17 ----------------- lib/Doctrine/DBAL/Connection.php | 17 ----------------- lib/Doctrine/DBAL/ConnectionException.php | 17 ----------------- .../Connections/MasterSlaveConnection.php | 17 ----------------- lib/Doctrine/DBAL/DBALException.php | 17 ----------------- lib/Doctrine/DBAL/Driver.php | 17 ----------------- .../DBAL/Driver/AbstractDB2Driver.php | 17 ----------------- .../DBAL/Driver/AbstractDriverException.php | 17 ----------------- .../DBAL/Driver/AbstractMySQLDriver.php | 17 ----------------- .../DBAL/Driver/AbstractOracleDriver.php | 17 ----------------- .../DBAL/Driver/AbstractPostgreSQLDriver.php | 17 ----------------- .../DBAL/Driver/AbstractSQLAnywhereDriver.php | 17 ----------------- .../DBAL/Driver/AbstractSQLServerDriver.php | 17 ----------------- .../DBAL/Driver/AbstractSQLiteDriver.php | 17 ----------------- lib/Doctrine/DBAL/Driver/Connection.php | 17 ----------------- lib/Doctrine/DBAL/Driver/DriverException.php | 17 ----------------- .../Driver/DrizzlePDOMySql/Connection.php | 17 ----------------- .../DBAL/Driver/DrizzlePDOMySql/Driver.php | 17 ----------------- .../DBAL/Driver/ExceptionConverterDriver.php | 17 ----------------- .../DBAL/Driver/IBMDB2/DB2Connection.php | 17 ----------------- lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php | 17 ----------------- .../DBAL/Driver/IBMDB2/DB2Exception.php | 17 ----------------- .../DBAL/Driver/IBMDB2/DB2Statement.php | 17 ----------------- lib/Doctrine/DBAL/Driver/Mysqli/Driver.php | 17 ----------------- .../DBAL/Driver/Mysqli/MysqliConnection.php | 17 ----------------- .../DBAL/Driver/Mysqli/MysqliException.php | 17 ----------------- .../DBAL/Driver/Mysqli/MysqliStatement.php | 17 ----------------- lib/Doctrine/DBAL/Driver/OCI8/Driver.php | 17 ----------------- .../DBAL/Driver/OCI8/OCI8Connection.php | 17 ----------------- .../DBAL/Driver/OCI8/OCI8Exception.php | 17 ----------------- .../DBAL/Driver/OCI8/OCI8Statement.php | 17 ----------------- lib/Doctrine/DBAL/Driver/PDOConnection.php | 17 ----------------- lib/Doctrine/DBAL/Driver/PDOException.php | 17 ----------------- lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php | 17 ----------------- lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php | 17 ----------------- lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php | 17 ----------------- lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php | 17 ----------------- lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php | 17 ----------------- .../DBAL/Driver/PDOSqlsrv/Connection.php | 17 ----------------- lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php | 17 ----------------- .../DBAL/Driver/PDOSqlsrv/Statement.php | 17 ----------------- lib/Doctrine/DBAL/Driver/PDOStatement.php | 17 ----------------- .../DBAL/Driver/PingableConnection.php | 17 ----------------- lib/Doctrine/DBAL/Driver/ResultStatement.php | 17 ----------------- .../DBAL/Driver/SQLAnywhere/Driver.php | 17 ----------------- .../SQLAnywhere/SQLAnywhereConnection.php | 17 ----------------- .../SQLAnywhere/SQLAnywhereException.php | 17 ----------------- .../SQLAnywhere/SQLAnywhereStatement.php | 17 ----------------- lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php | 17 ----------------- .../DBAL/Driver/SQLSrv/LastInsertId.php | 17 ----------------- .../DBAL/Driver/SQLSrv/SQLSrvConnection.php | 17 ----------------- .../DBAL/Driver/SQLSrv/SQLSrvException.php | 17 ----------------- .../DBAL/Driver/SQLSrv/SQLSrvStatement.php | 17 ----------------- .../DBAL/Driver/ServerInfoAwareConnection.php | 17 ----------------- lib/Doctrine/DBAL/Driver/Statement.php | 17 ----------------- lib/Doctrine/DBAL/DriverManager.php | 17 ----------------- .../DBAL/Event/ConnectionEventArgs.php | 17 ----------------- .../DBAL/Event/Listeners/MysqlSessionInit.php | 17 ----------------- .../Event/Listeners/OracleSessionInit.php | 17 ----------------- .../DBAL/Event/Listeners/SQLSessionInit.php | 17 ----------------- .../SchemaAlterTableAddColumnEventArgs.php | 17 ----------------- .../SchemaAlterTableChangeColumnEventArgs.php | 17 ----------------- .../DBAL/Event/SchemaAlterTableEventArgs.php | 17 ----------------- .../SchemaAlterTableRemoveColumnEventArgs.php | 17 ----------------- .../SchemaAlterTableRenameColumnEventArgs.php | 17 ----------------- .../Event/SchemaColumnDefinitionEventArgs.php | 17 ----------------- .../SchemaCreateTableColumnEventArgs.php | 17 ----------------- .../DBAL/Event/SchemaCreateTableEventArgs.php | 17 ----------------- .../DBAL/Event/SchemaDropTableEventArgs.php | 17 ----------------- lib/Doctrine/DBAL/Event/SchemaEventArgs.php | 17 ----------------- .../Event/SchemaIndexDefinitionEventArgs.php | 17 ----------------- lib/Doctrine/DBAL/Events.php | 17 ----------------- .../DBAL/Exception/ConnectionException.php | 17 ----------------- .../ConstraintViolationException.php | 17 ----------------- .../DatabaseObjectExistsException.php | 17 ----------------- .../DatabaseObjectNotFoundException.php | 17 ----------------- .../DBAL/Exception/DeadlockException.php | 17 ----------------- .../DBAL/Exception/DriverException.php | 17 ----------------- ...ForeignKeyConstraintViolationException.php | 17 ----------------- .../Exception/InvalidArgumentException.php | 17 ----------------- .../Exception/InvalidFieldNameException.php | 17 ----------------- .../Exception/LockWaitTimeoutException.php | 17 ----------------- .../Exception/NonUniqueFieldNameException.php | 17 ----------------- .../NotNullConstraintViolationException.php | 17 ----------------- .../DBAL/Exception/ReadOnlyException.php | 17 ----------------- .../DBAL/Exception/RetryableException.php | 17 ----------------- .../DBAL/Exception/ServerException.php | 17 ----------------- .../DBAL/Exception/SyntaxErrorException.php | 17 ----------------- .../DBAL/Exception/TableExistsException.php | 17 ----------------- .../DBAL/Exception/TableNotFoundException.php | 17 ----------------- .../UniqueConstraintViolationException.php | 17 ----------------- lib/Doctrine/DBAL/Id/TableGenerator.php | 17 ----------------- .../DBAL/Id/TableGeneratorSchemaVisitor.php | 17 ----------------- lib/Doctrine/DBAL/LockMode.php | 17 ----------------- lib/Doctrine/DBAL/Logging/DebugStack.php | 17 ----------------- lib/Doctrine/DBAL/Logging/EchoSQLLogger.php | 17 ----------------- lib/Doctrine/DBAL/Logging/LoggerChain.php | 17 ----------------- lib/Doctrine/DBAL/Logging/SQLLogger.php | 17 ----------------- .../DBAL/Platforms/AbstractPlatform.php | 17 ----------------- lib/Doctrine/DBAL/Platforms/DB2Platform.php | 17 ----------------- .../DBAL/Platforms/DrizzlePlatform.php | 17 ----------------- .../DBAL/Platforms/Keywords/DB2Keywords.php | 17 ----------------- .../Platforms/Keywords/DrizzleKeywords.php | 17 ----------------- .../DBAL/Platforms/Keywords/KeywordList.php | 17 ----------------- .../Platforms/Keywords/MariaDb102Keywords.php | 17 ----------------- .../DBAL/Platforms/Keywords/MsSQLKeywords.php | 17 ----------------- .../Platforms/Keywords/MySQL57Keywords.php | 17 ----------------- .../Platforms/Keywords/MySQL80Keywords.php | 17 ----------------- .../DBAL/Platforms/Keywords/MySQLKeywords.php | 17 ----------------- .../Platforms/Keywords/OracleKeywords.php | 17 ----------------- .../Keywords/PostgreSQL91Keywords.php | 17 ----------------- .../Keywords/PostgreSQL92Keywords.php | 17 ----------------- .../Keywords/PostgreSQL94Keywords.php | 17 ----------------- .../Platforms/Keywords/PostgreSQLKeywords.php | 17 ----------------- .../Keywords/ReservedKeywordsValidator.php | 17 ----------------- .../Keywords/SQLAnywhere11Keywords.php | 17 ----------------- .../Keywords/SQLAnywhere12Keywords.php | 17 ----------------- .../Keywords/SQLAnywhere16Keywords.php | 17 ----------------- .../Keywords/SQLAnywhereKeywords.php | 17 ----------------- .../Keywords/SQLServer2005Keywords.php | 17 ----------------- .../Keywords/SQLServer2008Keywords.php | 17 ----------------- .../Keywords/SQLServer2012Keywords.php | 17 ----------------- .../Platforms/Keywords/SQLServerKeywords.php | 17 ----------------- .../Platforms/Keywords/SQLiteKeywords.php | 17 ----------------- .../DBAL/Platforms/MariaDb1027Platform.php | 17 ----------------- .../DBAL/Platforms/MySQL57Platform.php | 17 ----------------- .../DBAL/Platforms/MySQL80Platform.php | 17 ----------------- lib/Doctrine/DBAL/Platforms/MySqlPlatform.php | 17 ----------------- .../DBAL/Platforms/OraclePlatform.php | 17 ----------------- .../DBAL/Platforms/PostgreSQL91Platform.php | 17 ----------------- .../DBAL/Platforms/PostgreSQL92Platform.php | 17 ----------------- .../DBAL/Platforms/PostgreSQL94Platform.php | 17 ----------------- .../DBAL/Platforms/PostgreSqlPlatform.php | 17 ----------------- .../DBAL/Platforms/SQLAnywhere11Platform.php | 17 ----------------- .../DBAL/Platforms/SQLAnywhere12Platform.php | 17 ----------------- .../DBAL/Platforms/SQLAnywhere16Platform.php | 17 ----------------- .../DBAL/Platforms/SQLAnywherePlatform.php | 17 ----------------- .../DBAL/Platforms/SQLAzurePlatform.php | 17 ----------------- .../DBAL/Platforms/SQLServer2005Platform.php | 17 ----------------- .../DBAL/Platforms/SQLServer2008Platform.php | 17 ----------------- .../DBAL/Platforms/SQLServer2012Platform.php | 17 ----------------- .../DBAL/Platforms/SQLServerPlatform.php | 17 ----------------- .../DBAL/Platforms/SqlitePlatform.php | 17 ----------------- lib/Doctrine/DBAL/Portability/Connection.php | 17 ----------------- lib/Doctrine/DBAL/Portability/Statement.php | 17 ----------------- .../Query/Expression/CompositeExpression.php | 17 ----------------- .../Query/Expression/ExpressionBuilder.php | 17 ----------------- lib/Doctrine/DBAL/Query/QueryBuilder.php | 17 ----------------- lib/Doctrine/DBAL/Query/QueryException.php | 17 ----------------- lib/Doctrine/DBAL/SQLParserUtils.php | 17 ----------------- lib/Doctrine/DBAL/SQLParserUtilsException.php | 19 ------------------- lib/Doctrine/DBAL/Schema/AbstractAsset.php | 17 ----------------- .../DBAL/Schema/AbstractSchemaManager.php | 17 ----------------- lib/Doctrine/DBAL/Schema/Column.php | 17 ----------------- lib/Doctrine/DBAL/Schema/ColumnDiff.php | 17 ----------------- lib/Doctrine/DBAL/Schema/Comparator.php | 17 ----------------- lib/Doctrine/DBAL/Schema/Constraint.php | 17 ----------------- lib/Doctrine/DBAL/Schema/DB2SchemaManager.php | 17 ----------------- .../DBAL/Schema/DrizzleSchemaManager.php | 17 ----------------- .../DBAL/Schema/ForeignKeyConstraint.php | 17 ----------------- lib/Doctrine/DBAL/Schema/Identifier.php | 17 ----------------- lib/Doctrine/DBAL/Schema/Index.php | 17 ----------------- .../DBAL/Schema/MySqlSchemaManager.php | 17 ----------------- .../DBAL/Schema/OracleSchemaManager.php | 17 ----------------- .../DBAL/Schema/PostgreSqlSchemaManager.php | 17 ----------------- .../DBAL/Schema/SQLAnywhereSchemaManager.php | 17 ----------------- .../DBAL/Schema/SQLServerSchemaManager.php | 17 ----------------- lib/Doctrine/DBAL/Schema/Schema.php | 17 ----------------- lib/Doctrine/DBAL/Schema/SchemaConfig.php | 17 ----------------- lib/Doctrine/DBAL/Schema/SchemaDiff.php | 17 ----------------- lib/Doctrine/DBAL/Schema/SchemaException.php | 17 ----------------- lib/Doctrine/DBAL/Schema/Sequence.php | 17 ----------------- .../DBAL/Schema/SqliteSchemaManager.php | 17 ----------------- .../AbstractSchemaSynchronizer.php | 17 ----------------- .../Synchronizer/SchemaSynchronizer.php | 17 ----------------- .../SingleDatabaseSynchronizer.php | 17 ----------------- lib/Doctrine/DBAL/Schema/Table.php | 17 ----------------- lib/Doctrine/DBAL/Schema/TableDiff.php | 17 ----------------- lib/Doctrine/DBAL/Schema/View.php | 17 ----------------- .../DBAL/Schema/Visitor/AbstractVisitor.php | 17 ----------------- .../Visitor/CreateSchemaSqlCollector.php | 17 ----------------- .../Schema/Visitor/DropSchemaSqlCollector.php | 17 ----------------- lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php | 17 ----------------- .../DBAL/Schema/Visitor/NamespaceVisitor.php | 17 ----------------- .../Schema/Visitor/RemoveNamespacedAssets.php | 17 ----------------- .../DBAL/Schema/Visitor/SchemaDiffVisitor.php | 17 ----------------- lib/Doctrine/DBAL/Schema/Visitor/Visitor.php | 17 ----------------- .../DBAL/Sharding/PoolingShardConnection.php | 17 ----------------- .../DBAL/Sharding/PoolingShardManager.php | 17 ----------------- .../SQLAzureFederationsSynchronizer.php | 17 ----------------- .../SQLAzure/SQLAzureShardManager.php | 17 ----------------- .../SQLAzure/Schema/MultiTenantVisitor.php | 17 ----------------- .../ShardChoser/MultiTenantShardChoser.php | 17 ----------------- .../DBAL/Sharding/ShardChoser/ShardChoser.php | 17 ----------------- lib/Doctrine/DBAL/Sharding/ShardManager.php | 17 ----------------- .../DBAL/Sharding/ShardingException.php | 17 ----------------- lib/Doctrine/DBAL/Statement.php | 17 ----------------- .../Tools/Console/Command/ImportCommand.php | 17 ----------------- .../Console/Command/ReservedWordsCommand.php | 17 ----------------- .../Tools/Console/Command/RunSqlCommand.php | 17 ----------------- .../DBAL/Tools/Console/ConsoleRunner.php | 17 ----------------- .../Tools/Console/Helper/ConnectionHelper.php | 17 ----------------- lib/Doctrine/DBAL/Types/ArrayType.php | 17 ----------------- lib/Doctrine/DBAL/Types/BigIntType.php | 17 ----------------- lib/Doctrine/DBAL/Types/BinaryType.php | 17 ----------------- lib/Doctrine/DBAL/Types/BlobType.php | 17 ----------------- lib/Doctrine/DBAL/Types/BooleanType.php | 17 ----------------- .../DBAL/Types/ConversionException.php | 17 ----------------- lib/Doctrine/DBAL/Types/DateImmutableType.php | 17 ----------------- .../DBAL/Types/DateTimeImmutableType.php | 17 ----------------- lib/Doctrine/DBAL/Types/DateTimeType.php | 17 ----------------- .../DBAL/Types/DateTimeTzImmutableType.php | 17 ----------------- lib/Doctrine/DBAL/Types/DateTimeTzType.php | 17 ----------------- lib/Doctrine/DBAL/Types/DateType.php | 17 ----------------- lib/Doctrine/DBAL/Types/DecimalType.php | 17 ----------------- lib/Doctrine/DBAL/Types/FloatType.php | 17 ----------------- lib/Doctrine/DBAL/Types/GuidType.php | 17 ----------------- lib/Doctrine/DBAL/Types/IntegerType.php | 17 ----------------- lib/Doctrine/DBAL/Types/JsonArrayType.php | 17 ----------------- lib/Doctrine/DBAL/Types/JsonType.php | 17 ----------------- lib/Doctrine/DBAL/Types/ObjectType.php | 17 ----------------- .../DBAL/Types/PhpDateTimeMappingType.php | 17 ----------------- .../DBAL/Types/PhpIntegerMappingType.php | 17 ----------------- lib/Doctrine/DBAL/Types/SimpleArrayType.php | 17 ----------------- lib/Doctrine/DBAL/Types/SmallIntType.php | 17 ----------------- lib/Doctrine/DBAL/Types/StringType.php | 17 ----------------- lib/Doctrine/DBAL/Types/TextType.php | 17 ----------------- lib/Doctrine/DBAL/Types/TimeImmutableType.php | 17 ----------------- lib/Doctrine/DBAL/Types/TimeType.php | 17 ----------------- lib/Doctrine/DBAL/Types/Type.php | 17 ----------------- .../DBAL/Types/VarDateTimeImmutableType.php | 17 ----------------- lib/Doctrine/DBAL/Types/VarDateTimeType.php | 17 ----------------- lib/Doctrine/DBAL/Version.php | 17 ----------------- .../DBAL/VersionAwarePlatformDriver.php | 17 ----------------- 238 files changed, 4048 deletions(-) diff --git a/lib/Doctrine/DBAL/Cache/ArrayStatement.php b/lib/Doctrine/DBAL/Cache/ArrayStatement.php index 6e09e124d83..e9247280e09 100644 --- a/lib/Doctrine/DBAL/Cache/ArrayStatement.php +++ b/lib/Doctrine/DBAL/Cache/ArrayStatement.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Cache; diff --git a/lib/Doctrine/DBAL/Cache/CacheException.php b/lib/Doctrine/DBAL/Cache/CacheException.php index 1b69058cde9..00c692940b4 100644 --- a/lib/Doctrine/DBAL/Cache/CacheException.php +++ b/lib/Doctrine/DBAL/Cache/CacheException.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Cache; diff --git a/lib/Doctrine/DBAL/Cache/QueryCacheProfile.php b/lib/Doctrine/DBAL/Cache/QueryCacheProfile.php index a722681ce43..2d29ea0d44f 100644 --- a/lib/Doctrine/DBAL/Cache/QueryCacheProfile.php +++ b/lib/Doctrine/DBAL/Cache/QueryCacheProfile.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Cache; diff --git a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php index 4b200a5d438..3951c52e815 100644 --- a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php +++ b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Cache; diff --git a/lib/Doctrine/DBAL/Configuration.php b/lib/Doctrine/DBAL/Configuration.php index fe9465cdd57..9a63928aa00 100644 --- a/lib/Doctrine/DBAL/Configuration.php +++ b/lib/Doctrine/DBAL/Configuration.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL; diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index c1cb8acf521..2a1d9a1b9c0 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL; diff --git a/lib/Doctrine/DBAL/ConnectionException.php b/lib/Doctrine/DBAL/ConnectionException.php index 86494b0361a..db94489668a 100644 --- a/lib/Doctrine/DBAL/ConnectionException.php +++ b/lib/Doctrine/DBAL/ConnectionException.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL; diff --git a/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php b/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php index 10ed8a1e99c..42c957876cf 100644 --- a/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php +++ b/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Connections; diff --git a/lib/Doctrine/DBAL/DBALException.php b/lib/Doctrine/DBAL/DBALException.php index 67265d954fb..72413141e4a 100644 --- a/lib/Doctrine/DBAL/DBALException.php +++ b/lib/Doctrine/DBAL/DBALException.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL; diff --git a/lib/Doctrine/DBAL/Driver.php b/lib/Doctrine/DBAL/Driver.php index 300a27dec5b..9bd58e80070 100644 --- a/lib/Doctrine/DBAL/Driver.php +++ b/lib/Doctrine/DBAL/Driver.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL; diff --git a/lib/Doctrine/DBAL/Driver/AbstractDB2Driver.php b/lib/Doctrine/DBAL/Driver/AbstractDB2Driver.php index baa081690c0..ad157f03830 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractDB2Driver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractDB2Driver.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver; diff --git a/lib/Doctrine/DBAL/Driver/AbstractDriverException.php b/lib/Doctrine/DBAL/Driver/AbstractDriverException.php index 83c38d71db6..d34ca5cdd93 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractDriverException.php +++ b/lib/Doctrine/DBAL/Driver/AbstractDriverException.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver; diff --git a/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php b/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php index bf6e11f5f1a..031a84dce04 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver; diff --git a/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php b/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php index f58b564f3c5..7ebb54a73b7 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver; diff --git a/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php b/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php index ea7aa71676b..5947ec59edf 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver; diff --git a/lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php b/lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php index ca966511d3b..c3311a15f02 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver; diff --git a/lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver.php b/lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver.php index fb9c989bd14..2097fe4c2bf 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver; diff --git a/lib/Doctrine/DBAL/Driver/AbstractSQLiteDriver.php b/lib/Doctrine/DBAL/Driver/AbstractSQLiteDriver.php index 406cb92ef2f..f8eb73af238 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractSQLiteDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractSQLiteDriver.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver; diff --git a/lib/Doctrine/DBAL/Driver/Connection.php b/lib/Doctrine/DBAL/Driver/Connection.php index a0dd1e66a45..31e8b2277d3 100644 --- a/lib/Doctrine/DBAL/Driver/Connection.php +++ b/lib/Doctrine/DBAL/Driver/Connection.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver; diff --git a/lib/Doctrine/DBAL/Driver/DriverException.php b/lib/Doctrine/DBAL/Driver/DriverException.php index ce1d1e38149..c020c295169 100644 --- a/lib/Doctrine/DBAL/Driver/DriverException.php +++ b/lib/Doctrine/DBAL/Driver/DriverException.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver; diff --git a/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Connection.php b/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Connection.php index bfc61acf9b8..e2b54471312 100644 --- a/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Connection.php +++ b/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Connection.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver\DrizzlePDOMySql; diff --git a/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Driver.php b/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Driver.php index 547fdb79570..202dbf80cdd 100644 --- a/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Driver.php +++ b/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Driver.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver\DrizzlePDOMySql; diff --git a/lib/Doctrine/DBAL/Driver/ExceptionConverterDriver.php b/lib/Doctrine/DBAL/Driver/ExceptionConverterDriver.php index 0bd8d516e14..77264e6e9f1 100644 --- a/lib/Doctrine/DBAL/Driver/ExceptionConverterDriver.php +++ b/lib/Doctrine/DBAL/Driver/ExceptionConverterDriver.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver; diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php index beae3ba0d86..26d84eaa6fa 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver\IBMDB2; diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php index de5921edd23..247247ec151 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver\IBMDB2; diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Exception.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Exception.php index 72775cbfe70..1381904cf10 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Exception.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Exception.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver\IBMDB2; diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php index 68f195427dd..512ff5e1f4e 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver\IBMDB2; diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/Driver.php b/lib/Doctrine/DBAL/Driver/Mysqli/Driver.php index d04e194d14f..1eb6bdad525 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/Driver.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/Driver.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver\Mysqli; diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php index 3a1b18d5781..4c80c21b4c6 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver\Mysqli; diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliException.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliException.php index 23728b113a6..c13b8eaadcf 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliException.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliException.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver\Mysqli; diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php index fe7d4c1297f..6e819335a02 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver\Mysqli; diff --git a/lib/Doctrine/DBAL/Driver/OCI8/Driver.php b/lib/Doctrine/DBAL/Driver/OCI8/Driver.php index 925e9b70f78..216eddb6bcb 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/Driver.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/Driver.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver\OCI8; diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php index e2111d47444..edd37c585ff 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver\OCI8; diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Exception.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Exception.php index 1cd08b8a408..51e52a51516 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Exception.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Exception.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver\OCI8; diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php index 0df45fc1b99..ae0604805fd 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver\OCI8; diff --git a/lib/Doctrine/DBAL/Driver/PDOConnection.php b/lib/Doctrine/DBAL/Driver/PDOConnection.php index 62a214a53d2..18c3efc7346 100644 --- a/lib/Doctrine/DBAL/Driver/PDOConnection.php +++ b/lib/Doctrine/DBAL/Driver/PDOConnection.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver; diff --git a/lib/Doctrine/DBAL/Driver/PDOException.php b/lib/Doctrine/DBAL/Driver/PDOException.php index 25689b66e2c..6104155bbb5 100644 --- a/lib/Doctrine/DBAL/Driver/PDOException.php +++ b/lib/Doctrine/DBAL/Driver/PDOException.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver; diff --git a/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php b/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php index faebcd84268..f082cf99334 100644 --- a/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver\PDOIbm; diff --git a/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php b/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php index 44a9d5b82f6..bcf3b5b47f6 100644 --- a/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver\PDOMySql; diff --git a/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php b/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php index 61edca747e9..484962f8afc 100644 --- a/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver\PDOOracle; diff --git a/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php b/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php index d0946fd4640..a6c7e39f166 100644 --- a/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver\PDOPgSql; diff --git a/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php b/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php index 096f7a2b64f..f19045c3145 100644 --- a/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver\PDOSqlite; diff --git a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Connection.php b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Connection.php index 7ce7e8a76b6..eded44a1411 100644 --- a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Connection.php +++ b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Connection.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver\PDOSqlsrv; diff --git a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php index c27ffe1b209..1ca19bdea4b 100644 --- a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver\PDOSqlsrv; diff --git a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Statement.php b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Statement.php index 3704003425f..6803bb14ed7 100644 --- a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Statement.php +++ b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Statement.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver\PDOSqlsrv; diff --git a/lib/Doctrine/DBAL/Driver/PDOStatement.php b/lib/Doctrine/DBAL/Driver/PDOStatement.php index 7b292639353..ab383c2fb51 100644 --- a/lib/Doctrine/DBAL/Driver/PDOStatement.php +++ b/lib/Doctrine/DBAL/Driver/PDOStatement.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver; diff --git a/lib/Doctrine/DBAL/Driver/PingableConnection.php b/lib/Doctrine/DBAL/Driver/PingableConnection.php index 8c85a82c839..043bb9704ee 100644 --- a/lib/Doctrine/DBAL/Driver/PingableConnection.php +++ b/lib/Doctrine/DBAL/Driver/PingableConnection.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver; diff --git a/lib/Doctrine/DBAL/Driver/ResultStatement.php b/lib/Doctrine/DBAL/Driver/ResultStatement.php index b03862ff6e3..1dea8bf5959 100644 --- a/lib/Doctrine/DBAL/Driver/ResultStatement.php +++ b/lib/Doctrine/DBAL/Driver/ResultStatement.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver; diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php index 1ff0b04b1ba..d8672f394f4 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver\SQLAnywhere; diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php index be60b2f3f26..17ac08c9e82 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver\SQLAnywhere; diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereException.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereException.php index 2a89206d782..061cbd9bdc8 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereException.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereException.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver\SQLAnywhere; diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php index 38d7fa0fdf1..2f34ea8e00f 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver\SQLAnywhere; diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php b/lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php index da0409f24c5..0d74217d04f 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver\SQLSrv; diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/LastInsertId.php b/lib/Doctrine/DBAL/Driver/SQLSrv/LastInsertId.php index 909f1e444be..44a5b9a83f8 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/LastInsertId.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/LastInsertId.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver\SQLSrv; diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php index 6cdd4bca97f..78216ed837c 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver\SQLSrv; diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvException.php b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvException.php index 3223c113608..4eee85f5e66 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvException.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvException.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver\SQLSrv; diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php index e9d35fdb72e..7ab219c437e 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver\SQLSrv; diff --git a/lib/Doctrine/DBAL/Driver/ServerInfoAwareConnection.php b/lib/Doctrine/DBAL/Driver/ServerInfoAwareConnection.php index f47ad0b2701..588ec859720 100644 --- a/lib/Doctrine/DBAL/Driver/ServerInfoAwareConnection.php +++ b/lib/Doctrine/DBAL/Driver/ServerInfoAwareConnection.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver; diff --git a/lib/Doctrine/DBAL/Driver/Statement.php b/lib/Doctrine/DBAL/Driver/Statement.php index 95a73442d7d..39dbc86c451 100644 --- a/lib/Doctrine/DBAL/Driver/Statement.php +++ b/lib/Doctrine/DBAL/Driver/Statement.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Driver; diff --git a/lib/Doctrine/DBAL/DriverManager.php b/lib/Doctrine/DBAL/DriverManager.php index 6f7164e9e0e..a9f27495dc9 100644 --- a/lib/Doctrine/DBAL/DriverManager.php +++ b/lib/Doctrine/DBAL/DriverManager.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL; diff --git a/lib/Doctrine/DBAL/Event/ConnectionEventArgs.php b/lib/Doctrine/DBAL/Event/ConnectionEventArgs.php index fd82638e771..5f8abc1ee59 100644 --- a/lib/Doctrine/DBAL/Event/ConnectionEventArgs.php +++ b/lib/Doctrine/DBAL/Event/ConnectionEventArgs.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Event; diff --git a/lib/Doctrine/DBAL/Event/Listeners/MysqlSessionInit.php b/lib/Doctrine/DBAL/Event/Listeners/MysqlSessionInit.php index 043f7b5ebc9..d65f3f799a1 100644 --- a/lib/Doctrine/DBAL/Event/Listeners/MysqlSessionInit.php +++ b/lib/Doctrine/DBAL/Event/Listeners/MysqlSessionInit.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Event\Listeners; diff --git a/lib/Doctrine/DBAL/Event/Listeners/OracleSessionInit.php b/lib/Doctrine/DBAL/Event/Listeners/OracleSessionInit.php index 851986cc1a4..f024a92190b 100644 --- a/lib/Doctrine/DBAL/Event/Listeners/OracleSessionInit.php +++ b/lib/Doctrine/DBAL/Event/Listeners/OracleSessionInit.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Event\Listeners; diff --git a/lib/Doctrine/DBAL/Event/Listeners/SQLSessionInit.php b/lib/Doctrine/DBAL/Event/Listeners/SQLSessionInit.php index 767c804821f..3eab0e8b58b 100644 --- a/lib/Doctrine/DBAL/Event/Listeners/SQLSessionInit.php +++ b/lib/Doctrine/DBAL/Event/Listeners/SQLSessionInit.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Event\Listeners; diff --git a/lib/Doctrine/DBAL/Event/SchemaAlterTableAddColumnEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaAlterTableAddColumnEventArgs.php index 7cb235ea18b..b4f281f6098 100644 --- a/lib/Doctrine/DBAL/Event/SchemaAlterTableAddColumnEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaAlterTableAddColumnEventArgs.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Event; diff --git a/lib/Doctrine/DBAL/Event/SchemaAlterTableChangeColumnEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaAlterTableChangeColumnEventArgs.php index fdafb45a7a4..55392c67cae 100644 --- a/lib/Doctrine/DBAL/Event/SchemaAlterTableChangeColumnEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaAlterTableChangeColumnEventArgs.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Event; diff --git a/lib/Doctrine/DBAL/Event/SchemaAlterTableEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaAlterTableEventArgs.php index 8e60b2c5f6b..4dcbbe0963d 100644 --- a/lib/Doctrine/DBAL/Event/SchemaAlterTableEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaAlterTableEventArgs.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Event; diff --git a/lib/Doctrine/DBAL/Event/SchemaAlterTableRemoveColumnEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaAlterTableRemoveColumnEventArgs.php index 52413ce9173..2a6aa93b2dd 100644 --- a/lib/Doctrine/DBAL/Event/SchemaAlterTableRemoveColumnEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaAlterTableRemoveColumnEventArgs.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Event; diff --git a/lib/Doctrine/DBAL/Event/SchemaAlterTableRenameColumnEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaAlterTableRenameColumnEventArgs.php index 697660442a5..f0d0500c568 100644 --- a/lib/Doctrine/DBAL/Event/SchemaAlterTableRenameColumnEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaAlterTableRenameColumnEventArgs.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Event; diff --git a/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php index 14bb8df73b3..192a7400aef 100644 --- a/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Event; diff --git a/lib/Doctrine/DBAL/Event/SchemaCreateTableColumnEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaCreateTableColumnEventArgs.php index 824e243b135..e3f414d575c 100644 --- a/lib/Doctrine/DBAL/Event/SchemaCreateTableColumnEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaCreateTableColumnEventArgs.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Event; diff --git a/lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php index 7993b3adb15..0e20c51aed8 100644 --- a/lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Event; diff --git a/lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php index b3c90422121..b114ce5d0d9 100644 --- a/lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Event; diff --git a/lib/Doctrine/DBAL/Event/SchemaEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaEventArgs.php index db12e57ad3b..4d19b1c0b4f 100644 --- a/lib/Doctrine/DBAL/Event/SchemaEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaEventArgs.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Event; diff --git a/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php index 3fd1d4bf7da..2095a6a6c27 100644 --- a/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Event; diff --git a/lib/Doctrine/DBAL/Events.php b/lib/Doctrine/DBAL/Events.php index 0d31504c70a..9a8c4faa244 100644 --- a/lib/Doctrine/DBAL/Events.php +++ b/lib/Doctrine/DBAL/Events.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL; diff --git a/lib/Doctrine/DBAL/Exception/ConnectionException.php b/lib/Doctrine/DBAL/Exception/ConnectionException.php index 8d976dcb325..134ee24db4e 100644 --- a/lib/Doctrine/DBAL/Exception/ConnectionException.php +++ b/lib/Doctrine/DBAL/Exception/ConnectionException.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Exception; diff --git a/lib/Doctrine/DBAL/Exception/ConstraintViolationException.php b/lib/Doctrine/DBAL/Exception/ConstraintViolationException.php index 8dd1cb69452..9168edd5cd7 100644 --- a/lib/Doctrine/DBAL/Exception/ConstraintViolationException.php +++ b/lib/Doctrine/DBAL/Exception/ConstraintViolationException.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Exception; diff --git a/lib/Doctrine/DBAL/Exception/DatabaseObjectExistsException.php b/lib/Doctrine/DBAL/Exception/DatabaseObjectExistsException.php index 279aae9a5a3..2d1be341331 100644 --- a/lib/Doctrine/DBAL/Exception/DatabaseObjectExistsException.php +++ b/lib/Doctrine/DBAL/Exception/DatabaseObjectExistsException.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Exception; diff --git a/lib/Doctrine/DBAL/Exception/DatabaseObjectNotFoundException.php b/lib/Doctrine/DBAL/Exception/DatabaseObjectNotFoundException.php index fbca22d9942..07473043f00 100644 --- a/lib/Doctrine/DBAL/Exception/DatabaseObjectNotFoundException.php +++ b/lib/Doctrine/DBAL/Exception/DatabaseObjectNotFoundException.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Exception; diff --git a/lib/Doctrine/DBAL/Exception/DeadlockException.php b/lib/Doctrine/DBAL/Exception/DeadlockException.php index 05af11e4b6f..042537634ac 100644 --- a/lib/Doctrine/DBAL/Exception/DeadlockException.php +++ b/lib/Doctrine/DBAL/Exception/DeadlockException.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Exception; diff --git a/lib/Doctrine/DBAL/Exception/DriverException.php b/lib/Doctrine/DBAL/Exception/DriverException.php index 08b7935a0c0..42328cc62fd 100644 --- a/lib/Doctrine/DBAL/Exception/DriverException.php +++ b/lib/Doctrine/DBAL/Exception/DriverException.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Exception; diff --git a/lib/Doctrine/DBAL/Exception/ForeignKeyConstraintViolationException.php b/lib/Doctrine/DBAL/Exception/ForeignKeyConstraintViolationException.php index d244855a16d..5cab4d982b5 100644 --- a/lib/Doctrine/DBAL/Exception/ForeignKeyConstraintViolationException.php +++ b/lib/Doctrine/DBAL/Exception/ForeignKeyConstraintViolationException.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Exception; diff --git a/lib/Doctrine/DBAL/Exception/InvalidArgumentException.php b/lib/Doctrine/DBAL/Exception/InvalidArgumentException.php index 5b811227bdd..be5d061b3e5 100644 --- a/lib/Doctrine/DBAL/Exception/InvalidArgumentException.php +++ b/lib/Doctrine/DBAL/Exception/InvalidArgumentException.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Exception; diff --git a/lib/Doctrine/DBAL/Exception/InvalidFieldNameException.php b/lib/Doctrine/DBAL/Exception/InvalidFieldNameException.php index e0b1013fe4c..81db4dff3f4 100644 --- a/lib/Doctrine/DBAL/Exception/InvalidFieldNameException.php +++ b/lib/Doctrine/DBAL/Exception/InvalidFieldNameException.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Exception; diff --git a/lib/Doctrine/DBAL/Exception/LockWaitTimeoutException.php b/lib/Doctrine/DBAL/Exception/LockWaitTimeoutException.php index 915e11b8b93..2b805c2ce03 100644 --- a/lib/Doctrine/DBAL/Exception/LockWaitTimeoutException.php +++ b/lib/Doctrine/DBAL/Exception/LockWaitTimeoutException.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Exception; diff --git a/lib/Doctrine/DBAL/Exception/NonUniqueFieldNameException.php b/lib/Doctrine/DBAL/Exception/NonUniqueFieldNameException.php index 7b214e3b946..098bfeaf9e9 100644 --- a/lib/Doctrine/DBAL/Exception/NonUniqueFieldNameException.php +++ b/lib/Doctrine/DBAL/Exception/NonUniqueFieldNameException.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Exception; diff --git a/lib/Doctrine/DBAL/Exception/NotNullConstraintViolationException.php b/lib/Doctrine/DBAL/Exception/NotNullConstraintViolationException.php index a1f45b92a44..7a7909d4f45 100644 --- a/lib/Doctrine/DBAL/Exception/NotNullConstraintViolationException.php +++ b/lib/Doctrine/DBAL/Exception/NotNullConstraintViolationException.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Exception; diff --git a/lib/Doctrine/DBAL/Exception/ReadOnlyException.php b/lib/Doctrine/DBAL/Exception/ReadOnlyException.php index 0345e88fce0..8920a102b06 100644 --- a/lib/Doctrine/DBAL/Exception/ReadOnlyException.php +++ b/lib/Doctrine/DBAL/Exception/ReadOnlyException.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Exception; diff --git a/lib/Doctrine/DBAL/Exception/RetryableException.php b/lib/Doctrine/DBAL/Exception/RetryableException.php index 6b019dcc472..54335734118 100644 --- a/lib/Doctrine/DBAL/Exception/RetryableException.php +++ b/lib/Doctrine/DBAL/Exception/RetryableException.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Exception; diff --git a/lib/Doctrine/DBAL/Exception/ServerException.php b/lib/Doctrine/DBAL/Exception/ServerException.php index 36460ee0d64..310d8c7bc5a 100644 --- a/lib/Doctrine/DBAL/Exception/ServerException.php +++ b/lib/Doctrine/DBAL/Exception/ServerException.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Exception; diff --git a/lib/Doctrine/DBAL/Exception/SyntaxErrorException.php b/lib/Doctrine/DBAL/Exception/SyntaxErrorException.php index 97b8fd25f3e..9e41c891f2b 100644 --- a/lib/Doctrine/DBAL/Exception/SyntaxErrorException.php +++ b/lib/Doctrine/DBAL/Exception/SyntaxErrorException.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Exception; diff --git a/lib/Doctrine/DBAL/Exception/TableExistsException.php b/lib/Doctrine/DBAL/Exception/TableExistsException.php index c90bfb476c4..1bfef855a5b 100644 --- a/lib/Doctrine/DBAL/Exception/TableExistsException.php +++ b/lib/Doctrine/DBAL/Exception/TableExistsException.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Exception; diff --git a/lib/Doctrine/DBAL/Exception/TableNotFoundException.php b/lib/Doctrine/DBAL/Exception/TableNotFoundException.php index 90793b909de..ea6a6d14a2e 100644 --- a/lib/Doctrine/DBAL/Exception/TableNotFoundException.php +++ b/lib/Doctrine/DBAL/Exception/TableNotFoundException.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Exception; diff --git a/lib/Doctrine/DBAL/Exception/UniqueConstraintViolationException.php b/lib/Doctrine/DBAL/Exception/UniqueConstraintViolationException.php index cd117738dd9..9f235cad377 100644 --- a/lib/Doctrine/DBAL/Exception/UniqueConstraintViolationException.php +++ b/lib/Doctrine/DBAL/Exception/UniqueConstraintViolationException.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Exception; diff --git a/lib/Doctrine/DBAL/Id/TableGenerator.php b/lib/Doctrine/DBAL/Id/TableGenerator.php index 068eb6056bf..4c21e5a1dbb 100644 --- a/lib/Doctrine/DBAL/Id/TableGenerator.php +++ b/lib/Doctrine/DBAL/Id/TableGenerator.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Id; diff --git a/lib/Doctrine/DBAL/Id/TableGeneratorSchemaVisitor.php b/lib/Doctrine/DBAL/Id/TableGeneratorSchemaVisitor.php index 619a92f7b4d..b92d421e6d7 100644 --- a/lib/Doctrine/DBAL/Id/TableGeneratorSchemaVisitor.php +++ b/lib/Doctrine/DBAL/Id/TableGeneratorSchemaVisitor.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Id; diff --git a/lib/Doctrine/DBAL/LockMode.php b/lib/Doctrine/DBAL/LockMode.php index 8d78180ede2..5b0c99c507e 100644 --- a/lib/Doctrine/DBAL/LockMode.php +++ b/lib/Doctrine/DBAL/LockMode.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL; diff --git a/lib/Doctrine/DBAL/Logging/DebugStack.php b/lib/Doctrine/DBAL/Logging/DebugStack.php index 4cffaa67fce..a283d7505e6 100644 --- a/lib/Doctrine/DBAL/Logging/DebugStack.php +++ b/lib/Doctrine/DBAL/Logging/DebugStack.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Logging; diff --git a/lib/Doctrine/DBAL/Logging/EchoSQLLogger.php b/lib/Doctrine/DBAL/Logging/EchoSQLLogger.php index a6c1ae5ea0b..c0f76fc1df2 100644 --- a/lib/Doctrine/DBAL/Logging/EchoSQLLogger.php +++ b/lib/Doctrine/DBAL/Logging/EchoSQLLogger.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Logging; diff --git a/lib/Doctrine/DBAL/Logging/LoggerChain.php b/lib/Doctrine/DBAL/Logging/LoggerChain.php index fee05a4a004..fa0fc8a1bda 100644 --- a/lib/Doctrine/DBAL/Logging/LoggerChain.php +++ b/lib/Doctrine/DBAL/Logging/LoggerChain.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Logging; diff --git a/lib/Doctrine/DBAL/Logging/SQLLogger.php b/lib/Doctrine/DBAL/Logging/SQLLogger.php index 52491e50fe6..b7774327d7f 100644 --- a/lib/Doctrine/DBAL/Logging/SQLLogger.php +++ b/lib/Doctrine/DBAL/Logging/SQLLogger.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Logging; diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index a9dbebe48c0..ecec475056f 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms; diff --git a/lib/Doctrine/DBAL/Platforms/DB2Platform.php b/lib/Doctrine/DBAL/Platforms/DB2Platform.php index b83c8f1dc7e..11fd6ae0176 100644 --- a/lib/Doctrine/DBAL/Platforms/DB2Platform.php +++ b/lib/Doctrine/DBAL/Platforms/DB2Platform.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms; diff --git a/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php b/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php index d8a4d092019..8e6968b1146 100644 --- a/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms; diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/DB2Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/DB2Keywords.php index 884cc8ec775..0dbceb3d537 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/DB2Keywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/DB2Keywords.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms\Keywords; diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/DrizzleKeywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/DrizzleKeywords.php index 46c8b246339..0c121f784a7 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/DrizzleKeywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/DrizzleKeywords.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms\Keywords; diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/KeywordList.php b/lib/Doctrine/DBAL/Platforms/Keywords/KeywordList.php index e8933a3860d..66b69f32331 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/KeywordList.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/KeywordList.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms\Keywords; diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/MariaDb102Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/MariaDb102Keywords.php index 3fb66934f86..6a9f19ed578 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/MariaDb102Keywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/MariaDb102Keywords.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms\Keywords; diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/MsSQLKeywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/MsSQLKeywords.php index 9c8f614993a..239d047de77 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/MsSQLKeywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/MsSQLKeywords.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms\Keywords; diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/MySQL57Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/MySQL57Keywords.php index ef7c389ed3a..44a04e5d94a 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/MySQL57Keywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/MySQL57Keywords.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms\Keywords; diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/MySQL80Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/MySQL80Keywords.php index 232b85cdd32..37616b0d457 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/MySQL80Keywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/MySQL80Keywords.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms\Keywords; diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/MySQLKeywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/MySQLKeywords.php index 8ba9b4d74ac..b6fd123b39d 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/MySQLKeywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/MySQLKeywords.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms\Keywords; diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/OracleKeywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/OracleKeywords.php index 4914d2e9db4..cc1140a20d2 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/OracleKeywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/OracleKeywords.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms\Keywords; diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL91Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL91Keywords.php index ecbd0a46db0..3fe676e0bb4 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL91Keywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL91Keywords.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms\Keywords; diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL92Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL92Keywords.php index d6c6a9d3f77..5c20c95ef21 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL92Keywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL92Keywords.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms\Keywords; diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL94Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL94Keywords.php index 8daa59539a4..4d7f1e25b02 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL94Keywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL94Keywords.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms\Keywords; diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQLKeywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQLKeywords.php index 571d6f4e818..146e3a1ae10 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQLKeywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQLKeywords.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms\Keywords; diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/ReservedKeywordsValidator.php b/lib/Doctrine/DBAL/Platforms/Keywords/ReservedKeywordsValidator.php index c6a5954e274..b8060967431 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/ReservedKeywordsValidator.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/ReservedKeywordsValidator.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms\Keywords; diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/SQLAnywhere11Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/SQLAnywhere11Keywords.php index 6e67ee2e6fa..6e769aabf20 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/SQLAnywhere11Keywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/SQLAnywhere11Keywords.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms\Keywords; diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/SQLAnywhere12Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/SQLAnywhere12Keywords.php index ebc38bf8440..a36608bf28d 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/SQLAnywhere12Keywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/SQLAnywhere12Keywords.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms\Keywords; diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/SQLAnywhere16Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/SQLAnywhere16Keywords.php index 1ec984e789c..44efb5ae8aa 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/SQLAnywhere16Keywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/SQLAnywhere16Keywords.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms\Keywords; diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/SQLAnywhereKeywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/SQLAnywhereKeywords.php index 9d5ab5db870..125f06d52d0 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/SQLAnywhereKeywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/SQLAnywhereKeywords.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms\Keywords; diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/SQLServer2005Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/SQLServer2005Keywords.php index 02b4656208d..573280b0139 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/SQLServer2005Keywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/SQLServer2005Keywords.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms\Keywords; diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/SQLServer2008Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/SQLServer2008Keywords.php index b5c38610afa..acd19645e70 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/SQLServer2008Keywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/SQLServer2008Keywords.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms\Keywords; diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/SQLServer2012Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/SQLServer2012Keywords.php index bf621bff8af..8334e3d3053 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/SQLServer2012Keywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/SQLServer2012Keywords.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms\Keywords; diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/SQLServerKeywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/SQLServerKeywords.php index 5b65cbc8721..d7287fbf991 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/SQLServerKeywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/SQLServerKeywords.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms\Keywords; diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/SQLiteKeywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/SQLiteKeywords.php index f240aa64469..5d34e0c9111 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/SQLiteKeywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/SQLiteKeywords.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms\Keywords; diff --git a/lib/Doctrine/DBAL/Platforms/MariaDb1027Platform.php b/lib/Doctrine/DBAL/Platforms/MariaDb1027Platform.php index 4c1f6b3f8b0..6aba377674e 100644 --- a/lib/Doctrine/DBAL/Platforms/MariaDb1027Platform.php +++ b/lib/Doctrine/DBAL/Platforms/MariaDb1027Platform.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms; diff --git a/lib/Doctrine/DBAL/Platforms/MySQL57Platform.php b/lib/Doctrine/DBAL/Platforms/MySQL57Platform.php index 5b2328b2e65..e2c6fc3d937 100644 --- a/lib/Doctrine/DBAL/Platforms/MySQL57Platform.php +++ b/lib/Doctrine/DBAL/Platforms/MySQL57Platform.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms; diff --git a/lib/Doctrine/DBAL/Platforms/MySQL80Platform.php b/lib/Doctrine/DBAL/Platforms/MySQL80Platform.php index e0727237b88..49dd5761e6f 100644 --- a/lib/Doctrine/DBAL/Platforms/MySQL80Platform.php +++ b/lib/Doctrine/DBAL/Platforms/MySQL80Platform.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms; diff --git a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php index a16bfe79da0..149d2eaef3c 100644 --- a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms; diff --git a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php index 32b12a0bc1f..8e1358606ef 100644 --- a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms; diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSQL91Platform.php b/lib/Doctrine/DBAL/Platforms/PostgreSQL91Platform.php index 94d810483d4..9ac1ad9d9e5 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSQL91Platform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSQL91Platform.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms; diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSQL92Platform.php b/lib/Doctrine/DBAL/Platforms/PostgreSQL92Platform.php index 052b75fa4af..f9deedd418d 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSQL92Platform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSQL92Platform.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms; diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSQL94Platform.php b/lib/Doctrine/DBAL/Platforms/PostgreSQL94Platform.php index 68700b1962d..d0bc3fd8183 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSQL94Platform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSQL94Platform.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms; diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php index 04d431caf3d..ea8fd64a8e7 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms; diff --git a/lib/Doctrine/DBAL/Platforms/SQLAnywhere11Platform.php b/lib/Doctrine/DBAL/Platforms/SQLAnywhere11Platform.php index e2773696072..875841a18d5 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLAnywhere11Platform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLAnywhere11Platform.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms; diff --git a/lib/Doctrine/DBAL/Platforms/SQLAnywhere12Platform.php b/lib/Doctrine/DBAL/Platforms/SQLAnywhere12Platform.php index 1b52bfee56e..bf8e232bfe1 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLAnywhere12Platform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLAnywhere12Platform.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms; diff --git a/lib/Doctrine/DBAL/Platforms/SQLAnywhere16Platform.php b/lib/Doctrine/DBAL/Platforms/SQLAnywhere16Platform.php index 1d59e2c0043..b744d437672 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLAnywhere16Platform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLAnywhere16Platform.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms; diff --git a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php index 79a6e483ab9..affbe01a889 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms; diff --git a/lib/Doctrine/DBAL/Platforms/SQLAzurePlatform.php b/lib/Doctrine/DBAL/Platforms/SQLAzurePlatform.php index 71829cd0e0d..d04a530c80e 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLAzurePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLAzurePlatform.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms; diff --git a/lib/Doctrine/DBAL/Platforms/SQLServer2005Platform.php b/lib/Doctrine/DBAL/Platforms/SQLServer2005Platform.php index af42f516641..1026a934f00 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServer2005Platform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServer2005Platform.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms; diff --git a/lib/Doctrine/DBAL/Platforms/SQLServer2008Platform.php b/lib/Doctrine/DBAL/Platforms/SQLServer2008Platform.php index b9a672e6c4b..41d81673afd 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServer2008Platform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServer2008Platform.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms; diff --git a/lib/Doctrine/DBAL/Platforms/SQLServer2012Platform.php b/lib/Doctrine/DBAL/Platforms/SQLServer2012Platform.php index c95d7b05f5d..d2d81f5a70e 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServer2012Platform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServer2012Platform.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms; diff --git a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php index 48cbcc6c1c8..92e45be2de2 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms; diff --git a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php index 3c99e0f0853..3697e116b96 100644 --- a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Platforms; diff --git a/lib/Doctrine/DBAL/Portability/Connection.php b/lib/Doctrine/DBAL/Portability/Connection.php index 723a333bb18..416087842b2 100644 --- a/lib/Doctrine/DBAL/Portability/Connection.php +++ b/lib/Doctrine/DBAL/Portability/Connection.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Portability; diff --git a/lib/Doctrine/DBAL/Portability/Statement.php b/lib/Doctrine/DBAL/Portability/Statement.php index d8826f2d2c6..f2dc61d8a24 100644 --- a/lib/Doctrine/DBAL/Portability/Statement.php +++ b/lib/Doctrine/DBAL/Portability/Statement.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Portability; diff --git a/lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php b/lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php index 00802a44ee8..23db991cecd 100644 --- a/lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php +++ b/lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Query\Expression; diff --git a/lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php b/lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php index 1ee72484775..b9e8559f000 100644 --- a/lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php +++ b/lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Query\Expression; diff --git a/lib/Doctrine/DBAL/Query/QueryBuilder.php b/lib/Doctrine/DBAL/Query/QueryBuilder.php index 40c133abe20..dc54ac06e1d 100644 --- a/lib/Doctrine/DBAL/Query/QueryBuilder.php +++ b/lib/Doctrine/DBAL/Query/QueryBuilder.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Query; diff --git a/lib/Doctrine/DBAL/Query/QueryException.php b/lib/Doctrine/DBAL/Query/QueryException.php index 45a3d55f650..ef12dca1a62 100644 --- a/lib/Doctrine/DBAL/Query/QueryException.php +++ b/lib/Doctrine/DBAL/Query/QueryException.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Query; diff --git a/lib/Doctrine/DBAL/SQLParserUtils.php b/lib/Doctrine/DBAL/SQLParserUtils.php index c24607f0e83..22883a2b9f0 100644 --- a/lib/Doctrine/DBAL/SQLParserUtils.php +++ b/lib/Doctrine/DBAL/SQLParserUtils.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL; diff --git a/lib/Doctrine/DBAL/SQLParserUtilsException.php b/lib/Doctrine/DBAL/SQLParserUtilsException.php index e7c15c53e84..4d17d226757 100644 --- a/lib/Doctrine/DBAL/SQLParserUtilsException.php +++ b/lib/Doctrine/DBAL/SQLParserUtilsException.php @@ -1,23 +1,4 @@ . - */ namespace Doctrine\DBAL; diff --git a/lib/Doctrine/DBAL/Schema/AbstractAsset.php b/lib/Doctrine/DBAL/Schema/AbstractAsset.php index 86f353cb993..551192d9b05 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractAsset.php +++ b/lib/Doctrine/DBAL/Schema/AbstractAsset.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema; diff --git a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php index f9f7cff7af6..d160d6c6b63 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema; diff --git a/lib/Doctrine/DBAL/Schema/Column.php b/lib/Doctrine/DBAL/Schema/Column.php index eead5e6aa82..862240c6e7d 100644 --- a/lib/Doctrine/DBAL/Schema/Column.php +++ b/lib/Doctrine/DBAL/Schema/Column.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema; diff --git a/lib/Doctrine/DBAL/Schema/ColumnDiff.php b/lib/Doctrine/DBAL/Schema/ColumnDiff.php index 65517d75cb5..196f83e3634 100644 --- a/lib/Doctrine/DBAL/Schema/ColumnDiff.php +++ b/lib/Doctrine/DBAL/Schema/ColumnDiff.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema; diff --git a/lib/Doctrine/DBAL/Schema/Comparator.php b/lib/Doctrine/DBAL/Schema/Comparator.php index 63389cd42d0..4421b05db9b 100644 --- a/lib/Doctrine/DBAL/Schema/Comparator.php +++ b/lib/Doctrine/DBAL/Schema/Comparator.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema; diff --git a/lib/Doctrine/DBAL/Schema/Constraint.php b/lib/Doctrine/DBAL/Schema/Constraint.php index 2e68a771019..8ca3b14c16b 100644 --- a/lib/Doctrine/DBAL/Schema/Constraint.php +++ b/lib/Doctrine/DBAL/Schema/Constraint.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema; diff --git a/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php b/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php index c97685b5d0e..aa1f1207bb1 100644 --- a/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema; diff --git a/lib/Doctrine/DBAL/Schema/DrizzleSchemaManager.php b/lib/Doctrine/DBAL/Schema/DrizzleSchemaManager.php index a10eb3da066..57ed4d3b687 100644 --- a/lib/Doctrine/DBAL/Schema/DrizzleSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/DrizzleSchemaManager.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema; diff --git a/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php b/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php index a50b7a0b5c5..962fcb8a0f1 100644 --- a/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php +++ b/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema; diff --git a/lib/Doctrine/DBAL/Schema/Identifier.php b/lib/Doctrine/DBAL/Schema/Identifier.php index babe583e43a..79686448c0b 100644 --- a/lib/Doctrine/DBAL/Schema/Identifier.php +++ b/lib/Doctrine/DBAL/Schema/Identifier.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema; diff --git a/lib/Doctrine/DBAL/Schema/Index.php b/lib/Doctrine/DBAL/Schema/Index.php index 78a2322c8d0..377127d4919 100644 --- a/lib/Doctrine/DBAL/Schema/Index.php +++ b/lib/Doctrine/DBAL/Schema/Index.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema; diff --git a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php index a56a6af86b2..1989872372a 100644 --- a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema; diff --git a/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php b/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php index c016db1a941..09dd845a887 100644 --- a/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema; diff --git a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php index 621fdc2454c..10e960c1fff 100644 --- a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema; diff --git a/lib/Doctrine/DBAL/Schema/SQLAnywhereSchemaManager.php b/lib/Doctrine/DBAL/Schema/SQLAnywhereSchemaManager.php index 84a04a34883..7fbbc09178b 100644 --- a/lib/Doctrine/DBAL/Schema/SQLAnywhereSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SQLAnywhereSchemaManager.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema; diff --git a/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php b/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php index f5383fb7f73..63b113bbe84 100644 --- a/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema; diff --git a/lib/Doctrine/DBAL/Schema/Schema.php b/lib/Doctrine/DBAL/Schema/Schema.php index cf5ed4054cb..8de3f95daba 100644 --- a/lib/Doctrine/DBAL/Schema/Schema.php +++ b/lib/Doctrine/DBAL/Schema/Schema.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema; diff --git a/lib/Doctrine/DBAL/Schema/SchemaConfig.php b/lib/Doctrine/DBAL/Schema/SchemaConfig.php index c8c7673bae2..e0b09050e1d 100644 --- a/lib/Doctrine/DBAL/Schema/SchemaConfig.php +++ b/lib/Doctrine/DBAL/Schema/SchemaConfig.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema; diff --git a/lib/Doctrine/DBAL/Schema/SchemaDiff.php b/lib/Doctrine/DBAL/Schema/SchemaDiff.php index ec9ccba933d..12ef74dabe4 100644 --- a/lib/Doctrine/DBAL/Schema/SchemaDiff.php +++ b/lib/Doctrine/DBAL/Schema/SchemaDiff.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema; diff --git a/lib/Doctrine/DBAL/Schema/SchemaException.php b/lib/Doctrine/DBAL/Schema/SchemaException.php index 7285d81cbf0..93966fe8b5c 100644 --- a/lib/Doctrine/DBAL/Schema/SchemaException.php +++ b/lib/Doctrine/DBAL/Schema/SchemaException.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema; diff --git a/lib/Doctrine/DBAL/Schema/Sequence.php b/lib/Doctrine/DBAL/Schema/Sequence.php index 607b76553e7..339bf81d237 100644 --- a/lib/Doctrine/DBAL/Schema/Sequence.php +++ b/lib/Doctrine/DBAL/Schema/Sequence.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema; diff --git a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php index dbe0cc2d563..74ade6ee854 100644 --- a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema; diff --git a/lib/Doctrine/DBAL/Schema/Synchronizer/AbstractSchemaSynchronizer.php b/lib/Doctrine/DBAL/Schema/Synchronizer/AbstractSchemaSynchronizer.php index 3158df47de1..1515304dc32 100644 --- a/lib/Doctrine/DBAL/Schema/Synchronizer/AbstractSchemaSynchronizer.php +++ b/lib/Doctrine/DBAL/Schema/Synchronizer/AbstractSchemaSynchronizer.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema\Synchronizer; diff --git a/lib/Doctrine/DBAL/Schema/Synchronizer/SchemaSynchronizer.php b/lib/Doctrine/DBAL/Schema/Synchronizer/SchemaSynchronizer.php index b65efbbb99f..d2913ab42c9 100644 --- a/lib/Doctrine/DBAL/Schema/Synchronizer/SchemaSynchronizer.php +++ b/lib/Doctrine/DBAL/Schema/Synchronizer/SchemaSynchronizer.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema\Synchronizer; diff --git a/lib/Doctrine/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizer.php b/lib/Doctrine/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizer.php index f22607e6b96..9e25c36ed9d 100644 --- a/lib/Doctrine/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizer.php +++ b/lib/Doctrine/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizer.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema\Synchronizer; diff --git a/lib/Doctrine/DBAL/Schema/Table.php b/lib/Doctrine/DBAL/Schema/Table.php index bc7f8197908..b6db40d75fe 100644 --- a/lib/Doctrine/DBAL/Schema/Table.php +++ b/lib/Doctrine/DBAL/Schema/Table.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema; diff --git a/lib/Doctrine/DBAL/Schema/TableDiff.php b/lib/Doctrine/DBAL/Schema/TableDiff.php index a50c6b40628..914f6caa1c4 100644 --- a/lib/Doctrine/DBAL/Schema/TableDiff.php +++ b/lib/Doctrine/DBAL/Schema/TableDiff.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema; diff --git a/lib/Doctrine/DBAL/Schema/View.php b/lib/Doctrine/DBAL/Schema/View.php index 0ef7d305bbb..9d54cd1ff68 100644 --- a/lib/Doctrine/DBAL/Schema/View.php +++ b/lib/Doctrine/DBAL/Schema/View.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema; diff --git a/lib/Doctrine/DBAL/Schema/Visitor/AbstractVisitor.php b/lib/Doctrine/DBAL/Schema/Visitor/AbstractVisitor.php index 7bf5b2fec32..ec5a41ddebc 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/AbstractVisitor.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/AbstractVisitor.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema\Visitor; diff --git a/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php b/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php index 0d92edb0998..70328e6d45b 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema\Visitor; diff --git a/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php b/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php index abd183d5ae5..b5f0e0ce934 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema\Visitor; diff --git a/lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php b/lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php index daec58ef064..56908226350 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema\Visitor; diff --git a/lib/Doctrine/DBAL/Schema/Visitor/NamespaceVisitor.php b/lib/Doctrine/DBAL/Schema/Visitor/NamespaceVisitor.php index da7b1edbcaa..b04935982c3 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/NamespaceVisitor.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/NamespaceVisitor.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema\Visitor; diff --git a/lib/Doctrine/DBAL/Schema/Visitor/RemoveNamespacedAssets.php b/lib/Doctrine/DBAL/Schema/Visitor/RemoveNamespacedAssets.php index e328d071cde..5f3c8645c07 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/RemoveNamespacedAssets.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/RemoveNamespacedAssets.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema\Visitor; diff --git a/lib/Doctrine/DBAL/Schema/Visitor/SchemaDiffVisitor.php b/lib/Doctrine/DBAL/Schema/Visitor/SchemaDiffVisitor.php index bde4453b357..69bb23ecf59 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/SchemaDiffVisitor.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/SchemaDiffVisitor.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema\Visitor; diff --git a/lib/Doctrine/DBAL/Schema/Visitor/Visitor.php b/lib/Doctrine/DBAL/Schema/Visitor/Visitor.php index 656f0e20c6f..e3dbed7839a 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/Visitor.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/Visitor.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Schema\Visitor; diff --git a/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php b/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php index e307d5ebc4d..90bfd76040f 100644 --- a/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php +++ b/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Sharding; diff --git a/lib/Doctrine/DBAL/Sharding/PoolingShardManager.php b/lib/Doctrine/DBAL/Sharding/PoolingShardManager.php index 7f9a33fc5b2..dc606a8e616 100644 --- a/lib/Doctrine/DBAL/Sharding/PoolingShardManager.php +++ b/lib/Doctrine/DBAL/Sharding/PoolingShardManager.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Sharding; diff --git a/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php b/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php index 2b700b38a4a..6272d476075 100644 --- a/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php +++ b/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Sharding\SQLAzure; diff --git a/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureShardManager.php b/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureShardManager.php index 255ca8b418e..0882a2d78bd 100644 --- a/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureShardManager.php +++ b/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureShardManager.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Sharding\SQLAzure; diff --git a/lib/Doctrine/DBAL/Sharding/SQLAzure/Schema/MultiTenantVisitor.php b/lib/Doctrine/DBAL/Sharding/SQLAzure/Schema/MultiTenantVisitor.php index 92851d00182..a53eee738b2 100644 --- a/lib/Doctrine/DBAL/Sharding/SQLAzure/Schema/MultiTenantVisitor.php +++ b/lib/Doctrine/DBAL/Sharding/SQLAzure/Schema/MultiTenantVisitor.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Sharding\SQLAzure\Schema; diff --git a/lib/Doctrine/DBAL/Sharding/ShardChoser/MultiTenantShardChoser.php b/lib/Doctrine/DBAL/Sharding/ShardChoser/MultiTenantShardChoser.php index f1d51b8c957..9340ace68d9 100644 --- a/lib/Doctrine/DBAL/Sharding/ShardChoser/MultiTenantShardChoser.php +++ b/lib/Doctrine/DBAL/Sharding/ShardChoser/MultiTenantShardChoser.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Sharding\ShardChoser; diff --git a/lib/Doctrine/DBAL/Sharding/ShardChoser/ShardChoser.php b/lib/Doctrine/DBAL/Sharding/ShardChoser/ShardChoser.php index 8bbf799b892..e4c5470b21b 100644 --- a/lib/Doctrine/DBAL/Sharding/ShardChoser/ShardChoser.php +++ b/lib/Doctrine/DBAL/Sharding/ShardChoser/ShardChoser.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Sharding\ShardChoser; diff --git a/lib/Doctrine/DBAL/Sharding/ShardManager.php b/lib/Doctrine/DBAL/Sharding/ShardManager.php index 98c8351d7c2..76b743edfa7 100644 --- a/lib/Doctrine/DBAL/Sharding/ShardManager.php +++ b/lib/Doctrine/DBAL/Sharding/ShardManager.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Sharding; diff --git a/lib/Doctrine/DBAL/Sharding/ShardingException.php b/lib/Doctrine/DBAL/Sharding/ShardingException.php index aa14d32af30..9951a60090a 100644 --- a/lib/Doctrine/DBAL/Sharding/ShardingException.php +++ b/lib/Doctrine/DBAL/Sharding/ShardingException.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Sharding; diff --git a/lib/Doctrine/DBAL/Statement.php b/lib/Doctrine/DBAL/Statement.php index fb1da7927bd..14983384b83 100644 --- a/lib/Doctrine/DBAL/Statement.php +++ b/lib/Doctrine/DBAL/Statement.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL; diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php index 005cf7ed5a6..d9a88da73d2 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Tools\Console\Command; diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php index 83587bdb544..1647df07f62 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Tools\Console\Command; diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php index f65b0de0f7e..36f7f4b6aec 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Tools\Console\Command; diff --git a/lib/Doctrine/DBAL/Tools/Console/ConsoleRunner.php b/lib/Doctrine/DBAL/Tools/Console/ConsoleRunner.php index 61412a7cc5a..0642594ee3e 100644 --- a/lib/Doctrine/DBAL/Tools/Console/ConsoleRunner.php +++ b/lib/Doctrine/DBAL/Tools/Console/ConsoleRunner.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Tools\Console; diff --git a/lib/Doctrine/DBAL/Tools/Console/Helper/ConnectionHelper.php b/lib/Doctrine/DBAL/Tools/Console/Helper/ConnectionHelper.php index 1331c2baea4..f85162139a8 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Helper/ConnectionHelper.php +++ b/lib/Doctrine/DBAL/Tools/Console/Helper/ConnectionHelper.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Tools\Console\Helper; diff --git a/lib/Doctrine/DBAL/Types/ArrayType.php b/lib/Doctrine/DBAL/Types/ArrayType.php index 16d48aa1d7f..994d52a4a6b 100644 --- a/lib/Doctrine/DBAL/Types/ArrayType.php +++ b/lib/Doctrine/DBAL/Types/ArrayType.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Types; diff --git a/lib/Doctrine/DBAL/Types/BigIntType.php b/lib/Doctrine/DBAL/Types/BigIntType.php index 9a2b42953ad..d579af34ad5 100644 --- a/lib/Doctrine/DBAL/Types/BigIntType.php +++ b/lib/Doctrine/DBAL/Types/BigIntType.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Types; diff --git a/lib/Doctrine/DBAL/Types/BinaryType.php b/lib/Doctrine/DBAL/Types/BinaryType.php index 57f0bbf0f8f..418ed2ff0cc 100644 --- a/lib/Doctrine/DBAL/Types/BinaryType.php +++ b/lib/Doctrine/DBAL/Types/BinaryType.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Types; diff --git a/lib/Doctrine/DBAL/Types/BlobType.php b/lib/Doctrine/DBAL/Types/BlobType.php index 84ee48af83e..dafe9917dc4 100644 --- a/lib/Doctrine/DBAL/Types/BlobType.php +++ b/lib/Doctrine/DBAL/Types/BlobType.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Types; diff --git a/lib/Doctrine/DBAL/Types/BooleanType.php b/lib/Doctrine/DBAL/Types/BooleanType.php index 748f7f52942..77dc9eba617 100644 --- a/lib/Doctrine/DBAL/Types/BooleanType.php +++ b/lib/Doctrine/DBAL/Types/BooleanType.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Types; diff --git a/lib/Doctrine/DBAL/Types/ConversionException.php b/lib/Doctrine/DBAL/Types/ConversionException.php index cab786de5d3..5ef88986c19 100644 --- a/lib/Doctrine/DBAL/Types/ConversionException.php +++ b/lib/Doctrine/DBAL/Types/ConversionException.php @@ -1,21 +1,4 @@ . - */ /** * Conversion Exception is thrown when the database to PHP conversion fails. diff --git a/lib/Doctrine/DBAL/Types/DateImmutableType.php b/lib/Doctrine/DBAL/Types/DateImmutableType.php index 8b9a91d7d32..9438efd9781 100644 --- a/lib/Doctrine/DBAL/Types/DateImmutableType.php +++ b/lib/Doctrine/DBAL/Types/DateImmutableType.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Types; diff --git a/lib/Doctrine/DBAL/Types/DateTimeImmutableType.php b/lib/Doctrine/DBAL/Types/DateTimeImmutableType.php index b8564fcddc3..33a6841c9e2 100644 --- a/lib/Doctrine/DBAL/Types/DateTimeImmutableType.php +++ b/lib/Doctrine/DBAL/Types/DateTimeImmutableType.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Types; diff --git a/lib/Doctrine/DBAL/Types/DateTimeType.php b/lib/Doctrine/DBAL/Types/DateTimeType.php index 3cb76ee5b54..57db8afa9c8 100644 --- a/lib/Doctrine/DBAL/Types/DateTimeType.php +++ b/lib/Doctrine/DBAL/Types/DateTimeType.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Types; diff --git a/lib/Doctrine/DBAL/Types/DateTimeTzImmutableType.php b/lib/Doctrine/DBAL/Types/DateTimeTzImmutableType.php index 91f3eda75de..78111f09b33 100644 --- a/lib/Doctrine/DBAL/Types/DateTimeTzImmutableType.php +++ b/lib/Doctrine/DBAL/Types/DateTimeTzImmutableType.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Types; diff --git a/lib/Doctrine/DBAL/Types/DateTimeTzType.php b/lib/Doctrine/DBAL/Types/DateTimeTzType.php index f731baf141d..8242819eebc 100644 --- a/lib/Doctrine/DBAL/Types/DateTimeTzType.php +++ b/lib/Doctrine/DBAL/Types/DateTimeTzType.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Types; diff --git a/lib/Doctrine/DBAL/Types/DateType.php b/lib/Doctrine/DBAL/Types/DateType.php index e3ed6a9e71e..8794706c4ce 100644 --- a/lib/Doctrine/DBAL/Types/DateType.php +++ b/lib/Doctrine/DBAL/Types/DateType.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Types; diff --git a/lib/Doctrine/DBAL/Types/DecimalType.php b/lib/Doctrine/DBAL/Types/DecimalType.php index 42c05d69a71..45a8e233f02 100644 --- a/lib/Doctrine/DBAL/Types/DecimalType.php +++ b/lib/Doctrine/DBAL/Types/DecimalType.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Types; diff --git a/lib/Doctrine/DBAL/Types/FloatType.php b/lib/Doctrine/DBAL/Types/FloatType.php index 87f9c32ae1a..ea1dc3b9ad3 100644 --- a/lib/Doctrine/DBAL/Types/FloatType.php +++ b/lib/Doctrine/DBAL/Types/FloatType.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Types; diff --git a/lib/Doctrine/DBAL/Types/GuidType.php b/lib/Doctrine/DBAL/Types/GuidType.php index 761d58a8e85..c522aa8ca50 100644 --- a/lib/Doctrine/DBAL/Types/GuidType.php +++ b/lib/Doctrine/DBAL/Types/GuidType.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Types; diff --git a/lib/Doctrine/DBAL/Types/IntegerType.php b/lib/Doctrine/DBAL/Types/IntegerType.php index 3c83341ded0..60b183a009a 100644 --- a/lib/Doctrine/DBAL/Types/IntegerType.php +++ b/lib/Doctrine/DBAL/Types/IntegerType.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Types; diff --git a/lib/Doctrine/DBAL/Types/JsonArrayType.php b/lib/Doctrine/DBAL/Types/JsonArrayType.php index 5650eb51856..0e62688251b 100644 --- a/lib/Doctrine/DBAL/Types/JsonArrayType.php +++ b/lib/Doctrine/DBAL/Types/JsonArrayType.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Types; diff --git a/lib/Doctrine/DBAL/Types/JsonType.php b/lib/Doctrine/DBAL/Types/JsonType.php index 6395332c682..e7f0ed0869d 100644 --- a/lib/Doctrine/DBAL/Types/JsonType.php +++ b/lib/Doctrine/DBAL/Types/JsonType.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Types; diff --git a/lib/Doctrine/DBAL/Types/ObjectType.php b/lib/Doctrine/DBAL/Types/ObjectType.php index 0547377c9c2..ed53fb03a73 100644 --- a/lib/Doctrine/DBAL/Types/ObjectType.php +++ b/lib/Doctrine/DBAL/Types/ObjectType.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Types; diff --git a/lib/Doctrine/DBAL/Types/PhpDateTimeMappingType.php b/lib/Doctrine/DBAL/Types/PhpDateTimeMappingType.php index d530d8cf074..58de0177233 100644 --- a/lib/Doctrine/DBAL/Types/PhpDateTimeMappingType.php +++ b/lib/Doctrine/DBAL/Types/PhpDateTimeMappingType.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Types; diff --git a/lib/Doctrine/DBAL/Types/PhpIntegerMappingType.php b/lib/Doctrine/DBAL/Types/PhpIntegerMappingType.php index 034aaecb33a..cd41f5ff6df 100644 --- a/lib/Doctrine/DBAL/Types/PhpIntegerMappingType.php +++ b/lib/Doctrine/DBAL/Types/PhpIntegerMappingType.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Types; diff --git a/lib/Doctrine/DBAL/Types/SimpleArrayType.php b/lib/Doctrine/DBAL/Types/SimpleArrayType.php index fb01479e322..8059ef3490f 100644 --- a/lib/Doctrine/DBAL/Types/SimpleArrayType.php +++ b/lib/Doctrine/DBAL/Types/SimpleArrayType.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Types; diff --git a/lib/Doctrine/DBAL/Types/SmallIntType.php b/lib/Doctrine/DBAL/Types/SmallIntType.php index 1a2abdbe062..4fc2ab96211 100644 --- a/lib/Doctrine/DBAL/Types/SmallIntType.php +++ b/lib/Doctrine/DBAL/Types/SmallIntType.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Types; diff --git a/lib/Doctrine/DBAL/Types/StringType.php b/lib/Doctrine/DBAL/Types/StringType.php index 39bd32dbc8e..e56569c4644 100644 --- a/lib/Doctrine/DBAL/Types/StringType.php +++ b/lib/Doctrine/DBAL/Types/StringType.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Types; diff --git a/lib/Doctrine/DBAL/Types/TextType.php b/lib/Doctrine/DBAL/Types/TextType.php index bd72355464d..19bb875439d 100644 --- a/lib/Doctrine/DBAL/Types/TextType.php +++ b/lib/Doctrine/DBAL/Types/TextType.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Types; diff --git a/lib/Doctrine/DBAL/Types/TimeImmutableType.php b/lib/Doctrine/DBAL/Types/TimeImmutableType.php index 118d80ea8df..8e43e18f934 100644 --- a/lib/Doctrine/DBAL/Types/TimeImmutableType.php +++ b/lib/Doctrine/DBAL/Types/TimeImmutableType.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Types; diff --git a/lib/Doctrine/DBAL/Types/TimeType.php b/lib/Doctrine/DBAL/Types/TimeType.php index 639533fad5c..b9a5b66cd8a 100644 --- a/lib/Doctrine/DBAL/Types/TimeType.php +++ b/lib/Doctrine/DBAL/Types/TimeType.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Types; diff --git a/lib/Doctrine/DBAL/Types/Type.php b/lib/Doctrine/DBAL/Types/Type.php index 31f93866b9a..e75c93242a6 100644 --- a/lib/Doctrine/DBAL/Types/Type.php +++ b/lib/Doctrine/DBAL/Types/Type.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Types; diff --git a/lib/Doctrine/DBAL/Types/VarDateTimeImmutableType.php b/lib/Doctrine/DBAL/Types/VarDateTimeImmutableType.php index f0e8ff84482..a8bf8f2f090 100644 --- a/lib/Doctrine/DBAL/Types/VarDateTimeImmutableType.php +++ b/lib/Doctrine/DBAL/Types/VarDateTimeImmutableType.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Types; diff --git a/lib/Doctrine/DBAL/Types/VarDateTimeType.php b/lib/Doctrine/DBAL/Types/VarDateTimeType.php index b55e0b05b3e..2396230c3b5 100644 --- a/lib/Doctrine/DBAL/Types/VarDateTimeType.php +++ b/lib/Doctrine/DBAL/Types/VarDateTimeType.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL\Types; diff --git a/lib/Doctrine/DBAL/Version.php b/lib/Doctrine/DBAL/Version.php index e82d1e8ae62..481e27b4128 100644 --- a/lib/Doctrine/DBAL/Version.php +++ b/lib/Doctrine/DBAL/Version.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL; diff --git a/lib/Doctrine/DBAL/VersionAwarePlatformDriver.php b/lib/Doctrine/DBAL/VersionAwarePlatformDriver.php index 53e2d3ab781..45eb8a91fa2 100644 --- a/lib/Doctrine/DBAL/VersionAwarePlatformDriver.php +++ b/lib/Doctrine/DBAL/VersionAwarePlatformDriver.php @@ -1,21 +1,4 @@ . - */ namespace Doctrine\DBAL; From dca1465bdc0836c71ed97e46820490127ccc89ab Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 28 Sep 2018 23:56:29 -0700 Subject: [PATCH 31/76] Automated coding style fixes using phpcbf --- bin/doctrine-dbal.php | 16 +- lib/Doctrine/DBAL/Cache/ArrayStatement.php | 38 +- lib/Doctrine/DBAL/Cache/CacheException.php | 12 +- lib/Doctrine/DBAL/Cache/QueryCacheProfile.php | 13 +- .../DBAL/Cache/ResultCacheStatement.php | 79 ++- lib/Doctrine/DBAL/ColumnCase.php | 6 +- lib/Doctrine/DBAL/Configuration.php | 26 +- lib/Doctrine/DBAL/Connection.php | 355 +++++++------ lib/Doctrine/DBAL/ConnectionException.php | 10 +- .../Connections/MasterSlaveConnection.php | 35 +- lib/Doctrine/DBAL/DBALException.php | 96 ++-- lib/Doctrine/DBAL/Driver.php | 13 +- .../DBAL/Driver/AbstractDB2Driver.php | 7 +- .../DBAL/Driver/AbstractDriverException.php | 8 +- .../DBAL/Driver/AbstractMySQLDriver.php | 19 +- .../DBAL/Driver/AbstractOracleDriver.php | 7 +- .../DBAL/Driver/AbstractPostgreSQLDriver.php | 11 +- .../DBAL/Driver/AbstractSQLAnywhereDriver.php | 11 +- .../DBAL/Driver/AbstractSQLServerDriver.php | 11 +- .../DBAL/Driver/AbstractSQLiteDriver.php | 7 +- lib/Doctrine/DBAL/Driver/Connection.php | 4 +- lib/Doctrine/DBAL/Driver/DriverException.php | 6 +- .../Driver/DrizzlePDOMySql/Connection.php | 6 +- .../DBAL/Driver/DrizzlePDOMySql/Driver.php | 6 +- .../DBAL/Driver/ExceptionConverterDriver.php | 7 +- .../DBAL/Driver/IBMDB2/DB2Connection.php | 22 +- lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php | 11 +- .../DBAL/Driver/IBMDB2/DB2Exception.php | 4 +- .../DBAL/Driver/IBMDB2/DB2Statement.php | 70 ++- lib/Doctrine/DBAL/Driver/Mysqli/Driver.php | 5 +- .../DBAL/Driver/Mysqli/MysqliConnection.php | 59 ++- .../DBAL/Driver/Mysqli/MysqliException.php | 3 - .../DBAL/Driver/Mysqli/MysqliStatement.php | 117 ++--- lib/Doctrine/DBAL/Driver/OCI8/Driver.php | 3 - .../DBAL/Driver/OCI8/OCI8Connection.php | 29 +- .../DBAL/Driver/OCI8/OCI8Statement.php | 113 ++-- lib/Doctrine/DBAL/Driver/PDOConnection.php | 12 +- lib/Doctrine/DBAL/Driver/PDOException.php | 4 - lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php | 9 +- lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php | 4 +- lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php | 3 +- lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php | 12 +- lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php | 10 +- .../DBAL/Driver/PDOSqlsrv/Connection.php | 9 +- lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php | 7 +- lib/Doctrine/DBAL/Driver/PDOStatement.php | 22 +- .../DBAL/Driver/PingableConnection.php | 3 - lib/Doctrine/DBAL/Driver/ResultStatement.php | 11 +- .../DBAL/Driver/SQLAnywhere/Driver.php | 9 +- .../SQLAnywhere/SQLAnywhereConnection.php | 32 +- .../SQLAnywhere/SQLAnywhereException.php | 15 +- .../SQLAnywhere/SQLAnywhereStatement.php | 69 ++- lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php | 6 +- .../DBAL/Driver/SQLSrv/LastInsertId.php | 7 +- .../DBAL/Driver/SQLSrv/SQLSrvConnection.php | 28 +- .../DBAL/Driver/SQLSrv/SQLSrvException.php | 21 +- .../DBAL/Driver/SQLSrv/SQLSrvStatement.php | 65 ++- .../DBAL/Driver/ServerInfoAwareConnection.php | 2 - lib/Doctrine/DBAL/Driver/Statement.php | 4 - .../DBAL/Driver/StatementIterator.php | 13 +- lib/Doctrine/DBAL/DriverManager.php | 102 ++-- .../DBAL/Event/ConnectionEventArgs.php | 20 +- .../DBAL/Event/Listeners/MysqlSessionInit.php | 21 +- .../Event/Listeners/OracleSessionInit.php | 45 +- .../DBAL/Event/Listeners/SQLSessionInit.php | 10 +- .../SchemaAlterTableAddColumnEventArgs.php | 29 +- .../SchemaAlterTableChangeColumnEventArgs.php | 29 +- .../DBAL/Event/SchemaAlterTableEventArgs.php | 22 +- .../SchemaAlterTableRemoveColumnEventArgs.php | 29 +- .../SchemaAlterTableRenameColumnEventArgs.php | 33 +- .../Event/SchemaColumnDefinitionEventArgs.php | 36 +- .../SchemaCreateTableColumnEventArgs.php | 29 +- .../DBAL/Event/SchemaCreateTableEventArgs.php | 32 +- .../DBAL/Event/SchemaDropTableEventArgs.php | 28 +- lib/Doctrine/DBAL/Event/SchemaEventArgs.php | 6 +- .../Event/SchemaIndexDefinitionEventArgs.php | 30 +- lib/Doctrine/DBAL/Events.php | 25 +- .../DBAL/Exception/ConnectionException.php | 2 - .../ConstraintViolationException.php | 2 - .../DatabaseObjectExistsException.php | 2 - .../DatabaseObjectNotFoundException.php | 2 - .../DBAL/Exception/DeadlockException.php | 2 - .../DBAL/Exception/DriverException.php | 7 +- ...ForeignKeyConstraintViolationException.php | 3 - .../Exception/InvalidArgumentException.php | 2 - .../Exception/InvalidFieldNameException.php | 2 - .../Exception/LockWaitTimeoutException.php | 2 - .../Exception/NonUniqueFieldNameException.php | 2 - .../NotNullConstraintViolationException.php | 3 - .../DBAL/Exception/ReadOnlyException.php | 2 - .../DBAL/Exception/RetryableException.php | 2 - .../DBAL/Exception/ServerException.php | 2 - .../DBAL/Exception/SyntaxErrorException.php | 2 - .../DBAL/Exception/TableExistsException.php | 2 - .../DBAL/Exception/TableNotFoundException.php | 2 - .../UniqueConstraintViolationException.php | 3 - lib/Doctrine/DBAL/FetchMode.php | 14 +- lib/Doctrine/DBAL/Id/TableGenerator.php | 50 +- .../DBAL/Id/TableGeneratorSchemaVisitor.php | 13 +- lib/Doctrine/DBAL/LockMode.php | 11 +- lib/Doctrine/DBAL/Logging/DebugStack.php | 29 +- lib/Doctrine/DBAL/Logging/EchoSQLLogger.php | 13 +- lib/Doctrine/DBAL/Logging/LoggerChain.php | 10 +- lib/Doctrine/DBAL/Logging/SQLLogger.php | 7 +- lib/Doctrine/DBAL/ParameterType.php | 12 +- .../DBAL/Platforms/AbstractPlatform.php | 482 ++++++++---------- lib/Doctrine/DBAL/Platforms/DB2Platform.php | 78 +-- .../DBAL/Platforms/DrizzlePlatform.php | 86 ++-- .../DBAL/Platforms/Keywords/DB2Keywords.php | 2 - .../Platforms/Keywords/DrizzleKeywords.php | 2 - .../DBAL/Platforms/Keywords/KeywordList.php | 6 +- .../Platforms/Keywords/MariaDb102Keywords.php | 1 + .../DBAL/Platforms/Keywords/MsSQLKeywords.php | 9 +- .../Platforms/Keywords/MySQL57Keywords.php | 2 - .../DBAL/Platforms/Keywords/MySQLKeywords.php | 3 - .../Platforms/Keywords/OracleKeywords.php | 3 - .../Keywords/PostgreSQL91Keywords.php | 3 - .../Keywords/PostgreSQL92Keywords.php | 6 +- .../Keywords/PostgreSQL94Keywords.php | 10 +- .../Platforms/Keywords/PostgreSQLKeywords.php | 5 +- .../Keywords/ReservedKeywordsValidator.php | 26 +- .../Keywords/SQLAnywhere11Keywords.php | 4 +- .../Keywords/SQLAnywhere12Keywords.php | 6 +- .../Keywords/SQLAnywhere16Keywords.php | 4 +- .../Keywords/SQLAnywhereKeywords.php | 4 +- .../Keywords/SQLServer2005Keywords.php | 5 +- .../Keywords/SQLServer2008Keywords.php | 7 +- .../Keywords/SQLServer2012Keywords.php | 5 +- .../Platforms/Keywords/SQLServerKeywords.php | 7 +- .../Platforms/Keywords/SQLiteKeywords.php | 4 +- .../DBAL/Platforms/MariaDb1027Platform.php | 1 - .../DBAL/Platforms/MySQL57Platform.php | 7 +- lib/Doctrine/DBAL/Platforms/MySqlPlatform.php | 212 ++++---- .../DBAL/Platforms/OraclePlatform.php | 152 +++--- .../DBAL/Platforms/PostgreSQL100Platform.php | 4 +- .../DBAL/Platforms/PostgreSQL91Platform.php | 6 +- .../DBAL/Platforms/PostgreSQL92Platform.php | 4 +- .../DBAL/Platforms/PostgreSQL94Platform.php | 4 +- .../DBAL/Platforms/PostgreSqlPlatform.php | 157 +++--- .../DBAL/Platforms/SQLAnywhere11Platform.php | 2 - .../DBAL/Platforms/SQLAnywhere12Platform.php | 4 +- .../DBAL/Platforms/SQLAnywhere16Platform.php | 4 +- .../DBAL/Platforms/SQLAnywherePlatform.php | 204 ++++---- .../DBAL/Platforms/SQLAzurePlatform.php | 4 +- .../DBAL/Platforms/SQLServer2008Platform.php | 6 +- .../DBAL/Platforms/SQLServer2012Platform.php | 18 +- .../DBAL/Platforms/SQLServerPlatform.php | 256 +++++----- .../DBAL/Platforms/SqlitePlatform.php | 208 ++++---- lib/Doctrine/DBAL/Portability/Connection.php | 74 ++- lib/Doctrine/DBAL/Portability/Statement.php | 36 +- .../Query/Expression/CompositeExpression.php | 14 +- .../Query/Expression/ExpressionBuilder.php | 27 +- lib/Doctrine/DBAL/Query/QueryBuilder.php | 139 +++-- lib/Doctrine/DBAL/Query/QueryException.php | 11 +- lib/Doctrine/DBAL/SQLParserUtils.php | 36 +- lib/Doctrine/DBAL/SQLParserUtilsException.php | 3 - lib/Doctrine/DBAL/Schema/AbstractAsset.php | 42 +- .../DBAL/Schema/AbstractSchemaManager.php | 224 ++++---- lib/Doctrine/DBAL/Schema/Column.php | 69 +-- lib/Doctrine/DBAL/Schema/ColumnDiff.php | 28 +- lib/Doctrine/DBAL/Schema/Comparator.php | 247 ++++----- lib/Doctrine/DBAL/Schema/Constraint.php | 6 +- lib/Doctrine/DBAL/Schema/DB2SchemaManager.php | 62 +-- .../DBAL/Schema/DrizzleSchemaManager.php | 16 +- .../DBAL/Schema/ForeignKeyConstraint.php | 31 +- lib/Doctrine/DBAL/Schema/Identifier.php | 10 +- lib/Doctrine/DBAL/Schema/Index.php | 52 +- .../DBAL/Schema/MySqlSchemaManager.php | 20 +- .../DBAL/Schema/OracleSchemaManager.php | 113 ++-- .../DBAL/Schema/PostgreSqlSchemaManager.php | 103 ++-- .../DBAL/Schema/SQLAnywhereSchemaManager.php | 34 +- .../DBAL/Schema/SQLServerSchemaManager.php | 64 ++- lib/Doctrine/DBAL/Schema/Schema.php | 81 +-- lib/Doctrine/DBAL/Schema/SchemaConfig.php | 18 +- lib/Doctrine/DBAL/Schema/SchemaDiff.php | 62 +-- lib/Doctrine/DBAL/Schema/SchemaException.php | 47 +- lib/Doctrine/DBAL/Schema/Sequence.php | 26 +- .../DBAL/Schema/SqliteSchemaManager.php | 203 ++++---- .../AbstractSchemaSynchronizer.php | 11 +- .../Synchronizer/SchemaSynchronizer.php | 16 +- .../SingleDatabaseSynchronizer.php | 36 +- lib/Doctrine/DBAL/Schema/Table.php | 152 +++--- lib/Doctrine/DBAL/Schema/TableDiff.php | 73 ++- lib/Doctrine/DBAL/Schema/View.php | 6 +- .../DBAL/Schema/Visitor/AbstractVisitor.php | 27 +- .../Visitor/CreateSchemaSqlCollector.php | 44 +- .../Schema/Visitor/DropSchemaSqlCollector.php | 36 +- lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php | 22 +- .../DBAL/Schema/Visitor/NamespaceVisitor.php | 2 - .../Schema/Visitor/RemoveNamespacedAssets.php | 31 +- .../DBAL/Schema/Visitor/SchemaDiffVisitor.php | 28 +- lib/Doctrine/DBAL/Schema/Visitor/Visitor.php | 23 +- .../DBAL/Sharding/PoolingShardConnection.php | 52 +- .../DBAL/Sharding/PoolingShardManager.php | 26 +- .../SQLAzureFederationsSynchronizer.php | 94 ++-- .../SQLAzure/SQLAzureShardManager.php | 67 +-- .../SQLAzure/Schema/MultiTenantVisitor.php | 41 +- .../ShardChoser/MultiTenantShardChoser.php | 2 - .../DBAL/Sharding/ShardChoser/ShardChoser.php | 5 +- lib/Doctrine/DBAL/Sharding/ShardManager.php | 4 +- .../DBAL/Sharding/ShardingException.php | 12 +- lib/Doctrine/DBAL/Statement.php | 39 +- .../Tools/Console/Command/ImportCommand.php | 119 ++--- .../Console/Command/ReservedWordsCommand.php | 45 +- .../Tools/Console/Command/RunSqlCommand.php | 15 +- .../DBAL/Tools/Console/ConsoleRunner.php | 10 +- .../Tools/Console/Helper/ConnectionHelper.php | 15 +- lib/Doctrine/DBAL/Types/ArrayType.php | 4 +- lib/Doctrine/DBAL/Types/BigIntType.php | 5 +- lib/Doctrine/DBAL/Types/BinaryType.php | 7 +- lib/Doctrine/DBAL/Types/BlobType.php | 6 +- lib/Doctrine/DBAL/Types/BooleanType.php | 2 - .../DBAL/Types/ConversionException.php | 23 +- lib/Doctrine/DBAL/Types/DateImmutableType.php | 14 +- lib/Doctrine/DBAL/Types/DateIntervalType.php | 12 +- .../DBAL/Types/DateTimeImmutableType.php | 17 +- lib/Doctrine/DBAL/Types/DateTimeType.php | 16 +- .../DBAL/Types/DateTimeTzImmutableType.php | 14 +- lib/Doctrine/DBAL/Types/DateTimeTzType.php | 17 +- lib/Doctrine/DBAL/Types/DateType.php | 14 +- lib/Doctrine/DBAL/Types/DecimalType.php | 2 - lib/Doctrine/DBAL/Types/FloatType.php | 2 +- lib/Doctrine/DBAL/Types/GuidType.php | 5 +- lib/Doctrine/DBAL/Types/IntegerType.php | 5 +- lib/Doctrine/DBAL/Types/JsonArrayType.php | 4 +- lib/Doctrine/DBAL/Types/JsonType.php | 7 +- lib/Doctrine/DBAL/Types/ObjectType.php | 4 +- .../DBAL/Types/PhpDateTimeMappingType.php | 1 + .../DBAL/Types/PhpIntegerMappingType.php | 1 + lib/Doctrine/DBAL/Types/SimpleArrayType.php | 7 +- lib/Doctrine/DBAL/Types/SmallIntType.php | 4 +- lib/Doctrine/DBAL/Types/StringType.php | 2 - lib/Doctrine/DBAL/Types/TextType.php | 4 +- lib/Doctrine/DBAL/Types/TimeImmutableType.php | 14 +- lib/Doctrine/DBAL/Types/TimeType.php | 14 +- lib/Doctrine/DBAL/Types/Type.php | 102 ++-- .../DBAL/Types/VarDateTimeImmutableType.php | 12 +- lib/Doctrine/DBAL/Types/VarDateTimeType.php | 10 +- lib/Doctrine/DBAL/Version.php | 7 +- .../DBAL/VersionAwarePlatformDriver.php | 6 +- phpcs.xml.dist | 1 + 241 files changed, 3362 insertions(+), 4330 deletions(-) diff --git a/bin/doctrine-dbal.php b/bin/doctrine-dbal.php index 3d1131f1a42..f785c1b12a2 100644 --- a/bin/doctrine-dbal.php +++ b/bin/doctrine-dbal.php @@ -17,13 +17,13 @@ * . */ -use Symfony\Component\Console\Helper\HelperSet; use Doctrine\DBAL\Tools\Console\ConsoleRunner; +use Symfony\Component\Console\Helper\HelperSet; -$files = array(__DIR__ . '/../vendor/autoload.php', __DIR__ . '/../../../autoload.php'); +$files = [__DIR__ . '/../vendor/autoload.php', __DIR__ . '/../../../autoload.php']; $loader = null; $cwd = getcwd(); -$directories = array($cwd, $cwd . DIRECTORY_SEPARATOR . 'config'); +$directories = [$cwd, $cwd . DIRECTORY_SEPARATOR . 'config']; $configFile = null; foreach ($files as $file) { @@ -34,7 +34,7 @@ } } -if ( ! $loader) { +if (! $loader) { throw new RuntimeException('vendor/autoload.php could not be found. Did you run `php composer.phar install`?'); } @@ -46,22 +46,22 @@ } } -if ( ! file_exists($configFile)) { +if (! file_exists($configFile)) { ConsoleRunner::printCliConfigTemplate(); exit(1); } -if ( ! is_readable($configFile)) { +if (! is_readable($configFile)) { echo 'Configuration file [' . $configFile . '] does not have read permission.' . PHP_EOL; exit(1); } -$commands = array(); +$commands = []; $helperSet = require $configFile; -if ( ! $helperSet instanceof HelperSet) { +if (! $helperSet instanceof HelperSet) { foreach ($GLOBALS as $helperSetCandidate) { if ($helperSetCandidate instanceof HelperSet) { $helperSet = $helperSetCandidate; diff --git a/lib/Doctrine/DBAL/Cache/ArrayStatement.php b/lib/Doctrine/DBAL/Cache/ArrayStatement.php index e9247280e09..e06998723a8 100644 --- a/lib/Doctrine/DBAL/Cache/ArrayStatement.php +++ b/lib/Doctrine/DBAL/Cache/ArrayStatement.php @@ -2,33 +2,29 @@ namespace Doctrine\DBAL\Cache; +use ArrayIterator; use Doctrine\DBAL\Driver\ResultStatement; use Doctrine\DBAL\FetchMode; +use InvalidArgumentException; +use IteratorAggregate; +use PDO; use function array_merge; use function array_values; use function count; use function reset; -class ArrayStatement implements \IteratorAggregate, ResultStatement +class ArrayStatement implements IteratorAggregate, ResultStatement { - /** - * @var array - */ + /** @var array */ private $data; - /** - * @var int - */ + /** @var int */ private $columnCount = 0; - /** - * @var int - */ + /** @var int */ private $num = 0; - /** - * @var int - */ + /** @var int */ private $defaultFetchMode = FetchMode::MIXED; /** @@ -37,9 +33,11 @@ class ArrayStatement implements \IteratorAggregate, ResultStatement public function __construct(array $data) { $this->data = $data; - if (count($data)) { - $this->columnCount = count($data[0]); + if (! count($data)) { + return; } + + $this->columnCount = count($data[0]); } /** @@ -47,7 +45,7 @@ public function __construct(array $data) */ public function closeCursor() { - unset ($this->data); + unset($this->data); } /** @@ -64,7 +62,7 @@ public function columnCount() public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) { if ($arg2 !== null || $arg3 !== null) { - throw new \InvalidArgumentException("Caching layer does not support 2nd/3rd argument to setFetchMode()"); + throw new InvalidArgumentException('Caching layer does not support 2nd/3rd argument to setFetchMode()'); } $this->defaultFetchMode = $fetchMode; @@ -79,13 +77,13 @@ public function getIterator() { $data = $this->fetchAll(); - return new \ArrayIterator($data); + return new ArrayIterator($data); } /** * {@inheritdoc} */ - public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) + public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0) { if (! isset($this->data[$this->num])) { return false; @@ -110,7 +108,7 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE return reset($row); } - throw new \InvalidArgumentException('Invalid fetch-style given for fetching result.'); + throw new InvalidArgumentException('Invalid fetch-style given for fetching result.'); } /** diff --git a/lib/Doctrine/DBAL/Cache/CacheException.php b/lib/Doctrine/DBAL/Cache/CacheException.php index 00c692940b4..636c948a616 100644 --- a/lib/Doctrine/DBAL/Cache/CacheException.php +++ b/lib/Doctrine/DBAL/Cache/CacheException.php @@ -2,18 +2,16 @@ namespace Doctrine\DBAL\Cache; -/** - * @author Benjamin Eberlei - * @since 2.2 - */ -class CacheException extends \Doctrine\DBAL\DBALException +use Doctrine\DBAL\DBALException; + +class CacheException extends DBALException { /** * @return \Doctrine\DBAL\Cache\CacheException */ public static function noCacheKey() { - return new self("No cache key was set."); + return new self('No cache key was set.'); } /** @@ -21,6 +19,6 @@ public static function noCacheKey() */ public static function noResultDriverConfigured() { - return new self("Trying to cache a query but no result driver is configured."); + return new self('Trying to cache a query but no result driver is configured.'); } } diff --git a/lib/Doctrine/DBAL/Cache/QueryCacheProfile.php b/lib/Doctrine/DBAL/Cache/QueryCacheProfile.php index 2d29ea0d44f..8b42c7ce658 100644 --- a/lib/Doctrine/DBAL/Cache/QueryCacheProfile.php +++ b/lib/Doctrine/DBAL/Cache/QueryCacheProfile.php @@ -14,19 +14,13 @@ */ class QueryCacheProfile { - /** - * @var Cache|null - */ + /** @var Cache|null */ private $resultCacheDriver; - /** - * @var int - */ + /** @var int */ private $lifetime = 0; - /** - * @var string|null - */ + /** @var string|null */ private $cacheKey; /** @@ -98,7 +92,6 @@ public function generateCacheKeys($query, $params, $types, array $connectionPara } /** - * * @return \Doctrine\DBAL\Cache\QueryCacheProfile */ public function setResultCacheDriver(Cache $cache) diff --git a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php index 3951c52e815..606df4e7e4e 100644 --- a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php +++ b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php @@ -2,10 +2,14 @@ namespace Doctrine\DBAL\Cache; -use Doctrine\DBAL\Driver\Statement; -use Doctrine\DBAL\Driver\ResultStatement; +use ArrayIterator; use Doctrine\Common\Cache\Cache; +use Doctrine\DBAL\Driver\ResultStatement; +use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\FetchMode; +use InvalidArgumentException; +use IteratorAggregate; +use PDO; use function array_merge; use function array_values; use function reset; @@ -23,32 +27,21 @@ * Also you have to realize that the cache will load the whole result into memory at once to ensure 2. * This means that the memory usage for cached results might increase by using this feature. */ -class ResultCacheStatement implements \IteratorAggregate, ResultStatement +class ResultCacheStatement implements IteratorAggregate, ResultStatement { - /** - * @var \Doctrine\Common\Cache\Cache - */ + /** @var Cache */ private $resultCache; - /** - * - * @var string - */ + /** @var string */ private $cacheKey; - /** - * @var string - */ + /** @var string */ private $realKey; - /** - * @var int - */ + /** @var int */ private $lifetime; - /** - * @var \Doctrine\DBAL\Driver\Statement - */ + /** @var Statement */ private $statement; /** @@ -58,30 +51,24 @@ class ResultCacheStatement implements \IteratorAggregate, ResultStatement */ private $emptied = false; - /** - * @var array - */ + /** @var array */ private $data; - /** - * @var int - */ + /** @var int */ private $defaultFetchMode = FetchMode::MIXED; /** - * @param \Doctrine\DBAL\Driver\Statement $stmt - * @param \Doctrine\Common\Cache\Cache $resultCache - * @param string $cacheKey - * @param string $realKey - * @param int $lifetime + * @param string $cacheKey + * @param string $realKey + * @param int $lifetime */ public function __construct(Statement $stmt, Cache $resultCache, $cacheKey, $realKey, $lifetime) { - $this->statement = $stmt; + $this->statement = $stmt; $this->resultCache = $resultCache; - $this->cacheKey = $cacheKey; - $this->realKey = $realKey; - $this->lifetime = $lifetime; + $this->cacheKey = $cacheKey; + $this->realKey = $realKey; + $this->lifetime = $lifetime; } /** @@ -90,16 +77,18 @@ public function __construct(Statement $stmt, Cache $resultCache, $cacheKey, $rea public function closeCursor() { $this->statement->closeCursor(); - if ($this->emptied && $this->data !== null) { - $data = $this->resultCache->fetch($this->cacheKey); - if ( ! $data) { - $data = []; - } - $data[$this->realKey] = $this->data; + if (! $this->emptied || $this->data === null) { + return; + } - $this->resultCache->save($this->cacheKey, $data, $this->lifetime); - unset($this->data); + $data = $this->resultCache->fetch($this->cacheKey); + if (! $data) { + $data = []; } + $data[$this->realKey] = $this->data; + + $this->resultCache->save($this->cacheKey, $data, $this->lifetime); + unset($this->data); } /** @@ -127,13 +116,13 @@ public function getIterator() { $data = $this->fetchAll(); - return new \ArrayIterator($data); + return new ArrayIterator($data); } /** * {@inheritdoc} */ - public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) + public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0) { if ($this->data === null) { $this->data = []; @@ -162,7 +151,7 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE return reset($row); } - throw new \InvalidArgumentException('Invalid fetch-style given for caching result.'); + throw new InvalidArgumentException('Invalid fetch-style given for caching result.'); } $this->emptied = true; diff --git a/lib/Doctrine/DBAL/ColumnCase.php b/lib/Doctrine/DBAL/ColumnCase.php index 420d868f582..872d3ede873 100644 --- a/lib/Doctrine/DBAL/ColumnCase.php +++ b/lib/Doctrine/DBAL/ColumnCase.php @@ -2,6 +2,8 @@ namespace Doctrine\DBAL; +use PDO; + /** * Contains portable column case conversions. */ @@ -12,14 +14,14 @@ final class ColumnCase * * @see \PDO::CASE_UPPER */ - public const UPPER = \PDO::CASE_UPPER; + public const UPPER = PDO::CASE_UPPER; /** * Convert column names to lower case. * * @see \PDO::CASE_LOWER */ - public const LOWER = \PDO::CASE_LOWER; + public const LOWER = PDO::CASE_LOWER; /** * This class cannot be instantiated. diff --git a/lib/Doctrine/DBAL/Configuration.php b/lib/Doctrine/DBAL/Configuration.php index 9a63928aa00..21660affb8e 100644 --- a/lib/Doctrine/DBAL/Configuration.php +++ b/lib/Doctrine/DBAL/Configuration.php @@ -2,16 +2,12 @@ namespace Doctrine\DBAL; -use Doctrine\DBAL\Logging\SQLLogger; use Doctrine\Common\Cache\Cache; +use Doctrine\DBAL\Logging\SQLLogger; /** * Configuration container for the Doctrine DBAL. * - * @since 2.0 - * @author Guilherme Blanco - * @author Jonathan Wage - * @author Roman Borschel * @internal When adding a new configuration option just write a getter/setter * pair and add the option to the _attributes array with a proper default value. */ @@ -28,11 +24,9 @@ class Configuration /** * Sets the SQL logger to use. Defaults to NULL which means SQL logging is disabled. * - * @param \Doctrine\DBAL\Logging\SQLLogger|null $logger - * * @return void */ - public function setSQLLogger(SQLLogger $logger = null) + public function setSQLLogger(?SQLLogger $logger = null) { $this->_attributes['sqlLogger'] = $logger; } @@ -40,7 +34,7 @@ public function setSQLLogger(SQLLogger $logger = null) /** * Gets the SQL logger that is used. * - * @return \Doctrine\DBAL\Logging\SQLLogger|null + * @return SQLLogger|null */ public function getSQLLogger() { @@ -50,7 +44,7 @@ public function getSQLLogger() /** * Gets the cache driver implementation that is used for query result caching. * - * @return \Doctrine\Common\Cache\Cache|null + * @return Cache|null */ public function getResultCacheImpl() { @@ -60,8 +54,6 @@ public function getResultCacheImpl() /** * Sets the cache driver implementation that is used for query result caching. * - * @param \Doctrine\Common\Cache\Cache $cacheImpl - * * @return void */ public function setResultCacheImpl(Cache $cacheImpl) @@ -102,21 +94,21 @@ public function getFilterSchemaAssetsExpression() * transactions. Otherwise, its SQL statements are grouped into transactions that are terminated by a call to either * the method commit or the method rollback. By default, new connections are in auto-commit mode. * - * @param bool $autoCommit True to enable auto-commit mode; false to disable it. - * * @see getAutoCommit + * + * @param bool $autoCommit True to enable auto-commit mode; false to disable it. */ public function setAutoCommit($autoCommit) { - $this->_attributes['autoCommit'] = (boolean) $autoCommit; + $this->_attributes['autoCommit'] = (bool) $autoCommit; } /** * Returns the default auto-commit mode for connections. * - * @return bool True if auto-commit mode is enabled by default for connections, false otherwise. - * * @see setAutoCommit + * + * @return bool True if auto-commit mode is enabled by default for connections, false otherwise. */ public function getAutoCommit() { diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index 2a1d9a1b9c0..b0c30aceabc 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -2,24 +2,28 @@ namespace Doctrine\DBAL; -use Doctrine\DBAL\Driver\ResultStatement; -use Doctrine\DBAL\Driver\ServerInfoAwareConnection; -use Doctrine\DBAL\Exception\InvalidArgumentException; use Closure; -use Exception; -use Doctrine\DBAL\Types\Type; -use Doctrine\DBAL\Driver\Connection as DriverConnection; -use Doctrine\DBAL\Driver\Statement as DriverStatement; use Doctrine\Common\EventManager; -use Doctrine\DBAL\Cache\ResultCacheStatement; -use Doctrine\DBAL\Cache\QueryCacheProfile; use Doctrine\DBAL\Cache\ArrayStatement; use Doctrine\DBAL\Cache\CacheException; +use Doctrine\DBAL\Cache\QueryCacheProfile; +use Doctrine\DBAL\Cache\ResultCacheStatement; +use Doctrine\DBAL\Driver\Connection as DriverConnection; use Doctrine\DBAL\Driver\PingableConnection; +use Doctrine\DBAL\Driver\ResultStatement; +use Doctrine\DBAL\Driver\ServerInfoAwareConnection; +use Doctrine\DBAL\Driver\Statement as DriverStatement; +use Doctrine\DBAL\Exception\InvalidArgumentException; +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Query\Expression\ExpressionBuilder; +use Doctrine\DBAL\Query\QueryBuilder; +use Doctrine\DBAL\Schema\AbstractSchemaManager; +use Doctrine\DBAL\Types\Type; +use Exception; use Throwable; -use function assert; use function array_key_exists; use function array_merge; +use function assert; use function func_get_args; use function implode; use function is_int; @@ -32,13 +36,6 @@ * lazy connecting and more. * * @link www.doctrine-project.org - * @since 2.0 - * @author Guilherme Blanco - * @author Jonathan Wage - * @author Roman Borschel - * @author Konsta Vesterinen - * @author Lukas Smith (MDB2 library) - * @author Benjamin Eberlei */ class Connection implements DriverConnection { @@ -72,24 +69,18 @@ class Connection implements DriverConnection /** * Represents an array of ints to be expanded by Doctrine SQL parsing. - * - * @var int */ public const PARAM_INT_ARRAY = ParameterType::INTEGER + self::ARRAY_PARAM_OFFSET; /** * Represents an array of strings to be expanded by Doctrine SQL parsing. - * - * @var int */ public const PARAM_STR_ARRAY = ParameterType::STRING + self::ARRAY_PARAM_OFFSET; /** * Offset by which PARAM_* constants are detected as arrays of the param type. - * - * @var int */ - const ARRAY_PARAM_OFFSET = 100; + public const ARRAY_PARAM_OFFSET = 100; /** * The wrapped driver connection. @@ -98,19 +89,13 @@ class Connection implements DriverConnection */ protected $_conn; - /** - * @var \Doctrine\DBAL\Configuration - */ + /** @var Configuration */ protected $_config; - /** - * @var \Doctrine\Common\EventManager - */ + /** @var EventManager */ protected $_eventManager; - /** - * @var \Doctrine\DBAL\Query\Expression\ExpressionBuilder - */ + /** @var ExpressionBuilder */ protected $_expr; /** @@ -159,21 +144,21 @@ class Connection implements DriverConnection * The DatabasePlatform object that provides information about the * database platform used by the connection. * - * @var \Doctrine\DBAL\Platforms\AbstractPlatform + * @var AbstractPlatform */ private $platform; /** * The schema manager. * - * @var \Doctrine\DBAL\Schema\AbstractSchemaManager + * @var AbstractSchemaManager */ protected $_schemaManager; /** * The used DBAL driver. * - * @var \Doctrine\DBAL\Driver + * @var Driver */ protected $_driver; @@ -184,52 +169,53 @@ class Connection implements DriverConnection */ private $_isRollbackOnly = false; - /** - * @var int - */ + /** @var int */ protected $defaultFetchMode = FetchMode::ASSOCIATIVE; /** * Initializes a new instance of the Connection class. * - * @param array $params The connection parameters. - * @param \Doctrine\DBAL\Driver $driver The driver to use. - * @param \Doctrine\DBAL\Configuration|null $config The configuration, optional. - * @param \Doctrine\Common\EventManager|null $eventManager The event manager, optional. + * @param array $params The connection parameters. + * @param Driver $driver The driver to use. + * @param Configuration|null $config The configuration, optional. + * @param EventManager|null $eventManager The event manager, optional. * - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ - public function __construct(array $params, Driver $driver, Configuration $config = null, - EventManager $eventManager = null) - { + public function __construct( + array $params, + Driver $driver, + ?Configuration $config = null, + ?EventManager $eventManager = null + ) { $this->_driver = $driver; $this->_params = $params; if (isset($params['pdo'])) { - $this->_conn = $params['pdo']; + $this->_conn = $params['pdo']; $this->_isConnected = true; unset($this->_params['pdo']); } - if (isset($params["platform"])) { - if ( ! $params['platform'] instanceof Platforms\AbstractPlatform) { + if (isset($params['platform'])) { + if (! $params['platform'] instanceof Platforms\AbstractPlatform) { throw DBALException::invalidPlatformType($params['platform']); } - $this->platform = $params["platform"]; - unset($this->_params["platform"]); + $this->platform = $params['platform']; + unset($this->_params['platform']); } // Create default config and event manager if none given - if ( ! $config) { + if (! $config) { $config = new Configuration(); } - if ( ! $eventManager) { + if (! $eventManager) { $eventManager = new EventManager(); } - $this->_config = $config; + $this->_config = $config; $this->_eventManager = $eventManager; $this->_expr = new Query\Expression\ExpressionBuilder($this); @@ -300,7 +286,7 @@ public function getPassword() /** * Gets the DBAL driver instance. * - * @return \Doctrine\DBAL\Driver + * @return Driver */ public function getDriver() { @@ -310,7 +296,7 @@ public function getDriver() /** * Gets the Configuration used by the Connection. * - * @return \Doctrine\DBAL\Configuration + * @return Configuration */ public function getConfiguration() { @@ -320,7 +306,7 @@ public function getConfiguration() /** * Gets the EventManager used by the Connection. * - * @return \Doctrine\Common\EventManager + * @return EventManager */ public function getEventManager() { @@ -330,13 +316,13 @@ public function getEventManager() /** * Gets the DatabasePlatform for the connection. * - * @return \Doctrine\DBAL\Platforms\AbstractPlatform + * @return AbstractPlatform * - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ public function getDatabasePlatform() { - if (null === $this->platform) { + if ($this->platform === null) { $this->detectDatabasePlatform(); } @@ -346,7 +332,7 @@ public function getDatabasePlatform() /** * Gets the ExpressionBuilder for the connection. * - * @return \Doctrine\DBAL\Query\Expression\ExpressionBuilder + * @return ExpressionBuilder */ public function getExpressionBuilder() { @@ -366,13 +352,13 @@ public function connect() } $driverOptions = $this->_params['driverOptions'] ?? []; - $user = $this->_params['user'] ?? null; - $password = $this->_params['password'] ?? null; + $user = $this->_params['user'] ?? null; + $password = $this->_params['password'] ?? null; - $this->_conn = $this->_driver->connect($this->_params, $user, $password, $driverOptions); + $this->_conn = $this->_driver->connect($this->_params, $user, $password, $driverOptions); $this->_isConnected = true; - if (false === $this->autoCommit) { + if ($this->autoCommit === false) { $this->beginTransaction(); } @@ -421,7 +407,7 @@ private function detectDatabasePlatform() private function getDatabasePlatformVersion() { // Driver does not support version specific platforms. - if ( ! $this->_driver instanceof VersionAwarePlatformDriver) { + if (! $this->_driver instanceof VersionAwarePlatformDriver) { return null; } @@ -431,22 +417,22 @@ private function getDatabasePlatformVersion() } // If not connected, we need to connect now to determine the platform version. - if (null === $this->_conn) { + if ($this->_conn === null) { try { $this->connect(); - } catch (\Exception $originalException) { + } catch (Throwable $originalException) { if (empty($this->_params['dbname'])) { throw $originalException; } // The database to connect to might not yet exist. // Retry detection without database name connection parameter. - $databaseName = $this->_params['dbname']; + $databaseName = $this->_params['dbname']; $this->_params['dbname'] = null; try { $this->connect(); - } catch (\Exception $fallbackException) { + } catch (Throwable $fallbackException) { // Either the platform does not support database-less connections // or something else went wrong. // Reset connection parameters and rethrow the original exception. @@ -457,14 +443,13 @@ private function getDatabasePlatformVersion() // Reset connection parameters. $this->_params['dbname'] = $databaseName; - $serverVersion = $this->getServerVersion(); + $serverVersion = $this->getServerVersion(); // Close "temporary" connection to allow connecting to the real database again. $this->close(); return $serverVersion; } - } return $this->getServerVersion(); @@ -491,13 +476,13 @@ private function getServerVersion() /** * Returns the current auto-commit mode for this connection. * - * @return bool True if auto-commit mode is currently enabled for this connection, false otherwise. - * * @see setAutoCommit + * + * @return bool True if auto-commit mode is currently enabled for this connection, false otherwise. */ public function isAutoCommit() { - return true === $this->autoCommit; + return $this->autoCommit === true; } /** @@ -510,13 +495,13 @@ public function isAutoCommit() * NOTE: If this method is called during a transaction and the auto-commit mode is changed, the transaction is * committed. If this method is called and the auto-commit mode is not changed, the call is a no-op. * - * @param bool $autoCommit True to enable auto-commit mode; false to disable it. - * * @see isAutoCommit + * + * @param bool $autoCommit True to enable auto-commit mode; false to disable it. */ public function setAutoCommit($autoCommit) { - $autoCommit = (boolean) $autoCommit; + $autoCommit = (bool) $autoCommit; // Mode not changed, no-op. if ($autoCommit === $this->autoCommit) { @@ -526,9 +511,11 @@ public function setAutoCommit($autoCommit) $this->autoCommit = $autoCommit; // Commit all currently active transactions if any when switching auto-commit mode. - if (true === $this->_isConnected && 0 !== $this->_transactionNestingLevel) { - $this->commitAll(); + if ($this->_isConnected !== true || $this->_transactionNestingLevel === 0) { + return; } + + $this->commitAll(); } /** @@ -553,7 +540,7 @@ public function setFetchMode($fetchMode) * * @return array|bool False is returned if no rows are found. * - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ public function fetchAssoc($statement, array $params = [], array $types = []) { @@ -586,7 +573,7 @@ public function fetchArray($statement, array $params = [], array $types = []) * * @return mixed|bool False is returned if no rows are found. * - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ public function fetchColumn($statement, array $params = [], $column = 0, array $types = []) { @@ -625,18 +612,18 @@ public function isTransactionActive() */ private function gatherConditions(array $identifiers) { - $columns = []; - $values = []; + $columns = []; + $values = []; $conditions = []; foreach ($identifiers as $columnName => $value) { - if (null === $value) { + if ($value === null) { $conditions[] = $this->getDatabasePlatform()->getIsNullExpression($columnName); continue; } - $columns[] = $columnName; - $values[] = $value; + $columns[] = $columnName; + $values[] = $value; $conditions[] = $columnName . ' = ?'; } @@ -654,7 +641,7 @@ private function gatherConditions(array $identifiers) * * @return int The number of affected rows. * - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException * @throws InvalidArgumentException */ public function delete($tableExpression, array $identifier, array $types = []) @@ -663,7 +650,7 @@ public function delete($tableExpression, array $identifier, array $types = []) throw InvalidArgumentException::fromEmptyCriteria(); } - list($columns, $values, $conditions) = $this->gatherConditions($identifier); + [$columns, $values, $conditions] = $this->gatherConditions($identifier); return $this->executeUpdate( 'DELETE FROM ' . $tableExpression . ' WHERE ' . implode(' AND ', $conditions), @@ -705,7 +692,7 @@ public function setTransactionIsolation($level) */ public function getTransactionIsolation() { - if (null === $this->_transactionIsolationLevel) { + if ($this->_transactionIsolationLevel === null) { $this->_transactionIsolationLevel = $this->getDatabasePlatform()->getDefaultTransactionIsolationLevel(); } @@ -724,29 +711,29 @@ public function getTransactionIsolation() * * @return int The number of affected rows. * - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ public function update($tableExpression, array $data, array $identifier, array $types = []) { $setColumns = []; - $setValues = []; - $set = []; + $setValues = []; + $set = []; foreach ($data as $columnName => $value) { $setColumns[] = $columnName; - $setValues[] = $value; - $set[] = $columnName . ' = ?'; + $setValues[] = $value; + $set[] = $columnName . ' = ?'; } - list($conditionColumns, $conditionValues, $conditions) = $this->gatherConditions($identifier); - $columns = array_merge($setColumns, $conditionColumns); - $values = array_merge($setValues, $conditionValues); + [$conditionColumns, $conditionValues, $conditions] = $this->gatherConditions($identifier); + $columns = array_merge($setColumns, $conditionColumns); + $values = array_merge($setValues, $conditionValues); if (is_string(key($types))) { $types = $this->extractTypeValues($columns, $types); } - $sql = 'UPDATE ' . $tableExpression . ' SET ' . implode(', ', $set) + $sql = 'UPDATE ' . $tableExpression . ' SET ' . implode(', ', $set) . ' WHERE ' . implode(' AND ', $conditions); return $this->executeUpdate($sql, $values, $types); @@ -763,7 +750,7 @@ public function update($tableExpression, array $data, array $identifier, array $ * * @return int The number of affected rows. * - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ public function insert($tableExpression, array $data, array $types = []) { @@ -772,13 +759,13 @@ public function insert($tableExpression, array $data, array $types = []) } $columns = []; - $values = []; - $set = []; + $values = []; + $set = []; foreach ($data as $columnName => $value) { $columns[] = $columnName; - $values[] = $value; - $set[] = '?'; + $values[] = $value; + $set[] = '?'; } return $this->executeUpdate( @@ -839,7 +826,7 @@ public function quote($input, $type = null) { $this->connect(); - list($value, $bindingType) = $this->getBindingInfo($input, $type); + [$value, $bindingType] = $this->getBindingInfo($input, $type); return $this->_conn->quote($value, $bindingType); } @@ -865,13 +852,13 @@ public function fetchAll($sql, array $params = [], $types = []) * * @return DriverStatement The prepared statement. * - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ public function prepare($statement) { try { $stmt = new Statement($statement, $this); - } catch (Exception $ex) { + } catch (Throwable $ex) { throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $statement); } @@ -886,16 +873,16 @@ public function prepare($statement) * If the query is parametrized, a prepared statement is used. * If an SQLLogger is configured, the execution is logged. * - * @param string $query The SQL query to execute. - * @param array $params The parameters to bind to the query, if any. - * @param array $types The types the previous parameters are in. - * @param \Doctrine\DBAL\Cache\QueryCacheProfile|null $qcp The query cache profile, optional. + * @param string $query The SQL query to execute. + * @param array $params The parameters to bind to the query, if any. + * @param array $types The types the previous parameters are in. + * @param QueryCacheProfile|null $qcp The query cache profile, optional. * * @return ResultStatement The executed statement. * - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ - public function executeQuery($query, array $params = [], $types = [], QueryCacheProfile $qcp = null) + public function executeQuery($query, array $params = [], $types = [], ?QueryCacheProfile $qcp = null) { if ($qcp !== null) { return $this->executeCacheQuery($query, $params, $types, $qcp); @@ -910,7 +897,7 @@ public function executeQuery($query, array $params = [], $types = [], QueryCache try { if ($params) { - list($query, $params, $types) = SQLParserUtils::expandListParameters($query, $params, $types); + [$query, $params, $types] = SQLParserUtils::expandListParameters($query, $params, $types); $stmt = $this->_conn->prepare($query); if ($types) { @@ -922,7 +909,7 @@ public function executeQuery($query, array $params = [], $types = [], QueryCache } else { $stmt = $this->_conn->query($query); } - } catch (Exception $ex) { + } catch (Throwable $ex) { throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $query, $this->resolveParams($params, $types)); } @@ -938,23 +925,23 @@ public function executeQuery($query, array $params = [], $types = [], QueryCache /** * Executes a caching query. * - * @param string $query The SQL query to execute. - * @param array $params The parameters to bind to the query, if any. - * @param array $types The types the previous parameters are in. - * @param \Doctrine\DBAL\Cache\QueryCacheProfile $qcp The query cache profile. + * @param string $query The SQL query to execute. + * @param array $params The parameters to bind to the query, if any. + * @param array $types The types the previous parameters are in. + * @param QueryCacheProfile $qcp The query cache profile. * * @return ResultStatement * - * @throws \Doctrine\DBAL\Cache\CacheException + * @throws CacheException */ public function executeCacheQuery($query, $params, $types, QueryCacheProfile $qcp) { $resultCache = $qcp->getResultCacheDriver() ?: $this->_config->getResultCacheImpl(); - if ( ! $resultCache) { + if (! $resultCache) { throw CacheException::noResultDriverConfigured(); } - list($cacheKey, $realKey) = $qcp->generateCacheKeys($query, $params, $types, $this->getParams()); + [$cacheKey, $realKey] = $qcp->generateCacheKeys($query, $params, $types, $this->getParams()); // fetch the row pointers entry if ($data = $resultCache->fetch($cacheKey)) { @@ -966,7 +953,7 @@ public function executeCacheQuery($query, $params, $types, QueryCacheProfile $qc } } - if (!isset($stmt)) { + if (! isset($stmt)) { $stmt = new ResultCacheStatement($this->executeQuery($query, $params, $types), $resultCache, $cacheKey, $realKey, $qcp->getLifetime()); } @@ -979,9 +966,9 @@ public function executeCacheQuery($query, $params, $types, QueryCacheProfile $qc * Executes an, optionally parametrized, SQL query and returns the result, * applying a given projection/transformation function on each row of the result. * - * @param string $query The SQL query to execute. - * @param array $params The parameters, if any. - * @param \Closure $function The transformation function that is applied on each row. + * @param string $query The SQL query to execute. + * @param array $params The parameters, if any. + * @param Closure $function The transformation function that is applied on each row. * The function receives a single parameter, an array, that * represents a row of the result set. * @@ -990,7 +977,7 @@ public function executeCacheQuery($query, $params, $types, QueryCacheProfile $qc public function project($query, array $params, Closure $function) { $result = []; - $stmt = $this->executeQuery($query, $params); + $stmt = $this->executeQuery($query, $params); while ($row = $stmt->fetch()) { $result[] = $function($row); @@ -1006,7 +993,7 @@ public function project($query, array $params, Closure $function) * * @return \Doctrine\DBAL\Driver\Statement * - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ public function query() { @@ -1021,7 +1008,7 @@ public function query() try { $statement = $this->_conn->query(...$args); - } catch (Exception $ex) { + } catch (Throwable $ex) { throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $args[0]); } @@ -1046,7 +1033,7 @@ public function query() * * @return int The number of affected rows. * - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ public function executeUpdate($query, array $params = [], array $types = []) { @@ -1059,7 +1046,7 @@ public function executeUpdate($query, array $params = [], array $types = []) try { if ($params) { - list($query, $params, $types) = SQLParserUtils::expandListParameters($query, $params, $types); + [$query, $params, $types] = SQLParserUtils::expandListParameters($query, $params, $types); $stmt = $this->_conn->prepare($query); if ($types) { @@ -1072,7 +1059,7 @@ public function executeUpdate($query, array $params = [], array $types = []) } else { $result = $this->_conn->exec($query); } - } catch (Exception $ex) { + } catch (Throwable $ex) { throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $query, $this->resolveParams($params, $types)); } @@ -1090,7 +1077,7 @@ public function executeUpdate($query, array $params = [], array $types = []) * * @return int The number of affected rows. * - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ public function exec($statement) { @@ -1103,7 +1090,7 @@ public function exec($statement) try { $result = $this->_conn->exec($statement); - } catch (Exception $ex) { + } catch (Throwable $ex) { throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $statement); } @@ -1175,7 +1162,7 @@ public function lastInsertId($seqName = null) * If an exception occurs during execution of the function or transaction commit, * the transaction is rolled back and the exception re-thrown. * - * @param \Closure $func The function to execute transactionally. + * @param Closure $func The function to execute transactionally. * * @return mixed The value returned by $func * @@ -1205,7 +1192,7 @@ public function transactional(Closure $func) * * @return void * - * @throws \Doctrine\DBAL\ConnectionException + * @throws ConnectionException */ public function setNestTransactionsWithSavepoints($nestTransactionsWithSavepoints) { @@ -1213,7 +1200,7 @@ public function setNestTransactionsWithSavepoints($nestTransactionsWithSavepoint throw ConnectionException::mayNotAlterNestedTransactionWithSavepointsInTransaction(); } - if ( ! $this->getDatabasePlatform()->supportsSavepoints()) { + if (! $this->getDatabasePlatform()->supportsSavepoints()) { throw ConnectionException::savepointsNotSupported(); } @@ -1238,7 +1225,7 @@ public function getNestTransactionsWithSavepoints() */ protected function _getNestedTransactionSavePointName() { - return 'DOCTRINE2_SAVEPOINT_'.$this->_transactionNestingLevel; + return 'DOCTRINE2_SAVEPOINT_' . $this->_transactionNestingLevel; } /** @@ -1254,7 +1241,7 @@ public function beginTransaction() $logger = $this->_config->getSQLLogger(); - if ($this->_transactionNestingLevel == 1) { + if ($this->_transactionNestingLevel === 1) { if ($logger) { $logger->startQuery('"START TRANSACTION"'); } @@ -1278,12 +1265,12 @@ public function beginTransaction() * * @return void * - * @throws \Doctrine\DBAL\ConnectionException If the commit failed due to no active transaction or + * @throws ConnectionException If the commit failed due to no active transaction or * because the transaction was marked for rollback only. */ public function commit() { - if ($this->_transactionNestingLevel == 0) { + if ($this->_transactionNestingLevel === 0) { throw ConnectionException::noActiveTransaction(); } if ($this->_isRollbackOnly) { @@ -1294,7 +1281,7 @@ public function commit() $logger = $this->_config->getSQLLogger(); - if ($this->_transactionNestingLevel == 1) { + if ($this->_transactionNestingLevel === 1) { if ($logger) { $logger->startQuery('"COMMIT"'); } @@ -1314,9 +1301,11 @@ public function commit() --$this->_transactionNestingLevel; - if (false === $this->autoCommit && 0 === $this->_transactionNestingLevel) { - $this->beginTransaction(); + if ($this->autoCommit !== false || $this->_transactionNestingLevel !== 0) { + return; } + + $this->beginTransaction(); } /** @@ -1324,8 +1313,8 @@ public function commit() */ private function commitAll() { - while (0 !== $this->_transactionNestingLevel) { - if (false === $this->autoCommit && 1 === $this->_transactionNestingLevel) { + while ($this->_transactionNestingLevel !== 0) { + if ($this->autoCommit === false && $this->_transactionNestingLevel === 1) { // When in no auto-commit mode, the last nesting commit immediately starts a new transaction. // Therefore we need to do the final commit here and then leave to avoid an infinite loop. $this->commit(); @@ -1340,11 +1329,11 @@ private function commitAll() /** * Cancels any database changes done during the current transaction. * - * @throws \Doctrine\DBAL\ConnectionException If the rollback operation failed. + * @throws ConnectionException If the rollback operation failed. */ public function rollBack() { - if ($this->_transactionNestingLevel == 0) { + if ($this->_transactionNestingLevel === 0) { throw ConnectionException::noActiveTransaction(); } @@ -1352,7 +1341,7 @@ public function rollBack() $logger = $this->_config->getSQLLogger(); - if ($this->_transactionNestingLevel == 1) { + if ($this->_transactionNestingLevel === 1) { if ($logger) { $logger->startQuery('"ROLLBACK"'); } @@ -1363,7 +1352,7 @@ public function rollBack() $logger->stopQuery(); } - if (false === $this->autoCommit) { + if ($this->autoCommit === false) { $this->beginTransaction(); } } elseif ($this->_nestTransactionsWithSavepoints) { @@ -1388,11 +1377,11 @@ public function rollBack() * * @return void * - * @throws \Doctrine\DBAL\ConnectionException + * @throws ConnectionException */ public function createSavepoint($savepoint) { - if ( ! $this->getDatabasePlatform()->supportsSavepoints()) { + if (! $this->getDatabasePlatform()->supportsSavepoints()) { throw ConnectionException::savepointsNotSupported(); } @@ -1406,17 +1395,19 @@ public function createSavepoint($savepoint) * * @return void * - * @throws \Doctrine\DBAL\ConnectionException + * @throws ConnectionException */ public function releaseSavepoint($savepoint) { - if ( ! $this->getDatabasePlatform()->supportsSavepoints()) { + if (! $this->getDatabasePlatform()->supportsSavepoints()) { throw ConnectionException::savepointsNotSupported(); } - if ($this->platform->supportsReleaseSavepoints()) { - $this->_conn->exec($this->platform->releaseSavePoint($savepoint)); + if (! $this->platform->supportsReleaseSavepoints()) { + return; } + + $this->_conn->exec($this->platform->releaseSavePoint($savepoint)); } /** @@ -1426,11 +1417,11 @@ public function releaseSavepoint($savepoint) * * @return void * - * @throws \Doctrine\DBAL\ConnectionException + * @throws ConnectionException */ public function rollbackSavepoint($savepoint) { - if ( ! $this->getDatabasePlatform()->supportsSavepoints()) { + if (! $this->getDatabasePlatform()->supportsSavepoints()) { throw ConnectionException::savepointsNotSupported(); } @@ -1453,11 +1444,11 @@ public function getWrappedConnection() * Gets the SchemaManager that can be used to inspect or change the * database schema through the connection. * - * @return \Doctrine\DBAL\Schema\AbstractSchemaManager + * @return AbstractSchemaManager */ public function getSchemaManager() { - if ( ! $this->_schemaManager) { + if (! $this->_schemaManager) { $this->_schemaManager = $this->_driver->getSchemaManager($this); } @@ -1470,11 +1461,11 @@ public function getSchemaManager() * * @return void * - * @throws \Doctrine\DBAL\ConnectionException If no transaction is active. + * @throws ConnectionException If no transaction is active. */ public function setRollbackOnly() { - if ($this->_transactionNestingLevel == 0) { + if ($this->_transactionNestingLevel === 0) { throw ConnectionException::noActiveTransaction(); } $this->_isRollbackOnly = true; @@ -1485,11 +1476,11 @@ public function setRollbackOnly() * * @return bool * - * @throws \Doctrine\DBAL\ConnectionException If no transaction is active. + * @throws ConnectionException If no transaction is active. */ public function isRollbackOnly() { - if ($this->_transactionNestingLevel == 0) { + if ($this->_transactionNestingLevel === 0) { throw ConnectionException::noActiveTransaction(); } @@ -1528,14 +1519,14 @@ public function convertToPHPValue($value, $type) * Binds a set of parameters, some or all of which are typed with a PDO binding type * or DBAL mapping type, to a given statement. * + * @internal Duck-typing used on the $stmt parameter to support driver statements as well as + * raw PDOStatement instances. + * * @param \Doctrine\DBAL\Driver\Statement $stmt The statement to bind the values to. * @param array $params The map/list of named/positional parameters. * @param array $types The parameter types (PDO binding types or DBAL mapping types). * * @return void - * - * @internal Duck-typing used on the $stmt parameter to support driver statements as well as - * raw PDOStatement instances. */ private function _bindTypedValues($stmt, array $params, array $types) { @@ -1543,12 +1534,12 @@ private function _bindTypedValues($stmt, array $params, array $types) if (is_int(key($params))) { // Positional parameters $typeOffset = array_key_exists(0, $types) ? -1 : 0; - $bindIndex = 1; + $bindIndex = 1; foreach ($params as $value) { $typeIndex = $bindIndex + $typeOffset; if (isset($types[$typeIndex])) { - $type = $types[$typeIndex]; - list($value, $bindingType) = $this->getBindingInfo($value, $type); + $type = $types[$typeIndex]; + [$value, $bindingType] = $this->getBindingInfo($value, $type); $stmt->bindValue($bindIndex, $value, $bindingType); } else { $stmt->bindValue($bindIndex, $value); @@ -1559,8 +1550,8 @@ private function _bindTypedValues($stmt, array $params, array $types) // Named parameters foreach ($params as $name => $value) { if (isset($types[$name])) { - $type = $types[$name]; - list($value, $bindingType) = $this->getBindingInfo($value, $type); + $type = $types[$name]; + [$value, $bindingType] = $this->getBindingInfo($value, $type); $stmt->bindValue($name, $value, $bindingType); } else { $stmt->bindValue($name, $value); @@ -1583,7 +1574,7 @@ private function getBindingInfo($value, $type) $type = Type::getType($type); } if ($type instanceof Type) { - $value = $type->convertToDatabaseValue($value, $this->getDatabasePlatform()); + $value = $type->convertToDatabaseValue($value, $this->getDatabasePlatform()); $bindingType = $type->getBindingType(); } else { $bindingType = $type; @@ -1611,12 +1602,12 @@ public function resolveParams(array $params, array $types) if (is_int(key($params))) { // Positional parameters $typeOffset = array_key_exists(0, $types) ? -1 : 0; - $bindIndex = 1; + $bindIndex = 1; foreach ($params as $value) { $typeIndex = $bindIndex + $typeOffset; if (isset($types[$typeIndex])) { - $type = $types[$typeIndex]; - list($value,) = $this->getBindingInfo($value, $type); + $type = $types[$typeIndex]; + [$value] = $this->getBindingInfo($value, $type); $resolvedParams[$bindIndex] = $value; } else { $resolvedParams[$bindIndex] = $value; @@ -1627,8 +1618,8 @@ public function resolveParams(array $params, array $types) // Named parameters foreach ($params as $name => $value) { if (isset($types[$name])) { - $type = $types[$name]; - list($value,) = $this->getBindingInfo($value, $type); + $type = $types[$name]; + [$value] = $this->getBindingInfo($value, $type); $resolvedParams[$name] = $value; } else { $resolvedParams[$name] = $value; @@ -1642,7 +1633,7 @@ public function resolveParams(array $params, array $types) /** * Creates a new instance of a SQL query builder. * - * @return \Doctrine\DBAL\Query\QueryBuilder + * @return QueryBuilder */ public function createQueryBuilder() { @@ -1656,6 +1647,8 @@ public function createQueryBuilder() * It is responsibility of the developer to handle this case * and abort the request or reconnect manually: * + * @return bool + * * @example * * if ($conn->ping() === false) { @@ -1667,8 +1660,6 @@ public function createQueryBuilder() * or disconnect when the connection is not available anymore * as long it returns TRUE when a reconnect succeeded and * FALSE when the connection was dropped. - * - * @return bool */ public function ping() { diff --git a/lib/Doctrine/DBAL/ConnectionException.php b/lib/Doctrine/DBAL/ConnectionException.php index db94489668a..3d9c841bec8 100644 --- a/lib/Doctrine/DBAL/ConnectionException.php +++ b/lib/Doctrine/DBAL/ConnectionException.php @@ -4,8 +4,6 @@ /** * @link www.doctrine-project.org - * @since 2.0 - * @author Jonathan H. Wage - * @author Benjamin Eberlei */ class MasterSlaveConnection extends Connection { @@ -87,20 +85,17 @@ class MasterSlaveConnection extends Connection /** * Creates Master Slave Connection. * - * @param array $params - * @param \Doctrine\DBAL\Driver $driver - * @param \Doctrine\DBAL\Configuration|null $config - * @param \Doctrine\Common\EventManager|null $eventManager + * @param array $params * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ - public function __construct(array $params, Driver $driver, Configuration $config = null, EventManager $eventManager = null) + public function __construct(array $params, Driver $driver, ?Configuration $config = null, ?EventManager $eventManager = null) { if (! isset($params['slaves'], $params['master'])) { - throw new \InvalidArgumentException('master or slaves configuration missing'); + throw new InvalidArgumentException('master or slaves configuration missing'); } - if (count($params['slaves']) == 0) { - throw new \InvalidArgumentException('You have to configure at least one slaves.'); + if (count($params['slaves']) === 0) { + throw new InvalidArgumentException('You have to configure at least one slaves.'); } $params['master']['driver'] = $params['driver']; @@ -132,13 +127,13 @@ public function connect($connectionName = null) $connectionName = $connectionName ?: 'slave'; if ($connectionName !== 'slave' && $connectionName !== 'master') { - throw new \InvalidArgumentException("Invalid option to connect(), only master or slave allowed."); + throw new InvalidArgumentException('Invalid option to connect(), only master or slave allowed.'); } // 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 (isset($this->_conn) && $this->_conn && ! $requestedConnectionChange) { return false; } @@ -163,7 +158,7 @@ public function connect($connectionName = null) $this->connections['master'] = $this->_conn = $this->connectTo($connectionName); // Set slave connection to master to avoid invalid reads - if ( ! $this->keepSlave) { + if (! $this->keepSlave) { $this->connections['slave'] = $this->connections['master']; } } else { @@ -193,7 +188,7 @@ protected function connectTo($connectionName) $connectionParams = $this->chooseConnectionConfiguration($connectionName, $params); - $user = $connectionParams['user'] ?? null; + $user = $connectionParams['user'] ?? null; $password = $connectionParams['password'] ?? null; return $this->_driver->connect($connectionParams, $user, $password, $driverOptions); @@ -213,7 +208,7 @@ protected function chooseConnectionConfiguration($connectionName, $params) $config = $params['slaves'][array_rand($params['slaves'])]; - if ( ! isset($config['charset']) && isset($params['master']['charset'])) { + if (! isset($config['charset']) && isset($params['master']['charset'])) { $config['charset'] = $params['master']['charset']; } @@ -279,7 +274,7 @@ public function close() parent::close(); - $this->_conn = null; + $this->_conn = null; $this->connections = ['master' => null, 'slave' => null]; } diff --git a/lib/Doctrine/DBAL/DBALException.php b/lib/Doctrine/DBAL/DBALException.php index 72413141e4a..8acf6aa1e3f 100644 --- a/lib/Doctrine/DBAL/DBALException.php +++ b/lib/Doctrine/DBAL/DBALException.php @@ -2,20 +2,25 @@ namespace Doctrine\DBAL; -use Doctrine\DBAL\Exception; -use Doctrine\DBAL\Driver; +use Doctrine\DBAL\Driver\DriverException as DriverExceptionInterface; use Doctrine\DBAL\Driver\ExceptionConverterDriver; +use Doctrine\DBAL\Exception\DriverException; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Exception; +use Throwable; use function array_map; use function bin2hex; +use function get_class; +use function gettype; use function implode; +use function is_object; use function is_resource; use function is_string; use function json_encode; use function sprintf; use function str_split; -class DBALException extends \Exception +class DBALException extends Exception { /** * @param string $method @@ -30,8 +35,9 @@ public static function notSupported($method) public static function invalidPlatformSpecified() : self { return new self( - "Invalid 'platform' option specified, need to give an instance of ". - "\Doctrine\DBAL\Platforms\AbstractPlatform."); + "Invalid 'platform' option specified, need to give an instance of " . + '\Doctrine\DBAL\Platforms\AbstractPlatform.' + ); } /** @@ -39,12 +45,12 @@ public static function invalidPlatformSpecified() : self */ public static function invalidPlatformType($invalidPlatform) : self { - if (\is_object($invalidPlatform)) { + if (is_object($invalidPlatform)) { return new self( sprintf( "Option 'platform' must be a subtype of '%s', instance of '%s' given", AbstractPlatform::class, - \get_class($invalidPlatform) + get_class($invalidPlatform) ) ); } @@ -53,7 +59,7 @@ public static function invalidPlatformType($invalidPlatform) : self sprintf( "Option 'platform' must be an object and subtype of '%s'. Got '%s'", AbstractPlatform::class, - \gettype($invalidPlatform) + gettype($invalidPlatform) ) ); } @@ -84,8 +90,8 @@ public static function invalidPlatformVersionSpecified($version, $expectedFormat public static function invalidPdoInstance() { return new self( - "The 'pdo' option was used in DriverManager::getConnection() but no ". - "instance of PDO was given." + "The 'pdo' option was used in DriverManager::getConnection() but no " . + 'instance of PDO was given.' ); } @@ -100,14 +106,14 @@ public static function driverRequired($url = null) return new self( sprintf( "The options 'driver' or 'driverClass' are mandatory if a connection URL without scheme " . - "is given to DriverManager::getConnection(). Given URL: %s", + 'is given to DriverManager::getConnection(). Given URL: %s', $url ) ); } - return new self("The options 'driver' or 'driverClass' are mandatory if no PDO ". - "instance is given to DriverManager::getConnection()."); + return new self("The options 'driver' or 'driverClass' are mandatory if no PDO " . + 'instance is given to DriverManager::getConnection().'); } /** @@ -118,52 +124,49 @@ public static function driverRequired($url = null) */ public static function unknownDriver($unknownDriverName, array $knownDrivers) { - return new self("The given 'driver' ".$unknownDriverName." is unknown, ". - "Doctrine currently supports only the following drivers: ".implode(", ", $knownDrivers)); + return new self("The given 'driver' " . $unknownDriverName . ' is unknown, ' . + 'Doctrine currently supports only the following drivers: ' . implode(', ', $knownDrivers)); } /** - * @param \Doctrine\DBAL\Driver $driver - * @param \Exception $driverEx - * @param string $sql - * @param array $params + * @param Exception $driverEx + * @param string $sql + * @param array $params * * @return \Doctrine\DBAL\DBALException */ - public static function driverExceptionDuringQuery(Driver $driver, \Exception $driverEx, $sql, array $params = []) + public static function driverExceptionDuringQuery(Driver $driver, Throwable $driverEx, $sql, array $params = []) { - $msg = "An exception occurred while executing '".$sql."'"; + $msg = "An exception occurred while executing '" . $sql . "'"; if ($params) { - $msg .= " with params " . self::formatParameters($params); + $msg .= ' with params ' . self::formatParameters($params); } - $msg .= ":\n\n".$driverEx->getMessage(); + $msg .= ":\n\n" . $driverEx->getMessage(); return static::wrapException($driver, $driverEx, $msg); } /** - * @param \Doctrine\DBAL\Driver $driver - * @param \Exception $driverEx + * @param Exception $driverEx * * @return \Doctrine\DBAL\DBALException */ - public static function driverException(Driver $driver, \Exception $driverEx) + public static function driverException(Driver $driver, Throwable $driverEx) { - return static::wrapException($driver, $driverEx, "An exception occurred in driver: " . $driverEx->getMessage()); + return static::wrapException($driver, $driverEx, 'An exception occurred in driver: ' . $driverEx->getMessage()); } /** - * @param \Doctrine\DBAL\Driver $driver - * @param \Exception $driverEx + * @param Exception $driverEx * * @return \Doctrine\DBAL\DBALException */ - private static function wrapException(Driver $driver, \Exception $driverEx, $msg) + private static function wrapException(Driver $driver, Throwable $driverEx, $msg) { - if ($driverEx instanceof Exception\DriverException) { + if ($driverEx instanceof DriverException) { return $driverEx; } - if ($driver instanceof ExceptionConverterDriver && $driverEx instanceof Driver\DriverException) { + if ($driver instanceof ExceptionConverterDriver && $driverEx instanceof DriverExceptionInterface) { return $driver->convertException($msg, $driverEx); } @@ -180,14 +183,14 @@ private static function wrapException(Driver $driver, \Exception $driverEx, $msg */ private static function formatParameters(array $params) { - return '[' . implode(', ', array_map(function ($param) { + return '[' . implode(', ', array_map(static function ($param) { if (is_resource($param)) { return (string) $param; } - + $json = @json_encode($param); - if (! is_string($json) || $json == 'null' && is_string($param)) { + 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)) . '"'; } @@ -203,8 +206,8 @@ private static function formatParameters(array $params) */ public static function invalidWrapperClass($wrapperClass) { - return new self("The given 'wrapperClass' ".$wrapperClass." has to be a ". - "subtype of \Doctrine\DBAL\Connection."); + return new self("The given 'wrapperClass' " . $wrapperClass . ' has to be a ' . + 'subtype of \Doctrine\DBAL\Connection.'); } /** @@ -214,8 +217,8 @@ public static function invalidWrapperClass($wrapperClass) */ public static function invalidDriverClass($driverClass) { - return new self("The given 'driverClass' ".$driverClass." has to implement the ". - "\Doctrine\DBAL\Driver interface."); + return new self("The given 'driverClass' " . $driverClass . ' has to implement the ' . + '\Doctrine\DBAL\Driver interface.'); } /** @@ -225,7 +228,7 @@ public static function invalidDriverClass($driverClass) */ public static function invalidTableName($tableName) { - return new self("Invalid table name specified: ".$tableName); + return new self('Invalid table name specified: ' . $tableName); } /** @@ -235,7 +238,7 @@ public static function invalidTableName($tableName) */ public static function noColumnsSpecifiedForTable($tableName) { - return new self("No columns specified for table ".$tableName); + return new self('No columns specified for table ' . $tableName); } /** @@ -243,7 +246,7 @@ public static function noColumnsSpecifiedForTable($tableName) */ public static function limitOffsetInvalid() { - return new self("Invalid Offset in Limit Query, it has to be larger than or equal to 0."); + return new self('Invalid Offset in Limit Query, it has to be larger than or equal to 0.'); } /** @@ -253,7 +256,7 @@ public static function limitOffsetInvalid() */ public static function typeExists($name) { - return new self('Type '.$name.' already exists.'); + return new self('Type ' . $name . ' already exists.'); } /** @@ -263,14 +266,13 @@ public static function typeExists($name) */ public static function unknownColumnType($name) { - return new self('Unknown column type "'.$name.'" requested. Any Doctrine type that you use has ' . + return new self('Unknown column type "' . $name . '" requested. Any Doctrine type that you use has ' . 'to be registered with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the ' . 'known types with \Doctrine\DBAL\Types\Type::getTypesMap(). If this error occurs during database ' . 'introspection then you might have forgotten to register all database types for a Doctrine Type. Use ' . 'AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement ' . 'Type#getMappedDatabaseTypes(). If the type name is empty you might ' . - 'have a problem with the cache or forgot some mapping information.' - ); + 'have a problem with the cache or forgot some mapping information.'); } /** @@ -280,6 +282,6 @@ public static function unknownColumnType($name) */ public static function typeNotFound($name) { - return new self('Type to be overwritten '.$name.' does not exist.'); + return new self('Type to be overwritten ' . $name . ' does not exist.'); } } diff --git a/lib/Doctrine/DBAL/Driver.php b/lib/Doctrine/DBAL/Driver.php index 9bd58e80070..22e9c6781e5 100644 --- a/lib/Doctrine/DBAL/Driver.php +++ b/lib/Doctrine/DBAL/Driver.php @@ -2,11 +2,12 @@ namespace Doctrine\DBAL; +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Schema\AbstractSchemaManager; + /** * Driver interface. * Interface that all DBAL drivers must implement. - * - * @since 2.0 */ interface Driver { @@ -26,7 +27,7 @@ public function connect(array $params, $username = null, $password = null, array * Gets the DatabasePlatform instance that provides all the metadata about * the platform this driver connects to. * - * @return \Doctrine\DBAL\Platforms\AbstractPlatform The database platform. + * @return AbstractPlatform The database platform. */ public function getDatabasePlatform(); @@ -34,9 +35,7 @@ public function getDatabasePlatform(); * Gets the SchemaManager that can be used to inspect and change the underlying * database schema of the platform this driver connects to. * - * @param \Doctrine\DBAL\Connection $conn - * - * @return \Doctrine\DBAL\Schema\AbstractSchemaManager + * @return AbstractSchemaManager */ public function getSchemaManager(Connection $conn); @@ -50,8 +49,6 @@ public function getName(); /** * Gets the name of the database connected to for this driver. * - * @param \Doctrine\DBAL\Connection $conn - * * @return string The name of the database. */ public function getDatabase(Connection $conn); diff --git a/lib/Doctrine/DBAL/Driver/AbstractDB2Driver.php b/lib/Doctrine/DBAL/Driver/AbstractDB2Driver.php index ad157f03830..a58fc339802 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractDB2Driver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractDB2Driver.php @@ -2,6 +2,7 @@ namespace Doctrine\DBAL\Driver; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Platforms\DB2Platform; use Doctrine\DBAL\Schema\DB2SchemaManager; @@ -9,16 +10,14 @@ /** * Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for IBM DB2 based drivers. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ abstract class AbstractDB2Driver implements Driver { /** * {@inheritdoc} */ - public function getDatabase(\Doctrine\DBAL\Connection $conn) + public function getDatabase(Connection $conn) { $params = $conn->getParams(); @@ -36,7 +35,7 @@ public function getDatabasePlatform() /** * {@inheritdoc} */ - public function getSchemaManager(\Doctrine\DBAL\Connection $conn) + public function getSchemaManager(Connection $conn) { return new DB2SchemaManager($conn); } diff --git a/lib/Doctrine/DBAL/Driver/AbstractDriverException.php b/lib/Doctrine/DBAL/Driver/AbstractDriverException.php index d34ca5cdd93..b42159181b3 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractDriverException.php +++ b/lib/Doctrine/DBAL/Driver/AbstractDriverException.php @@ -2,14 +2,14 @@ namespace Doctrine\DBAL\Driver; +use Exception; + /** * Abstract base implementation of the {@link DriverException} interface. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ -abstract class AbstractDriverException extends \Exception implements DriverException +abstract class AbstractDriverException extends Exception implements DriverException { /** * The driver specific error code. @@ -26,8 +26,6 @@ abstract class AbstractDriverException extends \Exception implements DriverExcep private $sqlState; /** - * Constructor. - * * @param string $message The driver error message. * @param string|null $sqlState The SQLSTATE the driver is in at the time the error occurred, if any. * @param int|string|null $errorCode The driver specific error code if any. diff --git a/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php b/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php index 031a84dce04..97d97b57d62 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php @@ -2,6 +2,7 @@ namespace Doctrine\DBAL\Driver; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Exception; @@ -18,9 +19,7 @@ /** * Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for MySQL based drivers. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver, VersionAwarePlatformDriver { @@ -116,7 +115,7 @@ public function convertException($message, DriverException $exception) */ public function createDatabasePlatformForVersion($version) { - $mariadb = false !== stripos($version, 'mariadb'); + $mariadb = stripos($version, 'mariadb') !== false; if ($mariadb && version_compare($this->getMariaDbMysqlVersionNumber($version), '10.2.7', '>=')) { return new MariaDb1027Platform(); } @@ -139,11 +138,12 @@ public function createDatabasePlatformForVersion($version) * returned by Oracle MySQL servers. * * @param string $versionString Version string returned by the driver, i.e. '5.7.10' + * * @throws DBALException */ private function getOracleMysqlVersionNumber(string $versionString) : string { - if ( ! preg_match( + if (! preg_match( '/^(?P\d+)(?:\.(?P\d+)(?:\.(?P\d+))?)?/', $versionString, $versionParts @@ -157,7 +157,7 @@ private function getOracleMysqlVersionNumber(string $versionString) : string $minorVersion = $versionParts['minor'] ?? 0; $patchVersion = $versionParts['patch'] ?? null; - if ('5' === $majorVersion && '7' === $minorVersion && null === $patchVersion) { + if ($majorVersion === '5' && $minorVersion === '7' && $patchVersion === null) { $patchVersion = '9'; } @@ -169,11 +169,12 @@ private function getOracleMysqlVersionNumber(string $versionString) : string * that starts with the prefix '5.5.5-' * * @param string $versionString Version string as returned by mariadb server, i.e. '5.5.5-Mariadb-10.0.8-xenial' + * * @throws DBALException */ private function getMariaDbMysqlVersionNumber(string $versionString) : string { - if ( ! preg_match( + if (! preg_match( '/^(?:5\.5\.5-)?(mariadb-)?(?P\d+)\.(?P\d+)\.(?P\d+)/i', $versionString, $versionParts @@ -190,7 +191,7 @@ private function getMariaDbMysqlVersionNumber(string $versionString) : string /** * {@inheritdoc} */ - public function getDatabase(\Doctrine\DBAL\Connection $conn) + public function getDatabase(Connection $conn) { $params = $conn->getParams(); @@ -199,6 +200,7 @@ public function getDatabase(\Doctrine\DBAL\Connection $conn) /** * {@inheritdoc} + * * @return MySqlPlatform */ public function getDatabasePlatform() @@ -208,9 +210,10 @@ public function getDatabasePlatform() /** * {@inheritdoc} + * * @return MySqlSchemaManager */ - public function getSchemaManager(\Doctrine\DBAL\Connection $conn) + public function getSchemaManager(Connection $conn) { return new MySqlSchemaManager($conn); } diff --git a/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php b/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php index 7ebb54a73b7..0a8771f117f 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php @@ -2,6 +2,7 @@ namespace Doctrine\DBAL\Driver; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\AbstractOracleDriver\EasyConnectString; use Doctrine\DBAL\Exception; @@ -11,9 +12,7 @@ /** * Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for Oracle based drivers. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ abstract class AbstractOracleDriver implements Driver, ExceptionConverterDriver { @@ -63,7 +62,7 @@ public function convertException($message, DriverException $exception) /** * {@inheritdoc} */ - public function getDatabase(\Doctrine\DBAL\Connection $conn) + public function getDatabase(Connection $conn) { $params = $conn->getParams(); @@ -81,7 +80,7 @@ public function getDatabasePlatform() /** * {@inheritdoc} */ - public function getSchemaManager(\Doctrine\DBAL\Connection $conn) + public function getSchemaManager(Connection $conn) { return new OracleSchemaManager($conn); } diff --git a/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php b/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php index 5947ec59edf..bab33e0f95f 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php @@ -2,6 +2,7 @@ namespace Doctrine\DBAL\Driver; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Exception; @@ -19,9 +20,7 @@ /** * Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for PostgreSQL based drivers. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ abstract class AbstractPostgreSQLDriver implements Driver, ExceptionConverterDriver, VersionAwarePlatformDriver { @@ -87,7 +86,7 @@ public function convertException($message, DriverException $exception) */ public function createDatabasePlatformForVersion($version) { - if ( ! preg_match('/^(?P\d+)(?:\.(?P\d+)(?:\.(?P\d+))?)?/', $version, $versionParts)) { + if (! preg_match('/^(?P\d+)(?:\.(?P\d+)(?:\.(?P\d+))?)?/', $version, $versionParts)) { throw DBALException::invalidPlatformVersionSpecified( $version, '..' @@ -99,7 +98,7 @@ public function createDatabasePlatformForVersion($version) $patchVersion = $versionParts['patch'] ?? 0; $version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion; - switch(true) { + switch (true) { case version_compare($version, '10.0', '>='): return new PostgreSQL100Platform(); case version_compare($version, '9.4', '>='): @@ -116,7 +115,7 @@ public function createDatabasePlatformForVersion($version) /** * {@inheritdoc} */ - public function getDatabase(\Doctrine\DBAL\Connection $conn) + public function getDatabase(Connection $conn) { $params = $conn->getParams(); @@ -134,7 +133,7 @@ public function getDatabasePlatform() /** * {@inheritdoc} */ - public function getSchemaManager(\Doctrine\DBAL\Connection $conn) + public function getSchemaManager(Connection $conn) { return new PostgreSqlSchemaManager($conn); } diff --git a/lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php b/lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php index c3311a15f02..2d5d196238a 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php @@ -2,6 +2,7 @@ namespace Doctrine\DBAL\Driver; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Exception; @@ -17,9 +18,7 @@ /** * Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for SAP Sybase SQL Anywhere based drivers. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ abstract class AbstractSQLAnywhereDriver implements Driver, ExceptionConverterDriver, VersionAwarePlatformDriver { @@ -73,7 +72,7 @@ public function convertException($message, DriverException $exception) */ public function createDatabasePlatformForVersion($version) { - if ( ! preg_match( + if (! preg_match( '/^(?P\d+)(?:\.(?P\d+)(?:\.(?P\d+)(?:\.(?P\d+))?)?)?/', $version, $versionParts @@ -90,7 +89,7 @@ public function createDatabasePlatformForVersion($version) $buildVersion = $versionParts['build'] ?? 0; $version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion . '.' . $buildVersion; - switch(true) { + switch (true) { case version_compare($version, '16', '>='): return new SQLAnywhere16Platform(); case version_compare($version, '12', '>='): @@ -105,7 +104,7 @@ public function createDatabasePlatformForVersion($version) /** * {@inheritdoc} */ - public function getDatabase(\Doctrine\DBAL\Connection $conn) + public function getDatabase(Connection $conn) { $params = $conn->getParams(); @@ -123,7 +122,7 @@ public function getDatabasePlatform() /** * {@inheritdoc} */ - public function getSchemaManager(\Doctrine\DBAL\Connection $conn) + public function getSchemaManager(Connection $conn) { return new SQLAnywhereSchemaManager($conn); } diff --git a/lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver.php b/lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver.php index 2097fe4c2bf..0df1ec62efa 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver.php @@ -2,6 +2,7 @@ namespace Doctrine\DBAL\Driver; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Platforms\SQLServer2005Platform; @@ -16,9 +17,7 @@ /** * Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for Microsoft SQL Server based drivers. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ abstract class AbstractSQLServerDriver implements Driver, VersionAwarePlatformDriver { @@ -27,7 +26,7 @@ abstract class AbstractSQLServerDriver implements Driver, VersionAwarePlatformDr */ public function createDatabasePlatformForVersion($version) { - if ( ! preg_match( + if (! preg_match( '/^(?P\d+)(?:\.(?P\d+)(?:\.(?P\d+)(?:\.(?P\d+))?)?)?/', $version, $versionParts @@ -44,7 +43,7 @@ public function createDatabasePlatformForVersion($version) $buildVersion = $versionParts['build'] ?? 0; $version = $majorVersion . '.' . $minorVersion . '.' . $patchVersion . '.' . $buildVersion; - switch(true) { + switch (true) { case version_compare($version, '11.00.2100', '>='): return new SQLServer2012Platform(); case version_compare($version, '10.00.1600', '>='): @@ -59,7 +58,7 @@ public function createDatabasePlatformForVersion($version) /** * {@inheritdoc} */ - public function getDatabase(\Doctrine\DBAL\Connection $conn) + public function getDatabase(Connection $conn) { $params = $conn->getParams(); @@ -78,7 +77,7 @@ public function getDatabasePlatform() * {@inheritdoc} */ - public function getSchemaManager(\Doctrine\DBAL\Connection $conn) + public function getSchemaManager(Connection $conn) { return new SQLServerSchemaManager($conn); } diff --git a/lib/Doctrine/DBAL/Driver/AbstractSQLiteDriver.php b/lib/Doctrine/DBAL/Driver/AbstractSQLiteDriver.php index f8eb73af238..a5a22b12ea9 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractSQLiteDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractSQLiteDriver.php @@ -2,6 +2,7 @@ namespace Doctrine\DBAL\Driver; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\SqlitePlatform; @@ -11,9 +12,7 @@ /** * Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for SQLite based drivers. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ abstract class AbstractSQLiteDriver implements Driver, ExceptionConverterDriver { @@ -76,7 +75,7 @@ public function convertException($message, DriverException $exception) /** * {@inheritdoc} */ - public function getDatabase(\Doctrine\DBAL\Connection $conn) + public function getDatabase(Connection $conn) { $params = $conn->getParams(); @@ -94,7 +93,7 @@ public function getDatabasePlatform() /** * {@inheritdoc} */ - public function getSchemaManager(\Doctrine\DBAL\Connection $conn) + public function getSchemaManager(Connection $conn) { return new SqliteSchemaManager($conn); } diff --git a/lib/Doctrine/DBAL/Driver/Connection.php b/lib/Doctrine/DBAL/Driver/Connection.php index 31e8b2277d3..d9ce4b4b5d3 100644 --- a/lib/Doctrine/DBAL/Driver/Connection.php +++ b/lib/Doctrine/DBAL/Driver/Connection.php @@ -9,8 +9,6 @@ * Driver connections must implement this interface. * * This resembles (a subset of) the PDO interface. - * - * @since 2.0 */ interface Connection { @@ -26,7 +24,7 @@ public function prepare($prepareString); /** * Executes an SQL statement, returning a result set as a Statement object. * - * @return \Doctrine\DBAL\Driver\Statement + * @return Statement */ public function query(); diff --git a/lib/Doctrine/DBAL/Driver/DriverException.php b/lib/Doctrine/DBAL/Driver/DriverException.php index c020c295169..d23cc3f3081 100644 --- a/lib/Doctrine/DBAL/Driver/DriverException.php +++ b/lib/Doctrine/DBAL/Driver/DriverException.php @@ -2,17 +2,17 @@ namespace Doctrine\DBAL\Driver; +use Throwable; + /** * Contract for a driver exception. * * Driver exceptions provide the SQLSTATE of the driver * and the driver specific error code at the time the error occurred. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ -interface DriverException extends \Throwable +interface DriverException extends Throwable { /** * Returns the driver specific error code if available. diff --git a/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Connection.php b/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Connection.php index e2b54471312..4089ab26e11 100644 --- a/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Connection.php +++ b/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Connection.php @@ -2,12 +2,10 @@ namespace Doctrine\DBAL\Driver\DrizzlePDOMySql; +use Doctrine\DBAL\Driver\PDOConnection; use Doctrine\DBAL\ParameterType; -/** - * @author Kim Hemsø Rasmussen - */ -class Connection extends \Doctrine\DBAL\Driver\PDOConnection +class Connection extends PDOConnection { /** * {@inheritdoc} diff --git a/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Driver.php b/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Driver.php index 202dbf80cdd..851f0ee23c4 100644 --- a/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Driver.php +++ b/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Driver.php @@ -7,8 +7,6 @@ /** * Drizzle driver using PDO MySql. - * - * @author Kim Hemsø Rasmussen */ class Driver extends \Doctrine\DBAL\Driver\PDOMySql\Driver { @@ -17,14 +15,12 @@ class Driver extends \Doctrine\DBAL\Driver\PDOMySql\Driver */ public function connect(array $params, $username = null, $password = null, array $driverOptions = []) { - $conn = new Connection( + return new Connection( $this->constructPdoDsn($params), $username, $password, $driverOptions ); - - return $conn; } /** diff --git a/lib/Doctrine/DBAL/Driver/ExceptionConverterDriver.php b/lib/Doctrine/DBAL/Driver/ExceptionConverterDriver.php index 77264e6e9f1..fd594c2ad79 100644 --- a/lib/Doctrine/DBAL/Driver/ExceptionConverterDriver.php +++ b/lib/Doctrine/DBAL/Driver/ExceptionConverterDriver.php @@ -5,10 +5,7 @@ /** * Contract for a driver that is capable of converting DBAL driver exceptions into standardized DBAL driver exceptions. * - * @author Benjamin Eberlei - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ interface ExceptionConverterDriver { @@ -18,8 +15,8 @@ interface ExceptionConverterDriver * It evaluates the vendor specific error code and SQLSTATE and transforms * it into a unified {@link Doctrine\DBAL\Exception\DriverException} subclass. * - * @param string $message The DBAL exception message to use. - * @param \Doctrine\DBAL\Driver\DriverException $exception The DBAL driver exception to convert. + * @param string $message The DBAL exception message to use. + * @param DriverException $exception The DBAL driver exception to convert. * * @return \Doctrine\DBAL\Exception\DriverException An instance of one of the DriverException subclasses. */ diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php index 26d84eaa6fa..fbd369e8483 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php @@ -26,9 +26,7 @@ class DB2Connection implements Connection, ServerInfoAwareConnection { - /** - * @var resource - */ + /** @var resource */ private $_conn = null; /** @@ -37,18 +35,18 @@ class DB2Connection implements Connection, ServerInfoAwareConnection * @param string $password * @param array $driverOptions * - * @throws \Doctrine\DBAL\Driver\IBMDB2\DB2Exception + * @throws DB2Exception */ public function __construct(array $params, $username, $password, $driverOptions = []) { - $isPersistent = (isset($params['persistent']) && $params['persistent'] == true); + $isPersistent = (isset($params['persistent']) && $params['persistent'] === true); if ($isPersistent) { $this->_conn = db2_pconnect($params['dbname'], $username, $password, $driverOptions); } else { $this->_conn = db2_connect($params['dbname'], $username, $password, $driverOptions); } - if ( ! $this->_conn) { + if (! $this->_conn) { throw new DB2Exception(db2_conn_errormsg()); } } @@ -78,7 +76,7 @@ public function requiresQueryForServerVersion() public function prepare($sql) { $stmt = @db2_prepare($this->_conn, $sql); - if ( ! $stmt) { + if (! $stmt) { throw new DB2Exception(db2_stmt_errormsg()); } @@ -91,7 +89,7 @@ public function prepare($sql) public function query() { $args = func_get_args(); - $sql = $args[0]; + $sql = $args[0]; $stmt = $this->prepare($sql); $stmt->execute(); @@ -109,7 +107,7 @@ public function quote($input, $type = ParameterType::STRING) return $input; } - return "'".$input."'"; + return "'" . $input . "'"; } /** @@ -119,7 +117,7 @@ public function exec($statement) { $stmt = @db2_exec($this->_conn, $statement); - if (false === $stmt) { + if ($stmt === false) { throw new DB2Exception(db2_stmt_errormsg()); } @@ -147,7 +145,7 @@ public function beginTransaction() */ public function commit() { - if (!db2_commit($this->_conn)) { + if (! db2_commit($this->_conn)) { throw new DB2Exception(db2_conn_errormsg($this->_conn)); } db2_autocommit($this->_conn, DB2_AUTOCOMMIT_ON); @@ -158,7 +156,7 @@ public function commit() */ public function rollBack() { - if (!db2_rollback($this->_conn)) { + if (! db2_rollback($this->_conn)) { throw new DB2Exception(db2_conn_errormsg($this->_conn)); } db2_autocommit($this->_conn, DB2_AUTOCOMMIT_ON); diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php index 247247ec151..712cbe419f3 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Driver.php @@ -6,9 +6,6 @@ /** * IBM DB2 Driver. - * - * @since 2.0 - * @author Benjamin Eberlei */ class DB2Driver extends AbstractDB2Driver { @@ -17,18 +14,18 @@ class DB2Driver extends AbstractDB2Driver */ public function connect(array $params, $username = null, $password = null, array $driverOptions = []) { - if ( ! isset($params['protocol'])) { + if (! isset($params['protocol'])) { $params['protocol'] = 'TCPIP'; } - if ($params['host'] !== 'localhost' && $params['host'] != '127.0.0.1') { + if ($params['host'] !== 'localhost' && $params['host'] !== '127.0.0.1') { // if the host isn't localhost, use extended connection params $params['dbname'] = 'DRIVER={IBM DB2 ODBC DRIVER}' . ';DATABASE=' . $params['dbname'] . ';HOSTNAME=' . $params['host'] . ';PROTOCOL=' . $params['protocol'] . - ';UID=' . $username . - ';PWD=' . $password .';'; + ';UID=' . $username . + ';PWD=' . $password . ';'; if (isset($params['port'])) { $params['dbname'] .= 'PORT=' . $params['port']; } diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Exception.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Exception.php index 1381904cf10..b01c4552a23 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Exception.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Exception.php @@ -2,6 +2,8 @@ namespace Doctrine\DBAL\Driver\IBMDB2; -class DB2Exception extends \Exception +use Exception; + +class DB2Exception extends Exception { } diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php index 512ff5e1f4e..181815b522d 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php @@ -6,6 +6,13 @@ use Doctrine\DBAL\Driver\StatementIterator; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; +use IteratorAggregate; +use PDO; +use ReflectionClass; +use ReflectionObject; +use ReflectionProperty; +use stdClass; +use const CASE_LOWER; use const DB2_CHAR; use const DB2_LONG; use const DB2_PARAM_IN; @@ -30,31 +37,21 @@ use function sprintf; use function strtolower; -class DB2Statement implements \IteratorAggregate, Statement +class DB2Statement implements IteratorAggregate, Statement { - /** - * @var resource - */ + /** @var resource */ private $_stmt; - /** - * @var array - */ + /** @var array */ private $_bindParam = []; - /** - * @var string Name of the default class to instantiate when fetching class instances. - */ + /** @var string Name of the default class to instantiate when fetching class instances. */ private $defaultFetchClass = '\stdClass'; - /** - * @var mixed[] Constructor arguments for the default class to instantiate when fetching class instances. - */ + /** @var mixed[] Constructor arguments for the default class to instantiate when fetching class instances. */ private $defaultFetchClassCtorArgs = []; - /** - * @var int - */ + /** @var int */ private $_defaultFetchMode = FetchMode::MIXED; /** @@ -103,7 +100,7 @@ public function bindParam($column, &$variable, $type = ParameterType::STRING, $l $type = DB2_CHAR; } - if (!db2_bind_param($this->_stmt, $column, "variable", DB2_PARAM_IN, $type)) { + if (! db2_bind_param($this->_stmt, $column, 'variable', DB2_PARAM_IN, $type)) { throw new DB2Exception(db2_stmt_errormsg()); } @@ -115,13 +112,13 @@ public function bindParam($column, &$variable, $type = ParameterType::STRING, $l */ public function closeCursor() { - if ( ! $this->_stmt) { + if (! $this->_stmt) { return false; } $this->_bindParam = []; - if (!db2_free_result($this->_stmt)) { + if (! db2_free_result($this->_stmt)) { return false; } @@ -135,7 +132,7 @@ public function closeCursor() */ public function columnCount() { - if ( ! $this->_stmt) { + if (! $this->_stmt) { return false; } @@ -166,7 +163,7 @@ public function errorInfo() */ public function execute($params = null) { - if ( ! $this->_stmt) { + if (! $this->_stmt) { return false; } @@ -214,11 +211,11 @@ public function getIterator() /** * {@inheritdoc} */ - public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) + public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0) { // 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->result) { return false; } @@ -245,7 +242,7 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE $result = db2_fetch_object($this->_stmt); - if ($result instanceof \stdClass) { + if ($result instanceof stdClass) { $result = $this->castObject($result, $className, $ctorArgs); } @@ -296,7 +293,7 @@ public function fetchColumn($columnIndex = 0) { $row = $this->fetch(FetchMode::NUMERIC); - if (false === $row) { + if ($row === false) { return false; } @@ -308,13 +305,13 @@ public function fetchColumn($columnIndex = 0) */ public function rowCount() { - return (@db2_num_rows($this->_stmt)) ? : 0; + return @db2_num_rows($this->_stmt) ? : 0; } /** * Casts a stdClass object to the given class name mapping its' properties. * - * @param \stdClass $sourceObject Object to cast from. + * @param stdClass $sourceObject Object to cast from. * @param string|object $destinationClass Name of the class or class instance to cast to. * @param array $ctorArgs Arguments to use for constructing the destination class instance. * @@ -322,23 +319,24 @@ public function rowCount() * * @throws DB2Exception */ - private function castObject(\stdClass $sourceObject, $destinationClass, array $ctorArgs = []) + private function castObject(stdClass $sourceObject, $destinationClass, array $ctorArgs = []) { - if ( ! is_string($destinationClass)) { - if ( ! is_object($destinationClass)) { + if (! is_string($destinationClass)) { + if (! is_object($destinationClass)) { throw new DB2Exception(sprintf( - 'Destination class has to be of type string or object, %s given.', gettype($destinationClass) + 'Destination class has to be of type string or object, %s given.', + gettype($destinationClass) )); } } else { - $destinationClass = new \ReflectionClass($destinationClass); + $destinationClass = new ReflectionClass($destinationClass); $destinationClass = $destinationClass->newInstanceArgs($ctorArgs); } - $sourceReflection = new \ReflectionObject($sourceObject); - $destinationClassReflection = new \ReflectionObject($destinationClass); - /** @var \ReflectionProperty[] $destinationProperties */ - $destinationProperties = array_change_key_case($destinationClassReflection->getProperties(), \CASE_LOWER); + $sourceReflection = new ReflectionObject($sourceObject); + $destinationClassReflection = new ReflectionObject($destinationClass); + /** @var ReflectionProperty[] $destinationProperties */ + $destinationProperties = array_change_key_case($destinationClassReflection->getProperties(), CASE_LOWER); foreach ($sourceReflection->getProperties() as $sourceProperty) { $sourceProperty->setAccessible(true); diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/Driver.php b/lib/Doctrine/DBAL/Driver/Mysqli/Driver.php index 1eb6bdad525..aaf4f2bd9fd 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/Driver.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/Driver.php @@ -2,12 +2,9 @@ namespace Doctrine\DBAL\Driver\Mysqli; -use Doctrine\DBAL\Driver\AbstractMySQLDriver; use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Driver\AbstractMySQLDriver; -/** - * @author Kim Hemsø Rasmussen - */ class Driver extends AbstractMySQLDriver { /** diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php index 4c80c21b4c6..e0ae5f8b2f9 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php @@ -6,6 +6,13 @@ use Doctrine\DBAL\Driver\PingableConnection; use Doctrine\DBAL\Driver\ServerInfoAwareConnection; use Doctrine\DBAL\ParameterType; +use mysqli; +use const MYSQLI_INIT_COMMAND; +use const MYSQLI_OPT_CONNECT_TIMEOUT; +use const MYSQLI_OPT_LOCAL_INFILE; +use const MYSQLI_READ_DEFAULT_FILE; +use const MYSQLI_READ_DEFAULT_GROUP; +use const MYSQLI_SERVER_PUBLIC_KEY; use function defined; use function floor; use function func_get_args; @@ -20,20 +27,14 @@ use function sprintf; use function stripos; -/** - * @author Kim Hemsø Rasmussen - * @author Till Klampaeckel - */ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwareConnection { /** * Name of the option to set connection flags */ - const OPTION_FLAGS = 'flags'; + public const OPTION_FLAGS = 'flags'; - /** - * @var \mysqli - */ + /** @var mysqli */ private $_conn; /** @@ -42,14 +43,14 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar * @param string $password * @param array $driverOptions * - * @throws \Doctrine\DBAL\Driver\Mysqli\MysqliException + * @throws MysqliException */ public function __construct(array $params, $username, $password, array $driverOptions = []) { $port = $params['port'] ?? ini_get('mysqli.default_port'); // Fallback to default MySQL port if not given. - if ( ! $port) { + if (! $port) { $port = 3306; } @@ -63,18 +64,21 @@ public function __construct(array $params, $username, $password, array $driverOp $this->setSecureConnection($params); $this->setDriverOptions($driverOptions); - set_error_handler(function () {}); + set_error_handler(static function () { + }); try { - if ( ! $this->_conn->real_connect($params['host'], $username, $password, $dbname, $port, $socket, $flags)) { + if (! $this->_conn->real_connect($params['host'], $username, $password, $dbname, $port, $socket, $flags)) { throw new MysqliException($this->_conn->connect_error, $this->_conn->sqlstate ?? 'HY000', $this->_conn->connect_errno); } } finally { restore_error_handler(); } - if (isset($params['charset'])) { - $this->_conn->set_charset($params['charset']); + if (! isset($params['charset'])) { + return; } + + $this->_conn->set_charset($params['charset']); } /** @@ -82,7 +86,7 @@ public function __construct(array $params, $username, $password, array $driverOp * * Could be used if part of your application is not using DBAL. * - * @return \mysqli + * @return mysqli */ public function getWrappedResourceHandle() { @@ -94,12 +98,13 @@ public function getWrappedResourceHandle() * * The server version detection includes a special case for MariaDB * to support '5.5.5-' prefixed versions introduced in Maria 10+ + * * @link https://jira.mariadb.org/browse/MDEV-4088 */ public function getServerVersion() { $serverInfos = $this->_conn->get_server_info(); - if (false !== stripos($serverInfos, 'mariadb')) { + if (stripos($serverInfos, 'mariadb') !== false) { return $serverInfos; } @@ -132,7 +137,7 @@ public function prepare($prepareString) public function query() { $args = func_get_args(); - $sql = $args[0]; + $sql = $args[0]; $stmt = $this->prepare($sql); $stmt->execute(); @@ -144,7 +149,7 @@ public function query() */ public function quote($input, $type = ParameterType::STRING) { - return "'". $this->_conn->escape_string($input) ."'"; + return "'" . $this->_conn->escape_string($input) . "'"; } /** @@ -152,7 +157,7 @@ public function quote($input, $type = ParameterType::STRING) */ public function exec($statement) { - if (false === $this->_conn->query($statement)) { + if ($this->_conn->query($statement) === false) { throw new MysqliException($this->_conn->error, $this->_conn->sqlstate, $this->_conn->errno); } @@ -220,26 +225,25 @@ public function errorInfo() private function setDriverOptions(array $driverOptions = []) { $supportedDriverOptions = [ - \MYSQLI_OPT_CONNECT_TIMEOUT, - \MYSQLI_OPT_LOCAL_INFILE, - \MYSQLI_INIT_COMMAND, - \MYSQLI_READ_DEFAULT_FILE, - \MYSQLI_READ_DEFAULT_GROUP, + MYSQLI_OPT_CONNECT_TIMEOUT, + MYSQLI_OPT_LOCAL_INFILE, + MYSQLI_INIT_COMMAND, + MYSQLI_READ_DEFAULT_FILE, + MYSQLI_READ_DEFAULT_GROUP, ]; if (defined('MYSQLI_SERVER_PUBLIC_KEY')) { - $supportedDriverOptions[] = \MYSQLI_SERVER_PUBLIC_KEY; + $supportedDriverOptions[] = MYSQLI_SERVER_PUBLIC_KEY; } $exceptionMsg = "%s option '%s' with value '%s'"; foreach ($driverOptions as $option => $value) { - if ($option === static::OPTION_FLAGS) { continue; } - if (!in_array($option, $supportedDriverOptions, true)) { + if (! in_array($option, $supportedDriverOptions, true)) { throw new MysqliException( sprintf($exceptionMsg, 'Unsupported', $option, $value) ); @@ -274,6 +278,7 @@ public function ping() * Establish a secure connection * * @param array $params + * * @throws MysqliException */ private function setSecureConnection(array $params) diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliException.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliException.php index c13b8eaadcf..1fa0c900fbd 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliException.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliException.php @@ -6,9 +6,6 @@ /** * Exception thrown in case the mysqli driver errors. - * - * @author Kim Hemsø Rasmussen - * @author Steve Müller */ class MysqliException extends AbstractDriverException { diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php index 6e819335a02..8948a49efc1 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php @@ -7,6 +7,11 @@ use Doctrine\DBAL\Exception\InvalidArgumentException; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; +use IteratorAggregate; +use mysqli; +use mysqli_stmt; +use PDO; +use stdClass; use function array_combine; use function array_fill; use function count; @@ -16,14 +21,9 @@ use function is_resource; use function str_repeat; -/** - * @author Kim Hemsø Rasmussen - */ -class MysqliStatement implements \IteratorAggregate, Statement +class MysqliStatement implements IteratorAggregate, Statement { - /** - * @var array - */ + /** @var array */ protected static $_paramTypeMap = [ ParameterType::STRING => 's', ParameterType::BINARY => 's', @@ -33,34 +33,22 @@ class MysqliStatement implements \IteratorAggregate, Statement ParameterType::LARGE_OBJECT => 'b', ]; - /** - * @var \mysqli - */ + /** @var mysqli */ protected $_conn; - /** - * @var \mysqli_stmt - */ + /** @var mysqli_stmt */ protected $_stmt; - /** - * @var null|boolean|array - */ + /** @var bool|array|null */ protected $_columnNames; - /** - * @var null|array - */ + /** @var array|null */ protected $_rowBindedValues; - /** - * @var array - */ + /** @var array */ protected $_bindedValues; - /** - * @var string - */ + /** @var string */ protected $types; /** @@ -70,9 +58,7 @@ class MysqliStatement implements \IteratorAggregate, Statement */ protected $_values = []; - /** - * @var int - */ + /** @var int */ protected $_defaultFetchMode = FetchMode::MIXED; /** @@ -83,24 +69,25 @@ class MysqliStatement implements \IteratorAggregate, Statement private $result = false; /** - * @param \mysqli $conn - * @param string $prepareString + * @param string $prepareString * - * @throws \Doctrine\DBAL\Driver\Mysqli\MysqliException + * @throws MysqliException */ - public function __construct(\mysqli $conn, $prepareString) + public function __construct(mysqli $conn, $prepareString) { $this->_conn = $conn; $this->_stmt = $conn->prepare($prepareString); - if (false === $this->_stmt) { + if ($this->_stmt === false) { throw new MysqliException($this->_conn->error, $this->_conn->sqlstate, $this->_conn->errno); } $paramCount = $this->_stmt->param_count; - if (0 < $paramCount) { - $this->types = str_repeat('s', $paramCount); - $this->_bindedValues = array_fill(1, $paramCount, null); + if (0 >= $paramCount) { + return; } + + $this->types = str_repeat('s', $paramCount); + $this->_bindedValues = array_fill(1, $paramCount, null); } /** @@ -108,18 +95,18 @@ public function __construct(\mysqli $conn, $prepareString) */ public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null) { - if (null === $type) { + if ($type === null) { $type = 's'; } else { - if (isset(self::$_paramTypeMap[$type])) { - $type = self::$_paramTypeMap[$type]; - } else { + if (! isset(self::$_paramTypeMap[$type])) { throw new MysqliException("Unknown type: '{$type}'"); } + + $type = self::$_paramTypeMap[$type]; } $this->_bindedValues[$column] =& $variable; - $this->types[$column - 1] = $type; + $this->types[$column - 1] = $type; return true; } @@ -129,19 +116,19 @@ public function bindParam($column, &$variable, $type = ParameterType::STRING, $l */ public function bindValue($param, $value, $type = ParameterType::STRING) { - if (null === $type) { + if ($type === null) { $type = 's'; } else { - if (isset(self::$_paramTypeMap[$type])) { - $type = self::$_paramTypeMap[$type]; - } else { + if (! isset(self::$_paramTypeMap[$type])) { throw new MysqliException("Unknown type: '{$type}'"); } + + $type = self::$_paramTypeMap[$type]; } - $this->_values[$param] = $value; + $this->_values[$param] = $value; $this->_bindedValues[$param] =& $this->_values[$param]; - $this->types[$param - 1] = $type; + $this->types[$param - 1] = $type; return true; } @@ -151,13 +138,13 @@ public function bindValue($param, $value, $type = ParameterType::STRING) */ public function execute($params = null) { - if (null !== $this->_bindedValues) { - if (null !== $params) { - if ( ! $this->_bindValues($params)) { + if ($this->_bindedValues !== null) { + if ($params !== null) { + if (! $this->_bindValues($params)) { throw new MysqliException($this->_stmt->error, $this->_stmt->errno); } } else { - list($types, $values, $streams) = $this->separateBoundValues(); + [$types, $values, $streams] = $this->separateBoundValues(); if (! $this->_stmt->bind_param($types, ...$values)) { throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno); } @@ -165,13 +152,13 @@ public function execute($params = null) } } - if ( ! $this->_stmt->execute()) { + if (! $this->_stmt->execute()) { throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno); } - if (null === $this->_columnNames) { + if ($this->_columnNames === null) { $meta = $this->_stmt->result_metadata(); - if (false !== $meta) { + if ($meta !== false) { $columnNames = []; foreach ($meta->fetch_fields() as $col) { $columnNames[] = $col->name; @@ -184,7 +171,7 @@ public function execute($params = null) } } - if (false !== $this->_columnNames) { + if ($this->_columnNames !== false) { // Store result of every execution which has it. Otherwise it will be impossible // to execute a new statement in case if the previous one has non-fetched rows // @link http://dev.mysql.com/doc/refman/5.7/en/commands-out-of-sync.html @@ -285,7 +272,7 @@ private function sendLongData($streams) private function _bindValues($values) { $params = []; - $types = str_repeat('s', count($values)); + $types = str_repeat('s', count($values)); foreach ($values as &$v) { $params[] =& $v; @@ -301,7 +288,7 @@ private function _fetch() { $ret = $this->_stmt->fetch(); - if (true === $ret) { + if ($ret === true) { $values = []; foreach ($this->_rowBindedValues as $v) { $values[] = $v; @@ -316,11 +303,11 @@ private function _fetch() /** * {@inheritdoc} */ - public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) + public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0) { // 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->result) { return false; } @@ -331,11 +318,11 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE } $values = $this->_fetch(); - if (null === $values) { + if ($values === null) { return false; } - if (false === $values) { + if ($values === false) { throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno); } @@ -347,14 +334,14 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE return array_combine($this->_columnNames, $values); case FetchMode::MIXED: - $ret = array_combine($this->_columnNames, $values); + $ret = array_combine($this->_columnNames, $values); $ret += $values; return $ret; case FetchMode::STANDARD_OBJECT: $assoc = array_combine($this->_columnNames, $values); - $ret = new \stdClass(); + $ret = new stdClass(); foreach ($assoc as $column => $value) { $ret->$column = $value; @@ -396,7 +383,7 @@ public function fetchColumn($columnIndex = 0) { $row = $this->fetch(FetchMode::NUMERIC); - if (false === $row) { + if ($row === false) { return false; } @@ -435,7 +422,7 @@ public function closeCursor() */ public function rowCount() { - if (false === $this->_columnNames) { + if ($this->_columnNames === false) { return $this->_stmt->affected_rows; } diff --git a/lib/Doctrine/DBAL/Driver/OCI8/Driver.php b/lib/Doctrine/DBAL/Driver/OCI8/Driver.php index 216eddb6bcb..c0a792ed7ba 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/Driver.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/Driver.php @@ -8,9 +8,6 @@ /** * A Doctrine DBAL driver for the Oracle OCI8 PHP extensions. - * - * @author Roman Borschel - * @since 2.0 */ class Driver extends AbstractOracleDriver { diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php index edd37c585ff..818c4531aa4 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php @@ -5,6 +5,7 @@ use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\Driver\ServerInfoAwareConnection; use Doctrine\DBAL\ParameterType; +use UnexpectedValueException; use const OCI_COMMIT_ON_SUCCESS; use const OCI_DEFAULT; use const OCI_NO_AUTO_COMMIT; @@ -26,19 +27,13 @@ /** * OCI8 implementation of the Connection interface. - * - * @since 2.0 */ class OCI8Connection implements Connection, ServerInfoAwareConnection { - /** - * @var resource - */ + /** @var resource */ protected $dbh; - /** - * @var int - */ + /** @var int */ protected $executeMode = OCI_COMMIT_ON_SUCCESS; /** @@ -55,7 +50,7 @@ class OCI8Connection implements Connection, ServerInfoAwareConnection */ public function __construct($username, $password, $db, $charset = null, $sessionMode = OCI_DEFAULT, $persistent = false) { - if (!defined('OCI_NO_AUTO_COMMIT')) { + if (! defined('OCI_NO_AUTO_COMMIT')) { define('OCI_NO_AUTO_COMMIT', 0); } @@ -63,7 +58,7 @@ public function __construct($username, $password, $db, $charset = null, $session ? @oci_pconnect($username, $password, $db, $charset, $sessionMode) : @oci_connect($username, $password, $db, $charset, $sessionMode); - if ( ! $this->dbh) { + if (! $this->dbh) { throw OCI8Exception::fromErrorInfo(oci_error()); } } @@ -71,13 +66,13 @@ public function __construct($username, $password, $db, $charset = null, $session /** * {@inheritdoc} * - * @throws \UnexpectedValueException if the version string returned by the database server + * @throws UnexpectedValueException if the version string returned by the database server * does not contain a parsable version number. */ public function getServerVersion() { - if ( ! preg_match('/\s+(\d+\.\d+\.\d+\.\d+\.\d+)\s+/', oci_server_version($this->dbh), $version)) { - throw new \UnexpectedValueException( + if (! preg_match('/\s+(\d+\.\d+\.\d+\.\d+\.\d+)\s+/', oci_server_version($this->dbh), $version)) { + 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.', @@ -111,7 +106,7 @@ public function prepare($prepareString) public function query() { $args = func_get_args(); - $sql = $args[0]; + $sql = $args[0]; //$fetchMode = $args[1]; $stmt = $this->prepare($sql); $stmt->execute(); @@ -157,7 +152,7 @@ public function lastInsertId($name = null) $result = $stmt->fetchColumn(); if ($result === false) { - throw new OCI8Exception("lastInsertId failed: Query was executed but no result was returned."); + throw new OCI8Exception('lastInsertId failed: Query was executed but no result was returned.'); } return (int) $result; @@ -188,7 +183,7 @@ public function beginTransaction() */ public function commit() { - if (!oci_commit($this->dbh)) { + if (! oci_commit($this->dbh)) { throw OCI8Exception::fromErrorInfo($this->errorInfo()); } $this->executeMode = OCI_COMMIT_ON_SUCCESS; @@ -201,7 +196,7 @@ public function commit() */ public function rollBack() { - if (!oci_rollback($this->dbh)) { + if (! oci_rollback($this->dbh)) { throw OCI8Exception::fromErrorInfo($this->errorInfo()); } $this->executeMode = OCI_COMMIT_ON_SUCCESS; diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php index ae0604805fd..51cf3864885 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php @@ -6,7 +6,9 @@ use Doctrine\DBAL\Driver\StatementIterator; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; +use InvalidArgumentException; use IteratorAggregate; +use PDO; use const OCI_ASSOC; use const OCI_B_BIN; use const OCI_B_BLOB; @@ -42,35 +44,22 @@ /** * The OCI8 implementation of the Statement interface. - * - * @since 2.0 - * @author Roman Borschel */ class OCI8Statement implements IteratorAggregate, Statement { - /** - * @var resource - */ + /** @var resource */ protected $_dbh; - /** - * @var resource - */ + /** @var resource */ protected $_sth; - /** - * @var \Doctrine\DBAL\Driver\OCI8\OCI8Connection - */ + /** @var OCI8Connection */ protected $_conn; - /** - * @var string - */ + /** @var string */ protected static $_PARAM = ':param'; - /** - * @var array - */ + /** @var array */ protected static $fetchModeMap = [ FetchMode::MIXED => OCI_BOTH, FetchMode::ASSOCIATIVE => OCI_ASSOC, @@ -78,14 +67,10 @@ class OCI8Statement implements IteratorAggregate, Statement FetchMode::COLUMN => OCI_NUM, ]; - /** - * @var int - */ + /** @var int */ protected $_defaultFetchMode = FetchMode::MIXED; - /** - * @var array - */ + /** @var array */ protected $_paramMap = []; /** @@ -107,17 +92,16 @@ 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 \Doctrine\DBAL\Driver\OCI8\OCI8Connection $conn + * @param resource $dbh The connection handle. + * @param string $statement The SQL statement. */ public function __construct($dbh, $statement, OCI8Connection $conn) { - list($statement, $paramMap) = self::convertPositionalToNamedPlaceholders($statement); - $this->_sth = oci_parse($dbh, $statement); - $this->_dbh = $dbh; - $this->_paramMap = $paramMap; - $this->_conn = $conn; + [$statement, $paramMap] = self::convertPositionalToNamedPlaceholders($statement); + $this->_sth = oci_parse($dbh, $statement); + $this->_dbh = $dbh; + $this->_paramMap = $paramMap; + $this->_conn = $conn; } /** @@ -132,22 +116,23 @@ public function __construct($dbh, $statement, OCI8Connection $conn) * Question marks inside literal strings are therefore handled correctly by this method. * This comes at a cost, the whole sql statement has to be looped over. * - * @todo extract into utility class in Doctrine\DBAL\Util namespace - * @todo review and test for lost spaces. we experienced missing spaces with oci8 in some sql statements. - * * @param string $statement The SQL statement to convert. * * @return array [0] => the statement value (string), [1] => the paramMap value (array). - * @throws \Doctrine\DBAL\Driver\OCI8\OCI8Exception + * + * @throws OCI8Exception + * + * @todo extract into utility class in Doctrine\DBAL\Util namespace + * @todo review and test for lost spaces. we experienced missing spaces with oci8 in some sql statements. */ public static function convertPositionalToNamedPlaceholders($statement) { - $fragmentOffset = $tokenOffset = 0; - $fragments = $paramMap = []; + $fragmentOffset = $tokenOffset = 0; + $fragments = $paramMap = []; $currentLiteralDelimiter = null; do { - if (!$currentLiteralDelimiter) { + if (! $currentLiteralDelimiter) { $result = self::findPlaceholderOrOpeningQuote( $statement, $tokenOffset, @@ -169,7 +154,7 @@ public static function convertPositionalToNamedPlaceholders($statement) } $fragments[] = substr($statement, $fragmentOffset); - $statement = implode('', $fragments); + $statement = implode('', $fragments); return [$statement, $paramMap]; } @@ -184,6 +169,7 @@ public static function convertPositionalToNamedPlaceholders($statement) * @param string|null $currentLiteralDelimiter The delimiter of the current string literal * or NULL if not currently in a literal * @param array $paramMap Mapping of the original parameter positions to their named replacements + * * @return bool Whether the token was found */ private static function findPlaceholderOrOpeningQuote( @@ -196,18 +182,18 @@ private static function findPlaceholderOrOpeningQuote( ) { $token = self::findToken($statement, $tokenOffset, '/[?\'"]/'); - if (!$token) { + if (! $token) { return false; } if ($token === '?') { - $position = count($paramMap) + 1; - $param = ':param' . $position; - $fragments[] = substr($statement, $fragmentOffset, $tokenOffset - $fragmentOffset); - $fragments[] = $param; + $position = count($paramMap) + 1; + $param = ':param' . $position; + $fragments[] = substr($statement, $fragmentOffset, $tokenOffset - $fragmentOffset); + $fragments[] = $param; $paramMap[$position] = $param; - $tokenOffset += 1; - $fragmentOffset = $tokenOffset; + $tokenOffset += 1; + $fragmentOffset = $tokenOffset; return true; } @@ -225,6 +211,7 @@ private static function findPlaceholderOrOpeningQuote( * @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 + * * @return bool Whether the token was found */ private static function findClosingQuote( @@ -238,7 +225,7 @@ private static function findClosingQuote( '/' . preg_quote($currentLiteralDelimiter, '/') . '/' ); - if (!$token) { + if (! $token) { return false; } @@ -255,6 +242,7 @@ private static function findClosingQuote( * @param string $statement The SQL statement to parse * @param string $offset The offset to start searching from * @param string $regex The regex containing token pattern + * * @return string|null Token or NULL if not found */ private static function findToken($statement, &$offset, $regex) @@ -323,7 +311,7 @@ private function convertParameterType(int $type) : int public function closeCursor() { // not having the result means there's nothing to close - if (!$this->result) { + if (! $this->result) { return true; } @@ -380,7 +368,7 @@ public function execute($params = null) } $ret = @oci_execute($this->_sth, $this->_conn->getExecuteMode()); - if ( ! $ret) { + if (! $ret) { throw OCI8Exception::fromErrorInfo($this->errorInfo()); } @@ -410,11 +398,11 @@ public function getIterator() /** * {@inheritdoc} */ - public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) + public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0) { // 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->result) { return false; } @@ -429,7 +417,7 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE } if (! isset(self::$fetchModeMap[$fetchMode])) { - throw new \InvalidArgumentException("Invalid fetch style: " . $fetchMode); + throw new InvalidArgumentException('Invalid fetch style: ' . $fetchMode); } return oci_fetch_array( @@ -455,8 +443,8 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n return $result; } - if ( ! isset(self::$fetchModeMap[$fetchMode])) { - throw new \InvalidArgumentException("Invalid fetch style: " . $fetchMode); + if (! isset(self::$fetchModeMap[$fetchMode])) { + throw new InvalidArgumentException('Invalid fetch style: ' . $fetchMode); } if (self::$fetchModeMap[$fetchMode] === OCI_BOTH) { @@ -472,12 +460,17 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n // 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->result) { return []; } - oci_fetch_all($this->_sth, $result, 0, -1, - self::$fetchModeMap[$fetchMode] | OCI_RETURN_NULLS | $fetchStructure | OCI_RETURN_LOBS); + oci_fetch_all( + $this->_sth, + $result, + 0, + -1, + self::$fetchModeMap[$fetchMode] | OCI_RETURN_NULLS | $fetchStructure | OCI_RETURN_LOBS + ); if ($fetchMode === FetchMode::COLUMN) { $result = $result[0]; @@ -494,13 +487,13 @@ public function fetchColumn($columnIndex = 0) { // 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->result) { return false; } $row = oci_fetch_array($this->_sth, OCI_NUM | OCI_RETURN_NULLS | OCI_RETURN_LOBS); - if (false === $row) { + if ($row === false) { return false; } diff --git a/lib/Doctrine/DBAL/Driver/PDOConnection.php b/lib/Doctrine/DBAL/Driver/PDOConnection.php index 18c3efc7346..e7bced5e796 100644 --- a/lib/Doctrine/DBAL/Driver/PDOConnection.php +++ b/lib/Doctrine/DBAL/Driver/PDOConnection.php @@ -10,8 +10,6 @@ /** * PDO implementation of the Connection interface. * Used by all PDO-based drivers. - * - * @since 2.0 */ class PDOConnection extends PDO implements Connection, ServerInfoAwareConnection { @@ -23,7 +21,7 @@ class PDOConnection extends PDO implements Connection, ServerInfoAwareConnection * * @throws PDOException in case of an error. */ - public function __construct($dsn, $user = null, $password = null, array $options = null) + public function __construct($dsn, $user = null, $password = null, ?array $options = null) { try { parent::__construct($dsn, $user, $password, $options); @@ -71,19 +69,19 @@ public function prepare($prepareString, $driverOptions = []) */ public function query() { - $args = func_get_args(); + $args = func_get_args(); $argsCount = count($args); try { - if ($argsCount == 4) { + if ($argsCount === 4) { return parent::query($args[0], $args[1], $args[2], $args[3]); } - if ($argsCount == 3) { + if ($argsCount === 3) { return parent::query($args[0], $args[1], $args[2]); } - if ($argsCount == 2) { + if ($argsCount === 2) { return parent::query($args[0], $args[1]); } diff --git a/lib/Doctrine/DBAL/Driver/PDOException.php b/lib/Doctrine/DBAL/Driver/PDOException.php index 6104155bbb5..ee677e3832b 100644 --- a/lib/Doctrine/DBAL/Driver/PDOException.php +++ b/lib/Doctrine/DBAL/Driver/PDOException.php @@ -5,9 +5,7 @@ /** * Tiny wrapper for PDOException instances to implement the {@link DriverException} interface. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ class PDOException extends \PDOException implements DriverException { @@ -26,8 +24,6 @@ class PDOException extends \PDOException implements DriverException private $sqlState; /** - * Constructor. - * * @param \PDOException $exception The PDO exception to wrap. */ public function __construct(\PDOException $exception) diff --git a/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php b/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php index f082cf99334..d2e3e506f70 100644 --- a/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php @@ -9,11 +9,6 @@ * Driver for the PDO IBM extension. * * @link www.doctrine-project.org - * @since 1.0 - * @author Benjamin Eberlei - * @author Guilherme Blanco - * @author Jonathan Wage - * @author Roman Borschel */ class Driver extends AbstractDB2Driver { @@ -22,14 +17,12 @@ class Driver extends AbstractDB2Driver */ public function connect(array $params, $username = null, $password = null, array $driverOptions = []) { - $conn = new PDOConnection( + return new PDOConnection( $this->_constructPdoDsn($params), $username, $password, $driverOptions ); - - return $conn; } /** diff --git a/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php b/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php index bcf3b5b47f6..bc0727ff3e6 100644 --- a/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php @@ -9,8 +9,6 @@ /** * PDO MySql driver. - * - * @since 2.0 */ class Driver extends AbstractMySQLDriver { @@ -43,7 +41,7 @@ public function connect(array $params, $username = null, $password = null, array protected function constructPdoDsn(array $params) { $dsn = 'mysql:'; - if (isset($params['host']) && $params['host'] != '') { + if (isset($params['host']) && $params['host'] !== '') { $dsn .= 'host=' . $params['host'] . ';'; } if (isset($params['port'])) { diff --git a/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php b/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php index 484962f8afc..57dfbe76688 100644 --- a/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php @@ -5,6 +5,7 @@ use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\AbstractOracleDriver; use Doctrine\DBAL\Driver\PDOConnection; +use PDOException; /** * PDO Oracle driver. @@ -28,7 +29,7 @@ public function connect(array $params, $username = null, $password = null, array $password, $driverOptions ); - } catch (\PDOException $e) { + } catch (PDOException $e) { throw DBALException::driverException($this, $e); } } diff --git a/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php b/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php index a6c7e39f166..914f55348a4 100644 --- a/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php @@ -2,17 +2,15 @@ namespace Doctrine\DBAL\Driver\PDOPgSql; +use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\AbstractPostgreSQLDriver; use Doctrine\DBAL\Driver\PDOConnection; -use Doctrine\DBAL\DBALException; -use PDOException; use PDO; +use PDOException; use function defined; /** * Driver that connects through pdo_pgsql. - * - * @since 2.0 */ class Driver extends AbstractPostgreSQLDriver { @@ -31,7 +29,7 @@ public function connect(array $params, $username = null, $password = null, array if (defined('PDO::PGSQL_ATTR_DISABLE_PREPARES') && (! isset($driverOptions[PDO::PGSQL_ATTR_DISABLE_PREPARES]) - || true === $driverOptions[PDO::PGSQL_ATTR_DISABLE_PREPARES] + || $driverOptions[PDO::PGSQL_ATTR_DISABLE_PREPARES] === true ) ) { $pdo->setAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES, true); @@ -62,11 +60,11 @@ private function _constructPdoDsn(array $params) { $dsn = 'pgsql:'; - if (isset($params['host']) && $params['host'] != '') { + if (isset($params['host']) && $params['host'] !== '') { $dsn .= 'host=' . $params['host'] . ';'; } - if (isset($params['port']) && $params['port'] != '') { + if (isset($params['port']) && $params['port'] !== '') { $dsn .= 'port=' . $params['port'] . ';'; } diff --git a/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php b/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php index f19045c3145..9a23e719140 100644 --- a/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php @@ -10,14 +10,10 @@ /** * The PDO Sqlite driver. - * - * @since 2.0 */ class Driver extends AbstractSQLiteDriver { - /** - * @var array - */ + /** @var array */ protected $_userDefinedFunctions = [ 'sqrt' => ['callback' => ['Doctrine\DBAL\Platforms\SqlitePlatform', 'udfSqrt'], 'numArgs' => 1], 'mod' => ['callback' => ['Doctrine\DBAL\Platforms\SqlitePlatform', 'udfMod'], 'numArgs' => 2], @@ -31,7 +27,9 @@ public function connect(array $params, $username = null, $password = null, array { if (isset($driverOptions['userDefinedFunctions'])) { $this->_userDefinedFunctions = array_merge( - $this->_userDefinedFunctions, $driverOptions['userDefinedFunctions']); + $this->_userDefinedFunctions, + $driverOptions['userDefinedFunctions'] + ); unset($driverOptions['userDefinedFunctions']); } diff --git a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Connection.php b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Connection.php index eded44a1411..86ad9aedf29 100644 --- a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Connection.php +++ b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Connection.php @@ -4,23 +4,22 @@ use Doctrine\DBAL\Driver\PDOConnection; use Doctrine\DBAL\ParameterType; +use PDO; use function strpos; use function substr; /** * Sqlsrv Connection implementation. - * - * @since 2.0 */ class Connection extends PDOConnection implements \Doctrine\DBAL\Driver\Connection { /** * {@inheritdoc} */ - public function __construct($dsn, $user = null, $password = null, array $options = null) + public function __construct($dsn, $user = null, $password = null, ?array $options = null) { parent::__construct($dsn, $user, $password, $options); - $this->setAttribute(\PDO::ATTR_STATEMENT_CLASS, [Statement::class, []]); + $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, [Statement::class, []]); } /** @@ -28,7 +27,7 @@ public function __construct($dsn, $user = null, $password = null, array $options */ public function lastInsertId($name = null) { - if (null === $name) { + if ($name === null) { return parent::lastInsertId($name); } diff --git a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php index 1ca19bdea4b..7fb131d27f1 100644 --- a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php @@ -8,8 +8,6 @@ /** * The PDO-based Sqlsrv driver. - * - * @since 2.0 */ class Driver extends AbstractSQLServerDriver { @@ -31,7 +29,7 @@ public function connect(array $params, $username = null, $password = null, array /** * Constructs the Sqlsrv PDO DSN. * - * @param array $params + * @param array $params * @param string[] $connectionOptions * * @return string The DSN. @@ -44,7 +42,7 @@ private function _constructPdoDsn(array $params, array $connectionOptions) $dsn .= $params['host']; } - if (isset($params['port']) && !empty($params['port'])) { + if (isset($params['port']) && ! empty($params['port'])) { $dsn .= ',' . $params['port']; } @@ -65,6 +63,7 @@ private function _constructPdoDsn(array $params, array $connectionOptions) * Separates a connection options from a driver options * * @param int[]|string[] $options + * * @return int[][]|string[][] */ private function splitOptions(array $options) : array diff --git a/lib/Doctrine/DBAL/Driver/PDOStatement.php b/lib/Doctrine/DBAL/Driver/PDOStatement.php index ab383c2fb51..2aed89fbf07 100644 --- a/lib/Doctrine/DBAL/Driver/PDOStatement.php +++ b/lib/Doctrine/DBAL/Driver/PDOStatement.php @@ -12,14 +12,9 @@ /** * The PDO implementation of the Statement interface. * Used by all PDO-based drivers. - * - * @since 2.0 */ class PDOStatement extends \PDOStatement implements Statement { - /** - * @var int[] - */ private const PARAM_TYPE_MAP = [ ParameterType::NULL => PDO::PARAM_NULL, ParameterType::INTEGER => PDO::PARAM_INT, @@ -29,9 +24,6 @@ class PDOStatement extends \PDOStatement implements Statement ParameterType::BOOLEAN => PDO::PARAM_BOOL, ]; - /** - * @var int[] - */ private const FETCH_MODE_MAP = [ FetchMode::ASSOCIATIVE => PDO::FETCH_ASSOC, FetchMode::NUMERIC => PDO::FETCH_NUM, @@ -131,20 +123,20 @@ public function execute($params = null) /** * {@inheritdoc} */ - public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) + public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0) { $fetchMode = $this->convertFetchMode($fetchMode); try { - if ($fetchMode === null && \PDO::FETCH_ORI_NEXT === $cursorOrientation && 0 === $cursorOffset) { + if ($fetchMode === null && $cursorOrientation === PDO::FETCH_ORI_NEXT && $cursorOffset === 0) { return parent::fetch(); } - if (\PDO::FETCH_ORI_NEXT === $cursorOrientation && 0 === $cursorOffset) { + if ($cursorOrientation === PDO::FETCH_ORI_NEXT && $cursorOffset === 0) { return parent::fetch($fetchMode); } - if (0 === $cursorOffset) { + if ($cursorOffset === 0) { return parent::fetch($fetchMode, $cursorOrientation); } @@ -162,15 +154,15 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n $fetchMode = $this->convertFetchMode($fetchMode); try { - if ($fetchMode === null && null === $fetchArgument && null === $ctorArgs) { + if ($fetchMode === null && $fetchArgument === null && $ctorArgs === null) { return parent::fetchAll(); } - if (null === $fetchArgument && null === $ctorArgs) { + if ($fetchArgument === null && $ctorArgs === null) { return parent::fetchAll($fetchMode); } - if (null === $ctorArgs) { + if ($ctorArgs === null) { return parent::fetchAll($fetchMode, $fetchArgument); } diff --git a/lib/Doctrine/DBAL/Driver/PingableConnection.php b/lib/Doctrine/DBAL/Driver/PingableConnection.php index 043bb9704ee..8586bce2239 100644 --- a/lib/Doctrine/DBAL/Driver/PingableConnection.php +++ b/lib/Doctrine/DBAL/Driver/PingableConnection.php @@ -6,9 +6,6 @@ * An interface for connections which support a "native" ping method. * * @link www.doctrine-project.org - * @since 2.5 - * @author Till Klampaeckel - * @author Benjamin Eberlei */ interface PingableConnection { diff --git a/lib/Doctrine/DBAL/Driver/ResultStatement.php b/lib/Doctrine/DBAL/Driver/ResultStatement.php index 1dea8bf5959..d0258a29b37 100644 --- a/lib/Doctrine/DBAL/Driver/ResultStatement.php +++ b/lib/Doctrine/DBAL/Driver/ResultStatement.php @@ -2,12 +2,13 @@ namespace Doctrine\DBAL\Driver; +use PDO; +use Traversable; + /** * Interface for the reading part of a prepare statement only. - * - * @author Benjamin Eberlei */ -interface ResultStatement extends \Traversable +interface ResultStatement extends Traversable { /** * Closes the cursor, enabling the statement to be executed again. @@ -61,7 +62,7 @@ public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null); * @return mixed The return value of this method on success depends on the fetch mode. In all cases, FALSE is * returned on failure. */ - public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0); + public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0); /** * Returns an array containing all of the result set rows. @@ -92,7 +93,7 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n * If no value is supplied, PDOStatement->fetchColumn() * fetches the first column. * - * @return string|boolean A single column in the next row of a result set, or FALSE if there are no more rows. + * @return string|bool A single column in the next row of a result set, or FALSE if there are no more rows. */ public function fetchColumn($columnIndex = 0); } diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php index d8672f394f4..38558702092 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php @@ -11,16 +11,14 @@ /** * A Doctrine DBAL driver for the SAP Sybase SQL Anywhere PHP extension. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ class Driver extends AbstractSQLAnywhereDriver { /** * {@inheritdoc} * - * @throws \Doctrine\DBAL\DBALException if there was a problem establishing the connection. + * @throws DBALException if there was a problem establishing the connection. */ public function connect(array $params, $username = null, $password = null, array $driverOptions = []) { @@ -74,15 +72,14 @@ private function buildDsn($host, $port, $server, $dbname, $username = null, $pas $server = ';ServerName=' . $server; } - return - 'HOST=' . $host . ':' . $port . + return 'HOST=' . $host . ':' . $port . $server . ';DBN=' . $dbname . ';UID=' . $username . ';PWD=' . $password . ';' . implode( ';', - array_map(function ($key, $value) { + array_map(static function ($key, $value) { return $key . '=' . $value; }, array_keys($driverOptions), $driverOptions) ); diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php index 17ac08c9e82..8e977e2d077 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php @@ -26,20 +26,14 @@ /** * SAP Sybase SQL Anywhere implementation of the Connection interface. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection { - /** - * @var resource The SQL Anywhere connection resource. - */ + /** @var resource The SQL Anywhere connection resource. */ private $connection; /** - * Constructor. - * * Connects to database with given connection string. * * @param string $dsn The connection string. @@ -51,22 +45,22 @@ public function __construct($dsn, $persistent = false) { $this->connection = $persistent ? @sasql_pconnect($dsn) : @sasql_connect($dsn); - if ( ! is_resource($this->connection)) { + if (! is_resource($this->connection)) { throw SQLAnywhereException::fromSQLAnywhereError(); } // Disable PHP warnings on error. - if ( ! sasql_set_option($this->connection, 'verbose_errors', false)) { + if (! sasql_set_option($this->connection, 'verbose_errors', false)) { throw SQLAnywhereException::fromSQLAnywhereError($this->connection); } // Enable auto committing by default. - if ( ! sasql_set_option($this->connection, 'auto_commit', 'on')) { + if (! sasql_set_option($this->connection, 'auto_commit', 'on')) { throw SQLAnywhereException::fromSQLAnywhereError($this->connection); } // Enable exact, non-approximated row count retrieval. - if ( ! sasql_set_option($this->connection, 'row_counts', true)) { + if (! sasql_set_option($this->connection, 'row_counts', true)) { throw SQLAnywhereException::fromSQLAnywhereError($this->connection); } } @@ -78,7 +72,7 @@ public function __construct($dsn, $persistent = false) */ public function beginTransaction() { - if ( ! sasql_set_option($this->connection, 'auto_commit', 'off')) { + if (! sasql_set_option($this->connection, 'auto_commit', 'off')) { throw SQLAnywhereException::fromSQLAnywhereError($this->connection); } @@ -92,7 +86,7 @@ public function beginTransaction() */ public function commit() { - if ( ! sasql_commit($this->connection)) { + if (! sasql_commit($this->connection)) { throw SQLAnywhereException::fromSQLAnywhereError($this->connection); } @@ -122,7 +116,7 @@ public function errorInfo() */ public function exec($statement) { - if (false === sasql_real_query($this->connection, $statement)) { + if (sasql_real_query($this->connection, $statement) === false) { throw SQLAnywhereException::fromSQLAnywhereError($this->connection); } @@ -146,7 +140,7 @@ public function getServerVersion() */ public function lastInsertId($name = null) { - if (null === $name) { + if ($name === null) { return sasql_insert_id($this->connection); } @@ -201,7 +195,7 @@ public function requiresQueryForServerVersion() */ public function rollBack() { - if ( ! sasql_rollback($this->connection)) { + if (! sasql_rollback($this->connection)) { throw SQLAnywhereException::fromSQLAnywhereError($this->connection); } @@ -213,13 +207,13 @@ public function rollBack() /** * Ends transactional mode and enables auto commit again. * - * @throws SQLAnywhereException - * * @return bool Whether or not ending transactional mode succeeded. + * + * @throws SQLAnywhereException */ private function endTransaction() { - if ( ! sasql_set_option($this->connection, 'auto_commit', 'on')) { + if (! sasql_set_option($this->connection, 'auto_commit', 'on')) { throw SQLAnywhereException::fromSQLAnywhereError($this->connection); } diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereException.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereException.php index 061cbd9bdc8..dfe9187bb93 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereException.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereException.php @@ -3,6 +3,7 @@ namespace Doctrine\DBAL\Driver\SQLAnywhere; use Doctrine\DBAL\Driver\AbstractDriverException; +use InvalidArgumentException; use function is_resource; use function sasql_error; use function sasql_errorcode; @@ -13,9 +14,7 @@ /** * SAP Sybase SQL Anywhere driver exception. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ class SQLAnywhereException extends AbstractDriverException { @@ -27,16 +26,16 @@ class SQLAnywhereException extends AbstractDriverException * * @return SQLAnywhereException * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ public static function fromSQLAnywhereError($conn = null, $stmt = null) { - if (null !== $conn && ! (is_resource($conn))) { - throw new \InvalidArgumentException('Invalid SQL Anywhere connection resource given: ' . $conn); + if ($conn !== null && ! is_resource($conn)) { + throw new InvalidArgumentException('Invalid SQL Anywhere connection resource given: ' . $conn); } - if (null !== $stmt && ! (is_resource($stmt))) { - throw new \InvalidArgumentException('Invalid SQL Anywhere statement resource given: ' . $stmt); + if ($stmt !== null && ! is_resource($stmt)) { + throw new InvalidArgumentException('Invalid SQL Anywhere statement resource given: ' . $stmt); } $state = $conn ? sasql_sqlstate($conn) : sasql_sqlstate(); @@ -69,7 +68,7 @@ public static function fromSQLAnywhereError($conn = null, $stmt = null) * or the last error could not be retrieved from the given * connection / statement resource. */ - if ( ! $conn || ! $code) { + if (! $conn || ! $code) { $code = sasql_errorcode(); $message = sasql_error(); } diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php index 2f34ea8e00f..78d3fde398b 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php @@ -7,6 +7,10 @@ use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; use IteratorAggregate; +use PDO; +use ReflectionClass; +use ReflectionObject; +use stdClass; use const SASQL_BOTH; use function array_key_exists; use function func_get_args; @@ -35,45 +39,29 @@ /** * SAP SQL Anywhere implementation of the Statement interface. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ class SQLAnywhereStatement implements IteratorAggregate, Statement { - /** - * @var resource The connection resource. - */ + /** @var resource The connection resource. */ private $conn; - /** - * @var string Name of the default class to instantiate when fetching class instances. - */ + /** @var string Name of the default class to instantiate when fetching class instances. */ private $defaultFetchClass = '\stdClass'; - /** - * @var mixed[] Constructor arguments for the default class to instantiate when fetching class instances. - */ + /** @var mixed[] Constructor arguments for the default class to instantiate when fetching class instances. */ private $defaultFetchClassCtorArgs = []; - /** - * @var int Default fetch mode to use. - */ + /** @var int Default fetch mode to use. */ private $defaultFetchMode = FetchMode::MIXED; - /** - * @var resource The result set resource to fetch. - */ + /** @var resource The result set resource to fetch. */ private $result; - /** - * @var resource The prepared SQL statement to execute. - */ + /** @var resource The prepared SQL statement to execute. */ private $stmt; /** - * Constructor. - * * Prepares given statement for given connection. * * @param resource $conn The connection resource to use. @@ -83,14 +71,14 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement */ public function __construct($conn, $sql) { - if ( ! is_resource($conn)) { + if (! is_resource($conn)) { throw new SQLAnywhereException('Invalid SQL Anywhere connection resource: ' . $conn); } $this->conn = $conn; $this->stmt = sasql_prepare($conn, $sql); - if ( ! is_resource($this->stmt)) { + if (! is_resource($this->stmt)) { throw SQLAnywhereException::fromSQLAnywhereError($conn); } } @@ -122,7 +110,7 @@ public function bindParam($column, &$variable, $type = ParameterType::STRING, $l throw new SQLAnywhereException('Unknown type: ' . $type); } - if ( ! sasql_stmt_bind_param_ex($this->stmt, $column - 1, $variable, $type, $variable === null)) { + if (! sasql_stmt_bind_param_ex($this->stmt, $column - 1, $variable, $type, $variable === null)) { throw SQLAnywhereException::fromSQLAnywhereError($this->conn, $this->stmt); } @@ -144,7 +132,7 @@ public function bindValue($param, $value, $type = ParameterType::STRING) */ public function closeCursor() { - if (!sasql_stmt_reset($this->stmt)) { + if (! sasql_stmt_reset($this->stmt)) { throw SQLAnywhereException::fromSQLAnywhereError($this->conn, $this->stmt); } @@ -186,13 +174,13 @@ public function execute($params = null) $hasZeroIndex = array_key_exists(0, $params); foreach ($params as $key => $val) { - $key = ($hasZeroIndex && is_numeric($key)) ? $key + 1 : $key; + $key = $hasZeroIndex && is_numeric($key) ? $key + 1 : $key; $this->bindValue($key, $val); } } - if ( ! sasql_stmt_execute($this->stmt)) { + if (! sasql_stmt_execute($this->stmt)) { throw SQLAnywhereException::fromSQLAnywhereError($this->conn, $this->stmt); } @@ -206,9 +194,9 @@ public function execute($params = null) * * @throws SQLAnywhereException */ - public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) + public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0) { - if ( ! is_resource($this->result)) { + if (! is_resource($this->result)) { return false; } @@ -236,7 +224,7 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE $result = sasql_fetch_object($this->result); - if ($result instanceof \stdClass) { + if ($result instanceof stdClass) { $result = $this->castObject($result, $className, $ctorArgs); } @@ -289,7 +277,7 @@ public function fetchColumn($columnIndex = 0) { $row = $this->fetch(FetchMode::NUMERIC); - if (false === $row) { + if ($row === false) { return false; } @@ -325,7 +313,7 @@ public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) /** * Casts a stdClass object to the given class name mapping its' properties. * - * @param \stdClass $sourceObject Object to cast from. + * @param stdClass $sourceObject Object to cast from. * @param string|object $destinationClass Name of the class or class instance to cast to. * @param array $ctorArgs Arguments to use for constructing the destination class instance. * @@ -333,21 +321,22 @@ public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) * * @throws SQLAnywhereException */ - private function castObject(\stdClass $sourceObject, $destinationClass, array $ctorArgs = []) + private function castObject(stdClass $sourceObject, $destinationClass, array $ctorArgs = []) { - if ( ! is_string($destinationClass)) { - if ( ! is_object($destinationClass)) { + if (! is_string($destinationClass)) { + if (! is_object($destinationClass)) { throw new SQLAnywhereException(sprintf( - 'Destination class has to be of type string or object, %s given.', gettype($destinationClass) + 'Destination class has to be of type string or object, %s given.', + gettype($destinationClass) )); } } else { - $destinationClass = new \ReflectionClass($destinationClass); + $destinationClass = new ReflectionClass($destinationClass); $destinationClass = $destinationClass->newInstanceArgs($ctorArgs); } - $sourceReflection = new \ReflectionObject($sourceObject); - $destinationClassReflection = new \ReflectionObject($destinationClass); + $sourceReflection = new ReflectionObject($sourceObject); + $destinationClassReflection = new ReflectionObject($destinationClass); foreach ($sourceReflection->getProperties() as $sourceProperty) { $sourceProperty->setAccessible(true); diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php b/lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php index 0d74217d04f..2b84a0fcf81 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php @@ -14,7 +14,7 @@ class Driver extends AbstractSQLServerDriver */ public function connect(array $params, $username = null, $password = null, array $driverOptions = []) { - if (!isset($params['host'])) { + if (! isset($params['host'])) { throw new SQLSrvException("Missing 'host' in configuration for sqlsrv driver."); } @@ -26,7 +26,7 @@ public function connect(array $params, $username = null, $password = null, array if (isset($params['dbname'])) { $driverOptions['Database'] = $params['dbname']; } - + if (isset($params['charset'])) { $driverOptions['CharacterSet'] = $params['charset']; } @@ -34,7 +34,7 @@ public function connect(array $params, $username = null, $password = null, array $driverOptions['UID'] = $username; $driverOptions['PWD'] = $password; - if (!isset($driverOptions['ReturnDatesAsStrings'])) { + if (! isset($driverOptions['ReturnDatesAsStrings'])) { $driverOptions['ReturnDatesAsStrings'] = 1; } diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/LastInsertId.php b/lib/Doctrine/DBAL/Driver/SQLSrv/LastInsertId.php index 44a5b9a83f8..363b260950e 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/LastInsertId.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/LastInsertId.php @@ -4,15 +4,10 @@ /** * Last Id Data Container. - * - * @since 2.3 - * @author Benjamin Eberlei */ class LastInsertId { - /** - * @var int - */ + /** @var int */ private $id; /** diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php index 78216ed837c..243bf7569da 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php @@ -23,36 +23,29 @@ /** * SQL Server implementation for the Connection interface. - * - * @since 2.3 - * @author Benjamin Eberlei */ class SQLSrvConnection implements Connection, ServerInfoAwareConnection { - /** - * @var resource - */ + /** @var resource */ protected $conn; - /** - * @var \Doctrine\DBAL\Driver\SQLSrv\LastInsertId - */ + /** @var LastInsertId */ protected $lastInsertId; /** * @param string $serverName * @param array $connectionOptions * - * @throws \Doctrine\DBAL\Driver\SQLSrv\SQLSrvException + * @throws SQLSrvException */ public function __construct($serverName, $connectionOptions) { - if ( ! sqlsrv_configure('WarningsReturnAsErrors', 0)) { + if (! sqlsrv_configure('WarningsReturnAsErrors', 0)) { throw SQLSrvException::fromSqlSrvErrors(); } $this->conn = sqlsrv_connect($serverName, $connectionOptions); - if ( ! $this->conn) { + if (! $this->conn) { throw SQLSrvException::fromSqlSrvErrors(); } $this->lastInsertId = new LastInsertId(); @@ -90,7 +83,7 @@ public function prepare($sql) public function query() { $args = func_get_args(); - $sql = $args[0]; + $sql = $args[0]; $stmt = $this->prepare($sql); $stmt->execute(); @@ -99,7 +92,6 @@ public function query() /** * {@inheritDoc} - * @license New BSD, code from Zend Framework */ public function quote($value, $type = ParameterType::STRING) { @@ -119,7 +111,7 @@ public function exec($statement) { $stmt = sqlsrv_query($this->conn, $statement); - if (false === $stmt) { + if ($stmt === false) { throw SQLSrvException::fromSqlSrvErrors(); } @@ -146,7 +138,7 @@ public function lastInsertId($name = null) */ public function beginTransaction() { - if ( ! sqlsrv_begin_transaction($this->conn)) { + if (! sqlsrv_begin_transaction($this->conn)) { throw SQLSrvException::fromSqlSrvErrors(); } } @@ -156,7 +148,7 @@ public function beginTransaction() */ public function commit() { - if ( ! sqlsrv_commit($this->conn)) { + if (! sqlsrv_commit($this->conn)) { throw SQLSrvException::fromSqlSrvErrors(); } } @@ -166,7 +158,7 @@ public function commit() */ public function rollBack() { - if ( ! sqlsrv_rollback($this->conn)) { + if (! sqlsrv_rollback($this->conn)) { throw SQLSrvException::fromSqlSrvErrors(); } } diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvException.php b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvException.php index 4eee85f5e66..796f5d129d4 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvException.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvException.php @@ -2,7 +2,6 @@ namespace Doctrine\DBAL\Driver\SQLSrv; - use Doctrine\DBAL\Driver\AbstractDriverException; use const SQLSRV_ERR_ERRORS; use function rtrim; @@ -17,24 +16,26 @@ class SQLSrvException extends AbstractDriverException */ public static function fromSqlSrvErrors() { - $errors = sqlsrv_errors(SQLSRV_ERR_ERRORS); - $message = ""; - $sqlState = null; + $errors = sqlsrv_errors(SQLSRV_ERR_ERRORS); + $message = ''; + $sqlState = null; $errorCode = null; foreach ($errors as $error) { - $message .= "SQLSTATE [".$error['SQLSTATE'].", ".$error['code']."]: ". $error['message']."\n"; + $message .= 'SQLSTATE [' . $error['SQLSTATE'] . ', ' . $error['code'] . ']: ' . $error['message'] . "\n"; - if (null === $sqlState) { + if ($sqlState === null) { $sqlState = $error['SQLSTATE']; } - if (null === $errorCode) { - $errorCode = $error['code']; + if ($errorCode !== null) { + continue; } + + $errorCode = $error['code']; } - if ( ! $message) { - $message = "SQL Server error occurred but no error message was retrieved from driver."; + if (! $message) { + $message = 'SQL Server error occurred but no error message was retrieved from driver.'; } return new self(rtrim($message), $sqlState, $errorCode); diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php index 7ab219c437e..23dfb6c0658 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php @@ -2,11 +2,12 @@ namespace Doctrine\DBAL\Driver\SQLSrv; +use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\Driver\StatementIterator; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; use IteratorAggregate; -use Doctrine\DBAL\Driver\Statement; +use PDO; use const SQLSRV_ENC_BINARY; use const SQLSRV_ERR_ERRORS; use const SQLSRV_FETCH_ASSOC; @@ -35,9 +36,6 @@ /** * SQL Server Statement. - * - * @since 2.3 - * @author Benjamin Eberlei */ class SQLSrvStatement implements IteratorAggregate, Statement { @@ -111,7 +109,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement /** * The last insert ID. * - * @var \Doctrine\DBAL\Driver\SQLSrv\LastInsertId|null + * @var LastInsertId|null */ private $lastInsertId; @@ -124,25 +122,24 @@ class SQLSrvStatement implements IteratorAggregate, Statement /** * Append to any INSERT query to retrieve the last insert id. - * - * @var string */ - const LAST_INSERT_ID_SQL = ';SELECT SCOPE_IDENTITY() AS LastInsertId;'; + public const LAST_INSERT_ID_SQL = ';SELECT SCOPE_IDENTITY() AS LastInsertId;'; /** - * @param resource $conn - * @param string $sql - * @param \Doctrine\DBAL\Driver\SQLSrv\LastInsertId|null $lastInsertId + * @param resource $conn + * @param string $sql */ - public function __construct($conn, $sql, LastInsertId $lastInsertId = null) + public function __construct($conn, $sql, ?LastInsertId $lastInsertId = null) { $this->conn = $conn; - $this->sql = $sql; + $this->sql = $sql; - if (stripos($sql, 'INSERT INTO ') === 0) { - $this->sql .= self::LAST_INSERT_ID_SQL; - $this->lastInsertId = $lastInsertId; + if (stripos($sql, 'INSERT INTO ') !== 0) { + return; } + + $this->sql .= self::LAST_INSERT_ID_SQL; + $this->lastInsertId = $lastInsertId; } /** @@ -150,14 +147,14 @@ public function __construct($conn, $sql, LastInsertId $lastInsertId = null) */ public function bindValue($param, $value, $type = ParameterType::STRING) { - if (!is_numeric($param)) { + if (! is_numeric($param)) { throw new SQLSrvException( 'sqlsrv does not support named parameters to queries, use question mark (?) placeholders instead.' ); } $this->variables[$param] = $value; - $this->types[$param] = $type; + $this->types[$param] = $type; } /** @@ -165,12 +162,12 @@ public function bindValue($param, $value, $type = ParameterType::STRING) */ public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null) { - if (!is_numeric($column)) { - throw new SQLSrvException("sqlsrv does not support named parameters to queries, use question mark (?) placeholders instead."); + if (! is_numeric($column)) { + throw new SQLSrvException('sqlsrv does not support named parameters to queries, use question mark (?) placeholders instead.'); } $this->variables[$column] =& $variable; - $this->types[$column] = $type; + $this->types[$column] = $type; // unset the statement resource if it exists as the new one will need to be bound to the new variable $this->stmt = null; @@ -182,7 +179,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->result) { return true; } @@ -190,7 +187,8 @@ public function closeCursor() // @link http://php.net/manual/en/pdostatement.closecursor.php // @link https://github.com/php/php-src/blob/php-7.0.11/ext/pdo/pdo_stmt.c#L2075 // deliberately do not consider multiple result sets, since doctrine/dbal doesn't support them - while (sqlsrv_fetch($this->stmt)); + while (sqlsrv_fetch($this->stmt)) { + } $this->result = false; @@ -234,16 +232,16 @@ 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; + $key = $hasZeroIndex && is_numeric($key) ? $key + 1 : $key; $this->bindValue($key, $val); } } - if ( ! $this->stmt) { + if (! $this->stmt) { $this->stmt = $this->prepare(); } - if (!sqlsrv_execute($this->stmt)) { + if (! sqlsrv_execute($this->stmt)) { throw SQLSrvException::fromSqlSrvErrors(); } @@ -260,6 +258,7 @@ public function execute($params = null) * Prepares SQL Server statement resource * * @return resource + * * @throws SQLSrvException */ private function prepare() @@ -272,8 +271,8 @@ private function prepare() $params[$column - 1] = [ &$variable, SQLSRV_PARAM_IN, - SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), - SQLSRV_SQLTYPE_VARBINARY('max'), + sqlsrv_phptype_stream(SQLSRV_ENC_BINARY), + sqlsrv_sqltype_varbinary('max'), ]; break; @@ -281,7 +280,7 @@ private function prepare() $params[$column - 1] = [ &$variable, SQLSRV_PARAM_IN, - SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY), + sqlsrv_phptype_string(SQLSRV_ENC_BINARY), ]; break; @@ -293,7 +292,7 @@ private function prepare() $stmt = sqlsrv_prepare($this->conn, $this->sql, $params); - if (!$stmt) { + if (! $stmt) { throw SQLSrvException::fromSqlSrvErrors(); } @@ -325,11 +324,11 @@ public function getIterator() * * @throws SQLSrvException */ - public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) + public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0) { // 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->result) { return false; } @@ -395,7 +394,7 @@ public function fetchColumn($columnIndex = 0) { $row = $this->fetch(FetchMode::NUMERIC); - if (false === $row) { + if ($row === false) { return false; } diff --git a/lib/Doctrine/DBAL/Driver/ServerInfoAwareConnection.php b/lib/Doctrine/DBAL/Driver/ServerInfoAwareConnection.php index 588ec859720..35bf9ebd094 100644 --- a/lib/Doctrine/DBAL/Driver/ServerInfoAwareConnection.php +++ b/lib/Doctrine/DBAL/Driver/ServerInfoAwareConnection.php @@ -5,9 +5,7 @@ /** * Contract for a connection that is able to provide information about the server it is connected to. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ interface ServerInfoAwareConnection { diff --git a/lib/Doctrine/DBAL/Driver/Statement.php b/lib/Doctrine/DBAL/Driver/Statement.php index 39dbc86c451..66f17ab7c51 100644 --- a/lib/Doctrine/DBAL/Driver/Statement.php +++ b/lib/Doctrine/DBAL/Driver/Statement.php @@ -10,10 +10,7 @@ * * This resembles (a subset of) the PDOStatement interface. * - * @author Konsta Vesterinen - * @author Roman Borschel * @link www.doctrine-project.org - * @since 2.0 */ interface Statement extends ResultStatement { @@ -90,7 +87,6 @@ public function errorInfo(); * if any, of their associated parameter markers or pass an array of input-only * parameter values. * - * * @param array|null $params An array of values with as many elements as there are * bound parameters in the SQL statement being executed. * diff --git a/lib/Doctrine/DBAL/Driver/StatementIterator.php b/lib/Doctrine/DBAL/Driver/StatementIterator.php index 2dc3f2b3d13..5246b38a448 100644 --- a/lib/Doctrine/DBAL/Driver/StatementIterator.php +++ b/lib/Doctrine/DBAL/Driver/StatementIterator.php @@ -2,16 +2,13 @@ namespace Doctrine\DBAL\Driver; -class StatementIterator implements \IteratorAggregate +use IteratorAggregate; + +class StatementIterator implements IteratorAggregate { - /** - * @var Statement - */ + /** @var Statement */ private $statement; - /** - * @param Statement $statement - */ public function __construct(Statement $statement) { $this->statement = $statement; @@ -22,7 +19,7 @@ public function __construct(Statement $statement) */ public function getIterator() { - while (false !== ($result = $this->statement->fetch())) { + while (($result = $this->statement->fetch()) !== false) { yield $result; } } diff --git a/lib/Doctrine/DBAL/DriverManager.php b/lib/Doctrine/DBAL/DriverManager.php index a9f27495dc9..1b5d64cc329 100644 --- a/lib/Doctrine/DBAL/DriverManager.php +++ b/lib/Doctrine/DBAL/DriverManager.php @@ -3,6 +3,7 @@ namespace Doctrine\DBAL; use Doctrine\Common\EventManager; +use PDO; use function array_keys; use function array_map; use function array_merge; @@ -18,9 +19,6 @@ /** * Factory for creating Doctrine\DBAL\Connection instances. - * - * @author Roman Borschel - * @since 2.0 */ final class DriverManager { @@ -32,18 +30,18 @@ final class DriverManager * * @var array */ - private static $_driverMap = [ - 'pdo_mysql' => 'Doctrine\DBAL\Driver\PDOMySql\Driver', - 'pdo_sqlite' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver', - 'pdo_pgsql' => 'Doctrine\DBAL\Driver\PDOPgSql\Driver', - 'pdo_oci' => 'Doctrine\DBAL\Driver\PDOOracle\Driver', - 'oci8' => 'Doctrine\DBAL\Driver\OCI8\Driver', - 'ibm_db2' => 'Doctrine\DBAL\Driver\IBMDB2\DB2Driver', - 'pdo_sqlsrv' => 'Doctrine\DBAL\Driver\PDOSqlsrv\Driver', - 'mysqli' => 'Doctrine\DBAL\Driver\Mysqli\Driver', - 'drizzle_pdo_mysql' => 'Doctrine\DBAL\Driver\DrizzlePDOMySql\Driver', - 'sqlanywhere' => 'Doctrine\DBAL\Driver\SQLAnywhere\Driver', - 'sqlsrv' => 'Doctrine\DBAL\Driver\SQLSrv\Driver', + private static $_driverMap = [ + 'pdo_mysql' => 'Doctrine\DBAL\Driver\PDOMySql\Driver', + 'pdo_sqlite' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver', + 'pdo_pgsql' => 'Doctrine\DBAL\Driver\PDOPgSql\Driver', + 'pdo_oci' => 'Doctrine\DBAL\Driver\PDOOracle\Driver', + 'oci8' => 'Doctrine\DBAL\Driver\OCI8\Driver', + 'ibm_db2' => 'Doctrine\DBAL\Driver\IBMDB2\DB2Driver', + 'pdo_sqlsrv' => 'Doctrine\DBAL\Driver\PDOSqlsrv\Driver', + 'mysqli' => 'Doctrine\DBAL\Driver\Mysqli\Driver', + 'drizzle_pdo_mysql' => 'Doctrine\DBAL\Driver\DrizzlePDOMySql\Driver', + 'sqlanywhere' => 'Doctrine\DBAL\Driver\SQLAnywhere\Driver', + 'sqlsrv' => 'Doctrine\DBAL\Driver\SQLSrv\Driver', ]; /** @@ -115,24 +113,22 @@ private function __construct() * driverClass: * The driver class to use. * - * @param array $params The parameters. - * @param \Doctrine\DBAL\Configuration|null $config The configuration to use. - * @param \Doctrine\Common\EventManager|null $eventManager The event manager to use. + * @param array $params The parameters. + * @param Configuration|null $config The configuration to use. + * @param EventManager|null $eventManager The event manager to use. * - * @return \Doctrine\DBAL\Connection - * - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ public static function getConnection( - array $params, - Configuration $config = null, - EventManager $eventManager = null): Connection - { + array $params, + ?Configuration $config = null, + ?EventManager $eventManager = null + ) : Connection { // create default config and event manager, if not set - if ( ! $config) { + if (! $config) { $config = new Configuration(); } - if ( ! $eventManager) { + if (! $eventManager) { $eventManager = new EventManager(); } @@ -161,11 +157,11 @@ public static function getConnection( } // check for existing pdo object - if (isset($params['pdo']) && ! $params['pdo'] instanceof \PDO) { + if (isset($params['pdo']) && ! $params['pdo'] instanceof PDO) { throw DBALException::invalidPdoInstance(); } elseif (isset($params['pdo'])) { - $params['pdo']->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); - $params['driver'] = 'pdo_' . $params['pdo']->getAttribute(\PDO::ATTR_DRIVER_NAME); + $params['pdo']->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $params['driver'] = 'pdo_' . $params['pdo']->getAttribute(PDO::ATTR_DRIVER_NAME); } else { self::_checkParams($params); } @@ -176,11 +172,11 @@ public static function getConnection( $wrapperClass = 'Doctrine\DBAL\Connection'; if (isset($params['wrapperClass'])) { - if (is_subclass_of($params['wrapperClass'], $wrapperClass)) { - $wrapperClass = $params['wrapperClass']; - } else { + if (! is_subclass_of($params['wrapperClass'], $wrapperClass)) { throw DBALException::invalidWrapperClass($params['wrapperClass']); } + + $wrapperClass = $params['wrapperClass']; } return new $wrapperClass($params, $driver, $config, $eventManager); @@ -191,7 +187,7 @@ public static function getConnection( * * @return array */ - public static function getAvailableDrivers(): array + public static function getAvailableDrivers() : array { return array_keys(self::$_driverMap); } @@ -201,16 +197,14 @@ public static function getAvailableDrivers(): array * * @param array $params The list of parameters. * - * @return void - * - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ - private static function _checkParams(array $params): void + private static function _checkParams(array $params) : void { // check existence of mandatory parameters // driver - if ( ! isset($params['driver']) && ! isset($params['driverClass'])) { + if (! isset($params['driver']) && ! isset($params['driverClass'])) { throw DBALException::driverRequired(); } @@ -229,11 +223,9 @@ private static function _checkParams(array $params): void /** * Normalizes the given connection URL path. * - * @param string $urlPath - * * @return string The normalized connection URL path */ - private static function normalizeDatabaseUrlPath(string $urlPath): string + private static function normalizeDatabaseUrlPath(string $urlPath) : string { // Trim leading slash from URL path. return substr($urlPath, 1); @@ -250,9 +242,9 @@ private static function normalizeDatabaseUrlPath(string $urlPath): string * * @throws DBALException */ - private static function parseDatabaseUrl(array $params): array + private static function parseDatabaseUrl(array $params) : array { - if (!isset($params['url'])) { + if (! isset($params['url'])) { return $params; } @@ -297,14 +289,14 @@ private static function parseDatabaseUrl(array $params): array * Assumes that the connection URL scheme is already parsed and resolved into the given connection parameters * via {@link parseDatabaseUrlScheme}. * + * @see parseDatabaseUrlScheme + * * @param array $url The URL parts to evaluate. * @param array $params The connection parameters to resolve. * * @return array The resolved connection parameters. - * - * @see parseDatabaseUrlScheme */ - private static function parseDatabaseUrlPath(array $url, array $params): array + private static function parseDatabaseUrlPath(array $url, array $params) : array { if (! isset($url['path'])) { return $params; @@ -333,7 +325,7 @@ private static function parseDatabaseUrlPath(array $url, array $params): array * * @return array The resolved connection parameters. */ - private static function parseDatabaseUrlQuery(array $url, array $params): array + private static function parseDatabaseUrlQuery(array $url, array $params) : array { if (! isset($url['query'])) { return $params; @@ -351,14 +343,14 @@ private static function parseDatabaseUrlQuery(array $url, array $params): array * * Assumes that the "path" URL part is already normalized via {@link normalizeDatabaseUrlPath}. * + * @see normalizeDatabaseUrlPath + * * @param array $url The regular connection URL parts to evaluate. * @param array $params The connection parameters to resolve. * * @return array The resolved connection parameters. - * - * @see normalizeDatabaseUrlPath */ - private static function parseRegularDatabaseUrlPath(array $url, array $params): array + private static function parseRegularDatabaseUrlPath(array $url, array $params) : array { $params['dbname'] = $url['path']; @@ -370,14 +362,14 @@ private static function parseRegularDatabaseUrlPath(array $url, array $params): * * Assumes that the "path" URL part is already normalized via {@link normalizeDatabaseUrlPath}. * + * @see normalizeDatabaseUrlPath + * * @param array $url The SQLite connection URL parts to evaluate. * @param array $params The connection parameters to resolve. * * @return array The resolved connection parameters. - * - * @see normalizeDatabaseUrlPath */ - private static function parseSqliteDatabaseUrlPath(array $url, array $params): array + private static function parseSqliteDatabaseUrlPath(array $url, array $params) : array { if ($url['path'] === ':memory:') { $params['memory'] = true; @@ -400,7 +392,7 @@ private static function parseSqliteDatabaseUrlPath(array $url, array $params): a * * @throws DBALException if parsing failed or resolution is not possible. */ - private static function parseDatabaseUrlScheme(array $url, array $params): array + private static function parseDatabaseUrlScheme(array $url, array $params) : array { if (isset($url['scheme'])) { // The requested driver from the URL scheme takes precedence diff --git a/lib/Doctrine/DBAL/Event/ConnectionEventArgs.php b/lib/Doctrine/DBAL/Event/ConnectionEventArgs.php index 5f8abc1ee59..9492005ad6b 100644 --- a/lib/Doctrine/DBAL/Event/ConnectionEventArgs.php +++ b/lib/Doctrine/DBAL/Event/ConnectionEventArgs.php @@ -4,31 +4,27 @@ use Doctrine\Common\EventArgs; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver; +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Schema\AbstractSchemaManager; /** * Event Arguments used when a Driver connection is established inside Doctrine\DBAL\Connection. * * @link www.doctrine-project.org - * @since 1.0 - * @author Benjamin Eberlei */ class ConnectionEventArgs extends EventArgs { - /** - * @var \Doctrine\DBAL\Connection - */ + /** @var Connection */ private $_connection; - /** - * @param \Doctrine\DBAL\Connection $connection - */ public function __construct(Connection $connection) { $this->_connection = $connection; } /** - * @return \Doctrine\DBAL\Connection + * @return Connection */ public function getConnection() { @@ -36,7 +32,7 @@ public function getConnection() } /** - * @return \Doctrine\DBAL\Driver + * @return Driver */ public function getDriver() { @@ -44,7 +40,7 @@ public function getDriver() } /** - * @return \Doctrine\DBAL\Platforms\AbstractPlatform + * @return AbstractPlatform */ public function getDatabasePlatform() { @@ -52,7 +48,7 @@ public function getDatabasePlatform() } /** - * @return \Doctrine\DBAL\Schema\AbstractSchemaManager + * @return AbstractSchemaManager */ public function getSchemaManager() { diff --git a/lib/Doctrine/DBAL/Event/Listeners/MysqlSessionInit.php b/lib/Doctrine/DBAL/Event/Listeners/MysqlSessionInit.php index d65f3f799a1..c16d4aea329 100644 --- a/lib/Doctrine/DBAL/Event/Listeners/MysqlSessionInit.php +++ b/lib/Doctrine/DBAL/Event/Listeners/MysqlSessionInit.php @@ -2,17 +2,16 @@ namespace Doctrine\DBAL\Event\Listeners; +use Doctrine\Common\EventSubscriber; use Doctrine\DBAL\Event\ConnectionEventArgs; use Doctrine\DBAL\Events; -use Doctrine\Common\EventSubscriber; /** * MySQL Session Init Event Subscriber which allows to set the Client Encoding of the Connection. * - * @link www.doctrine-project.org - * @since 1.0 - * @author Benjamin Eberlei * @deprecated Use "charset" option to PDO MySQL Connection instead. + * + * @link www.doctrine-project.org */ class MysqlSessionInit implements EventSubscriber { @@ -26,31 +25,29 @@ class MysqlSessionInit implements EventSubscriber /** * The collation, or FALSE if no collation. * - * @var string|boolean + * @var string|bool */ private $_collation; /** * Configure Charset and Collation options of MySQL Client for each Connection. * - * @param string $charset The charset. - * @param string|boolean $collation The collation, or FALSE if no collation. + * @param string $charset The charset. + * @param string|bool $collation The collation, or FALSE if no collation. */ public function __construct($charset = 'utf8', $collation = false) { - $this->_charset = $charset; + $this->_charset = $charset; $this->_collation = $collation; } /** - * @param \Doctrine\DBAL\Event\ConnectionEventArgs $args - * * @return void */ public function postConnect(ConnectionEventArgs $args) { - $collation = ($this->_collation) ? " COLLATE ".$this->_collation : ""; - $args->getConnection()->executeUpdate("SET NAMES ".$this->_charset . $collation); + $collation = $this->_collation ? ' COLLATE ' . $this->_collation : ''; + $args->getConnection()->executeUpdate('SET NAMES ' . $this->_charset . $collation); } /** diff --git a/lib/Doctrine/DBAL/Event/Listeners/OracleSessionInit.php b/lib/Doctrine/DBAL/Event/Listeners/OracleSessionInit.php index f024a92190b..8415e2e49d4 100644 --- a/lib/Doctrine/DBAL/Event/Listeners/OracleSessionInit.php +++ b/lib/Doctrine/DBAL/Event/Listeners/OracleSessionInit.php @@ -2,9 +2,10 @@ namespace Doctrine\DBAL\Event\Listeners; +use Doctrine\Common\EventSubscriber; use Doctrine\DBAL\Event\ConnectionEventArgs; use Doctrine\DBAL\Events; -use Doctrine\Common\EventSubscriber; +use const CASE_UPPER; use function array_change_key_case; use function array_merge; use function count; @@ -21,20 +22,16 @@ * NLS_TIMESTAMP_TZ_FORMAT="YYYY-MM-DD HH24:MI:SS TZH:TZM" * * @link www.doctrine-project.org - * @since 2.0 - * @author Benjamin Eberlei */ class OracleSessionInit implements EventSubscriber { - /** - * @var array - */ + /** @var array */ protected $_defaultSessionVars = [ - 'NLS_TIME_FORMAT' => "HH24:MI:SS", - 'NLS_DATE_FORMAT' => "YYYY-MM-DD HH24:MI:SS", - 'NLS_TIMESTAMP_FORMAT' => "YYYY-MM-DD HH24:MI:SS", - 'NLS_TIMESTAMP_TZ_FORMAT' => "YYYY-MM-DD HH24:MI:SS TZH:TZM", - 'NLS_NUMERIC_CHARACTERS' => ".,", + 'NLS_TIME_FORMAT' => 'HH24:MI:SS', + 'NLS_DATE_FORMAT' => 'YYYY-MM-DD HH24:MI:SS', + 'NLS_TIMESTAMP_FORMAT' => 'YYYY-MM-DD HH24:MI:SS', + 'NLS_TIMESTAMP_TZ_FORMAT' => 'YYYY-MM-DD HH24:MI:SS TZH:TZM', + 'NLS_NUMERIC_CHARACTERS' => '.,', ]; /** @@ -46,25 +43,25 @@ public function __construct(array $oracleSessionVars = []) } /** - * @param \Doctrine\DBAL\Event\ConnectionEventArgs $args - * * @return void */ public function postConnect(ConnectionEventArgs $args) { - if (count($this->_defaultSessionVars)) { - array_change_key_case($this->_defaultSessionVars, \CASE_UPPER); - $vars = []; - foreach ($this->_defaultSessionVars as $option => $value) { - if ($option === 'CURRENT_SCHEMA') { - $vars[] = $option . " = " . $value; - } else { - $vars[] = $option . " = '" . $value . "'"; - } + if (! count($this->_defaultSessionVars)) { + return; + } + + array_change_key_case($this->_defaultSessionVars, CASE_UPPER); + $vars = []; + foreach ($this->_defaultSessionVars as $option => $value) { + if ($option === 'CURRENT_SCHEMA') { + $vars[] = $option . ' = ' . $value; + } else { + $vars[] = $option . " = '" . $value . "'"; } - $sql = "ALTER SESSION SET ".implode(" ", $vars); - $args->getConnection()->executeUpdate($sql); } + $sql = 'ALTER SESSION SET ' . implode(' ', $vars); + $args->getConnection()->executeUpdate($sql); } /** diff --git a/lib/Doctrine/DBAL/Event/Listeners/SQLSessionInit.php b/lib/Doctrine/DBAL/Event/Listeners/SQLSessionInit.php index 3eab0e8b58b..8b25489ca7f 100644 --- a/lib/Doctrine/DBAL/Event/Listeners/SQLSessionInit.php +++ b/lib/Doctrine/DBAL/Event/Listeners/SQLSessionInit.php @@ -2,22 +2,18 @@ namespace Doctrine\DBAL\Event\Listeners; +use Doctrine\Common\EventSubscriber; use Doctrine\DBAL\Event\ConnectionEventArgs; use Doctrine\DBAL\Events; -use Doctrine\Common\EventSubscriber; /** * Session init listener for executing a single SQL statement right after a connection is opened. * * @link www.doctrine-project.org - * @since 2.2 - * @author Benjamin Eberlei */ class SQLSessionInit implements EventSubscriber { - /** - * @var string - */ + /** @var string */ protected $sql; /** @@ -29,8 +25,6 @@ public function __construct($sql) } /** - * @param \Doctrine\DBAL\Event\ConnectionEventArgs $args - * * @return void */ public function postConnect(ConnectionEventArgs $args) diff --git a/lib/Doctrine/DBAL/Event/SchemaAlterTableAddColumnEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaAlterTableAddColumnEventArgs.php index b4f281f6098..7d07abc1d57 100644 --- a/lib/Doctrine/DBAL/Event/SchemaAlterTableAddColumnEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaAlterTableAddColumnEventArgs.php @@ -12,36 +12,21 @@ * Event Arguments used when SQL queries for adding table columns are generated inside Doctrine\DBAL\Platform\*Platform. * * @link www.doctrine-project.org - * @since 2.2 - * @author Jan Sorgalla */ class SchemaAlterTableAddColumnEventArgs extends SchemaEventArgs { - /** - * @var \Doctrine\DBAL\Schema\Column - */ + /** @var Column */ private $_column; - /** - * @var \Doctrine\DBAL\Schema\TableDiff - */ + /** @var TableDiff */ private $_tableDiff; - /** - * @var \Doctrine\DBAL\Platforms\AbstractPlatform - */ + /** @var AbstractPlatform */ private $_platform; - /** - * @var array - */ + /** @var array */ private $_sql = []; - /** - * @param \Doctrine\DBAL\Schema\Column $column - * @param \Doctrine\DBAL\Schema\TableDiff $tableDiff - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform - */ public function __construct(Column $column, TableDiff $tableDiff, AbstractPlatform $platform) { $this->_column = $column; @@ -50,7 +35,7 @@ public function __construct(Column $column, TableDiff $tableDiff, AbstractPlatfo } /** - * @return \Doctrine\DBAL\Schema\Column + * @return Column */ public function getColumn() { @@ -58,7 +43,7 @@ public function getColumn() } /** - * @return \Doctrine\DBAL\Schema\TableDiff + * @return TableDiff */ public function getTableDiff() { @@ -66,7 +51,7 @@ public function getTableDiff() } /** - * @return \Doctrine\DBAL\Platforms\AbstractPlatform + * @return AbstractPlatform */ public function getPlatform() { diff --git a/lib/Doctrine/DBAL/Event/SchemaAlterTableChangeColumnEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaAlterTableChangeColumnEventArgs.php index 55392c67cae..b3ecfa78ef2 100644 --- a/lib/Doctrine/DBAL/Event/SchemaAlterTableChangeColumnEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaAlterTableChangeColumnEventArgs.php @@ -12,36 +12,21 @@ * Event Arguments used when SQL queries for changing table columns are generated inside Doctrine\DBAL\Platform\*Platform. * * @link www.doctrine-project.org - * @since 2.2 - * @author Jan Sorgalla */ class SchemaAlterTableChangeColumnEventArgs extends SchemaEventArgs { - /** - * @var \Doctrine\DBAL\Schema\ColumnDiff - */ + /** @var ColumnDiff */ private $_columnDiff; - /** - * @var \Doctrine\DBAL\Schema\TableDiff - */ + /** @var TableDiff */ private $_tableDiff; - /** - * @var \Doctrine\DBAL\Platforms\AbstractPlatform - */ + /** @var AbstractPlatform */ private $_platform; - /** - * @var array - */ + /** @var array */ private $_sql = []; - /** - * @param \Doctrine\DBAL\Schema\ColumnDiff $columnDiff - * @param \Doctrine\DBAL\Schema\TableDiff $tableDiff - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform - */ public function __construct(ColumnDiff $columnDiff, TableDiff $tableDiff, AbstractPlatform $platform) { $this->_columnDiff = $columnDiff; @@ -50,7 +35,7 @@ public function __construct(ColumnDiff $columnDiff, TableDiff $tableDiff, Abstra } /** - * @return \Doctrine\DBAL\Schema\ColumnDiff + * @return ColumnDiff */ public function getColumnDiff() { @@ -58,7 +43,7 @@ public function getColumnDiff() } /** - * @return \Doctrine\DBAL\Schema\TableDiff + * @return TableDiff */ public function getTableDiff() { @@ -66,7 +51,7 @@ public function getTableDiff() } /** - * @return \Doctrine\DBAL\Platforms\AbstractPlatform + * @return AbstractPlatform */ public function getPlatform() { diff --git a/lib/Doctrine/DBAL/Event/SchemaAlterTableEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaAlterTableEventArgs.php index 4dcbbe0963d..9684fbae646 100644 --- a/lib/Doctrine/DBAL/Event/SchemaAlterTableEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaAlterTableEventArgs.php @@ -11,30 +11,18 @@ * Event Arguments used when SQL queries for creating tables are generated inside Doctrine\DBAL\Platform\*Platform. * * @link www.doctrine-project.org - * @since 2.2 - * @author Jan Sorgalla */ class SchemaAlterTableEventArgs extends SchemaEventArgs { - /** - * @var \Doctrine\DBAL\Schema\TableDiff - */ + /** @var TableDiff */ private $_tableDiff; - /** - * @var \Doctrine\DBAL\Platforms\AbstractPlatform - */ + /** @var AbstractPlatform */ private $_platform; - /** - * @var array - */ + /** @var array */ private $_sql = []; - /** - * @param \Doctrine\DBAL\Schema\TableDiff $tableDiff - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform - */ public function __construct(TableDiff $tableDiff, AbstractPlatform $platform) { $this->_tableDiff = $tableDiff; @@ -42,7 +30,7 @@ public function __construct(TableDiff $tableDiff, AbstractPlatform $platform) } /** - * @return \Doctrine\DBAL\Schema\TableDiff + * @return TableDiff */ public function getTableDiff() { @@ -50,7 +38,7 @@ public function getTableDiff() } /** - * @return \Doctrine\DBAL\Platforms\AbstractPlatform + * @return AbstractPlatform */ public function getPlatform() { diff --git a/lib/Doctrine/DBAL/Event/SchemaAlterTableRemoveColumnEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaAlterTableRemoveColumnEventArgs.php index 2a6aa93b2dd..36798a7661b 100644 --- a/lib/Doctrine/DBAL/Event/SchemaAlterTableRemoveColumnEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaAlterTableRemoveColumnEventArgs.php @@ -12,36 +12,21 @@ * Event Arguments used when SQL queries for removing table columns are generated inside Doctrine\DBAL\Platform\*Platform. * * @link www.doctrine-project.org - * @since 2.2 - * @author Jan Sorgalla */ class SchemaAlterTableRemoveColumnEventArgs extends SchemaEventArgs { - /** - * @var \Doctrine\DBAL\Schema\Column - */ + /** @var Column */ private $_column; - /** - * @var \Doctrine\DBAL\Schema\TableDiff - */ + /** @var TableDiff */ private $_tableDiff; - /** - * @var \Doctrine\DBAL\Platforms\AbstractPlatform - */ + /** @var AbstractPlatform */ private $_platform; - /** - * @var array - */ + /** @var array */ private $_sql = []; - /** - * @param \Doctrine\DBAL\Schema\Column $column - * @param \Doctrine\DBAL\Schema\TableDiff $tableDiff - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform - */ public function __construct(Column $column, TableDiff $tableDiff, AbstractPlatform $platform) { $this->_column = $column; @@ -50,7 +35,7 @@ public function __construct(Column $column, TableDiff $tableDiff, AbstractPlatfo } /** - * @return \Doctrine\DBAL\Schema\Column + * @return Column */ public function getColumn() { @@ -58,7 +43,7 @@ public function getColumn() } /** - * @return \Doctrine\DBAL\Schema\TableDiff + * @return TableDiff */ public function getTableDiff() { @@ -66,7 +51,7 @@ public function getTableDiff() } /** - * @return \Doctrine\DBAL\Platforms\AbstractPlatform + * @return AbstractPlatform */ public function getPlatform() { diff --git a/lib/Doctrine/DBAL/Event/SchemaAlterTableRenameColumnEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaAlterTableRenameColumnEventArgs.php index f0d0500c568..8b15a270998 100644 --- a/lib/Doctrine/DBAL/Event/SchemaAlterTableRenameColumnEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaAlterTableRenameColumnEventArgs.php @@ -12,41 +12,26 @@ * Event Arguments used when SQL queries for renaming table columns are generated inside Doctrine\DBAL\Platform\*Platform. * * @link www.doctrine-project.org - * @since 2.2 - * @author Jan Sorgalla */ class SchemaAlterTableRenameColumnEventArgs extends SchemaEventArgs { - /** - * @var string - */ + /** @var string */ private $_oldColumnName; - /** - * @var \Doctrine\DBAL\Schema\Column - */ + /** @var Column */ private $_column; - /** - * @var \Doctrine\DBAL\Schema\TableDiff - */ + /** @var TableDiff */ private $_tableDiff; - /** - * @var \Doctrine\DBAL\Platforms\AbstractPlatform - */ + /** @var AbstractPlatform */ private $_platform; - /** - * @var array - */ + /** @var array */ private $_sql = []; /** - * @param string $oldColumnName - * @param \Doctrine\DBAL\Schema\Column $column - * @param \Doctrine\DBAL\Schema\TableDiff $tableDiff - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform + * @param string $oldColumnName */ public function __construct($oldColumnName, Column $column, TableDiff $tableDiff, AbstractPlatform $platform) { @@ -65,7 +50,7 @@ public function getOldColumnName() } /** - * @return \Doctrine\DBAL\Schema\Column + * @return Column */ public function getColumn() { @@ -73,7 +58,7 @@ public function getColumn() } /** - * @return \Doctrine\DBAL\Schema\TableDiff + * @return TableDiff */ public function getTableDiff() { @@ -81,7 +66,7 @@ public function getTableDiff() } /** - * @return \Doctrine\DBAL\Platforms\AbstractPlatform + * @return AbstractPlatform */ public function getPlatform() { diff --git a/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php index 192a7400aef..270ab8d8027 100644 --- a/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php @@ -3,20 +3,17 @@ namespace Doctrine\DBAL\Event; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\Column; /** * Event Arguments used when the portable column definition is generated inside Doctrine\DBAL\Schema\AbstractSchemaManager. * * @link www.doctrine-project.org - * @since 2.2 - * @author Jan Sorgalla */ class SchemaColumnDefinitionEventArgs extends SchemaEventArgs { - /** - * @var \Doctrine\DBAL\Schema\Column|null - */ + /** @var Column|null */ private $_column = null; /** @@ -26,26 +23,19 @@ class SchemaColumnDefinitionEventArgs extends SchemaEventArgs */ private $_tableColumn; - /** - * @var string - */ + /** @var string */ private $_table; - /** - * @var string - */ + /** @var string */ private $_database; - /** - * @var \Doctrine\DBAL\Connection - */ + /** @var Connection */ private $_connection; /** - * @param array $tableColumn - * @param string $table - * @param string $database - * @param \Doctrine\DBAL\Connection $connection + * @param array $tableColumn + * @param string $table + * @param string $database */ public function __construct(array $tableColumn, $table, $database, Connection $connection) { @@ -59,11 +49,9 @@ public function __construct(array $tableColumn, $table, $database, Connection $c * Allows to clear the column which means the column will be excluded from * tables column list. * - * @param null|\Doctrine\DBAL\Schema\Column $column - * * @return \Doctrine\DBAL\Event\SchemaColumnDefinitionEventArgs */ - public function setColumn(Column $column = null) + public function setColumn(?Column $column = null) { $this->_column = $column; @@ -71,7 +59,7 @@ public function setColumn(Column $column = null) } /** - * @return \Doctrine\DBAL\Schema\Column|null + * @return Column|null */ public function getColumn() { @@ -103,7 +91,7 @@ public function getDatabase() } /** - * @return \Doctrine\DBAL\Connection + * @return Connection */ public function getConnection() { @@ -111,7 +99,7 @@ public function getConnection() } /** - * @return \Doctrine\DBAL\Platforms\AbstractPlatform + * @return AbstractPlatform */ public function getDatabasePlatform() { diff --git a/lib/Doctrine/DBAL/Event/SchemaCreateTableColumnEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaCreateTableColumnEventArgs.php index e3f414d575c..db1f53e846e 100644 --- a/lib/Doctrine/DBAL/Event/SchemaCreateTableColumnEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaCreateTableColumnEventArgs.php @@ -12,36 +12,21 @@ * Event Arguments used when SQL queries for creating table columns are generated inside Doctrine\DBAL\Platform\AbstractPlatform. * * @link www.doctrine-project.org - * @since 2.2 - * @author Jan Sorgalla */ class SchemaCreateTableColumnEventArgs extends SchemaEventArgs { - /** - * @var \Doctrine\DBAL\Schema\Column - */ + /** @var Column */ private $_column; - /** - * @var \Doctrine\DBAL\Schema\Table - */ + /** @var Table */ private $_table; - /** - * @var \Doctrine\DBAL\Platforms\AbstractPlatform - */ + /** @var AbstractPlatform */ private $_platform; - /** - * @var array - */ + /** @var array */ private $_sql = []; - /** - * @param \Doctrine\DBAL\Schema\Column $column - * @param \Doctrine\DBAL\Schema\Table $table - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform - */ public function __construct(Column $column, Table $table, AbstractPlatform $platform) { $this->_column = $column; @@ -50,7 +35,7 @@ public function __construct(Column $column, Table $table, AbstractPlatform $plat } /** - * @return \Doctrine\DBAL\Schema\Column + * @return Column */ public function getColumn() { @@ -58,7 +43,7 @@ public function getColumn() } /** - * @return \Doctrine\DBAL\Schema\Table + * @return Table */ public function getTable() { @@ -66,7 +51,7 @@ public function getTable() } /** - * @return \Doctrine\DBAL\Platforms\AbstractPlatform + * @return AbstractPlatform */ public function getPlatform() { diff --git a/lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php index 0e20c51aed8..8da2cf68f53 100644 --- a/lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php @@ -11,41 +11,27 @@ * Event Arguments used when SQL queries for creating tables are generated inside Doctrine\DBAL\Platform\AbstractPlatform. * * @link www.doctrine-project.org - * @since 2.2 - * @author Jan Sorgalla */ class SchemaCreateTableEventArgs extends SchemaEventArgs { - /** - * @var \Doctrine\DBAL\Schema\Table - */ + /** @var Table */ private $_table; - /** - * @var array - */ + /** @var array */ private $_columns; - /** - * @var array - */ + /** @var array */ private $_options; - /** - * @var \Doctrine\DBAL\Platforms\AbstractPlatform - */ + /** @var AbstractPlatform */ private $_platform; - /** - * @var array - */ + /** @var array */ private $_sql = []; /** - * @param \Doctrine\DBAL\Schema\Table $table - * @param array $columns - * @param array $options - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform + * @param array $columns + * @param array $options */ public function __construct(Table $table, array $columns, array $options, AbstractPlatform $platform) { @@ -56,7 +42,7 @@ public function __construct(Table $table, array $columns, array $options, Abstra } /** - * @return \Doctrine\DBAL\Schema\Table + * @return Table */ public function getTable() { @@ -80,7 +66,7 @@ public function getOptions() } /** - * @return \Doctrine\DBAL\Platforms\AbstractPlatform + * @return AbstractPlatform */ public function getPlatform() { diff --git a/lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php index b114ce5d0d9..cc77805ca83 100644 --- a/lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php @@ -4,42 +4,34 @@ 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. * * @link www.doctrine-project.org - * @since 2.2 - * @author Jan Sorgalla */ class SchemaDropTableEventArgs extends SchemaEventArgs { - /** - * @var string|\Doctrine\DBAL\Schema\Table - */ + /** @var string|Table */ private $_table; - /** - * @var \Doctrine\DBAL\Platforms\AbstractPlatform - */ + /** @var AbstractPlatform */ private $_platform; - /** - * @var string|null - */ + /** @var string|null */ private $_sql = null; /** - * @param string|\Doctrine\DBAL\Schema\Table $table - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform + * @param string|Table $table * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ 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.'); + 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; @@ -47,7 +39,7 @@ public function __construct($table, AbstractPlatform $platform) } /** - * @return string|\Doctrine\DBAL\Schema\Table + * @return string|Table */ public function getTable() { @@ -55,7 +47,7 @@ public function getTable() } /** - * @return \Doctrine\DBAL\Platforms\AbstractPlatform + * @return AbstractPlatform */ public function getPlatform() { diff --git a/lib/Doctrine/DBAL/Event/SchemaEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaEventArgs.php index 4d19b1c0b4f..a47bde72916 100644 --- a/lib/Doctrine/DBAL/Event/SchemaEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaEventArgs.php @@ -8,14 +8,10 @@ * Base class for schema related events. * * @link www.doctrine-project.org - * @since 2.2 - * @author Jan Sorgalla */ class SchemaEventArgs extends EventArgs { - /** - * @var bool - */ + /** @var bool */ private $_preventDefault = false; /** diff --git a/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php index 2095a6a6c27..84584fcbb6e 100644 --- a/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php @@ -3,20 +3,17 @@ namespace Doctrine\DBAL\Event; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\Index; /** * Event Arguments used when the portable index definition is generated inside Doctrine\DBAL\Schema\AbstractSchemaManager. * * @link www.doctrine-project.org - * @since 2.2 - * @author Jan Sorgalla */ class SchemaIndexDefinitionEventArgs extends SchemaEventArgs { - /** - * @var \Doctrine\DBAL\Schema\Index|null - */ + /** @var Index|null */ private $_index = null; /** @@ -26,20 +23,15 @@ class SchemaIndexDefinitionEventArgs extends SchemaEventArgs */ private $_tableIndex; - /** - * @var string - */ + /** @var string */ private $_table; - /** - * @var \Doctrine\DBAL\Connection - */ + /** @var Connection */ private $_connection; /** - * @param array $tableIndex - * @param string $table - * @param \Doctrine\DBAL\Connection $connection + * @param array $tableIndex + * @param string $table */ public function __construct(array $tableIndex, $table, Connection $connection) { @@ -51,11 +43,9 @@ public function __construct(array $tableIndex, $table, Connection $connection) /** * Allows to clear the index which means the index will be excluded from tables index list. * - * @param null|\Doctrine\DBAL\Schema\Index $index - * * @return SchemaIndexDefinitionEventArgs */ - public function setIndex(Index $index = null) + public function setIndex(?Index $index = null) { $this->_index = $index; @@ -63,7 +53,7 @@ public function setIndex(Index $index = null) } /** - * @return \Doctrine\DBAL\Schema\Index|null + * @return Index|null */ public function getIndex() { @@ -87,7 +77,7 @@ public function getTable() } /** - * @return \Doctrine\DBAL\Connection + * @return Connection */ public function getConnection() { @@ -95,7 +85,7 @@ public function getConnection() } /** - * @return \Doctrine\DBAL\Platforms\AbstractPlatform + * @return AbstractPlatform */ public function getDatabasePlatform() { diff --git a/lib/Doctrine/DBAL/Events.php b/lib/Doctrine/DBAL/Events.php index 9a8c4faa244..5398d0f84c2 100644 --- a/lib/Doctrine/DBAL/Events.php +++ b/lib/Doctrine/DBAL/Events.php @@ -6,9 +6,6 @@ * Container for all DBAL events. * * This class cannot be instantiated. - * - * @author Roman Borschel - * @since 2.0 */ final class Events { @@ -19,16 +16,16 @@ private function __construct() { } - const postConnect = 'postConnect'; + public const postConnect = 'postConnect'; - const onSchemaCreateTable = 'onSchemaCreateTable'; - const onSchemaCreateTableColumn = 'onSchemaCreateTableColumn'; - const onSchemaDropTable = 'onSchemaDropTable'; - const onSchemaAlterTable = 'onSchemaAlterTable'; - const onSchemaAlterTableAddColumn = 'onSchemaAlterTableAddColumn'; - const onSchemaAlterTableRemoveColumn = 'onSchemaAlterTableRemoveColumn'; - const onSchemaAlterTableChangeColumn = 'onSchemaAlterTableChangeColumn'; - const onSchemaAlterTableRenameColumn = 'onSchemaAlterTableRenameColumn'; - const onSchemaColumnDefinition = 'onSchemaColumnDefinition'; - const onSchemaIndexDefinition = 'onSchemaIndexDefinition'; + public const onSchemaCreateTable = 'onSchemaCreateTable'; + public const onSchemaCreateTableColumn = 'onSchemaCreateTableColumn'; + public const onSchemaDropTable = 'onSchemaDropTable'; + public const onSchemaAlterTable = 'onSchemaAlterTable'; + public const onSchemaAlterTableAddColumn = 'onSchemaAlterTableAddColumn'; + public const onSchemaAlterTableRemoveColumn = 'onSchemaAlterTableRemoveColumn'; + public const onSchemaAlterTableChangeColumn = 'onSchemaAlterTableChangeColumn'; + public const onSchemaAlterTableRenameColumn = 'onSchemaAlterTableRenameColumn'; + public const onSchemaColumnDefinition = 'onSchemaColumnDefinition'; + public const onSchemaIndexDefinition = 'onSchemaIndexDefinition'; } diff --git a/lib/Doctrine/DBAL/Exception/ConnectionException.php b/lib/Doctrine/DBAL/Exception/ConnectionException.php index 134ee24db4e..3b17d09d52a 100644 --- a/lib/Doctrine/DBAL/Exception/ConnectionException.php +++ b/lib/Doctrine/DBAL/Exception/ConnectionException.php @@ -5,9 +5,7 @@ /** * Base class for all connection related errors detected in the driver. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ class ConnectionException extends DriverException { diff --git a/lib/Doctrine/DBAL/Exception/ConstraintViolationException.php b/lib/Doctrine/DBAL/Exception/ConstraintViolationException.php index 9168edd5cd7..ed7865a998d 100644 --- a/lib/Doctrine/DBAL/Exception/ConstraintViolationException.php +++ b/lib/Doctrine/DBAL/Exception/ConstraintViolationException.php @@ -5,9 +5,7 @@ /** * Base class for all constraint violation related errors detected in the driver. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ class ConstraintViolationException extends ServerException { diff --git a/lib/Doctrine/DBAL/Exception/DatabaseObjectExistsException.php b/lib/Doctrine/DBAL/Exception/DatabaseObjectExistsException.php index 2d1be341331..e1932de88a3 100644 --- a/lib/Doctrine/DBAL/Exception/DatabaseObjectExistsException.php +++ b/lib/Doctrine/DBAL/Exception/DatabaseObjectExistsException.php @@ -9,9 +9,7 @@ * such as schemas, tables, views, sequences, triggers, constraints, indexes, * functions, stored procedures etc. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ class DatabaseObjectExistsException extends ServerException { diff --git a/lib/Doctrine/DBAL/Exception/DatabaseObjectNotFoundException.php b/lib/Doctrine/DBAL/Exception/DatabaseObjectNotFoundException.php index 07473043f00..4b0f96b5cf6 100644 --- a/lib/Doctrine/DBAL/Exception/DatabaseObjectNotFoundException.php +++ b/lib/Doctrine/DBAL/Exception/DatabaseObjectNotFoundException.php @@ -9,9 +9,7 @@ * such as schemas, tables, views, sequences, triggers, constraints, indexes, * functions, stored procedures etc. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ class DatabaseObjectNotFoundException extends ServerException { diff --git a/lib/Doctrine/DBAL/Exception/DeadlockException.php b/lib/Doctrine/DBAL/Exception/DeadlockException.php index 042537634ac..95ba4467f1c 100644 --- a/lib/Doctrine/DBAL/Exception/DeadlockException.php +++ b/lib/Doctrine/DBAL/Exception/DeadlockException.php @@ -5,9 +5,7 @@ /** * Exception for a deadlock error of a transaction detected in the driver. * - * @author Tobias Schultze * @link www.doctrine-project.org - * @since 2.6 */ class DeadlockException extends ServerException implements RetryableException { diff --git a/lib/Doctrine/DBAL/Exception/DriverException.php b/lib/Doctrine/DBAL/Exception/DriverException.php index 42328cc62fd..69fb4dafdee 100644 --- a/lib/Doctrine/DBAL/Exception/DriverException.php +++ b/lib/Doctrine/DBAL/Exception/DriverException.php @@ -3,13 +3,12 @@ namespace Doctrine\DBAL\Exception; use Doctrine\DBAL\DBALException; +use Exception; /** * Base class for all errors detected in the driver. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ class DriverException extends DBALException { @@ -21,8 +20,6 @@ class DriverException extends DBALException private $driverException; /** - * Constructor. - * * @param string $message The exception message. * @param \Doctrine\DBAL\Driver\DriverException $driverException The DBAL driver exception to chain. */ @@ -30,7 +27,7 @@ public function __construct($message, \Doctrine\DBAL\Driver\DriverException $dri { $exception = null; - if ($driverException instanceof \Exception) { + if ($driverException instanceof Exception) { $exception = $driverException; } diff --git a/lib/Doctrine/DBAL/Exception/ForeignKeyConstraintViolationException.php b/lib/Doctrine/DBAL/Exception/ForeignKeyConstraintViolationException.php index 5cab4d982b5..ba60e1c93c0 100644 --- a/lib/Doctrine/DBAL/Exception/ForeignKeyConstraintViolationException.php +++ b/lib/Doctrine/DBAL/Exception/ForeignKeyConstraintViolationException.php @@ -5,10 +5,7 @@ /** * Exception for a foreign key constraint violation detected in the driver. * - * @author Benjamin Eberlei - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ class ForeignKeyConstraintViolationException extends ConstraintViolationException { diff --git a/lib/Doctrine/DBAL/Exception/InvalidArgumentException.php b/lib/Doctrine/DBAL/Exception/InvalidArgumentException.php index be5d061b3e5..8363d172266 100644 --- a/lib/Doctrine/DBAL/Exception/InvalidArgumentException.php +++ b/lib/Doctrine/DBAL/Exception/InvalidArgumentException.php @@ -7,9 +7,7 @@ /** * Exception to be thrown when invalid arguments are passed to any DBAL API * - * @author Marco Pivetta * @link www.doctrine-project.org - * @since 2.5 */ class InvalidArgumentException extends DBALException { diff --git a/lib/Doctrine/DBAL/Exception/InvalidFieldNameException.php b/lib/Doctrine/DBAL/Exception/InvalidFieldNameException.php index 81db4dff3f4..a35f3e7dc29 100644 --- a/lib/Doctrine/DBAL/Exception/InvalidFieldNameException.php +++ b/lib/Doctrine/DBAL/Exception/InvalidFieldNameException.php @@ -5,9 +5,7 @@ /** * Exception for an invalid specified field name in a statement detected in the driver. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ class InvalidFieldNameException extends ServerException { diff --git a/lib/Doctrine/DBAL/Exception/LockWaitTimeoutException.php b/lib/Doctrine/DBAL/Exception/LockWaitTimeoutException.php index 2b805c2ce03..c26b59fc676 100644 --- a/lib/Doctrine/DBAL/Exception/LockWaitTimeoutException.php +++ b/lib/Doctrine/DBAL/Exception/LockWaitTimeoutException.php @@ -5,9 +5,7 @@ /** * Exception for a lock wait timeout error of a transaction detected in the driver. * - * @author Tobias Schultze * @link www.doctrine-project.org - * @since 2.6 */ class LockWaitTimeoutException extends ServerException implements RetryableException { diff --git a/lib/Doctrine/DBAL/Exception/NonUniqueFieldNameException.php b/lib/Doctrine/DBAL/Exception/NonUniqueFieldNameException.php index 098bfeaf9e9..cde6f2bf860 100644 --- a/lib/Doctrine/DBAL/Exception/NonUniqueFieldNameException.php +++ b/lib/Doctrine/DBAL/Exception/NonUniqueFieldNameException.php @@ -5,9 +5,7 @@ /** * Exception for a non-unique/ambiguous specified field name in a statement detected in the driver. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ class NonUniqueFieldNameException extends ServerException { diff --git a/lib/Doctrine/DBAL/Exception/NotNullConstraintViolationException.php b/lib/Doctrine/DBAL/Exception/NotNullConstraintViolationException.php index 7a7909d4f45..235239a6163 100644 --- a/lib/Doctrine/DBAL/Exception/NotNullConstraintViolationException.php +++ b/lib/Doctrine/DBAL/Exception/NotNullConstraintViolationException.php @@ -5,10 +5,7 @@ /** * Exception for a NOT NULL constraint violation detected in the driver. * - * @author Benjamin Eberlei - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ class NotNullConstraintViolationException extends ConstraintViolationException { diff --git a/lib/Doctrine/DBAL/Exception/ReadOnlyException.php b/lib/Doctrine/DBAL/Exception/ReadOnlyException.php index 8920a102b06..cd8f2c757f7 100644 --- a/lib/Doctrine/DBAL/Exception/ReadOnlyException.php +++ b/lib/Doctrine/DBAL/Exception/ReadOnlyException.php @@ -5,9 +5,7 @@ /** * Exception for a write operation attempt on a read-only database element detected in the driver. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ class ReadOnlyException extends ServerException { diff --git a/lib/Doctrine/DBAL/Exception/RetryableException.php b/lib/Doctrine/DBAL/Exception/RetryableException.php index 54335734118..b84863fcb61 100644 --- a/lib/Doctrine/DBAL/Exception/RetryableException.php +++ b/lib/Doctrine/DBAL/Exception/RetryableException.php @@ -5,9 +5,7 @@ /** * Marker interface for all exceptions where retrying the transaction makes sense. * - * @author Tobias Schultze * @link www.doctrine-project.org - * @since 2.6 */ interface RetryableException { diff --git a/lib/Doctrine/DBAL/Exception/ServerException.php b/lib/Doctrine/DBAL/Exception/ServerException.php index 310d8c7bc5a..30c8288fc7e 100644 --- a/lib/Doctrine/DBAL/Exception/ServerException.php +++ b/lib/Doctrine/DBAL/Exception/ServerException.php @@ -5,9 +5,7 @@ /** * Base class for all server related errors detected in the driver. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ class ServerException extends DriverException { diff --git a/lib/Doctrine/DBAL/Exception/SyntaxErrorException.php b/lib/Doctrine/DBAL/Exception/SyntaxErrorException.php index 9e41c891f2b..2dedd689b7a 100644 --- a/lib/Doctrine/DBAL/Exception/SyntaxErrorException.php +++ b/lib/Doctrine/DBAL/Exception/SyntaxErrorException.php @@ -5,9 +5,7 @@ /** * Exception for a syntax error in a statement detected in the driver. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ class SyntaxErrorException extends ServerException { diff --git a/lib/Doctrine/DBAL/Exception/TableExistsException.php b/lib/Doctrine/DBAL/Exception/TableExistsException.php index 1bfef855a5b..93405890d4f 100644 --- a/lib/Doctrine/DBAL/Exception/TableExistsException.php +++ b/lib/Doctrine/DBAL/Exception/TableExistsException.php @@ -5,9 +5,7 @@ /** * Exception for an already existing table referenced in a statement detected in the driver. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ class TableExistsException extends DatabaseObjectExistsException { diff --git a/lib/Doctrine/DBAL/Exception/TableNotFoundException.php b/lib/Doctrine/DBAL/Exception/TableNotFoundException.php index ea6a6d14a2e..32349aa3b20 100644 --- a/lib/Doctrine/DBAL/Exception/TableNotFoundException.php +++ b/lib/Doctrine/DBAL/Exception/TableNotFoundException.php @@ -5,9 +5,7 @@ /** * Exception for an unknown table referenced in a statement detected in the driver. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ class TableNotFoundException extends DatabaseObjectNotFoundException { diff --git a/lib/Doctrine/DBAL/Exception/UniqueConstraintViolationException.php b/lib/Doctrine/DBAL/Exception/UniqueConstraintViolationException.php index 9f235cad377..a202245094c 100644 --- a/lib/Doctrine/DBAL/Exception/UniqueConstraintViolationException.php +++ b/lib/Doctrine/DBAL/Exception/UniqueConstraintViolationException.php @@ -5,10 +5,7 @@ /** * Exception for a unique constraint violation detected in the driver. * - * @author Benjamin Eberlei - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ class UniqueConstraintViolationException extends ConstraintViolationException { diff --git a/lib/Doctrine/DBAL/FetchMode.php b/lib/Doctrine/DBAL/FetchMode.php index a3e7f3ba601..b3fe42f4ceb 100644 --- a/lib/Doctrine/DBAL/FetchMode.php +++ b/lib/Doctrine/DBAL/FetchMode.php @@ -2,6 +2,8 @@ namespace Doctrine\DBAL; +use PDO; + /** * Contains statement fetch modes. */ @@ -15,7 +17,7 @@ final class FetchMode * * @see \PDO::FETCH_ASSOC */ - public const ASSOCIATIVE = \PDO::FETCH_ASSOC; + public const ASSOCIATIVE = PDO::FETCH_ASSOC; /** * Specifies that the fetch method shall return each row as an array indexed @@ -24,7 +26,7 @@ final class FetchMode * * @see \PDO::FETCH_NUM */ - public const NUMERIC = \PDO::FETCH_NUM; + public const NUMERIC = PDO::FETCH_NUM; /** * Specifies that the fetch method shall return each row as an array indexed @@ -33,7 +35,7 @@ final class FetchMode * * @see \PDO::FETCH_BOTH */ - public const MIXED = \PDO::FETCH_BOTH; + public const MIXED = PDO::FETCH_BOTH; /** * Specifies that the fetch method shall return each row as an object with @@ -42,7 +44,7 @@ final class FetchMode * * @see \PDO::FETCH_OBJ */ - public const STANDARD_OBJECT = \PDO::FETCH_OBJ; + public const STANDARD_OBJECT = PDO::FETCH_OBJ; /** * Specifies that the fetch method shall return only a single requested @@ -50,7 +52,7 @@ final class FetchMode * * @see \PDO::FETCH_COLUMN */ - public const COLUMN = \PDO::FETCH_COLUMN; + public const COLUMN = PDO::FETCH_COLUMN; /** * Specifies that the fetch method shall return a new instance of the @@ -58,7 +60,7 @@ final class FetchMode * * @see \PDO::FETCH_CLASS */ - public const CUSTOM_OBJECT = \PDO::FETCH_CLASS; + public const CUSTOM_OBJECT = PDO::FETCH_CLASS; /** * This class cannot be instantiated. diff --git a/lib/Doctrine/DBAL/Id/TableGenerator.php b/lib/Doctrine/DBAL/Id/TableGenerator.php index 4c21e5a1dbb..f4fc8a67040 100644 --- a/lib/Doctrine/DBAL/Id/TableGenerator.php +++ b/lib/Doctrine/DBAL/Id/TableGenerator.php @@ -2,10 +2,12 @@ namespace Doctrine\DBAL\Id; -use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\LockMode; +use Throwable; use const CASE_LOWER; use function array_change_key_case; @@ -45,39 +47,30 @@ * * If no row is present for a given sequence a new one will be created with the * default values 'value' = 1 and 'increment_by' = 1 - * - * @author Benjamin Eberlei */ class TableGenerator { - /** - * @var \Doctrine\DBAL\Connection - */ + /** @var Connection */ private $conn; - /** - * @var string - */ + /** @var string */ private $generatorTableName; - /** - * @var array - */ + /** @var array */ private $sequences = []; /** - * @param \Doctrine\DBAL\Connection $conn - * @param string $generatorTableName + * @param string $generatorTableName * - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ public function __construct(Connection $conn, $generatorTableName = 'sequences') { $params = $conn->getParams(); - if ($params['driver'] == 'pdo_sqlite') { - throw new \Doctrine\DBAL\DBALException("Cannot use TableGenerator with SQLite."); + if ($params['driver'] === 'pdo_sqlite') { + throw new DBALException('Cannot use TableGenerator with SQLite.'); } - $this->conn = DriverManager::getConnection($params, $conn->getConfiguration(), $conn->getEventManager()); + $this->conn = DriverManager::getConnection($params, $conn->getConfiguration(), $conn->getEventManager()); $this->generatorTableName = $generatorTableName; } @@ -88,7 +81,7 @@ public function __construct(Connection $conn, $generatorTableName = 'sequences') * * @return int * - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ public function nextValue($sequenceName) { @@ -96,7 +89,7 @@ public function nextValue($sequenceName) $value = $this->sequences[$sequenceName]['value']; $this->sequences[$sequenceName]['value']++; if ($this->sequences[$sequenceName]['value'] >= $this->sequences[$sequenceName]['max']) { - unset ($this->sequences[$sequenceName]); + unset($this->sequences[$sequenceName]); } return $value; @@ -121,17 +114,17 @@ public function nextValue($sequenceName) if ($row['sequence_increment_by'] > 1) { $this->sequences[$sequenceName] = [ 'value' => $value, - 'max' => $row['sequence_value'] + $row['sequence_increment_by'] + 'max' => $row['sequence_value'] + $row['sequence_increment_by'], ]; } - $sql = "UPDATE " . $this->generatorTableName . " ". - "SET sequence_value = sequence_value + sequence_increment_by " . - "WHERE sequence_name = ? AND sequence_value = ?"; + $sql = 'UPDATE ' . $this->generatorTableName . ' ' . + 'SET sequence_value = sequence_value + sequence_increment_by ' . + 'WHERE sequence_name = ? AND sequence_value = ?'; $rows = $this->conn->executeUpdate($sql, [$sequenceName, $row['sequence_value']]); - if ($rows != 1) { - throw new \Doctrine\DBAL\DBALException("Race-condition detected while updating sequence. Aborting generation"); + if ($rows !== 1) { + throw new DBALException('Race-condition detected while updating sequence. Aborting generation'); } } else { $this->conn->insert( @@ -142,10 +135,9 @@ public function nextValue($sequenceName) } $this->conn->commit(); - - } catch (\Exception $e) { + } catch (Throwable $e) { $this->conn->rollBack(); - throw new \Doctrine\DBAL\DBALException("Error occurred while generating ID with TableGenerator, aborted generation: " . $e->getMessage(), 0, $e); + throw new DBALException('Error occurred while generating ID with TableGenerator, aborted generation: ' . $e->getMessage(), 0, $e); } return $value; diff --git a/lib/Doctrine/DBAL/Id/TableGeneratorSchemaVisitor.php b/lib/Doctrine/DBAL/Id/TableGeneratorSchemaVisitor.php index b92d421e6d7..3ec22f37c5c 100644 --- a/lib/Doctrine/DBAL/Id/TableGeneratorSchemaVisitor.php +++ b/lib/Doctrine/DBAL/Id/TableGeneratorSchemaVisitor.php @@ -2,18 +2,17 @@ namespace Doctrine\DBAL\Id; -use Doctrine\DBAL\Schema\Table; -use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ForeignKeyConstraint; -use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Index; +use Doctrine\DBAL\Schema\Schema; +use Doctrine\DBAL\Schema\Sequence; +use Doctrine\DBAL\Schema\Table; +use Doctrine\DBAL\Schema\Visitor\Visitor; -class TableGeneratorSchemaVisitor implements \Doctrine\DBAL\Schema\Visitor\Visitor +class TableGeneratorSchemaVisitor implements Visitor { - /** - * @var string - */ + /** @var string */ private $generatorTableName; /** diff --git a/lib/Doctrine/DBAL/LockMode.php b/lib/Doctrine/DBAL/LockMode.php index 5b0c99c507e..6016bb0f36c 100644 --- a/lib/Doctrine/DBAL/LockMode.php +++ b/lib/Doctrine/DBAL/LockMode.php @@ -6,16 +6,13 @@ * Contains all DBAL LockModes. * * @link www.doctrine-project.org - * @since 1.0 - * @author Benjamin Eberlei - * @author Roman Borschel */ class LockMode { - const NONE = 0; - const OPTIMISTIC = 1; - const PESSIMISTIC_READ = 2; - const PESSIMISTIC_WRITE = 4; + public const NONE = 0; + public const OPTIMISTIC = 1; + public const PESSIMISTIC_READ = 2; + public const PESSIMISTIC_WRITE = 4; /** * Private constructor. This class cannot be instantiated. diff --git a/lib/Doctrine/DBAL/Logging/DebugStack.php b/lib/Doctrine/DBAL/Logging/DebugStack.php index a283d7505e6..6863c8cef59 100644 --- a/lib/Doctrine/DBAL/Logging/DebugStack.php +++ b/lib/Doctrine/DBAL/Logging/DebugStack.php @@ -8,11 +8,6 @@ * Includes executed SQLs in a Debug Stack. * * @link www.doctrine-project.org - * @since 2.0 - * @author Benjamin Eberlei - * @author Guilherme Blanco - * @author Jonathan Wage - * @author Roman Borschel */ class DebugStack implements SQLLogger { @@ -30,25 +25,23 @@ class DebugStack implements SQLLogger */ public $enabled = true; - /** - * @var float|null - */ + /** @var float|null */ public $start = null; - /** - * @var int - */ + /** @var int */ public $currentQuery = 0; /** * {@inheritdoc} */ - public function startQuery($sql, array $params = null, array $types = null) + public function startQuery($sql, ?array $params = null, ?array $types = null) { - if ($this->enabled) { - $this->start = microtime(true); - $this->queries[++$this->currentQuery] = ['sql' => $sql, 'params' => $params, 'types' => $types, 'executionMS' => 0]; + if (! $this->enabled) { + return; } + + $this->start = microtime(true); + $this->queries[++$this->currentQuery] = ['sql' => $sql, 'params' => $params, 'types' => $types, 'executionMS' => 0]; } /** @@ -56,8 +49,10 @@ public function startQuery($sql, array $params = null, array $types = null) */ public function stopQuery() { - if ($this->enabled) { - $this->queries[$this->currentQuery]['executionMS'] = microtime(true) - $this->start; + if (! $this->enabled) { + return; } + + $this->queries[$this->currentQuery]['executionMS'] = microtime(true) - $this->start; } } diff --git a/lib/Doctrine/DBAL/Logging/EchoSQLLogger.php b/lib/Doctrine/DBAL/Logging/EchoSQLLogger.php index c0f76fc1df2..5f422bd0a41 100644 --- a/lib/Doctrine/DBAL/Logging/EchoSQLLogger.php +++ b/lib/Doctrine/DBAL/Logging/EchoSQLLogger.php @@ -9,18 +9,13 @@ * A SQL logger that logs to the standard output using echo/var_dump. * * @link www.doctrine-project.org - * @since 2.0 - * @author Benjamin Eberlei - * @author Guilherme Blanco - * @author Jonathan Wage - * @author Roman Borschel */ class EchoSQLLogger implements SQLLogger { /** * {@inheritdoc} */ - public function startQuery($sql, array $params = null, array $types = null) + public function startQuery($sql, ?array $params = null, ?array $types = null) { echo $sql . PHP_EOL; @@ -28,9 +23,11 @@ public function startQuery($sql, array $params = null, array $types = null) var_dump($params); } - if ($types) { - var_dump($types); + if (! $types) { + return; } + + var_dump($types); } /** diff --git a/lib/Doctrine/DBAL/Logging/LoggerChain.php b/lib/Doctrine/DBAL/Logging/LoggerChain.php index fa0fc8a1bda..fc944815527 100644 --- a/lib/Doctrine/DBAL/Logging/LoggerChain.php +++ b/lib/Doctrine/DBAL/Logging/LoggerChain.php @@ -6,21 +6,15 @@ * Chains multiple SQLLogger. * * @link www.doctrine-project.org - * @since 2.2 - * @author Christophe Coevoet */ class LoggerChain implements SQLLogger { - /** - * @var \Doctrine\DBAL\Logging\SQLLogger[] - */ + /** @var SQLLogger[] */ private $loggers = []; /** * Adds a logger in the chain. * - * @param \Doctrine\DBAL\Logging\SQLLogger $logger - * * @return void */ public function addLogger(SQLLogger $logger) @@ -31,7 +25,7 @@ public function addLogger(SQLLogger $logger) /** * {@inheritdoc} */ - public function startQuery($sql, array $params = null, array $types = null) + public function startQuery($sql, ?array $params = null, ?array $types = null) { foreach ($this->loggers as $logger) { $logger->startQuery($sql, $params, $types); diff --git a/lib/Doctrine/DBAL/Logging/SQLLogger.php b/lib/Doctrine/DBAL/Logging/SQLLogger.php index b7774327d7f..1fc197fccf3 100644 --- a/lib/Doctrine/DBAL/Logging/SQLLogger.php +++ b/lib/Doctrine/DBAL/Logging/SQLLogger.php @@ -6,11 +6,6 @@ * Interface for SQL loggers. * * @link www.doctrine-project.org - * @since 2.0 - * @author Benjamin Eberlei - * @author Guilherme Blanco - * @author Jonathan Wage - * @author Roman Borschel */ interface SQLLogger { @@ -23,7 +18,7 @@ interface SQLLogger * * @return void */ - public function startQuery($sql, array $params = null, array $types = null); + public function startQuery($sql, ?array $params = null, ?array $types = null); /** * Marks the last started query as stopped. This can be used for timing of queries. diff --git a/lib/Doctrine/DBAL/ParameterType.php b/lib/Doctrine/DBAL/ParameterType.php index be5413e61bb..422fee895ee 100644 --- a/lib/Doctrine/DBAL/ParameterType.php +++ b/lib/Doctrine/DBAL/ParameterType.php @@ -2,6 +2,8 @@ namespace Doctrine\DBAL; +use PDO; + /** * Contains statement parameter types. */ @@ -12,35 +14,35 @@ final class ParameterType * * @see \PDO::PARAM_NULL */ - public const NULL = \PDO::PARAM_NULL; + public const NULL = PDO::PARAM_NULL; /** * Represents the SQL INTEGER data type. * * @see \PDO::PARAM_INT */ - public const INTEGER = \PDO::PARAM_INT; + public const INTEGER = PDO::PARAM_INT; /** * Represents the SQL CHAR, VARCHAR, or other string data type. * * @see \PDO::PARAM_STR */ - public const STRING = \PDO::PARAM_STR; + public const STRING = PDO::PARAM_STR; /** * Represents the SQL large object data type. * * @see \PDO::PARAM_LOB */ - public const LARGE_OBJECT = \PDO::PARAM_LOB; + public const LARGE_OBJECT = PDO::PARAM_LOB; /** * Represents a boolean data type. * * @see \PDO::PARAM_BOOL */ - public const BOOLEAN = \PDO::PARAM_BOOL; + public const BOOLEAN = PDO::PARAM_BOOL; /** * Represents a binary string data type. diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index ecec475056f..5f929019e51 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -13,6 +13,7 @@ use Doctrine\DBAL\Event\SchemaCreateTableEventArgs; use Doctrine\DBAL\Event\SchemaDropTableEventArgs; use Doctrine\DBAL\Events; +use Doctrine\DBAL\Platforms\Keywords\KeywordList; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ColumnDiff; use Doctrine\DBAL\Schema\Constraint; @@ -25,6 +26,7 @@ use Doctrine\DBAL\TransactionIsolationLevel; use Doctrine\DBAL\Types; use Doctrine\DBAL\Types\Type; +use InvalidArgumentException; use const E_USER_DEPRECATED; use function addcslashes; use function array_map; @@ -36,7 +38,6 @@ use function func_get_arg; use function func_get_args; use function func_num_args; -use function get_class; use function implode; use function in_array; use function is_array; @@ -60,25 +61,14 @@ * They are a passive source of information. * * @link www.doctrine-project.org - * @since 2.0 - * @author Guilherme Blanco - * @author Jonathan Wage - * @author Roman Borschel - * @author Lukas Smith (PEAR MDB2 library) - * @author Benjamin Eberlei + * * @todo Remove any unnecessary methods. */ abstract class AbstractPlatform { - /** - * @var int - */ - const CREATE_INDEXES = 1; + public const CREATE_INDEXES = 1; - /** - * @var int - */ - const CREATE_FOREIGNKEYS = 2; + public const CREATE_FOREIGNKEYS = 2; /** * @deprecated Use DateIntervalUnit::INTERVAL_UNIT_SECOND. @@ -121,36 +111,26 @@ abstract class AbstractPlatform public const DATE_INTERVAL_UNIT_YEAR = DateIntervalUnit::YEAR; /** - * @var int - * * @deprecated Use TrimMode::UNSPECIFIED. */ public const TRIM_UNSPECIFIED = TrimMode::UNSPECIFIED; /** - * @var int - * * @deprecated Use TrimMode::LEADING. */ public const TRIM_LEADING = TrimMode::LEADING; /** - * @var int - * * @deprecated Use TrimMode::TRAILING. */ public const TRIM_TRAILING = TrimMode::TRAILING; /** - * @var int - * * @deprecated Use TrimMode::BOTH. */ public const TRIM_BOTH = TrimMode::BOTH; - /** - * @var array|null - */ + /** @var array|null */ protected $doctrineTypeMapping = null; /** @@ -161,29 +141,22 @@ abstract class AbstractPlatform */ protected $doctrineTypeComments = null; - /** - * @var \Doctrine\Common\EventManager - */ + /** @var EventManager */ protected $_eventManager; /** * Holds the KeywordList instance for the current platform. * - * @var \Doctrine\DBAL\Platforms\Keywords\KeywordList + * @var KeywordList */ protected $_keywords; - /** - * Constructor. - */ public function __construct() { } /** * Sets the EventManager used by the Platform. - * - * @param \Doctrine\Common\EventManager $eventManager */ public function setEventManager(EventManager $eventManager) { @@ -193,7 +166,7 @@ public function setEventManager(EventManager $eventManager) /** * Gets the EventManager used by the Platform. * - * @return \Doctrine\Common\EventManager + * @return EventManager */ public function getEventManager() { @@ -278,7 +251,7 @@ private function initializeAllDoctrineTypeMappings() */ public function getVarcharTypeDeclarationSQL(array $field) { - if ( !isset($field['length'])) { + if (! isset($field['length'])) { $field['length'] = $this->getVarcharDefaultLength(); } @@ -304,7 +277,7 @@ public function getVarcharTypeDeclarationSQL(array $field) */ public function getBinaryTypeDeclarationSQL(array $field) { - if ( ! isset($field['length'])) { + if (! isset($field['length'])) { $field['length'] = $this->getBinaryDefaultLength(); } @@ -366,7 +339,7 @@ public function getJsonTypeDeclarationSQL(array $field) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) { @@ -381,7 +354,7 @@ protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ protected function getBinaryTypeDeclarationSQLSnippet($length, $fixed) { @@ -419,7 +392,7 @@ abstract public function getName(); * @param string $dbType * @param string $doctrineType * - * @throws \Doctrine\DBAL\DBALException If the type is not found. + * @throws DBALException If the type is not found. */ public function registerDoctrineTypeMapping($dbType, $doctrineType) { @@ -427,18 +400,20 @@ public function registerDoctrineTypeMapping($dbType, $doctrineType) $this->initializeAllDoctrineTypeMappings(); } - if (!Types\Type::hasType($doctrineType)) { + if (! Types\Type::hasType($doctrineType)) { throw DBALException::typeNotFound($doctrineType); } - $dbType = strtolower($dbType); + $dbType = strtolower($dbType); $this->doctrineTypeMapping[$dbType] = $doctrineType; $doctrineType = Type::getType($doctrineType); - if ($doctrineType->requiresSQLCommentHint($this)) { - $this->markDoctrineTypeCommented($doctrineType); + if (! $doctrineType->requiresSQLCommentHint($this)) { + return; } + + $this->markDoctrineTypeCommented($doctrineType); } /** @@ -448,7 +423,7 @@ public function registerDoctrineTypeMapping($dbType, $doctrineType) * * @return string * - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ public function getDoctrineTypeMapping($dbType) { @@ -458,8 +433,8 @@ public function getDoctrineTypeMapping($dbType) $dbType = strtolower($dbType); - if (!isset($this->doctrineTypeMapping[$dbType])) { - throw new \Doctrine\DBAL\DBALException("Unknown database type ".$dbType." requested, " . get_class($this) . " may not support it."); + if (! isset($this->doctrineTypeMapping[$dbType])) { + throw new DBALException('Unknown database type ' . $dbType . ' requested, ' . static::class . ' may not support it.'); } return $this->doctrineTypeMapping[$dbType]; @@ -495,17 +470,17 @@ protected function initializeCommentedDoctrineTypes() foreach (Type::getTypesMap() as $typeName => $className) { $type = Type::getType($typeName); - if ($type->requiresSQLCommentHint($this)) { - $this->doctrineTypeComments[] = $typeName; + if (! $type->requiresSQLCommentHint($this)) { + continue; } + + $this->doctrineTypeComments[] = $typeName; } } /** * Is it necessary for the platform to add a parsable type comment to allow reverse engineering the given type? * - * @param \Doctrine\DBAL\Types\Type $doctrineType - * * @return bool */ public function isCommentedDoctrineType(Type $doctrineType) @@ -520,7 +495,7 @@ public function isCommentedDoctrineType(Type $doctrineType) /** * Marks this type as to be commented in ALTER TABLE and CREATE TABLE statements. * - * @param string|\Doctrine\DBAL\Types\Type $doctrineType + * @param string|Type $doctrineType * * @return void */ @@ -536,8 +511,6 @@ public function markDoctrineTypeCommented($doctrineType) /** * Gets the comment to append to a column comment that helps parsing this type in reverse engineering. * - * @param \Doctrine\DBAL\Types\Type $doctrineType - * * @return string */ public function getDoctrineTypeComment(Type $doctrineType) @@ -548,8 +521,6 @@ public function getDoctrineTypeComment(Type $doctrineType) /** * Gets the comment of a passed column modified by potential doctrine type comment hints. * - * @param \Doctrine\DBAL\Schema\Column $column - * * @return string */ protected function getColumnComment(Column $column) @@ -580,7 +551,7 @@ public function getIdentifierQuoteCharacter() */ public function getSqlCommentStartString() { - return "--"; + return '--'; } /** @@ -656,7 +627,7 @@ public function getWildcards() * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getRegexpExpression() { @@ -666,11 +637,11 @@ public function getRegexpExpression() /** * Returns the global unique identifier expression. * - * @return string + * @deprecated Use application-generated UUIDs instead * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @return string * - * @deprecated Use application-generated UUIDs instead + * @throws DBALException If not supported on this platform. */ public function getGuidExpression() { @@ -694,7 +665,7 @@ public function getAvgExpression($column) * * If a '*' is used instead of a column the number of selected rows is returned. * - * @param string|integer $column The column to use. + * @param string|int $column The column to use. * * @return string Generated SQL including a COUNT aggregate function. */ @@ -902,7 +873,7 @@ public function getLowerExpression($str) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getLocateExpression($str, $substr, $startPos = false) { @@ -1014,7 +985,7 @@ public function getIsNotNullExpression($expression) */ public function getBetweenExpression($expression, $value1, $value2) { - return $expression . ' BETWEEN ' .$value1 . ' AND ' . $value2; + return $expression . ' BETWEEN ' . $value1 . ' AND ' . $value2; } /** @@ -1073,7 +1044,7 @@ public function getCosExpression($value) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getDateDiffExpression($date1, $date2) { @@ -1088,7 +1059,7 @@ public function getDateDiffExpression($date1, $date2) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getDateAddSecondsExpression($date, $seconds) { @@ -1103,7 +1074,7 @@ public function getDateAddSecondsExpression($date, $seconds) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getDateSubSecondsExpression($date, $seconds) { @@ -1118,7 +1089,7 @@ public function getDateSubSecondsExpression($date, $seconds) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getDateAddMinutesExpression($date, $minutes) { @@ -1133,7 +1104,7 @@ public function getDateAddMinutesExpression($date, $minutes) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getDateSubMinutesExpression($date, $minutes) { @@ -1148,7 +1119,7 @@ public function getDateSubMinutesExpression($date, $minutes) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getDateAddHourExpression($date, $hours) { @@ -1163,7 +1134,7 @@ public function getDateAddHourExpression($date, $hours) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getDateSubHourExpression($date, $hours) { @@ -1178,7 +1149,7 @@ public function getDateSubHourExpression($date, $hours) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getDateAddDaysExpression($date, $days) { @@ -1193,7 +1164,7 @@ public function getDateAddDaysExpression($date, $days) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getDateSubDaysExpression($date, $days) { @@ -1208,7 +1179,7 @@ public function getDateSubDaysExpression($date, $days) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getDateAddWeeksExpression($date, $weeks) { @@ -1223,7 +1194,7 @@ public function getDateAddWeeksExpression($date, $weeks) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getDateSubWeeksExpression($date, $weeks) { @@ -1238,7 +1209,7 @@ public function getDateSubWeeksExpression($date, $weeks) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getDateAddMonthExpression($date, $months) { @@ -1253,7 +1224,7 @@ public function getDateAddMonthExpression($date, $months) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getDateSubMonthExpression($date, $months) { @@ -1268,7 +1239,7 @@ public function getDateSubMonthExpression($date, $months) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getDateAddQuartersExpression($date, $quarters) { @@ -1283,7 +1254,7 @@ public function getDateAddQuartersExpression($date, $quarters) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getDateSubQuartersExpression($date, $quarters) { @@ -1298,7 +1269,7 @@ public function getDateSubQuartersExpression($date, $quarters) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getDateAddYearsExpression($date, $years) { @@ -1313,7 +1284,7 @@ public function getDateAddYearsExpression($date, $years) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getDateSubYearsExpression($date, $years) { @@ -1331,7 +1302,7 @@ public function getDateSubYearsExpression($date, $years) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ protected function getDateArithmeticIntervalExpression($date, $operator, $interval, $unit) { @@ -1428,11 +1399,11 @@ public function getDropDatabaseSQL($database) /** * Returns the SQL snippet to drop an existing table. * - * @param \Doctrine\DBAL\Schema\Table|string $table + * @param Table|string $table * * @return string * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ public function getDropTableSQL($table) { @@ -1440,11 +1411,11 @@ public function getDropTableSQL($table) if ($table instanceof Table) { $table = $table->getQuotedName($this); - } elseif (!is_string($table)) { - throw new \InvalidArgumentException('getDropTableSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.'); + } elseif (! is_string($table)) { + throw new InvalidArgumentException('getDropTableSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.'); } - if (null !== $this->_eventManager && $this->_eventManager->hasListeners(Events::onSchemaDropTable)) { + if ($this->_eventManager !== null && $this->_eventManager->hasListeners(Events::onSchemaDropTable)) { $eventArgs = new SchemaDropTableEventArgs($tableArg, $this); $this->_eventManager->dispatchEvent(Events::onSchemaDropTable, $eventArgs); @@ -1459,7 +1430,7 @@ public function getDropTableSQL($table) /** * Returns the SQL to safely drop a temporary table WITHOUT implicitly committing an open transaction. * - * @param \Doctrine\DBAL\Schema\Table|string $table + * @param Table|string $table * * @return string */ @@ -1471,19 +1442,19 @@ public function getDropTemporaryTableSQL($table) /** * Returns the SQL to drop an index from a table. * - * @param \Doctrine\DBAL\Schema\Index|string $index - * @param \Doctrine\DBAL\Schema\Table|string $table + * @param Index|string $index + * @param Table|string $table * * @return string * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ public function getDropIndexSQL($index, $table = null) { if ($index instanceof Index) { $index = $index->getQuotedName($this); - } elseif (!is_string($index)) { - throw new \InvalidArgumentException('AbstractPlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.'); + } elseif (! is_string($index)) { + throw new InvalidArgumentException('AbstractPlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.'); } return 'DROP INDEX ' . $index; @@ -1492,8 +1463,8 @@ public function getDropIndexSQL($index, $table = null) /** * Returns the SQL to drop a constraint. * - * @param \Doctrine\DBAL\Schema\Constraint|string $constraint - * @param \Doctrine\DBAL\Schema\Table|string $table + * @param Constraint|string $constraint + * @param Table|string $table * * @return string */ @@ -1508,7 +1479,7 @@ public function getDropConstraintSQL($constraint, $table) } $constraint = $constraint->getQuotedName($this); - $table = $table->getQuotedName($this); + $table = $table->getQuotedName($this); return 'ALTER TABLE ' . $table . ' DROP CONSTRAINT ' . $constraint; } @@ -1516,8 +1487,8 @@ public function getDropConstraintSQL($constraint, $table) /** * Returns the SQL to drop a foreign key. * - * @param \Doctrine\DBAL\Schema\ForeignKeyConstraint|string $foreignKey - * @param \Doctrine\DBAL\Schema\Table|string $table + * @param ForeignKeyConstraint|string $foreignKey + * @param Table|string $table * * @return string */ @@ -1532,7 +1503,7 @@ public function getDropForeignKeySQL($foreignKey, $table) } $foreignKey = $foreignKey->getQuotedName($this); - $table = $table->getQuotedName($this); + $table = $table->getQuotedName($this); return 'ALTER TABLE ' . $table . ' DROP FOREIGN KEY ' . $foreignKey; } @@ -1541,33 +1512,32 @@ public function getDropForeignKeySQL($foreignKey, $table) * Returns the SQL statement(s) to create a table with the specified name, columns and constraints * on this platform. * - * @param \Doctrine\DBAL\Schema\Table $table - * @param int $createFlags + * @param int $createFlags * * @return array The sequence of SQL statements. * - * @throws \Doctrine\DBAL\DBALException - * @throws \InvalidArgumentException + * @throws DBALException + * @throws InvalidArgumentException */ public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDEXES) { - if ( ! is_int($createFlags)) { - throw new \InvalidArgumentException("Second argument of AbstractPlatform::getCreateTableSQL() has to be integer."); + if (! is_int($createFlags)) { + throw new InvalidArgumentException('Second argument of AbstractPlatform::getCreateTableSQL() has to be integer.'); } if (count($table->getColumns()) === 0) { throw DBALException::noColumnsSpecifiedForTable($table->getName()); } - $tableName = $table->getQuotedName($this); - $options = $table->getOptions(); + $tableName = $table->getQuotedName($this); + $options = $table->getOptions(); $options['uniqueConstraints'] = []; - $options['indexes'] = []; - $options['primary'] = []; + $options['indexes'] = []; + $options['primary'] = []; if (($createFlags&self::CREATE_INDEXES) > 0) { foreach ($table->getIndexes() as $index) { - /* @var $index Index */ + /** @var $index Index */ if ($index->isPrimary()) { $options['primary'] = $index->getQuotedColumns($this); $options['primary_index'] = $index; @@ -1578,12 +1548,12 @@ public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDE } $columnSql = []; - $columns = []; + $columns = []; foreach ($table->getColumns() as $column) { - /* @var \Doctrine\DBAL\Schema\Column $column */ + /** @var Column $column */ - if (null !== $this->_eventManager && $this->_eventManager->hasListeners(Events::onSchemaCreateTableColumn)) { + if ($this->_eventManager !== null && $this->_eventManager->hasListeners(Events::onSchemaCreateTableColumn)) { $eventArgs = new SchemaCreateTableColumnEventArgs($column, $table, $this); $this->_eventManager->dispatchEvent(Events::onSchemaCreateTableColumn, $eventArgs); @@ -1594,9 +1564,9 @@ public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDE } } - $columnData = $column->toArray(); - $columnData['name'] = $column->getQuotedName($this); - $columnData['version'] = $column->hasPlatformOption("version") ? $column->getPlatformOption('version') : false; + $columnData = $column->toArray(); + $columnData['name'] = $column->getQuotedName($this); + $columnData['version'] = $column->hasPlatformOption('version') ? $column->getPlatformOption('version') : false; $columnData['comment'] = $this->getColumnComment($column); if ($columnData['type'] instanceof Types\StringType && $columnData['length'] === null) { @@ -1617,7 +1587,7 @@ public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDE } } - if (null !== $this->_eventManager && $this->_eventManager->hasListeners(Events::onSchemaCreateTable)) { + if ($this->_eventManager !== null && $this->_eventManager->hasListeners(Events::onSchemaCreateTable)) { $eventArgs = new SchemaCreateTableEventArgs($table, $columns, $options, $this); $this->_eventManager->dispatchEvent(Events::onSchemaCreateTable, $eventArgs); @@ -1631,9 +1601,11 @@ public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDE foreach ($table->getColumns() as $column) { $comment = $this->getColumnComment($column); - if (null !== $comment && '' !== $comment) { - $sql[] = $this->getCommentOnColumnSQL($tableName, $column->getQuotedName($this), $comment); + if ($comment === null || $comment === '') { + continue; } + + $sql[] = $this->getCommentOnColumnSQL($tableName, $column->getQuotedName($this), $comment); } } @@ -1649,12 +1621,12 @@ public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDE */ public function getCommentOnColumnSQL($tableName, $columnName, $comment) { - $tableName = new Identifier($tableName); + $tableName = new Identifier($tableName); $columnName = new Identifier($columnName); - $comment = $this->quoteStringLiteral($comment); + $comment = $this->quoteStringLiteral($comment); - return "COMMENT ON COLUMN " . $tableName->getQuotedName($this) . "." . $columnName->getQuotedName($this) . - " IS " . $comment; + return 'COMMENT ON COLUMN ' . $tableName->getQuotedName($this) . '.' . $columnName->getQuotedName($this) . + ' IS ' . $comment; } /** @@ -1664,7 +1636,7 @@ public function getCommentOnColumnSQL($tableName, $columnName, $comment) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getInlineColumnCommentSQL($comment) { @@ -1672,7 +1644,7 @@ public function getInlineColumnCommentSQL($comment) throw DBALException::notSupported(__METHOD__); } - return "COMMENT " . $this->quoteStringLiteral($comment); + return 'COMMENT ' . $this->quoteStringLiteral($comment); } /** @@ -1707,7 +1679,7 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options $query = 'CREATE TABLE ' . $tableName . ' (' . $columnListSql; $check = $this->getCheckDeclarationSQL($columns); - if ( ! empty($check)) { + if (! empty($check)) { $query .= ', ' . $check; } $query .= ')'; @@ -1728,17 +1700,15 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options */ public function getCreateTemporaryTableSnippetSQL() { - return "CREATE TEMPORARY TABLE"; + return 'CREATE TEMPORARY TABLE'; } /** * Returns the SQL to create a sequence on this platform. * - * @param \Doctrine\DBAL\Schema\Sequence $sequence - * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getCreateSequenceSQL(Sequence $sequence) { @@ -1748,11 +1718,9 @@ public function getCreateSequenceSQL(Sequence $sequence) /** * Returns the SQL to change a sequence on this platform. * - * @param \Doctrine\DBAL\Schema\Sequence $sequence - * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getAlterSequenceSQL(Sequence $sequence) { @@ -1762,12 +1730,11 @@ public function getAlterSequenceSQL(Sequence $sequence) /** * Returns the SQL to create a constraint on a table on this platform. * - * @param \Doctrine\DBAL\Schema\Constraint $constraint - * @param \Doctrine\DBAL\Schema\Table|string $table + * @param Table|string $table * * @return string * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ public function getCreateConstraintSQL(Constraint $constraint, $table) { @@ -1777,7 +1744,7 @@ public function getCreateConstraintSQL(Constraint $constraint, $table) $query = 'ALTER TABLE ' . $table . ' ADD CONSTRAINT ' . $constraint->getQuotedName($this); - $columnList = '('. implode(', ', $constraint->getQuotedColumns($this)) . ')'; + $columnList = '(' . implode(', ', $constraint->getQuotedColumns($this)) . ')'; $referencesClause = ''; if ($constraint instanceof Index) { @@ -1786,7 +1753,7 @@ public function getCreateConstraintSQL(Constraint $constraint, $table) } elseif ($constraint->isUnique()) { $query .= ' UNIQUE'; } else { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Can only create primary or unique constraints, no common indexes with getCreateConstraintSQL().' ); } @@ -1796,7 +1763,7 @@ public function getCreateConstraintSQL(Constraint $constraint, $table) $referencesClause = ' REFERENCES ' . $constraint->getQuotedForeignTableName($this) . ' (' . implode(', ', $constraint->getQuotedForeignColumns($this)) . ')'; } - $query .= ' '.$columnList.$referencesClause; + $query .= ' ' . $columnList . $referencesClause; return $query; } @@ -1804,30 +1771,29 @@ public function getCreateConstraintSQL(Constraint $constraint, $table) /** * Returns the SQL to create an index on a table on this platform. * - * @param \Doctrine\DBAL\Schema\Index $index - * @param \Doctrine\DBAL\Schema\Table|string $table The name of the table on which the index is to be created. + * @param Table|string $table The name of the table on which the index is to be created. * * @return string * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ public function getCreateIndexSQL(Index $index, $table) { if ($table instanceof Table) { $table = $table->getQuotedName($this); } - $name = $index->getQuotedName($this); + $name = $index->getQuotedName($this); $columns = $index->getQuotedColumns($this); - if (count($columns) == 0) { - throw new \InvalidArgumentException("Incomplete definition. 'columns' required."); + if (count($columns) === 0) { + throw new InvalidArgumentException("Incomplete definition. 'columns' required."); } if ($index->isPrimary()) { return $this->getCreatePrimaryKeySQL($index, $table); } - $query = 'CREATE ' . $this->getCreateIndexSQLFlags($index) . 'INDEX ' . $name . ' ON ' . $table; + $query = 'CREATE ' . $this->getCreateIndexSQLFlags($index) . 'INDEX ' . $name . ' ON ' . $table; $query .= ' (' . $this->getIndexFieldDeclarationListSQL($columns) . ')' . $this->getPartialIndexSQL($index); return $query; @@ -1836,14 +1802,12 @@ public function getCreateIndexSQL(Index $index, $table) /** * Adds condition for partial index. * - * @param \Doctrine\DBAL\Schema\Index $index - * * @return string */ protected function getPartialIndexSQL(Index $index) { if ($this->supportsPartialIndexes() && $index->hasOption('where')) { - return ' WHERE ' . $index->getOption('where'); + return ' WHERE ' . $index->getOption('where'); } return ''; @@ -1852,8 +1816,6 @@ protected function getPartialIndexSQL(Index $index) /** * Adds additional flags for index generation. * - * @param \Doctrine\DBAL\Schema\Index $index - * * @return string */ protected function getCreateIndexSQLFlags(Index $index) @@ -1864,8 +1826,7 @@ protected function getCreateIndexSQLFlags(Index $index) /** * Returns the SQL to create an unnamed primary key constraint. * - * @param \Doctrine\DBAL\Schema\Index $index - * @param \Doctrine\DBAL\Schema\Table|string $table + * @param Table|string $table * * @return string */ @@ -1880,7 +1841,8 @@ public function getCreatePrimaryKeySQL(Index $index, $table) * @param string $schemaName * * @return string - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * + * @throws DBALException If not supported on this platform. */ public function getCreateSchemaSQL($schemaName) { @@ -1902,10 +1864,10 @@ public function getCreateSchemaSQL($schemaName) */ public function quoteIdentifier($str) { - if (strpos($str, ".") !== false) { - $parts = array_map([$this, "quoteSingleIdentifier"], explode(".", $str)); + if (strpos($str, '.') !== false) { + $parts = array_map([$this, 'quoteSingleIdentifier'], explode('.', $str)); - return implode(".", $parts); + return implode('.', $parts); } return $this->quoteSingleIdentifier($str); @@ -1922,14 +1884,14 @@ public function quoteSingleIdentifier($str) { $c = $this->getIdentifierQuoteCharacter(); - return $c . str_replace($c, $c.$c, $str) . $c; + return $c . str_replace($c, $c . $c, $str) . $c; } /** * Returns the SQL to create a new foreign key. * - * @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey The foreign key constraint. - * @param \Doctrine\DBAL\Schema\Table|string $table The name of the table on which the foreign key is to be created. + * @param ForeignKeyConstraint $foreignKey The foreign key constraint. + * @param Table|string $table The name of the table on which the foreign key is to be created. * * @return string */ @@ -1949,11 +1911,9 @@ public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table) * * This method returns an array of SQL statements, since some platforms need several statements. * - * @param \Doctrine\DBAL\Schema\TableDiff $diff - * * @return array * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getAlterTableSQL(TableDiff $diff) { @@ -1961,19 +1921,17 @@ public function getAlterTableSQL(TableDiff $diff) } /** - * @param \Doctrine\DBAL\Schema\Column $column - * @param \Doctrine\DBAL\Schema\TableDiff $diff - * @param array $columnSql + * @param array $columnSql * * @return bool */ protected function onSchemaAlterTableAddColumn(Column $column, TableDiff $diff, &$columnSql) { - if (null === $this->_eventManager) { + if ($this->_eventManager === null) { return false; } - if ( ! $this->_eventManager->hasListeners(Events::onSchemaAlterTableAddColumn)) { + if (! $this->_eventManager->hasListeners(Events::onSchemaAlterTableAddColumn)) { return false; } @@ -1986,19 +1944,17 @@ protected function onSchemaAlterTableAddColumn(Column $column, TableDiff $diff, } /** - * @param \Doctrine\DBAL\Schema\Column $column - * @param \Doctrine\DBAL\Schema\TableDiff $diff - * @param array $columnSql + * @param array $columnSql * * @return bool */ protected function onSchemaAlterTableRemoveColumn(Column $column, TableDiff $diff, &$columnSql) { - if (null === $this->_eventManager) { + if ($this->_eventManager === null) { return false; } - if ( ! $this->_eventManager->hasListeners(Events::onSchemaAlterTableRemoveColumn)) { + if (! $this->_eventManager->hasListeners(Events::onSchemaAlterTableRemoveColumn)) { return false; } @@ -2011,19 +1967,17 @@ protected function onSchemaAlterTableRemoveColumn(Column $column, TableDiff $dif } /** - * @param \Doctrine\DBAL\Schema\ColumnDiff $columnDiff - * @param \Doctrine\DBAL\Schema\TableDiff $diff - * @param array $columnSql + * @param array $columnSql * * @return bool */ protected function onSchemaAlterTableChangeColumn(ColumnDiff $columnDiff, TableDiff $diff, &$columnSql) { - if (null === $this->_eventManager) { + if ($this->_eventManager === null) { return false; } - if ( ! $this->_eventManager->hasListeners(Events::onSchemaAlterTableChangeColumn)) { + if (! $this->_eventManager->hasListeners(Events::onSchemaAlterTableChangeColumn)) { return false; } @@ -2036,20 +1990,18 @@ protected function onSchemaAlterTableChangeColumn(ColumnDiff $columnDiff, TableD } /** - * @param string $oldColumnName - * @param \Doctrine\DBAL\Schema\Column $column - * @param \Doctrine\DBAL\Schema\TableDiff $diff - * @param array $columnSql + * @param string $oldColumnName + * @param array $columnSql * * @return bool */ protected function onSchemaAlterTableRenameColumn($oldColumnName, Column $column, TableDiff $diff, &$columnSql) { - if (null === $this->_eventManager) { + if ($this->_eventManager === null) { return false; } - if ( ! $this->_eventManager->hasListeners(Events::onSchemaAlterTableRenameColumn)) { + if (! $this->_eventManager->hasListeners(Events::onSchemaAlterTableRenameColumn)) { return false; } @@ -2062,18 +2014,17 @@ protected function onSchemaAlterTableRenameColumn($oldColumnName, Column $column } /** - * @param \Doctrine\DBAL\Schema\TableDiff $diff - * @param array $sql + * @param array $sql * * @return bool */ protected function onSchemaAlterTable(TableDiff $diff, &$sql) { - if (null === $this->_eventManager) { + if ($this->_eventManager === null) { return false; } - if ( ! $this->_eventManager->hasListeners(Events::onSchemaAlterTable)) { + if (! $this->_eventManager->hasListeners(Events::onSchemaAlterTable)) { return false; } @@ -2086,8 +2037,6 @@ protected function onSchemaAlterTable(TableDiff $diff, &$sql) } /** - * @param \Doctrine\DBAL\Schema\TableDiff $diff - * * @return array */ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) @@ -2115,13 +2064,11 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) } /** - * @param \Doctrine\DBAL\Schema\TableDiff $diff - * * @return array */ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff) { - $tableName = (false !== $diff->newName) + $tableName = $diff->newName !== false ? $diff->getNewName()->getQuotedName($this) : $diff->getName($this)->getQuotedName($this); @@ -2159,9 +2106,9 @@ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff) /** * Returns the SQL for renaming an index on a table. * - * @param string $oldIndexName The name of the index to rename from. - * @param \Doctrine\DBAL\Schema\Index $index The definition of the index to rename to. - * @param string $tableName The table to rename the given index on. + * @param string $oldIndexName The name of the index to rename from. + * @param Index $index The definition of the index to rename to. + * @param string $tableName The table to rename the given index on. * * @return array The sequence of SQL statements for renaming the given index. */ @@ -2169,15 +2116,13 @@ protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName) { return [ $this->getDropIndexSQL($oldIndexName, $tableName), - $this->getCreateIndexSQL($index, $tableName) + $this->getCreateIndexSQL($index, $tableName), ]; } /** * Common code for alter table statement generation that updates the changed Index and Foreign Key definitions. * - * @param \Doctrine\DBAL\Schema\TableDiff $diff - * * @return array */ protected function _getAlterTableIndexForeignKeySQL(TableDiff $diff) @@ -2265,21 +2210,21 @@ public function getColumnDeclarationSQL($name, array $field) } else { $default = $this->getDefaultValueDeclarationSQL($field); - $charset = (isset($field['charset']) && $field['charset']) ? + $charset = isset($field['charset']) && $field['charset'] ? ' ' . $this->getColumnCharsetDeclarationSQL($field['charset']) : ''; - $collation = (isset($field['collation']) && $field['collation']) ? + $collation = isset($field['collation']) && $field['collation'] ? ' ' . $this->getColumnCollationDeclarationSQL($field['collation']) : ''; - $notnull = (isset($field['notnull']) && $field['notnull']) ? ' NOT NULL' : ''; + $notnull = isset($field['notnull']) && $field['notnull'] ? ' NOT NULL' : ''; - $unique = (isset($field['unique']) && $field['unique']) ? + $unique = isset($field['unique']) && $field['unique'] ? ' ' . $this->getUniqueFieldDeclarationSQL() : ''; - $check = (isset($field['check']) && $field['check']) ? + $check = isset($field['check']) && $field['check'] ? ' ' . $field['check'] : ''; - $typeDecl = $field['type']->getSQLDeclaration($field, $this); + $typeDecl = $field['type']->getSQLDeclaration($field, $this); $columnDef = $typeDecl . $charset . $default . $notnull . $unique . $check . $collation; if ($this->supportsInlineColumnComments() && isset($field['comment']) && $field['comment'] !== '') { @@ -2299,9 +2244,9 @@ public function getColumnDeclarationSQL($name, array $field) */ public function getDecimalTypeDeclarationSQL(array $columnDef) { - $columnDef['precision'] = ( ! isset($columnDef['precision']) || empty($columnDef['precision'])) + $columnDef['precision'] = ! isset($columnDef['precision']) || empty($columnDef['precision']) ? 10 : $columnDef['precision']; - $columnDef['scale'] = ( ! isset($columnDef['scale']) || empty($columnDef['scale'])) + $columnDef['scale'] = ! isset($columnDef['scale']) || empty($columnDef['scale']) ? 0 : $columnDef['scale']; return 'NUMERIC(' . $columnDef['precision'] . ', ' . $columnDef['scale'] . ')'; @@ -2317,13 +2262,13 @@ public function getDecimalTypeDeclarationSQL(array $columnDef) */ public function getDefaultValueDeclarationSQL($field) { - if ( ! isset($field['default'])) { + if (! isset($field['default'])) { return empty($field['notnull']) ? ' DEFAULT NULL' : ''; } $default = $field['default']; - if ( ! isset($field['type'])) { + if (! isset($field['type'])) { return " DEFAULT '" . $default . "'"; } @@ -2384,20 +2329,20 @@ public function getCheckDeclarationSQL(array $definition) * Obtains DBMS specific SQL code portion needed to set a unique * constraint declaration to be used in statements like CREATE TABLE. * - * @param string $name The name of the unique constraint. - * @param \Doctrine\DBAL\Schema\Index $index The index definition. + * @param string $name The name of the unique constraint. + * @param Index $index The index definition. * * @return string DBMS specific SQL code portion needed to set a constraint. * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ public function getUniqueConstraintDeclarationSQL($name, Index $index) { $columns = $index->getQuotedColumns($this); - $name = new Identifier($name); + $name = new Identifier($name); if (count($columns) === 0) { - throw new \InvalidArgumentException("Incomplete definition. 'columns' required."); + throw new InvalidArgumentException("Incomplete definition. 'columns' required."); } return 'CONSTRAINT ' . $name->getQuotedName($this) . ' UNIQUE (' @@ -2409,20 +2354,20 @@ public function getUniqueConstraintDeclarationSQL($name, Index $index) * Obtains DBMS specific SQL code portion needed to set an index * declaration to be used in statements like CREATE TABLE. * - * @param string $name The name of the index. - * @param \Doctrine\DBAL\Schema\Index $index The index definition. + * @param string $name The name of the index. + * @param Index $index The index definition. * * @return string DBMS specific SQL code portion needed to set an index. * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ public function getIndexDeclarationSQL($name, Index $index) { $columns = $index->getQuotedColumns($this); - $name = new Identifier($name); + $name = new Identifier($name); if (count($columns) === 0) { - throw new \InvalidArgumentException("Incomplete definition. 'columns' required."); + throw new InvalidArgumentException("Incomplete definition. 'columns' required."); } return $this->getCreateIndexSQLFlags($index) . 'INDEX ' . $name->getQuotedName($this) . ' (' @@ -2502,8 +2447,6 @@ public function getTemporaryTableName($tableName) * Obtain DBMS specific SQL code portion needed to set the FOREIGN KEY constraint * of a field declaration to be used in statements like CREATE TABLE. * - * @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey - * * @return string DBMS specific SQL code portion needed to set the FOREIGN KEY constraint * of a field declaration. */ @@ -2519,7 +2462,7 @@ public function getForeignKeyDeclarationSQL(ForeignKeyConstraint $foreignKey) * Returns the FOREIGN KEY query section dealing with non-standard options * as MATCH, INITIALLY DEFERRED, ON UPDATE, ... * - * @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey The foreign key definition. + * @param ForeignKeyConstraint $foreignKey The foreign key definition. * * @return string */ @@ -2543,7 +2486,7 @@ public function getAdvancedForeignKeyOptionsSQL(ForeignKeyConstraint $foreignKey * * @return string * - * @throws \InvalidArgumentException if unknown referential action given + * @throws InvalidArgumentException if unknown referential action given */ public function getForeignKeyReferentialActionSQL($action) { @@ -2556,7 +2499,7 @@ public function getForeignKeyReferentialActionSQL($action) case 'SET DEFAULT': return $upper; default: - throw new \InvalidArgumentException('Invalid foreign key action: ' . $upper); + throw new InvalidArgumentException('Invalid foreign key action: ' . $upper); } } @@ -2564,11 +2507,9 @@ public function getForeignKeyReferentialActionSQL($action) * Obtains DBMS specific SQL code portion needed to set the FOREIGN KEY constraint * of a field declaration to be used in statements like CREATE TABLE. * - * @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey - * * @return string * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ public function getForeignKeyBaseDeclarationSQL(ForeignKeyConstraint $foreignKey) { @@ -2579,13 +2520,13 @@ public function getForeignKeyBaseDeclarationSQL(ForeignKeyConstraint $foreignKey $sql .= 'FOREIGN KEY ('; if (count($foreignKey->getLocalColumns()) === 0) { - throw new \InvalidArgumentException("Incomplete definition. 'local' required."); + throw new InvalidArgumentException("Incomplete definition. 'local' required."); } if (count($foreignKey->getForeignColumns()) === 0) { - throw new \InvalidArgumentException("Incomplete definition. 'foreign' required."); + throw new InvalidArgumentException("Incomplete definition. 'foreign' required."); } if (strlen($foreignKey->getForeignTableName()) === 0) { - throw new \InvalidArgumentException("Incomplete definition. 'foreignTable' required."); + throw new InvalidArgumentException("Incomplete definition. 'foreignTable' required."); } $sql .= implode(', ', $foreignKey->getQuotedLocalColumns($this)) @@ -2676,9 +2617,11 @@ public function convertBooleans($item) { if (is_array($item)) { foreach ($item as $k => $value) { - if (is_bool($value)) { - $item[$k] = (int) $value; + if (! is_bool($value)) { + continue; } + + $item[$k] = (int) $value; } } elseif (is_bool($item)) { $item = (int) $item; @@ -2698,7 +2641,7 @@ public function convertBooleans($item) */ public function convertFromBoolean($item) { - return null === $item ? null: (bool) $item ; + return $item === null ? null: (bool) $item; } /** @@ -2753,7 +2696,7 @@ public function getCurrentTimestampSQL() * * @return string * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ protected function _getTransactionIsolationLevelSQL($level) { @@ -2767,14 +2710,14 @@ protected function _getTransactionIsolationLevelSQL($level) case TransactionIsolationLevel::SERIALIZABLE: return 'SERIALIZABLE'; default: - throw new \InvalidArgumentException('Invalid isolation level:' . $level); + throw new InvalidArgumentException('Invalid isolation level:' . $level); } } /** * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getListDatabasesSQL() { @@ -2786,7 +2729,7 @@ public function getListDatabasesSQL() * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getListNamespacesSQL() { @@ -2798,7 +2741,7 @@ public function getListNamespacesSQL() * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getListSequencesSQL($database) { @@ -2810,7 +2753,7 @@ public function getListSequencesSQL($database) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getListTableConstraintsSQL($table) { @@ -2823,7 +2766,7 @@ public function getListTableConstraintsSQL($table) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getListTableColumnsSQL($table, $database = null) { @@ -2833,7 +2776,7 @@ public function getListTableColumnsSQL($table, $database = null) /** * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getListTablesSQL() { @@ -2843,7 +2786,7 @@ public function getListTablesSQL() /** * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getListUsersSQL() { @@ -2857,7 +2800,7 @@ public function getListUsersSQL() * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getListViewsSQL($database) { @@ -2879,7 +2822,7 @@ public function getListViewsSQL($database) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getListTableIndexesSQL($table, $currentDatabase = null) { @@ -2891,7 +2834,7 @@ public function getListTableIndexesSQL($table, $currentDatabase = null) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getListTableForeignKeysSQL($table) { @@ -2904,7 +2847,7 @@ public function getListTableForeignKeysSQL($table) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getCreateViewSQL($name, $sql) { @@ -2916,7 +2859,7 @@ public function getCreateViewSQL($name, $sql) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getDropViewSQL($name) { @@ -2930,7 +2873,7 @@ public function getDropViewSQL($name) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getDropSequenceSQL($sequence) { @@ -2942,7 +2885,7 @@ public function getDropSequenceSQL($sequence) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getSequenceNextValSQL($sequenceName) { @@ -2956,7 +2899,7 @@ public function getSequenceNextValSQL($sequenceName) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getCreateDatabaseSQL($database) { @@ -2970,7 +2913,7 @@ public function getCreateDatabaseSQL($database) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getSetTransactionIsolationSQL($level) { @@ -2985,7 +2928,7 @@ public function getSetTransactionIsolationSQL($level) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration) { @@ -3013,7 +2956,7 @@ public function getDateTimeTzTypeDeclarationSQL(array $fieldDeclaration) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getDateTypeDeclarationSQL(array $fieldDeclaration) { @@ -3028,7 +2971,7 @@ public function getDateTypeDeclarationSQL(array $fieldDeclaration) * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getTimeTypeDeclarationSQL(array $fieldDeclaration) { @@ -3048,9 +2991,9 @@ public function getFloatDeclarationSQL(array $fieldDeclaration) /** * Gets the default transaction isolation level of the platform. * - * @return int The default isolation level. - * * @see TransactionIsolationLevel + * + * @return int The default isolation level. */ public function getDefaultTransactionIsolationLevel() { @@ -3099,14 +3042,14 @@ public function usesSequenceEmulatedIdentityColumns() /** * Returns the name of the sequence for a particular identity column in a particular table. * + * @see usesSequenceEmulatedIdentityColumns + * * @param string $tableName The name of the table to return the sequence name for. * @param string $columnName The name of the identity column in the table to return the sequence name for. * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. - * - * @see usesSequenceEmulatedIdentityColumns + * @throws DBALException If not supported on this platform. */ public function getIdentitySequenceName($tableName, $columnName) { @@ -3200,7 +3143,7 @@ public function supportsForeignKeyConstraints() */ public function supportsForeignKeyOnUpdate() { - return ($this->supportsForeignKeyConstraints() && true); + return $this->supportsForeignKeyConstraints() && true; } /** @@ -3232,7 +3175,7 @@ public function canEmulateSchemas() * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ public function getDefaultSchemaName() { @@ -3303,11 +3246,12 @@ public function hasNativeJsonType() /** * @deprecated + * * @todo Remove in 3.0 */ public function getIdentityColumnNullInsertSQL() { - return ""; + return ''; } /** @@ -3559,9 +3503,9 @@ public function rollbackSavePoint($savepoint) /** * Returns the keyword list instance of this platform. * - * @return \Doctrine\DBAL\Platforms\Keywords\KeywordList + * @return KeywordList * - * @throws \Doctrine\DBAL\DBALException If no keyword list is specified. + * @throws DBALException If no keyword list is specified. */ final public function getReservedKeywordsList() { @@ -3570,9 +3514,9 @@ final public function getReservedKeywordsList() return $this->_keywords; } - $class = $this->getReservedKeywordsClass(); - $keywords = new $class; - if ( ! $keywords instanceof \Doctrine\DBAL\Platforms\Keywords\KeywordList) { + $class = $this->getReservedKeywordsClass(); + $keywords = new $class(); + if (! $keywords instanceof KeywordList) { throw DBALException::notSupported(__METHOD__); } @@ -3587,7 +3531,7 @@ final public function getReservedKeywordsList() * * @return string * - * @throws \Doctrine\DBAL\DBALException If not supported on this platform. + * @throws DBALException If not supported on this platform. */ protected function getReservedKeywordsClass() { diff --git a/lib/Doctrine/DBAL/Platforms/DB2Platform.php b/lib/Doctrine/DBAL/Platforms/DB2Platform.php index 11fd6ae0176..56b4d19562e 100644 --- a/lib/Doctrine/DBAL/Platforms/DB2Platform.php +++ b/lib/Doctrine/DBAL/Platforms/DB2Platform.php @@ -178,7 +178,7 @@ public function getSmallIntTypeDeclarationSQL(array $columnDef) protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) { $autoinc = ''; - if ( ! empty($columnDef['autoincrement'])) { + if (! empty($columnDef['autoincrement'])) { $autoinc = ' GENERATED BY DEFAULT AS IDENTITY'; } @@ -234,8 +234,8 @@ public function getDateDiffExpression($date1, $date2) */ public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration) { - if (isset($fieldDeclaration['version']) && $fieldDeclaration['version'] == true) { - return "TIMESTAMP(0) WITH DEFAULT"; + if (isset($fieldDeclaration['version']) && $fieldDeclaration['version'] === true) { + return 'TIMESTAMP(0) WITH DEFAULT'; } return 'TIMESTAMP(0)'; @@ -270,8 +270,6 @@ public function getTruncateTableSQL($tableName, $cascade = false) /** * This code fragment is originally from the Zend_Db_Adapter_Db2 class, but has been edited. * - * @license New BSD License - * * @param string $table * @param string $database * @@ -314,7 +312,7 @@ public function getListTableColumnsSQL($table, $database = null) ON (c.tabschema = k.tabschema AND c.tabname = k.tabname AND c.colname = k.colname) - WHERE UPPER(c.tabname) = UPPER(" . $table . ") + WHERE UPPER(c.tabname) = UPPER(" . $table . ') ORDER BY c.colno ) subq JOIN syscat.columns cols @@ -322,7 +320,7 @@ public function getListTableColumnsSQL($table, $database = null) AND subq.tabname = cols.tabname AND subq.colno = cols.colno ORDER BY subq.colno - "; + '; } /** @@ -338,7 +336,7 @@ public function getListTablesSQL() */ public function getListViewsSQL($database) { - return "SELECT NAME, TEXT FROM SYSIBM.SYSVIEWS"; + return 'SELECT NAME, TEXT FROM SYSIBM.SYSVIEWS'; } /** @@ -361,8 +359,8 @@ public function getListTableIndexesSQL($table, $currentDatabase = null) FROM SYSCAT.INDEXES AS idx JOIN SYSCAT.INDEXCOLUSE AS idxcol ON idx.INDSCHEMA = idxcol.INDSCHEMA AND idx.INDNAME = idxcol.INDNAME - WHERE idx.TABNAME = UPPER(" . $table . ") - ORDER BY idxcol.COLSEQ ASC"; + WHERE idx.TABNAME = UPPER(" . $table . ') + ORDER BY idxcol.COLSEQ ASC'; } /** @@ -395,8 +393,8 @@ public function getListTableForeignKeysSQL($table) ON fk.REFKEYNAME = pkcol.CONSTNAME AND fk.REFTABSCHEMA = pkcol.TABSCHEMA AND fk.REFTABNAME = pkcol.TABNAME - WHERE fk.TABNAME = UPPER(" . $table . ") - ORDER BY fkcol.COLSEQ ASC"; + WHERE fk.TABNAME = UPPER(" . $table . ') + ORDER BY fkcol.COLSEQ ASC'; } /** @@ -404,7 +402,7 @@ public function getListTableForeignKeysSQL($table) */ public function getCreateViewSQL($name, $sql) { - return "CREATE VIEW ".$name." AS ".$sql; + return 'CREATE VIEW ' . $name . ' AS ' . $sql; } /** @@ -412,7 +410,7 @@ public function getCreateViewSQL($name, $sql) */ public function getDropViewSQL($name) { - return "DROP VIEW ".$name; + return 'DROP VIEW ' . $name; } /** @@ -420,7 +418,7 @@ public function getDropViewSQL($name) */ public function getCreateDatabaseSQL($database) { - return "CREATE DATABASE ".$database; + return 'CREATE DATABASE ' . $database; } /** @@ -428,7 +426,7 @@ public function getCreateDatabaseSQL($database) */ public function getDropDatabaseSQL($database) { - return "DROP DATABASE " . $database; + return 'DROP DATABASE ' . $database; } /** @@ -476,7 +474,7 @@ public function getCurrentTimeSQL() */ public function getCurrentTimestampSQL() { - return "CURRENT TIMESTAMP"; + return 'CURRENT TIMESTAMP'; } /** @@ -512,8 +510,8 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options */ public function getAlterTableSQL(TableDiff $diff) { - $sql = []; - $columnSql = []; + $sql = []; + $columnSql = []; $commentsSQL = []; $queryParts = []; @@ -526,7 +524,7 @@ public function getAlterTableSQL(TableDiff $diff) $queryPart = 'ADD COLUMN ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnDef); // Adding non-nullable columns to a table requires a default value to be specified. - if ( ! empty($columnDef['notnull']) && + if (! empty($columnDef['notnull']) && ! isset($columnDef['default']) && empty($columnDef['autoincrement']) ) { @@ -537,13 +535,15 @@ public function getAlterTableSQL(TableDiff $diff) $comment = $this->getColumnComment($column); - if (null !== $comment && '' !== $comment) { - $commentsSQL[] = $this->getCommentOnColumnSQL( - $diff->getName($this)->getQuotedName($this), - $column->getQuotedName($this), - $comment - ); + if ($comment === null || $comment === '') { + continue; } + + $commentsSQL[] = $this->getCommentOnColumnSQL( + $diff->getName($this)->getQuotedName($this), + $column->getQuotedName($this), + $comment + ); } foreach ($diff->removedColumns as $column) { @@ -587,13 +587,13 @@ public function getAlterTableSQL(TableDiff $diff) $tableSql = []; - if ( ! $this->onSchemaAlterTable($diff, $tableSql)) { + if (! $this->onSchemaAlterTable($diff, $tableSql)) { if (count($queryParts) > 0) { - $sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ' . implode(" ", $queryParts); + $sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ' . implode(' ', $queryParts); } // Some table alteration operations require a table reorganization. - if ( ! empty($diff->removedColumns) || ! empty($diff->changedColumns)) { + if (! empty($diff->removedColumns) || ! empty($diff->changedColumns)) { $sql[] = "CALL SYSPROC.ADMIN_CMD ('REORG TABLE " . $diff->getName($this)->getQuotedName($this) . "')"; } @@ -696,12 +696,12 @@ private function getAlterColumnClausesSQL(ColumnDiff $columnDiff) */ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) { - $sql = []; + $sql = []; $table = $diff->getName($this)->getQuotedName($this); foreach ($diff->removedIndexes as $remKey => $remIndex) { foreach ($diff->addedIndexes as $addKey => $addIndex) { - if ($remIndex->getColumns() == $addIndex->getColumns()) { + if ($remIndex->getColumns() === $addIndex->getColumns()) { if ($remIndex->isPrimary()) { $sql[] = 'ALTER TABLE ' . $table . ' DROP PRIMARY KEY'; } elseif ($remIndex->isUnique()) { @@ -730,7 +730,7 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName) { if (strpos($tableName, '.') !== false) { - list($schema) = explode('.', $tableName); + [$schema] = explode('.', $tableName); $oldIndexName = $schema . '.' . $oldIndexName; } @@ -742,13 +742,13 @@ protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName) */ public function getDefaultValueDeclarationSQL($field) { - if ( ! empty($field['autoincrement'])) { + if (! empty($field['autoincrement'])) { return ''; } if (isset($field['version']) && $field['version']) { - if ((string) $field['type'] != "DateTime") { - $field['default'] = "1"; + if ((string) $field['type'] !== 'DateTime') { + $field['default'] = '1'; } } @@ -768,7 +768,7 @@ public function getEmptyIdentityInsertSQL($tableName, $identifierColumnName) */ public function getCreateTemporaryTableSnippetSQL() { - return "DECLARE GLOBAL TEMPORARY TABLE"; + return 'DECLARE GLOBAL TEMPORARY TABLE'; } /** @@ -776,7 +776,7 @@ public function getCreateTemporaryTableSnippetSQL() */ public function getTemporaryTableName($tableName) { - return "SESSION." . $tableName; + return 'SESSION.' . $tableName; } /** @@ -811,11 +811,11 @@ protected function doModifyLimitQuery($query, $limit, $offset = null) */ public function getLocateExpression($str, $substr, $startPos = false) { - if ($startPos == false) { + if ($startPos === false) { return 'LOCATE(' . $substr . ', ' . $str . ')'; } - return 'LOCATE(' . $substr . ', ' . $str . ', '.$startPos.')'; + return 'LOCATE(' . $substr . ', ' . $str . ', ' . $startPos . ')'; } /** diff --git a/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php b/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php index 8e6968b1146..fd23ab011c0 100644 --- a/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php @@ -2,11 +2,13 @@ namespace Doctrine\DBAL\Platforms; +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\BinaryType; +use InvalidArgumentException; use function array_merge; use function array_unique; use function array_values; @@ -23,8 +25,6 @@ /** * Drizzle platform - * - * @author Kim Hemsø Rasmussen */ class DrizzlePlatform extends AbstractPlatform { @@ -59,7 +59,7 @@ public function getConcatExpression() */ protected function getDateArithmeticIntervalExpression($date, $operator, $interval, $unit) { - $function = '+' === $operator ? 'DATE_ADD' : 'DATE_SUB'; + $function = $operator === '+' ? 'DATE_ADD' : 'DATE_SUB'; return $function . '(' . $date . ', INTERVAL ' . $interval . ' ' . $unit . ')'; } @@ -94,7 +94,7 @@ public function getIntegerTypeDeclarationSQL(array $field) protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) { $autoinc = ''; - if ( ! empty($columnDef['autoincrement'])) { + if (! empty($columnDef['autoincrement'])) { $autoinc = ' AUTO_INCREMENT'; } @@ -209,13 +209,13 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options // attach all primary keys if (isset($options['primary']) && ! empty($options['primary'])) { - $keyColumns = array_unique(array_values($options['primary'])); + $keyColumns = array_unique(array_values($options['primary'])); $queryFields .= ', PRIMARY KEY(' . implode(', ', $keyColumns) . ')'; } $query = 'CREATE '; - if (!empty($options['temporary'])) { + if (! empty($options['temporary'])) { $query .= 'TEMPORARY '; } @@ -250,14 +250,14 @@ private function buildTableOptions(array $options) $tableOptions = []; // Collate - if ( ! isset($options['collate'])) { + if (! isset($options['collate'])) { $options['collate'] = 'utf8_unicode_ci'; } $tableOptions[] = sprintf('COLLATE %s', $options['collate']); // Engine - if ( ! isset($options['engine'])) { + if (! isset($options['engine'])) { $options['engine'] = 'InnoDB'; } @@ -272,7 +272,7 @@ private function buildTableOptions(array $options) if (isset($options['comment'])) { $comment = trim($options['comment'], " '"); - $tableOptions[] = sprintf("COMMENT = %s ", $this->quoteStringLiteral($comment)); + $tableOptions[] = sprintf('COMMENT = %s ', $this->quoteStringLiteral($comment)); } // Row format @@ -292,7 +292,7 @@ private function buildTableOptions(array $options) */ private function buildPartitionOptions(array $options) { - return (isset($options['partition_options'])) + return isset($options['partition_options']) ? ' ' . $options['partition_options'] : ''; } @@ -332,10 +332,10 @@ public function getListTableColumnsSQL($table, $database = null) $database = 'DATABASE()'; } - return "SELECT COLUMN_NAME, DATA_TYPE, COLUMN_COMMENT, IS_NULLABLE, IS_AUTO_INCREMENT, CHARACTER_MAXIMUM_LENGTH, COLUMN_DEFAULT," . - " NUMERIC_PRECISION, NUMERIC_SCALE, COLLATION_NAME" . - " FROM DATA_DICTIONARY.COLUMNS" . - " WHERE TABLE_SCHEMA=" . $database . " AND TABLE_NAME = '" . $table . "'"; + return 'SELECT COLUMN_NAME, DATA_TYPE, COLUMN_COMMENT, IS_NULLABLE, IS_AUTO_INCREMENT, CHARACTER_MAXIMUM_LENGTH, COLUMN_DEFAULT,' . + ' NUMERIC_PRECISION, NUMERIC_SCALE, COLLATION_NAME' . + ' FROM DATA_DICTIONARY.COLUMNS' . + ' WHERE TABLE_SCHEMA=' . $database . " AND TABLE_NAME = '" . $table . "'"; } /** @@ -349,9 +349,9 @@ public function getListTableForeignKeysSQL($table, $database = null) $database = 'DATABASE()'; } - return "SELECT CONSTRAINT_NAME, CONSTRAINT_COLUMNS, REFERENCED_TABLE_NAME, REFERENCED_TABLE_COLUMNS, UPDATE_RULE, DELETE_RULE" . - " FROM DATA_DICTIONARY.FOREIGN_KEYS" . - " WHERE CONSTRAINT_SCHEMA=" . $database . " AND CONSTRAINT_TABLE='" . $table . "'"; + return 'SELECT CONSTRAINT_NAME, CONSTRAINT_COLUMNS, REFERENCED_TABLE_NAME, REFERENCED_TABLE_COLUMNS, UPDATE_RULE, DELETE_RULE' . + ' FROM DATA_DICTIONARY.FOREIGN_KEYS' . + ' WHERE CONSTRAINT_SCHEMA=' . $database . " AND CONSTRAINT_TABLE='" . $table . "'"; } /** @@ -366,8 +366,8 @@ public function getListTableIndexesSQL($table, $database = null) } return "SELECT INDEX_NAME AS 'key_name', COLUMN_NAME AS 'column_name', IS_USED_IN_PRIMARY AS 'primary', IS_UNIQUE=0 AS 'non_unique'" . - " FROM DATA_DICTIONARY.INDEX_PARTS" . - " WHERE TABLE_SCHEMA=" . $database . " AND TABLE_NAME='" . $table . "'"; + ' FROM DATA_DICTIONARY.INDEX_PARTS' . + ' WHERE TABLE_SCHEMA=' . $database . " AND TABLE_NAME='" . $table . "'"; } /** @@ -413,20 +413,20 @@ public function supportsColumnCollation() /** * {@inheritDoc} */ - public function getDropIndexSQL($index, $table=null) + public function getDropIndexSQL($index, $table = null) { if ($index instanceof Index) { $indexName = $index->getQuotedName($this); } elseif (is_string($index)) { $indexName = $index; } else { - throw new \InvalidArgumentException('DrizzlePlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.'); + throw new InvalidArgumentException('DrizzlePlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.'); } if ($table instanceof Table) { $table = $table->getQuotedName($this); - } elseif (!is_string($table)) { - throw new \InvalidArgumentException('DrizzlePlatform::getDropIndexSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.'); + } elseif (! is_string($table)) { + throw new InvalidArgumentException('DrizzlePlatform::getDropIndexSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.'); } if ($index instanceof Index && $index->isPrimary()) { @@ -451,7 +451,7 @@ protected function getDropPrimaryKeySQL($table) */ public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration) { - if (isset($fieldDeclaration['version']) && $fieldDeclaration['version'] == true) { + if (isset($fieldDeclaration['version']) && $fieldDeclaration['version'] === true) { return 'TIMESTAMP'; } @@ -479,7 +479,7 @@ public function getDateTypeDeclarationSQL(array $fieldDeclaration) */ public function getAlterTableSQL(TableDiff $diff) { - $columnSql = []; + $columnSql = []; $queryParts = []; if ($diff->newName !== false) { @@ -491,9 +491,9 @@ public function getAlterTableSQL(TableDiff $diff) continue; } - $columnArray = $column->toArray(); + $columnArray = $column->toArray(); $columnArray['comment'] = $this->getColumnComment($column); - $queryParts[] = 'ADD ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnArray); + $queryParts[] = 'ADD ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnArray); } foreach ($diff->removedColumns as $column) { @@ -509,8 +509,8 @@ public function getAlterTableSQL(TableDiff $diff) continue; } - /* @var $columnDiff \Doctrine\DBAL\Schema\ColumnDiff */ - $column = $columnDiff->column; + /** @var ColumnDiff $columnDiff */ + $column = $columnDiff->column; $columnArray = $column->toArray(); // Do not generate column alteration clause if type is binary and only fixed property has changed. @@ -524,7 +524,7 @@ public function getAlterTableSQL(TableDiff $diff) } $columnArray['comment'] = $this->getColumnComment($column); - $queryParts[] = 'CHANGE ' . ($columnDiff->getOldColumnName()->getQuotedName($this)) . ' ' + $queryParts[] = 'CHANGE ' . ($columnDiff->getOldColumnName()->getQuotedName($this)) . ' ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnArray); } @@ -535,18 +535,18 @@ public function getAlterTableSQL(TableDiff $diff) $oldColumnName = new Identifier($oldColumnName); - $columnArray = $column->toArray(); + $columnArray = $column->toArray(); $columnArray['comment'] = $this->getColumnComment($column); - $queryParts[] = 'CHANGE ' . $oldColumnName->getQuotedName($this) . ' ' + $queryParts[] = 'CHANGE ' . $oldColumnName->getQuotedName($this) . ' ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnArray); } - $sql = []; + $sql = []; $tableSql = []; - if ( ! $this->onSchemaAlterTable($diff, $tableSql)) { + if (! $this->onSchemaAlterTable($diff, $tableSql)) { if (count($queryParts) > 0) { - $sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ' . implode(", ", $queryParts); + $sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ' . implode(', ', $queryParts); } $sql = array_merge( $this->getPreAlterTableIndexForeignKeySQL($diff), @@ -565,8 +565,8 @@ public function getDropTemporaryTableSQL($table) { if ($table instanceof Table) { $table = $table->getQuotedName($this); - } elseif (!is_string($table)) { - throw new \InvalidArgumentException('getDropTableSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.'); + } elseif (! is_string($table)) { + throw new InvalidArgumentException('getDropTableSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.'); } return 'DROP TEMPORARY TABLE ' . $table; @@ -579,12 +579,14 @@ public function convertBooleans($item) { if (is_array($item)) { foreach ($item as $key => $value) { - if (is_bool($value) || is_numeric($item)) { - $item[$key] = ($value) ? 'true' : 'false'; + if (! is_bool($value) && ! is_numeric($item)) { + continue; } + + $item[$key] = $value ? 'true' : 'false'; } } elseif (is_bool($item) || is_numeric($item)) { - $item = ($item) ? 'true' : 'false'; + $item = $item ? 'true' : 'false'; } return $item; @@ -595,11 +597,11 @@ public function convertBooleans($item) */ public function getLocateExpression($str, $substr, $startPos = false) { - if ($startPos == false) { + if ($startPos === false) { return 'LOCATE(' . $substr . ', ' . $str . ')'; } - return 'LOCATE(' . $substr . ', ' . $str . ', '.$startPos.')'; + return 'LOCATE(' . $substr . ', ' . $str . ', ' . $startPos . ')'; } /** diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/DB2Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/DB2Keywords.php index 0dbceb3d537..d2c09878dda 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/DB2Keywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/DB2Keywords.php @@ -6,8 +6,6 @@ * DB2 Keywords. * * @link www.doctrine-project.org - * @since 2.0 - * @author Benjamin Eberlei */ class DB2Keywords extends KeywordList { diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/DrizzleKeywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/DrizzleKeywords.php index 0c121f784a7..70f69f44b0b 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/DrizzleKeywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/DrizzleKeywords.php @@ -4,8 +4,6 @@ /** * Drizzle Keywordlist. - * - * @author Kim Hemsø Rasmussen */ class DrizzleKeywords extends KeywordList { diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/KeywordList.php b/lib/Doctrine/DBAL/Platforms/Keywords/KeywordList.php index 66b69f32331..0135ff1a31f 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/KeywordList.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/KeywordList.php @@ -10,14 +10,10 @@ * Abstract interface for a SQL reserved keyword dictionary. * * @link www.doctrine-project.org - * @since 2.0 - * @author Benjamin Eberlei */ abstract class KeywordList { - /** - * @var array|null - */ + /** @var array|null */ private $keywords = null; /** diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/MariaDb102Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/MariaDb102Keywords.php index 6a9f19ed578..1b31c7682e7 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/MariaDb102Keywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/MariaDb102Keywords.php @@ -4,6 +4,7 @@ /** * MariaDb reserved keywords list. + * * @link https://mariadb.com/kb/en/the-mariadb-library/reserved-words/ */ final class MariaDb102Keywords extends MySQLKeywords diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/MsSQLKeywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/MsSQLKeywords.php index 239d047de77..5306b5b0d2b 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/MsSQLKeywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/MsSQLKeywords.php @@ -1,18 +1,13 @@ - * @author David Coallier - * @author Steve Müller * @deprecated Use SQLServerKeywords class instead. + * + * @link www.doctrine-project.com */ class MsSQLKeywords extends SQLServerKeywords { diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/MySQL57Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/MySQL57Keywords.php index 44a04e5d94a..da856d84ab0 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/MySQL57Keywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/MySQL57Keywords.php @@ -5,9 +5,7 @@ /** * MySQL 5.7 reserved keywords list. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ class MySQL57Keywords extends MySQLKeywords { diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/MySQLKeywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/MySQLKeywords.php index b6fd123b39d..dd80d647081 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/MySQLKeywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/MySQLKeywords.php @@ -6,9 +6,6 @@ * MySQL Keywordlist. * * @link www.doctrine-project.org - * @since 2.0 - * @author Benjamin Eberlei - * @author David Coallier */ class MySQLKeywords extends KeywordList { diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/OracleKeywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/OracleKeywords.php index cc1140a20d2..0441e99d72f 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/OracleKeywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/OracleKeywords.php @@ -6,9 +6,6 @@ * Oracle Keywordlist. * * @link www.doctrine-project.org - * @since 2.0 - * @author Benjamin Eberlei - * @author David Coallier */ class OracleKeywords extends KeywordList { diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL91Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL91Keywords.php index 3fe676e0bb4..9f7ccef1c7b 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL91Keywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL91Keywords.php @@ -5,10 +5,7 @@ /** * PostgreSQL 9.1 reserved keywords list. * - * @author Martin Hasoň - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ class PostgreSQL91Keywords extends PostgreSQLKeywords { diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL92Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL92Keywords.php index 5c20c95ef21..e7d197d9e0f 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL92Keywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL92Keywords.php @@ -7,9 +7,7 @@ /** * PostgreSQL 9.2 reserved keywords list. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ class PostgreSQL92Keywords extends PostgreSQL91Keywords { @@ -28,8 +26,6 @@ public function getName() */ protected function getKeywords() { - return array_merge(parent::getKeywords(), [ - 'COLLATION', - ]); + return array_merge(parent::getKeywords(), ['COLLATION']); } } diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL94Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL94Keywords.php index 4d7f1e25b02..eda90731fef 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL94Keywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL94Keywords.php @@ -8,9 +8,7 @@ /** * PostgreSQL 9.4 reserved keywords list. * - * @author Matteo Beccati * @link www.doctrine-project.org - * @since 2.6 */ class PostgreSQL94Keywords extends PostgreSQL92Keywords { @@ -29,12 +27,8 @@ public function getName() */ protected function getKeywords() { - $parentKeywords = array_diff(parent::getKeywords(), [ - 'OVER', - ]); + $parentKeywords = array_diff(parent::getKeywords(), ['OVER']); - return array_merge($parentKeywords, [ - 'LATERAL', - ]); + return array_merge($parentKeywords, ['LATERAL']); } } diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQLKeywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQLKeywords.php index 146e3a1ae10..0baabe87475 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQLKeywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQLKeywords.php @@ -6,9 +6,6 @@ * PostgreSQL Keywordlist. * * @link www.doctrine-project.org - * @since 2.0 - * @author Benjamin Eberlei - * @author Marcelo Santos Araujo */ class PostgreSQLKeywords extends KeywordList { @@ -112,7 +109,7 @@ protected function getKeywords() 'USING', 'VERBOSE', 'WHEN', - 'WHERE' + 'WHERE', ]; } } diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/ReservedKeywordsValidator.php b/lib/Doctrine/DBAL/Platforms/Keywords/ReservedKeywordsValidator.php index b8060967431..503765e267f 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/ReservedKeywordsValidator.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/ReservedKeywordsValidator.php @@ -2,30 +2,26 @@ namespace Doctrine\DBAL\Platforms\Keywords; -use Doctrine\DBAL\Schema\Visitor\Visitor; -use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ForeignKeyConstraint; +use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Sequence; -use Doctrine\DBAL\Schema\Index; +use Doctrine\DBAL\Schema\Table; +use Doctrine\DBAL\Schema\Visitor\Visitor; use function implode; use function str_replace; class ReservedKeywordsValidator implements Visitor { - /** - * @var KeywordList[] - */ + /** @var KeywordList[] */ private $keywordLists = []; - /** - * @var array - */ + /** @var array */ private $violations = []; /** - * @param \Doctrine\DBAL\Platforms\Keywords\KeywordList[] $keywordLists + * @param KeywordList[] $keywordLists */ public function __construct(array $keywordLists) { @@ -47,15 +43,17 @@ public function getViolations() */ private function isReservedWord($word) { - if ($word[0] == "`") { + if ($word[0] === '`') { $word = str_replace('`', '', $word); } $keywordLists = []; foreach ($this->keywordLists as $keywordList) { - if ($keywordList->isKeyword($word)) { - $keywordLists[] = $keywordList->getName(); + if (! $keywordList->isKeyword($word)) { + continue; } + + $keywordLists[] = $keywordList->getName(); } return $keywordLists; @@ -69,7 +67,7 @@ private function isReservedWord($word) */ private function addViolation($asset, $violatedPlatforms) { - if ( ! $violatedPlatforms) { + if (! $violatedPlatforms) { return; } diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/SQLAnywhere11Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/SQLAnywhere11Keywords.php index 6e769aabf20..09513c5770e 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/SQLAnywhere11Keywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/SQLAnywhere11Keywords.php @@ -7,8 +7,6 @@ /** * SAP Sybase SQL Anywhere 11 reserved keywords list. - * - * @author Steve Müller */ class SQLAnywhere11Keywords extends SQLAnywhereKeywords { @@ -34,7 +32,7 @@ protected function getKeywords() ), [ 'MERGE', - 'OPENSTRING' + 'OPENSTRING', ] ); } diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/SQLAnywhere12Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/SQLAnywhere12Keywords.php index a36608bf28d..489a83f7173 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/SQLAnywhere12Keywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/SQLAnywhere12Keywords.php @@ -7,8 +7,6 @@ /** * SAP Sybase SQL Anywhere 12 reserved keywords list. - * - * @author Steve Müller */ class SQLAnywhere12Keywords extends SQLAnywhere11Keywords { @@ -35,7 +33,7 @@ protected function getKeywords() 'SYNTAX_ERROR', 'WITH_CUBE', 'WITH_LPAREN', - 'WITH_ROLLUP' + 'WITH_ROLLUP', ] ), [ @@ -43,7 +41,7 @@ protected function getKeywords() 'LIMIT', 'OPENXML', 'SPATIAL', - 'TREAT' + 'TREAT', ] ); } diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/SQLAnywhere16Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/SQLAnywhere16Keywords.php index 44efb5ae8aa..fce19b41627 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/SQLAnywhere16Keywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/SQLAnywhere16Keywords.php @@ -6,8 +6,6 @@ /** * SAP Sybase SQL Anywhere 16 reserved keywords list. - * - * @author Steve Müller */ class SQLAnywhere16Keywords extends SQLAnywhere12Keywords { @@ -34,7 +32,7 @@ protected function getKeywords() 'ROW', 'ROWTYPE', 'UNNEST', - 'VARRAY' + 'VARRAY', ] ); } diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/SQLAnywhereKeywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/SQLAnywhereKeywords.php index 125f06d52d0..5223d4a9e43 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/SQLAnywhereKeywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/SQLAnywhereKeywords.php @@ -4,8 +4,6 @@ /** * SAP Sybase SQL Anywhere 10 reserved keywords list. - * - * @author Steve Müller */ class SQLAnywhereKeywords extends KeywordList { @@ -258,7 +256,7 @@ protected function getKeywords() 'WITHIN', 'WORK', 'WRITETEXT', - 'XML' + 'XML', ]; } } diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/SQLServer2005Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/SQLServer2005Keywords.php index 573280b0139..c4fc6c838ff 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/SQLServer2005Keywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/SQLServer2005Keywords.php @@ -8,10 +8,7 @@ /** * Microsoft SQL Server 2005 reserved keyword dictionary. * - * @license BSD http://www.opensource.org/licenses/bsd-license.php * @link www.doctrine-project.com - * @since 2.3 - * @author Steve Müller */ class SQLServer2005Keywords extends SQLServerKeywords { @@ -36,7 +33,7 @@ protected function getKeywords() 'REVERT', 'SECURITYAUDIT', 'TABLESAMPLE', - 'UNPIVOT' + 'UNPIVOT', ]); } } diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/SQLServer2008Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/SQLServer2008Keywords.php index acd19645e70..54a4e3a5fd5 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/SQLServer2008Keywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/SQLServer2008Keywords.php @@ -7,10 +7,7 @@ /** * Microsoft SQL Server 2008 reserved keyword dictionary. * - * @license BSD http://www.opensource.org/licenses/bsd-license.php * @link www.doctrine-project.com - * @since 2.3 - * @author Steve Müller */ class SQLServer2008Keywords extends SQLServer2005Keywords { @@ -29,8 +26,6 @@ public function getName() */ protected function getKeywords() { - return array_merge(parent::getKeywords(), [ - 'MERGE' - ]); + return array_merge(parent::getKeywords(), ['MERGE']); } } diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/SQLServer2012Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/SQLServer2012Keywords.php index 8334e3d3053..142e8a388d0 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/SQLServer2012Keywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/SQLServer2012Keywords.php @@ -7,10 +7,7 @@ /** * Microsoft SQL Server 2012 reserved keyword dictionary. * - * @license BSD http://www.opensource.org/licenses/bsd-license.php * @link www.doctrine-project.com - * @since 2.3 - * @author Steve Müller */ class SQLServer2012Keywords extends SQLServer2008Keywords { @@ -34,7 +31,7 @@ protected function getKeywords() 'SEMANTICSIMILARITYDETAILSTABLE', 'SEMANTICSIMILARITYTABLE', 'TRY_CONVERT', - 'WITHIN GROUP' + 'WITHIN GROUP', ]); } } diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/SQLServerKeywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/SQLServerKeywords.php index d7287fbf991..1e477309c16 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/SQLServerKeywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/SQLServerKeywords.php @@ -5,12 +5,7 @@ /** * Microsoft SQL Server 2000 reserved keyword dictionary. * - * @license BSD http://www.opensource.org/licenses/bsd-license.php * @link www.doctrine-project.com - * @since 2.0 - * @author Benjamin Eberlei - * @author David Coallier - * @author Steve Müller */ class SQLServerKeywords extends KeywordList { @@ -208,7 +203,7 @@ protected function getKeywords() 'WHERE', 'WHILE', 'WITH', - 'WRITETEXT' + 'WRITETEXT', ]; } } diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/SQLiteKeywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/SQLiteKeywords.php index 5d34e0c9111..343b5ed813f 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/SQLiteKeywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/SQLiteKeywords.php @@ -6,8 +6,6 @@ * SQLite Keywordlist. * * @link www.doctrine-project.org - * @since 2.0 - * @author Benjamin Eberlei */ class SQLiteKeywords extends KeywordList { @@ -145,7 +143,7 @@ protected function getKeywords() 'VIEW', 'VIRTUAL', 'WHEN', - 'WHERE' + 'WHERE', ]; } } diff --git a/lib/Doctrine/DBAL/Platforms/MariaDb1027Platform.php b/lib/Doctrine/DBAL/Platforms/MariaDb1027Platform.php index 6aba377674e..9489c127b74 100644 --- a/lib/Doctrine/DBAL/Platforms/MariaDb1027Platform.php +++ b/lib/Doctrine/DBAL/Platforms/MariaDb1027Platform.php @@ -9,7 +9,6 @@ * * Note: Should not be used with versions prior to 10.2.7. * - * @author Vanvelthem Sébastien * @link www.doctrine-project.org */ final class MariaDb1027Platform extends MySqlPlatform diff --git a/lib/Doctrine/DBAL/Platforms/MySQL57Platform.php b/lib/Doctrine/DBAL/Platforms/MySQL57Platform.php index e2c6fc3d937..1d0dbfc3caa 100644 --- a/lib/Doctrine/DBAL/Platforms/MySQL57Platform.php +++ b/lib/Doctrine/DBAL/Platforms/MySQL57Platform.php @@ -9,10 +9,7 @@ /** * Provides the behavior, features and SQL dialect of the MySQL 5.7 (5.7.9 GA) database platform. * - * @author İsmail BASKIN - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ class MySQL57Platform extends MySqlPlatform { @@ -53,9 +50,7 @@ protected function getPostAlterTableRenameIndexForeignKeySQL(TableDiff $diff) */ protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName) { - return [ - 'ALTER TABLE ' . $tableName . ' RENAME INDEX ' . $oldIndexName . ' TO ' . $index->getQuotedName($this) - ]; + return ['ALTER TABLE ' . $tableName . ' RENAME INDEX ' . $oldIndexName . ' TO ' . $index->getQuotedName($this)]; } /** diff --git a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php index 149d2eaef3c..edbae0fc536 100644 --- a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php @@ -2,6 +2,8 @@ namespace Doctrine\DBAL\Platforms; +use Doctrine\DBAL\Schema\ColumnDiff; +use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\Identifier; use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\Table; @@ -9,6 +11,7 @@ use Doctrine\DBAL\TransactionIsolationLevel; use Doctrine\DBAL\Types\BlobType; use Doctrine\DBAL\Types\TextType; +use InvalidArgumentException; use function array_diff_key; use function array_merge; use function array_unique; @@ -30,20 +33,17 @@ * MySQL database platform. This platform represents a MySQL 5.0 or greater platform that * uses the InnoDB storage engine. * - * @since 2.0 - * @author Roman Borschel - * @author Benjamin Eberlei * @todo Rename: MySQLPlatform */ class MySqlPlatform extends AbstractPlatform { - const LENGTH_LIMIT_TINYTEXT = 255; - const LENGTH_LIMIT_TEXT = 65535; - const LENGTH_LIMIT_MEDIUMTEXT = 16777215; + public const LENGTH_LIMIT_TINYTEXT = 255; + public const LENGTH_LIMIT_TEXT = 65535; + public const LENGTH_LIMIT_MEDIUMTEXT = 16777215; - const LENGTH_LIMIT_TINYBLOB = 255; - const LENGTH_LIMIT_BLOB = 65535; - const LENGTH_LIMIT_MEDIUMBLOB = 16777215; + public const LENGTH_LIMIT_TINYBLOB = 255; + public const LENGTH_LIMIT_BLOB = 65535; + public const LENGTH_LIMIT_MEDIUMBLOB = 16777215; /** * {@inheritDoc} @@ -95,11 +95,11 @@ public function getGuidExpression() */ public function getLocateExpression($str, $substr, $startPos = false) { - if ($startPos == false) { + if ($startPos === false) { return 'LOCATE(' . $substr . ', ' . $str . ')'; } - return 'LOCATE(' . $substr . ', ' . $str . ', '.$startPos.')'; + return 'LOCATE(' . $substr . ', ' . $str . ', ' . $startPos . ')'; } /** @@ -117,7 +117,7 @@ public function getConcatExpression() */ protected function getDateArithmeticIntervalExpression($date, $operator, $interval, $unit) { - $function = '+' === $operator ? 'DATE_ADD' : 'DATE_SUB'; + $function = $operator === '+' ? 'DATE_ADD' : 'DATE_SUB'; return $function . '(' . $date . ', INTERVAL ' . $interval . ' ' . $unit . ')'; } @@ -156,13 +156,13 @@ public function getListTableIndexesSQL($table, $currentDatabase = null) { if ($currentDatabase) { $currentDatabase = $this->quoteStringLiteral($currentDatabase); - $table = $this->quoteStringLiteral($table); + $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 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 'SHOW INDEX FROM ' . $table; @@ -175,7 +175,7 @@ public function getListViewsSQL($database) { $database = $this->quoteStringLiteral($database); - return "SELECT * FROM information_schema.VIEWS WHERE TABLE_SCHEMA = " . $database; + return 'SELECT * FROM information_schema.VIEWS WHERE TABLE_SCHEMA = ' . $database; } /** @@ -185,21 +185,21 @@ public function getListTableForeignKeysSQL($table, $database = null) { $table = $this->quoteStringLiteral($table); - if (null !== $database) { + if ($database !== null) { $database = $this->quoteStringLiteral($database); } - $sql = "SELECT DISTINCT k.`CONSTRAINT_NAME`, k.`COLUMN_NAME`, k.`REFERENCED_TABLE_NAME`, ". - "k.`REFERENCED_COLUMN_NAME` /*!50116 , c.update_rule, c.delete_rule */ ". - "FROM information_schema.key_column_usage k /*!50116 ". - "INNER JOIN information_schema.referential_constraints c ON ". - " c.constraint_name = k.constraint_name AND ". + $sql = 'SELECT DISTINCT k.`CONSTRAINT_NAME`, k.`COLUMN_NAME`, k.`REFERENCED_TABLE_NAME`, ' . + 'k.`REFERENCED_COLUMN_NAME` /*!50116 , c.update_rule, c.delete_rule */ ' . + 'FROM information_schema.key_column_usage k /*!50116 ' . + 'INNER JOIN information_schema.referential_constraints c ON ' . + ' c.constraint_name = k.constraint_name AND ' . " c.table_name = $table */ WHERE k.table_name = $table"; $databaseNameSql = $database ?? 'DATABASE()'; $sql .= " AND k.table_schema = $databaseNameSql /*!50116 AND c.constraint_schema = $databaseNameSql */"; - $sql .= " AND k.`REFERENCED_COLUMN_NAME` is not NULL"; + $sql .= ' AND k.`REFERENCED_COLUMN_NAME` is not NULL'; return $sql; } @@ -217,7 +217,7 @@ public function getCreateViewSQL($name, $sql) */ public function getDropViewSQL($name) { - return 'DROP VIEW '. $name; + return 'DROP VIEW ' . $name; } /** @@ -250,7 +250,7 @@ protected function getBinaryTypeDeclarationSQLSnippet($length, $fixed) */ public function getClobTypeDeclarationSQL(array $field) { - if ( ! empty($field['length']) && is_numeric($field['length'])) { + if (! empty($field['length']) && is_numeric($field['length'])) { $length = $field['length']; if ($length <= static::LENGTH_LIMIT_TINYTEXT) { @@ -274,7 +274,7 @@ public function getClobTypeDeclarationSQL(array $field) */ public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration) { - if (isset($fieldDeclaration['version']) && $fieldDeclaration['version'] == true) { + if (isset($fieldDeclaration['version']) && $fieldDeclaration['version'] === true) { return 'TIMESTAMP'; } @@ -379,10 +379,10 @@ public function getListTableColumnsSQL($table, $database = null) $database = 'DATABASE()'; } - return "SELECT COLUMN_NAME AS Field, COLUMN_TYPE AS Type, IS_NULLABLE AS `Null`, ". - "COLUMN_KEY AS `Key`, COLUMN_DEFAULT AS `Default`, EXTRA AS Extra, COLUMN_COMMENT AS Comment, " . - "CHARACTER_SET_NAME AS CharacterSet, COLLATION_NAME AS Collation ". - "FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = " . $database . " AND TABLE_NAME = " . $table; + return 'SELECT COLUMN_NAME AS Field, COLUMN_TYPE AS Type, IS_NULLABLE AS `Null`, ' . + 'COLUMN_KEY AS `Key`, COLUMN_DEFAULT AS `Default`, EXTRA AS Extra, COLUMN_COMMENT AS Comment, ' . + 'CHARACTER_SET_NAME AS CharacterSet, COLLATION_NAME AS Collation ' . + 'FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = ' . $database . ' AND TABLE_NAME = ' . $table; } /** @@ -423,13 +423,13 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options // attach all primary keys if (isset($options['primary']) && ! empty($options['primary'])) { - $keyColumns = array_unique(array_values($options['primary'])); + $keyColumns = array_unique(array_values($options['primary'])); $queryFields .= ', PRIMARY KEY(' . implode(', ', $keyColumns) . ')'; } $query = 'CREATE '; - if (!empty($options['temporary'])) { + if (! empty($options['temporary'])) { $query .= 'TEMPORARY '; } @@ -483,21 +483,21 @@ private function buildTableOptions(array $options) $tableOptions = []; // Charset - if ( ! isset($options['charset'])) { + if (! isset($options['charset'])) { $options['charset'] = 'utf8'; } $tableOptions[] = sprintf('DEFAULT CHARACTER SET %s', $options['charset']); // Collate - if ( ! isset($options['collate'])) { + if (! isset($options['collate'])) { $options['collate'] = $options['charset'] . '_unicode_ci'; } $tableOptions[] = sprintf('COLLATE %s', $options['collate']); // Engine - if ( ! isset($options['engine'])) { + if (! isset($options['engine'])) { $options['engine'] = 'InnoDB'; } @@ -512,7 +512,7 @@ private function buildTableOptions(array $options) if (isset($options['comment'])) { $comment = trim($options['comment'], " '"); - $tableOptions[] = sprintf("COMMENT = %s ", $this->quoteStringLiteral($comment)); + $tableOptions[] = sprintf('COMMENT = %s ', $this->quoteStringLiteral($comment)); } // Row format @@ -532,7 +532,7 @@ private function buildTableOptions(array $options) */ private function buildPartitionOptions(array $options) { - return (isset($options['partition_options'])) + return isset($options['partition_options']) ? ' ' . $options['partition_options'] : ''; } @@ -542,7 +542,7 @@ private function buildPartitionOptions(array $options) */ public function getAlterTableSQL(TableDiff $diff) { - $columnSql = []; + $columnSql = []; $queryParts = []; if ($diff->newName !== false) { $queryParts[] = 'RENAME TO ' . $diff->getNewName()->getQuotedName($this); @@ -553,9 +553,9 @@ public function getAlterTableSQL(TableDiff $diff) continue; } - $columnArray = $column->toArray(); + $columnArray = $column->toArray(); $columnArray['comment'] = $this->getColumnComment($column); - $queryParts[] = 'ADD ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnArray); + $queryParts[] = 'ADD ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnArray); } foreach ($diff->removedColumns as $column) { @@ -571,8 +571,8 @@ public function getAlterTableSQL(TableDiff $diff) continue; } - /* @var $columnDiff \Doctrine\DBAL\Schema\ColumnDiff */ - $column = $columnDiff->column; + /** @var ColumnDiff $columnDiff */ + $column = $columnDiff->column; $columnArray = $column->toArray(); // Don't propagate default value changes for unsupported column types. @@ -584,7 +584,7 @@ public function getAlterTableSQL(TableDiff $diff) } $columnArray['comment'] = $this->getColumnComment($column); - $queryParts[] = 'CHANGE ' . ($columnDiff->getOldColumnName()->getQuotedName($this)) . ' ' + $queryParts[] = 'CHANGE ' . ($columnDiff->getOldColumnName()->getQuotedName($this)) . ' ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnArray); } @@ -593,25 +593,25 @@ public function getAlterTableSQL(TableDiff $diff) continue; } - $oldColumnName = new Identifier($oldColumnName); - $columnArray = $column->toArray(); + $oldColumnName = new Identifier($oldColumnName); + $columnArray = $column->toArray(); $columnArray['comment'] = $this->getColumnComment($column); - $queryParts[] = 'CHANGE ' . $oldColumnName->getQuotedName($this) . ' ' + $queryParts[] = 'CHANGE ' . $oldColumnName->getQuotedName($this) . ' ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnArray); } if (isset($diff->addedIndexes['primary'])) { - $keyColumns = array_unique(array_values($diff->addedIndexes['primary']->getColumns())); + $keyColumns = array_unique(array_values($diff->addedIndexes['primary']->getColumns())); $queryParts[] = 'ADD PRIMARY KEY (' . implode(', ', $keyColumns) . ')'; unset($diff->addedIndexes['primary']); } - $sql = []; + $sql = []; $tableSql = []; - if ( ! $this->onSchemaAlterTable($diff, $tableSql)) { + if (! $this->onSchemaAlterTable($diff, $tableSql)) { if (count($queryParts) > 0) { - $sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ' . implode(", ", $queryParts); + $sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ' . implode(', ', $queryParts); } $sql = array_merge( $this->getPreAlterTableIndexForeignKeySQL($diff), @@ -628,7 +628,7 @@ public function getAlterTableSQL(TableDiff $diff) */ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) { - $sql = []; + $sql = []; $table = $diff->getName($this)->getQuotedName($this); foreach ($diff->changedIndexes as $changedIndex) { @@ -639,8 +639,7 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) $sql = array_merge($sql, $this->getPreAlterTableAlterPrimaryKeySQL($diff, $remIndex)); foreach ($diff->addedIndexes as $addKey => $addIndex) { - if ($remIndex->getColumns() == $addIndex->getColumns()) { - + if ($remIndex->getColumns() === $addIndex->getColumns()) { $indexClause = 'INDEX ' . $addIndex->getName(); if ($addIndex->isPrimary()) { @@ -649,7 +648,7 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) $indexClause = 'UNIQUE INDEX ' . $addIndex->getName(); } - $query = 'ALTER TABLE ' . $table . ' DROP INDEX ' . $remIndex->getName() . ', '; + $query = 'ALTER TABLE ' . $table . ' DROP INDEX ' . $remIndex->getName() . ', '; $query .= 'ADD ' . $indexClause; $query .= ' (' . $this->getIndexFieldDeclarationListSQL($addIndex->getQuotedColumns($this)) . ')'; @@ -669,7 +668,7 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) } // Suppress foreign key constraint propagation on non-supporting engines. - if ('INNODB' !== $engine) { + if ($engine !== 'INNODB') { $diff->addedForeignKeys = []; $diff->changedForeignKeys = []; $diff->removedForeignKeys = []; @@ -686,9 +685,6 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) } /** - * @param TableDiff $diff - * @param Index $index - * * @return string[] */ private function getPreAlterTableAlterPrimaryKeySQL(TableDiff $diff, Index $index) @@ -709,15 +705,17 @@ private function getPreAlterTableAlterPrimaryKeySQL(TableDiff $diff, Index $inde $column = $diff->fromTable->getColumn($columnName); - if ($column->getAutoincrement() === true) { - $column->setAutoincrement(false); + if ($column->getAutoincrement() !== true) { + continue; + } - $sql[] = 'ALTER TABLE ' . $tableName . ' MODIFY ' . - $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray()); + $column->setAutoincrement(false); - // original autoincrement information might be needed later on by other parts of the table alteration - $column->setAutoincrement(true); - } + $sql[] = 'ALTER TABLE ' . $tableName . ' MODIFY ' . + $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray()); + + // original autoincrement information might be needed later on by other parts of the table alteration + $column->setAutoincrement(true); } return $sql; @@ -730,29 +728,33 @@ private function getPreAlterTableAlterPrimaryKeySQL(TableDiff $diff, Index $inde */ private function getPreAlterTableAlterIndexForeignKeySQL(TableDiff $diff) { - $sql = []; + $sql = []; $table = $diff->getName($this)->getQuotedName($this); foreach ($diff->changedIndexes as $changedIndex) { // Changed primary key - if ($changedIndex->isPrimary() && $diff->fromTable instanceof Table) { - foreach ($diff->fromTable->getPrimaryKeyColumns() as $columnName) { - $column = $diff->fromTable->getColumn($columnName); - - // Check if an autoincrement column was dropped from the primary key. - if ($column->getAutoincrement() && ! in_array($columnName, $changedIndex->getColumns())) { - // The autoincrement attribute needs to be removed from the dropped column - // before we can drop and recreate the primary key. - $column->setAutoincrement(false); - - $sql[] = 'ALTER TABLE ' . $table . ' MODIFY ' . - $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray()); - - // Restore the autoincrement attribute as it might be needed later on - // by other parts of the table alteration. - $column->setAutoincrement(true); - } + if (! $changedIndex->isPrimary() || ! ($diff->fromTable instanceof Table)) { + continue; + } + + foreach ($diff->fromTable->getPrimaryKeyColumns() as $columnName) { + $column = $diff->fromTable->getColumn($columnName); + + // Check if an autoincrement column was dropped from the primary key. + if (! $column->getAutoincrement() || in_array($columnName, $changedIndex->getColumns())) { + continue; } + + // The autoincrement attribute needs to be removed from the dropped column + // before we can drop and recreate the primary key. + $column->setAutoincrement(false); + + $sql[] = 'ALTER TABLE ' . $table . ' MODIFY ' . + $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray()); + + // Restore the autoincrement attribute as it might be needed later on + // by other parts of the table alteration. + $column->setAutoincrement(true); } } @@ -766,13 +768,15 @@ private function getPreAlterTableAlterIndexForeignKeySQL(TableDiff $diff) */ protected function getPreAlterTableRenameIndexForeignKeySQL(TableDiff $diff) { - $sql = []; + $sql = []; $tableName = $diff->getName($this)->getQuotedName($this); foreach ($this->getRemainingForeignKeyConstraintsRequiringRenamedIndexes($diff) as $foreignKey) { - if (! in_array($foreignKey, $diff->changedForeignKeys, true)) { - $sql[] = $this->getDropForeignKeySQL($foreignKey, $tableName); + if (in_array($foreignKey, $diff->changedForeignKeys, true)) { + continue; } + + $sql[] = $this->getDropForeignKeySQL($foreignKey, $tableName); } return $sql; @@ -795,7 +799,7 @@ private function getRemainingForeignKeyConstraintsRequiringRenamedIndexes(TableD } $foreignKeys = []; - /** @var \Doctrine\DBAL\Schema\ForeignKeyConstraint[] $remainingForeignKeys */ + /** @var ForeignKeyConstraint[] $remainingForeignKeys */ $remainingForeignKeys = array_diff_key( $diff->fromTable->getForeignKeys(), $diff->removedForeignKeys @@ -832,15 +836,17 @@ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff) */ protected function getPostAlterTableRenameIndexForeignKeySQL(TableDiff $diff) { - $sql = []; - $tableName = (false !== $diff->newName) + $sql = []; + $tableName = $diff->newName !== false ? $diff->getNewName()->getQuotedName($this) : $diff->getName($this)->getQuotedName($this); foreach ($this->getRemainingForeignKeyConstraintsRequiringRenamedIndexes($diff) as $foreignKey) { - if (! in_array($foreignKey, $diff->changedForeignKeys, true)) { - $sql[] = $this->getCreateForeignKeySQL($foreignKey, $tableName); + if (in_array($foreignKey, $diff->changedForeignKeys, true)) { + continue; } + + $sql[] = $this->getCreateForeignKeySQL($foreignKey, $tableName); } return $sql; @@ -921,7 +927,7 @@ private function getUnsignedDeclaration(array $columnDef) protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) { $autoinc = ''; - if ( ! empty($columnDef['autoincrement'])) { + if (! empty($columnDef['autoincrement'])) { $autoinc = ' AUTO_INCREMENT'; } @@ -931,7 +937,7 @@ protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) /** * {@inheritDoc} */ - public function getAdvancedForeignKeyOptionsSQL(\Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey) + public function getAdvancedForeignKeyOptionsSQL(ForeignKeyConstraint $foreignKey) { $query = ''; if ($foreignKey->hasOption('match')) { @@ -945,20 +951,20 @@ public function getAdvancedForeignKeyOptionsSQL(\Doctrine\DBAL\Schema\ForeignKey /** * {@inheritDoc} */ - public function getDropIndexSQL($index, $table=null) + public function getDropIndexSQL($index, $table = null) { if ($index instanceof Index) { $indexName = $index->getQuotedName($this); } elseif (is_string($index)) { $indexName = $index; } else { - throw new \InvalidArgumentException('MysqlPlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.'); + throw new InvalidArgumentException('MysqlPlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.'); } if ($table instanceof Table) { $table = $table->getQuotedName($this); - } elseif (!is_string($table)) { - throw new \InvalidArgumentException('MysqlPlatform::getDropIndexSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.'); + } elseif (! is_string($table)) { + throw new InvalidArgumentException('MysqlPlatform::getDropIndexSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.'); } if ($index instanceof Index && $index->isPrimary()) { @@ -1077,8 +1083,8 @@ public function getDropTemporaryTableSQL($table) { if ($table instanceof Table) { $table = $table->getQuotedName($this); - } elseif (!is_string($table)) { - throw new \InvalidArgumentException('getDropTemporaryTableSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.'); + } elseif (! is_string($table)) { + throw new InvalidArgumentException('getDropTemporaryTableSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.'); } return 'DROP TEMPORARY TABLE ' . $table; @@ -1097,7 +1103,7 @@ public function getDropTemporaryTableSQL($table) */ public function getBlobTypeDeclarationSQL(array $field) { - if ( ! empty($field['length']) && is_numeric($field['length'])) { + if (! empty($field['length']) && is_numeric($field['length'])) { $length = $field['length']; if ($length <= static::LENGTH_LIMIT_TINYBLOB) { diff --git a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php index 8e1358606ef..4976511b4d7 100644 --- a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php @@ -3,6 +3,7 @@ namespace Doctrine\DBAL\Platforms; use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Schema\ColumnDiff; use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\Identifier; use Doctrine\DBAL\Schema\Index; @@ -11,6 +12,7 @@ use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\TransactionIsolationLevel; use Doctrine\DBAL\Types\BinaryType; +use InvalidArgumentException; use function array_merge; use function count; use function explode; @@ -27,11 +29,6 @@ /** * OraclePlatform. - * - * @since 2.0 - * @author Roman Borschel - * @author Lukas Smith (PEAR MDB2 library) - * @author Benjamin Eberlei */ class OraclePlatform extends AbstractPlatform { @@ -46,8 +43,8 @@ class OraclePlatform extends AbstractPlatform */ public static function assertValidIdentifier($identifier) { - if ( ! preg_match('(^(([a-zA-Z]{1}[a-zA-Z0-9_$#]{0,})|("[^"]+"))$)', $identifier)) { - throw new DBALException("Invalid Oracle identifier"); + if (! preg_match('(^(([a-zA-Z]{1}[a-zA-Z0-9_$#]{0,})|("[^"]+"))$)', $identifier)) { + throw new DBALException('Invalid Oracle identifier'); } } @@ -82,11 +79,11 @@ public function getNowExpression($type = 'timestamp') */ public function getLocateExpression($str, $substr, $startPos = false) { - if ($startPos == false) { - return 'INSTR('.$str.', '.$substr.')'; + if ($startPos === false) { + return 'INSTR(' . $str . ', ' . $substr . ')'; } - return 'INSTR('.$str.', '.$substr.', '.$startPos.')'; + return 'INSTR(' . $str . ', ' . $substr . ', ' . $startPos . ')'; } /** @@ -158,7 +155,7 @@ public function getDateDiffExpression($date1, $date2) */ public function getBitAndComparisonExpression($value1, $value2) { - return 'BITAND('.$value1 . ', ' . $value2 . ')'; + return 'BITAND(' . $value1 . ', ' . $value2 . ')'; } /** @@ -200,17 +197,15 @@ public function getAlterSequenceSQL(Sequence $sequence) /** * Cache definition for sequences * - * @param Sequence $sequence - * * @return string */ private function getSequenceCacheSQL(Sequence $sequence) { if ($sequence->getCache() === 0) { return ' NOCACHE'; - } else if ($sequence->getCache() === 1) { + } elseif ($sequence->getCache() === 1) { return ' NOCACHE'; - } else if ($sequence->getCache() > 1) { + } elseif ($sequence->getCache() > 1) { return ' CACHE ' . $sequence->getCache(); } @@ -372,8 +367,8 @@ public function getListSequencesSQL($database) $database = $this->normalizeIdentifier($database); $database = $this->quoteStringLiteral($database->getName()); - return "SELECT sequence_name, min_value, increment_by FROM sys.all_sequences ". - "WHERE SEQUENCE_OWNER = " . $database; + return 'SELECT sequence_name, min_value, increment_by FROM sys.all_sequences ' . + 'WHERE SEQUENCE_OWNER = ' . $database; } /** @@ -390,10 +385,12 @@ protected function _getCreateTableSQL($table, array $columns, array $options = [ $sql[] = $this->getCreateSequenceSQL($column['sequence']); } - if (isset($column['autoincrement']) && $column['autoincrement'] || - (isset($column['autoinc']) && $column['autoinc'])) { - $sql = array_merge($sql, $this->getCreateAutoincrementSql($name, $table)); + if (! isset($column['autoincrement']) || ! $column['autoincrement'] && + (! isset($column['autoinc']) || ! $column['autoinc'])) { + continue; } + + $sql = array_merge($sql, $this->getCreateAutoincrementSql($name, $table)); } if (isset($indexes) && ! empty($indexes)) { @@ -408,7 +405,6 @@ protected function _getCreateTableSQL($table, array $columns, array $options = [ /** * {@inheritDoc} * - * @license New BSD License * @link http://ezcomponents.org/docs/api/trunk/DatabaseSchema/ezcDbSchemaOracleReader.html */ public function getListTableIndexesSQL($table, $currentDatabase = null) @@ -441,8 +437,8 @@ public function getListTableIndexesSQL($table, $currentDatabase = null) WHERE ucon.index_name = uind_col.index_name ) AS is_primary FROM user_ind_columns uind_col - WHERE uind_col.table_name = " . $table . " - ORDER BY uind_col.column_position ASC"; + WHERE uind_col.table_name = " . $table . ' + ORDER BY uind_col.column_position ASC'; } /** @@ -474,7 +470,7 @@ public function getCreateViewSQL($name, $sql) */ public function getDropViewSQL($name) { - return 'DROP VIEW '. $name; + return 'DROP VIEW ' . $name; } /** @@ -486,13 +482,13 @@ public function getDropViewSQL($name) */ public function getCreateAutoincrementSql($name, $table, $start = 1) { - $tableIdentifier = $this->normalizeIdentifier($table); - $quotedTableName = $tableIdentifier->getQuotedName($this); + $tableIdentifier = $this->normalizeIdentifier($table); + $quotedTableName = $tableIdentifier->getQuotedName($this); $unquotedTableName = $tableIdentifier->getName(); $nameIdentifier = $this->normalizeIdentifier($name); - $quotedName = $nameIdentifier->getQuotedName($this); - $unquotedName = $nameIdentifier->getName(); + $quotedName = $nameIdentifier->getQuotedName($this); + $unquotedName = $nameIdentifier->getName(); $sql = []; @@ -505,7 +501,7 @@ public function getCreateAutoincrementSql($name, $table, $start = 1) BEGIN SELECT COUNT(CONSTRAINT_NAME) INTO constraints_Count FROM USER_CONSTRAINTS WHERE TABLE_NAME = \'' . $unquotedTableName . '\' AND CONSTRAINT_TYPE = \'P\'; IF constraints_Count = 0 OR constraints_Count = \'\' THEN - EXECUTE IMMEDIATE \''.$this->getCreateConstraintSQL($idx, $quotedTableName).'\'; + EXECUTE IMMEDIATE \'' . $this->getCreateConstraintSQL($idx, $quotedTableName) . '\'; END IF; END;'; @@ -513,8 +509,8 @@ public function getCreateAutoincrementSql($name, $table, $start = 1) $tableIdentifier->isQuoted() ? $quotedTableName : $unquotedTableName, $nameIdentifier->isQuoted() ? $quotedName : $unquotedName ); - $sequence = new Sequence($sequenceName, $start); - $sql[] = $this->getCreateSequenceSQL($sequence); + $sequence = new Sequence($sequenceName, $start); + $sql[] = $this->getCreateSequenceSQL($sequence); $sql[] = 'CREATE TRIGGER ' . $autoincrementIdentifierName . ' BEFORE INSERT @@ -525,7 +521,7 @@ public function getCreateAutoincrementSql($name, $table, $start = 1) last_InsertID NUMBER; BEGIN SELECT ' . $sequenceName . '.NEXTVAL INTO :NEW.' . $quotedName . ' FROM DUAL; - IF (:NEW.' . $quotedName . ' IS NULL OR :NEW.'.$quotedName.' = 0) THEN + IF (:NEW.' . $quotedName . ' IS NULL OR :NEW.' . $quotedName . ' = 0) THEN SELECT ' . $sequenceName . '.NEXTVAL INTO :NEW.' . $quotedName . ' FROM DUAL; ELSE SELECT NVL(Last_Number, 0) INTO last_Sequence @@ -550,9 +546,9 @@ public function getCreateAutoincrementSql($name, $table, $start = 1) */ public function getDropAutoincrementSql($table) { - $table = $this->normalizeIdentifier($table); + $table = $this->normalizeIdentifier($table); $autoincrementIdentifierName = $this->getAutoincrementIdentifierName($table); - $identitySequenceName = $this->getIdentitySequenceName( + $identitySequenceName = $this->getIdentitySequenceName( $table->isQuoted() ? $table->getQuotedName($this) : $table->getName(), '' ); @@ -628,8 +624,8 @@ public function getListTableForeignKeysSQL($table) JOIN user_constraints alc ON alc.constraint_name = cols.constraint_name AND alc.constraint_type = 'R' - AND alc.table_name = " . $table . " - ORDER BY cols.constraint_name ASC, cols.position ASC"; + AND alc.table_name = " . $table . ' + ORDER BY cols.constraint_name ASC, cols.position ASC'; } /** @@ -640,7 +636,7 @@ public function getListTableConstraintsSQL($table) $table = $this->normalizeIdentifier($table); $table = $this->quoteStringLiteral($table->getName()); - return "SELECT * FROM user_constraints WHERE table_name = " . $table; + return 'SELECT * FROM user_constraints WHERE table_name = ' . $table; } /** @@ -651,18 +647,18 @@ public function getListTableColumnsSQL($table, $database = null) $table = $this->normalizeIdentifier($table); $table = $this->quoteStringLiteral($table->getName()); - $tabColumnsTableName = "user_tab_columns"; - $colCommentsTableName = "user_col_comments"; - $tabColumnsOwnerCondition = ''; + $tabColumnsTableName = 'user_tab_columns'; + $colCommentsTableName = 'user_col_comments'; + $tabColumnsOwnerCondition = ''; $colCommentsOwnerCondition = ''; - if (null !== $database && '/' !== $database) { - $database = $this->normalizeIdentifier($database); - $database = $this->quoteStringLiteral($database->getName()); - $tabColumnsTableName = "all_tab_columns"; - $colCommentsTableName = "all_col_comments"; - $tabColumnsOwnerCondition = "AND c.owner = " . $database; - $colCommentsOwnerCondition = "AND d.OWNER = c.OWNER"; + if ($database !== null && $database !== '/') { + $database = $this->normalizeIdentifier($database); + $database = $this->quoteStringLiteral($database->getName()); + $tabColumnsTableName = 'all_tab_columns'; + $colCommentsTableName = 'all_col_comments'; + $tabColumnsOwnerCondition = 'AND c.owner = ' . $database; + $colCommentsOwnerCondition = 'AND d.OWNER = c.OWNER'; } return "SELECT c.*, @@ -703,7 +699,7 @@ public function getDropForeignKeySQL($foreignKey, $table) } $foreignKey = $foreignKey->getQuotedName($this); - $table = $table->getQuotedName($this); + $table = $table->getQuotedName($this); return 'ALTER TABLE ' . $table . ' DROP CONSTRAINT ' . $foreignKey; } @@ -742,7 +738,7 @@ public function getForeignKeyReferentialActionSQL($action) default: // SET DEFAULT is not supported, throw exception instead. - throw new \InvalidArgumentException('Invalid foreign key action: ' . $action); + throw new InvalidArgumentException('Invalid foreign key action: ' . $action); } } @@ -759,9 +755,9 @@ public function getDropDatabaseSQL($database) */ public function getAlterTableSQL(TableDiff $diff) { - $sql = []; + $sql = []; $commentsSQL = []; - $columnSql = []; + $columnSql = []; $fields = []; @@ -771,13 +767,15 @@ public function getAlterTableSQL(TableDiff $diff) } $fields[] = $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray()); - if ($comment = $this->getColumnComment($column)) { - $commentsSQL[] = $this->getCommentOnColumnSQL( - $diff->getName($this)->getQuotedName($this), - $column->getQuotedName($this), - $comment - ); + if (! $comment = $this->getColumnComment($column)) { + continue; } + + $commentsSQL[] = $this->getCommentOnColumnSQL( + $diff->getName($this)->getQuotedName($this), + $column->getQuotedName($this), + $comment + ); } if (count($fields)) { @@ -790,7 +788,7 @@ public function getAlterTableSQL(TableDiff $diff) continue; } - /* @var $columnDiff \Doctrine\DBAL\Schema\ColumnDiff */ + /** @var ColumnDiff $columnDiff */ $column = $columnDiff->column; // Do not generate column alteration clause if type is binary and only fixed property has changed. @@ -808,23 +806,25 @@ public function getAlterTableSQL(TableDiff $diff) /** * Do not add query part if only comment has changed */ - if ( ! ($columnHasChangedComment && count($columnDiff->changedProperties) === 1)) { + if (! ($columnHasChangedComment && count($columnDiff->changedProperties) === 1)) { $columnInfo = $column->toArray(); - if ( ! $columnDiff->hasChanged('notnull')) { + if (! $columnDiff->hasChanged('notnull')) { unset($columnInfo['notnull']); } $fields[] = $column->getQuotedName($this) . $this->getColumnDeclarationSQL('', $columnInfo); } - if ($columnHasChangedComment) { - $commentsSQL[] = $this->getCommentOnColumnSQL( - $diff->getName($this)->getQuotedName($this), - $column->getQuotedName($this), - $this->getColumnComment($column) - ); + if (! $columnHasChangedComment) { + continue; } + + $commentsSQL[] = $this->getCommentOnColumnSQL( + $diff->getName($this)->getQuotedName($this), + $column->getQuotedName($this), + $this->getColumnComment($column) + ); } if (count($fields)) { @@ -839,7 +839,7 @@ public function getAlterTableSQL(TableDiff $diff) $oldColumnName = new Identifier($oldColumnName); $sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . - ' RENAME COLUMN ' . $oldColumnName->getQuotedName($this) .' TO ' . $column->getQuotedName($this); + ' RENAME COLUMN ' . $oldColumnName->getQuotedName($this) . ' TO ' . $column->getQuotedName($this); } $fields = []; @@ -852,12 +852,12 @@ public function getAlterTableSQL(TableDiff $diff) } if (count($fields)) { - $sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' DROP (' . implode(', ', $fields).')'; + $sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' DROP (' . implode(', ', $fields) . ')'; } $tableSql = []; - if ( ! $this->onSchemaAlterTable($diff, $tableSql)) { + if (! $this->onSchemaAlterTable($diff, $tableSql)) { $sql = array_merge($sql, $commentsSQL); if ($diff->newName !== false) { @@ -890,13 +890,13 @@ public function getColumnDeclarationSQL($name, array $field) $notnull = $field['notnull'] ? ' NOT NULL' : ' NULL'; } - $unique = (isset($field['unique']) && $field['unique']) ? + $unique = isset($field['unique']) && $field['unique'] ? ' ' . $this->getUniqueFieldDeclarationSQL() : ''; - $check = (isset($field['check']) && $field['check']) ? + $check = isset($field['check']) && $field['check'] ? ' ' . $field['check'] : ''; - $typeDecl = $field['type']->getSQLDeclaration($field, $this); + $typeDecl = $field['type']->getSQLDeclaration($field, $this); $columnDef = $typeDecl . $default . $notnull . $unique . $check; } @@ -909,7 +909,7 @@ public function getColumnDeclarationSQL($name, array $field) protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName) { if (strpos($tableName, '.') !== false) { - list($schema) = explode('.', $tableName); + [$schema] = explode('.', $tableName); $oldIndexName = $schema . '.' . $oldIndexName; } @@ -977,8 +977,8 @@ protected function doModifyLimitQuery($query, $limit, $offset = null) } if (preg_match('/^\s*SELECT/i', $query)) { - if (!preg_match('/\sFROM\s/i', $query)) { - $query .= " FROM dual"; + if (! preg_match('/\sFROM\s/i', $query)) { + $query .= ' FROM dual'; } $columns = ['a.*']; @@ -1016,7 +1016,7 @@ public function getSQLResultCasing($column) */ public function getCreateTemporaryTableSnippetSQL() { - return "CREATE GLOBAL TEMPORARY TABLE"; + return 'CREATE GLOBAL TEMPORARY TABLE'; } /** diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSQL100Platform.php b/lib/Doctrine/DBAL/Platforms/PostgreSQL100Platform.php index 0d379f2fb6c..cfb079f94dd 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSQL100Platform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSQL100Platform.php @@ -21,12 +21,12 @@ protected function getReservedKeywordsClass() : string public function getListSequencesSQL($database) : string { - return "SELECT sequence_name AS relname, + return 'SELECT sequence_name AS relname, sequence_schema AS schemaname, minimum_value AS min_value, increment AS increment_by FROM information_schema.sequences - WHERE sequence_catalog = " . $this->quoteStringLiteral($database) . " + WHERE sequence_catalog = ' . $this->quoteStringLiteral($database) . " AND sequence_schema NOT LIKE 'pg\_%' AND sequence_schema != 'information_schema'"; } diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSQL91Platform.php b/lib/Doctrine/DBAL/Platforms/PostgreSQL91Platform.php index 9ac1ad9d9e5..e81f08ea60a 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSQL91Platform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSQL91Platform.php @@ -7,9 +7,7 @@ /** * Provides the behavior, features and SQL dialect of the PostgreSQL 9.1 database platform. * - * @author Martin Hasoň * @link www.doctrine-project.org - * @since 2.5 */ class PostgreSQL91Platform extends PostgreSqlPlatform { @@ -42,9 +40,9 @@ public function getColumnCollationDeclarationSQL($collation) */ public function getListTableColumnsSQL($table, $database = null) { - $sql = parent::getListTableColumnsSQL($table, $database); + $sql = parent::getListTableColumnsSQL($table, $database); $parts = explode('AS complete_type,', $sql, 2); - return $parts[0].'AS complete_type, (SELECT tc.collcollate FROM pg_catalog.pg_collation tc WHERE tc.oid = a.attcollation) AS collation,'.$parts[1]; + return $parts[0] . 'AS complete_type, (SELECT tc.collcollate FROM pg_catalog.pg_collation tc WHERE tc.oid = a.attcollation) AS collation,' . $parts[1]; } } diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSQL92Platform.php b/lib/Doctrine/DBAL/Platforms/PostgreSQL92Platform.php index f9deedd418d..76c40e56635 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSQL92Platform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSQL92Platform.php @@ -7,9 +7,7 @@ /** * Provides the behavior, features and SQL dialect of the PostgreSQL 9.2 database platform. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ class PostgreSQL92Platform extends PostgreSQL91Platform { @@ -26,7 +24,7 @@ public function getJsonTypeDeclarationSQL(array $field) */ public function getSmallIntTypeDeclarationSQL(array $field) { - if ( ! empty($field['autoincrement'])) { + if (! empty($field['autoincrement'])) { return 'SMALLSERIAL'; } diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSQL94Platform.php b/lib/Doctrine/DBAL/Platforms/PostgreSQL94Platform.php index d0bc3fd8183..a607fae1d21 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSQL94Platform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSQL94Platform.php @@ -7,9 +7,7 @@ /** * Provides the behavior, features and SQL dialect of the PostgreSQL 9.4 database platform. * - * @author Matteo Beccati * @link www.doctrine-project.org - * @since 2.6 */ class PostgreSQL94Platform extends PostgreSQL92Platform { @@ -18,7 +16,7 @@ class PostgreSQL94Platform extends PostgreSQL92Platform */ public function getJsonTypeDeclarationSQL(array $field) { - if (!empty($field['jsonb'])) { + if (! empty($field['jsonb'])) { return 'JSONB'; } diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php index ea8fd64a8e7..cacccffd8d2 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php @@ -4,15 +4,17 @@ use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ColumnDiff; +use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\Identifier; use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\TableDiff; -use Doctrine\DBAL\Types\BinaryType; use Doctrine\DBAL\Types\BigIntType; +use Doctrine\DBAL\Types\BinaryType; use Doctrine\DBAL\Types\BlobType; use Doctrine\DBAL\Types\IntegerType; use Doctrine\DBAL\Types\Type; +use UnexpectedValueException; use function array_diff; use function array_merge; use function array_unique; @@ -33,22 +35,14 @@ /** * PostgreSqlPlatform. * - * @since 2.0 - * @author Roman Borschel - * @author Lukas Smith (PEAR MDB2 library) - * @author Benjamin Eberlei * @todo Rename: PostgreSQLPlatform */ class PostgreSqlPlatform extends AbstractPlatform { - /** - * @var bool - */ + /** @var bool */ private $useBooleanTrueFalseStrings = true; - /** - * @var array PostgreSQL booleans literals - */ + /** @var array PostgreSQL booleans literals */ private $booleanLiterals = [ 'true' => [ 't', @@ -56,7 +50,7 @@ class PostgreSqlPlatform extends AbstractPlatform 'y', 'yes', 'on', - '1' + '1', ], 'false' => [ 'f', @@ -64,8 +58,8 @@ class PostgreSqlPlatform extends AbstractPlatform 'n', 'no', 'off', - '0' - ] + '0', + ], ]; /** @@ -117,10 +111,10 @@ public function getLocateExpression($str, $substr, $startPos = false) if ($startPos !== false) { $str = $this->getSubstringExpression($str, $startPos); - return 'CASE WHEN (POSITION('.$substr.' IN '.$str.') = 0) THEN 0 ELSE (POSITION('.$substr.' IN '.$str.') + '.($startPos-1).') END'; + return 'CASE WHEN (POSITION(' . $substr . ' IN ' . $str . ') = 0) THEN 0 ELSE (POSITION(' . $substr . ' IN ' . $str . ') + ' . ($startPos-1) . ') END'; } - return 'POSITION('.$substr.' IN '.$str.')'; + return 'POSITION(' . $substr . ' IN ' . $str . ')'; } /** @@ -133,7 +127,7 @@ protected function getDateArithmeticIntervalExpression($date, $operator, $interv $unit = DateIntervalUnit::MONTH; } - return "(" . $date ." " . $operator . " (" . $interval . " || ' " . $unit . "')::interval)"; + return '(' . $date . ' ' . $operator . ' (' . $interval . " || ' " . $unit . "')::interval)"; } /** @@ -287,13 +281,13 @@ public function getListViewsSQL($database) */ public function getListTableForeignKeysSQL($table, $database = null) { - return "SELECT quote_ident(r.conname) as conname, pg_catalog.pg_get_constraintdef(r.oid, true) as condef + return 'SELECT quote_ident(r.conname) as conname, pg_catalog.pg_get_constraintdef(r.oid, true) as condef FROM pg_catalog.pg_constraint r WHERE r.conrelid = ( SELECT c.oid FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n - WHERE " .$this->getTableWhereClause($table) ." AND n.oid = c.relnamespace + WHERE ' . $this->getTableWhereClause($table) . " AND n.oid = c.relnamespace ) AND r.contype = 'f'"; } @@ -311,7 +305,7 @@ public function getCreateViewSQL($name, $sql) */ public function getDropViewSQL($name) { - return 'DROP VIEW '. $name; + return 'DROP VIEW ' . $name; } /** @@ -338,20 +332,19 @@ public function getListTableConstraintsSQL($table) /** * {@inheritDoc} * - * @license New BSD License * @link http://ezcomponents.org/docs/api/trunk/DatabaseSchema/ezcDbSchemaPgsqlReader.html */ public function getListTableIndexesSQL($table, $currentDatabase = null) { - return "SELECT quote_ident(relname) as relname, pg_index.indisunique, pg_index.indisprimary, + return 'SELECT quote_ident(relname) as relname, pg_index.indisunique, pg_index.indisprimary, pg_index.indkey, pg_index.indrelid, pg_get_expr(indpred, indrelid) AS where FROM pg_class, pg_index WHERE oid IN ( SELECT indexrelid FROM pg_index si, pg_class sc, pg_namespace sn - WHERE " . $this->getTableWhereClause($table, 'sc', 'sn')." AND sc.oid=si.indrelid AND sc.relnamespace = sn.oid - ) AND pg_index.indexrelid = oid"; + WHERE ' . $this->getTableWhereClause($table, 'sc', 'sn') . ' AND sc.oid=si.indrelid AND sc.relnamespace = sn.oid + ) AND pg_index.indexrelid = oid'; } /** @@ -363,19 +356,17 @@ public function getListTableIndexesSQL($table, $currentDatabase = null) */ private function getTableWhereClause($table, $classAlias = 'c', $namespaceAlias = 'n') { - $whereClause = $namespaceAlias.".nspname NOT IN ('pg_catalog', 'information_schema', 'pg_toast') AND "; - if (strpos($table, ".") !== false) { - list($schema, $table) = explode(".", $table); - $schema = $this->quoteStringLiteral($schema); + $whereClause = $namespaceAlias . ".nspname NOT IN ('pg_catalog', 'information_schema', 'pg_toast') AND "; + if (strpos($table, '.') !== false) { + [$schema, $table] = explode('.', $table); + $schema = $this->quoteStringLiteral($schema); } else { $schema = "ANY(string_to_array((select replace(replace(setting,'\"\$user\"',user),' ','') from pg_catalog.pg_settings where name = 'search_path'),','))"; } $table = new Identifier($table); $table = $this->quoteStringLiteral($table->getName()); - $whereClause .= "$classAlias.relname = " . $table . " AND $namespaceAlias.nspname = $schema"; - - return $whereClause; + return $whereClause . "$classAlias.relname = " . $table . " AND $namespaceAlias.nspname = $schema"; } /** @@ -407,12 +398,12 @@ public function getListTableColumnsSQL($table, $database = null) FROM pg_description WHERE pg_description.objoid = c.oid AND a.attnum = pg_description.objsubid ) AS comment FROM pg_attribute a, pg_class c, pg_type t, pg_namespace n - WHERE ".$this->getTableWhereClause($table, 'c', 'n') ." + WHERE " . $this->getTableWhereClause($table, 'c', 'n') . ' AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid AND n.oid = c.relnamespace - ORDER BY a.attnum"; + ORDER BY a.attnum'; } /** @@ -456,7 +447,7 @@ public function getCloseActiveDatabaseConnectionsSQL($database) /** * {@inheritDoc} */ - public function getAdvancedForeignKeyOptionsSQL(\Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey) + public function getAdvancedForeignKeyOptionsSQL(ForeignKeyConstraint $foreignKey) { $query = ''; @@ -488,9 +479,9 @@ public function getAdvancedForeignKeyOptionsSQL(\Doctrine\DBAL\Schema\ForeignKey */ public function getAlterTableSQL(TableDiff $diff) { - $sql = []; + $sql = []; $commentsSQL = []; - $columnSql = []; + $columnSql = []; foreach ($diff->addedColumns as $column) { if ($this->onSchemaAlterTableAddColumn($column, $diff, $columnSql)) { @@ -502,13 +493,15 @@ public function getAlterTableSQL(TableDiff $diff) $comment = $this->getColumnComment($column); - if (null !== $comment && '' !== $comment) { - $commentsSQL[] = $this->getCommentOnColumnSQL( - $diff->getName($this)->getQuotedName($this), - $column->getQuotedName($this), - $comment - ); + if ($comment === null || $comment === '') { + continue; } + + $commentsSQL[] = $this->getCommentOnColumnSQL( + $diff->getName($this)->getQuotedName($this), + $column->getQuotedName($this), + $comment + ); } foreach ($diff->removedColumns as $column) { @@ -531,13 +524,13 @@ public function getAlterTableSQL(TableDiff $diff) } $oldColumnName = $columnDiff->getOldColumnName()->getQuotedName($this); - $column = $columnDiff->column; + $column = $columnDiff->column; if ($columnDiff->hasChanged('type') || $columnDiff->hasChanged('precision') || $columnDiff->hasChanged('scale') || $columnDiff->hasChanged('fixed')) { $type = $column->getType(); // SERIAL/BIGSERIAL are not "real" types and we can't alter a column to that type - $columnDefinition = $column->toArray(); + $columnDefinition = $column->toArray(); $columnDefinition['autoincrement'] = false; // here was a server version check before, but DBAL API does not support this anymore. @@ -546,11 +539,11 @@ public function getAlterTableSQL(TableDiff $diff) } if ($columnDiff->hasChanged('default') || $this->typeChangeBreaksDefaultValue($columnDiff)) { - $defaultClause = null === $column->getDefault() + $defaultClause = $column->getDefault() === null ? ' DROP DEFAULT' : ' SET' . $this->getDefaultValueDeclarationSQL($column->toArray()); - $query = 'ALTER ' . $oldColumnName . $defaultClause; - $sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ' . $query; + $query = 'ALTER ' . $oldColumnName . $defaultClause; + $sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ' . $query; } if ($columnDiff->hasChanged('notnull')) { @@ -563,14 +556,14 @@ public function getAlterTableSQL(TableDiff $diff) // add autoincrement $seqName = $this->getIdentitySequenceName($diff->name, $oldColumnName); - $sql[] = "CREATE SEQUENCE " . $seqName; - $sql[] = "SELECT setval('" . $seqName . "', (SELECT MAX(" . $oldColumnName . ") FROM " . $diff->getName($this)->getQuotedName($this) . "))"; - $query = "ALTER " . $oldColumnName . " SET DEFAULT nextval('" . $seqName . "')"; - $sql[] = "ALTER TABLE " . $diff->getName($this)->getQuotedName($this) . " " . $query; + $sql[] = 'CREATE SEQUENCE ' . $seqName; + $sql[] = "SELECT setval('" . $seqName . "', (SELECT MAX(" . $oldColumnName . ') FROM ' . $diff->getName($this)->getQuotedName($this) . '))'; + $query = 'ALTER ' . $oldColumnName . " SET DEFAULT nextval('" . $seqName . "')"; + $sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ' . $query; } else { // Drop autoincrement, but do NOT drop the sequence. It might be re-used by other tables or have - $query = "ALTER " . $oldColumnName . " " . "DROP DEFAULT"; - $sql[] = "ALTER TABLE " . $diff->getName($this)->getQuotedName($this) . " " . $query; + $query = 'ALTER ' . $oldColumnName . ' ' . 'DROP DEFAULT'; + $sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ' . $query; } } @@ -582,10 +575,12 @@ public function getAlterTableSQL(TableDiff $diff) ); } - if ($columnDiff->hasChanged('length')) { - $query = 'ALTER ' . $oldColumnName . ' TYPE ' . $column->getType()->getSQLDeclaration($column->toArray(), $this); - $sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ' . $query; + if (! $columnDiff->hasChanged('length')) { + continue; } + + $query = 'ALTER ' . $oldColumnName . ' TYPE ' . $column->getType()->getSQLDeclaration($column->toArray(), $this); + $sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ' . $query; } foreach ($diff->renamedColumns as $oldColumnName => $column) { @@ -601,7 +596,7 @@ public function getAlterTableSQL(TableDiff $diff) $tableSql = []; - if ( ! $this->onSchemaAlterTable($diff, $tableSql)) { + if (! $this->onSchemaAlterTable($diff, $tableSql)) { $sql = array_merge($sql, $commentsSQL); if ($diff->newName !== false) { @@ -636,7 +631,7 @@ private function isUnchangedBinaryColumn(ColumnDiff $columnDiff) { $columnType = $columnDiff->column->getType(); - if ( ! $columnType instanceof BinaryType && ! $columnType instanceof BlobType) { + if (! $columnType instanceof BinaryType && ! $columnType instanceof BlobType) { return false; } @@ -645,7 +640,7 @@ private function isUnchangedBinaryColumn(ColumnDiff $columnDiff) if ($fromColumn) { $fromColumnType = $fromColumn->getType(); - if ( ! $fromColumnType instanceof BinaryType && ! $fromColumnType instanceof BlobType) { + if (! $fromColumnType instanceof BinaryType && ! $fromColumnType instanceof BlobType) { return false; } @@ -665,7 +660,7 @@ private function isUnchangedBinaryColumn(ColumnDiff $columnDiff) protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName) { if (strpos($tableName, '.') !== false) { - list($schema) = explode('.', $tableName); + [$schema] = explode('.', $tableName); $oldIndexName = $schema . '.' . $oldIndexName; } @@ -677,11 +672,11 @@ protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName) */ public function getCommentOnColumnSQL($tableName, $columnName, $comment) { - $tableName = new Identifier($tableName); + $tableName = new Identifier($tableName); $columnName = new Identifier($columnName); - $comment = $comment === null ? 'NULL' : $this->quoteStringLiteral($comment); + $comment = $comment === null ? 'NULL' : $this->quoteStringLiteral($comment); - return "COMMENT ON COLUMN " . $tableName->getQuotedName($this) . "." . $columnName->getQuotedName($this) . + return 'COMMENT ON COLUMN ' . $tableName->getQuotedName($this) . '.' . $columnName->getQuotedName($this) . " IS $comment"; } @@ -710,8 +705,6 @@ public function getAlterSequenceSQL(Sequence $sequence) /** * Cache definition for sequences * - * @param Sequence $sequence - * * @return string */ private function getSequenceCacheSQL(Sequence $sequence) @@ -759,7 +752,7 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options $queryFields = $this->getColumnDeclarationListSQL($columns); if (isset($options['primary']) && ! empty($options['primary'])) { - $keyColumns = array_unique(array_values($options['primary'])); + $keyColumns = array_unique(array_values($options['primary'])); $queryFields .= ', PRIMARY KEY(' . implode(', ', $keyColumns) . ')'; } @@ -793,11 +786,12 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options * @param callable $callback The callback function to use for converting the real boolean value. * * @return mixed - * @throws \UnexpectedValueException + * + * @throws UnexpectedValueException */ private function convertSingleBooleanValue($value, $callback) { - if (null === $value) { + if ($value === null) { return $callback(null); } @@ -805,7 +799,7 @@ private function convertSingleBooleanValue($value, $callback) return $callback($value ? true : false); } - if (!is_string($value)) { + if (! is_string($value)) { return $callback(true); } @@ -820,7 +814,7 @@ private function convertSingleBooleanValue($value, $callback) return $callback(true); } - throw new \UnexpectedValueException("Unrecognized boolean literal '${value}'"); + throw new UnexpectedValueException("Unrecognized boolean literal '${value}'"); } /** @@ -855,18 +849,18 @@ private function doConvertBooleans($item, $callback) */ public function convertBooleans($item) { - if ( ! $this->useBooleanTrueFalseStrings) { + if (! $this->useBooleanTrueFalseStrings) { return parent::convertBooleans($item); } return $this->doConvertBooleans( $item, - function ($boolean) { - if (null === $boolean) { + static function ($boolean) { + if ($boolean === null) { return 'NULL'; } - return true === $boolean ? 'true' : 'false'; + return $boolean === true ? 'true' : 'false'; } ); } @@ -876,14 +870,14 @@ function ($boolean) { */ public function convertBooleansToDatabaseValue($item) { - if ( ! $this->useBooleanTrueFalseStrings) { + if (! $this->useBooleanTrueFalseStrings) { return parent::convertBooleansToDatabaseValue($item); } return $this->doConvertBooleans( $item, - function ($boolean) { - return null === $boolean ? null : (int) $boolean; + static function ($boolean) { + return $boolean === null ? null : (int) $boolean; } ); } @@ -930,7 +924,7 @@ public function getBooleanTypeDeclarationSQL(array $field) */ public function getIntegerTypeDeclarationSQL(array $field) { - if ( ! empty($field['autoincrement'])) { + if (! empty($field['autoincrement'])) { return 'SERIAL'; } @@ -942,7 +936,7 @@ public function getIntegerTypeDeclarationSQL(array $field) */ public function getBigIntTypeDeclarationSQL(array $field) { - if ( ! empty($field['autoincrement'])) { + if (! empty($field['autoincrement'])) { return 'BIGSERIAL'; } @@ -1080,7 +1074,7 @@ public function getEmptyIdentityInsertSQL($quotedTableName, $quotedIdentifierCol public function getTruncateTableSQL($tableName, $cascade = false) { $tableIdentifier = new Identifier($tableName); - $sql = 'TRUNCATE ' . $tableIdentifier->getQuotedName($this); + $sql = 'TRUNCATE ' . $tableIdentifier->getQuotedName($this); if ($cascade) { $sql .= ' CASCADE'; @@ -1215,9 +1209,6 @@ private function isSerialField(array $field) : bool /** * Check whether the type of a column is changed in a way that invalidates the default value for the column - * - * @param ColumnDiff $columnDiff - * @return bool */ private function typeChangeBreaksDefaultValue(ColumnDiff $columnDiff) : bool { diff --git a/lib/Doctrine/DBAL/Platforms/SQLAnywhere11Platform.php b/lib/Doctrine/DBAL/Platforms/SQLAnywhere11Platform.php index 875841a18d5..6c9b10ec535 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLAnywhere11Platform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLAnywhere11Platform.php @@ -6,9 +6,7 @@ * The SQLAnywhere11Platform provides the behavior, features and SQL dialect of the * SAP Sybase SQL Anywhere 11 database platform. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ class SQLAnywhere11Platform extends SQLAnywherePlatform { diff --git a/lib/Doctrine/DBAL/Platforms/SQLAnywhere12Platform.php b/lib/Doctrine/DBAL/Platforms/SQLAnywhere12Platform.php index bf8e232bfe1..1e793038311 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLAnywhere12Platform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLAnywhere12Platform.php @@ -9,9 +9,7 @@ * The SQLAnywhere12Platform provides the behavior, features and SQL dialect of the * SAP Sybase SQL Anywhere 12 database platform. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ class SQLAnywhere12Platform extends SQLAnywhere11Platform { @@ -92,7 +90,7 @@ public function supportsSequences() */ protected function getAdvancedIndexOptionsSQL(Index $index) { - if ( ! $index->isPrimary() && $index->isUnique() && $index->hasFlag('with_nulls_not_distinct')) { + if (! $index->isPrimary() && $index->isUnique() && $index->hasFlag('with_nulls_not_distinct')) { return ' WITH NULLS NOT DISTINCT' . parent::getAdvancedIndexOptionsSQL($index); } diff --git a/lib/Doctrine/DBAL/Platforms/SQLAnywhere16Platform.php b/lib/Doctrine/DBAL/Platforms/SQLAnywhere16Platform.php index b744d437672..b58b5740c5f 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLAnywhere16Platform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLAnywhere16Platform.php @@ -9,9 +9,7 @@ * The SQLAnywhere16Platform provides the behavior, features and SQL dialect of the * SAP Sybase SQL Anywhere 16 database platform. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ class SQLAnywhere16Platform extends SQLAnywhere12Platform { @@ -26,7 +24,7 @@ protected function getAdvancedIndexOptionsSQL(Index $index) ); } - if ( ! $index->isPrimary() && $index->isUnique() && $index->hasFlag('with_nulls_distinct')) { + if (! $index->isPrimary() && $index->isUnique() && $index->hasFlag('with_nulls_distinct')) { return ' WITH NULLS DISTINCT' . parent::getAdvancedIndexOptionsSQL($index); } diff --git a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php index affbe01a889..07f45fd7a59 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php @@ -13,6 +13,7 @@ use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\TransactionIsolationLevel; +use InvalidArgumentException; use function array_merge; use function array_unique; use function array_values; @@ -32,28 +33,14 @@ * The SQLAnywherePlatform provides the behavior, features and SQL dialect of the * SAP Sybase SQL Anywhere 10 database platform. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ class SQLAnywherePlatform extends AbstractPlatform { - /** - * @var int - */ - const FOREIGN_KEY_MATCH_SIMPLE = 1; - /** - * @var int - */ - const FOREIGN_KEY_MATCH_FULL = 2; - /** - * @var int - */ - const FOREIGN_KEY_MATCH_SIMPLE_UNIQUE = 129; - /** - * @var int - */ - const FOREIGN_KEY_MATCH_FULL_UNIQUE = 130; + public const FOREIGN_KEY_MATCH_SIMPLE = 1; + public const FOREIGN_KEY_MATCH_FULL = 2; + public const FOREIGN_KEY_MATCH_SIMPLE_UNIQUE = 129; + public const FOREIGN_KEY_MATCH_FULL_UNIQUE = 130; /** * {@inheritdoc} @@ -104,15 +91,15 @@ public function getAdvancedForeignKeyOptionsSQL(ForeignKeyConstraint $foreignKey $query .= parent::getAdvancedForeignKeyOptionsSQL($foreignKey); - if ($foreignKey->hasOption('check_on_commit') && (boolean) $foreignKey->getOption('check_on_commit')) { + if ($foreignKey->hasOption('check_on_commit') && (bool) $foreignKey->getOption('check_on_commit')) { $query .= ' CHECK ON COMMIT'; } - if ($foreignKey->hasOption('clustered') && (boolean) $foreignKey->getOption('clustered')) { + if ($foreignKey->hasOption('clustered') && (bool) $foreignKey->getOption('clustered')) { $query .= ' CLUSTERED'; } - if ($foreignKey->hasOption('for_olap_workload') && (boolean) $foreignKey->getOption('for_olap_workload')) { + if ($foreignKey->hasOption('for_olap_workload') && (bool) $foreignKey->getOption('for_olap_workload')) { $query .= ' FOR OLAP WORKLOAD'; } @@ -130,7 +117,7 @@ public function getAlterTableSQL(TableDiff $diff) $tableSql = []; $alterClauses = []; - /** @var \Doctrine\DBAL\Schema\Column $column */ + /** @var Column $column */ foreach ($diff->addedColumns as $column) { if ($this->onSchemaAlterTableAddColumn($column, $diff, $columnSql)) { continue; @@ -140,16 +127,18 @@ public function getAlterTableSQL(TableDiff $diff) $comment = $this->getColumnComment($column); - if (null !== $comment && '' !== $comment) { - $commentsSQL[] = $this->getCommentOnColumnSQL( - $diff->getName($this)->getQuotedName($this), - $column->getQuotedName($this), - $comment - ); + if ($comment === null || $comment === '') { + continue; } + + $commentsSQL[] = $this->getCommentOnColumnSQL( + $diff->getName($this)->getQuotedName($this), + $column->getQuotedName($this), + $comment + ); } - /** @var \Doctrine\DBAL\Schema\Column $column */ + /** @var Column $column */ foreach ($diff->removedColumns as $column) { if ($this->onSchemaAlterTableRemoveColumn($column, $diff, $columnSql)) { continue; @@ -158,7 +147,7 @@ public function getAlterTableSQL(TableDiff $diff) $alterClauses[] = $this->getAlterTableRemoveColumnClause($column); } - /** @var \Doctrine\DBAL\Schema\ColumnDiff $columnDiff */ + /** @var ColumnDiff $columnDiff */ foreach ($diff->changedColumns as $columnDiff) { if ($this->onSchemaAlterTableChangeColumn($columnDiff, $diff, $columnSql)) { continue; @@ -166,19 +155,21 @@ public function getAlterTableSQL(TableDiff $diff) $alterClause = $this->getAlterTableChangeColumnClause($columnDiff); - if (null !== $alterClause) { + if ($alterClause !== null) { $alterClauses[] = $alterClause; } - if ($columnDiff->hasChanged('comment')) { - $column = $columnDiff->column; - - $commentsSQL[] = $this->getCommentOnColumnSQL( - $diff->getName($this)->getQuotedName($this), - $column->getQuotedName($this), - $this->getColumnComment($column) - ); + if (! $columnDiff->hasChanged('comment')) { + continue; } + + $column = $columnDiff->column; + + $commentsSQL[] = $this->getCommentOnColumnSQL( + $diff->getName($this)->getQuotedName($this), + $column->getQuotedName($this), + $this->getColumnComment($column) + ); } foreach ($diff->renamedColumns as $oldColumnName => $column) { @@ -190,9 +181,9 @@ public function getAlterTableSQL(TableDiff $diff) $this->getAlterTableRenameColumnClause($oldColumnName, $column); } - if ( ! $this->onSchemaAlterTable($diff, $tableSql)) { - if ( ! empty($alterClauses)) { - $sql[] = $this->getAlterTableClause($diff->getName($this)) . ' ' . implode(", ", $alterClauses); + if (! $this->onSchemaAlterTable($diff, $tableSql)) { + if (! empty($alterClauses)) { + $sql[] = $this->getAlterTableClause($diff->getName($this)) . ' ' . implode(', ', $alterClauses); } $sql = array_merge($sql, $commentsSQL); @@ -260,7 +251,7 @@ protected function getAlterTableRenameColumnClause($oldColumnName, Column $colum { $oldColumnName = new Identifier($oldColumnName); - return 'RENAME ' . $oldColumnName->getQuotedName($this) .' TO ' . $column->getQuotedName($this); + return 'RENAME ' . $oldColumnName->getQuotedName($this) . ' TO ' . $column->getQuotedName($this); } /** @@ -290,11 +281,11 @@ protected function getAlterTableChangeColumnClause(ColumnDiff $columnDiff) $column = $columnDiff->column; // Do not return alter clause if only comment has changed. - if ( ! ($columnDiff->hasChanged('comment') && count($columnDiff->changedProperties) === 1)) { + if (! ($columnDiff->hasChanged('comment') && count($columnDiff->changedProperties) === 1)) { $columnAlterationClause = 'ALTER ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray()); - if ($columnDiff->hasChanged('default') && null === $column->getDefault()) { + if ($columnDiff->hasChanged('default') && $column->getDefault() === null) { $columnAlterationClause .= ', ALTER ' . $column->getQuotedName($this) . ' DROP DEFAULT'; } @@ -348,7 +339,7 @@ public function getBlobTypeDeclarationSQL(array $field) */ public function getBooleanTypeDeclarationSQL(array $columnDef) { - $nullClause = isset($columnDef['notnull']) && (boolean) $columnDef['notnull'] === false ? ' NULL' : ''; + $nullClause = isset($columnDef['notnull']) && (bool) $columnDef['notnull'] === false ? ' NULL' : ''; return 'BIT' . $nullClause; } @@ -366,11 +357,11 @@ public function getClobTypeDeclarationSQL(array $field) */ public function getCommentOnColumnSQL($tableName, $columnName, $comment) { - $tableName = new Identifier($tableName); + $tableName = new Identifier($tableName); $columnName = new Identifier($columnName); - $comment = $comment === null ? 'NULL' : $this->quoteStringLiteral($comment); + $comment = $comment === null ? 'NULL' : $this->quoteStringLiteral($comment); - return "COMMENT ON COLUMN " . $tableName->getQuotedName($this) . '.' . $columnName->getQuotedName($this) . + return 'COMMENT ON COLUMN ' . $tableName->getQuotedName($this) . '.' . $columnName->getQuotedName($this) . " IS $comment"; } @@ -416,7 +407,7 @@ public function getCreateDatabaseSQL($database) */ public function getCreateIndexSQL(Index $index, $table) { - return parent::getCreateIndexSQL($index, $table). $this->getAdvancedIndexOptionsSQL($index); + return parent::getCreateIndexSQL($index, $table) . $this->getAdvancedIndexOptionsSQL($index); } /** @@ -478,7 +469,7 @@ protected function getDateArithmeticIntervalExpression($date, $operator, $interv { $factorClause = ''; - if ('-' === $operator) { + if ($operator === '-') { $factorClause = '-1 * '; } @@ -552,14 +543,14 @@ public function getDropIndexSQL($index, $table = null) $index = $index->getQuotedName($this); } - if ( ! is_string($index)) { - throw new \InvalidArgumentException( + if (! is_string($index)) { + throw new InvalidArgumentException( 'SQLAnywherePlatform::getDropIndexSQL() expects $index parameter to be string or ' . '\Doctrine\DBAL\Schema\Index.' ); } - if ( ! isset($table)) { + if (! isset($table)) { return 'DROP INDEX ' . $index; } @@ -567,8 +558,8 @@ public function getDropIndexSQL($index, $table = null) $table = $table->getQuotedName($this); } - if ( ! is_string($table)) { - throw new \InvalidArgumentException( + if (! is_string($table)) { + throw new InvalidArgumentException( 'SQLAnywherePlatform::getDropIndexSQL() expects $table parameter to be string or ' . '\Doctrine\DBAL\Schema\Table.' ); @@ -596,23 +587,23 @@ public function getForeignKeyBaseDeclarationSQL(ForeignKeyConstraint $foreignKey $foreignColumns = $foreignKey->getQuotedForeignColumns($this); $foreignTableName = $foreignKey->getQuotedForeignTableName($this); - if ( ! empty($foreignKeyName)) { + if (! empty($foreignKeyName)) { $sql .= 'CONSTRAINT ' . $foreignKey->getQuotedName($this) . ' '; } if (empty($localColumns)) { - throw new \InvalidArgumentException("Incomplete definition. 'local' required."); + throw new InvalidArgumentException("Incomplete definition. 'local' required."); } if (empty($foreignColumns)) { - throw new \InvalidArgumentException("Incomplete definition. 'foreign' required."); + throw new InvalidArgumentException("Incomplete definition. 'foreign' required."); } if (empty($foreignTableName)) { - throw new \InvalidArgumentException("Incomplete definition. 'foreignTable' required."); + throw new InvalidArgumentException("Incomplete definition. 'foreignTable' required."); } - if ($foreignKey->hasOption('notnull') && (boolean) $foreignKey->getOption('notnull')) { + if ($foreignKey->hasOption('notnull') && (bool) $foreignKey->getOption('notnull')) { $sql .= 'NOT NULL '; } @@ -629,7 +620,7 @@ public function getForeignKeyBaseDeclarationSQL(ForeignKeyConstraint $foreignKey * * @return string * - * @throws \InvalidArgumentException if unknown match type given + * @throws InvalidArgumentException if unknown match type given */ public function getForeignKeyMatchClauseSQL($type) { @@ -646,7 +637,7 @@ public function getForeignKeyMatchClauseSQL($type) case self::FOREIGN_KEY_MATCH_FULL_UNIQUE: return 'UNIQUE FULL'; default: - throw new \InvalidArgumentException('Invalid foreign key match type: ' . $type); + throw new InvalidArgumentException('Invalid foreign key match type: ' . $type); } } @@ -724,8 +715,8 @@ public function getListTableColumnsSQL($table, $database = null) $user = 'USER_NAME()'; if (strpos($table, '.') !== false) { - list($user, $table) = explode('.', $table); - $user = $this->quoteStringLiteral($user); + [$user, $table] = explode('.', $table); + $user = $this->quoteStringLiteral($user); } return "SELECT col.column_name, @@ -756,9 +747,9 @@ public function getListTableConstraintsSQL($table) $user = ''; if (strpos($table, '.') !== false) { - list($user, $table) = explode('.', $table); - $user = $this->quoteStringLiteral($user); - $table = $this->quoteStringLiteral($table); + [$user, $table] = explode('.', $table); + $user = $this->quoteStringLiteral($user); + $table = $this->quoteStringLiteral($table); } else { $table = $this->quoteStringLiteral($table); } @@ -778,9 +769,9 @@ public function getListTableForeignKeysSQL($table) $user = ''; if (strpos($table, '.') !== false) { - list($user, $table) = explode('.', $table); - $user = $this->quoteStringLiteral($user); - $table = $this->quoteStringLiteral($table); + [$user, $table] = explode('.', $table); + $user = $this->quoteStringLiteral($user); + $table = $this->quoteStringLiteral($table); } else { $table = $this->quoteStringLiteral($table); } @@ -864,9 +855,9 @@ public function getListTableIndexesSQL($table, $currentDatabase = null) $user = ''; if (strpos($table, '.') !== false) { - list($user, $table) = explode('.', $table); - $user = $this->quoteStringLiteral($user); - $table = $this->quoteStringLiteral($table); + [$user, $table] = explode('.', $table); + $user = $this->quoteStringLiteral($user); + $table = $this->quoteStringLiteral($table); } else { $table = $this->quoteStringLiteral($table); } @@ -953,7 +944,7 @@ public function getListViewsSQL($database) */ public function getLocateExpression($str, $substr, $startPos = false) { - if ($startPos == false) { + if ($startPos === false) { return 'LOCATE(' . $str . ', ' . $substr . ')'; } @@ -973,7 +964,7 @@ public function getMaxIdentifierLength() */ public function getMd5Expression($column) { - return "HASH(" . $column . ", 'MD5')"; + return 'HASH(' . $column . ", 'MD5')"; } /** @@ -993,12 +984,12 @@ public function getName() * * @return string DBMS specific SQL code portion needed to set a primary key * - * @throws \InvalidArgumentException if the given index is not a primary key. + * @throws InvalidArgumentException if the given index is not a primary key. */ public function getPrimaryKeyDeclarationSQL(Index $index, $name = null) { - if ( ! $index->isPrimary()) { - throw new \InvalidArgumentException( + if (! $index->isPrimary()) { + throw new InvalidArgumentException( 'Can only create primary key declarations with getPrimaryKeyDeclarationSQL()' ); } @@ -1068,7 +1059,7 @@ public function getStopDatabaseSQL($database) */ public function getSubstringExpression($value, $from, $length = null) { - if (null === $length) { + if ($length === null) { return 'SUBSTRING(' . $value . ', ' . $from . ')'; } @@ -1104,7 +1095,7 @@ public function getTimeTypeDeclarationSQL(array $fieldDeclaration) */ public function getTrimExpression($str, $pos = TrimMode::UNSPECIFIED, $char = false) { - if ( ! $char) { + if (! $char) { switch ($pos) { case TrimMode::LEADING: return $this->getLtrimExpression($str); @@ -1123,8 +1114,7 @@ public function getTrimExpression($str, $pos = TrimMode::UNSPECIFIED, $char = fa case TrimMode::TRAILING: return 'REVERSE(SUBSTR(REVERSE(' . $str . '), PATINDEX(' . $pattern . ', REVERSE(' . $str . '))))'; default: - return - 'REVERSE(SUBSTR(REVERSE(SUBSTR(' . $str . ', PATINDEX(' . $pattern . ', ' . $str . '))), ' . + return 'REVERSE(SUBSTR(REVERSE(SUBSTR(' . $str . ', PATINDEX(' . $pattern . ', ' . $str . '))), ' . 'PATINDEX(' . $pattern . ', REVERSE(SUBSTR(' . $str . ', PATINDEX(' . $pattern . ', ' . $str . '))))))'; } } @@ -1145,13 +1135,13 @@ public function getTruncateTableSQL($tableName, $cascade = false) public function getUniqueConstraintDeclarationSQL($name, Index $index) { if ($index->isPrimary()) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( 'Cannot create primary key constraint declarations with getUniqueConstraintDeclarationSQL().' ); } - if ( ! $index->isUnique()) { - throw new \InvalidArgumentException( + if (! $index->isUnique()) { + throw new InvalidArgumentException( 'Can only create unique constraint declarations, no common index declarations with ' . 'getUniqueConstraintDeclarationSQL().' ); @@ -1225,22 +1215,22 @@ protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) protected function _getCreateTableSQL($tableName, array $columns, array $options = []) { $columnListSql = $this->getColumnDeclarationListSQL($columns); - $indexSql = []; + $indexSql = []; - if ( ! empty($options['uniqueConstraints'])) { + if (! empty($options['uniqueConstraints'])) { foreach ((array) $options['uniqueConstraints'] as $name => $definition) { $columnListSql .= ', ' . $this->getUniqueConstraintDeclarationSQL($name, $definition); } } - if ( ! empty($options['indexes'])) { - /** @var \Doctrine\DBAL\Schema\Index $index */ + if (! empty($options['indexes'])) { + /** @var Index $index */ foreach ((array) $options['indexes'] as $index) { $indexSql[] = $this->getCreateIndexSQL($index, $tableName); } } - if ( ! empty($options['primary'])) { + if (! empty($options['primary'])) { $flags = ''; if (isset($options['primary_index']) && $options['primary_index']->hasFlag('clustered')) { @@ -1250,7 +1240,7 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options $columnListSql .= ', PRIMARY KEY' . $flags . ' (' . implode(', ', array_unique(array_values((array) $options['primary']))) . ')'; } - if ( ! empty($options['foreignKeys'])) { + if (! empty($options['foreignKeys'])) { foreach ((array) $options['foreignKeys'] as $definition) { $columnListSql .= ', ' . $this->getForeignKeyDeclarationSQL($definition); } @@ -1259,7 +1249,7 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options $query = 'CREATE TABLE ' . $tableName . ' (' . $columnListSql; $check = $this->getCheckDeclarationSQL($columns); - if ( ! empty($check)) { + if (! empty($check)) { $query .= ', ' . $check; } @@ -1283,7 +1273,7 @@ protected function _getTransactionIsolationLevelSQL($level) case TransactionIsolationLevel::SERIALIZABLE: return 3; default: - throw new \InvalidArgumentException('Invalid isolation level:' . $level); + throw new InvalidArgumentException('Invalid isolation level:' . $level); } } @@ -1299,7 +1289,7 @@ protected function doModifyLimitQuery($query, $limit, $offset) } if ($offset > 0) { - if ($limit == 0) { + if ($limit === 0) { $limitOffsetClause = 'TOP ALL '; } @@ -1325,7 +1315,7 @@ protected function getAdvancedIndexOptionsSQL(Index $index) { $sql = ''; - if ( ! $index->isPrimary() && $index->hasFlag('for_olap_workload')) { + if (! $index->isPrimary() && $index->hasFlag('for_olap_workload')) { $sql .= ' FOR OLAP WORKLOAD'; } @@ -1350,7 +1340,7 @@ protected function getBinaryTypeDeclarationSQLSnippet($length, $fixed) * * @return string * - * @throws \InvalidArgumentException if the given table constraint type is not supported by this method. + * @throws InvalidArgumentException if the given table constraint type is not supported by this method. */ protected function getTableConstraintDeclarationSQL(Constraint $constraint, $name = null) { @@ -1358,12 +1348,12 @@ protected function getTableConstraintDeclarationSQL(Constraint $constraint, $nam return $this->getForeignKeyDeclarationSQL($constraint); } - if ( ! $constraint instanceof Index) { - throw new \InvalidArgumentException('Unsupported constraint type: ' . get_class($constraint)); + if (! $constraint instanceof Index) { + throw new InvalidArgumentException('Unsupported constraint type: ' . get_class($constraint)); } - if ( ! $constraint->isPrimary() && ! $constraint->isUnique()) { - throw new \InvalidArgumentException( + if (! $constraint->isPrimary() && ! $constraint->isUnique()) { + throw new InvalidArgumentException( 'Can only create primary, unique or foreign key constraint declarations, no common index declarations ' . 'with getTableConstraintDeclarationSQL().' ); @@ -1372,13 +1362,13 @@ protected function getTableConstraintDeclarationSQL(Constraint $constraint, $nam $constraintColumns = $constraint->getQuotedColumns($this); if (empty($constraintColumns)) { - throw new \InvalidArgumentException("Incomplete definition. 'columns' required."); + throw new InvalidArgumentException("Incomplete definition. 'columns' required."); } $sql = ''; $flags = ''; - if ( ! empty($name)) { + if (! empty($name)) { $name = new Identifier($name); $sql .= 'CONSTRAINT ' . $name->getQuotedName($this) . ' '; } @@ -1388,10 +1378,10 @@ protected function getTableConstraintDeclarationSQL(Constraint $constraint, $nam } if ($constraint->isPrimary()) { - return $sql . 'PRIMARY KEY ' . $flags . '('. $this->getIndexFieldDeclarationListSQL($constraintColumns) . ')'; + return $sql . 'PRIMARY KEY ' . $flags . '(' . $this->getIndexFieldDeclarationListSQL($constraintColumns) . ')'; } - return $sql . 'UNIQUE ' . $flags . '('. $this->getIndexFieldDeclarationListSQL($constraintColumns) . ')'; + return $sql . 'UNIQUE ' . $flags . '(' . $this->getIndexFieldDeclarationListSQL($constraintColumns) . ')'; } /** @@ -1420,9 +1410,7 @@ protected function getCreateIndexSQLFlags(Index $index) */ protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName) { - return [ - 'ALTER INDEX ' . $oldIndexName . ' ON ' . $tableName . ' RENAME TO ' . $index->getQuotedName($this) - ]; + return ['ALTER INDEX ' . $oldIndexName . ' ON ' . $tableName . ' RENAME TO ' . $index->getQuotedName($this)]; } /** diff --git a/lib/Doctrine/DBAL/Platforms/SQLAzurePlatform.php b/lib/Doctrine/DBAL/Platforms/SQLAzurePlatform.php index d04a530c80e..a104848f84e 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLAzurePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLAzurePlatform.php @@ -16,7 +16,7 @@ class SQLAzurePlatform extends SQLServer2008Platform /** * {@inheritDoc} */ - public function getCreateTableSQL(Table $table, $createFlags=self::CREATE_INDEXES) + public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDEXES) { $sql = parent::getCreateTableSQL($table, $createFlags); @@ -25,7 +25,7 @@ public function getCreateTableSQL(Table $table, $createFlags=self::CREATE_INDEXE $columnName = $table->getOption('azure.federatedOnColumnName'); $stmt = ' FEDERATED ON (' . $distributionName . ' = ' . $columnName . ')'; - $sql[0] = $sql[0] . $stmt; + $sql[0] .= $stmt; } return $sql; diff --git a/lib/Doctrine/DBAL/Platforms/SQLServer2008Platform.php b/lib/Doctrine/DBAL/Platforms/SQLServer2008Platform.php index 41d81673afd..c2e36f34e67 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServer2008Platform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServer2008Platform.php @@ -94,9 +94,9 @@ public function getTimeFormatString() protected function initializeDoctrineTypeMappings() { parent::initializeDoctrineTypeMappings(); - $this->doctrineTypeMapping['datetime2'] = 'datetime'; - $this->doctrineTypeMapping['date'] = 'date'; - $this->doctrineTypeMapping['time'] = 'time'; + $this->doctrineTypeMapping['datetime2'] = 'datetime'; + $this->doctrineTypeMapping['date'] = 'date'; + $this->doctrineTypeMapping['time'] = 'time'; $this->doctrineTypeMapping['datetimeoffset'] = 'datetimetz'; } diff --git a/lib/Doctrine/DBAL/Platforms/SQLServer2012Platform.php b/lib/Doctrine/DBAL/Platforms/SQLServer2012Platform.php index d2d81f5a70e..009a37d33b0 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServer2012Platform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServer2012Platform.php @@ -13,8 +13,6 @@ * * Differences to SQL Server 2008 and before are that sequences are introduced, * and support for the new OFFSET... FETCH syntax for result pagination has been added. - * - * @author Steve Müller */ class SQLServer2012Platform extends SQLServer2008Platform { @@ -103,15 +101,15 @@ protected function doModifyLimitQuery($query, $limit, $offset = null) // Queries using OFFSET... FETCH MUST have an ORDER BY clause // Find the position of the last instance of ORDER BY and ensure it is not within a parenthetical statement // but can be in a newline - $matches = []; - $matchesCount = preg_match_all("/[\\s]+order\\s+by\\s/im", $query, $matches, PREG_OFFSET_CAPTURE); - $orderByPos = false; + $matches = []; + $matchesCount = preg_match_all('/[\\s]+order\\s+by\\s/im', $query, $matches, PREG_OFFSET_CAPTURE); + $orderByPos = false; if ($matchesCount > 0) { $orderByPos = $matches[0][($matchesCount - 1)][1]; } if ($orderByPos === false - || substr_count($query, "(", $orderByPos) - substr_count($query, ")", $orderByPos) + || substr_count($query, '(', $orderByPos) - substr_count($query, ')', $orderByPos) ) { if (preg_match('/^SELECT\s+DISTINCT/im', $query)) { // SQL Server won't let us order by a non-selected column in a DISTINCT query, @@ -119,11 +117,11 @@ protected function doModifyLimitQuery($query, $limit, $offset = null) // result. SQL Server's docs say that a nonordered query's result order is non- // deterministic anyway, so this won't do anything that a bunch of update and // deletes to the table wouldn't do anyway. - $query .= " ORDER BY 1"; + $query .= ' ORDER BY 1'; } else { // In another DBMS, we could do ORDER BY 0, but SQL Server gets angry if you // use constant expressions in the order by list. - $query .= " ORDER BY (SELECT 0)"; + $query .= ' ORDER BY (SELECT 0)'; } } @@ -134,10 +132,10 @@ protected function doModifyLimitQuery($query, $limit, $offset = null) // This looks somewhat like MYSQL, but limit/offset are in inverse positions // Supposedly SQL:2008 core standard. // Per TSQL spec, FETCH NEXT n ROWS ONLY is not valid without OFFSET n ROWS. - $query .= " OFFSET " . (int) $offset . " ROWS"; + $query .= ' OFFSET ' . (int) $offset . ' ROWS'; if ($limit !== null) { - $query .= " FETCH NEXT " . (int) $limit . " ROWS ONLY"; + $query .= ' FETCH NEXT ' . (int) $limit . ' ROWS ONLY'; } return $query; diff --git a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php index 92e45be2de2..12811fa9da7 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php @@ -11,6 +11,7 @@ use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Types; +use InvalidArgumentException; use function array_merge; use function array_unique; use function array_values; @@ -39,12 +40,6 @@ /** * The SQLServerPlatform provides the behavior, features and SQL dialect of the * Microsoft SQL Server database platform. - * - * @since 2.0 - * @author Roman Borschel - * @author Jonathan H. Wage - * @author Benjamin Eberlei - * @author Steve Müller */ class SQLServerPlatform extends AbstractPlatform { @@ -84,7 +79,7 @@ protected function getDateArithmeticIntervalExpression($date, $operator, $interv { $factorClause = ''; - if ('-' === $operator) { + if ($operator === '-') { $factorClause = '-1 * '; } @@ -206,7 +201,7 @@ public function getDropForeignKeySQL($foreignKey, $table) } $foreignKey = $foreignKey->getQuotedName($this); - $table = $table->getQuotedName($this); + $table = $table->getQuotedName($this); return 'ALTER TABLE ' . $table . ' DROP CONSTRAINT ' . $foreignKey; } @@ -218,11 +213,11 @@ public function getDropIndexSQL($index, $table = null) { if ($index instanceof Index) { $index = $index->getQuotedName($this); - } elseif (!is_string($index)) { - throw new \InvalidArgumentException('AbstractPlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.'); + } elseif (! is_string($index)) { + throw new InvalidArgumentException('AbstractPlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.'); } - if (!isset($table)) { + if (! isset($table)) { return 'DROP INDEX ' . $index; } @@ -231,9 +226,9 @@ public function getDropIndexSQL($index, $table = null) } return "IF EXISTS (SELECT * FROM sysobjects WHERE name = '$index') - ALTER TABLE " . $table . " DROP CONSTRAINT " . $index . " + ALTER TABLE " . $table . ' DROP CONSTRAINT ' . $index . ' ELSE - DROP INDEX " . $index . " ON " . $table; + DROP INDEX ' . $index . ' ON ' . $table; } /** @@ -257,20 +252,22 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options ' ADD' . $this->getDefaultConstraintDeclarationSQL($tableName, $column); } - if ( ! empty($column['comment']) || is_numeric($column['comment'])) { - $commentsSql[] = $this->getCreateColumnCommentSQL($tableName, $column['name'], $column['comment']); + if (empty($column['comment']) && ! is_numeric($column['comment'])) { + continue; } + + $commentsSql[] = $this->getCreateColumnCommentSQL($tableName, $column['name'], $column['comment']); } $columnListSql = $this->getColumnDeclarationListSQL($columns); - if (isset($options['uniqueConstraints']) && !empty($options['uniqueConstraints'])) { + if (isset($options['uniqueConstraints']) && ! empty($options['uniqueConstraints'])) { foreach ($options['uniqueConstraints'] as $name => $definition) { $columnListSql .= ', ' . $this->getUniqueConstraintDeclarationSQL($name, $definition); } } - if (isset($options['primary']) && !empty($options['primary'])) { + if (isset($options['primary']) && ! empty($options['primary'])) { $flags = ''; if (isset($options['primary_index']) && $options['primary_index']->hasFlag('nonclustered')) { $flags = ' NONCLUSTERED'; @@ -281,14 +278,14 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options $query = 'CREATE TABLE ' . $tableName . ' (' . $columnListSql; $check = $this->getCheckDeclarationSQL($columns); - if (!empty($check)) { + if (! empty($check)) { $query .= ', ' . $check; } $query .= ')'; $sql = [$query]; - if (isset($options['indexes']) && !empty($options['indexes'])) { + if (isset($options['indexes']) && ! empty($options['indexes'])) { foreach ($options['indexes'] as $index) { $sql[] = $this->getCreateIndexSQL($index, $tableName); } @@ -364,18 +361,17 @@ protected function getCreateColumnCommentSQL($tableName, $columnName, $comment) * * @return string * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ public function getDefaultConstraintDeclarationSQL($table, array $column) { - if ( ! isset($column['default'])) { - throw new \InvalidArgumentException("Incomplete column definition. 'default' required."); + if (! isset($column['default'])) { + throw new InvalidArgumentException("Incomplete column definition. 'default' required."); } $columnName = new Identifier($column['name']); - return - ' CONSTRAINT ' . + return ' CONSTRAINT ' . $this->generateDefaultConstraintName($table, $column['name']) . $this->getDefaultValueDeclarationSQL($column) . ' FOR ' . $columnName->getQuotedName($this); @@ -400,7 +396,7 @@ public function getCreateIndexSQL(Index $index, $table) { $constraint = parent::getCreateIndexSQL($index, $table); - if ($index->isUnique() && !$index->isPrimary()) { + if ($index->isUnique() && ! $index->isPrimary()) { $constraint = $this->_appendUniqueConstraintDefinition($constraint, $index); } @@ -429,8 +425,7 @@ protected function getCreateIndexSQLFlags(Index $index) /** * Extend unique key constraint with required filters * - * @param string $sql - * @param \Doctrine\DBAL\Schema\Index $index + * @param string $sql * * @return string */ @@ -455,13 +450,13 @@ public function getAlterTableSQL(TableDiff $diff) $columnSql = []; $commentsSql = []; - /** @var \Doctrine\DBAL\Schema\Column $column */ + /** @var Column $column */ foreach ($diff->addedColumns as $column) { if ($this->onSchemaAlterTableAddColumn($column, $diff, $columnSql)) { continue; } - $columnDef = $column->toArray(); + $columnDef = $column->toArray(); $queryParts[] = 'ADD ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnDef); if (isset($columnDef['default'])) { @@ -470,13 +465,15 @@ public function getAlterTableSQL(TableDiff $diff) $comment = $this->getColumnComment($column); - if ( ! empty($comment) || is_numeric($comment)) { - $commentsSql[] = $this->getCreateColumnCommentSQL( - $diff->name, - $column->getQuotedName($this), - $comment - ); + if (empty($comment) && ! is_numeric($comment)) { + continue; } + + $commentsSql[] = $this->getCreateColumnCommentSQL( + $diff->name, + $column->getQuotedName($this), + $comment + ); } foreach ($diff->removedColumns as $column) { @@ -487,7 +484,7 @@ public function getAlterTableSQL(TableDiff $diff) $queryParts[] = 'DROP COLUMN ' . $column->getQuotedName($this); } - /* @var $columnDiff \Doctrine\DBAL\Schema\ColumnDiff */ + /** @var ColumnDiff $columnDiff */ foreach ($diff->changedColumns as $columnDiff) { if ($this->onSchemaAlterTableChangeColumn($columnDiff, $diff, $columnSql)) { continue; @@ -495,13 +492,13 @@ public function getAlterTableSQL(TableDiff $diff) $column = $columnDiff->column; $comment = $this->getColumnComment($column); - $hasComment = ! empty ($comment) || is_numeric($comment); + $hasComment = ! empty($comment) || is_numeric($comment); if ($columnDiff->fromColumn instanceof Column) { $fromComment = $this->getColumnComment($columnDiff->fromColumn); - $hasFromComment = ! empty ($fromComment) || is_numeric($fromComment); + $hasFromComment = ! empty($fromComment) || is_numeric($fromComment); - if ($hasFromComment && $hasComment && $fromComment != $comment) { + if ($hasFromComment && $hasComment && $fromComment !== $comment) { $commentsSql[] = $this->getAlterColumnCommentSQL( $diff->name, $column->getQuotedName($this), @@ -539,9 +536,11 @@ public function getAlterTableSQL(TableDiff $diff) $queryParts[] = 'ALTER COLUMN ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $columnDef); - if (isset($columnDef['default']) && ($requireDropDefaultConstraint || $columnDiff->hasChanged('default'))) { - $queryParts[] = $this->getAlterTableAddDefaultConstraintClause($diff->name, $column); + if (! isset($columnDef['default']) || (! $requireDropDefaultConstraint && ! $columnDiff->hasChanged('default'))) { + continue; } + + $queryParts[] = $this->getAlterTableAddDefaultConstraintClause($diff->name, $column); } foreach ($diff->renamedColumns as $oldColumnName => $column) { @@ -552,17 +551,19 @@ public function getAlterTableSQL(TableDiff $diff) $oldColumnName = new Identifier($oldColumnName); $sql[] = "sp_RENAME '" . - $diff->getName($this)->getQuotedName($this) . "." . $oldColumnName->getQuotedName($this) . + $diff->getName($this)->getQuotedName($this) . '.' . $oldColumnName->getQuotedName($this) . "', '" . $column->getQuotedName($this) . "', 'COLUMN'"; // Recreate default constraint with new column name if necessary (for future reference). - if ($column->getDefault() !== null) { - $queryParts[] = $this->getAlterTableDropDefaultConstraintClause( - $diff->name, - $oldColumnName->getQuotedName($this) - ); - $queryParts[] = $this->getAlterTableAddDefaultConstraintClause($diff->name, $column); + if ($column->getDefault() === null) { + continue; } + + $queryParts[] = $this->getAlterTableDropDefaultConstraintClause( + $diff->name, + $oldColumnName->getQuotedName($this) + ); + $queryParts[] = $this->getAlterTableAddDefaultConstraintClause($diff->name, $column); } $tableSql = []; @@ -592,10 +593,10 @@ public function getAlterTableSQL(TableDiff $diff) "SELECT @sql += N'EXEC sp_rename N''' + dc.name + ''', N''' " . "+ REPLACE(dc.name, '" . $this->generateIdentifierName($diff->name) . "', " . "'" . $this->generateIdentifierName($diff->newName) . "') + ''', ''OBJECT'';' " . - "FROM sys.default_constraints dc " . - "JOIN sys.tables tbl ON dc.parent_object_id = tbl.object_id " . + 'FROM sys.default_constraints dc ' . + 'JOIN sys.tables tbl ON dc.parent_object_id = tbl.object_id ' . "WHERE tbl.name = '" . $diff->getNewName()->getName() . "';" . - "EXEC sp_executesql @sql"; + 'EXEC sp_executesql @sql'; } $sql = array_merge( @@ -617,7 +618,7 @@ public function getAlterTableSQL(TableDiff $diff) */ private function getAlterTableAddDefaultConstraintClause($tableName, Column $column) { - $columnDef = $column->toArray(); + $columnDef = $column->toArray(); $columnDef['name'] = $column->getQuotedName($this); return 'ADD' . $this->getDefaultConstraintDeclarationSQL($tableName, $columnDef); @@ -652,7 +653,7 @@ private function alterColumnRequiresDropDefaultConstraint(ColumnDiff $columnDiff { // We can only decide whether to drop an existing default constraint // if we know the original default value. - if ( ! $columnDiff->fromColumn instanceof Column) { + if (! $columnDiff->fromColumn instanceof Column) { return false; } @@ -756,19 +757,20 @@ protected function getDropColumnCommentSQL($tableName, $columnName) */ protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName) { - return [ - sprintf( - "EXEC sp_RENAME N'%s.%s', N'%s', N'INDEX'", - $tableName, - $oldIndexName, - $index->getQuotedName($this) - ) + return [sprintf( + "EXEC sp_RENAME N'%s.%s', N'%s', N'INDEX'", + $tableName, + $oldIndexName, + $index->getQuotedName($this) + ), ]; } /** * Returns the SQL statement for adding an extended property to a database object. * + * @link http://msdn.microsoft.com/en-us/library/ms180047%28v=sql.90%29.aspx + * * @param string $name The name of the property to add. * @param string|null $value The value of the property to add. * @param string|null $level0Type The type of the object at level 0 the property belongs to. @@ -779,8 +781,6 @@ protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName) * @param string|null $level2Name The name of the object at level 2 the property belongs to. * * @return string - * - * @link http://msdn.microsoft.com/en-us/library/ms180047%28v=sql.90%29.aspx */ public function getAddExtendedPropertySQL( $name, @@ -792,16 +792,18 @@ public function getAddExtendedPropertySQL( $level2Type = null, $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; + 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; } /** * Returns the SQL statement for dropping an extended property from a database object. * + * @link http://technet.microsoft.com/en-gb/library/ms178595%28v=sql.90%29.aspx + * * @param string $name The name of the property to drop. * @param string|null $level0Type The type of the object at level 0 the property belongs to. * @param string|null $level0Name The name of the object at level 0 the property belongs to. @@ -811,8 +813,6 @@ public function getAddExtendedPropertySQL( * @param string|null $level2Name The name of the object at level 2 the property belongs to. * * @return string - * - * @link http://technet.microsoft.com/en-gb/library/ms178595%28v=sql.90%29.aspx */ public function getDropExtendedPropertySQL( $name, @@ -823,16 +823,18 @@ public function getDropExtendedPropertySQL( $level2Type = null, $level2Name = null ) { - return "EXEC sp_dropextendedproperty " . - "N" . $this->quoteStringLiteral($name) . ", " . - "N" . $this->quoteStringLiteral($level0Type) . ", " . $level0Name . ', ' . - "N" . $this->quoteStringLiteral($level1Type) . ", " . $level1Name . ', ' . - "N" . $this->quoteStringLiteral($level2Type) . ", " . $level2Name; + return 'EXEC sp_dropextendedproperty ' . + 'N' . $this->quoteStringLiteral($name) . ', ' . + 'N' . $this->quoteStringLiteral($level0Type) . ', ' . $level0Name . ', ' . + 'N' . $this->quoteStringLiteral($level1Type) . ', ' . $level1Name . ', ' . + 'N' . $this->quoteStringLiteral($level2Type) . ', ' . $level2Name; } /** * Returns the SQL statement for updating an extended property of a database object. * + * @link http://msdn.microsoft.com/en-us/library/ms186885%28v=sql.90%29.aspx + * * @param string $name The name of the property to update. * @param string|null $value The value of the property to update. * @param string|null $level0Type The type of the object at level 0 the property belongs to. @@ -843,8 +845,6 @@ public function getDropExtendedPropertySQL( * @param string|null $level2Name The name of the object at level 2 the property belongs to. * * @return string - * - * @link http://msdn.microsoft.com/en-us/library/ms186885%28v=sql.90%29.aspx */ public function getUpdateExtendedPropertySQL( $name, @@ -856,11 +856,11 @@ public function getUpdateExtendedPropertySQL( $level2Type = null, $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; + 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; } /** @@ -919,7 +919,7 @@ public function getListTableColumnsSQL($table, $database = null) */ public function getListTableForeignKeysSQL($table, $database = null) { - return "SELECT f.name AS ForeignKey, + return 'SELECT f.name AS ForeignKey, SCHEMA_NAME (f.SCHEMA_ID) AS SchemaName, OBJECT_NAME (f.parent_object_id) AS TableName, COL_NAME (fc.parent_object_id,fc.parent_column_id) AS ColumnName, @@ -932,7 +932,7 @@ public function getListTableForeignKeysSQL($table, $database = null) INNER JOIN sys.foreign_key_columns AS fc INNER JOIN sys.objects AS o ON o.OBJECT_ID = fc.referenced_object_id ON f.OBJECT_ID = fc.constraint_object_id - WHERE " . + WHERE ' . $this->getTableWhereClause($table, 'SCHEMA_NAME (f.schema_id)', 'OBJECT_NAME (f.parent_object_id)'); } @@ -955,8 +955,8 @@ public function getListTableIndexesSQL($table, $currentDatabase = null) JOIN sys.indexes AS idx ON tbl.object_id = idx.object_id JOIN sys.index_columns AS idxcol ON idx.object_id = idxcol.object_id AND idx.index_id = idxcol.index_id JOIN sys.columns AS col ON idxcol.object_id = col.object_id AND idxcol.column_id = col.column_id - WHERE " . $this->getTableWhereClause($table, 'scm.name', 'tbl.name') . " - ORDER BY idx.index_id ASC, idxcol.key_ordinal ASC"; + WHERE " . $this->getTableWhereClause($table, 'scm.name', 'tbl.name') . ' + ORDER BY idx.index_id ASC, idxcol.key_ordinal ASC'; } /** @@ -986,13 +986,13 @@ public function getListViewsSQL($database) */ private function getTableWhereClause($table, $schemaColumn, $tableColumn) { - if (strpos($table, ".") !== false) { - list($schema, $table) = explode(".", $table); - $schema = $this->quoteStringLiteral($schema); - $table = $this->quoteStringLiteral($table); + if (strpos($table, '.') !== false) { + [$schema, $table] = explode('.', $table); + $schema = $this->quoteStringLiteral($schema); + $table = $this->quoteStringLiteral($table); } else { - $schema = "SCHEMA_NAME()"; - $table = $this->quoteStringLiteral($table); + $schema = 'SCHEMA_NAME()'; + $table = $this->quoteStringLiteral($table); } return "({$tableColumn} = {$table} AND {$schemaColumn} = {$schema})"; @@ -1021,7 +1021,7 @@ public function getGuidExpression() */ public function getLocateExpression($str, $substr, $startPos = false) { - if ($startPos == false) { + if ($startPos === false) { return 'CHARINDEX(' . $substr . ', ' . $str . ')'; } @@ -1041,7 +1041,7 @@ public function getModExpression($expression1, $expression2) */ public function getTrimExpression($str, $pos = TrimMode::UNSPECIFIED, $char = false) { - if ( ! $char) { + if (! $char) { switch ($pos) { case TrimMode::LEADING: $trimFn = 'LTRIM'; @@ -1203,7 +1203,7 @@ public function getClobTypeDeclarationSQL(array $field) */ protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) { - return (!empty($columnDef['autoincrement'])) ? ' IDENTITY' : ''; + return ! empty($columnDef['autoincrement']) ? ' IDENTITY' : ''; } /** @@ -1264,11 +1264,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'; + $selectPattern = '/^(\s*SELECT\s+(?:DISTINCT\s+)?)(.*)$/im'; $replacePattern = sprintf('$1%s $2', $top); - $query = preg_replace($selectPattern, $replacePattern, $query); + $query = preg_replace($selectPattern, $replacePattern, $query); - if (stristr($query, "ORDER BY")) { + if (stristr($query, 'ORDER BY')) { // Inner order by is not valid in SQL Server for our purposes // unless it's in a TOP N subquery. $query = $this->scrubInnerOrderBy($query); @@ -1276,10 +1276,10 @@ protected function doModifyLimitQuery($query, $limit, $offset = null) // Build a new limited query around the original, using a CTE return sprintf( - "WITH dctrn_cte AS (%s) " - . "SELECT * FROM (" - . "SELECT *, ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS doctrine_rownum FROM dctrn_cte" - . ") AS doctrine_tbl " + 'WITH dctrn_cte AS (%s) ' + . 'SELECT * FROM (' + . 'SELECT *, ROW_NUMBER() OVER (ORDER BY (SELECT 0)) AS doctrine_rownum FROM dctrn_cte' + . ') AS doctrine_tbl ' . 'WHERE %s ORDER BY doctrine_rownum ASC', $query, implode(' AND ', $where) @@ -1291,11 +1291,12 @@ protected function doModifyLimitQuery($query, $limit, $offset = null) * Caveat: will leave ORDER BY in TOP N subqueries. * * @param string $query + * * @return string */ private function scrubInnerOrderBy($query) { - $count = substr_count(strtoupper($query), 'ORDER BY'); + $count = substr_count(strtoupper($query), 'ORDER BY'); $offset = 0; while ($count-- > 0) { @@ -1304,8 +1305,8 @@ private function scrubInnerOrderBy($query) break; } - $qLen = strlen($query); - $parenCount = 0; + $qLen = strlen($query); + $parenCount = 0; $currentPosition = $orderByPos; while ($parenCount >= 0 && $currentPosition < $qLen) { @@ -1325,10 +1326,12 @@ private function scrubInnerOrderBy($query) continue; } - if ($currentPosition < $qLen - 1) { - $query = substr($query, 0, $orderByPos) . substr($query, $currentPosition - 1); - $offset = $orderByPos; + if ($currentPosition >= $qLen - 1) { + continue; } + + $query = substr($query, 0, $orderByPos) . substr($query, $currentPosition - 1); + $offset = $orderByPos; } return $query; } @@ -1338,13 +1341,14 @@ private function scrubInnerOrderBy($query) * * @param string $query The query * @param int $currentPosition Start position of ORDER BY clause + * * @return bool true if ORDER BY is in a TOP N query, false otherwise */ private function isOrderByInTopNSubquery($query, $currentPosition) { // Grab query text on the same nesting level as the ORDER BY clause we're examining. $subQueryBuffer = ''; - $parenCount = 0; + $parenCount = 0; // If $parenCount goes negative, we've exited the subquery we're examining. // If $currentPosition goes negative, we've reached the beginning of the query. @@ -1379,12 +1383,14 @@ public function convertBooleans($item) { if (is_array($item)) { foreach ($item as $key => $value) { - if (is_bool($value) || is_numeric($item)) { - $item[$key] = ($value) ? 1 : 0; + if (! is_bool($value) && ! is_numeric($item)) { + continue; } + + $item[$key] = $value ? 1 : 0; } } elseif (is_bool($item) || is_numeric($item)) { - $item = ($item) ? 1 : 0; + $item = $item ? 1 : 0; } return $item; @@ -1395,7 +1401,7 @@ public function convertBooleans($item) */ public function getCreateTemporaryTableSnippetSQL() { - return "CREATE TABLE"; + return 'CREATE TABLE'; } /** @@ -1523,13 +1529,13 @@ public function getForeignKeyReferentialActionSQL($action) public function appendLockHint($fromClause, $lockMode) { switch (true) { - case LockMode::NONE === $lockMode: + case $lockMode === LockMode::NONE: return $fromClause . ' WITH (NOLOCK)'; - case LockMode::PESSIMISTIC_READ === $lockMode: + case $lockMode === LockMode::PESSIMISTIC_READ: return $fromClause . ' WITH (HOLDLOCK, ROWLOCK)'; - case LockMode::PESSIMISTIC_WRITE === $lockMode: + case $lockMode === LockMode::PESSIMISTIC_WRITE: return $fromClause . ' WITH (UPDLOCK, ROWLOCK)'; default: @@ -1558,7 +1564,7 @@ protected function getReservedKeywordsClass() */ public function quoteSingleIdentifier($str) { - return "[" . str_replace("]", "][", $str) . "]"; + return '[' . str_replace(']', '][', $str) . ']'; } /** @@ -1584,22 +1590,22 @@ public function getBlobTypeDeclarationSQL(array $field) */ public function getDefaultValueDeclarationSQL($field) { - if ( ! isset($field['default'])) { + if (! isset($field['default'])) { return empty($field['notnull']) ? ' NULL' : ''; } - if ( ! isset($field['type'])) { + if (! isset($field['type'])) { return " DEFAULT '" . $field['default'] . "'"; } $type = $field['type']; if ($type instanceof Types\PhpIntegerMappingType) { - return " DEFAULT " . $field['default']; + return ' DEFAULT ' . $field['default']; } if ($type instanceof Types\PhpDateTimeMappingType && $field['default'] === $this->getCurrentTimestampSQL()) { - return " DEFAULT " . $this->getCurrentTimestampSQL(); + return ' DEFAULT ' . $this->getCurrentTimestampSQL(); } if ($type instanceof Types\BooleanType) { @@ -1619,18 +1625,18 @@ public function getColumnDeclarationSQL($name, array $field) if (isset($field['columnDefinition'])) { $columnDef = $this->getCustomTypeDeclarationSQL($field); } else { - $collation = (isset($field['collation']) && $field['collation']) ? + $collation = isset($field['collation']) && $field['collation'] ? ' ' . $this->getColumnCollationDeclarationSQL($field['collation']) : ''; - $notnull = (isset($field['notnull']) && $field['notnull']) ? ' NOT NULL' : ''; + $notnull = isset($field['notnull']) && $field['notnull'] ? ' NOT NULL' : ''; - $unique = (isset($field['unique']) && $field['unique']) ? + $unique = isset($field['unique']) && $field['unique'] ? ' ' . $this->getUniqueFieldDeclarationSQL() : ''; - $check = (isset($field['check']) && $field['check']) ? + $check = isset($field['check']) && $field['check'] ? ' ' . $field['check'] : ''; - $typeDecl = $field['type']->getSQLDeclaration($field, $this); + $typeDecl = $field['type']->getSQLDeclaration($field, $this); $columnDef = $typeDecl . $collation . $notnull . $unique . $check; } diff --git a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php index 3697e116b96..fab0410a19f 100644 --- a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php @@ -28,10 +28,6 @@ * The SqlitePlatform class describes the specifics and dialects of the SQLite * database platform. * - * @since 2.0 - * @author Roman Borschel - * @author Benjamin Eberlei - * @author Martin Hasoň * @todo Rename: SQLitePlatform */ class SqlitePlatform extends AbstractPlatform @@ -78,7 +74,7 @@ public function getNowExpression($type = 'timestamp') */ public function getTrimExpression($str, $pos = TrimMode::UNSPECIFIED, $char = false) { - $trimChar = ($char != false) ? (', ' . $char) : ''; + $trimChar = $char !== false ? (', ' . $char) : ''; switch ($pos) { case TrimMode::LEADING: @@ -115,11 +111,11 @@ public function getSubstringExpression($value, $position, $length = null) */ public function getLocateExpression($str, $substr, $startPos = false) { - if ($startPos == false) { - return 'LOCATE('.$str.', '.$substr.')'; + if ($startPos === false) { + return 'LOCATE(' . $str . ', ' . $substr . ')'; } - return 'LOCATE('.$str.', '.$substr.', '.$startPos.')'; + return 'LOCATE(' . $str . ', ' . $substr . ', ' . $startPos . ')'; } /** @@ -131,7 +127,7 @@ protected function getDateArithmeticIntervalExpression($date, $operator, $interv case DateIntervalUnit::SECOND: case DateIntervalUnit::MINUTE: case DateIntervalUnit::HOUR: - return "DATETIME(" . $date . ",'" . $operator . $interval . " " . $unit . "')"; + return 'DATETIME(' . $date . ",'" . $operator . $interval . ' ' . $unit . "')"; default: switch ($unit) { @@ -150,7 +146,7 @@ protected function getDateArithmeticIntervalExpression($date, $operator, $interv $interval = "' || " . $interval . " || '"; } - return "DATE(" . $date . ",'" . $operator . $interval . " " . $unit . "')"; + return 'DATE(' . $date . ",'" . $operator . $interval . ' ' . $unit . "')"; } } @@ -217,7 +213,7 @@ public function getIntegerTypeDeclarationSQL(array $field) public function getBigIntTypeDeclarationSQL(array $field) { // SQLite autoincrement is implicit for INTEGER PKs, but not for BIGINT fields. - if ( ! empty($field['autoincrement'])) { + if (! empty($field['autoincrement'])) { return $this->getIntegerTypeDeclarationSQL($field); } @@ -230,7 +226,7 @@ public function getBigIntTypeDeclarationSQL(array $field) public function getTinyIntTypeDeclarationSql(array $field) { // SQLite autoincrement is implicit for INTEGER PKs, but not for TINYINT fields. - if ( ! empty($field['autoincrement'])) { + if (! empty($field['autoincrement'])) { return $this->getIntegerTypeDeclarationSQL($field); } @@ -243,7 +239,7 @@ public function getTinyIntTypeDeclarationSql(array $field) public function getSmallIntTypeDeclarationSQL(array $field) { // SQLite autoincrement is implicit for INTEGER PKs, but not for SMALLINT fields. - if ( ! empty($field['autoincrement'])) { + if (! empty($field['autoincrement'])) { return $this->getIntegerTypeDeclarationSQL($field); } @@ -256,7 +252,7 @@ public function getSmallIntTypeDeclarationSQL(array $field) public function getMediumIntTypeDeclarationSql(array $field) { // SQLite autoincrement is implicit for INTEGER PKs, but not for MEDIUMINT fields. - if ( ! empty($field['autoincrement'])) { + if (! empty($field['autoincrement'])) { return $this->getIntegerTypeDeclarationSQL($field); } @@ -293,7 +289,7 @@ public function getTimeTypeDeclarationSQL(array $fieldDeclaration) protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) { // sqlite autoincrement is only possible for the primary key - if ( ! empty($columnDef['autoincrement'])) { + if (! empty($columnDef['autoincrement'])) { return ' PRIMARY KEY AUTOINCREMENT'; } @@ -319,7 +315,7 @@ public function getForeignKeyDeclarationSQL(ForeignKeyConstraint $foreignKey) */ protected function _getCreateTableSQL($name, array $columns, array $options = []) { - $name = str_replace('.', '__', $name); + $name = str_replace('.', '__', $name); $queryFields = $this->getColumnDeclarationListSQL($columns); if (isset($options['uniqueConstraints']) && ! empty($options['uniqueConstraints'])) { @@ -332,13 +328,13 @@ protected function _getCreateTableSQL($name, array $columns, array $options = [] if (isset($options['foreignKeys'])) { foreach ($options['foreignKeys'] as $foreignKey) { - $queryFields.= ', '.$this->getForeignKeyDeclarationSQL($foreignKey); + $queryFields .= ', ' . $this->getForeignKeyDeclarationSQL($foreignKey); } } $query = ['CREATE TABLE ' . $name . ' (' . $queryFields . ')']; - if (isset($options['alter']) && true === $options['alter']) { + if (isset($options['alter']) && $options['alter'] === true) { return $query; } @@ -460,7 +456,7 @@ public function getListTableIndexesSQL($table, $currentDatabase = null) public function getListTablesSQL() { return "SELECT name FROM sqlite_master WHERE type = 'table' AND name != 'sqlite_sequence' AND name != 'geometry_columns' AND name != 'spatial_ref_sys' " - . "UNION ALL SELECT name FROM sqlite_temp_master " + . 'UNION ALL SELECT name FROM sqlite_temp_master ' . "WHERE type = 'table' ORDER BY name"; } @@ -485,7 +481,7 @@ public function getCreateViewSQL($name, $sql) */ public function getDropViewSQL($name) { - return 'DROP VIEW '. $name; + return 'DROP VIEW ' . $name; } /** @@ -495,8 +491,8 @@ public function getAdvancedForeignKeyOptionsSQL(ForeignKeyConstraint $foreignKey { $query = parent::getAdvancedForeignKeyOptionsSQL($foreignKey); - $query .= (($foreignKey->hasOption('deferrable') && $foreignKey->getOption('deferrable') !== false) ? ' ' : ' NOT ') . 'DEFERRABLE'; - $query .= ' INITIALLY ' . (($foreignKey->hasOption('deferred') && $foreignKey->getOption('deferred') !== false) ? 'DEFERRED' : 'IMMEDIATE'); + $query .= ($foreignKey->hasOption('deferrable') && $foreignKey->getOption('deferrable') !== false ? ' ' : ' NOT ') . 'DEFERRABLE'; + $query .= ' INITIALLY ' . ($foreignKey->hasOption('deferred') && $foreignKey->getOption('deferred') !== false ? 'DEFERRED' : 'IMMEDIATE'); return $query; } @@ -539,7 +535,7 @@ public function getName() public function getTruncateTableSQL($tableName, $cascade = false) { $tableIdentifier = new Identifier($tableName); - $tableName = str_replace('.', '__', $tableIdentifier->getQuotedName($this)); + $tableName = str_replace('.', '__', $tableIdentifier->getQuotedName($this)); return 'DELETE FROM ' . $tableName; } @@ -566,7 +562,7 @@ public static function udfSqrt($value) */ public static function udfMod($a, $b) { - return ($a % $b); + return $a % $b; } /** @@ -663,15 +659,17 @@ protected function getReservedKeywordsClass() */ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) { - if ( ! $diff->fromTable instanceof Table) { + if (! $diff->fromTable instanceof Table) { throw new DBALException('Sqlite platform requires for alter table the table diff with reference to original table schema'); } $sql = []; foreach ($diff->fromTable->getIndexes() as $index) { - if ( ! $index->isPrimary()) { - $sql[] = $this->getDropIndexSQL($index, $diff->name); + if ($index->isPrimary()) { + continue; } + + $sql[] = $this->getDropIndexSQL($index, $diff->name); } return $sql; @@ -682,11 +680,11 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) */ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff) { - if ( ! $diff->fromTable instanceof Table) { + if (! $diff->fromTable instanceof Table) { throw new DBALException('Sqlite platform requires for alter table the table diff with reference to original table schema'); } - $sql = []; + $sql = []; $tableName = $diff->newName ? $diff->getNewName(): $diff->getName($this); foreach ($this->getIndexesInAlteredTable($diff) as $index) { if ($index->isPrimary()) { @@ -810,25 +808,25 @@ public function getListTableForeignKeysSQL($table, $database = null) public function getAlterTableSQL(TableDiff $diff) { $sql = $this->getSimpleAlterTableSQL($diff); - if (false !== $sql) { + if ($sql !== false) { return $sql; } $fromTable = $diff->fromTable; - if ( ! $fromTable instanceof Table) { + if (! $fromTable instanceof Table) { throw new DBALException('Sqlite platform requires for alter table the table diff with reference to original table schema'); } $table = clone $fromTable; - $columns = []; + $columns = []; $oldColumnNames = []; $newColumnNames = []; - $columnSql = []; + $columnSql = []; foreach ($table->getColumns() as $columnName => $column) { - $columnName = strtolower($columnName); - $columns[$columnName] = $column; + $columnName = strtolower($columnName); + $columns[$columnName] = $column; $oldColumnNames[$columnName] = $newColumnNames[$columnName] = $column->getQuotedName($this); } @@ -838,13 +836,15 @@ public function getAlterTableSQL(TableDiff $diff) } $columnName = strtolower($columnName); - if (isset($columns[$columnName])) { - unset( - $columns[$columnName], - $oldColumnNames[$columnName], - $newColumnNames[$columnName] - ); + if (! isset($columns[$columnName])) { + continue; } + + unset( + $columns[$columnName], + $oldColumnNames[$columnName], + $newColumnNames[$columnName] + ); } foreach ($diff->renamedColumns as $oldColumnName => $column) { @@ -859,9 +859,11 @@ public function getAlterTableSQL(TableDiff $diff) $columns[strtolower($column->getName())] = $column; - if (isset($newColumnNames[$oldColumnName])) { - $newColumnNames[$oldColumnName] = $column->getQuotedName($this); + if (! isset($newColumnNames[$oldColumnName])) { + continue; } + + $newColumnNames[$oldColumnName] = $column->getQuotedName($this); } foreach ($diff->changedColumns as $oldColumnName => $columnDiff) { @@ -875,9 +877,11 @@ public function getAlterTableSQL(TableDiff $diff) $columns[strtolower($columnDiff->column->getName())] = $columnDiff->column; - if (isset($newColumnNames[$oldColumnName])) { - $newColumnNames[$oldColumnName] = $columnDiff->column->getQuotedName($this); + if (! isset($newColumnNames[$oldColumnName])) { + continue; } + + $newColumnNames[$oldColumnName] = $columnDiff->column->getQuotedName($this); } foreach ($diff->addedColumns as $columnName => $column) { @@ -888,10 +892,10 @@ public function getAlterTableSQL(TableDiff $diff) $columns[strtolower($columnName)] = $column; } - $sql = []; + $sql = []; $tableSql = []; - if ( ! $this->onSchemaAlterTable($diff, $tableSql)) { - $dataTable = new Table('__temp__'.$table->getName()); + if (! $this->onSchemaAlterTable($diff, $tableSql)) { + $dataTable = new Table('__temp__' . $table->getName()); $newTable = new Table($table->getQuotedName($this), $columns, $this->getPrimaryIndexInAlteredTable($diff), $this->getForeignKeysInAlteredTable($diff), 0, $table->getOptions()); $newTable->addOption('alter', true); @@ -901,13 +905,13 @@ public function getAlterTableSQL(TableDiff $diff) $sql[] = sprintf('CREATE TEMPORARY TABLE %s AS SELECT %s FROM %s', $dataTable->getQuotedName($this), implode(', ', $oldColumnNames), $table->getQuotedName($this)); $sql[] = $this->getDropTableSQL($fromTable); - $sql = array_merge($sql, $this->getCreateTableSQL($newTable)); + $sql = array_merge($sql, $this->getCreateTableSQL($newTable)); $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) { + if ($diff->newName && $diff->newName !== $diff->name) { $renamedTable = $diff->getNewName(); - $sql[] = 'ALTER TABLE '.$newTable->getQuotedName($this).' RENAME TO '.$renamedTable->getQuotedName($this); + $sql[] = 'ALTER TABLE ' . $newTable->getQuotedName($this) . ' RENAME TO ' . $renamedTable->getQuotedName($this); } $sql = array_merge($sql, $this->getPostAlterTableIndexForeignKeySQL($diff)); @@ -917,15 +921,13 @@ public function getAlterTableSQL(TableDiff $diff) } /** - * @param \Doctrine\DBAL\Schema\TableDiff $diff - * * @return string[]|false */ private function getSimpleAlterTableSQL(TableDiff $diff) { // Suppress changes on integer type autoincrement columns. foreach ($diff->changedColumns as $oldColumnName => $columnDiff) { - if ( ! $columnDiff->fromColumn instanceof Column || + if (! $columnDiff->fromColumn instanceof Column || ! $columnDiff->column instanceof Column || ! $columnDiff->column->getAutoincrement() || ! $columnDiff->column->getType() instanceof Types\IntegerType @@ -933,7 +935,7 @@ private function getSimpleAlterTableSQL(TableDiff $diff) continue; } - if ( ! $columnDiff->hasChanged('type') && $columnDiff->hasChanged('unsigned')) { + if (! $columnDiff->hasChanged('type') && $columnDiff->hasChanged('unsigned')) { unset($diff->changedColumns[$oldColumnName]); continue; @@ -941,12 +943,14 @@ private function getSimpleAlterTableSQL(TableDiff $diff) $fromColumnType = $columnDiff->fromColumn->getType(); - if ($fromColumnType instanceof Types\SmallIntType || $fromColumnType instanceof Types\BigIntType) { - unset($diff->changedColumns[$oldColumnName]); + if (! ($fromColumnType instanceof Types\SmallIntType) && ! ($fromColumnType instanceof Types\BigIntType)) { + continue; } + + unset($diff->changedColumns[$oldColumnName]); } - if ( ! empty($diff->renamedColumns) || ! empty($diff->addedForeignKeys) || ! empty($diff->addedIndexes) + if (! empty($diff->renamedColumns) || ! empty($diff->addedForeignKeys) || ! empty($diff->addedIndexes) || ! empty($diff->changedColumns) || ! empty($diff->changedForeignKeys) || ! empty($diff->changedIndexes) || ! empty($diff->removedColumns) || ! empty($diff->removedForeignKeys) || ! empty($diff->removedIndexes) || ! empty($diff->renamedIndexes) @@ -956,8 +960,8 @@ private function getSimpleAlterTableSQL(TableDiff $diff) $table = new Table($diff->name); - $sql = []; - $tableSql = []; + $sql = []; + $tableSql = []; $columnSql = []; foreach ($diff->addedColumns as $column) { @@ -966,12 +970,12 @@ private function getSimpleAlterTableSQL(TableDiff $diff) } $field = array_merge(['unique' => null, 'autoincrement' => null, 'default' => null], $column->toArray()); - $type = $field['type']; + $type = $field['type']; switch (true) { case isset($field['columnDefinition']) || $field['autoincrement'] || $field['unique']: - case $type instanceof Types\DateTimeType && $field['default'] == $this->getCurrentTimestampSQL(): - case $type instanceof Types\DateType && $field['default'] == $this->getCurrentDateSQL(): - case $type instanceof Types\TimeType && $field['default'] == $this->getCurrentTimeSQL(): + case $type instanceof Types\DateTimeType && $field['default'] === $this->getCurrentTimestampSQL(): + case $type instanceof Types\DateType && $field['default'] === $this->getCurrentDateSQL(): + case $type instanceof Types\TimeType && $field['default'] === $this->getCurrentTimeSQL(): return false; } @@ -980,13 +984,13 @@ private function getSimpleAlterTableSQL(TableDiff $diff) $field['length'] = 255; } - $sql[] = 'ALTER TABLE '.$table->getQuotedName($this).' ADD COLUMN '.$this->getColumnDeclarationSQL($field['name'], $field); + $sql[] = 'ALTER TABLE ' . $table->getQuotedName($this) . ' ADD COLUMN ' . $this->getColumnDeclarationSQL($field['name'], $field); } - if ( ! $this->onSchemaAlterTable($diff, $tableSql)) { + if (! $this->onSchemaAlterTable($diff, $tableSql)) { if ($diff->newName !== false) { $newTable = new Identifier($diff->newName); - $sql[] = 'ALTER TABLE '.$table->getQuotedName($this).' RENAME TO '.$newTable->getQuotedName($this); + $sql[] = 'ALTER TABLE ' . $table->getQuotedName($this) . ' RENAME TO ' . $newTable->getQuotedName($this); } } @@ -994,8 +998,6 @@ private function getSimpleAlterTableSQL(TableDiff $diff) } /** - * @param \Doctrine\DBAL\Schema\TableDiff $diff - * * @return array */ private function getColumnNamesInAlteredTable(TableDiff $diff) @@ -1008,21 +1010,23 @@ private function getColumnNamesInAlteredTable(TableDiff $diff) foreach ($diff->removedColumns as $columnName => $column) { $columnName = strtolower($columnName); - if (isset($columns[$columnName])) { - unset($columns[$columnName]); + if (! isset($columns[$columnName])) { + continue; } + + unset($columns[$columnName]); } foreach ($diff->renamedColumns as $oldColumnName => $column) { - $columnName = $column->getName(); + $columnName = $column->getName(); $columns[strtolower($oldColumnName)] = $columnName; - $columns[strtolower($columnName)] = $columnName; + $columns[strtolower($columnName)] = $columnName; } foreach ($diff->changedColumns as $oldColumnName => $columnDiff) { - $columnName = $columnDiff->column->getName(); + $columnName = $columnDiff->column->getName(); $columns[strtolower($oldColumnName)] = $columnName; - $columns[strtolower($columnName)] = $columnName; + $columns[strtolower($columnName)] = $columnName; } foreach ($diff->addedColumns as $columnName => $column) { @@ -1033,27 +1037,27 @@ private function getColumnNamesInAlteredTable(TableDiff $diff) } /** - * @param \Doctrine\DBAL\Schema\TableDiff $diff - * - * @return \Doctrine\DBAL\Schema\Index[] + * @return Index[] */ private function getIndexesInAlteredTable(TableDiff $diff) { - $indexes = $diff->fromTable->getIndexes(); + $indexes = $diff->fromTable->getIndexes(); $columnNames = $this->getColumnNamesInAlteredTable($diff); foreach ($indexes as $key => $index) { foreach ($diff->renamedIndexes as $oldIndexName => $renamedIndex) { - if (strtolower($key) === strtolower($oldIndexName)) { - unset($indexes[$key]); + if (strtolower($key) !== strtolower($oldIndexName)) { + continue; } + + unset($indexes[$key]); } - $changed = false; + $changed = false; $indexColumns = []; foreach ($index->getColumns() as $columnName) { $normalizedColumnName = strtolower($columnName); - if ( ! isset($columnNames[$normalizedColumnName])) { + if (! isset($columnNames[$normalizedColumnName])) { unset($indexes[$key]); continue 2; } else { @@ -1064,16 +1068,20 @@ private function getIndexesInAlteredTable(TableDiff $diff) } } - if ($changed) { - $indexes[$key] = new Index($index->getName(), $indexColumns, $index->isUnique(), $index->isPrimary(), $index->getFlags()); + if (! $changed) { + continue; } + + $indexes[$key] = new Index($index->getName(), $indexColumns, $index->isUnique(), $index->isPrimary(), $index->getFlags()); } foreach ($diff->removedIndexes as $index) { $indexName = strtolower($index->getName()); - if (strlen($indexName) && isset($indexes[$indexName])) { - unset($indexes[$indexName]); + if (! strlen($indexName) || ! isset($indexes[$indexName])) { + continue; } + + unset($indexes[$indexName]); } foreach (array_merge($diff->changedIndexes, $diff->addedIndexes, $diff->renamedIndexes) as $index) { @@ -1089,8 +1097,6 @@ private function getIndexesInAlteredTable(TableDiff $diff) } /** - * @param \Doctrine\DBAL\Schema\TableDiff $diff - * * @return array */ private function getForeignKeysInAlteredTable(TableDiff $diff) @@ -1099,11 +1105,11 @@ private function getForeignKeysInAlteredTable(TableDiff $diff) $columnNames = $this->getColumnNamesInAlteredTable($diff); foreach ($foreignKeys as $key => $constraint) { - $changed = false; + $changed = false; $localColumns = []; foreach ($constraint->getLocalColumns() as $columnName) { $normalizedColumnName = strtolower($columnName); - if ( ! isset($columnNames[$normalizedColumnName])) { + if (! isset($columnNames[$normalizedColumnName])) { unset($foreignKeys[$key]); continue 2; } else { @@ -1114,16 +1120,20 @@ private function getForeignKeysInAlteredTable(TableDiff $diff) } } - if ($changed) { - $foreignKeys[$key] = new ForeignKeyConstraint($localColumns, $constraint->getForeignTableName(), $constraint->getForeignColumns(), $constraint->getName(), $constraint->getOptions()); + if (! $changed) { + continue; } + + $foreignKeys[$key] = new ForeignKeyConstraint($localColumns, $constraint->getForeignTableName(), $constraint->getForeignColumns(), $constraint->getName(), $constraint->getOptions()); } foreach ($diff->removedForeignKeys as $constraint) { $constraintName = strtolower($constraint->getName()); - if (strlen($constraintName) && isset($foreignKeys[$constraintName])) { - unset($foreignKeys[$constraintName]); + if (! strlen($constraintName) || ! isset($foreignKeys[$constraintName])) { + continue; } + + unset($foreignKeys[$constraintName]); } foreach (array_merge($diff->changedForeignKeys, $diff->addedForeignKeys) as $constraint) { @@ -1139,8 +1149,6 @@ private function getForeignKeysInAlteredTable(TableDiff $diff) } /** - * @param \Doctrine\DBAL\Schema\TableDiff $diff - * * @return array */ private function getPrimaryIndexInAlteredTable(TableDiff $diff) @@ -1148,9 +1156,11 @@ private function getPrimaryIndexInAlteredTable(TableDiff $diff) $primaryIndex = []; foreach ($this->getIndexesInAlteredTable($diff) as $index) { - if ($index->isPrimary()) { - $primaryIndex = [$index->getName() => $index]; + if (! $index->isPrimary()) { + continue; } + + $primaryIndex = [$index->getName() => $index]; } return $primaryIndex; diff --git a/lib/Doctrine/DBAL/Portability/Connection.php b/lib/Doctrine/DBAL/Portability/Connection.php index 416087842b2..a7446cf89ea 100644 --- a/lib/Doctrine/DBAL/Portability/Connection.php +++ b/lib/Doctrine/DBAL/Portability/Connection.php @@ -4,6 +4,8 @@ use Doctrine\DBAL\Cache\QueryCacheProfile; use Doctrine\DBAL\ColumnCase; +use Doctrine\DBAL\Driver\PDOConnection; +use PDO; use const CASE_LOWER; use const CASE_UPPER; use function func_get_args; @@ -12,34 +14,28 @@ * Portability wrapper for a Connection. * * @link www.doctrine-project.org - * @since 2.0 - * @author Benjamin Eberlei */ class Connection extends \Doctrine\DBAL\Connection { - const PORTABILITY_ALL = 255; - const PORTABILITY_NONE = 0; - const PORTABILITY_RTRIM = 1; - const PORTABILITY_EMPTY_TO_NULL = 4; - const PORTABILITY_FIX_CASE = 8; - - const PORTABILITY_DB2 = 13; - const PORTABILITY_ORACLE = 9; - const PORTABILITY_POSTGRESQL = 13; - const PORTABILITY_SQLITE = 13; - const PORTABILITY_OTHERVENDORS = 12; - const PORTABILITY_DRIZZLE = 13; - const PORTABILITY_SQLANYWHERE = 13; - const PORTABILITY_SQLSRV = 13; - - /** - * @var int - */ + public const PORTABILITY_ALL = 255; + public const PORTABILITY_NONE = 0; + public const PORTABILITY_RTRIM = 1; + public const PORTABILITY_EMPTY_TO_NULL = 4; + public const PORTABILITY_FIX_CASE = 8; + + public const PORTABILITY_DB2 = 13; + public const PORTABILITY_ORACLE = 9; + public const PORTABILITY_POSTGRESQL = 13; + public const PORTABILITY_SQLITE = 13; + public const PORTABILITY_OTHERVENDORS = 12; + public const PORTABILITY_DRIZZLE = 13; + public const PORTABILITY_SQLANYWHERE = 13; + public const PORTABILITY_SQLSRV = 13; + + /** @var int */ private $portability = self::PORTABILITY_NONE; - /** - * @var int - */ + /** @var int */ private $case; /** @@ -51,32 +47,32 @@ public function connect() if ($ret) { $params = $this->getParams(); if (isset($params['portability'])) { - if ($this->getDatabasePlatform()->getName() === "oracle") { - $params['portability'] = $params['portability'] & self::PORTABILITY_ORACLE; - } elseif ($this->getDatabasePlatform()->getName() === "postgresql") { - $params['portability'] = $params['portability'] & self::PORTABILITY_POSTGRESQL; - } elseif ($this->getDatabasePlatform()->getName() === "sqlite") { - $params['portability'] = $params['portability'] & self::PORTABILITY_SQLITE; - } elseif ($this->getDatabasePlatform()->getName() === "drizzle") { - $params['portability'] = $params['portability'] & self::PORTABILITY_DRIZZLE; + if ($this->getDatabasePlatform()->getName() === 'oracle') { + $params['portability'] &= self::PORTABILITY_ORACLE; + } elseif ($this->getDatabasePlatform()->getName() === 'postgresql') { + $params['portability'] &= self::PORTABILITY_POSTGRESQL; + } elseif ($this->getDatabasePlatform()->getName() === 'sqlite') { + $params['portability'] &= self::PORTABILITY_SQLITE; + } elseif ($this->getDatabasePlatform()->getName() === 'drizzle') { + $params['portability'] &= self::PORTABILITY_DRIZZLE; } elseif ($this->getDatabasePlatform()->getName() === 'sqlanywhere') { - $params['portability'] = $params['portability'] & self::PORTABILITY_SQLANYWHERE; + $params['portability'] &= self::PORTABILITY_SQLANYWHERE; } elseif ($this->getDatabasePlatform()->getName() === 'db2') { - $params['portability'] = $params['portability'] & self::PORTABILITY_DB2; + $params['portability'] &= self::PORTABILITY_DB2; } elseif ($this->getDatabasePlatform()->getName() === 'mssql') { - $params['portability'] = $params['portability'] & self::PORTABILITY_SQLSRV; + $params['portability'] &= self::PORTABILITY_SQLSRV; } else { - $params['portability'] = $params['portability'] & self::PORTABILITY_OTHERVENDORS; + $params['portability'] &= self::PORTABILITY_OTHERVENDORS; } $this->portability = $params['portability']; } if (isset($params['fetch_case']) && $this->portability & self::PORTABILITY_FIX_CASE) { - if ($this->_conn instanceof \Doctrine\DBAL\Driver\PDOConnection) { + if ($this->_conn instanceof PDOConnection) { // make use of c-level support for case handling - $this->_conn->setAttribute(\PDO::ATTR_CASE, $params['fetch_case']); + $this->_conn->setAttribute(PDO::ATTR_CASE, $params['fetch_case']); } else { - $this->case = ($params['fetch_case'] === ColumnCase::LOWER) ? CASE_LOWER : CASE_UPPER; + $this->case = $params['fetch_case'] === ColumnCase::LOWER ? CASE_LOWER : CASE_UPPER; } } } @@ -103,7 +99,7 @@ public function getFetchCase() /** * {@inheritdoc} */ - public function executeQuery($query, array $params = [], $types = [], QueryCacheProfile $qcp = null) + public function executeQuery($query, array $params = [], $types = [], ?QueryCacheProfile $qcp = null) { $stmt = new Statement(parent::executeQuery($query, $params, $types, $qcp), $this); $stmt->setFetchMode($this->defaultFetchMode); diff --git a/lib/Doctrine/DBAL/Portability/Statement.php b/lib/Doctrine/DBAL/Portability/Statement.php index f2dc61d8a24..bf137d1eae1 100644 --- a/lib/Doctrine/DBAL/Portability/Statement.php +++ b/lib/Doctrine/DBAL/Portability/Statement.php @@ -5,8 +5,9 @@ use Doctrine\DBAL\Driver\StatementIterator; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; +use IteratorAggregate; +use PDO; use function array_change_key_case; -use function is_null; use function is_string; use function rtrim; @@ -14,42 +15,31 @@ * Portability wrapper for a Statement. * * @link www.doctrine-project.org - * @since 2.0 - * @author Benjamin Eberlei */ -class Statement implements \IteratorAggregate, \Doctrine\DBAL\Driver\Statement +class Statement implements IteratorAggregate, \Doctrine\DBAL\Driver\Statement { - /** - * @var int - */ + /** @var int */ private $portability; - /** - * @var \Doctrine\DBAL\Driver\Statement - */ + /** @var \Doctrine\DBAL\Driver\Statement */ private $stmt; - /** - * @var int - */ + /** @var int */ private $case; - /** - * @var int - */ + /** @var int */ private $defaultFetchMode = FetchMode::MIXED; /** * Wraps Statement and applies portability measures. * - * @param \Doctrine\DBAL\Driver\Statement $stmt - * @param \Doctrine\DBAL\Portability\Connection $conn + * @param \Doctrine\DBAL\Driver\Statement $stmt */ public function __construct($stmt, Connection $conn) { - $this->stmt = $stmt; + $this->stmt = $stmt; $this->portability = $conn->getPortability(); - $this->case = $conn->getFetchCase(); + $this->case = $conn->getFetchCase(); } /** @@ -129,7 +119,7 @@ public function getIterator() /** * {@inheritdoc} */ - public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) + public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0) { $fetchMode = $fetchMode ?: $this->defaultFetchMode; @@ -163,7 +153,7 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n && ($fetchMode === FetchMode::ASSOCIATIVE || $fetchMode === FetchMode::MIXED) && ($this->portability & Connection::PORTABILITY_FIX_CASE); - if ( ! $iterateRow && !$fixCase) { + if (! $iterateRow && ! $fixCase) { return $rows; } @@ -195,7 +185,7 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n */ protected function fixRow($row, $iterateRow, $fixCase) { - if ( ! $row) { + if (! $row) { return $row; } diff --git a/lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php b/lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php index 23db991cecd..6f2c06621f8 100644 --- a/lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php +++ b/lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php @@ -2,6 +2,7 @@ namespace Doctrine\DBAL\Query\Expression; +use Countable; use function count; use function implode; @@ -9,21 +10,18 @@ * Composite expression is responsible to build a group of similar expression. * * @link www.doctrine-project.org - * @since 2.1 - * @author Guilherme Blanco - * @author Benjamin Eberlei */ -class CompositeExpression implements \Countable +class CompositeExpression implements Countable { /** * Constant that represents an AND composite expression. */ - const TYPE_AND = 'AND'; + public const TYPE_AND = 'AND'; /** * Constant that represents an OR composite expression. */ - const TYPE_OR = 'OR'; + public const TYPE_OR = 'OR'; /** * The instance type of composite expression. @@ -40,8 +38,6 @@ class CompositeExpression implements \Countable private $parts = []; /** - * Constructor. - * * @param string $type Instance type of composite expression. * @param array $parts Composition of expressions to be joined on composite expression. */ @@ -81,7 +77,7 @@ public function add($part) return $this; } - if ($part instanceof self && 0 === count($part)) { + if ($part instanceof self && count($part) === 0) { return $this; } diff --git a/lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php b/lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php index b9e8559f000..19742c9fa04 100644 --- a/lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php +++ b/lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php @@ -13,30 +13,27 @@ * ExpressionBuilder class is responsible to dynamically create SQL query parts. * * @link www.doctrine-project.org - * @since 2.1 - * @author Guilherme Blanco - * @author Benjamin Eberlei */ class ExpressionBuilder { - const EQ = '='; - const NEQ = '<>'; - const LT = '<'; - const LTE = '<='; - const GT = '>'; - const GTE = '>='; + public const EQ = '='; + public const NEQ = '<>'; + public const LT = '<'; + public const LTE = '<='; + public const GT = '>'; + public const GTE = '>='; /** * The DBAL Connection. * - * @var \Doctrine\DBAL\Connection + * @var Connection */ private $connection; /** * Initializes a new ExpressionBuilder. * - * @param \Doctrine\DBAL\Connection $connection The DBAL Connection. + * @param Connection $connection The DBAL Connection. */ public function __construct(Connection $connection) { @@ -55,7 +52,7 @@ public function __construct(Connection $connection) * @param mixed $x Optional clause. Defaults = null, but requires * at least one defined when converting to string. * - * @return \Doctrine\DBAL\Query\Expression\CompositeExpression + * @return CompositeExpression */ public function andX($x = null) { @@ -74,7 +71,7 @@ public function andX($x = null) * @param mixed $x Optional clause. Defaults = null, but requires * at least one defined when converting to string. * - * @return \Doctrine\DBAL\Query\Expression\CompositeExpression + * @return CompositeExpression */ public function orX($x = null) { @@ -272,7 +269,7 @@ public function notLike($x, $y/*, ?string $escapeChar = null */) */ public function in($x, $y) { - return $this->comparison($x, 'IN', '('.implode(', ', (array) $y).')'); + return $this->comparison($x, 'IN', '(' . implode(', ', (array) $y) . ')'); } /** @@ -285,7 +282,7 @@ public function in($x, $y) */ public function notIn($x, $y) { - return $this->comparison($x, 'NOT IN', '('.implode(', ', (array) $y).')'); + return $this->comparison($x, 'NOT IN', '(' . implode(', ', (array) $y) . ')'); } /** diff --git a/lib/Doctrine/DBAL/Query/QueryBuilder.php b/lib/Doctrine/DBAL/Query/QueryBuilder.php index dc54ac06e1d..e8efa12b1e0 100644 --- a/lib/Doctrine/DBAL/Query/QueryBuilder.php +++ b/lib/Doctrine/DBAL/Query/QueryBuilder.php @@ -2,9 +2,11 @@ namespace Doctrine\DBAL\Query; +use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Query\Expression\CompositeExpression; -use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Query\Expression\ExpressionBuilder; use function array_key_exists; use function array_keys; use function array_unshift; @@ -12,7 +14,6 @@ use function func_num_args; use function implode; use function is_array; -use function is_null; use function is_object; use function key; use function strtoupper; @@ -29,36 +30,31 @@ * even if some vendors such as MySQL support it. * * @link www.doctrine-project.org - * @since 2.1 - * @author Guilherme Blanco - * @author Benjamin Eberlei */ class QueryBuilder { /* * The query types. */ - const SELECT = 0; - const DELETE = 1; - const UPDATE = 2; - const INSERT = 3; + public const SELECT = 0; + public const DELETE = 1; + public const UPDATE = 2; + public const INSERT = 3; /* * The builder states. */ - const STATE_DIRTY = 0; - const STATE_CLEAN = 1; + public const STATE_DIRTY = 0; + public const STATE_CLEAN = 1; /** * The DBAL Connection. * - * @var \Doctrine\DBAL\Connection + * @var Connection */ private $connection; - /** - * @var array The array of SQL parts collected. - */ + /** @var array The array of SQL parts collected. */ private $sqlParts = [ 'select' => [], 'from' => [], @@ -130,7 +126,7 @@ class QueryBuilder /** * Initializes a new QueryBuilder. * - * @param \Doctrine\DBAL\Connection $connection The DBAL Connection. + * @param Connection $connection The DBAL Connection. */ public function __construct(Connection $connection) { @@ -151,7 +147,7 @@ public function __construct(Connection $connection) * For more complex expression construction, consider storing the expression * builder object in a local variable. * - * @return \Doctrine\DBAL\Query\Expression\ExpressionBuilder + * @return ExpressionBuilder */ public function expr() { @@ -171,7 +167,7 @@ public function getType() /** * Gets the associated DBAL Connection for this query builder. * - * @return \Doctrine\DBAL\Connection + * @return Connection */ public function getConnection() { @@ -194,11 +190,11 @@ public function getState() * Uses {@see Connection::executeQuery} for select statements and {@see Connection::executeUpdate} * for insert, update and delete statements. * - * @return \Doctrine\DBAL\Driver\Statement|int + * @return Statement|int */ public function execute() { - if ($this->type == self::SELECT) { + if ($this->type === self::SELECT) { return $this->connection->executeQuery($this->getSQL(), $this->params, $this->paramTypes); } @@ -242,7 +238,7 @@ public function getSQL() } $this->state = self::STATE_CLEAN; - $this->sql = $sql; + $this->sql = $sql; return $sql; } @@ -297,7 +293,7 @@ public function setParameter($key, $value, $type = null) public function setParameters(array $params, array $types = []) { $this->paramTypes = $types; - $this->params = $params; + $this->params = $params; return $this; } @@ -355,7 +351,7 @@ public function getParameterType($key) */ public function setFirstResult($firstResult) { - $this->state = self::STATE_DIRTY; + $this->state = self::STATE_DIRTY; $this->firstResult = $firstResult; return $this; @@ -381,7 +377,7 @@ public function getFirstResult() */ public function setMaxResults($maxResults) { - $this->state = self::STATE_DIRTY; + $this->state = self::STATE_DIRTY; $this->maxResults = $maxResults; return $this; @@ -412,22 +408,22 @@ public function getMaxResults() */ public function add($sqlPartName, $sqlPart, $append = false) { - $isArray = is_array($sqlPart); + $isArray = is_array($sqlPart); $isMultiple = is_array($this->sqlParts[$sqlPartName]); - if ($isMultiple && !$isArray) { + if ($isMultiple && ! $isArray) { $sqlPart = [$sqlPart]; } $this->state = self::STATE_DIRTY; if ($append) { - if ($sqlPartName == "orderBy" || $sqlPartName == "groupBy" || $sqlPartName == "select" || $sqlPartName == "set") { + if ($sqlPartName === 'orderBy' || $sqlPartName === 'groupBy' || $sqlPartName === 'select' || $sqlPartName === 'set') { foreach ($sqlPart as $part) { $this->sqlParts[$sqlPartName][] = $part; } } elseif ($isArray && is_array($sqlPart[key($sqlPart)])) { - $key = key($sqlPart); + $key = key($sqlPart); $this->sqlParts[$sqlPartName][$key][] = $sqlPart[$key]; } elseif ($isMultiple) { $this->sqlParts[$sqlPartName][] = $sqlPart; @@ -519,13 +515,13 @@ public function delete($delete = null, $alias = null) { $this->type = self::DELETE; - if ( ! $delete) { + if (! $delete) { return $this; } return $this->add('from', [ 'table' => $delete, - 'alias' => $alias + 'alias' => $alias, ]); } @@ -549,13 +545,13 @@ public function update($update = null, $alias = null) { $this->type = self::UPDATE; - if ( ! $update) { + if (! $update) { return $this; } return $this->add('from', [ 'table' => $update, - 'alias' => $alias + 'alias' => $alias, ]); } @@ -582,12 +578,12 @@ public function insert($insert = null) { $this->type = self::INSERT; - if ( ! $insert) { + if (! $insert) { return $this; } return $this->add('from', [ - 'table' => $insert + 'table' => $insert, ]); } @@ -610,7 +606,7 @@ public function from($from, $alias = null) { return $this->add('from', [ 'table' => $from, - 'alias' => $alias + 'alias' => $alias, ], true); } @@ -660,8 +656,8 @@ public function innerJoin($fromAlias, $join, $alias, $condition = null) 'joinType' => 'inner', 'joinTable' => $join, 'joinAlias' => $alias, - 'joinCondition' => $condition - ] + 'joinCondition' => $condition, + ], ], true); } @@ -689,8 +685,8 @@ public function leftJoin($fromAlias, $join, $alias, $condition = null) 'joinType' => 'left', 'joinTable' => $join, 'joinAlias' => $alias, - 'joinCondition' => $condition - ] + 'joinCondition' => $condition, + ], ], true); } @@ -718,8 +714,8 @@ public function rightJoin($fromAlias, $join, $alias, $condition = null) 'joinType' => 'right', 'joinTable' => $join, 'joinAlias' => $alias, - 'joinCondition' => $condition - ] + 'joinCondition' => $condition, + ], ], true); } @@ -740,7 +736,7 @@ public function rightJoin($fromAlias, $join, $alias, $condition = null) */ public function set($key, $value) { - return $this->add('set', $key .' = ' . $value, true); + return $this->add('set', $key . ' = ' . $value, true); } /** @@ -771,7 +767,7 @@ public function set($key, $value) */ public function where($predicates) { - if ( ! (func_num_args() == 1 && $predicates instanceof CompositeExpression)) { + if (! (func_num_args() === 1 && $predicates instanceof CompositeExpression)) { $predicates = new CompositeExpression(CompositeExpression::TYPE_AND, func_get_args()); } @@ -790,15 +786,15 @@ public function where($predicates) * ->andWhere('u.is_active = 1'); * * + * @see where() + * * @param mixed $where The query restrictions. * * @return $this This QueryBuilder instance. - * - * @see where() */ public function andWhere($where) { - $args = func_get_args(); + $args = func_get_args(); $where = $this->getQueryPart('where'); if ($where instanceof CompositeExpression && $where->getType() === CompositeExpression::TYPE_AND) { @@ -823,15 +819,15 @@ public function andWhere($where) * ->orWhere('u.id = 2'); * * + * @see where() + * * @param mixed $where The WHERE statement. * * @return $this This QueryBuilder instance. - * - * @see where() */ public function orWhere($where) { - $args = func_get_args(); + $args = func_get_args(); $where = $this->getQueryPart('where'); if ($where instanceof CompositeExpression && $where->getType() === CompositeExpression::TYPE_OR) { @@ -957,7 +953,7 @@ public function values(array $values) */ public function having($having) { - if ( ! (func_num_args() == 1 && $having instanceof CompositeExpression)) { + if (! (func_num_args() === 1 && $having instanceof CompositeExpression)) { $having = new CompositeExpression(CompositeExpression::TYPE_AND, func_get_args()); } @@ -974,7 +970,7 @@ public function having($having) */ public function andHaving($having) { - $args = func_get_args(); + $args = func_get_args(); $having = $this->getQueryPart('having'); if ($having instanceof CompositeExpression && $having->getType() === CompositeExpression::TYPE_AND) { @@ -997,7 +993,7 @@ public function andHaving($having) */ public function orHaving($having) { - $args = func_get_args(); + $args = func_get_args(); $having = $this->getQueryPart('having'); if ($having instanceof CompositeExpression && $having->getType() === CompositeExpression::TYPE_OR) { @@ -1099,7 +1095,7 @@ public function resetQueryPart($queryPartName) /** * @return string * - * @throws \Doctrine\DBAL\Query\QueryException + * @throws QueryException */ private function getSQLForSelect() { @@ -1127,16 +1123,16 @@ private function getSQLForSelect() */ private function getFromClauses() { - $fromClauses = []; + $fromClauses = []; $knownAliases = []; // Loop through all FROM clauses foreach ($this->sqlParts['from'] as $from) { if ($from['alias'] === null) { - $tableSql = $from['table']; + $tableSql = $from['table']; $tableReference = $from['table']; } else { - $tableSql = $from['table'] . ' ' . $from['alias']; + $tableSql = $from['table'] . ' ' . $from['alias']; $tableReference = $from['alias']; } @@ -1158,7 +1154,7 @@ private function getFromClauses() private function verifyAllAliasesAreKnown(array $knownAliases) { foreach ($this->sqlParts['join'] as $fromAlias => $joins) { - if ( ! isset($knownAliases[$fromAlias])) { + if (! isset($knownAliases[$fromAlias])) { throw QueryException::unknownAlias($fromAlias, array_keys($knownAliases)); } } @@ -1192,11 +1188,9 @@ private function getSQLForInsert() private function getSQLForUpdate() { $table = $this->sqlParts['from']['table'] . ($this->sqlParts['from']['alias'] ? ' ' . $this->sqlParts['from']['alias'] : ''); - $query = 'UPDATE ' . $table - . ' SET ' . implode(", ", $this->sqlParts['set']) + return 'UPDATE ' . $table + . ' SET ' . implode(', ', $this->sqlParts['set']) . ($this->sqlParts['where'] !== null ? ' WHERE ' . ((string) $this->sqlParts['where']) : ''); - - return $query; } /** @@ -1207,9 +1201,7 @@ private function getSQLForUpdate() private function getSQLForDelete() { $table = $this->sqlParts['from']['table'] . ($this->sqlParts['from']['alias'] ? ' ' . $this->sqlParts['from']['alias'] : ''); - $query = 'DELETE FROM ' . $table . ($this->sqlParts['where'] !== null ? ' WHERE ' . ((string) $this->sqlParts['where']) : ''); - - return $query; + return 'DELETE FROM ' . $table . ($this->sqlParts['where'] !== null ? ' WHERE ' . ((string) $this->sqlParts['where']) : ''); } /** @@ -1243,7 +1235,6 @@ public function __toString() * $stmt = $q->executeQuery(); // executed with 'id = 2' * * - * @license New BSD License * @link http://www.zetacomponents.org * * @param mixed $value @@ -1256,7 +1247,7 @@ public function createNamedParameter($value, $type = ParameterType::STRING, $pla { if ($placeHolder === null) { $this->boundCounter++; - $placeHolder = ":dcValue" . $this->boundCounter; + $placeHolder = ':dcValue' . $this->boundCounter; } $this->setParameter(substr($placeHolder, 1), $value, $type); @@ -1290,7 +1281,7 @@ public function createPositionalParameter($value, $type = ParameterType::STRING) $this->boundCounter++; $this->setParameter($this->boundCounter, $value, $type); - return "?"; + return '?'; } /** @@ -1310,7 +1301,7 @@ private function getSQLForJoins($fromAlias, array &$knownAliases) if (array_key_exists($join['joinAlias'], $knownAliases)) { throw QueryException::nonUniqueAlias($join['joinAlias'], array_keys($knownAliases)); } - $sql .= ' ' . strtoupper($join['joinType']) + $sql .= ' ' . strtoupper($join['joinType']) . ' JOIN ' . $join['joinTable'] . ' ' . $join['joinAlias'] . ' ON ' . ((string) $join['joinCondition']); $knownAliases[$join['joinAlias']] = true; @@ -1334,9 +1325,11 @@ public function __clone() foreach ($this->sqlParts as $part => $elements) { if (is_array($this->sqlParts[$part])) { foreach ($this->sqlParts[$part] as $idx => $element) { - if (is_object($element)) { - $this->sqlParts[$part][$idx] = clone $element; + if (! is_object($element)) { + continue; } + + $this->sqlParts[$part][$idx] = clone $element; } } elseif (is_object($elements)) { $this->sqlParts[$part] = clone $elements; @@ -1344,9 +1337,11 @@ public function __clone() } foreach ($this->params as $name => $param) { - if (is_object($param)) { - $this->params[$name] = clone $param; + if (! is_object($param)) { + continue; } + + $this->params[$name] = clone $param; } } } diff --git a/lib/Doctrine/DBAL/Query/QueryException.php b/lib/Doctrine/DBAL/Query/QueryException.php index ef12dca1a62..266852c7da0 100644 --- a/lib/Doctrine/DBAL/Query/QueryException.php +++ b/lib/Doctrine/DBAL/Query/QueryException.php @@ -5,9 +5,6 @@ use Doctrine\DBAL\DBALException; use function implode; -/** - * @since 2.1.4 - */ class QueryException extends DBALException { /** @@ -19,8 +16,8 @@ class QueryException extends DBALException public static function unknownAlias($alias, $registeredAliases) { return new self("The given alias '" . $alias . "' is not part of " . - "any FROM or JOIN clause table. The currently registered " . - "aliases are: " . implode(", ", $registeredAliases) . "."); + 'any FROM or JOIN clause table. The currently registered ' . + 'aliases are: ' . implode(', ', $registeredAliases) . '.'); } /** @@ -32,7 +29,7 @@ public static function unknownAlias($alias, $registeredAliases) public static function nonUniqueAlias($alias, $registeredAliases) { return new self("The given alias '" . $alias . "' is not unique " . - "in FROM and JOIN clause table. The currently registered " . - "aliases are: " . implode(", ", $registeredAliases) . "."); + 'in FROM and JOIN clause table. The currently registered ' . + 'aliases are: ' . implode(', ', $registeredAliases) . '.'); } } diff --git a/lib/Doctrine/DBAL/SQLParserUtils.php b/lib/Doctrine/DBAL/SQLParserUtils.php index 22883a2b9f0..5e8196b0b0b 100644 --- a/lib/Doctrine/DBAL/SQLParserUtils.php +++ b/lib/Doctrine/DBAL/SQLParserUtils.php @@ -22,18 +22,16 @@ * Utility class that parses sql statements with regard to types and parameters. * * @link www.doctrine-project.org - * @since 2.0 - * @author Benjamin Eberlei */ class SQLParserUtils { - const POSITIONAL_TOKEN = '\?'; - const NAMED_TOKEN = '(? $needlePos) { - if ( ! isset($arrayPositions[$needle])) { + if (! isset($arrayPositions[$needle])) { continue; } @@ -145,8 +143,8 @@ public static function expandListParameters($query, $params, $types) array_slice($types, $needle + 1) ); - $expandStr = $count ? implode(", ", array_fill(0, $count, "?")) : 'NULL'; - $query = substr($query, 0, $needlePos) . $expandStr . substr($query, $needlePos + 1); + $expandStr = $count ? implode(', ', array_fill(0, $count, '?')) : 'NULL'; + $query = substr($query, 0, $needlePos) . $expandStr . substr($query, $needlePos + 1); $paramOffset += ($count - 1); // Grows larger by number of parameters minus the replaced needle. $queryOffset += (strlen($expandStr) - 1); @@ -163,7 +161,7 @@ public static function expandListParameters($query, $params, $types) $paramLen = strlen($paramName) + 1; $value = static::extractParam($paramName, $params, true); - if ( ! isset($arrayPositions[$paramName]) && ! isset($arrayPositions[':' . $paramName])) { + if (! isset($arrayPositions[$paramName]) && ! isset($arrayPositions[':' . $paramName])) { $pos += $queryOffset; $queryOffset -= ($paramLen - 1); $paramsOrd[] = $value; @@ -173,8 +171,8 @@ public static function expandListParameters($query, $params, $types) continue; } - $count = count($value); - $expandStr = $count > 0 ? implode(', ', array_fill(0, $count, '?')) : 'NULL'; + $count = count($value); + $expandStr = $count > 0 ? implode(', ', array_fill(0, $count, '?')) : 'NULL'; foreach ($value as $val) { $paramsOrd[] = $val; @@ -198,6 +196,7 @@ public static function expandListParameters($query, $params, $types) * 1 => offset of fragment in $statement * * @param string $statement + * * @return array */ private static function getUnquotedStatementFragments($statement) @@ -217,8 +216,9 @@ private static function getUnquotedStatementFragments($statement) * @param bool $isParam * @param mixed $defaultValue An optional default value. If omitted, an exception is thrown * - * @throws SQLParserUtilsException * @return mixed + * + * @throws SQLParserUtilsException */ private static function extractParam($paramName, $paramsOrTypes, $isParam, $defaultValue = null) { @@ -231,7 +231,7 @@ private static function extractParam($paramName, $paramsOrTypes, $isParam, $defa return $paramsOrTypes[':' . $paramName]; } - if (null !== $defaultValue) { + if ($defaultValue !== null) { return $defaultValue; } diff --git a/lib/Doctrine/DBAL/SQLParserUtilsException.php b/lib/Doctrine/DBAL/SQLParserUtilsException.php index 4d17d226757..271a9929a93 100644 --- a/lib/Doctrine/DBAL/SQLParserUtilsException.php +++ b/lib/Doctrine/DBAL/SQLParserUtilsException.php @@ -7,10 +7,7 @@ /** * Doctrine\DBAL\ConnectionException * - * @license http://www.opensource.org/licenses/mit-license.php MIT * @link www.doctrine-project.org - * @since 2.4 - * @author Lars Strojny */ class SQLParserUtilsException extends DBALException { diff --git a/lib/Doctrine/DBAL/Schema/AbstractAsset.php b/lib/Doctrine/DBAL/Schema/AbstractAsset.php index 551192d9b05..b97d0371c2c 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractAsset.php +++ b/lib/Doctrine/DBAL/Schema/AbstractAsset.php @@ -21,14 +21,10 @@ * array($tableName => Table($tableName)); if you want to rename the table, you have to make sure * * @link www.doctrine-project.org - * @since 2.0 - * @author Benjamin Eberlei */ abstract class AbstractAsset { - /** - * @var string - */ + /** @var string */ protected $_name; /** @@ -38,9 +34,7 @@ abstract class AbstractAsset */ protected $_namespace = null; - /** - * @var bool - */ + /** @var bool */ protected $_quoted = false; /** @@ -54,12 +48,12 @@ protected function _setName($name) { if ($this->isIdentifierQuoted($name)) { $this->_quoted = true; - $name = $this->trimQuotes($name); + $name = $this->trimQuotes($name); } - if (strpos($name, ".") !== false) { - $parts = explode(".", $name); + if (strpos($name, '.') !== false) { + $parts = explode('.', $name); $this->_namespace = $parts[0]; - $name = $parts[1]; + $name = $parts[1]; } $this->_name = $name; } @@ -73,7 +67,7 @@ protected function _setName($name) */ public function isInDefaultNamespace($defaultNamespaceName) { - return $this->_namespace == $defaultNamespaceName || $this->_namespace === null; + return $this->_namespace === $defaultNamespaceName || $this->_namespace === null; } /** @@ -99,7 +93,7 @@ public function getNamespaceName() public function getShortestName($defaultNamespaceName) { $shortestName = $this->getName(); - if ($this->_namespace == $defaultNamespaceName) { + if ($this->_namespace === $defaultNamespaceName) { $shortestName = $this->_name; } @@ -122,8 +116,8 @@ public function getShortestName($defaultNamespaceName) public function getFullQualifiedName($defaultNamespaceName) { $name = $this->getName(); - if ( ! $this->_namespace) { - $name = $defaultNamespaceName . "." . $name; + if (! $this->_namespace) { + $name = $defaultNamespaceName . '.' . $name; } return strtolower($name); @@ -148,7 +142,7 @@ public function isQuoted() */ protected function isIdentifierQuoted($identifier) { - return (isset($identifier[0]) && ($identifier[0] == '`' || $identifier[0] == '"' || $identifier[0] == '[')); + return isset($identifier[0]) && ($identifier[0] === '`' || $identifier[0] === '"' || $identifier[0] === '['); } /** @@ -171,7 +165,7 @@ protected function trimQuotes($identifier) public function getName() { if ($this->_namespace) { - return $this->_namespace . "." . $this->_name; + return $this->_namespace . '.' . $this->_name; } return $this->_name; @@ -181,19 +175,17 @@ public function getName() * Gets the quoted representation of this asset but only if it was defined with one. Otherwise * return the plain unquoted value as inserted. * - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform - * * @return string */ public function getQuotedName(AbstractPlatform $platform) { $keywords = $platform->getReservedKeywordsList(); - $parts = explode(".", $this->getName()); + $parts = explode('.', $this->getName()); foreach ($parts as $k => $v) { - $parts[$k] = ($this->_quoted || $keywords->isKeyword($v)) ? $platform->quoteIdentifier($v) : $v; + $parts[$k] = $this->_quoted || $keywords->isKeyword($v) ? $platform->quoteIdentifier($v) : $v; } - return implode(".", $parts); + return implode('.', $parts); } /** @@ -209,9 +201,9 @@ public function getQuotedName(AbstractPlatform $platform) * * @return string */ - protected function _generateIdentifierName($columnNames, $prefix='', $maxSize=30) + protected function _generateIdentifierName($columnNames, $prefix = '', $maxSize = 30) { - $hash = implode("", array_map(function ($column) { + $hash = implode('', array_map(static function ($column) { return dechex(crc32($column)); }, $columnNames)); diff --git a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php index d160d6c6b63..becf2e4bf82 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php @@ -2,19 +2,22 @@ namespace Doctrine\DBAL\Schema; -use Doctrine\DBAL\Events; +use Doctrine\DBAL\Connection; +use Doctrine\DBAL\ConnectionException; +use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Event\SchemaColumnDefinitionEventArgs; use Doctrine\DBAL\Event\SchemaIndexDefinitionEventArgs; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Events; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Throwable; use function array_filter; +use function array_intersect; use function array_map; use function array_values; use function call_user_func_array; use function count; use function func_get_args; use function is_array; -use function is_null; use function preg_match; use function str_replace; use function strtolower; @@ -22,37 +25,27 @@ /** * Base class for schema managers. Schema managers are used to inspect and/or * modify the database schema/structure. - * - * @author Konsta Vesterinen - * @author Lukas Smith (PEAR MDB2 library) - * @author Roman Borschel - * @author Jonathan H. Wage - * @author Benjamin Eberlei - * @since 2.0 */ abstract class AbstractSchemaManager { /** * Holds instance of the Doctrine connection for this schema manager. * - * @var \Doctrine\DBAL\Connection + * @var Connection */ protected $_conn; /** * Holds instance of the database platform used for this schema manager. * - * @var \Doctrine\DBAL\Platforms\AbstractPlatform + * @var AbstractPlatform */ protected $_platform; /** * Constructor. Accepts the Connection instance to manage the schema for. - * - * @param \Doctrine\DBAL\Connection $conn - * @param \Doctrine\DBAL\Platforms\AbstractPlatform|null $platform */ - public function __construct(\Doctrine\DBAL\Connection $conn, AbstractPlatform $platform = null) + public function __construct(Connection $conn, ?AbstractPlatform $platform = null) { $this->_conn = $conn; $this->_platform = $platform ?: $this->_conn->getDatabasePlatform(); @@ -61,7 +54,7 @@ public function __construct(\Doctrine\DBAL\Connection $conn, AbstractPlatform $p /** * Returns the associated platform. * - * @return \Doctrine\DBAL\Platforms\AbstractPlatform + * @return AbstractPlatform */ public function getDatabasePlatform() { @@ -82,14 +75,14 @@ public function getDatabasePlatform() */ public function tryMethod() { - $args = func_get_args(); + $args = func_get_args(); $method = $args[0]; unset($args[0]); $args = array_values($args); try { return call_user_func_array([$this, $method], $args); - } catch (\Exception $e) { + } catch (Throwable $e) { return false; } } @@ -127,7 +120,7 @@ public function listNamespaceNames() * * @param string|null $database * - * @return \Doctrine\DBAL\Schema\Sequence[] + * @return Sequence[] */ public function listSequences($database = null) { @@ -154,11 +147,11 @@ public function listSequences($database = null) * @param string $table The name of the table. * @param string|null $database * - * @return \Doctrine\DBAL\Schema\Column[] + * @return Column[] */ public function listTableColumns($table, $database = null) { - if ( ! $database) { + if (! $database) { $database = $this->_conn->getDatabase(); } @@ -176,7 +169,7 @@ public function listTableColumns($table, $database = null) * * @param string $table The name of the table. * - * @return \Doctrine\DBAL\Schema\Index[] + * @return Index[] */ public function listTableIndexes($table) { @@ -198,7 +191,7 @@ public function tablesExist($tableNames) { $tableNames = array_map('strtolower', (array) $tableNames); - return count($tableNames) == count(\array_intersect($tableNames, array_map('strtolower', $this->listTableNames()))); + return count($tableNames) === count(array_intersect($tableNames, array_map('strtolower', $this->listTableNames()))); } /** @@ -210,7 +203,7 @@ public function listTableNames() { $sql = $this->_platform->getListTablesSQL(); - $tables = $this->_conn->fetchAll($sql); + $tables = $this->_conn->fetchAll($sql); $tableNames = $this->_getPortableTablesList($tables); return $this->filterAssetNames($tableNames); @@ -227,13 +220,13 @@ public function listTableNames() protected function filterAssetNames($assetNames) { $filterExpr = $this->getFilterSchemaAssetsExpression(); - if ( ! $filterExpr) { + if (! $filterExpr) { return $assetNames; } return array_values( - array_filter($assetNames, function ($assetName) use ($filterExpr) { - $assetName = ($assetName instanceof AbstractAsset) ? $assetName->getName() : $assetName; + array_filter($assetNames, static function ($assetName) use ($filterExpr) { + $assetName = $assetName instanceof AbstractAsset ? $assetName->getName() : $assetName; return preg_match($filterExpr, $assetName); }) @@ -251,7 +244,7 @@ protected function getFilterSchemaAssetsExpression() /** * Lists the tables for this connection. * - * @return \Doctrine\DBAL\Schema\Table[] + * @return Table[] */ public function listTables() { @@ -268,11 +261,11 @@ public function listTables() /** * @param string $tableName * - * @return \Doctrine\DBAL\Schema\Table + * @return Table */ public function listTableDetails($tableName) { - $columns = $this->listTableColumns($tableName); + $columns = $this->listTableColumns($tableName); $foreignKeys = []; if ($this->_platform->supportsForeignKeyConstraints()) { $foreignKeys = $this->listTableForeignKeys($tableName); @@ -285,13 +278,13 @@ public function listTableDetails($tableName) /** * Lists the views this connection has. * - * @return \Doctrine\DBAL\Schema\View[] + * @return View[] */ public function listViews() { $database = $this->_conn->getDatabase(); - $sql = $this->_platform->getListViewsSQL($database); - $views = $this->_conn->fetchAll($sql); + $sql = $this->_platform->getListViewsSQL($database); + $views = $this->_conn->fetchAll($sql); return $this->_getPortableViewsList($views); } @@ -302,14 +295,14 @@ public function listViews() * @param string $table The name of the table. * @param string|null $database * - * @return \Doctrine\DBAL\Schema\ForeignKeyConstraint[] + * @return ForeignKeyConstraint[] */ public function listTableForeignKeys($table, $database = null) { if ($database === null) { $database = $this->_conn->getDatabase(); } - $sql = $this->_platform->getListTableForeignKeysSQL($table, $database); + $sql = $this->_platform->getListTableForeignKeysSQL($table, $database); $tableForeignKeys = $this->_conn->fetchAll($sql); return $this->_getPortableTableForeignKeysList($tableForeignKeys); @@ -346,8 +339,8 @@ public function dropTable($tableName) /** * Drops the index from the given table. * - * @param \Doctrine\DBAL\Schema\Index|string $index The name of the index. - * @param \Doctrine\DBAL\Schema\Table|string $table The name of the table. + * @param Index|string $index The name of the index. + * @param Table|string $table The name of the table. * * @return void */ @@ -363,8 +356,7 @@ public function dropIndex($index, $table) /** * Drops the constraint from the given table. * - * @param \Doctrine\DBAL\Schema\Constraint $constraint - * @param \Doctrine\DBAL\Schema\Table|string $table The name of the table. + * @param Table|string $table The name of the table. * * @return void */ @@ -376,8 +368,8 @@ public function dropConstraint(Constraint $constraint, $table) /** * Drops a foreign key from a table. * - * @param \Doctrine\DBAL\Schema\ForeignKeyConstraint|string $foreignKey The name of the foreign key. - * @param \Doctrine\DBAL\Schema\Table|string $table The name of the table with the foreign key. + * @param ForeignKeyConstraint|string $foreignKey The name of the foreign key. + * @param Table|string $table The name of the table with the foreign key. * * @return void */ @@ -427,8 +419,6 @@ public function createDatabase($database) /** * Creates a new table. * - * @param \Doctrine\DBAL\Schema\Table $table - * * @return void */ public function createTable(Table $table) @@ -440,11 +430,11 @@ public function createTable(Table $table) /** * Creates a new sequence. * - * @param \Doctrine\DBAL\Schema\Sequence $sequence + * @param Sequence $sequence * * @return void * - * @throws \Doctrine\DBAL\ConnectionException If something fails at database level. + * @throws ConnectionException If something fails at database level. */ public function createSequence($sequence) { @@ -454,8 +444,7 @@ public function createSequence($sequence) /** * Creates a constraint on a table. * - * @param \Doctrine\DBAL\Schema\Constraint $constraint - * @param \Doctrine\DBAL\Schema\Table|string $table + * @param Table|string $table * * @return void */ @@ -467,8 +456,7 @@ public function createConstraint(Constraint $constraint, $table) /** * Creates a new index on a table. * - * @param \Doctrine\DBAL\Schema\Index $index - * @param \Doctrine\DBAL\Schema\Table|string $table The name of the table on which the index is to be created. + * @param Table|string $table The name of the table on which the index is to be created. * * @return void */ @@ -480,8 +468,8 @@ public function createIndex(Index $index, $table) /** * Creates a new foreign key. * - * @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey The ForeignKey instance. - * @param \Doctrine\DBAL\Schema\Table|string $table The name of the table on which the foreign key is to be created. + * @param ForeignKeyConstraint $foreignKey The ForeignKey instance. + * @param Table|string $table The name of the table on which the foreign key is to be created. * * @return void */ @@ -493,8 +481,6 @@ public function createForeignKey(ForeignKeyConstraint $foreignKey, $table) /** * Creates a new view. * - * @param \Doctrine\DBAL\Schema\View $view - * * @return void */ public function createView(View $view) @@ -510,8 +496,7 @@ public function createView(View $view) * @see dropConstraint() * @see createConstraint() * - * @param \Doctrine\DBAL\Schema\Constraint $constraint - * @param \Doctrine\DBAL\Schema\Table|string $table + * @param Table|string $table * * @return void */ @@ -524,8 +509,7 @@ public function dropAndCreateConstraint(Constraint $constraint, $table) /** * Drops and creates a new index on a table. * - * @param \Doctrine\DBAL\Schema\Index $index - * @param \Doctrine\DBAL\Schema\Table|string $table The name of the table on which the index is to be created. + * @param Table|string $table The name of the table on which the index is to be created. * * @return void */ @@ -538,8 +522,8 @@ public function dropAndCreateIndex(Index $index, $table) /** * Drops and creates a new foreign key. * - * @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey An associative array that defines properties of the foreign key to be created. - * @param \Doctrine\DBAL\Schema\Table|string $table The name of the table on which the foreign key is to be created. + * @param ForeignKeyConstraint $foreignKey An associative array that defines properties of the foreign key to be created. + * @param Table|string $table The name of the table on which the foreign key is to be created. * * @return void */ @@ -552,11 +536,9 @@ public function dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, $table /** * Drops and create a new sequence. * - * @param \Doctrine\DBAL\Schema\Sequence $sequence - * * @return void * - * @throws \Doctrine\DBAL\ConnectionException If something fails at database level. + * @throws ConnectionException If something fails at database level. */ public function dropAndCreateSequence(Sequence $sequence) { @@ -567,8 +549,6 @@ public function dropAndCreateSequence(Sequence $sequence) /** * Drops and creates a new table. * - * @param \Doctrine\DBAL\Schema\Table $table - * * @return void */ public function dropAndCreateTable(Table $table) @@ -593,8 +573,6 @@ public function dropAndCreateDatabase($database) /** * Drops and creates a new view. * - * @param \Doctrine\DBAL\Schema\View $view - * * @return void */ public function dropAndCreateView(View $view) @@ -608,17 +586,17 @@ public function dropAndCreateView(View $view) /** * Alters an existing tables schema. * - * @param \Doctrine\DBAL\Schema\TableDiff $tableDiff - * * @return void */ public function alterTable(TableDiff $tableDiff) { $queries = $this->_platform->getAlterTableSQL($tableDiff); - if (is_array($queries) && count($queries)) { - foreach ($queries as $ddlQuery) { - $this->_execSql($ddlQuery); - } + if (! is_array($queries) || ! count($queries)) { + return; + } + + foreach ($queries as $ddlQuery) { + $this->_execSql($ddlQuery); } } @@ -632,7 +610,7 @@ public function alterTable(TableDiff $tableDiff) */ public function renameTable($name, $newName) { - $tableDiff = new TableDiff($name); + $tableDiff = new TableDiff($name); $tableDiff->newName = $newName; $this->alterTable($tableDiff); } @@ -651,9 +629,11 @@ protected function _getPortableDatabasesList($databases) { $list = []; foreach ($databases as $value) { - if ($value = $this->_getPortableDatabaseDefinition($value)) { - $list[] = $value; + if (! $value = $this->_getPortableDatabaseDefinition($value)) { + continue; } + + $list[] = $value; } return $list; @@ -708,9 +688,11 @@ protected function _getPortableFunctionsList($functions) { $list = []; foreach ($functions as $value) { - if ($value = $this->_getPortableFunctionDefinition($value)) { - $list[] = $value; + if (! $value = $this->_getPortableFunctionDefinition($value)) { + continue; } + + $list[] = $value; } return $list; @@ -735,9 +717,11 @@ protected function _getPortableTriggersList($triggers) { $list = []; foreach ($triggers as $value) { - if ($value = $this->_getPortableTriggerDefinition($value)) { - $list[] = $value; + if (! $value = $this->_getPortableTriggerDefinition($value)) { + continue; } + + $list[] = $value; } return $list; @@ -762,9 +746,11 @@ protected function _getPortableSequencesList($sequences) { $list = []; foreach ($sequences as $value) { - if ($value = $this->_getPortableSequenceDefinition($value)) { - $list[] = $value; + if (! $value = $this->_getPortableSequenceDefinition($value)) { + continue; } + + $list[] = $value; } return $list; @@ -773,9 +759,9 @@ protected function _getPortableSequencesList($sequences) /** * @param array $sequence * - * @return \Doctrine\DBAL\Schema\Sequence + * @return Sequence * - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ protected function _getPortableSequenceDefinition($sequence) { @@ -799,25 +785,27 @@ protected function _getPortableTableColumnList($table, $database, $tableColumns) $list = []; foreach ($tableColumns as $tableColumn) { - $column = null; + $column = null; $defaultPrevented = false; - if (null !== $eventManager && $eventManager->hasListeners(Events::onSchemaColumnDefinition)) { + if ($eventManager !== null && $eventManager->hasListeners(Events::onSchemaColumnDefinition)) { $eventArgs = new SchemaColumnDefinitionEventArgs($tableColumn, $table, $database, $this->_conn); $eventManager->dispatchEvent(Events::onSchemaColumnDefinition, $eventArgs); $defaultPrevented = $eventArgs->isDefaultPrevented(); - $column = $eventArgs->getColumn(); + $column = $eventArgs->getColumn(); } - if ( ! $defaultPrevented) { + if (! $defaultPrevented) { $column = $this->_getPortableTableColumnDefinition($tableColumn); } - if ($column) { - $name = strtolower($column->getQuotedName($this->_platform)); - $list[$name] = $column; + if (! $column) { + continue; } + + $name = strtolower($column->getQuotedName($this->_platform)); + $list[$name] = $column; } return $list; @@ -828,7 +816,7 @@ protected function _getPortableTableColumnList($table, $database, $tableColumns) * * @param array $tableColumn * - * @return \Doctrine\DBAL\Schema\Column + * @return Column */ abstract protected function _getPortableTableColumnDefinition($tableColumn); @@ -840,7 +828,7 @@ abstract protected function _getPortableTableColumnDefinition($tableColumn); * * @return array */ - protected function _getPortableTableIndexesList($tableIndexRows, $tableName=null) + protected function _getPortableTableIndexesList($tableIndexRows, $tableName = null) { $result = []; foreach ($tableIndexRows as $tableIndex) { @@ -850,7 +838,7 @@ protected function _getPortableTableIndexesList($tableIndexRows, $tableName=null } $keyName = strtolower($keyName); - if (!isset($result[$keyName])) { + if (! isset($result[$keyName])) { $result[$keyName] = [ 'name' => $indexName, 'columns' => [$tableIndex['column_name']], @@ -868,24 +856,26 @@ protected function _getPortableTableIndexesList($tableIndexRows, $tableName=null $indexes = []; foreach ($result as $indexKey => $data) { - $index = null; + $index = null; $defaultPrevented = false; - if (null !== $eventManager && $eventManager->hasListeners(Events::onSchemaIndexDefinition)) { + if ($eventManager !== null && $eventManager->hasListeners(Events::onSchemaIndexDefinition)) { $eventArgs = new SchemaIndexDefinitionEventArgs($data, $tableName, $this->_conn); $eventManager->dispatchEvent(Events::onSchemaIndexDefinition, $eventArgs); $defaultPrevented = $eventArgs->isDefaultPrevented(); - $index = $eventArgs->getIndex(); + $index = $eventArgs->getIndex(); } - if ( ! $defaultPrevented) { + if (! $defaultPrevented) { $index = new Index($data['name'], $data['columns'], $data['unique'], $data['primary'], $data['flags'], $data['options']); } - if ($index) { - $indexes[$indexKey] = $index; + if (! $index) { + continue; } + + $indexes[$indexKey] = $index; } return $indexes; @@ -900,9 +890,11 @@ protected function _getPortableTablesList($tables) { $list = []; foreach ($tables as $value) { - if ($value = $this->_getPortableTableDefinition($value)) { - $list[] = $value; + if (! $value = $this->_getPortableTableDefinition($value)) { + continue; } + + $list[] = $value; } return $list; @@ -927,9 +919,11 @@ protected function _getPortableUsersList($users) { $list = []; foreach ($users as $value) { - if ($value = $this->_getPortableUserDefinition($value)) { - $list[] = $value; + if (! $value = $this->_getPortableUserDefinition($value)) { + continue; } + + $list[] = $value; } return $list; @@ -954,10 +948,12 @@ protected function _getPortableViewsList($views) { $list = []; foreach ($views as $value) { - if ($view = $this->_getPortableViewDefinition($value)) { - $viewName = strtolower($view->getQuotedName($this->_platform)); - $list[$viewName] = $view; + if (! $view = $this->_getPortableViewDefinition($value)) { + continue; } + + $viewName = strtolower($view->getQuotedName($this->_platform)); + $list[$viewName] = $view; } return $list; @@ -982,9 +978,11 @@ protected function _getPortableTableForeignKeysList($tableForeignKeys) { $list = []; foreach ($tableForeignKeys as $value) { - if ($value = $this->_getPortableTableForeignKeyDefinition($value)) { - $list[] = $value; + if (! $value = $this->_getPortableTableForeignKeyDefinition($value)) { + continue; } + + $list[] = $value; } return $list; @@ -1015,7 +1013,7 @@ protected function _execSql($sql) /** * Creates a schema instance for the current database. * - * @return \Doctrine\DBAL\Schema\Schema + * @return Schema */ public function createSchema() { @@ -1039,7 +1037,7 @@ public function createSchema() /** * Creates the configuration for this schema. * - * @return \Doctrine\DBAL\Schema\SchemaConfig + * @return SchemaConfig */ public function createSchemaConfig() { @@ -1091,7 +1089,7 @@ public function getSchemaSearchPaths() */ public function extractDoctrineTypeFromComment($comment, $currentType) { - if (preg_match("(\(DC2Type:(((?!\)).)+)\))", $comment, $match)) { + if (preg_match('(\(DC2Type:(((?!\)).)+)\))', $comment, $match)) { $currentType = $match[1]; } @@ -1106,6 +1104,6 @@ public function extractDoctrineTypeFromComment($comment, $currentType) */ public function removeDoctrineTypeFromComment($comment, $type) { - return str_replace('(DC2Type:'.$type.')', '', $comment); + return str_replace('(DC2Type:' . $type . ')', '', $comment); } } diff --git a/lib/Doctrine/DBAL/Schema/Column.php b/lib/Doctrine/DBAL/Schema/Column.php index 862240c6e7d..f79310bfee1 100644 --- a/lib/Doctrine/DBAL/Schema/Column.php +++ b/lib/Doctrine/DBAL/Schema/Column.php @@ -14,84 +14,55 @@ * Object representation of a database column. * * @link www.doctrine-project.org - * @since 2.0 - * @author Benjamin Eberlei */ class Column extends AbstractAsset { - /** - * @var Type - */ + /** @var Type */ protected $_type; - /** - * @var int|null - */ + /** @var int|null */ protected $_length = null; - /** - * @var int - */ + /** @var int */ protected $_precision = 10; - /** - * @var int - */ + /** @var int */ protected $_scale = 0; - /** - * @var bool - */ + /** @var bool */ protected $_unsigned = false; - /** - * @var bool - */ + /** @var bool */ protected $_fixed = false; - /** - * @var bool - */ + /** @var bool */ protected $_notnull = true; - /** - * @var string|null - */ + /** @var string|null */ protected $_default = null; - /** - * @var bool - */ + /** @var bool */ protected $_autoincrement = false; - /** - * @var array - */ + /** @var array */ protected $_platformOptions = []; - /** - * @var string|null - */ + /** @var string|null */ protected $_columnDefinition = null; - /** - * @var string|null - */ + /** @var string|null */ protected $_comment = null; - /** - * @var array - */ + /** @var array */ protected $_customSchemaOptions = []; /** * Creates a new Column. * * @param string $columnName - * @param Type $type * @param array $options */ - public function __construct($columnName, Type $type, array $options=[]) + public function __construct($columnName, Type $type, array $options = []) { $this->_setName($columnName); $this->setType($type); @@ -106,11 +77,11 @@ public function __construct($columnName, Type $type, array $options=[]) public function setOptions(array $options) { foreach ($options as $name => $value) { - $method = "set".$name; - if ( ! method_exists($this, $method)) { + $method = 'set' . $name; + if (! method_exists($this, $method)) { // next major: throw an exception @trigger_error(sprintf( - 'The "%s" column option is not supported,'. + 'The "%s" column option is not supported,' . ' setting it is deprecated and will cause an error in Doctrine 3.0', $name ), E_USER_DEPRECATED); @@ -124,8 +95,6 @@ public function setOptions(array $options) } /** - * @param Type $type - * * @return Column */ public function setType(Type $type) @@ -158,7 +127,7 @@ public function setLength($length) */ public function setPrecision($precision) { - if (!is_numeric($precision)) { + if (! is_numeric($precision)) { $precision = 10; // defaults to 10 when no valid precision is given. } @@ -174,7 +143,7 @@ public function setPrecision($precision) */ public function setScale($scale) { - if (!is_numeric($scale)) { + if (! is_numeric($scale)) { $scale = 0; } diff --git a/lib/Doctrine/DBAL/Schema/ColumnDiff.php b/lib/Doctrine/DBAL/Schema/ColumnDiff.php index 196f83e3634..0204e43db4c 100644 --- a/lib/Doctrine/DBAL/Schema/ColumnDiff.php +++ b/lib/Doctrine/DBAL/Schema/ColumnDiff.php @@ -8,43 +8,31 @@ * Represents the change of a column. * * @link www.doctrine-project.org - * @since 2.0 - * @author Benjamin Eberlei */ class ColumnDiff { - /** - * @var string - */ + /** @var string */ public $oldColumnName; - /** - * @var Column - */ + /** @var Column */ public $column; - /** - * @var array - */ + /** @var array */ public $changedProperties = []; - /** - * @var Column - */ + /** @var Column */ public $fromColumn; /** * @param string $oldColumnName - * @param Column $column * @param string[] $changedProperties - * @param Column $fromColumn */ - public function __construct($oldColumnName, Column $column, array $changedProperties = [], Column $fromColumn = null) + public function __construct($oldColumnName, Column $column, array $changedProperties = [], ?Column $fromColumn = null) { - $this->oldColumnName = $oldColumnName; - $this->column = $column; + $this->oldColumnName = $oldColumnName; + $this->column = $column; $this->changedProperties = $changedProperties; - $this->fromColumn = $fromColumn; + $this->fromColumn = $fromColumn; } /** diff --git a/lib/Doctrine/DBAL/Schema/Comparator.php b/lib/Doctrine/DBAL/Schema/Comparator.php index 4421b05db9b..8297e05ccaa 100644 --- a/lib/Doctrine/DBAL/Schema/Comparator.php +++ b/lib/Doctrine/DBAL/Schema/Comparator.php @@ -17,16 +17,11 @@ * Compares two Schemas and return an instance of SchemaDiff. * * @link www.doctrine-project.org - * @since 2.0 - * @author Benjamin Eberlei */ class Comparator { /** - * @param \Doctrine\DBAL\Schema\Schema $fromSchema - * @param \Doctrine\DBAL\Schema\Schema $toSchema - * - * @return \Doctrine\DBAL\Schema\SchemaDiff + * @return SchemaDiff */ public static function compareSchemas(Schema $fromSchema, Schema $toSchema) { @@ -42,33 +37,34 @@ public static function compareSchemas(Schema $fromSchema, Schema $toSchema) * operations to change the schema stored in $fromSchema to the schema that is * stored in $toSchema. * - * @param \Doctrine\DBAL\Schema\Schema $fromSchema - * @param \Doctrine\DBAL\Schema\Schema $toSchema - * - * @return \Doctrine\DBAL\Schema\SchemaDiff + * @return SchemaDiff */ public function compare(Schema $fromSchema, Schema $toSchema) { - $diff = new SchemaDiff(); + $diff = new SchemaDiff(); $diff->fromSchema = $fromSchema; $foreignKeysToTable = []; foreach ($toSchema->getNamespaces() as $namespace) { - if ( ! $fromSchema->hasNamespace($namespace)) { - $diff->newNamespaces[$namespace] = $namespace; + if ($fromSchema->hasNamespace($namespace)) { + continue; } + + $diff->newNamespaces[$namespace] = $namespace; } foreach ($fromSchema->getNamespaces() as $namespace) { - if ( ! $toSchema->hasNamespace($namespace)) { - $diff->removedNamespaces[$namespace] = $namespace; + if ($toSchema->hasNamespace($namespace)) { + continue; } + + $diff->removedNamespaces[$namespace] = $namespace; } foreach ($toSchema->getTables() as $table) { $tableName = $table->getShortestName($toSchema->getName()); - if ( ! $fromSchema->hasTable($tableName)) { + if (! $fromSchema->hasTable($tableName)) { $diff->newTables[$tableName] = $toSchema->getTable($tableName); } else { $tableDifferences = $this->diffTable($fromSchema->getTable($tableName), $toSchema->getTable($tableName)); @@ -83,14 +79,14 @@ public function compare(Schema $fromSchema, Schema $toSchema) $tableName = $table->getShortestName($fromSchema->getName()); $table = $fromSchema->getTable($tableName); - if ( ! $toSchema->hasTable($tableName)) { + if (! $toSchema->hasTable($tableName)) { $diff->removedTables[$tableName] = $table; } // also remember all foreign keys that point to a specific table foreach ($table->getForeignKeys() as $foreignKey) { $foreignTable = strtolower($foreignKey->getForeignTableName()); - if (!isset($foreignKeysToTable[$foreignTable])) { + if (! isset($foreignKeysToTable[$foreignTable])) { $foreignKeysToTable[$foreignTable] = []; } $foreignKeysToTable[$foreignTable][] = $foreignKey; @@ -98,31 +94,35 @@ public function compare(Schema $fromSchema, Schema $toSchema) } foreach ($diff->removedTables as $tableName => $table) { - if (isset($foreignKeysToTable[$tableName])) { - $diff->orphanedForeignKeys = array_merge($diff->orphanedForeignKeys, $foreignKeysToTable[$tableName]); - - // deleting duplicated foreign keys present on both on the orphanedForeignKey - // and the removedForeignKeys from changedTables - foreach ($foreignKeysToTable[$tableName] as $foreignKey) { - // strtolower the table name to make if compatible with getShortestName - $localTableName = strtolower($foreignKey->getLocalTableName()); - if (isset($diff->changedTables[$localTableName])) { - foreach ($diff->changedTables[$localTableName]->removedForeignKeys as $key => $removedForeignKey) { - // We check if the key is from the removed table if not we skip. - if ($tableName !== strtolower($removedForeignKey->getForeignTableName())) { - continue; - } - unset($diff->changedTables[$localTableName]->removedForeignKeys[$key]); - } + if (! isset($foreignKeysToTable[$tableName])) { + continue; + } + + $diff->orphanedForeignKeys = array_merge($diff->orphanedForeignKeys, $foreignKeysToTable[$tableName]); + + // deleting duplicated foreign keys present on both on the orphanedForeignKey + // and the removedForeignKeys from changedTables + foreach ($foreignKeysToTable[$tableName] as $foreignKey) { + // strtolower the table name to make if compatible with getShortestName + $localTableName = strtolower($foreignKey->getLocalTableName()); + if (! isset($diff->changedTables[$localTableName])) { + continue; + } + + foreach ($diff->changedTables[$localTableName]->removedForeignKeys as $key => $removedForeignKey) { + // We check if the key is from the removed table if not we skip. + if ($tableName !== strtolower($removedForeignKey->getForeignTableName())) { + continue; } + unset($diff->changedTables[$localTableName]->removedForeignKeys[$key]); } } } foreach ($toSchema->getSequences() as $sequence) { $sequenceName = $sequence->getShortestName($toSchema->getName()); - if ( ! $fromSchema->hasSequence($sequenceName)) { - if ( ! $this->isAutoIncrementSequenceInSchema($fromSchema, $sequence)) { + if (! $fromSchema->hasSequence($sequenceName)) { + if (! $this->isAutoIncrementSequenceInSchema($fromSchema, $sequence)) { $diff->newSequences[] = $sequence; } } else { @@ -139,17 +139,19 @@ public function compare(Schema $fromSchema, Schema $toSchema) $sequenceName = $sequence->getShortestName($fromSchema->getName()); - if ( ! $toSchema->hasSequence($sequenceName)) { - $diff->removedSequences[] = $sequence; + if ($toSchema->hasSequence($sequenceName)) { + continue; } + + $diff->removedSequences[] = $sequence; } return $diff; } /** - * @param \Doctrine\DBAL\Schema\Schema $schema - * @param \Doctrine\DBAL\Schema\Sequence $sequence + * @param Schema $schema + * @param Sequence $sequence * * @return bool */ @@ -165,14 +167,11 @@ private function isAutoIncrementSequenceInSchema($schema, $sequence) } /** - * @param \Doctrine\DBAL\Schema\Sequence $sequence1 - * @param \Doctrine\DBAL\Schema\Sequence $sequence2 - * * @return bool */ public function diffSequence(Sequence $sequence1, Sequence $sequence2) { - if ($sequence1->getAllocationSize() != $sequence2->getAllocationSize()) { + if ($sequence1->getAllocationSize() !== $sequence2->getAllocationSize()) { return true; } @@ -184,15 +183,12 @@ public function diffSequence(Sequence $sequence1, Sequence $sequence2) * * If there are no differences this method returns the boolean false. * - * @param \Doctrine\DBAL\Schema\Table $table1 - * @param \Doctrine\DBAL\Schema\Table $table2 - * * @return TableDiff|false */ public function diffTable(Table $table1, Table $table2) { - $changes = 0; - $tableDifferences = new TableDiff($table1->getName()); + $changes = 0; + $tableDifferences = new TableDiff($table1->getName()); $tableDifferences->fromTable = $table1; $table1Columns = $table1->getColumns(); @@ -200,15 +196,17 @@ public function diffTable(Table $table1, Table $table2) /* See if all the fields in table 1 exist in table 2 */ foreach ($table2Columns as $columnName => $column) { - if ( !$table1->hasColumn($columnName)) { - $tableDifferences->addedColumns[$columnName] = $column; - $changes++; + if ($table1->hasColumn($columnName)) { + continue; } + + $tableDifferences->addedColumns[$columnName] = $column; + $changes++; } /* See if there are any removed fields in table 2 */ foreach ($table1Columns as $columnName => $column) { // See if column is removed in table 2. - if ( ! $table2->hasColumn($columnName)) { + if (! $table2->hasColumn($columnName)) { $tableDifferences->removedColumns[$columnName] = $column; $changes++; continue; @@ -217,12 +215,14 @@ public function diffTable(Table $table1, Table $table2) // See if column has changed properties in table 2. $changedProperties = $this->diffColumn($column, $table2->getColumn($columnName)); - if ( ! empty($changedProperties)) { - $columnDiff = new ColumnDiff($column->getName(), $table2->getColumn($columnName), $changedProperties); - $columnDiff->fromColumn = $column; - $tableDifferences->changedColumns[$column->getName()] = $columnDiff; - $changes++; + if (empty($changedProperties)) { + continue; } + + $columnDiff = new ColumnDiff($column->getName(), $table2->getColumn($columnName), $changedProperties); + $columnDiff->fromColumn = $column; + $tableDifferences->changedColumns[$column->getName()] = $columnDiff; + $changes++; } $this->detectColumnRenamings($tableDifferences); @@ -253,23 +253,25 @@ public function diffTable(Table $table1, Table $table2) // See if index has changed in table 2. $table2Index = $index->isPrimary() ? $table2->getPrimaryKey() : $table2->getIndex($indexName); - if ($this->diffIndex($index, $table2Index)) { - $tableDifferences->changedIndexes[$indexName] = $table2Index; - $changes++; + if (! $this->diffIndex($index, $table2Index)) { + continue; } + + $tableDifferences->changedIndexes[$indexName] = $table2Index; + $changes++; } $this->detectIndexRenamings($tableDifferences); $fromFkeys = $table1->getForeignKeys(); - $toFkeys = $table2->getForeignKeys(); + $toFkeys = $table2->getForeignKeys(); foreach ($fromFkeys as $key1 => $constraint1) { foreach ($toFkeys as $key2 => $constraint2) { if ($this->diffForeignKey($constraint1, $constraint2) === false) { unset($fromFkeys[$key1], $toFkeys[$key2]); } else { - if (strtolower($constraint1->getName()) == strtolower($constraint2->getName())) { + if (strtolower($constraint1->getName()) === strtolower($constraint2->getName())) { $tableDifferences->changedForeignKeys[] = $constraint2; $changes++; unset($fromFkeys[$key1], $toFkeys[$key2]); @@ -302,26 +304,32 @@ private function detectColumnRenamings(TableDiff $tableDifferences) $renameCandidates = []; foreach ($tableDifferences->addedColumns as $addedColumnName => $addedColumn) { foreach ($tableDifferences->removedColumns as $removedColumn) { - if (count($this->diffColumn($addedColumn, $removedColumn)) == 0) { - $renameCandidates[$addedColumn->getName()][] = [$removedColumn, $addedColumn, $addedColumnName]; + if (count($this->diffColumn($addedColumn, $removedColumn)) !== 0) { + continue; } + + $renameCandidates[$addedColumn->getName()][] = [$removedColumn, $addedColumn, $addedColumnName]; } } foreach ($renameCandidates as $candidateColumns) { - if (count($candidateColumns) == 1) { - list($removedColumn, $addedColumn) = $candidateColumns[0]; - $removedColumnName = strtolower($removedColumn->getName()); - $addedColumnName = strtolower($addedColumn->getName()); - - if ( ! isset($tableDifferences->renamedColumns[$removedColumnName])) { - $tableDifferences->renamedColumns[$removedColumnName] = $addedColumn; - unset( - $tableDifferences->addedColumns[$addedColumnName], - $tableDifferences->removedColumns[$removedColumnName] - ); - } + if (count($candidateColumns) !== 1) { + continue; } + + [$removedColumn, $addedColumn] = $candidateColumns[0]; + $removedColumnName = strtolower($removedColumn->getName()); + $addedColumnName = strtolower($addedColumn->getName()); + + if (isset($tableDifferences->renamedColumns[$removedColumnName])) { + continue; + } + + $tableDifferences->renamedColumns[$removedColumnName] = $addedColumn; + unset( + $tableDifferences->addedColumns[$addedColumnName], + $tableDifferences->removedColumns[$removedColumnName] + ); } } @@ -338,9 +346,11 @@ private function detectIndexRenamings(TableDiff $tableDifferences) // Gather possible rename candidates by comparing each added and removed index based on semantics. foreach ($tableDifferences->addedIndexes as $addedIndexName => $addedIndex) { foreach ($tableDifferences->removedIndexes as $removedIndex) { - if (! $this->diffIndex($addedIndex, $removedIndex)) { - $renameCandidates[$addedIndex->getName()][] = [$removedIndex, $addedIndex, $addedIndexName]; + if ($this->diffIndex($addedIndex, $removedIndex)) { + continue; } + + $renameCandidates[$addedIndex->getName()][] = [$removedIndex, $addedIndex, $addedIndexName]; } } @@ -349,36 +359,37 @@ private function detectIndexRenamings(TableDiff $tableDifferences) // we can safely rename it. // Otherwise it is unclear if a rename action is really intended, // therefore we let those ambiguous indexes be added/dropped. - if (count($candidateIndexes) === 1) { - list($removedIndex, $addedIndex) = $candidateIndexes[0]; - - $removedIndexName = strtolower($removedIndex->getName()); - $addedIndexName = strtolower($addedIndex->getName()); - - if (! isset($tableDifferences->renamedIndexes[$removedIndexName])) { - $tableDifferences->renamedIndexes[$removedIndexName] = $addedIndex; - unset( - $tableDifferences->addedIndexes[$addedIndexName], - $tableDifferences->removedIndexes[$removedIndexName] - ); - } + if (count($candidateIndexes) !== 1) { + continue; + } + + [$removedIndex, $addedIndex] = $candidateIndexes[0]; + + $removedIndexName = strtolower($removedIndex->getName()); + $addedIndexName = strtolower($addedIndex->getName()); + + if (isset($tableDifferences->renamedIndexes[$removedIndexName])) { + continue; } + + $tableDifferences->renamedIndexes[$removedIndexName] = $addedIndex; + unset( + $tableDifferences->addedIndexes[$addedIndexName], + $tableDifferences->removedIndexes[$removedIndexName] + ); } } /** - * @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $key1 - * @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $key2 - * * @return bool */ public function diffForeignKey(ForeignKeyConstraint $key1, ForeignKeyConstraint $key2) { - if (array_map('strtolower', $key1->getUnquotedLocalColumns()) != array_map('strtolower', $key2->getUnquotedLocalColumns())) { + if (array_map('strtolower', $key1->getUnquotedLocalColumns()) !== array_map('strtolower', $key2->getUnquotedLocalColumns())) { return true; } - if (array_map('strtolower', $key1->getUnquotedForeignColumns()) != array_map('strtolower', $key2->getUnquotedForeignColumns())) { + if (array_map('strtolower', $key1->getUnquotedForeignColumns()) !== array_map('strtolower', $key2->getUnquotedForeignColumns())) { return true; } @@ -386,7 +397,7 @@ public function diffForeignKey(ForeignKeyConstraint $key1, ForeignKeyConstraint return true; } - if ($key1->onUpdate() != $key2->onUpdate()) { + if ($key1->onUpdate() !== $key2->onUpdate()) { return true; } @@ -399,9 +410,6 @@ public function diffForeignKey(ForeignKeyConstraint $key1, ForeignKeyConstraint * If there are differences this method returns $field2, otherwise the * boolean false. * - * @param \Doctrine\DBAL\Schema\Column $column1 - * @param \Doctrine\DBAL\Schema\Column $column2 - * * @return array */ public function diffColumn(Column $column1, Column $column2) @@ -412,9 +420,11 @@ public function diffColumn(Column $column1, Column $column2) $changedProperties = []; foreach (['type', 'notnull', 'unsigned', 'autoincrement'] as $property) { - if ($properties1[$property] != $properties2[$property]) { - $changedProperties[] = $property; + if ($properties1[$property] === $properties2[$property]) { + continue; } + + $changedProperties[] = $property; } // This is a very nasty hack to make comparator work with the legacy json_array type, which should be killed in v3 @@ -424,11 +434,11 @@ public function diffColumn(Column $column1, Column $column2) $changedProperties[] = 'comment'; } - if ($properties1['default'] != $properties2['default'] || + if ($properties1['default'] !== $properties2['default'] || // 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. - (null === $properties1['default'] && null !== $properties2['default']) || - (null === $properties2['default'] && null !== $properties1['default']) + ($properties1['default'] === null && $properties2['default'] !== null) || + ($properties2['default'] === null && $properties1['default'] !== null) ) { $changedProperties[] = 'default'; } @@ -439,26 +449,26 @@ public function diffColumn(Column $column1, Column $column2) // check if value of length is set at all, default value assumed otherwise. $length1 = $properties1['length'] ?: 255; $length2 = $properties2['length'] ?: 255; - if ($length1 != $length2) { + if ($length1 !== $length2) { $changedProperties[] = 'length'; } - if ($properties1['fixed'] != $properties2['fixed']) { + if ($properties1['fixed'] !== $properties2['fixed']) { $changedProperties[] = 'fixed'; } } elseif ($properties1['type'] instanceof Types\DecimalType) { - if (($properties1['precision'] ?: 10) != ($properties2['precision'] ?: 10)) { + if (($properties1['precision'] ?: 10) !== ($properties2['precision'] ?: 10)) { $changedProperties[] = 'precision'; } - if ($properties1['scale'] != $properties2['scale']) { + if ($properties1['scale'] !== $properties2['scale']) { $changedProperties[] = 'scale'; } } // A null value and an empty string are actually equal for a comment so they should not trigger a change. if ($properties1['comment'] !== $properties2['comment'] && - ! (null === $properties1['comment'] && '' === $properties2['comment']) && - ! (null === $properties2['comment'] && '' === $properties1['comment']) + ! ($properties1['comment'] === null && $properties2['comment'] === '') && + ! ($properties2['comment'] === null && $properties1['comment'] === '') ) { $changedProperties[] = 'comment'; } @@ -467,7 +477,7 @@ public function diffColumn(Column $column1, Column $column2) $customOptions2 = $column2->getCustomSchemaOptions(); foreach (array_merge(array_keys($customOptions1), array_keys($customOptions2)) as $key) { - if ( ! array_key_exists($key, $properties1) || ! array_key_exists($key, $properties2)) { + if (! array_key_exists($key, $properties1) || ! array_key_exists($key, $properties2)) { $changedProperties[] = $key; } elseif ($properties1[$key] !== $properties2[$key]) { $changedProperties[] = $key; @@ -478,9 +488,11 @@ public function diffColumn(Column $column1, Column $column2) $platformOptions2 = $column2->getPlatformOptions(); foreach (array_keys(array_intersect_key($platformOptions1, $platformOptions2)) as $key) { - if ($properties1[$key] !== $properties2[$key]) { - $changedProperties[] = $key; + if ($properties1[$key] === $properties2[$key]) { + continue; } + + $changedProperties[] = $key; } return array_unique($changedProperties); @@ -493,7 +505,7 @@ public function diffColumn(Column $column1, Column $column2) */ private function isALegacyJsonComparison(Types\Type $one, Types\Type $other) : bool { - if ( ! $one instanceof Types\JsonType || ! $other instanceof Types\JsonType) { + if (! $one instanceof Types\JsonType || ! $other instanceof Types\JsonType) { return false; } @@ -507,9 +519,6 @@ private function isALegacyJsonComparison(Types\Type $one, Types\Type $other) : b * Compares $index1 with $index2 and returns $index2 if there are any * differences or false in case there are no differences. * - * @param \Doctrine\DBAL\Schema\Index $index1 - * @param \Doctrine\DBAL\Schema\Index $index2 - * * @return bool */ public function diffIndex(Index $index1, Index $index2) diff --git a/lib/Doctrine/DBAL/Schema/Constraint.php b/lib/Doctrine/DBAL/Schema/Constraint.php index 8ca3b14c16b..9265e9f2cb6 100644 --- a/lib/Doctrine/DBAL/Schema/Constraint.php +++ b/lib/Doctrine/DBAL/Schema/Constraint.php @@ -8,8 +8,6 @@ * Marker interface for constraints. * * @link www.doctrine-project.org - * @since 2.0 - * @author Benjamin Eberlei */ interface Constraint { @@ -19,8 +17,6 @@ interface Constraint public function getName(); /** - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform - * * @return string */ public function getQuotedName(AbstractPlatform $platform); @@ -41,7 +37,7 @@ public function getColumns(); * is a keyword reserved by the platform. * Otherwise the plain unquoted value as inserted is returned. * - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform The platform to use for quotation. + * @param AbstractPlatform $platform The platform to use for quotation. * * @return array */ diff --git a/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php b/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php index aa1f1207bb1..ffb471bb543 100644 --- a/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php @@ -2,6 +2,8 @@ namespace Doctrine\DBAL\Schema; +use Doctrine\DBAL\Types\Type; +use const CASE_LOWER; use function array_change_key_case; use function is_resource; use function strpos; @@ -13,8 +15,6 @@ * IBM Db2 Schema Manager. * * @link www.doctrine-project.org - * @since 1.0 - * @author Benjamin Eberlei */ class DB2SchemaManager extends AbstractSchemaManager { @@ -26,8 +26,8 @@ class DB2SchemaManager extends AbstractSchemaManager */ public function listTableNames() { - $sql = $this->_platform->getListTablesSQL(); - $sql .= " AND CREATOR = UPPER('".$this->_conn->getUsername()."')"; + $sql = $this->_platform->getListTablesSQL(); + $sql .= " AND CREATOR = UPPER('" . $this->_conn->getUsername() . "')"; $tables = $this->_conn->fetchAll($sql); @@ -39,35 +39,35 @@ public function listTableNames() */ protected function _getPortableTableColumnDefinition($tableColumn) { - $tableColumn = array_change_key_case($tableColumn, \CASE_LOWER); + $tableColumn = array_change_key_case($tableColumn, CASE_LOWER); - $length = null; - $fixed = null; - $unsigned = false; - $scale = false; + $length = null; + $fixed = null; + $unsigned = false; + $scale = false; $precision = false; $default = null; - if (null !== $tableColumn['default'] && 'NULL' != $tableColumn['default']) { + if ($tableColumn['default'] !== null && $tableColumn['default'] !== 'NULL') { $default = trim($tableColumn['default'], "'"); } $type = $this->_platform->getDoctrineTypeMapping($tableColumn['typename']); if (isset($tableColumn['comment'])) { - $type = $this->extractDoctrineTypeFromComment($tableColumn['comment'], $type); + $type = $this->extractDoctrineTypeFromComment($tableColumn['comment'], $type); $tableColumn['comment'] = $this->removeDoctrineTypeFromComment($tableColumn['comment'], $type); } switch (strtolower($tableColumn['typename'])) { case 'varchar': $length = $tableColumn['length']; - $fixed = false; + $fixed = false; break; case 'character': $length = $tableColumn['length']; - $fixed = true; + $fixed = true; break; case 'clob': $length = $tableColumn['length']; @@ -75,7 +75,7 @@ protected function _getPortableTableColumnDefinition($tableColumn) case 'decimal': case 'double': case 'real': - $scale = $tableColumn['scale']; + $scale = $tableColumn['scale']; $precision = $tableColumn['length']; break; } @@ -85,8 +85,8 @@ protected function _getPortableTableColumnDefinition($tableColumn) 'unsigned' => (bool) $unsigned, 'fixed' => (bool) $fixed, 'default' => $default, - 'autoincrement' => (boolean) $tableColumn['autoincrement'], - 'notnull' => (bool) ($tableColumn['nulls'] == 'N'), + 'autoincrement' => (bool) $tableColumn['autoincrement'], + 'notnull' => (bool) ($tableColumn['nulls'] === 'N'), 'scale' => null, 'precision' => null, 'comment' => isset($tableColumn['comment']) && $tableColumn['comment'] !== '' @@ -96,11 +96,11 @@ protected function _getPortableTableColumnDefinition($tableColumn) ]; if ($scale !== null && $precision !== null) { - $options['scale'] = $scale; + $options['scale'] = $scale; $options['precision'] = $precision; } - return new Column($tableColumn['colname'], \Doctrine\DBAL\Types\Type::getType($type), $options); + return new Column($tableColumn['colname'], Type::getType($type), $options); } /** @@ -110,7 +110,7 @@ protected function _getPortableTablesList($tables) { $tableNames = []; foreach ($tables as $tableRow) { - $tableRow = array_change_key_case($tableRow, \CASE_LOWER); + $tableRow = array_change_key_case($tableRow, CASE_LOWER); $tableNames[] = $tableRow['name']; } @@ -123,8 +123,8 @@ protected function _getPortableTablesList($tables) protected function _getPortableTableIndexesList($tableIndexRows, $tableName = null) { foreach ($tableIndexRows as &$tableIndexRow) { - $tableIndexRow = array_change_key_case($tableIndexRow, \CASE_LOWER); - $tableIndexRow['primary'] = (boolean) $tableIndexRow['primary']; + $tableIndexRow = array_change_key_case($tableIndexRow, CASE_LOWER); + $tableIndexRow['primary'] = (bool) $tableIndexRow['primary']; } return parent::_getPortableTableIndexesList($tableIndexRows, $tableName); @@ -152,9 +152,9 @@ protected function _getPortableTableForeignKeysList($tableForeignKeys) $foreignKeys = []; foreach ($tableForeignKeys as $tableForeignKey) { - $tableForeignKey = array_change_key_case($tableForeignKey, \CASE_LOWER); + $tableForeignKey = array_change_key_case($tableForeignKey, CASE_LOWER); - if (!isset($foreignKeys[$tableForeignKey['index_name']])) { + if (! isset($foreignKeys[$tableForeignKey['index_name']])) { $foreignKeys[$tableForeignKey['index_name']] = [ 'local_columns' => [$tableForeignKey['local_column']], 'foreign_table' => $tableForeignKey['foreign_table'], @@ -163,10 +163,10 @@ protected function _getPortableTableForeignKeysList($tableForeignKeys) 'options' => [ 'onUpdate' => $tableForeignKey['on_update'], 'onDelete' => $tableForeignKey['on_delete'], - ] + ], ]; } else { - $foreignKeys[$tableForeignKey['index_name']]['local_columns'][] = $tableForeignKey['local_column']; + $foreignKeys[$tableForeignKey['index_name']]['local_columns'][] = $tableForeignKey['local_column']; $foreignKeys[$tableForeignKey['index_name']]['foreign_columns'][] = $tableForeignKey['foreign_column']; } } @@ -179,10 +179,10 @@ protected function _getPortableTableForeignKeysList($tableForeignKeys) */ protected function _getPortableForeignKeyRuleDef($def) { - if ($def == "C") { - return "CASCADE"; - } elseif ($def == "N") { - return "SET NULL"; + if ($def === 'C') { + return 'CASCADE'; + } elseif ($def === 'N') { + return 'SET NULL'; } return null; @@ -193,10 +193,10 @@ protected function _getPortableForeignKeyRuleDef($def) */ protected function _getPortableViewDefinition($view) { - $view = array_change_key_case($view, \CASE_LOWER); + $view = array_change_key_case($view, CASE_LOWER); // sadly this still segfaults on PDO_IBM, see http://pecl.php.net/bugs/bug.php?id=17199 //$view['text'] = (is_resource($view['text']) ? stream_get_contents($view['text']) : $view['text']); - if (!is_resource($view['text'])) { + if (! is_resource($view['text'])) { $pos = strpos($view['text'], ' AS '); $sql = substr($view['text'], $pos+4); } else { diff --git a/lib/Doctrine/DBAL/Schema/DrizzleSchemaManager.php b/lib/Doctrine/DBAL/Schema/DrizzleSchemaManager.php index 57ed4d3b687..c334db2797b 100644 --- a/lib/Doctrine/DBAL/Schema/DrizzleSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/DrizzleSchemaManager.php @@ -9,8 +9,6 @@ /** * Schema manager for the Drizzle RDBMS. - * - * @author Kim Hemsø Rasmussen */ class DrizzleSchemaManager extends AbstractSchemaManager { @@ -21,25 +19,25 @@ protected function _getPortableTableColumnDefinition($tableColumn) { $dbType = strtolower($tableColumn['DATA_TYPE']); - $type = $this->_platform->getDoctrineTypeMapping($dbType); - $type = $this->extractDoctrineTypeFromComment($tableColumn['COLUMN_COMMENT'], $type); + $type = $this->_platform->getDoctrineTypeMapping($dbType); + $type = $this->extractDoctrineTypeFromComment($tableColumn['COLUMN_COMMENT'], $type); $tableColumn['COLUMN_COMMENT'] = $this->removeDoctrineTypeFromComment($tableColumn['COLUMN_COMMENT'], $type); $options = [ - 'notnull' => !(bool) $tableColumn['IS_NULLABLE'], + 'notnull' => ! (bool) $tableColumn['IS_NULLABLE'], 'length' => (int) $tableColumn['CHARACTER_MAXIMUM_LENGTH'], 'default' => $tableColumn['COLUMN_DEFAULT'] ?? null, 'autoincrement' => (bool) $tableColumn['IS_AUTO_INCREMENT'], 'scale' => (int) $tableColumn['NUMERIC_SCALE'], 'precision' => (int) $tableColumn['NUMERIC_PRECISION'], - 'comment' => isset($tableColumn['COLUMN_COMMENT']) && '' !== $tableColumn['COLUMN_COMMENT'] + 'comment' => isset($tableColumn['COLUMN_COMMENT']) && $tableColumn['COLUMN_COMMENT'] !== '' ? $tableColumn['COLUMN_COMMENT'] : null, ]; $column = new Column($tableColumn['COLUMN_NAME'], Type::getType($type), $options); - if ( ! empty($tableColumn['COLLATION_NAME'])) { + if (! empty($tableColumn['COLLATION_NAME'])) { $column->setPlatformOption('collation', $tableColumn['COLLATION_NAME']); } @@ -96,8 +94,8 @@ protected function _getPortableTableIndexesList($tableIndexes, $tableName = null { $indexes = []; foreach ($tableIndexes as $k) { - $k['primary'] = (boolean) $k['primary']; - $indexes[] = $k; + $k['primary'] = (bool) $k['primary']; + $indexes[] = $k; } return parent::_getPortableTableIndexesList($indexes, $tableName); diff --git a/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php b/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php index 962fcb8a0f1..7f07b10551c 100644 --- a/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php +++ b/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php @@ -15,17 +15,14 @@ /** * An abstraction class for a foreign key constraint. * - * @author Benjamin Eberlei - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.0 */ class ForeignKeyConstraint extends AbstractAsset implements Constraint { /** * Instance of the referencing table the foreign key constraint is associated with. * - * @var \Doctrine\DBAL\Schema\Table + * @var Table */ protected $_localTable; @@ -52,9 +49,7 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint */ protected $_foreignColumnNames; - /** - * @var array Options associated with the foreign key constraint. - */ + /** @var array Options associated with the foreign key constraint. */ protected $_options; /** @@ -69,10 +64,10 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint public function __construct(array $localColumnNames, $foreignTableName, array $foreignColumnNames, $name = null, array $options = []) { $this->_setName($name); - $identifierConstructorCallback = function ($column) { + $identifierConstructorCallback = static function ($column) { return new Identifier($column); }; - $this->_localColumnNames = $localColumnNames + $this->_localColumnNames = $localColumnNames ? array_combine($localColumnNames, array_map($identifierConstructorCallback, $localColumnNames)) : []; @@ -85,7 +80,7 @@ public function __construct(array $localColumnNames, $foreignTableName, array $f $this->_foreignColumnNames = $foreignColumnNames ? array_combine($foreignColumnNames, array_map($identifierConstructorCallback, $foreignColumnNames)) : []; - $this->_options = $options; + $this->_options = $options; } /** @@ -103,7 +98,7 @@ public function getLocalTableName() * Sets the Table instance of the referencing table * the foreign key constraint is associated with. * - * @param \Doctrine\DBAL\Schema\Table $table Instance of the referencing table. + * @param Table $table Instance of the referencing table. * * @return void */ @@ -139,7 +134,7 @@ public function getLocalColumns() * is a keyword reserved by the platform. * Otherwise the plain unquoted value as inserted is returned. * - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform The platform to use for quotation. + * @param AbstractPlatform $platform The platform to use for quotation. * * @return array */ @@ -192,10 +187,10 @@ public function getColumns() * is a keyword reserved by the platform. * Otherwise the plain unquoted value as inserted is returned. * - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform The platform to use for quotation. - * * @see getQuotedLocalColumns * + * @param AbstractPlatform $platform The platform to use for quotation. + * * @return array */ public function getQuotedColumns(AbstractPlatform $platform) @@ -221,7 +216,7 @@ public function getForeignTableName() */ public function getUnqualifiedForeignTableName() { - $parts = explode(".", $this->_foreignTableName->getName()); + $parts = explode('.', $this->_foreignTableName->getName()); return strtolower(end($parts)); } @@ -234,7 +229,7 @@ public function getUnqualifiedForeignTableName() * is a keyword reserved by the platform. * Otherwise the plain unquoted value as inserted is returned. * - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform The platform to use for quotation. + * @param AbstractPlatform $platform The platform to use for quotation. * * @return string */ @@ -262,7 +257,7 @@ public function getForeignColumns() * is a keyword reserved by the platform. * Otherwise the plain unquoted value as inserted is returned. * - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform The platform to use for quotation. + * @param AbstractPlatform $platform The platform to use for quotation. * * @return array */ @@ -347,7 +342,7 @@ private function onEvent($event) if (isset($this->_options[$event])) { $onEvent = strtoupper($this->_options[$event]); - if ( ! in_array($onEvent, ['NO ACTION', 'RESTRICT'])) { + if (! in_array($onEvent, ['NO ACTION', 'RESTRICT'])) { return $onEvent; } } diff --git a/lib/Doctrine/DBAL/Schema/Identifier.php b/lib/Doctrine/DBAL/Schema/Identifier.php index 79686448c0b..a688be8e460 100644 --- a/lib/Doctrine/DBAL/Schema/Identifier.php +++ b/lib/Doctrine/DBAL/Schema/Identifier.php @@ -8,15 +8,11 @@ * Wraps identifier names like column names in indexes / foreign keys * in an abstract class for proper quotation capabilities. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.4 */ class Identifier extends AbstractAsset { /** - * Constructor. - * * @param string $identifier Identifier name to wrap. * @param bool $quote Whether to force quoting the given identifier. */ @@ -24,8 +20,10 @@ public function __construct($identifier, $quote = false) { $this->_setName($identifier); - if ($quote && ! $this->_quoted) { - $this->_setName('"' . $this->getName() . '"'); + if (! $quote || $this->_quoted) { + return; } + + $this->_setName('"' . $this->getName() . '"'); } } diff --git a/lib/Doctrine/DBAL/Schema/Index.php b/lib/Doctrine/DBAL/Schema/Index.php index 377127d4919..52f5a29b6ad 100644 --- a/lib/Doctrine/DBAL/Schema/Index.php +++ b/lib/Doctrine/DBAL/Schema/Index.php @@ -3,6 +3,7 @@ namespace Doctrine\DBAL\Schema; use Doctrine\DBAL\Platforms\AbstractPlatform; +use InvalidArgumentException; use function array_keys; use function array_map; use function array_search; @@ -20,14 +21,10 @@ class Index extends AbstractAsset implements Constraint */ protected $_columns = []; - /** - * @var bool - */ + /** @var bool */ protected $_isUnique = false; - /** - * @var bool - */ + /** @var bool */ protected $_isPrimary = false; /** @@ -42,7 +39,6 @@ class Index extends AbstractAsset implements Constraint * Platform specific options * * @todo $_flags should eventually be refactored into options - * * @var array */ private $options = []; @@ -60,9 +56,9 @@ public function __construct($indexName, array $columns, $isUnique = false, $isPr $isUnique = $isUnique || $isPrimary; $this->_setName($indexName); - $this->_isUnique = $isUnique; + $this->_isUnique = $isUnique; $this->_isPrimary = $isPrimary; - $this->options = $options; + $this->options = $options; foreach ($columns as $column) { $this->_addColumn($column); @@ -77,15 +73,15 @@ public function __construct($indexName, array $columns, $isUnique = false, $isPr * * @return void * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ protected function _addColumn($column) { - if (is_string($column)) { - $this->_columns[$column] = new Identifier($column); - } else { - throw new \InvalidArgumentException("Expecting a string as Index Column"); + if (! is_string($column)) { + throw new InvalidArgumentException('Expecting a string as Index Column'); } + + $this->_columns[$column] = new Identifier($column); } /** @@ -125,7 +121,7 @@ public function getUnquotedColumns() */ public function isSimpleIndex() { - return !$this->_isPrimary && !$this->_isUnique; + return ! $this->_isPrimary && ! $this->_isUnique; } /** @@ -172,9 +168,11 @@ public function spansColumns(array $columnNames) $sameColumns = true; for ($i = 0; $i < $numberOfColumns; $i++) { - if ( ! isset($columnNames[$i]) || $this->trimQuotes(strtolower($columns[$i])) !== $this->trimQuotes(strtolower($columnNames[$i]))) { - $sameColumns = false; + if (isset($columnNames[$i]) && $this->trimQuotes(strtolower($columns[$i])) === $this->trimQuotes(strtolower($columnNames[$i]))) { + continue; } + + $sameColumns = false; } return $sameColumns; @@ -183,15 +181,13 @@ public function spansColumns(array $columnNames) /** * Checks if the other index already fulfills all the indexing and constraint needs of the current one. * - * @param Index $other - * * @return bool */ public function isFullfilledBy(Index $other) { // allow the other index to be equally large only. It being larger is an option // but it creates a problem with scenarios of the kind PRIMARY KEY(foo,bar) UNIQUE(foo) - if (count($other->getColumns()) != count($this->getColumns())) { + if (count($other->getColumns()) !== count($this->getColumns())) { return false; } @@ -199,11 +195,11 @@ public function isFullfilledBy(Index $other) $sameColumns = $this->spansColumns($other->getColumns()); if ($sameColumns) { - if ( ! $this->samePartialIndex($other)) { + if (! $this->samePartialIndex($other)) { return false; } - if ( ! $this->isUnique() && ! $this->isPrimary()) { + 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 // overlaps. This means a primary or unique index can always fulfill the requirements of just an @@ -211,7 +207,7 @@ public function isFullfilledBy(Index $other) return true; } - if ($other->isPrimary() != $this->isPrimary()) { + if ($other->isPrimary() !== $this->isPrimary()) { return false; } @@ -224,8 +220,6 @@ public function isFullfilledBy(Index $other) /** * Detects if the other index is a non-unique, non primary index that can be overwritten by this one. * - * @param Index $other - * * @return bool */ public function overrules(Index $other) @@ -252,11 +246,11 @@ public function getFlags() /** * Adds Flag for an index that translates to platform specific handling. * - * @example $index->addFlag('CLUSTERED') - * * @param string $flag * * @return Index + * + * @example $index->addFlag('CLUSTERED') */ public function addFlag($flag) { @@ -319,17 +313,15 @@ public function getOptions() /** * Return whether the two indexes have the same partial index - * @param \Doctrine\DBAL\Schema\Index $other * * @return bool */ private function samePartialIndex(Index $other) { - if ($this->hasOption('where') && $other->hasOption('where') && $this->getOption('where') == $other->getOption('where')) { + if ($this->hasOption('where') && $other->hasOption('where') && $this->getOption('where') === $other->getOption('where')) { return true; } return ! $this->hasOption('where') && ! $other->hasOption('where'); } - } diff --git a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php index 1989872372a..37518cc15ce 100644 --- a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php @@ -20,12 +20,6 @@ /** * Schema manager for the MySql RDBMS. - * - * @author Konsta Vesterinen - * @author Lukas Smith (PEAR MDB2 library) - * @author Roman Borschel - * @author Benjamin Eberlei - * @since 2.0 */ class MySqlSchemaManager extends AbstractSchemaManager { @@ -108,7 +102,7 @@ protected function _getPortableTableColumnDefinition($tableColumn) $fixed = null; - if ( ! isset($tableColumn['name'])) { + if (! isset($tableColumn['name'])) { $tableColumn['name'] = ''; } @@ -216,7 +210,7 @@ protected function _getPortableTableColumnDefinition($tableColumn) * @link https://mariadb.com/kb/en/library/information-schema-columns-table/ * @link https://jira.mariadb.org/browse/MDEV-13132 * - * @param null|string $columnDefault default value as stored in information_schema for MariaDB >= 10.2.7 + * @param string|null $columnDefault default value as stored in information_schema for MariaDB >= 10.2.7 */ private function getMariaDb1027ColumnDefault(MariaDb1027Platform $platform, ?string $columnDefault) : ?string { @@ -225,7 +219,9 @@ private function getMariaDb1027ColumnDefault(MariaDb1027Platform $platform, ?str } if ($columnDefault[0] === "'") { return stripslashes( - str_replace("''", "'", + str_replace( + "''", + "'", preg_replace('/^\'(.*)\'$/', '$1', $columnDefault) ) ); @@ -249,11 +245,11 @@ protected function _getPortableTableForeignKeysList($tableForeignKeys) $list = []; foreach ($tableForeignKeys as $value) { $value = array_change_key_case($value, CASE_LOWER); - if ( ! isset($list[$value['constraint_name']])) { - if ( ! isset($value['delete_rule']) || $value['delete_rule'] === "RESTRICT") { + if (! isset($list[$value['constraint_name']])) { + if (! isset($value['delete_rule']) || $value['delete_rule'] === 'RESTRICT') { $value['delete_rule'] = null; } - if ( ! isset($value['update_rule']) || $value['update_rule'] === "RESTRICT") { + if (! isset($value['update_rule']) || $value['update_rule'] === 'RESTRICT') { $value['update_rule'] = null; } diff --git a/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php b/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php index 09dd845a887..e84b0a551f8 100644 --- a/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php @@ -10,7 +10,6 @@ use function array_change_key_case; use function array_values; use function assert; -use function is_null; use function preg_match; use function sprintf; use function strpos; @@ -20,11 +19,6 @@ /** * Oracle Schema Manager. - * - * @author Konsta Vesterinen - * @author Lukas Smith (PEAR MDB2 library) - * @author Benjamin Eberlei - * @since 2.0 */ class OracleSchemaManager extends AbstractSchemaManager { @@ -61,7 +55,7 @@ public function dropDatabase($database) */ protected function _getPortableViewDefinition($view) { - $view = \array_change_key_case($view, CASE_LOWER); + $view = array_change_key_case($view, CASE_LOWER); return new View($this->getQuotedIdentifierName($view['view_name']), $view['text']); } @@ -71,7 +65,7 @@ protected function _getPortableViewDefinition($view) */ protected function _getPortableUserDefinition($user) { - $user = \array_change_key_case($user, CASE_LOWER); + $user = array_change_key_case($user, CASE_LOWER); return [ 'user' => $user['username'], @@ -83,7 +77,7 @@ protected function _getPortableUserDefinition($user) */ protected function _getPortableTableDefinition($table) { - $table = \array_change_key_case($table, CASE_LOWER); + $table = array_change_key_case($table, CASE_LOWER); return $this->getQuotedIdentifierName($table['table_name']); } @@ -91,29 +85,28 @@ protected function _getPortableTableDefinition($table) /** * {@inheritdoc} * - * @license New BSD License * @link http://ezcomponents.org/docs/api/trunk/DatabaseSchema/ezcDbSchemaPgsqlReader.html */ - protected function _getPortableTableIndexesList($tableIndexes, $tableName=null) + protected function _getPortableTableIndexesList($tableIndexes, $tableName = null) { $indexBuffer = []; foreach ($tableIndexes as $tableIndex) { - $tableIndex = \array_change_key_case($tableIndex, CASE_LOWER); + $tableIndex = array_change_key_case($tableIndex, CASE_LOWER); $keyName = strtolower($tableIndex['name']); $buffer = []; - if (strtolower($tableIndex['is_primary']) == "p") { - $keyName = 'primary'; - $buffer['primary'] = true; + if (strtolower($tableIndex['is_primary']) === 'p') { + $keyName = 'primary'; + $buffer['primary'] = true; $buffer['non_unique'] = false; } else { - $buffer['primary'] = false; + $buffer['primary'] = false; $buffer['non_unique'] = ! $tableIndex['is_unique']; } - $buffer['key_name'] = $keyName; + $buffer['key_name'] = $keyName; $buffer['column_name'] = $this->getQuotedIdentifierName($tableIndex['column_name']); - $indexBuffer[] = $buffer; + $indexBuffer[] = $buffer; } return parent::_getPortableTableIndexesList($indexBuffer, $tableName); @@ -124,20 +117,20 @@ protected function _getPortableTableIndexesList($tableIndexes, $tableName=null) */ protected function _getPortableTableColumnDefinition($tableColumn) { - $tableColumn = \array_change_key_case($tableColumn, CASE_LOWER); + $tableColumn = array_change_key_case($tableColumn, CASE_LOWER); $dbType = strtolower($tableColumn['data_type']); - if (strpos($dbType, "timestamp(") === 0) { - if (strpos($dbType, "with time zone")) { - $dbType = "timestamptz"; + if (strpos($dbType, 'timestamp(') === 0) { + if (strpos($dbType, 'with time zone')) { + $dbType = 'timestamptz'; } else { - $dbType = "timestamp"; + $dbType = 'timestamp'; } } $unsigned = $fixed = null; - if ( ! isset($tableColumn['column_name'])) { + if (! isset($tableColumn['column_name'])) { $tableColumn['column_name'] = ''; } @@ -148,36 +141,36 @@ protected function _getPortableTableColumnDefinition($tableColumn) $tableColumn['data_default'] = null; } - if (null !== $tableColumn['data_default']) { + if ($tableColumn['data_default'] !== null) { // Default values returned from database are enclosed in single quotes. $tableColumn['data_default'] = trim($tableColumn['data_default'], "'"); } $precision = null; - $scale = null; + $scale = null; - $type = $this->_platform->getDoctrineTypeMapping($dbType); - $type = $this->extractDoctrineTypeFromComment($tableColumn['comments'], $type); + $type = $this->_platform->getDoctrineTypeMapping($dbType); + $type = $this->extractDoctrineTypeFromComment($tableColumn['comments'], $type); $tableColumn['comments'] = $this->removeDoctrineTypeFromComment($tableColumn['comments'], $type); switch ($dbType) { case 'number': - if ($tableColumn['data_precision'] == 20 && $tableColumn['data_scale'] == 0) { + 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'; + $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) { + $scale = 0; + } elseif ($tableColumn['data_precision'] === 1 && $tableColumn['data_scale'] === 0) { $precision = 1; - $scale = 0; - $type = 'boolean'; + $scale = 0; + $type = 'boolean'; } elseif ($tableColumn['data_scale'] > 0) { $precision = $tableColumn['data_precision']; - $scale = $tableColumn['data_scale']; - $type = 'decimal'; + $scale = $tableColumn['data_scale']; + $type = 'decimal'; } $length = null; break; @@ -189,12 +182,12 @@ protected function _getPortableTableColumnDefinition($tableColumn) case 'varchar2': case 'nvarchar2': $length = $tableColumn['char_length']; - $fixed = false; + $fixed = false; break; case 'char': case 'nchar': $length = $tableColumn['char_length']; - $fixed = true; + $fixed = true; break; case 'date': case 'timestamp': @@ -204,8 +197,8 @@ protected function _getPortableTableColumnDefinition($tableColumn) case 'binary_float': case 'binary_double': $precision = $tableColumn['data_precision']; - $scale = $tableColumn['data_scale']; - $length = null; + $scale = $tableColumn['data_scale']; + $length = null; break; case 'clob': case 'nclob': @@ -231,7 +224,7 @@ protected function _getPortableTableColumnDefinition($tableColumn) 'length' => $length, 'precision' => $precision, 'scale' => $scale, - 'comment' => isset($tableColumn['comments']) && '' !== $tableColumn['comments'] + 'comment' => isset($tableColumn['comments']) && $tableColumn['comments'] !== '' ? $tableColumn['comments'] : null, ]; @@ -246,9 +239,9 @@ protected function _getPortableTableForeignKeysList($tableForeignKeys) { $list = []; foreach ($tableForeignKeys as $value) { - $value = \array_change_key_case($value, CASE_LOWER); - if (!isset($list[$value['constraint_name']])) { - if ($value['delete_rule'] == "NO ACTION") { + $value = array_change_key_case($value, CASE_LOWER); + if (! isset($list[$value['constraint_name']])) { + if ($value['delete_rule'] === 'NO ACTION') { $value['delete_rule'] = null; } @@ -261,18 +254,20 @@ protected function _getPortableTableForeignKeysList($tableForeignKeys) ]; } - $localColumn = $this->getQuotedIdentifierName($value['local_column']); + $localColumn = $this->getQuotedIdentifierName($value['local_column']); $foreignColumn = $this->getQuotedIdentifierName($value['foreign_column']); - $list[$value['constraint_name']]['local'][$value['position']] = $localColumn; + $list[$value['constraint_name']]['local'][$value['position']] = $localColumn; $list[$value['constraint_name']]['foreign'][$value['position']] = $foreignColumn; } $result = []; foreach ($list as $constraint) { $result[] = new ForeignKeyConstraint( - array_values($constraint['local']), $this->getQuotedIdentifierName($constraint['foreignTable']), - array_values($constraint['foreign']), $this->getQuotedIdentifierName($constraint['name']), + array_values($constraint['local']), + $this->getQuotedIdentifierName($constraint['foreignTable']), + array_values($constraint['foreign']), + $this->getQuotedIdentifierName($constraint['name']), ['onDelete' => $constraint['onDelete']] ); } @@ -285,7 +280,7 @@ protected function _getPortableTableForeignKeysList($tableForeignKeys) */ protected function _getPortableSequenceDefinition($sequence) { - $sequence = \array_change_key_case($sequence, CASE_LOWER); + $sequence = array_change_key_case($sequence, CASE_LOWER); return new Sequence( $this->getQuotedIdentifierName($sequence['sequence_name']), @@ -299,7 +294,7 @@ protected function _getPortableSequenceDefinition($sequence) */ protected function _getPortableFunctionDefinition($function) { - $function = \array_change_key_case($function, CASE_LOWER); + $function = array_change_key_case($function, CASE_LOWER); return $function['name']; } @@ -309,7 +304,7 @@ protected function _getPortableFunctionDefinition($function) */ protected function _getPortableDatabaseDefinition($database) { - $database = \array_change_key_case($database, CASE_LOWER); + $database = array_change_key_case($database, CASE_LOWER); return $database['username']; } @@ -323,11 +318,11 @@ public function createDatabase($database = null) $database = $this->_conn->getDatabase(); } - $params = $this->_conn->getParams(); - $username = $database; - $password = $params['password']; + $params = $this->_conn->getParams(); + $username = $database; + $password = $params['password']; - $query = 'CREATE USER ' . $username . ' IDENTIFIED BY ' . $password; + $query = 'CREATE USER ' . $username . ' IDENTIFIED BY ' . $password; $this->_conn->executeUpdate($query); $query = 'GRANT DBA TO ' . $username; @@ -406,7 +401,7 @@ private function killUserSessions($user) $activeUserSessions = $this->_conn->fetchAll($sql, [strtoupper($user)]); foreach ($activeUserSessions as $activeUserSession) { - $activeUserSession = array_change_key_case($activeUserSession, \CASE_LOWER); + $activeUserSession = array_change_key_case($activeUserSession, CASE_LOWER); $this->_execSql( sprintf( diff --git a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php index 10e960c1fff..201224633dc 100644 --- a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php @@ -27,17 +27,10 @@ /** * PostgreSQL Schema Manager. - * - * @author Konsta Vesterinen - * @author Lukas Smith (PEAR MDB2 library) - * @author Benjamin Eberlei - * @since 2.0 */ class PostgreSqlSchemaManager extends AbstractSchemaManager { - /** - * @var array - */ + /** @var array */ private $existingSchemaPaths; /** @@ -62,7 +55,7 @@ public function getSchemaNames() public function getSchemaSearchPaths() { $params = $this->_conn->getParams(); - $schema = explode(",", $this->_conn->fetchColumn('SHOW search_path')); + $schema = explode(',', $this->_conn->fetchColumn('SHOW search_path')); if (isset($params['user'])) { $schema = str_replace('"$user"', $params['user'], $schema); @@ -99,7 +92,7 @@ public function determineExistingSchemaSearchPaths() $names = $this->getSchemaNames(); $paths = $this->getSchemaSearchPaths(); - $this->existingSchemaPaths = array_filter($paths, function ($v) use ($names) { + $this->existingSchemaPaths = array_filter($paths, static function ($v) use ($names) { return in_array($v, $names); }); } @@ -154,13 +147,16 @@ protected function _getPortableTableForeignKeyDefinition($tableForeignKey) if (preg_match('/FOREIGN KEY \((.+)\) REFERENCES (.+)\((.+)\)/', $tableForeignKey['condef'], $values)) { // PostgreSQL returns identifiers that are keywords with quotes, we need them later, don't get // the idea to trim them here. - $localColumns = array_map('trim', explode(",", $values[1])); - $foreignColumns = array_map('trim', explode(",", $values[3])); - $foreignTable = $values[2]; + $localColumns = array_map('trim', explode(',', $values[1])); + $foreignColumns = array_map('trim', explode(',', $values[3])); + $foreignTable = $values[2]; } return new ForeignKeyConstraint( - $localColumns, $foreignTable, $foreignColumns, $tableForeignKey['conname'], + $localColumns, + $foreignTable, + $foreignColumns, + $tableForeignKey['conname'], ['onUpdate' => $onUpdate, 'onDelete' => $onDelete] ); } @@ -178,7 +174,7 @@ protected function _getPortableTriggerDefinition($trigger) */ protected function _getPortableViewDefinition($view) { - return new View($view['schemaname'].'.'.$view['viewname'], $view['definition']); + return new View($view['schemaname'] . '.' . $view['viewname'], $view['definition']); } /** @@ -188,7 +184,7 @@ protected function _getPortableUserDefinition($user) { return [ 'user' => $user['usename'], - 'password' => $user['passwd'] + 'password' => $user['passwd'], ]; } @@ -197,46 +193,47 @@ protected function _getPortableUserDefinition($user) */ protected function _getPortableTableDefinition($table) { - $schemas = $this->getExistingSchemaSearchPaths(); + $schemas = $this->getExistingSchemaSearchPaths(); $firstSchema = array_shift($schemas); - if ($table['schema_name'] == $firstSchema) { + if ($table['schema_name'] === $firstSchema) { return $table['table_name']; } - return $table['schema_name'] . "." . $table['table_name']; + return $table['schema_name'] . '.' . $table['table_name']; } /** * {@inheritdoc} * - * @license New BSD License * @link http://ezcomponents.org/docs/api/trunk/DatabaseSchema/ezcDbSchemaPgsqlReader.html */ - protected function _getPortableTableIndexesList($tableIndexes, $tableName=null) + protected function _getPortableTableIndexesList($tableIndexes, $tableName = null) { $buffer = []; foreach ($tableIndexes as $row) { - $colNumbers = explode(' ', $row['indkey']); + $colNumbers = explode(' ', $row['indkey']); $colNumbersSql = 'IN (' . join(' ,', $colNumbers) . ' )'; $columnNameSql = "SELECT attnum, attname FROM pg_attribute WHERE attrelid={$row['indrelid']} AND attnum $colNumbersSql ORDER BY attnum ASC;"; - $stmt = $this->_conn->executeQuery($columnNameSql); + $stmt = $this->_conn->executeQuery($columnNameSql); $indexColumns = $stmt->fetchAll(); // required for getting the order of the columns right. foreach ($colNumbers as $colNum) { foreach ($indexColumns as $colRow) { - if ($colNum == $colRow['attnum']) { - $buffer[] = [ - 'key_name' => $row['relname'], - 'column_name' => trim($colRow['attname']), - 'non_unique' => !$row['indisunique'], - 'primary' => $row['indisprimary'], - 'where' => $row['where'], - ]; + if ($colNum !== $colRow['attnum']) { + continue; } + + $buffer[] = [ + 'key_name' => $row['relname'], + 'column_name' => trim($colRow['attname']), + 'non_unique' => ! $row['indisunique'], + 'primary' => $row['indisprimary'], + 'where' => $row['where'], + ]; } } } @@ -260,8 +257,8 @@ protected function _getPortableSequencesList($sequences) $sequenceDefinitions = []; foreach ($sequences as $sequence) { - if ($sequence['schemaname'] != 'public') { - $sequenceName = $sequence['schemaname'] . "." . $sequence['relname']; + if ($sequence['schemaname'] !== 'public') { + $sequenceName = $sequence['schemaname'] . '.' . $sequence['relname']; } else { $sequenceName = $sequence['relname']; } @@ -292,14 +289,14 @@ protected function getPortableNamespaceDefinition(array $namespace) protected function _getPortableSequenceDefinition($sequence) { if ($sequence['schemaname'] !== 'public') { - $sequenceName = $sequence['schemaname'] . "." . $sequence['relname']; + $sequenceName = $sequence['schemaname'] . '.' . $sequence['relname']; } else { $sequenceName = $sequence['relname']; } - if ( ! isset($sequence['increment_by'], $sequence['min_value'])) { + if (! isset($sequence['increment_by'], $sequence['min_value'])) { /** @var string[] $data */ - $data = $this->_conn->fetchAssoc('SELECT min_value, increment_by FROM ' . $this->_platform->quoteIdentifier($sequenceName)); + $data = $this->_conn->fetchAssoc('SELECT min_value, increment_by FROM ' . $this->_platform->quoteIdentifier($sequenceName)); $sequence += $data; } @@ -316,7 +313,7 @@ protected function _getPortableTableColumnDefinition($tableColumn) if (strtolower($tableColumn['type']) === 'varchar' || strtolower($tableColumn['type']) === 'bpchar') { // get length from varchar definition - $length = preg_replace('~.*\(([0-9]*)\).*~', '$1', $tableColumn['complete_type']); + $length = preg_replace('~.*\(([0-9]*)\).*~', '$1', $tableColumn['complete_type']); $tableColumn['length'] = $length; } @@ -325,8 +322,8 @@ protected function _getPortableTableColumnDefinition($tableColumn) $autoincrement = false; if (preg_match("/^nextval\('(.*)'(::.*)?\)$/", $tableColumn['default'], $matches)) { $tableColumn['sequence'] = $matches[1]; - $tableColumn['default'] = null; - $autoincrement = true; + $tableColumn['default'] = null; + $autoincrement = true; } if (preg_match("/^['(](.*)[')]::.*$/", $tableColumn['default'], $matches)) { @@ -338,7 +335,7 @@ protected function _getPortableTableColumnDefinition($tableColumn) } $length = $tableColumn['length'] ?? null; - if ($length == '-1' && isset($tableColumn['atttypmod'])) { + if ($length === '-1' && isset($tableColumn['atttypmod'])) { $length = $tableColumn['atttypmod'] - 4; } if ((int) $length <= 0) { @@ -346,40 +343,40 @@ protected function _getPortableTableColumnDefinition($tableColumn) } $fixed = null; - if (!isset($tableColumn['name'])) { + if (! isset($tableColumn['name'])) { $tableColumn['name'] = ''; } $precision = null; - $scale = null; - $jsonb = null; + $scale = null; + $jsonb = null; $dbType = strtolower($tableColumn['type']); - if (strlen($tableColumn['domain_type']) && !$this->_platform->hasDoctrineTypeMappingFor($tableColumn['type'])) { - $dbType = strtolower($tableColumn['domain_type']); + if (strlen($tableColumn['domain_type']) && ! $this->_platform->hasDoctrineTypeMappingFor($tableColumn['type'])) { + $dbType = strtolower($tableColumn['domain_type']); $tableColumn['complete_type'] = $tableColumn['domain_complete_type']; } - $type = $this->_platform->getDoctrineTypeMapping($dbType); - $type = $this->extractDoctrineTypeFromComment($tableColumn['comment'], $type); + $type = $this->_platform->getDoctrineTypeMapping($dbType); + $type = $this->extractDoctrineTypeFromComment($tableColumn['comment'], $type); $tableColumn['comment'] = $this->removeDoctrineTypeFromComment($tableColumn['comment'], $type); switch ($dbType) { case 'smallint': case 'int2': $tableColumn['default'] = $this->fixVersion94NegativeNumericDefaultValue($tableColumn['default']); - $length = null; + $length = null; break; case 'int': case 'int4': case 'integer': $tableColumn['default'] = $this->fixVersion94NegativeNumericDefaultValue($tableColumn['default']); - $length = null; + $length = null; break; case 'bigint': case 'int8': $tableColumn['default'] = $this->fixVersion94NegativeNumericDefaultValue($tableColumn['default']); - $length = null; + $length = null; break; case 'bool': case 'boolean': @@ -418,8 +415,8 @@ protected function _getPortableTableColumnDefinition($tableColumn) if (preg_match('([A-Za-z]+\(([0-9]+)\,([0-9]+)\))', $tableColumn['complete_type'], $match)) { $precision = $match[1]; - $scale = $match[2]; - $length = null; + $scale = $match[2]; + $length = null; } break; case 'year': @@ -452,7 +449,7 @@ protected function _getPortableTableColumnDefinition($tableColumn) $column = new Column($tableColumn['field'], Type::getType($type), $options); - if (isset($tableColumn['collation']) && !empty($tableColumn['collation'])) { + if (isset($tableColumn['collation']) && ! empty($tableColumn['collation'])) { $column->setPlatformOption('collation', $tableColumn['collation']); } diff --git a/lib/Doctrine/DBAL/Schema/SQLAnywhereSchemaManager.php b/lib/Doctrine/DBAL/Schema/SQLAnywhereSchemaManager.php index 7fbbc09178b..e88051db8d1 100644 --- a/lib/Doctrine/DBAL/Schema/SQLAnywhereSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SQLAnywhereSchemaManager.php @@ -10,9 +10,7 @@ /** * SAP Sybase SQL Anywhere schema manager. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ class SQLAnywhereSchemaManager extends AbstractSchemaManager { @@ -97,11 +95,11 @@ protected function _getPortableTableColumnDefinition($tableColumn) $fixed = false; $default = null; - if (null !== $tableColumn['default']) { + if ($tableColumn['default'] !== null) { // Strip quotes from default value. - $default = preg_replace(["/^'(.*)'$/", "/''/"], ["$1", "'"], $tableColumn['default']); + $default = preg_replace(["/^'(.*)'$/", "/''/"], ['$1', "'"], $tableColumn['default']); - if ('autoincrement' == $default) { + if ($default === 'autoincrement') { $default = null; } } @@ -117,14 +115,14 @@ protected function _getPortableTableColumnDefinition($tableColumn) case 'decimal': case 'float': $precision = $tableColumn['length']; - $scale = $tableColumn['scale']; + $scale = $tableColumn['scale']; } return new Column( $tableColumn['column_name'], Type::getType($type), [ - 'length' => $type == 'string' ? $tableColumn['length'] : null, + 'length' => $type === 'string' ? $tableColumn['length'] : null, 'precision' => $precision, 'scale' => $scale, 'unsigned' => (bool) $tableColumn['unsigned'], @@ -132,7 +130,7 @@ protected function _getPortableTableColumnDefinition($tableColumn) 'notnull' => (bool) $tableColumn['notnull'], 'default' => $default, 'autoincrement' => (bool) $tableColumn['autoincrement'], - 'comment' => isset($tableColumn['comment']) && '' !== $tableColumn['comment'] + 'comment' => isset($tableColumn['comment']) && $tableColumn['comment'] !== '' ? $tableColumn['comment'] : null, ] @@ -169,7 +167,7 @@ protected function _getPortableTableForeignKeysList($tableForeignKeys) $foreignKeys = []; foreach ($tableForeignKeys as $tableForeignKey) { - if (!isset($foreignKeys[$tableForeignKey['index_name']])) { + if (! isset($foreignKeys[$tableForeignKey['index_name']])) { $foreignKeys[$tableForeignKey['index_name']] = [ 'local_columns' => [$tableForeignKey['local_column']], 'foreign_table' => $tableForeignKey['foreign_table'], @@ -182,11 +180,11 @@ protected function _getPortableTableForeignKeysList($tableForeignKeys) 'onDelete' => $tableForeignKey['on_delete'], 'check_on_commit' => $tableForeignKey['check_on_commit'], 'clustered' => $tableForeignKey['clustered'], - 'for_olap_workload' => $tableForeignKey['for_olap_workload'] - ] + 'for_olap_workload' => $tableForeignKey['for_olap_workload'], + ], ]; } else { - $foreignKeys[$tableForeignKey['index_name']]['local_columns'][] = $tableForeignKey['local_column']; + $foreignKeys[$tableForeignKey['index_name']]['local_columns'][] = $tableForeignKey['local_column']; $foreignKeys[$tableForeignKey['index_name']]['foreign_columns'][] = $tableForeignKey['foreign_column']; } } @@ -200,8 +198,8 @@ protected function _getPortableTableForeignKeysList($tableForeignKeys) protected function _getPortableTableIndexesList($tableIndexRows, $tableName = null) { foreach ($tableIndexRows as &$tableIndex) { - $tableIndex['primary'] = (boolean) $tableIndex['primary']; - $tableIndex['flags'] = []; + $tableIndex['primary'] = (bool) $tableIndex['primary']; + $tableIndex['flags'] = []; if ($tableIndex['clustered']) { $tableIndex['flags'][] = 'clustered'; @@ -211,9 +209,11 @@ protected function _getPortableTableIndexesList($tableIndexRows, $tableName = nu $tableIndex['flags'][] = 'with_nulls_not_distinct'; } - if ($tableIndex['for_olap_workload']) { - $tableIndex['flags'][] = 'for_olap_workload'; + if (! $tableIndex['for_olap_workload']) { + continue; } + + $tableIndex['flags'][] = 'for_olap_workload'; } return parent::_getPortableTableIndexesList($tableIndexRows, $tableName); @@ -226,7 +226,7 @@ protected function _getPortableViewDefinition($view) { return new View( $view['table_name'], - preg_replace('/^.*\s+as\s+SELECT(.*)/i', "SELECT$1", $view['view_def']) + preg_replace('/^.*\s+as\s+SELECT(.*)/i', 'SELECT$1', $view['view_def']) ); } } diff --git a/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php b/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php index 63b113bbe84..59798aaad5e 100644 --- a/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php @@ -5,6 +5,7 @@ use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\DriverException; use Doctrine\DBAL\Types\Type; +use PDOException; use function count; use function in_array; use function preg_replace; @@ -16,13 +17,6 @@ /** * SQL Server Schema Manager. - * - * @license http://www.opensource.org/licenses/mit-license.php MIT - * @author Konsta Vesterinen - * @author Lukas Smith (PEAR MDB2 library) - * @author Juozas Kaziukenas - * @author Steve Müller - * @since 2.0 */ class SQLServerSchemaManager extends AbstractSchemaManager { @@ -67,21 +61,23 @@ protected function _getPortableSequenceDefinition($sequence) */ protected function _getPortableTableColumnDefinition($tableColumn) { - $dbType = strtok($tableColumn['type'], '(), '); - $fixed = null; - $length = (int) $tableColumn['length']; + $dbType = strtok($tableColumn['type'], '(), '); + $fixed = null; + $length = (int) $tableColumn['length']; $default = $tableColumn['default']; - if (!isset($tableColumn['name'])) { + if (! isset($tableColumn['name'])) { $tableColumn['name'] = ''; } - while ($default != ($default2 = preg_replace("/^\((.*)\)$/", '$1', $default))) { + while ($default !== ($default2 = preg_replace('/^\((.*)\)$/', '$1', $default))) { $default = trim($default2, "'"); - if ($default == 'getdate()') { - $default = $this->_platform->getCurrentTimestampSQL(); + if ($default !== 'getdate()') { + continue; } + + $default = $this->_platform->getCurrentTimestampSQL(); } switch ($dbType) { @@ -89,17 +85,17 @@ protected function _getPortableTableColumnDefinition($tableColumn) case 'nvarchar': case 'ntext': // Unicode data requires 2 bytes per character - $length = $length / 2; + $length /= 2; break; case 'varchar': // TEXT type is returned as VARCHAR(MAX) with a length of -1 - if ($length == -1) { + if ($length === -1) { $dbType = 'text'; } break; } - if ('char' === $dbType || 'nchar' === $dbType || 'binary' === $dbType) { + if ($dbType === 'char' || $dbType === 'nchar' || $dbType === 'binary') { $fixed = true; } @@ -108,7 +104,7 @@ protected function _getPortableTableColumnDefinition($tableColumn) $tableColumn['comment'] = $this->removeDoctrineTypeFromComment($tableColumn['comment'], $type); $options = [ - 'length' => ($length == 0 || !in_array($type, ['text', 'string'])) ? null : $length, + 'length' => $length === 0 || ! in_array($type, ['text', 'string']) ? null : $length, 'unsigned' => false, 'fixed' => (bool) $fixed, 'default' => $default !== 'NULL' ? $default : null, @@ -136,7 +132,7 @@ protected function _getPortableTableForeignKeysList($tableForeignKeys) $foreignKeys = []; foreach ($tableForeignKeys as $tableForeignKey) { - if ( ! isset($foreignKeys[$tableForeignKey['ForeignKey']])) { + if (! isset($foreignKeys[$tableForeignKey['ForeignKey']])) { $foreignKeys[$tableForeignKey['ForeignKey']] = [ 'local_columns' => [$tableForeignKey['ColumnName']], 'foreign_table' => $tableForeignKey['ReferenceTableName'], @@ -144,11 +140,11 @@ protected function _getPortableTableForeignKeysList($tableForeignKeys) 'name' => $tableForeignKey['ForeignKey'], 'options' => [ 'onUpdate' => str_replace('_', ' ', $tableForeignKey['update_referential_action_desc']), - 'onDelete' => str_replace('_', ' ', $tableForeignKey['delete_referential_action_desc']) - ] + 'onDelete' => str_replace('_', ' ', $tableForeignKey['delete_referential_action_desc']), + ], ]; } else { - $foreignKeys[$tableForeignKey['ForeignKey']]['local_columns'][] = $tableForeignKey['ColumnName']; + $foreignKeys[$tableForeignKey['ForeignKey']]['local_columns'][] = $tableForeignKey['ColumnName']; $foreignKeys[$tableForeignKey['ForeignKey']]['foreign_columns'][] = $tableForeignKey['ReferenceColumnName']; } } @@ -159,12 +155,12 @@ protected function _getPortableTableForeignKeysList($tableForeignKeys) /** * {@inheritdoc} */ - protected function _getPortableTableIndexesList($tableIndexRows, $tableName=null) + protected function _getPortableTableIndexesList($tableIndexRows, $tableName = null) { foreach ($tableIndexRows as &$tableIndex) { - $tableIndex['non_unique'] = (boolean) $tableIndex['non_unique']; - $tableIndex['primary'] = (boolean) $tableIndex['primary']; - $tableIndex['flags'] = $tableIndex['flags'] ? [$tableIndex['flags']] : null; + $tableIndex['non_unique'] = (bool) $tableIndex['non_unique']; + $tableIndex['primary'] = (bool) $tableIndex['primary']; + $tableIndex['flags'] = $tableIndex['flags'] ? [$tableIndex['flags']] : null; } return parent::_getPortableTableIndexesList($tableIndexRows, $tableName); @@ -230,18 +226,18 @@ public function listTableIndexes($table) try { $tableIndexes = $this->_conn->fetchAll($sql); - } catch (\PDOException $e) { - if ($e->getCode() == "IMSSP") { + } catch (PDOException $e) { + if ($e->getCode() === 'IMSSP') { return []; - } else { - throw $e; } + + throw $e; } catch (DBALException $e) { if (strpos($e->getMessage(), 'SQLSTATE [01000, 15472]') === 0) { return []; - } else { - throw $e; } + + throw $e; } return $this->_getPortableTableIndexesList($tableIndexes, $table); @@ -279,8 +275,8 @@ private function getColumnConstraintSQL($table, $column) ON Tab.[ID] = Sysobjects.[Parent_Obj] INNER JOIN sys.default_constraints DefCons ON DefCons.[object_id] = Sysobjects.[ID] INNER JOIN SysColumns Col ON Col.[ColID] = DefCons.[parent_column_id] AND Col.[ID] = Tab.[ID] - WHERE Col.[Name] = " . $this->_conn->quote($column) ." AND Tab.[Name] = " . $this->_conn->quote($table) . " - ORDER BY Col.[Name]"; + WHERE Col.[Name] = " . $this->_conn->quote($column) . ' AND Tab.[Name] = ' . $this->_conn->quote($table) . ' + ORDER BY Col.[Name]'; } /** diff --git a/lib/Doctrine/DBAL/Schema/Schema.php b/lib/Doctrine/DBAL/Schema/Schema.php index 8de3f95daba..7f3fe2304ff 100644 --- a/lib/Doctrine/DBAL/Schema/Schema.php +++ b/lib/Doctrine/DBAL/Schema/Schema.php @@ -2,11 +2,11 @@ namespace Doctrine\DBAL\Schema; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\Visitor\CreateSchemaSqlCollector; use Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector; use Doctrine\DBAL\Schema\Visitor\NamespaceVisitor; use Doctrine\DBAL\Schema\Visitor\Visitor; -use Doctrine\DBAL\Platforms\AbstractPlatform; use function array_keys; use function strpos; use function strtolower; @@ -36,8 +36,6 @@ * executed. * * @link www.doctrine-project.org - * @since 2.0 - * @author Benjamin Eberlei */ class Schema extends AbstractAsset { @@ -48,34 +46,27 @@ class Schema extends AbstractAsset */ private $namespaces = []; - /** - * @var \Doctrine\DBAL\Schema\Table[] - */ + /** @var Table[] */ protected $_tables = []; - /** - * @var \Doctrine\DBAL\Schema\Sequence[] - */ + /** @var Sequence[] */ protected $_sequences = []; - /** - * @var SchemaConfig - */ + /** @var SchemaConfig */ protected $_schemaConfig = false; /** - * @param \Doctrine\DBAL\Schema\Table[] $tables - * @param \Doctrine\DBAL\Schema\Sequence[] $sequences - * @param \Doctrine\DBAL\Schema\SchemaConfig $schemaConfig - * @param array $namespaces + * @param Table[] $tables + * @param Sequence[] $sequences + * @param array $namespaces */ public function __construct( array $tables = [], array $sequences = [], - SchemaConfig $schemaConfig = null, + ?SchemaConfig $schemaConfig = null, array $namespaces = [] ) { - if ($schemaConfig == null) { + if ($schemaConfig === null) { $schemaConfig = new SchemaConfig(); } $this->_schemaConfig = $schemaConfig; @@ -103,22 +94,20 @@ public function hasExplicitForeignKeyIndexes() } /** - * @param \Doctrine\DBAL\Schema\Table $table - * * @return void * - * @throws \Doctrine\DBAL\Schema\SchemaException + * @throws SchemaException */ protected function _addTable(Table $table) { $namespaceName = $table->getNamespaceName(); - $tableName = $table->getFullQualifiedName($this->getName()); + $tableName = $table->getFullQualifiedName($this->getName()); if (isset($this->_tables[$tableName])) { throw SchemaException::tableAlreadyExists($tableName); } - if ( ! $table->isInDefaultNamespace($this->getName()) && ! $this->hasNamespace($namespaceName)) { + if (! $table->isInDefaultNamespace($this->getName()) && ! $this->hasNamespace($namespaceName)) { $this->createNamespace($namespaceName); } @@ -127,22 +116,20 @@ protected function _addTable(Table $table) } /** - * @param \Doctrine\DBAL\Schema\Sequence $sequence - * * @return void * - * @throws \Doctrine\DBAL\Schema\SchemaException + * @throws SchemaException */ protected function _addSequence(Sequence $sequence) { $namespaceName = $sequence->getNamespaceName(); - $seqName = $sequence->getFullQualifiedName($this->getName()); + $seqName = $sequence->getFullQualifiedName($this->getName()); if (isset($this->_sequences[$seqName])) { throw SchemaException::sequenceAlreadyExists($seqName); } - if ( ! $sequence->isInDefaultNamespace($this->getName()) && ! $this->hasNamespace($namespaceName)) { + if (! $sequence->isInDefaultNamespace($this->getName()) && ! $this->hasNamespace($namespaceName)) { $this->createNamespace($namespaceName); } @@ -162,7 +149,7 @@ public function getNamespaces() /** * Gets all tables of this schema. * - * @return \Doctrine\DBAL\Schema\Table[] + * @return Table[] */ public function getTables() { @@ -172,14 +159,14 @@ public function getTables() /** * @param string $tableName * - * @return \Doctrine\DBAL\Schema\Table + * @return Table * - * @throws \Doctrine\DBAL\Schema\SchemaException + * @throws SchemaException */ public function getTable($tableName) { $tableName = $this->getFullQualifiedAssetName($tableName); - if (!isset($this->_tables[$tableName])) { + if (! isset($this->_tables[$tableName])) { throw SchemaException::tableDoesNotExist($tableName); } @@ -195,8 +182,8 @@ private function getFullQualifiedAssetName($name) { $name = $this->getUnquotedAssetName($name); - if (strpos($name, ".") === false) { - $name = $this->getName() . "." . $name; + if (strpos($name, '.') === false) { + $name = $this->getName() . '.' . $name; } return strtolower($name); @@ -271,14 +258,14 @@ public function hasSequence($sequenceName) /** * @param string $sequenceName * - * @return \Doctrine\DBAL\Schema\Sequence + * @return Sequence * - * @throws \Doctrine\DBAL\Schema\SchemaException + * @throws SchemaException */ public function getSequence($sequenceName) { $sequenceName = $this->getFullQualifiedAssetName($sequenceName); - if (!$this->hasSequence($sequenceName)) { + if (! $this->hasSequence($sequenceName)) { throw SchemaException::sequenceDoesNotExist($sequenceName); } @@ -286,7 +273,7 @@ public function getSequence($sequenceName) } /** - * @return \Doctrine\DBAL\Schema\Sequence[] + * @return Sequence[] */ public function getSequences() { @@ -320,7 +307,7 @@ public function createNamespace($namespaceName) * * @param string $tableName * - * @return \Doctrine\DBAL\Schema\Table + * @return Table */ public function createTable($tableName) { @@ -376,9 +363,9 @@ public function dropTable($tableName) * @param int $allocationSize * @param int $initialValue * - * @return \Doctrine\DBAL\Schema\Sequence + * @return Sequence */ - public function createSequence($sequenceName, $allocationSize=1, $initialValue=1) + public function createSequence($sequenceName, $allocationSize = 1, $initialValue = 1) { $seq = new Sequence($sequenceName, $allocationSize, $initialValue); $this->_addSequence($seq); @@ -402,8 +389,6 @@ public function dropSequence($sequenceName) /** * Returns an array of necessary SQL queries to create the schema on the given platform. * - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform - * * @return array */ public function toSql(AbstractPlatform $platform) @@ -417,8 +402,6 @@ public function toSql(AbstractPlatform $platform) /** * Return an array of necessary SQL queries to drop the schema on the given platform. * - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform - * * @return array */ public function toDropSql(AbstractPlatform $platform) @@ -430,9 +413,6 @@ public function toDropSql(AbstractPlatform $platform) } /** - * @param \Doctrine\DBAL\Schema\Schema $toSchema - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform - * * @return array */ public function getMigrateToSql(Schema $toSchema, AbstractPlatform $platform) @@ -444,9 +424,6 @@ public function getMigrateToSql(Schema $toSchema, AbstractPlatform $platform) } /** - * @param \Doctrine\DBAL\Schema\Schema $fromSchema - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform - * * @return array */ public function getMigrateFromSql(Schema $fromSchema, AbstractPlatform $platform) @@ -458,8 +435,6 @@ public function getMigrateFromSql(Schema $fromSchema, AbstractPlatform $platform } /** - * @param \Doctrine\DBAL\Schema\Visitor\Visitor $visitor - * * @return void */ public function visit(Visitor $visitor) diff --git a/lib/Doctrine/DBAL/Schema/SchemaConfig.php b/lib/Doctrine/DBAL/Schema/SchemaConfig.php index e0b09050e1d..de3bae5d5e5 100644 --- a/lib/Doctrine/DBAL/Schema/SchemaConfig.php +++ b/lib/Doctrine/DBAL/Schema/SchemaConfig.php @@ -6,29 +6,19 @@ * Configuration for a Schema. * * @link www.doctrine-project.org - * @since 2.0 - * @author Benjamin Eberlei */ class SchemaConfig { - /** - * @var bool - */ + /** @var bool */ protected $hasExplicitForeignKeyIndexes = false; - /** - * @var int - */ + /** @var int */ protected $maxIdentifierLength = 63; - /** - * @var string - */ + /** @var string */ protected $name; - /** - * @var array - */ + /** @var array */ protected $defaultTableOptions = []; /** diff --git a/lib/Doctrine/DBAL/Schema/SchemaDiff.php b/lib/Doctrine/DBAL/Schema/SchemaDiff.php index 12ef74dabe4..f1102bd4e55 100644 --- a/lib/Doctrine/DBAL/Schema/SchemaDiff.php +++ b/lib/Doctrine/DBAL/Schema/SchemaDiff.php @@ -2,23 +2,17 @@ namespace Doctrine\DBAL\Schema; -use \Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\AbstractPlatform; use function array_merge; /** * Schema Diff. * * @link www.doctrine-project.org - * @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved. - * @license http://ez.no/licenses/new_bsd New BSD License - * @since 2.0 - * @author Benjamin Eberlei */ class SchemaDiff { - /** - * @var \Doctrine\DBAL\Schema\Schema - */ + /** @var Schema */ public $fromSchema; /** @@ -38,53 +32,44 @@ class SchemaDiff /** * All added tables. * - * @var \Doctrine\DBAL\Schema\Table[] + * @var Table[] */ public $newTables = []; /** * All changed tables. * - * @var \Doctrine\DBAL\Schema\TableDiff[] + * @var TableDiff[] */ public $changedTables = []; /** * All removed tables. * - * @var \Doctrine\DBAL\Schema\Table[] + * @var Table[] */ public $removedTables = []; - /** - * @var \Doctrine\DBAL\Schema\Sequence[] - */ + /** @var Sequence[] */ public $newSequences = []; - /** - * @var \Doctrine\DBAL\Schema\Sequence[] - */ + /** @var Sequence[] */ public $changedSequences = []; - /** - * @var \Doctrine\DBAL\Schema\Sequence[] - */ + /** @var Sequence[] */ public $removedSequences = []; - /** - * @var \Doctrine\DBAL\Schema\ForeignKeyConstraint[] - */ + /** @var ForeignKeyConstraint[] */ public $orphanedForeignKeys = []; /** * Constructs an SchemaDiff object. * - * @param \Doctrine\DBAL\Schema\Table[] $newTables - * @param \Doctrine\DBAL\Schema\TableDiff[] $changedTables - * @param \Doctrine\DBAL\Schema\Table[] $removedTables - * @param \Doctrine\DBAL\Schema\Schema|null $fromSchema + * @param Table[] $newTables + * @param TableDiff[] $changedTables + * @param Table[] $removedTables */ - public function __construct($newTables = [], $changedTables = [], $removedTables = [], Schema $fromSchema = null) + public function __construct($newTables = [], $changedTables = [], $removedTables = [], ?Schema $fromSchema = null) { $this->newTables = $newTables; $this->changedTables = $changedTables; @@ -101,8 +86,6 @@ public function __construct($newTables = [], $changedTables = [], $removedTables * * This way it is ensured that assets are deleted which might not be relevant to the metadata schema at all. * - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform - * * @return array */ public function toSaveSql(AbstractPlatform $platform) @@ -111,8 +94,6 @@ public function toSaveSql(AbstractPlatform $platform) } /** - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform - * * @return array */ public function toSql(AbstractPlatform $platform) @@ -121,8 +102,7 @@ public function toSql(AbstractPlatform $platform) } /** - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform - * @param bool $saveMode + * @param bool $saveMode * * @return array */ @@ -136,13 +116,13 @@ protected function _toSql(AbstractPlatform $platform, $saveMode = false) } } - if ($platform->supportsForeignKeyConstraints() && $saveMode == false) { + if ($platform->supportsForeignKeyConstraints() && $saveMode === false) { foreach ($this->orphanedForeignKeys as $orphanedForeignKey) { $sql[] = $platform->getDropForeignKeySQL($orphanedForeignKey, $orphanedForeignKey->getLocalTable()); } } - if ($platform->supportsSequences() == true) { + if ($platform->supportsSequences() === true) { foreach ($this->changedSequences as $sequence) { $sql[] = $platform->getAlterSequenceSQL($sequence); } @@ -165,10 +145,12 @@ protected function _toSql(AbstractPlatform $platform, $saveMode = false) $platform->getCreateTableSQL($table, AbstractPlatform::CREATE_INDEXES) ); - if ($platform->supportsForeignKeyConstraints()) { - foreach ($table->getForeignKeys() as $foreignKey) { - $foreignKeySql[] = $platform->getCreateForeignKeySQL($foreignKey, $table); - } + if (! $platform->supportsForeignKeyConstraints()) { + continue; + } + + foreach ($table->getForeignKeys() as $foreignKey) { + $foreignKeySql[] = $platform->getCreateForeignKeySQL($foreignKey, $table); } } $sql = array_merge($sql, $foreignKeySql); diff --git a/lib/Doctrine/DBAL/Schema/SchemaException.php b/lib/Doctrine/DBAL/Schema/SchemaException.php index 93966fe8b5c..afc332ad5c2 100644 --- a/lib/Doctrine/DBAL/Schema/SchemaException.php +++ b/lib/Doctrine/DBAL/Schema/SchemaException.php @@ -2,22 +2,23 @@ namespace Doctrine\DBAL\Schema; +use Doctrine\DBAL\DBALException; use function implode; use function sprintf; -class SchemaException extends \Doctrine\DBAL\DBALException +class SchemaException extends DBALException { - const TABLE_DOESNT_EXIST = 10; - const TABLE_ALREADY_EXISTS = 20; - const COLUMN_DOESNT_EXIST = 30; - const COLUMN_ALREADY_EXISTS = 40; - const INDEX_DOESNT_EXIST = 50; - const INDEX_ALREADY_EXISTS = 60; - const SEQUENCE_DOENST_EXIST = 70; - const SEQUENCE_ALREADY_EXISTS = 80; - const INDEX_INVALID_NAME = 90; - const FOREIGNKEY_DOESNT_EXIST = 100; - const NAMESPACE_ALREADY_EXISTS = 110; + public const TABLE_DOESNT_EXIST = 10; + public const TABLE_ALREADY_EXISTS = 20; + public const COLUMN_DOESNT_EXIST = 30; + public const COLUMN_ALREADY_EXISTS = 40; + public const INDEX_DOESNT_EXIST = 50; + public const INDEX_ALREADY_EXISTS = 60; + public const SEQUENCE_DOENST_EXIST = 70; + public const SEQUENCE_ALREADY_EXISTS = 80; + public const INDEX_INVALID_NAME = 90; + public const FOREIGNKEY_DOESNT_EXIST = 100; + public const NAMESPACE_ALREADY_EXISTS = 110; /** * @param string $tableName @@ -26,7 +27,7 @@ class SchemaException extends \Doctrine\DBAL\DBALException */ public static function tableDoesNotExist($tableName) { - return new self("There is no table with name '".$tableName."' in the schema.", self::TABLE_DOESNT_EXIST); + return new self("There is no table with name '" . $tableName . "' in the schema.", self::TABLE_DOESNT_EXIST); } /** @@ -92,7 +93,7 @@ public static function namespaceAlreadyExists($namespaceName) */ public static function tableAlreadyExists($tableName) { - return new self("The table with name '".$tableName."' already exists.", self::TABLE_ALREADY_EXISTS); + return new self("The table with name '" . $tableName . "' already exists.", self::TABLE_ALREADY_EXISTS); } /** @@ -104,7 +105,8 @@ public static function tableAlreadyExists($tableName) public static function columnAlreadyExists($tableName, $columnName) { return new self( - "The column '".$columnName."' on table '".$tableName."' already exists.", self::COLUMN_ALREADY_EXISTS + "The column '" . $columnName . "' on table '" . $tableName . "' already exists.", + self::COLUMN_ALREADY_EXISTS ); } @@ -115,7 +117,7 @@ public static function columnAlreadyExists($tableName, $columnName) */ public static function sequenceAlreadyExists($sequenceName) { - return new self("The sequence '".$sequenceName."' already exists.", self::SEQUENCE_ALREADY_EXISTS); + return new self("The sequence '" . $sequenceName . "' already exists.", self::SEQUENCE_ALREADY_EXISTS); } /** @@ -125,7 +127,7 @@ public static function sequenceAlreadyExists($sequenceName) */ public static function sequenceDoesNotExist($sequenceName) { - return new self("There exists no sequence with the name '".$sequenceName."'.", self::SEQUENCE_DOENST_EXIST); + return new self("There exists no sequence with the name '" . $sequenceName . "'.", self::SEQUENCE_DOENST_EXIST); } /** @@ -140,18 +142,15 @@ public static function foreignKeyDoesNotExist($fkName, $table) } /** - * @param \Doctrine\DBAL\Schema\Table $localTable - * @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey - * * @return \Doctrine\DBAL\Schema\SchemaException */ public static function namedForeignKeyRequired(Table $localTable, ForeignKeyConstraint $foreignKey) { return new self( - "The performed schema operation on ".$localTable->getName()." requires a named foreign key, ". - "but the given foreign key from (".implode(", ", $foreignKey->getColumns()).") onto foreign table ". - "'".$foreignKey->getForeignTableName()."' (".implode(", ", $foreignKey->getForeignColumns()).") is currently ". - "unnamed." + 'The performed schema operation on ' . $localTable->getName() . ' requires a named foreign key, ' . + 'but the given foreign key from (' . implode(', ', $foreignKey->getColumns()) . ') onto foreign table ' . + "'" . $foreignKey->getForeignTableName() . "' (" . implode(', ', $foreignKey->getForeignColumns()) . ') is currently ' . + 'unnamed.' ); } diff --git a/lib/Doctrine/DBAL/Schema/Sequence.php b/lib/Doctrine/DBAL/Schema/Sequence.php index 339bf81d237..c88f4b2f3c0 100644 --- a/lib/Doctrine/DBAL/Schema/Sequence.php +++ b/lib/Doctrine/DBAL/Schema/Sequence.php @@ -11,24 +11,16 @@ * Sequence structure. * * @link www.doctrine-project.org - * @since 2.0 - * @author Benjamin Eberlei */ class Sequence extends AbstractAsset { - /** - * @var int - */ + /** @var int */ protected $allocationSize = 1; - /** - * @var int - */ + /** @var int */ protected $initialValue = 1; - /** - * @var int|null - */ + /** @var int|null */ protected $cache = null; /** @@ -42,7 +34,7 @@ public function __construct($name, $allocationSize = 1, $initialValue = 1, $cach $this->_setName($name); $this->setAllocationSize($allocationSize); $this->setInitialValue($initialValue); - $this->cache = $cache; + $this->cache = $cache; } /** @@ -111,25 +103,23 @@ public function setCache($cache) * This is used inside the comparator to not report sequences as missing, * when the "from" schema implicitly creates the sequences. * - * @param \Doctrine\DBAL\Schema\Table $table - * * @return bool */ public function isAutoIncrementsFor(Table $table) { - if ( ! $table->hasPrimaryKey()) { + if (! $table->hasPrimaryKey()) { return false; } $pkColumns = $table->getPrimaryKey()->getColumns(); - if (count($pkColumns) != 1) { + if (count($pkColumns) !== 1) { return false; } $column = $table->getColumn($pkColumns[0]); - if ( ! $column->getAutoincrement()) { + if (! $column->getAutoincrement()) { return false; } @@ -141,8 +131,6 @@ public function isAutoIncrementsFor(Table $table) } /** - * @param \Doctrine\DBAL\Schema\Visitor\Visitor $visitor - * * @return void */ public function visit(Visitor $visitor) diff --git a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php index 74ade6ee854..b42b0e0d4e5 100644 --- a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php @@ -3,6 +3,7 @@ namespace Doctrine\DBAL\Schema; use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\Types\StringType; use Doctrine\DBAL\Types\TextType; @@ -29,12 +30,6 @@ /** * Sqlite SchemaManager. - * - * @author Konsta Vesterinen - * @author Lukas Smith (PEAR MDB2 library) - * @author Jonathan H. Wage - * @author Martin Hasoň - * @since 2.0 */ class SqliteSchemaManager extends AbstractSchemaManager { @@ -43,9 +38,11 @@ class SqliteSchemaManager extends AbstractSchemaManager */ public function dropDatabase($database) { - if (file_exists($database)) { - unlink($database); + if (! file_exists($database)) { + return; } + + unlink($database); } /** @@ -53,13 +50,13 @@ public function dropDatabase($database) */ public function createDatabase($database) { - $params = $this->_conn->getParams(); - $driver = $params['driver']; + $params = $this->_conn->getParams(); + $driver = $params['driver']; $options = [ 'driver' => $driver, - 'path' => $database + 'path' => $database, ]; - $conn = \Doctrine\DBAL\DriverManager::getConnection($options); + $conn = DriverManager::getConnection($options); $conn->connect(); $conn->close(); } @@ -69,9 +66,9 @@ public function createDatabase($database) */ public function renameTable($name, $newName) { - $tableDiff = new TableDiff($name); + $tableDiff = new TableDiff($name); $tableDiff->fromTable = $this->listTableDetails($name); - $tableDiff->newName = $newName; + $tableDiff->newName = $newName; $this->alterTable($tableDiff); } @@ -80,7 +77,7 @@ public function renameTable($name, $newName) */ public function createForeignKey(ForeignKeyConstraint $foreignKey, $table) { - $tableDiff = $this->getTableDiffForAlterForeignKey($foreignKey, $table); + $tableDiff = $this->getTableDiffForAlterForeignKey($foreignKey, $table); $tableDiff->addedForeignKeys[] = $foreignKey; $this->alterTable($tableDiff); @@ -91,7 +88,7 @@ public function createForeignKey(ForeignKeyConstraint $foreignKey, $table) */ public function dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, $table) { - $tableDiff = $this->getTableDiffForAlterForeignKey($foreignKey, $table); + $tableDiff = $this->getTableDiffForAlterForeignKey($foreignKey, $table); $tableDiff->changedForeignKeys[] = $foreignKey; $this->alterTable($tableDiff); @@ -102,7 +99,7 @@ public function dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, $table */ public function dropForeignKey($foreignKey, $table) { - $tableDiff = $this->getTableDiffForAlterForeignKey($foreignKey, $table); + $tableDiff = $this->getTableDiffForAlterForeignKey($foreignKey, $table); $tableDiff->removedForeignKeys[] = $foreignKey; $this->alterTable($tableDiff); @@ -113,17 +110,18 @@ public function dropForeignKey($foreignKey, $table) */ public function listTableForeignKeys($table, $database = null) { - if (null === $database) { + if ($database === null) { $database = $this->_conn->getDatabase(); } - $sql = $this->_platform->getListTableForeignKeysSQL($table, $database); + $sql = $this->_platform->getListTableForeignKeysSQL($table, $database); $tableForeignKeys = $this->_conn->fetchAll($sql); - if ( ! empty($tableForeignKeys)) { + if (! empty($tableForeignKeys)) { $createSql = $this->_conn->fetchAll("SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE type = 'table' AND name = '$table'"); $createSql = $createSql[0]['sql'] ?? ''; - if (preg_match_all('# + if (preg_match_all( + '# (?:CONSTRAINT\s+([^\s]+)\s+)? (?:FOREIGN\s+KEY[^\)]+\)\s*)? REFERENCES\s+[^\s]+\s+(?:\([^\)]+\))? @@ -132,18 +130,19 @@ public function listTableForeignKeys($table, $database = null) (NOT\s+DEFERRABLE|DEFERRABLE) (?:\s+INITIALLY\s+(DEFERRED|IMMEDIATE))? )?#isx', - $createSql, $match)) { - - $names = array_reverse($match[1]); + $createSql, + $match + )) { + $names = array_reverse($match[1]); $deferrable = array_reverse($match[2]); - $deferred = array_reverse($match[3]); + $deferred = array_reverse($match[3]); } else { $names = $deferrable = $deferred = []; } foreach ($tableForeignKeys as $key => $value) { - $id = $value['id']; - $tableForeignKeys[$key]['constraint_name'] = isset($names[$id]) && '' != $names[$id] ? $names[$id] : $id; + $id = $value['id']; + $tableForeignKeys[$key]['constraint_name'] = isset($names[$id]) && $names[$id] !== '' ? $names[$id] : $id; $tableForeignKeys[$key]['deferrable'] = isset($deferrable[$id]) && strtolower($deferrable[$id]) === 'deferrable'; $tableForeignKeys[$key]['deferred'] = isset($deferred[$id]) && strtolower($deferred[$id]) === 'deferred'; } @@ -163,52 +162,55 @@ protected function _getPortableTableDefinition($table) /** * {@inheritdoc} * - * @license New BSD License * @link http://ezcomponents.org/docs/api/trunk/DatabaseSchema/ezcDbSchemaPgsqlReader.html */ - protected function _getPortableTableIndexesList($tableIndexes, $tableName=null) + protected function _getPortableTableIndexesList($tableIndexes, $tableName = null) { $indexBuffer = []; // fetch primary - $stmt = $this->_conn->executeQuery("PRAGMA TABLE_INFO ('$tableName')"); + $stmt = $this->_conn->executeQuery("PRAGMA TABLE_INFO ('$tableName')"); $indexArray = $stmt->fetchAll(FetchMode::ASSOCIATIVE); - usort($indexArray, function($a, $b) { - if ($a['pk'] == $b['pk']) { + usort($indexArray, static function ($a, $b) { + if ($a['pk'] === $b['pk']) { return $a['cid'] - $b['cid']; } return $a['pk'] - $b['pk']; }); foreach ($indexArray as $indexColumnRow) { - if ($indexColumnRow['pk'] != "0") { - $indexBuffer[] = [ - 'key_name' => 'primary', - 'primary' => true, - 'non_unique' => false, - 'column_name' => $indexColumnRow['name'] - ]; + if ($indexColumnRow['pk'] === '0') { + continue; } + + $indexBuffer[] = [ + 'key_name' => 'primary', + 'primary' => true, + 'non_unique' => false, + 'column_name' => $indexColumnRow['name'], + ]; } // fetch regular indexes foreach ($tableIndexes as $tableIndex) { // Ignore indexes with reserved names, e.g. autoindexes - if (strpos($tableIndex['name'], 'sqlite_') !== 0) { - $keyName = $tableIndex['name']; - $idx = []; - $idx['key_name'] = $keyName; - $idx['primary'] = false; - $idx['non_unique'] = $tableIndex['unique']?false:true; - - $stmt = $this->_conn->executeQuery("PRAGMA INDEX_INFO ('{$keyName}')"); - $indexArray = $stmt->fetchAll(FetchMode::ASSOCIATIVE); - - foreach ($indexArray as $indexColumnRow) { - $idx['column_name'] = $indexColumnRow['name']; - $indexBuffer[] = $idx; - } + if (strpos($tableIndex['name'], 'sqlite_') === 0) { + continue; + } + + $keyName = $tableIndex['name']; + $idx = []; + $idx['key_name'] = $keyName; + $idx['primary'] = false; + $idx['non_unique'] = $tableIndex['unique']?false:true; + + $stmt = $this->_conn->executeQuery("PRAGMA INDEX_INFO ('{$keyName}')"); + $indexArray = $stmt->fetchAll(FetchMode::ASSOCIATIVE); + + foreach ($indexArray as $indexColumnRow) { + $idx['column_name'] = $indexColumnRow['name']; + $indexBuffer[] = $idx; } } @@ -222,7 +224,7 @@ protected function _getPortableTableIndexDefinition($tableIndex) { return [ 'name' => $tableIndex['name'], - 'unique' => (bool) $tableIndex['unique'] + 'unique' => (bool) $tableIndex['unique'], ]; } @@ -235,22 +237,28 @@ protected function _getPortableTableColumnList($table, $database, $tableColumns) // find column with autoincrement $autoincrementColumn = null; - $autoincrementCount = 0; + $autoincrementCount = 0; foreach ($tableColumns as $tableColumn) { - if ('0' != $tableColumn['pk']) { - $autoincrementCount++; - if (null === $autoincrementColumn && 'integer' == strtolower($tableColumn['type'])) { - $autoincrementColumn = $tableColumn['name']; - } + if ($tableColumn['pk'] === '0') { + continue; + } + + $autoincrementCount++; + if ($autoincrementColumn !== null || strtolower($tableColumn['type']) !== 'integer') { + continue; } + + $autoincrementColumn = $tableColumn['name']; } - if (1 == $autoincrementCount && null !== $autoincrementColumn) { + if ($autoincrementCount === 1 && $autoincrementColumn !== null) { foreach ($list as $column) { - if ($autoincrementColumn == $column->getName()) { - $column->setAutoincrement(true); + if ($autoincrementColumn !== $column->getName()) { + continue; } + + $column->setAutoincrement(true); } } @@ -267,17 +275,19 @@ protected function _getPortableTableColumnList($table, $database, $tableColumns) $comment = $this->parseColumnCommentFromSQL($columnName, $createSql); - if ($comment !== null) { - $type = $this->extractDoctrineTypeFromComment($comment, null); + if ($comment === null) { + continue; + } - if (null !== $type) { - $column->setType(Type::getType($type)); + $type = $this->extractDoctrineTypeFromComment($comment, null); - $comment = $this->removeDoctrineTypeFromComment($comment, $type); - } + if ($type !== null) { + $column->setType(Type::getType($type)); - $column->setComment($comment); + $comment = $this->removeDoctrineTypeFromComment($comment, $type); } + + $column->setComment($comment); } return $list; @@ -288,10 +298,10 @@ protected function _getPortableTableColumnList($table, $database, $tableColumns) */ protected function _getPortableTableColumnDefinition($tableColumn) { - $parts = explode('(', $tableColumn['type']); + $parts = explode('(', $tableColumn['type']); $tableColumn['type'] = trim($parts[0]); if (isset($parts[1])) { - $length = trim($parts[1], ')'); + $length = trim($parts[1], ')'); $tableColumn['length'] = $length; } @@ -300,14 +310,14 @@ protected function _getPortableTableColumnDefinition($tableColumn) $unsigned = false; if (strpos($dbType, ' unsigned') !== false) { - $dbType = str_replace(' unsigned', '', $dbType); + $dbType = str_replace(' unsigned', '', $dbType); $unsigned = true; } - $fixed = false; - $type = $this->_platform->getDoctrineTypeMapping($dbType); + $fixed = false; + $type = $this->_platform->getDoctrineTypeMapping($dbType); $default = $tableColumn['dflt_value']; - if ($default == 'NULL') { + if ($default === 'NULL') { $default = null; } if ($default !== null) { @@ -316,12 +326,12 @@ protected function _getPortableTableColumnDefinition($tableColumn) } $notnull = (bool) $tableColumn['notnull']; - if ( ! isset($tableColumn['name'])) { + if (! isset($tableColumn['name'])) { $tableColumn['name'] = ''; } $precision = null; - $scale = null; + $scale = null; switch ($dbType) { case 'char': @@ -334,9 +344,9 @@ protected function _getPortableTableColumnDefinition($tableColumn) case 'numeric': if (isset($tableColumn['length'])) { if (strpos($tableColumn['length'], ',') === false) { - $tableColumn['length'] .= ",0"; + $tableColumn['length'] .= ',0'; } - list($precision, $scale) = array_map('trim', explode(',', $tableColumn['length'])); + [$precision, $scale] = array_map('trim', explode(',', $tableColumn['length'])); } $length = null; break; @@ -353,7 +363,7 @@ protected function _getPortableTableColumnDefinition($tableColumn) 'autoincrement' => false, ]; - return new Column($tableColumn['name'], \Doctrine\DBAL\Types\Type::getType($type), $options); + return new Column($tableColumn['name'], Type::getType($type), $options); } /** @@ -372,12 +382,12 @@ protected function _getPortableTableForeignKeysList($tableForeignKeys) $list = []; foreach ($tableForeignKeys as $value) { $value = array_change_key_case($value, CASE_LOWER); - $name = $value['constraint_name']; - if ( ! isset($list[$name])) { - if ( ! isset($value['on_delete']) || $value['on_delete'] == "RESTRICT") { + $name = $value['constraint_name']; + if (! isset($list[$name])) { + if (! isset($value['on_delete']) || $value['on_delete'] === 'RESTRICT') { $value['on_delete'] = null; } - if ( ! isset($value['on_update']) || $value['on_update'] == "RESTRICT") { + if (! isset($value['on_update']) || $value['on_update'] === 'RESTRICT') { $value['on_update'] = null; } @@ -392,15 +402,17 @@ protected function _getPortableTableForeignKeysList($tableForeignKeys) 'deferred'=> $value['deferred'], ]; } - $list[$name]['local'][] = $value['from']; + $list[$name]['local'][] = $value['from']; $list[$name]['foreign'][] = $value['to']; } $result = []; foreach ($list as $constraint) { $result[] = new ForeignKeyConstraint( - array_values($constraint['local']), $constraint['foreignTable'], - array_values($constraint['foreign']), $constraint['name'], + array_values($constraint['local']), + $constraint['foreignTable'], + array_values($constraint['foreign']), + $constraint['name'], [ 'onDelete' => $constraint['onDelete'], 'onUpdate' => $constraint['onUpdate'], @@ -414,25 +426,24 @@ protected function _getPortableTableForeignKeysList($tableForeignKeys) } /** - * @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey - * @param \Doctrine\DBAL\Schema\Table|string $table + * @param Table|string $table * - * @return \Doctrine\DBAL\Schema\TableDiff + * @return TableDiff * - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ private function getTableDiffForAlterForeignKey(ForeignKeyConstraint $foreignKey, $table) { - if ( ! $table instanceof Table) { + if (! $table instanceof Table) { $tableDetails = $this->tryMethod('listTableDetails', $table); - if (false === $table) { + if ($table === false) { throw new DBALException(sprintf('Sqlite schema manager requires to modify foreign keys table definition "%s".', $table)); } $table = $tableDetails; } - $tableDiff = new TableDiff($table->getName()); + $tableDiff = new TableDiff($table->getName()); $tableDiff->fromTable = $table; return $tableDiff; @@ -461,6 +472,6 @@ private function parseColumnCommentFromSQL(string $column, string $sql) : ?strin $comment = preg_replace('{^\s*--}m', '', rtrim($match[1], "\n")); - return '' === $comment ? null : $comment; + return $comment === '' ? null : $comment; } } diff --git a/lib/Doctrine/DBAL/Schema/Synchronizer/AbstractSchemaSynchronizer.php b/lib/Doctrine/DBAL/Schema/Synchronizer/AbstractSchemaSynchronizer.php index 1515304dc32..8ed118421d8 100644 --- a/lib/Doctrine/DBAL/Schema/Synchronizer/AbstractSchemaSynchronizer.php +++ b/lib/Doctrine/DBAL/Schema/Synchronizer/AbstractSchemaSynchronizer.php @@ -3,20 +3,16 @@ namespace Doctrine\DBAL\Schema\Synchronizer; use Doctrine\DBAL\Connection; +use Throwable; /** * Abstract schema synchronizer with methods for executing batches of SQL. */ abstract class AbstractSchemaSynchronizer implements SchemaSynchronizer { - /** - * @var \Doctrine\DBAL\Connection - */ + /** @var Connection */ protected $conn; - /** - * @param \Doctrine\DBAL\Connection $conn - */ public function __construct(Connection $conn) { $this->conn = $conn; @@ -30,8 +26,7 @@ protected function processSqlSafely(array $sql) foreach ($sql as $s) { try { $this->conn->exec($s); - } catch (\Exception $e) { - + } catch (Throwable $e) { } } } diff --git a/lib/Doctrine/DBAL/Schema/Synchronizer/SchemaSynchronizer.php b/lib/Doctrine/DBAL/Schema/Synchronizer/SchemaSynchronizer.php index d2913ab42c9..4d996515c64 100644 --- a/lib/Doctrine/DBAL/Schema/Synchronizer/SchemaSynchronizer.php +++ b/lib/Doctrine/DBAL/Schema/Synchronizer/SchemaSynchronizer.php @@ -7,16 +7,12 @@ /** * The synchronizer knows how to synchronize a schema with the configured * database. - * - * @author Benjamin Eberlei */ interface SchemaSynchronizer { /** * Gets the SQL statements that can be executed to create the schema. * - * @param \Doctrine\DBAL\Schema\Schema $createSchema - * * @return array */ function getCreateSchema(Schema $createSchema); @@ -24,8 +20,7 @@ function getCreateSchema(Schema $createSchema); /** * Gets the SQL Statements to update given schema with the underlying db. * - * @param \Doctrine\DBAL\Schema\Schema $toSchema - * @param bool $noDrops + * @param bool $noDrops * * @return array */ @@ -34,8 +29,6 @@ function getUpdateSchema(Schema $toSchema, $noDrops = false); /** * Gets the SQL Statements to drop the given schema from underlying db. * - * @param \Doctrine\DBAL\Schema\Schema $dropSchema - * * @return array */ function getDropSchema(Schema $dropSchema); @@ -50,8 +43,6 @@ function getDropAllSchema(); /** * Creates the Schema. * - * @param \Doctrine\DBAL\Schema\Schema $createSchema - * * @return void */ function createSchema(Schema $createSchema); @@ -59,8 +50,7 @@ function createSchema(Schema $createSchema); /** * Updates the Schema to new schema version. * - * @param \Doctrine\DBAL\Schema\Schema $toSchema - * @param bool $noDrops + * @param bool $noDrops * * @return void */ @@ -69,8 +59,6 @@ function updateSchema(Schema $toSchema, $noDrops = false); /** * Drops the given database schema from the underlying db. * - * @param \Doctrine\DBAL\Schema\Schema $dropSchema - * * @return void */ function dropSchema(Schema $dropSchema); diff --git a/lib/Doctrine/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizer.php b/lib/Doctrine/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizer.php index 9e25c36ed9d..bd5dc5e8f8f 100644 --- a/lib/Doctrine/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizer.php +++ b/lib/Doctrine/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizer.php @@ -3,26 +3,20 @@ namespace Doctrine\DBAL\Schema\Synchronizer; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Schema\Schema; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\Comparator; +use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector; use function count; /** * Schema Synchronizer for Default DBAL Connection. - * - * @author Benjamin Eberlei */ class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer { - /** - * @var \Doctrine\DBAL\Platforms\AbstractPlatform - */ + /** @var AbstractPlatform */ private $platform; - /** - * @param \Doctrine\DBAL\Connection $conn - */ public function __construct(Connection $conn) { parent::__construct($conn); @@ -61,8 +55,8 @@ public function getUpdateSchema(Schema $toSchema, $noDrops = false) */ public function getDropSchema(Schema $dropSchema) { - $visitor = new DropSchemaSqlCollector($this->platform); - $sm = $this->conn->getSchemaManager(); + $visitor = new DropSchemaSqlCollector($this->platform); + $sm = $this->conn->getSchemaManager(); $fullSchema = $sm->createSchema(); @@ -72,11 +66,11 @@ public function getDropSchema(Schema $dropSchema) } foreach ($table->getForeignKeys() as $foreignKey) { - if ( ! $dropSchema->hasTable($table->getName())) { + if (! $dropSchema->hasTable($table->getName())) { continue; } - if ( ! $dropSchema->hasTable($foreignKey->getForeignTableName())) { + if (! $dropSchema->hasTable($foreignKey->getForeignTableName())) { continue; } @@ -84,7 +78,7 @@ public function getDropSchema(Schema $dropSchema) } } - if ( ! $this->platform->supportsSequences()) { + if (! $this->platform->supportsSequences()) { return $visitor->getQueries(); } @@ -93,7 +87,7 @@ public function getDropSchema(Schema $dropSchema) } foreach ($dropSchema->getTables() as $table) { - if ( ! $table->hasPrimaryKey()) { + if (! $table->hasPrimaryKey()) { continue; } @@ -102,10 +96,12 @@ public function getDropSchema(Schema $dropSchema) continue; } - $checkSequence = $table->getName() . "_" . $columns[0] . "_seq"; - if ($fullSchema->hasSequence($checkSequence)) { - $visitor->acceptSequence($fullSchema->getSequence($checkSequence)); + $checkSequence = $table->getName() . '_' . $columns[0] . '_seq'; + if (! $fullSchema->hasSequence($checkSequence)) { + continue; } + + $visitor->acceptSequence($fullSchema->getSequence($checkSequence)); } return $visitor->getQueries(); @@ -119,8 +115,8 @@ public function getDropAllSchema() $sm = $this->conn->getSchemaManager(); $visitor = new DropSchemaSqlCollector($this->platform); - /* @var $schema \Doctrine\DBAL\Schema\Schema */ - $schema = $sm->createSchema(); + /** @var Schema $schema */ + $schema = $sm->createSchema(); $schema->visit($visitor); return $visitor->getQueries(); diff --git a/lib/Doctrine/DBAL/Schema/Table.php b/lib/Doctrine/DBAL/Schema/Table.php index b6db40d75fe..628f7e303be 100644 --- a/lib/Doctrine/DBAL/Schema/Table.php +++ b/lib/Doctrine/DBAL/Schema/Table.php @@ -2,9 +2,9 @@ namespace Doctrine\DBAL\Schema; -use Doctrine\DBAL\Types\Type; -use Doctrine\DBAL\Schema\Visitor\Visitor; use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Schema\Visitor\Visitor; +use Doctrine\DBAL\Types\Type; use const ARRAY_FILTER_USE_KEY; use function array_filter; use function array_merge; @@ -19,49 +19,31 @@ * Object Representation of a table. * * @link www.doctrine-project.org - * @since 2.0 - * @author Benjamin Eberlei */ class Table extends AbstractAsset { - /** - * @var string - */ + /** @var string */ protected $_name = null; - /** - * @var Column[] - */ + /** @var Column[] */ protected $_columns = []; - /** - * @var Index[] - */ + /** @var Index[] */ private $implicitIndexes = []; - /** - * @var Index[] - */ + /** @var Index[] */ protected $_indexes = []; - /** - * @var string - */ + /** @var string */ protected $_primaryKeyName = false; - /** - * @var ForeignKeyConstraint[] - */ + /** @var ForeignKeyConstraint[] */ protected $_fkConstraints = []; - /** - * @var array - */ + /** @var array */ protected $_options = []; - /** - * @var SchemaConfig|null - */ + /** @var SchemaConfig|null */ protected $_schemaConfig = null; /** @@ -74,9 +56,9 @@ class Table extends AbstractAsset * * @throws DBALException */ - public function __construct($tableName, array $columns=[], array $indexes=[], array $fkConstraints=[], $idGeneratorType = 0, array $options=[]) + public function __construct($tableName, array $columns = [], array $indexes = [], array $fkConstraints = [], $idGeneratorType = 0, array $options = []) { - if (strlen($tableName) == 0) { + if (strlen($tableName) === 0) { throw DBALException::invalidTableName($tableName); } @@ -98,8 +80,6 @@ public function __construct($tableName, array $columns=[], array $indexes=[], ar } /** - * @param SchemaConfig $schemaConfig - * * @return void */ public function setSchemaConfig(SchemaConfig $schemaConfig) @@ -122,14 +102,14 @@ protected function _getMaxIdentifierLength() /** * Sets the Primary Key. * - * @param array $columns - * @param string|boolean $indexName + * @param array $columns + * @param string|bool $indexName * * @return self */ public function setPrimaryKey(array $columns, $indexName = false) { - $this->_addIndex($this->_createIndex($columns, $indexName ?: "primary", true, true)); + $this->_addIndex($this->_createIndex($columns, $indexName ?: 'primary', true, true)); foreach ($columns as $columnName) { $column = $this->getColumn($columnName); @@ -149,9 +129,11 @@ public function setPrimaryKey(array $columns, $indexName = false) */ public function addIndex(array $columnNames, $indexName = null, array $flags = [], array $options = []) { - if ($indexName == null) { + if ($indexName === null) { $indexName = $this->_generateIdentifierName( - array_merge([$this->getName()], $columnNames), "idx", $this->_getMaxIdentifierLength() + array_merge([$this->getName()], $columnNames), + 'idx', + $this->_getMaxIdentifierLength() ); } @@ -181,7 +163,7 @@ public function dropPrimaryKey() public function dropIndex($indexName) { $indexName = $this->normalizeIdentifier($indexName); - if ( ! $this->hasIndex($indexName)) { + if (! $this->hasIndex($indexName)) { throw SchemaException::indexDoesNotExist($indexName, $this->_name); } unset($this->_indexes[$indexName]); @@ -198,7 +180,9 @@ public function addUniqueIndex(array $columnNames, $indexName = null, array $opt { if ($indexName === null) { $indexName = $this->_generateIdentifierName( - array_merge([$this->getName()], $columnNames), "uniq", $this->_getMaxIdentifierLength() + array_merge([$this->getName()], $columnNames), + 'uniq', + $this->_getMaxIdentifierLength() ); } @@ -226,7 +210,7 @@ public function renameIndex($oldIndexName, $newIndexName = null) return $this; } - if ( ! $this->hasIndex($oldIndexName)) { + if (! $this->hasIndex($oldIndexName)) { throw SchemaException::indexDoesNotExist($oldIndexName, $this->_name); } @@ -261,7 +245,7 @@ public function renameIndex($oldIndexName, $newIndexName = null) public function columnsAreIndexed(array $columnsNames) { foreach ($this->getIndexes() as $index) { - /* @var $index Index */ + /** @var $index Index */ if ($index->spansColumns($columnsNames)) { return true; } @@ -293,7 +277,7 @@ private function _createIndex(array $columnNames, $indexName, $isUnique, $isPrim $columnName = $indexColOptions; } - if ( ! $this->hasColumn($columnName)) { + if (! $this->hasColumn($columnName)) { throw SchemaException::columnDoesNotExist($columnName, $this->_name); } } @@ -308,7 +292,7 @@ private function _createIndex(array $columnNames, $indexName, $isUnique, $isPrim * * @return Column */ - public function addColumn($columnName, $typeName, array $options=[]) + public function addColumn($columnName, $typeName, array $options = []) { $column = new Column($columnName, Type::getType($typeName), $options); @@ -320,18 +304,18 @@ public function addColumn($columnName, $typeName, array $options=[]) /** * Renames a Column. * + * @deprecated + * * @param string $oldColumnName * @param string $newColumnName * - * @deprecated - * * @throws DBALException */ public function renameColumn($oldColumnName, $newColumnName) { - throw new DBALException("Table#renameColumn() was removed, because it drops and recreates " . - "the column instead. There is no fix available, because a schema diff cannot reliably detect if a " . - "column was renamed or one column was created and another one dropped."); + throw new DBALException('Table#renameColumn() was removed, because it drops and recreates ' . + 'the column instead. There is no fix available, because a schema diff cannot reliably detect if a ' . + 'column was renamed or one column was created and another one dropped.'); } /** @@ -378,9 +362,9 @@ public function dropColumn($columnName) * * @return self */ - public function addForeignKeyConstraint($foreignTable, array $localColumnNames, array $foreignColumnNames, array $options=[], $constraintName = null) + public function addForeignKeyConstraint($foreignTable, array $localColumnNames, array $foreignColumnNames, array $options = [], $constraintName = null) { - $constraintName = $constraintName ?: $this->_generateIdentifierName(array_merge((array) $this->getName(), $localColumnNames), "fk", $this->_getMaxIdentifierLength()); + $constraintName = $constraintName ?: $this->_generateIdentifierName(array_merge((array) $this->getName(), $localColumnNames), 'fk', $this->_getMaxIdentifierLength()); return $this->addNamedForeignKeyConstraint($constraintName, $foreignTable, $localColumnNames, $foreignColumnNames, $options); } @@ -399,7 +383,7 @@ public function addForeignKeyConstraint($foreignTable, array $localColumnNames, * * @return self */ - public function addUnnamedForeignKeyConstraint($foreignTable, array $localColumnNames, array $foreignColumnNames, array $options=[]) + public function addUnnamedForeignKeyConstraint($foreignTable, array $localColumnNames, array $foreignColumnNames, array $options = []) { return $this->addForeignKeyConstraint($foreignTable, $localColumnNames, $foreignColumnNames, $options); } @@ -419,24 +403,28 @@ public function addUnnamedForeignKeyConstraint($foreignTable, array $localColumn * * @throws SchemaException */ - public function addNamedForeignKeyConstraint($name, $foreignTable, array $localColumnNames, array $foreignColumnNames, array $options=[]) + public function addNamedForeignKeyConstraint($name, $foreignTable, array $localColumnNames, array $foreignColumnNames, array $options = []) { if ($foreignTable instanceof Table) { foreach ($foreignColumnNames as $columnName) { - if ( ! $foreignTable->hasColumn($columnName)) { + if (! $foreignTable->hasColumn($columnName)) { throw SchemaException::columnDoesNotExist($columnName, $foreignTable->getName()); } } } foreach ($localColumnNames as $columnName) { - if ( ! $this->hasColumn($columnName)) { + if (! $this->hasColumn($columnName)) { throw SchemaException::columnDoesNotExist($columnName, $this->_name); } } $constraint = new ForeignKeyConstraint( - $localColumnNames, $foreignTable, $foreignColumnNames, $name, $options + $localColumnNames, + $foreignTable, + $foreignColumnNames, + $name, + $options ); $this->_addForeignKeyConstraint($constraint); @@ -457,8 +445,6 @@ public function addOption($name, $value) } /** - * @param Column $column - * * @return void * * @throws SchemaException @@ -478,26 +464,26 @@ protected function _addColumn(Column $column) /** * Adds an index to the table. * - * @param Index $indexCandidate - * * @return self * * @throws SchemaException */ protected function _addIndex(Index $indexCandidate) { - $indexName = $indexCandidate->getName(); - $indexName = $this->normalizeIdentifier($indexName); + $indexName = $indexCandidate->getName(); + $indexName = $this->normalizeIdentifier($indexName); $replacedImplicitIndexes = []; foreach ($this->implicitIndexes as $name => $implicitIndex) { - if ($implicitIndex->isFullfilledBy($indexCandidate) && isset($this->_indexes[$name])) { - $replacedImplicitIndexes[] = $name; + if (! $implicitIndex->isFullfilledBy($indexCandidate) || ! isset($this->_indexes[$name])) { + continue; } + + $replacedImplicitIndexes[] = $name; } if ((isset($this->_indexes[$indexName]) && ! in_array($indexName, $replacedImplicitIndexes, true)) || - ($this->_primaryKeyName != false && $indexCandidate->isPrimary()) + ($this->_primaryKeyName !== false && $indexCandidate->isPrimary()) ) { throw SchemaException::indexAlreadyExists($indexName, $this->_name); } @@ -516,8 +502,6 @@ protected function _addIndex(Index $indexCandidate) } /** - * @param ForeignKeyConstraint $constraint - * * @return void */ protected function _addForeignKeyConstraint(ForeignKeyConstraint $constraint) @@ -528,7 +512,9 @@ protected function _addForeignKeyConstraint(ForeignKeyConstraint $constraint) $name = $constraint->getName(); } else { $name = $this->_generateIdentifierName( - array_merge((array) $this->getName(), $constraint->getLocalColumns()), "fk", $this->_getMaxIdentifierLength() + array_merge((array) $this->getName(), $constraint->getLocalColumns()), + 'fk', + $this->_getMaxIdentifierLength() ); } $name = $this->normalizeIdentifier($name); @@ -538,9 +524,9 @@ protected function _addForeignKeyConstraint(ForeignKeyConstraint $constraint) // add an explicit index on the foreign key columns. If there is already an index that fulfils this requirements drop the request. // In the case of __construct calling this method during hydration from schema-details all the explicitly added indexes // lead to duplicates. This creates computation overhead in this case, however no duplicate indexes are ever added (based on columns). - $indexName = $this->_generateIdentifierName( + $indexName = $this->_generateIdentifierName( array_merge([$this->getName()], $constraint->getColumns()), - "idx", + 'idx', $this->_getMaxIdentifierLength() ); $indexCandidate = $this->_createIndex($constraint->getColumns(), $indexName, false, false); @@ -581,7 +567,7 @@ public function hasForeignKey($constraintName) public function getForeignKey($constraintName) { $constraintName = $this->normalizeIdentifier($constraintName); - if (!$this->hasForeignKey($constraintName)) { + if (! $this->hasForeignKey($constraintName)) { throw SchemaException::foreignKeyDoesNotExist($constraintName, $this->_name); } @@ -600,7 +586,7 @@ public function getForeignKey($constraintName) public function removeForeignKey($constraintName) { $constraintName = $this->normalizeIdentifier($constraintName); - if (!$this->hasForeignKey($constraintName)) { + if (! $this->hasForeignKey($constraintName)) { throw SchemaException::foreignKeyDoesNotExist($constraintName, $this->_name); } @@ -609,6 +595,7 @@ public function removeForeignKey($constraintName) /** * Returns ordered list of columns (primary keys are first, then foreign keys, then the rest) + * * @return Column[] */ public function getColumns() @@ -623,13 +610,14 @@ public function getColumns() /** * Returns foreign key columns + * * @return Column[] */ private function getForeignKeyColumns() { $foreignKeyColumns = []; foreach ($this->getForeignKeys() as $foreignKey) { - /* @var $foreignKey ForeignKeyConstraint */ + /** @var ForeignKeyConstraint $foreignKey */ $foreignKeyColumns = array_merge($foreignKeyColumns, $foreignKey->getColumns()); } return $this->filterColumns($foreignKeyColumns); @@ -637,12 +625,14 @@ private function getForeignKeyColumns() /** * Returns only columns that have specified names + * * @param array $columnNames + * * @return Column[] */ private function filterColumns(array $columnNames) { - return array_filter($this->_columns, function ($columnName) use ($columnNames) { + return array_filter($this->_columns, static function ($columnName) use ($columnNames) { return in_array($columnName, $columnNames, true); }, ARRAY_FILTER_USE_KEY); } @@ -673,7 +663,7 @@ public function hasColumn($columnName) public function getColumn($columnName) { $columnName = $this->normalizeIdentifier($columnName); - if ( ! $this->hasColumn($columnName)) { + if (! $this->hasColumn($columnName)) { throw SchemaException::columnDoesNotExist($columnName, $this->_name); } @@ -687,7 +677,7 @@ public function getColumn($columnName) */ public function getPrimaryKey() { - if ( ! $this->hasPrimaryKey()) { + if (! $this->hasPrimaryKey()) { return null; } @@ -703,8 +693,8 @@ public function getPrimaryKey() */ public function getPrimaryKeyColumns() { - if ( ! $this->hasPrimaryKey()) { - throw new DBALException("Table " . $this->getName() . " has no primary key."); + if (! $this->hasPrimaryKey()) { + throw new DBALException('Table ' . $this->getName() . ' has no primary key.'); } return $this->getPrimaryKey()->getColumns(); } @@ -716,7 +706,7 @@ public function getPrimaryKeyColumns() */ public function hasPrimaryKey() { - return ($this->_primaryKeyName && $this->hasIndex($this->_primaryKeyName)); + return $this->_primaryKeyName && $this->hasIndex($this->_primaryKeyName); } /** @@ -730,7 +720,7 @@ public function hasIndex($indexName) { $indexName = $this->normalizeIdentifier($indexName); - return (isset($this->_indexes[$indexName])); + return isset($this->_indexes[$indexName]); } /** @@ -745,7 +735,7 @@ public function hasIndex($indexName) public function getIndex($indexName) { $indexName = $this->normalizeIdentifier($indexName); - if ( ! $this->hasIndex($indexName)) { + if (! $this->hasIndex($indexName)) { throw SchemaException::indexDoesNotExist($indexName, $this->_name); } @@ -799,8 +789,6 @@ public function getOptions() } /** - * @param Visitor $visitor - * * @return void */ public function visit(Visitor $visitor) diff --git a/lib/Doctrine/DBAL/Schema/TableDiff.php b/lib/Doctrine/DBAL/Schema/TableDiff.php index 914f6caa1c4..75ca75ff4b3 100644 --- a/lib/Doctrine/DBAL/Schema/TableDiff.php +++ b/lib/Doctrine/DBAL/Schema/TableDiff.php @@ -8,74 +8,68 @@ * Table Diff. * * @link www.doctrine-project.org - * @since 2.0 - * @author Benjamin Eberlei */ class TableDiff { - /** - * @var string - */ + /** @var string */ public $name = null; - /** - * @var string|boolean - */ + /** @var string|bool */ public $newName = false; /** * All added fields. * - * @var \Doctrine\DBAL\Schema\Column[] + * @var Column[] */ public $addedColumns; /** * All changed fields. * - * @var \Doctrine\DBAL\Schema\ColumnDiff[] + * @var ColumnDiff[] */ public $changedColumns = []; /** * All removed fields. * - * @var \Doctrine\DBAL\Schema\Column[] + * @var Column[] */ public $removedColumns = []; /** * Columns that are only renamed from key to column instance name. * - * @var \Doctrine\DBAL\Schema\Column[] + * @var Column[] */ public $renamedColumns = []; /** * All added indexes. * - * @var \Doctrine\DBAL\Schema\Index[] + * @var Index[] */ public $addedIndexes = []; /** * All changed indexes. * - * @var \Doctrine\DBAL\Schema\Index[] + * @var Index[] */ public $changedIndexes = []; /** * All removed indexes * - * @var \Doctrine\DBAL\Schema\Index[] + * @var Index[] */ public $removedIndexes = []; /** * Indexes that are only renamed but are identical otherwise. * - * @var \Doctrine\DBAL\Schema\Index[] + * @var Index[] */ public $renamedIndexes = []; @@ -89,7 +83,7 @@ class TableDiff /** * All changed foreign keys * - * @var \Doctrine\DBAL\Schema\ForeignKeyConstraint[] + * @var ForeignKeyConstraint[] */ public $changedForeignKeys = []; @@ -100,41 +94,44 @@ class TableDiff */ public $removedForeignKeys = []; - /** - * @var \Doctrine\DBAL\Schema\Table - */ + /** @var Table */ public $fromTable; /** * Constructs an TableDiff object. * - * @param string $tableName - * @param \Doctrine\DBAL\Schema\Column[] $addedColumns - * @param \Doctrine\DBAL\Schema\ColumnDiff[] $changedColumns - * @param \Doctrine\DBAL\Schema\Column[] $removedColumns - * @param \Doctrine\DBAL\Schema\Index[] $addedIndexes - * @param \Doctrine\DBAL\Schema\Index[] $changedIndexes - * @param \Doctrine\DBAL\Schema\Index[] $removedIndexes - * @param \Doctrine\DBAL\Schema\Table|null $fromTable - */ - public function __construct($tableName, $addedColumns = [], - $changedColumns = [], $removedColumns = [], $addedIndexes = [], - $changedIndexes = [], $removedIndexes = [], Table $fromTable = null) - { - $this->name = $tableName; - $this->addedColumns = $addedColumns; + * @param string $tableName + * @param Column[] $addedColumns + * @param ColumnDiff[] $changedColumns + * @param Column[] $removedColumns + * @param Index[] $addedIndexes + * @param Index[] $changedIndexes + * @param Index[] $removedIndexes + */ + public function __construct( + $tableName, + $addedColumns = [], + $changedColumns = [], + $removedColumns = [], + $addedIndexes = [], + $changedIndexes = [], + $removedIndexes = [], + ?Table $fromTable = null + ) { + $this->name = $tableName; + $this->addedColumns = $addedColumns; $this->changedColumns = $changedColumns; $this->removedColumns = $removedColumns; - $this->addedIndexes = $addedIndexes; + $this->addedIndexes = $addedIndexes; $this->changedIndexes = $changedIndexes; $this->removedIndexes = $removedIndexes; - $this->fromTable = $fromTable; + $this->fromTable = $fromTable; } /** * @param AbstractPlatform $platform The platform to use for retrieving this table diff's name. * - * @return \Doctrine\DBAL\Schema\Identifier + * @return Identifier */ public function getName(AbstractPlatform $platform) { diff --git a/lib/Doctrine/DBAL/Schema/View.php b/lib/Doctrine/DBAL/Schema/View.php index 9d54cd1ff68..6170f63680b 100644 --- a/lib/Doctrine/DBAL/Schema/View.php +++ b/lib/Doctrine/DBAL/Schema/View.php @@ -6,14 +6,10 @@ * Representation of a Database View. * * @link www.doctrine-project.org - * @since 1.0 - * @author Benjamin Eberlei */ class View extends AbstractAsset { - /** - * @var string - */ + /** @var string */ private $_sql; /** diff --git a/lib/Doctrine/DBAL/Schema/Visitor/AbstractVisitor.php b/lib/Doctrine/DBAL/Schema/Visitor/AbstractVisitor.php index ec5a41ddebc..47169044274 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/AbstractVisitor.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/AbstractVisitor.php @@ -2,21 +2,18 @@ namespace Doctrine\DBAL\Schema\Visitor; -use Doctrine\DBAL\Schema\Table; -use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ForeignKeyConstraint; -use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Index; +use Doctrine\DBAL\Schema\Schema; +use Doctrine\DBAL\Schema\Sequence; +use Doctrine\DBAL\Schema\Table; /** * Abstract Visitor with empty methods for easy extension. */ class AbstractVisitor implements Visitor, NamespaceVisitor { - /** - * @param \Doctrine\DBAL\Schema\Schema $schema - */ public function acceptSchema(Schema $schema) { } @@ -28,40 +25,22 @@ public function acceptNamespace($namespaceName) { } - /** - * @param \Doctrine\DBAL\Schema\Table $table - */ public function acceptTable(Table $table) { } - /** - * @param \Doctrine\DBAL\Schema\Table $table - * @param \Doctrine\DBAL\Schema\Column $column - */ public function acceptColumn(Table $table, Column $column) { } - /** - * @param \Doctrine\DBAL\Schema\Table $localTable - * @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $fkConstraint - */ public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) { } - /** - * @param \Doctrine\DBAL\Schema\Table $table - * @param \Doctrine\DBAL\Schema\Index $index - */ public function acceptIndex(Table $table, Index $index) { } - /** - * @param \Doctrine\DBAL\Schema\Sequence $sequence - */ public function acceptSequence(Sequence $sequence) { } diff --git a/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php b/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php index 70328e6d45b..673592d4c38 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php @@ -3,42 +3,28 @@ namespace Doctrine\DBAL\Schema\Visitor; use Doctrine\DBAL\Platforms\AbstractPlatform; -use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\Sequence; +use Doctrine\DBAL\Schema\Table; use function array_merge; class CreateSchemaSqlCollector extends AbstractVisitor { - /** - * @var array - */ + /** @var array */ private $createNamespaceQueries = []; - /** - * @var array - */ + /** @var array */ private $createTableQueries = []; - /** - * @var array - */ + /** @var array */ private $createSequenceQueries = []; - /** - * @var array - */ + /** @var array */ private $createFkConstraintQueries = []; - /** - * - * @var \Doctrine\DBAL\Platforms\AbstractPlatform - */ + /** @var AbstractPlatform */ private $platform = null; - /** - * @param AbstractPlatform $platform - */ public function __construct(AbstractPlatform $platform) { $this->platform = $platform; @@ -49,9 +35,11 @@ public function __construct(AbstractPlatform $platform) */ public function acceptNamespace($namespaceName) { - if ($this->platform->supportsSchemas()) { - $this->createNamespaceQueries[] = $this->platform->getCreateSchemaSQL($namespaceName); + if (! $this->platform->supportsSchemas()) { + return; } + + $this->createNamespaceQueries[] = $this->platform->getCreateSchemaSQL($namespaceName); } /** @@ -67,9 +55,11 @@ public function acceptTable(Table $table) */ public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) { - if ($this->platform->supportsForeignKeyConstraints()) { - $this->createFkConstraintQueries[] = $this->platform->getCreateForeignKeySQL($fkConstraint, $localTable); + if (! $this->platform->supportsForeignKeyConstraints()) { + return; } + + $this->createFkConstraintQueries[] = $this->platform->getCreateForeignKeySQL($fkConstraint, $localTable); } /** @@ -85,9 +75,9 @@ public function acceptSequence(Sequence $sequence) */ public function resetQueries() { - $this->createNamespaceQueries = []; - $this->createTableQueries = []; - $this->createSequenceQueries = []; + $this->createNamespaceQueries = []; + $this->createTableQueries = []; + $this->createSequenceQueries = []; $this->createFkConstraintQueries = []; } diff --git a/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php b/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php index b5f0e0ce934..33364de0c1a 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php @@ -3,44 +3,32 @@ namespace Doctrine\DBAL\Schema\Visitor; use Doctrine\DBAL\Platforms\AbstractPlatform; -use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\ForeignKeyConstraint; -use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\SchemaException; +use Doctrine\DBAL\Schema\Sequence; +use Doctrine\DBAL\Schema\Table; +use SplObjectStorage; use function strlen; /** * Gathers SQL statements that allow to completely drop the current schema. * * @link www.doctrine-project.org - * @since 2.0 - * @author Benjamin Eberlei */ class DropSchemaSqlCollector extends AbstractVisitor { - /** - * @var \SplObjectStorage - */ + /** @var SplObjectStorage */ private $constraints; - /** - * @var \SplObjectStorage - */ + /** @var SplObjectStorage */ private $sequences; - /** - * @var \SplObjectStorage - */ + /** @var SplObjectStorage */ private $tables; - /** - * @var AbstractPlatform - */ + /** @var AbstractPlatform */ private $platform; - /** - * @param AbstractPlatform $platform - */ public function __construct(AbstractPlatform $platform) { $this->platform = $platform; @@ -60,7 +48,7 @@ public function acceptTable(Table $table) */ public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) { - if (strlen($fkConstraint->getName()) == 0) { + if (strlen($fkConstraint->getName()) === 0) { throw SchemaException::namedForeignKeyRequired($localTable, $fkConstraint); } @@ -80,9 +68,9 @@ public function acceptSequence(Sequence $sequence) */ public function clearQueries() { - $this->constraints = new \SplObjectStorage(); - $this->sequences = new \SplObjectStorage(); - $this->tables = new \SplObjectStorage(); + $this->constraints = new SplObjectStorage(); + $this->sequences = new SplObjectStorage(); + $this->tables = new SplObjectStorage(); } /** @@ -94,7 +82,7 @@ public function getQueries() foreach ($this->constraints as $fkConstraint) { $localTable = $this->constraints[$fkConstraint]; - $sql[] = $this->platform->getDropForeignKeySQL($fkConstraint, $localTable); + $sql[] = $this->platform->getDropForeignKeySQL($fkConstraint, $localTable); } foreach ($this->sequences as $sequence) { diff --git a/lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php b/lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php index 56908226350..f07c4301f32 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php @@ -2,9 +2,9 @@ namespace Doctrine\DBAL\Schema\Visitor; -use Doctrine\DBAL\Schema\Table; -use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\ForeignKeyConstraint; +use Doctrine\DBAL\Schema\Schema; +use Doctrine\DBAL\Schema\Table; use function current; use function file_put_contents; use function in_array; @@ -17,9 +17,7 @@ */ class Graphviz extends AbstractVisitor { - /** - * @var string - */ + /** @var string */ private $output = ''; /** @@ -28,8 +26,8 @@ class Graphviz extends AbstractVisitor public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) { $this->output .= $this->createNodeRelation( - $fkConstraint->getLocalTableName() . ":col" . current($fkConstraint->getLocalColumns()).":se", - $fkConstraint->getForeignTableName() . ":col" . current($fkConstraint->getForeignColumns()).":se", + $fkConstraint->getLocalTableName() . ':col' . current($fkConstraint->getLocalColumns()) . ':se', + $fkConstraint->getForeignTableName() . ':col' . current($fkConstraint->getForeignColumns()) . ':se', [ 'dir' => 'back', 'arrowtail' => 'dot', @@ -46,7 +44,7 @@ public function acceptSchema(Schema $schema) $this->output = 'digraph "' . sha1(mt_rand()) . '" {' . "\n"; $this->output .= 'splines = true;' . "\n"; $this->output .= 'overlap = false;' . "\n"; - $this->output .= 'outputorder=edgesfirst;'."\n"; + $this->output .= 'outputorder=edgesfirst;' . "\n"; $this->output .= 'mindist = 0.6;' . "\n"; $this->output .= 'sep = .2;' . "\n"; } @@ -66,8 +64,6 @@ public function acceptTable(Table $table) } /** - * @param \Doctrine\DBAL\Schema\Table $table - * * @return string */ private function createTableLabel(Table $table) @@ -86,7 +82,7 @@ private function createTableLabel(Table $table) $label .= ''; $label .= '' . $columnLabel . ''; $label .= '' . strtolower($column->getType()) . ''; - $label .= ''; + $label .= ''; if ($table->hasPrimaryKey() && in_array($column->getName(), $table->getPrimaryKey()->getColumns())) { $label .= "\xe2\x9c\xb7"; } @@ -107,7 +103,7 @@ private function createTableLabel(Table $table) */ private function createNode($name, $options) { - $node = $name . " ["; + $node = $name . ' ['; foreach ($options as $key => $value) { $node .= $key . '=' . $value . ' '; } @@ -141,7 +137,7 @@ private function createNodeRelation($node1, $node2, $options) */ public function getOutput() { - return $this->output . "}"; + return $this->output . '}'; } /** diff --git a/lib/Doctrine/DBAL/Schema/Visitor/NamespaceVisitor.php b/lib/Doctrine/DBAL/Schema/Visitor/NamespaceVisitor.php index b04935982c3..35d18d6c4b8 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/NamespaceVisitor.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/NamespaceVisitor.php @@ -5,9 +5,7 @@ /** * Visitor that can visit schema namespaces. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ interface NamespaceVisitor { diff --git a/lib/Doctrine/DBAL/Schema/Visitor/RemoveNamespacedAssets.php b/lib/Doctrine/DBAL/Schema/Visitor/RemoveNamespacedAssets.php index 5f3c8645c07..9b23b395885 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/RemoveNamespacedAssets.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/RemoveNamespacedAssets.php @@ -2,10 +2,10 @@ namespace Doctrine\DBAL\Schema\Visitor; -use Doctrine\DBAL\Schema\Table; -use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\ForeignKeyConstraint; +use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Sequence; +use Doctrine\DBAL\Schema\Table; /** * Removes assets from a schema that are not in the default namespace. @@ -17,15 +17,10 @@ * * This visitor filters all these non-default namespaced tables and sequences * and removes them from the SChema instance. - * - * @author Benjamin Eberlei - * @since 2.2 */ class RemoveNamespacedAssets extends AbstractVisitor { - /** - * @var \Doctrine\DBAL\Schema\Schema - */ + /** @var Schema */ private $schema; /** @@ -41,9 +36,11 @@ public function acceptSchema(Schema $schema) */ public function acceptTable(Table $table) { - if ( ! $table->isInDefaultNamespace($this->schema->getName())) { - $this->schema->dropTable($table->getName()); + if ($table->isInDefaultNamespace($this->schema->getName())) { + return; } + + $this->schema->dropTable($table->getName()); } /** @@ -51,9 +48,11 @@ public function acceptTable(Table $table) */ public function acceptSequence(Sequence $sequence) { - if ( ! $sequence->isInDefaultNamespace($this->schema->getName())) { - $this->schema->dropSequence($sequence->getName()); + if ($sequence->isInDefaultNamespace($this->schema->getName())) { + return; } + + $this->schema->dropSequence($sequence->getName()); } /** @@ -64,14 +63,16 @@ public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkCons // The table may already be deleted in a previous // RemoveNamespacedAssets#acceptTable call. Removing Foreign keys that // point to nowhere. - if ( ! $this->schema->hasTable($fkConstraint->getForeignTableName())) { + if (! $this->schema->hasTable($fkConstraint->getForeignTableName())) { $localTable->removeForeignKey($fkConstraint->getName()); return; } $foreignTable = $this->schema->getTable($fkConstraint->getForeignTableName()); - if ( ! $foreignTable->isInDefaultNamespace($this->schema->getName())) { - $localTable->removeForeignKey($fkConstraint->getName()); + if ($foreignTable->isInDefaultNamespace($this->schema->getName())) { + return; } + + $localTable->removeForeignKey($fkConstraint->getName()); } } diff --git a/lib/Doctrine/DBAL/Schema/Visitor/SchemaDiffVisitor.php b/lib/Doctrine/DBAL/Schema/Visitor/SchemaDiffVisitor.php index 69bb23ecf59..593075816a8 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/SchemaDiffVisitor.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/SchemaDiffVisitor.php @@ -2,64 +2,40 @@ namespace Doctrine\DBAL\Schema\Visitor; -use Doctrine\DBAL\Schema\Table; -use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\Sequence; +use Doctrine\DBAL\Schema\Table; +use Doctrine\DBAL\Schema\TableDiff; /** * Visit a SchemaDiff. * * @link www.doctrine-project.org - * @since 2.4 - * @author Benjamin Eberlei */ interface SchemaDiffVisitor { /** * Visit an orphaned foreign key whose table was deleted. - * - * @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey */ function visitOrphanedForeignKey(ForeignKeyConstraint $foreignKey); /** * Visit a sequence that has changed. - * - * @param \Doctrine\DBAL\Schema\Sequence $sequence */ function visitChangedSequence(Sequence $sequence); /** * Visit a sequence that has been removed. - * - * @param \Doctrine\DBAL\Schema\Sequence $sequence */ function visitRemovedSequence(Sequence $sequence); - /** - * @param \Doctrine\DBAL\Schema\Sequence $sequence - */ function visitNewSequence(Sequence $sequence); - /** - * @param \Doctrine\DBAL\Schema\Table $table - */ function visitNewTable(Table $table); - /** - * @param \Doctrine\DBAL\Schema\Table $table - * @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $foreignKey - */ function visitNewTableForeignKey(Table $table, ForeignKeyConstraint $foreignKey); - /** - * @param \Doctrine\DBAL\Schema\Table $table - */ function visitRemovedTable(Table $table); - /** - * @param \Doctrine\DBAL\Schema\TableDiff $tableDiff - */ function visitChangedTable(TableDiff $tableDiff); } diff --git a/lib/Doctrine/DBAL/Schema/Visitor/Visitor.php b/lib/Doctrine/DBAL/Schema/Visitor/Visitor.php index e3dbed7839a..9cdea2d6d8a 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/Visitor.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/Visitor.php @@ -2,63 +2,46 @@ namespace Doctrine\DBAL\Schema\Visitor; -use Doctrine\DBAL\Schema\Table; -use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ForeignKeyConstraint; -use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Index; +use Doctrine\DBAL\Schema\Schema; +use Doctrine\DBAL\Schema\Sequence; +use Doctrine\DBAL\Schema\Table; /** * Schema Visitor used for Validation or Generation purposes. * * @link www.doctrine-project.org - * @since 2.0 - * @author Benjamin Eberlei */ interface Visitor { /** - * @param \Doctrine\DBAL\Schema\Schema $schema - * * @return void */ public function acceptSchema(Schema $schema); /** - * @param \Doctrine\DBAL\Schema\Table $table - * * @return void */ public function acceptTable(Table $table); /** - * @param \Doctrine\DBAL\Schema\Table $table - * @param \Doctrine\DBAL\Schema\Column $column - * * @return void */ public function acceptColumn(Table $table, Column $column); /** - * @param \Doctrine\DBAL\Schema\Table $localTable - * @param \Doctrine\DBAL\Schema\ForeignKeyConstraint $fkConstraint - * * @return void */ public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint); /** - * @param \Doctrine\DBAL\Schema\Table $table - * @param \Doctrine\DBAL\Schema\Index $index - * * @return void */ public function acceptIndex(Table $table, Index $index); /** - * @param \Doctrine\DBAL\Schema\Sequence $sequence - * * @return void */ public function acceptSequence(Sequence $sequence); diff --git a/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php b/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php index 90bfd76040f..02f124cc443 100644 --- a/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php +++ b/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php @@ -5,11 +5,12 @@ use Doctrine\Common\EventManager; use Doctrine\DBAL\Configuration; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Driver\Connection as DriverConnection; use Doctrine\DBAL\Driver; +use Doctrine\DBAL\Driver\Connection as DriverConnection; use Doctrine\DBAL\Event\ConnectionEventArgs; use Doctrine\DBAL\Events; use Doctrine\DBAL\Sharding\ShardChoser\ShardChoser; +use InvalidArgumentException; use function array_merge; use function is_numeric; use function is_string; @@ -46,65 +47,54 @@ * $shardManager = $conn->getShardManager(); * $shardManager->selectGlobal(); * $shardManager->selectShard($value); - * - * @author Benjamin Eberlei */ class PoolingShardConnection extends Connection { - /** - * @var DriverConnection[] - */ + /** @var DriverConnection[] */ private $activeConnections = []; - /** - * @var int|null - */ + /** @var int|null */ private $activeShardId; - /** - * @var mixed[] - */ + /** @var mixed[] */ private $connectionParameters = []; /** - * @param array $params - * @param \Doctrine\DBAL\Driver $driver - * @param \Doctrine\DBAL\Configuration $config - * @param \Doctrine\Common\EventManager $eventManager + * @param array $params * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ - public function __construct(array $params, Driver $driver, Configuration $config = null, EventManager $eventManager = null) + public function __construct(array $params, Driver $driver, ?Configuration $config = null, ?EventManager $eventManager = null) { if (! isset($params['global'], $params['shards'])) { - throw new \InvalidArgumentException("Connection Parameters require 'global' and 'shards' configurations."); + throw new InvalidArgumentException("Connection Parameters require 'global' and 'shards' configurations."); } if (! isset($params['shardChoser'])) { - throw new \InvalidArgumentException("Missing Shard Choser configuration 'shardChoser'"); + throw new InvalidArgumentException("Missing Shard Choser configuration 'shardChoser'"); } if (is_string($params['shardChoser'])) { - $params['shardChoser'] = new $params['shardChoser']; + $params['shardChoser'] = new $params['shardChoser'](); } - if ( ! ($params['shardChoser'] instanceof ShardChoser)) { - throw new \InvalidArgumentException("The 'shardChoser' configuration is not a valid instance of Doctrine\DBAL\Sharding\ShardChoser\ShardChoser"); + if (! ($params['shardChoser'] instanceof ShardChoser)) { + throw new InvalidArgumentException("The 'shardChoser' configuration is not a valid instance of Doctrine\DBAL\Sharding\ShardChoser\ShardChoser"); } $this->connectionParameters[0] = array_merge($params, $params['global']); foreach ($params['shards'] as $shard) { - if ( ! isset($shard['id'])) { - throw new \InvalidArgumentException("Missing 'id' for one configured shard. Please specify a unique shard-id."); + if (! isset($shard['id'])) { + throw new InvalidArgumentException("Missing 'id' for one configured shard. Please specify a unique shard-id."); } - if ( !is_numeric($shard['id']) || $shard['id'] < 1) { - throw new \InvalidArgumentException("Shard Id has to be a non-negative number."); + if (! is_numeric($shard['id']) || $shard['id'] < 1) { + throw new InvalidArgumentException('Shard Id has to be a non-negative number.'); } if (isset($this->connectionParameters[$shard['id']])) { - throw new \InvalidArgumentException("Shard " . $shard['id'] . " is duplicated in the configuration."); + throw new InvalidArgumentException('Shard ' . $shard['id'] . ' is duplicated in the configuration.'); } $this->connectionParameters[$shard['id']] = array_merge($params, $shard); @@ -178,7 +168,7 @@ public function getPassword() * * @return bool * - * @throws \Doctrine\DBAL\Sharding\ShardingException + * @throws ShardingException */ public function connect($shardId = null) { @@ -191,7 +181,7 @@ public function connect($shardId = null) } if ($this->getTransactionNestingLevel() > 0) { - throw new ShardingException("Cannot switch shard when transaction is active."); + throw new ShardingException('Cannot switch shard when transaction is active.'); } $this->activeShardId = (int) $shardId; @@ -227,7 +217,7 @@ protected function connectTo($shardId) $connectionParams = $this->connectionParameters[$shardId]; - $user = $connectionParams['user'] ?? null; + $user = $connectionParams['user'] ?? null; $password = $connectionParams['password'] ?? null; return $this->_driver->connect($connectionParams, $user, $password, $driverOptions); diff --git a/lib/Doctrine/DBAL/Sharding/PoolingShardManager.php b/lib/Doctrine/DBAL/Sharding/PoolingShardManager.php index dc606a8e616..7d3dc9b822b 100644 --- a/lib/Doctrine/DBAL/Sharding/PoolingShardManager.php +++ b/lib/Doctrine/DBAL/Sharding/PoolingShardManager.php @@ -3,32 +3,22 @@ namespace Doctrine\DBAL\Sharding; use Doctrine\DBAL\Sharding\ShardChoser\ShardChoser; +use RuntimeException; /** * Shard Manager for the Connection Pooling Shard Strategy - * - * @author Benjamin Eberlei */ class PoolingShardManager implements ShardManager { - /** - * @var PoolingShardConnection - */ + /** @var PoolingShardConnection */ private $conn; - /** - * @var ShardChoser - */ + /** @var ShardChoser */ private $choser; - /** - * @var string|null - */ + /** @var string|null */ private $currentDistributionValue; - /** - * @param PoolingShardConnection $conn - */ public function __construct(PoolingShardConnection $conn) { $params = $conn->getParams(); @@ -85,16 +75,16 @@ public function getShards() * * @return array * - * @throws \RuntimeException + * @throws RuntimeException */ public function queryAll($sql, array $params, array $types) { $shards = $this->getShards(); - if (!$shards) { - throw new \RuntimeException("No shards found."); + if (! $shards) { + throw new RuntimeException('No shards found.'); } - $result = []; + $result = []; $oldDistribution = $this->getCurrentDistributionValue(); foreach ($shards as $shard) { diff --git a/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php b/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php index 6272d476075..139cbd24eaf 100644 --- a/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php +++ b/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php @@ -2,13 +2,14 @@ namespace Doctrine\DBAL\Sharding\SQLAzure; -use Doctrine\DBAL\Schema\Schema; +use Closure; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Types\Type; - +use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Synchronizer\AbstractSchemaSynchronizer; -use Doctrine\DBAL\Schema\Synchronizer\SingleDatabaseSynchronizer; use Doctrine\DBAL\Schema\Synchronizer\SchemaSynchronizer; +use Doctrine\DBAL\Schema\Synchronizer\SingleDatabaseSynchronizer; +use Doctrine\DBAL\Types\Type; +use RuntimeException; use function array_merge; /** @@ -18,30 +19,19 @@ * by partitioning the passed schema into subschemas for the federation and the * global database and then applying the operations step by step using the * {@see \Doctrine\DBAL\Schema\Synchronizer\SingleDatabaseSynchronizer}. - * - * @author Benjamin Eberlei */ class SQLAzureFederationsSynchronizer extends AbstractSchemaSynchronizer { - const FEDERATION_TABLE_FEDERATED = 'azure.federated'; - const FEDERATION_DISTRIBUTION_NAME = 'azure.federatedOnDistributionName'; + public const FEDERATION_TABLE_FEDERATED = 'azure.federated'; + public const FEDERATION_DISTRIBUTION_NAME = 'azure.federatedOnDistributionName'; - /** - * @var \Doctrine\DBAL\Sharding\SQLAzure\SQLAzureShardManager - */ + /** @var SQLAzureShardManager */ private $shardManager; - /** - * @var \Doctrine\DBAL\Schema\Synchronizer\SchemaSynchronizer - */ + /** @var SchemaSynchronizer */ private $synchronizer; - /** - * @param \Doctrine\DBAL\Connection $conn - * @param \Doctrine\DBAL\Sharding\SQLAzure\SQLAzureShardManager $shardManager - * @param \Doctrine\DBAL\Schema\Synchronizer\SchemaSynchronizer|null $sync - */ - public function __construct(Connection $conn, SQLAzureShardManager $shardManager, SchemaSynchronizer $sync = null) + public function __construct(Connection $conn, SQLAzureShardManager $shardManager, ?SchemaSynchronizer $sync = null) { parent::__construct($conn); $this->shardManager = $shardManager; @@ -55,13 +45,13 @@ public function getCreateSchema(Schema $createSchema) { $sql = []; - list($global, $federation) = $this->partitionSchema($createSchema); + [$global, $federation] = $this->partitionSchema($createSchema); $globalSql = $this->synchronizer->getCreateSchema($global); if ($globalSql) { $sql[] = "-- Create Root Federation\n" . - "USE FEDERATION ROOT WITH RESET;"; - $sql = array_merge($sql, $globalSql); + 'USE FEDERATION ROOT WITH RESET;'; + $sql = array_merge($sql, $globalSql); } $federationSql = $this->synchronizer->getCreateSchema($federation); @@ -70,8 +60,8 @@ public function getCreateSchema(Schema $createSchema) $defaultValue = $this->getFederationTypeDefaultValue(); $sql[] = $this->getCreateFederationStatement(); - $sql[] = "USE FEDERATION " . $this->shardManager->getFederationName() . " (" . $this->shardManager->getDistributionKey() . " = " . $defaultValue . ") WITH RESET, FILTERING = OFF;"; - $sql = array_merge($sql, $federationSql); + $sql[] = 'USE FEDERATION ' . $this->shardManager->getFederationName() . ' (' . $this->shardManager->getDistributionKey() . ' = ' . $defaultValue . ') WITH RESET, FILTERING = OFF;'; + $sql = array_merge($sql, $federationSql); } return $sql; @@ -82,7 +72,7 @@ public function getCreateSchema(Schema $createSchema) */ public function getUpdateSchema(Schema $toSchema, $noDrops = false) { - return $this->work($toSchema, function ($synchronizer, $schema) use ($noDrops) { + return $this->work($toSchema, static function ($synchronizer, $schema) use ($noDrops) { return $synchronizer->getUpdateSchema($schema, $noDrops); }); } @@ -92,7 +82,7 @@ public function getUpdateSchema(Schema $toSchema, $noDrops = false) */ public function getDropSchema(Schema $dropSchema) { - return $this->work($dropSchema, function ($synchronizer, $schema) { + return $this->work($dropSchema, static function ($synchronizer, $schema) { return $synchronizer->getDropSchema($schema); }); } @@ -131,7 +121,7 @@ public function getDropAllSchema() if ($globalSql) { $sql[] = "-- Work on Root Federation\nUSE FEDERATION ROOT WITH RESET;"; - $sql = array_merge($sql, $globalSql); + $sql = array_merge($sql, $globalSql); } $shards = $this->shardManager->getShards(); @@ -139,15 +129,17 @@ public function getDropAllSchema() $this->shardManager->selectShard($shard['rangeLow']); $federationSql = $this->synchronizer->getDropAllSchema(); - if ($federationSql) { - $sql[] = "-- Work on Federation ID " . $shard['id'] . "\n" . - "USE FEDERATION " . $this->shardManager->getFederationName() . " (" . $this->shardManager->getDistributionKey() . " = " . $shard['rangeLow'].") WITH RESET, FILTERING = OFF;"; - $sql = array_merge($sql, $federationSql); + if (! $federationSql) { + continue; } + + $sql[] = '-- Work on Federation ID ' . $shard['id'] . "\n" . + 'USE FEDERATION ' . $this->shardManager->getFederationName() . ' (' . $this->shardManager->getDistributionKey() . ' = ' . $shard['rangeLow'] . ') WITH RESET, FILTERING = OFF;'; + $sql = array_merge($sql, $federationSql); } - $sql[] = "USE FEDERATION ROOT WITH RESET;"; - $sql[] = "DROP FEDERATION " . $this->shardManager->getFederationName(); + $sql[] = 'USE FEDERATION ROOT WITH RESET;'; + $sql[] = 'DROP FEDERATION ' . $this->shardManager->getFederationName(); return $sql; } @@ -161,8 +153,6 @@ public function dropAllSchema() } /** - * @param \Doctrine\DBAL\Schema\Schema $schema - * * @return array */ private function partitionSchema(Schema $schema) @@ -174,12 +164,11 @@ private function partitionSchema(Schema $schema) } /** - * @param \Doctrine\DBAL\Schema\Schema $schema - * @param bool $isFederation + * @param bool $isFederation * - * @return \Doctrine\DBAL\Schema\Schema + * @return Schema * - * @throws \RuntimeException + * @throws RuntimeException */ private function extractSchemaFederation(Schema $schema, $isFederation) { @@ -196,7 +185,7 @@ private function extractSchemaFederation(Schema $schema, $isFederation) foreach ($table->getForeignKeys() as $fk) { $foreignTable = $schema->getTable($fk->getForeignTableName()); if ($foreignTable->hasOption(self::FEDERATION_TABLE_FEDERATED) !== $isFederation) { - throw new \RuntimeException("Cannot have foreign key between global/federation."); + throw new RuntimeException('Cannot have foreign key between global/federation.'); } } } @@ -210,15 +199,12 @@ private function extractSchemaFederation(Schema $schema, $isFederation) * perform the given operation on the underlying schema synchronizer given * the different partitioned schema instances. * - * @param \Doctrine\DBAL\Schema\Schema $schema - * @param \Closure $operation - * * @return array */ - private function work(Schema $schema, \Closure $operation) + private function work(Schema $schema, Closure $operation) { - list($global, $federation) = $this->partitionSchema($schema); - $sql = []; + [$global, $federation] = $this->partitionSchema($schema); + $sql = []; $this->shardManager->selectGlobal(); $globalSql = $operation($this->synchronizer, $global); @@ -234,11 +220,13 @@ private function work(Schema $schema, \Closure $operation) $this->shardManager->selectShard($shard['rangeLow']); $federationSql = $operation($this->synchronizer, $federation); - if ($federationSql) { - $sql[] = "-- Work on Federation ID " . $shard['id'] . "\n" . - "USE FEDERATION " . $this->shardManager->getFederationName() . " (" . $this->shardManager->getDistributionKey() . " = " . $shard['rangeLow'].") WITH RESET, FILTERING = OFF;"; - $sql = array_merge($sql, $federationSql); + if (! $federationSql) { + continue; } + + $sql[] = '-- Work on Federation ID ' . $shard['id'] . "\n" . + 'USE FEDERATION ' . $this->shardManager->getFederationName() . ' (' . $this->shardManager->getDistributionKey() . ' = ' . $shard['rangeLow'] . ') WITH RESET, FILTERING = OFF;'; + $sql = array_merge($sql, $federationSql); } return $sql; @@ -273,10 +261,10 @@ private function getFederationTypeDefaultValue() */ private function getCreateFederationStatement() { - $federationType = Type::getType($this->shardManager->getDistributionType()); + $federationType = Type::getType($this->shardManager->getDistributionType()); $federationTypeSql = $federationType->getSQLDeclaration([], $this->conn->getDatabasePlatform()); return "--Create Federation\n" . - "CREATE FEDERATION " . $this->shardManager->getFederationName() . " (" . $this->shardManager->getDistributionKey() . " " . $federationTypeSql ." RANGE)"; + 'CREATE FEDERATION ' . $this->shardManager->getFederationName() . ' (' . $this->shardManager->getDistributionKey() . ' ' . $federationTypeSql . ' RANGE)'; } } diff --git a/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureShardManager.php b/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureShardManager.php index 0882a2d78bd..7c5dfe5c4be 100644 --- a/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureShardManager.php +++ b/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureShardManager.php @@ -6,71 +6,56 @@ use Doctrine\DBAL\Sharding\ShardingException; use Doctrine\DBAL\Sharding\ShardManager; use Doctrine\DBAL\Types\Type; +use RuntimeException; use function is_bool; use function is_scalar; use function sprintf; /** * Sharding using the SQL Azure Federations support. - * - * @author Benjamin Eberlei */ class SQLAzureShardManager implements ShardManager { - /** - * @var string - */ + /** @var string */ private $federationName; - /** - * @var bool - */ + /** @var bool */ private $filteringEnabled; - /** - * @var string - */ + /** @var string */ private $distributionKey; - /** - * @var string - */ + /** @var string */ private $distributionType; - /** - * @var \Doctrine\DBAL\Connection - */ + /** @var Connection */ private $conn; - /** - * @var string|null - */ + /** @var string|null */ private $currentDistributionValue; /** - * @param \Doctrine\DBAL\Connection $conn - * - * @throws \Doctrine\DBAL\Sharding\ShardingException + * @throws ShardingException */ public function __construct(Connection $conn) { $this->conn = $conn; - $params = $conn->getParams(); + $params = $conn->getParams(); - if ( ! isset($params['sharding']['federationName'])) { + if (! isset($params['sharding']['federationName'])) { throw ShardingException::missingDefaultFederationName(); } - if ( ! isset($params['sharding']['distributionKey'])) { + if (! isset($params['sharding']['distributionKey'])) { throw ShardingException::missingDefaultDistributionKey(); } - if ( ! isset($params['sharding']['distributionType'])) { + if (! isset($params['sharding']['distributionType'])) { throw ShardingException::missingDistributionType(); } - $this->federationName = $params['sharding']['federationName']; - $this->distributionKey = $params['sharding']['distributionKey']; + $this->federationName = $params['sharding']['federationName']; + $this->distributionKey = $params['sharding']['distributionKey']; $this->distributionType = $params['sharding']['distributionType']; $this->filteringEnabled = (bool) ($params['sharding']['filteringEnabled'] ?? false); } @@ -126,7 +111,7 @@ public function selectGlobal() throw ShardingException::activeTransaction(); } - $sql = "USE FEDERATION ROOT WITH RESET"; + $sql = 'USE FEDERATION ROOT WITH RESET'; $this->conn->exec($sql); $this->currentDistributionValue = null; } @@ -140,13 +125,13 @@ public function selectShard($distributionValue) throw ShardingException::activeTransaction(); } - if ($distributionValue === null || is_bool($distributionValue) || !is_scalar($distributionValue)) { + 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;", + $sql = sprintf( + 'USE FEDERATION %s (%s = %s) WITH RESET, FILTERING = %s;', $platform->quoteIdentifier($this->federationName), $platform->quoteIdentifier($this->distributionKey), $this->conn->quote($distributionValue), @@ -170,13 +155,13 @@ public function getCurrentDistributionValue() */ public function getShards() { - $sql = "SELECT member_id as id, + $sql = 'SELECT member_id as id, distribution_name as distribution_key, CAST(range_low AS CHAR) AS rangeLow, CAST(range_high AS CHAR) AS rangeHigh FROM sys.federation_member_distributions d INNER JOIN sys.federations f ON f.federation_id = d.federation_id - WHERE f.name = " . $this->conn->quote($this->federationName); + WHERE f.name = ' . $this->conn->quote($this->federationName); return $this->conn->fetchAll($sql); } @@ -187,11 +172,11 @@ public function getShards() public function queryAll($sql, array $params = [], array $types = []) { $shards = $this->getShards(); - if (!$shards) { - throw new \RuntimeException("No shards found for " . $this->federationName); + if (! $shards) { + throw new RuntimeException('No shards found for ' . $this->federationName); } - $result = []; + $result = []; $oldDistribution = $this->getCurrentDistributionValue(); foreach ($shards as $shard) { @@ -221,9 +206,9 @@ public function splitFederation($splitDistributionValue) { $type = Type::getType($this->distributionType); - $sql = "ALTER FEDERATION " . $this->getFederationName() . " " . - "SPLIT AT (" . $this->getDistributionKey() . " = " . - $this->conn->quote($splitDistributionValue, $type->getBindingType()) . ")"; + $sql = 'ALTER FEDERATION ' . $this->getFederationName() . ' ' . + 'SPLIT AT (' . $this->getDistributionKey() . ' = ' . + $this->conn->quote($splitDistributionValue, $type->getBindingType()) . ')'; $this->conn->exec($sql); } } diff --git a/lib/Doctrine/DBAL/Sharding/SQLAzure/Schema/MultiTenantVisitor.php b/lib/Doctrine/DBAL/Sharding/SQLAzure/Schema/MultiTenantVisitor.php index a53eee738b2..065af56ab09 100644 --- a/lib/Doctrine/DBAL/Sharding/SQLAzure/Schema/MultiTenantVisitor.php +++ b/lib/Doctrine/DBAL/Sharding/SQLAzure/Schema/MultiTenantVisitor.php @@ -2,13 +2,14 @@ namespace Doctrine\DBAL\Sharding\SQLAzure\Schema; -use Doctrine\DBAL\Schema\Visitor\Visitor; -use Doctrine\DBAL\Schema\Table; -use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ForeignKeyConstraint; -use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Index; +use Doctrine\DBAL\Schema\Schema; +use Doctrine\DBAL\Schema\Sequence; +use Doctrine\DBAL\Schema\Table; +use Doctrine\DBAL\Schema\Visitor\Visitor; +use RuntimeException; use function in_array; /** @@ -29,24 +30,16 @@ * (otherwise they will affect the same-id rows from other tenants as well). * SQLAzure throws errors when you try to create IDENTIY columns on federated * tables. - * - * @author Benjamin Eberlei */ class MultiTenantVisitor implements Visitor { - /** - * @var array - */ + /** @var array */ private $excludedTables = []; - /** - * @var string - */ + /** @var string */ private $tenantColumnName; - /** - * @var string - */ + /** @var string */ private $tenantColumnType = 'integer'; /** @@ -64,7 +57,7 @@ class MultiTenantVisitor implements Visitor */ public function __construct(array $excludedTables = [], $tenantColumnName = 'tenant_id', $distributionName = null) { - $this->excludedTables = $excludedTables; + $this->excludedTables = $excludedTables; $this->tenantColumnName = $tenantColumnName; $this->distributionName = $distributionName ?: $tenantColumnName; } @@ -79,12 +72,12 @@ public function acceptTable(Table $table) } $table->addColumn($this->tenantColumnName, $this->tenantColumnType, [ - 'default' => "federation_filtering_value('". $this->distributionName ."')", + 'default' => "federation_filtering_value('" . $this->distributionName . "')", ]); $clusteredIndex = $this->getClusteredIndex($table); - $indexColumns = $clusteredIndex->getColumns(); + $indexColumns = $clusteredIndex->getColumns(); $indexColumns[] = $this->tenantColumnName; if ($clusteredIndex->isPrimary()) { @@ -98,22 +91,24 @@ public function acceptTable(Table $table) } /** - * @param \Doctrine\DBAL\Schema\Table $table + * @param Table $table * - * @return \Doctrine\DBAL\Schema\Index + * @return Index * - * @throws \RuntimeException + * @throws RuntimeException */ private function getClusteredIndex($table) { foreach ($table->getIndexes() as $index) { if ($index->isPrimary() && ! $index->hasFlag('nonclustered')) { return $index; - } elseif ($index->hasFlag('clustered')) { + } + + if ($index->hasFlag('clustered')) { return $index; } } - throw new \RuntimeException("No clustered index found on table " . $table->getName()); + throw new RuntimeException('No clustered index found on table ' . $table->getName()); } /** diff --git a/lib/Doctrine/DBAL/Sharding/ShardChoser/MultiTenantShardChoser.php b/lib/Doctrine/DBAL/Sharding/ShardChoser/MultiTenantShardChoser.php index 9340ace68d9..584e8155ae9 100644 --- a/lib/Doctrine/DBAL/Sharding/ShardChoser/MultiTenantShardChoser.php +++ b/lib/Doctrine/DBAL/Sharding/ShardChoser/MultiTenantShardChoser.php @@ -7,8 +7,6 @@ /** * The MultiTenant Shard choser assumes that the distribution value directly * maps to the shard id. - * - * @author Benjamin Eberlei */ class MultiTenantShardChoser implements ShardChoser { diff --git a/lib/Doctrine/DBAL/Sharding/ShardChoser/ShardChoser.php b/lib/Doctrine/DBAL/Sharding/ShardChoser/ShardChoser.php index e4c5470b21b..d7db3b8615f 100644 --- a/lib/Doctrine/DBAL/Sharding/ShardChoser/ShardChoser.php +++ b/lib/Doctrine/DBAL/Sharding/ShardChoser/ShardChoser.php @@ -7,16 +7,13 @@ /** * Given a distribution value this shard-choser strategy will pick the shard to * connect to for retrieving rows with the distribution value. - * - * @author Benjamin Eberlei */ interface ShardChoser { /** * Picks a shard for the given distribution value. * - * @param string|int $distributionValue - * @param \Doctrine\DBAL\Sharding\PoolingShardConnection $conn + * @param string|int $distributionValue * * @return string|int */ diff --git a/lib/Doctrine/DBAL/Sharding/ShardManager.php b/lib/Doctrine/DBAL/Sharding/ShardManager.php index 76b743edfa7..843db03ff7a 100644 --- a/lib/Doctrine/DBAL/Sharding/ShardManager.php +++ b/lib/Doctrine/DBAL/Sharding/ShardManager.php @@ -17,8 +17,6 @@ * executed against the last shard that was selected. If a query is created for * a shard Y but then a shard X is selected when its actually executed you * will hit the wrong shard. - * - * @author Benjamin Eberlei */ interface ShardManager { @@ -39,7 +37,7 @@ function selectGlobal(); * * @return void * - * @throws \Doctrine\DBAL\Sharding\ShardingException If no value is passed as shard identifier. + * @throws ShardingException If no value is passed as shard identifier. */ function selectShard($distributionValue); diff --git a/lib/Doctrine/DBAL/Sharding/ShardingException.php b/lib/Doctrine/DBAL/Sharding/ShardingException.php index 9951a60090a..b46bda2ff0d 100644 --- a/lib/Doctrine/DBAL/Sharding/ShardingException.php +++ b/lib/Doctrine/DBAL/Sharding/ShardingException.php @@ -6,8 +6,6 @@ /** * Sharding related Exceptions - * - * @since 2.3 */ class ShardingException extends DBALException { @@ -16,7 +14,7 @@ class ShardingException extends DBALException */ public static function notImplemented() { - return new self("This functionality is not implemented with this sharding provider.", 1331557937); + return new self('This functionality is not implemented with this sharding provider.', 1331557937); } /** @@ -24,7 +22,7 @@ public static function notImplemented() */ public static function missingDefaultFederationName() { - return new self("SQLAzure requires a federation name to be set during sharding configuration.", 1332141280); + return new self('SQLAzure requires a federation name to be set during sharding configuration.', 1332141280); } /** @@ -32,7 +30,7 @@ public static function missingDefaultFederationName() */ public static function missingDefaultDistributionKey() { - return new self("SQLAzure requires a distribution key to be set during sharding configuration.", 1332141329); + return new self('SQLAzure requires a distribution key to be set during sharding configuration.', 1332141329); } /** @@ -40,7 +38,7 @@ public static function missingDefaultDistributionKey() */ public static function activeTransaction() { - return new self("Cannot switch shard during an active transaction.", 1332141766); + return new self('Cannot switch shard during an active transaction.', 1332141766); } /** @@ -48,7 +46,7 @@ public static function activeTransaction() */ public static function noShardDistributionValue() { - return new self("You have to specify a string or integer as shard distribution value.", 1332142103); + return new self('You have to specify a string or integer as shard distribution value.', 1332142103); } /** diff --git a/lib/Doctrine/DBAL/Statement.php b/lib/Doctrine/DBAL/Statement.php index 14983384b83..4b25274e65e 100644 --- a/lib/Doctrine/DBAL/Statement.php +++ b/lib/Doctrine/DBAL/Statement.php @@ -2,19 +2,20 @@ namespace Doctrine\DBAL; -use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Driver\Statement as DriverStatement; +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Types\Type; +use IteratorAggregate; +use PDO; +use Throwable; use function is_array; use function is_string; /** * A thin wrapper around a Doctrine\DBAL\Driver\Statement that adds support * for logging, DBAL mapping types, etc. - * - * @author Roman Borschel - * @since 2.0 */ -class Statement implements \IteratorAggregate, DriverStatement +class Statement implements IteratorAggregate, DriverStatement { /** * The SQL statement. @@ -47,28 +48,28 @@ class Statement implements \IteratorAggregate, DriverStatement /** * The underlying database platform. * - * @var \Doctrine\DBAL\Platforms\AbstractPlatform + * @var AbstractPlatform */ protected $platform; /** * The connection this statement is bound to and executed on. * - * @var \Doctrine\DBAL\Connection + * @var Connection */ protected $conn; /** * Creates a new Statement for the given SQL and Connection. * - * @param string $sql The SQL of the statement. - * @param \Doctrine\DBAL\Connection $conn The connection on which the statement should be executed. + * @param string $sql The SQL of the statement. + * @param Connection $conn The connection on which the statement should be executed. */ public function __construct($sql, Connection $conn) { - $this->sql = $sql; - $this->stmt = $conn->getWrappedConnection()->prepare($sql); - $this->conn = $conn; + $this->sql = $sql; + $this->stmt = $conn->getWrappedConnection()->prepare($sql); + $this->conn = $conn; $this->platform = $conn->getDatabasePlatform(); } @@ -89,13 +90,13 @@ public function __construct($sql, Connection $conn) public function bindValue($name, $value, $type = ParameterType::STRING) { $this->params[$name] = $value; - $this->types[$name] = $type; + $this->types[$name] = $type; if ($type !== null) { if (is_string($type)) { $type = Type::getType($type); } if ($type instanceof Type) { - $value = $type->convertToDatabaseValue($value, $this->platform); + $value = $type->convertToDatabaseValue($value, $this->platform); $bindingType = $type->getBindingType(); } else { $bindingType = $type; @@ -123,7 +124,7 @@ public function bindValue($name, $value, $type = ParameterType::STRING) public function bindParam($name, &$var, $type = ParameterType::STRING, $length = null) { $this->params[$name] = $var; - $this->types[$name] = $type; + $this->types[$name] = $type; return $this->stmt->bindParam($name, $var, $type, $length); } @@ -135,7 +136,7 @@ public function bindParam($name, &$var, $type = ParameterType::STRING, $length = * * @return bool TRUE on success, FALSE on failure. * - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ public function execute($params = null) { @@ -150,7 +151,7 @@ public function execute($params = null) try { $stmt = $this->stmt->execute($params); - } catch (\Exception $ex) { + } catch (Throwable $ex) { if ($logger) { $logger->stopQuery(); } @@ -166,7 +167,7 @@ public function execute($params = null) $logger->stopQuery(); } $this->params = []; - $this->types = []; + $this->types = []; return $stmt; } @@ -238,7 +239,7 @@ public function getIterator() /** * {@inheritdoc} */ - public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) + public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0) { return $this->stmt->fetch($fetchMode); } diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php index d9a88da73d2..37a1ecbb3da 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php @@ -2,7 +2,11 @@ namespace Doctrine\DBAL\Tools\Console\Command; +use Doctrine\DBAL\Driver\PDOConnection; use Doctrine\DBAL\Driver\PDOStatement; +use InvalidArgumentException; +use PDOException; +use RuntimeException; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -19,13 +23,9 @@ * Task for executing arbitrary SQL that can come from a file or directly from * the command line. * - * @link www.doctrine-project.org - * @since 2.0 - * @author Benjamin Eberlei - * @author Guilherme Blanco - * @author Jonathan Wage - * @author Roman Borschel * @deprecated Use a database client application instead + * + * @link www.doctrine-project.org */ class ImportCommand extends Command { @@ -37,10 +37,11 @@ protected function configure() $this ->setName('dbal:import') ->setDescription('Import SQL file(s) directly to Database.') - ->setDefinition([ - new InputArgument( - 'file', InputArgument::REQUIRED | InputArgument::IS_ARRAY, 'File path(s) of SQL to be executed.' - ) + ->setDefinition([new InputArgument( + 'file', + InputArgument::REQUIRED | InputArgument::IS_ARRAY, + 'File path(s) of SQL to be executed.' + ), ]) ->setHelp(<<getHelper('db')->getConnection(); - if (($fileNames = $input->getArgument('file')) !== null) { - foreach ((array) $fileNames as $fileName) { - $filePath = realpath($fileName); + if (($fileNames = $input->getArgument('file')) === null) { + return; + } - // Phar compatibility. - if (false === $filePath) { - $filePath = $fileName; - } + foreach ((array) $fileNames as $fileName) { + $filePath = realpath($fileName); - if ( ! file_exists($filePath)) { - throw new \InvalidArgumentException( - sprintf("SQL file '%s' does not exist.", $filePath) - ); - } elseif ( ! is_readable($filePath)) { - throw new \InvalidArgumentException( - sprintf("SQL file '%s' does not have read permissions.", $filePath) - ); - } + // Phar compatibility. + if ($filePath === false) { + $filePath = $fileName; + } - $output->write(sprintf("Processing file '%s'... ", $filePath)); - $sql = file_get_contents($filePath); + if (! file_exists($filePath)) { + throw new InvalidArgumentException( + sprintf("SQL file '%s' does not exist.", $filePath) + ); + } elseif (! is_readable($filePath)) { + throw new InvalidArgumentException( + sprintf("SQL file '%s' does not have read permissions.", $filePath) + ); + } - if ($conn instanceof \Doctrine\DBAL\Driver\PDOConnection) { - // PDO Drivers - try { - $lines = 0; + $output->write(sprintf("Processing file '%s'... ", $filePath)); + $sql = file_get_contents($filePath); - $stmt = $conn->prepare($sql); - assert($stmt instanceof PDOStatement); + if ($conn instanceof PDOConnection) { + // PDO Drivers + try { + $lines = 0; - $stmt->execute(); + $stmt = $conn->prepare($sql); + assert($stmt instanceof PDOStatement); - do { - // Required due to "MySQL has gone away!" issue - $stmt->fetch(); - $stmt->closeCursor(); + $stmt->execute(); - $lines++; - } while ($stmt->nextRowset()); + do { + // Required due to "MySQL has gone away!" issue + $stmt->fetch(); + $stmt->closeCursor(); - $output->write(sprintf('%d statements executed!', $lines) . PHP_EOL); - } catch (\PDOException $e) { - $output->write('error!' . PHP_EOL); + $lines++; + } while ($stmt->nextRowset()); - throw new \RuntimeException($e->getMessage(), $e->getCode(), $e); - } - } else { - // Non-PDO Drivers (ie. OCI8 driver) - $stmt = $conn->prepare($sql); - $rs = $stmt->execute(); + $output->write(sprintf('%d statements executed!', $lines) . PHP_EOL); + } catch (PDOException $e) { + $output->write('error!' . PHP_EOL); - if ($rs) { - $output->writeln('OK!' . PHP_EOL); - } else { - $error = $stmt->errorInfo(); + throw new RuntimeException($e->getMessage(), $e->getCode(), $e); + } + } else { + // Non-PDO Drivers (ie. OCI8 driver) + $stmt = $conn->prepare($sql); + $rs = $stmt->execute(); - $output->write('error!' . PHP_EOL); + if (! $rs) { + $error = $stmt->errorInfo(); - throw new \RuntimeException($error[2], $error[0]); - } + $output->write('error!' . PHP_EOL); - $stmt->closeCursor(); + throw new RuntimeException($error[2], $error[0]); } + + $output->writeln('OK!' . PHP_EOL); + + $stmt->closeCursor(); } } } diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php index 1647df07f62..9c560c5179d 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php @@ -2,7 +2,10 @@ namespace Doctrine\DBAL\Tools\Console\Command; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\Platforms\Keywords\ReservedKeywordsValidator; +use Doctrine\DBAL\Schema\Schema; +use InvalidArgumentException; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -13,9 +16,7 @@ class ReservedWordsCommand extends Command { - /** - * @var array - */ + /** @var array */ private $keywordListClasses = [ 'mysql' => 'Doctrine\DBAL\Platforms\Keywords\MySQLKeywords', 'mysql57' => 'Doctrine\DBAL\Platforms\Keywords\MySQL57Keywords', @@ -57,10 +58,12 @@ protected function configure() $this ->setName('dbal:reserved-words') ->setDescription('Checks if the current database contains identifiers that are reserved.') - ->setDefinition([ - new InputOption( - 'list', 'l', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Keyword-List name.' - ) + ->setDefinition([new InputOption( + 'list', + 'l', + InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, + 'Keyword-List name.' + ), ]) ->setHelp(<<getHelper('db')->getConnection(); $keywordLists = (array) $input->getOption('list'); - if ( ! $keywordLists) { + if (! $keywordLists) { $keywordLists = [ 'mysql', 'mysql57', @@ -129,27 +132,25 @@ protected function execute(InputInterface $input, OutputInterface $output) $keywords = []; foreach ($keywordLists as $keywordList) { - if (!isset($this->keywordListClasses[$keywordList])) { - throw new \InvalidArgumentException( - "There exists no keyword list with name '" . $keywordList . "'. ". - "Known lists: " . implode(", ", array_keys($this->keywordListClasses)) + if (! isset($this->keywordListClasses[$keywordList])) { + throw new InvalidArgumentException( + "There exists no keyword list with name '" . $keywordList . "'. " . + 'Known lists: ' . implode(', ', array_keys($this->keywordListClasses)) ); } - $class = $this->keywordListClasses[$keywordList]; - $keywords[] = new $class; + $class = $this->keywordListClasses[$keywordList]; + $keywords[] = new $class(); } - $output->write('Checking keyword violations for ' . implode(", ", $keywordLists) . "...", true); + $output->write('Checking keyword violations for ' . implode(', ', $keywordLists) . '...', true); - /* @var $schema \Doctrine\DBAL\Schema\Schema */ - $schema = $conn->getSchemaManager()->createSchema(); + /** @var Schema $schema */ + $schema = $conn->getSchemaManager()->createSchema(); $visitor = new ReservedKeywordsValidator($keywords); $schema->visit($visitor); $violations = $visitor->getViolations(); - if (count($violations) == 0) { - $output->write("No reserved keywords violations have been found!", true); - } else { + if (count($violations) !== 0) { $output->write('There are ' . count($violations) . ' reserved keyword violations in your database schema:', true); foreach ($violations as $violation) { $output->write(' - ' . $violation, true); @@ -158,6 +159,8 @@ protected function execute(InputInterface $input, OutputInterface $output) return 1; } + $output->write('No reserved keywords violations have been found!', true); + return 0; } } diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php index 36f7f4b6aec..e3e56f67eaf 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php @@ -3,11 +3,13 @@ namespace Doctrine\DBAL\Tools\Console\Command; use Doctrine\DBAL\Tools\Dumper; +use LogicException; +use RuntimeException; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; use function is_numeric; use function stripos; @@ -16,11 +18,6 @@ * the command line. * * @link www.doctrine-project.org - * @since 2.0 - * @author Benjamin Eberlei - * @author Guilherme Blanco - * @author Jonathan Wage - * @author Roman Borschel */ class RunSqlCommand extends Command { @@ -51,13 +48,13 @@ protected function execute(InputInterface $input, OutputInterface $output) $conn = $this->getHelper('db')->getConnection(); if (($sql = $input->getArgument('sql')) === null) { - throw new \RuntimeException("Argument 'SQL' is required in order to execute this command correctly."); + throw new RuntimeException("Argument 'SQL' is required in order to execute this command correctly."); } $depth = $input->getOption('depth'); - if ( ! is_numeric($depth)) { - throw new \LogicException("Option 'depth' must contains an integer value"); + if (! is_numeric($depth)) { + throw new LogicException("Option 'depth' must contains an integer value"); } if (stripos($sql, 'select') === 0 || $input->getOption('force-fetch')) { diff --git a/lib/Doctrine/DBAL/Tools/Console/ConsoleRunner.php b/lib/Doctrine/DBAL/Tools/Console/ConsoleRunner.php index 0642594ee3e..520a9af80aa 100644 --- a/lib/Doctrine/DBAL/Tools/Console/ConsoleRunner.php +++ b/lib/Doctrine/DBAL/Tools/Console/ConsoleRunner.php @@ -9,6 +9,7 @@ use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper; use Doctrine\DBAL\Version; use Symfony\Component\Console\Application; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\HelperSet; /** @@ -19,22 +20,19 @@ class ConsoleRunner /** * Create a Symfony Console HelperSet * - * @param Connection $connection - * * @return HelperSet */ public static function createHelperSet(Connection $connection) { return new HelperSet([ - 'db' => new ConnectionHelper($connection) + 'db' => new ConnectionHelper($connection), ]); } /** * Runs console with the given helperset. * - * @param \Symfony\Component\Console\Helper\HelperSet $helperSet - * @param \Symfony\Component\Console\Command\Command[] $commands + * @param Command[] $commands * * @return void */ @@ -52,8 +50,6 @@ public static function run(HelperSet $helperSet, $commands = []) } /** - * @param Application $cli - * * @return void */ public static function addCommands(Application $cli) diff --git a/lib/Doctrine/DBAL/Tools/Console/Helper/ConnectionHelper.php b/lib/Doctrine/DBAL/Tools/Console/Helper/ConnectionHelper.php index f85162139a8..5aa2ea9a5d1 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Helper/ConnectionHelper.php +++ b/lib/Doctrine/DBAL/Tools/Console/Helper/ConnectionHelper.php @@ -2,32 +2,25 @@ namespace Doctrine\DBAL\Tools\Console\Helper; -use Symfony\Component\Console\Helper\Helper; use Doctrine\DBAL\Connection; +use Symfony\Component\Console\Helper\Helper; /** * Doctrine CLI Connection Helper. * * @link www.doctrine-project.org - * @since 2.0 - * @author Benjamin Eberlei - * @author Guilherme Blanco - * @author Jonathan Wage - * @author Roman Borschel */ class ConnectionHelper extends Helper { /** * The Doctrine database Connection. * - * @var \Doctrine\DBAL\Connection + * @var Connection */ protected $_connection; /** - * Constructor. - * - * @param \Doctrine\DBAL\Connection $connection The Doctrine database Connection. + * @param Connection $connection The Doctrine database Connection. */ public function __construct(Connection $connection) { @@ -37,7 +30,7 @@ public function __construct(Connection $connection) /** * Retrieves the Doctrine database Connection. * - * @return \Doctrine\DBAL\Connection + * @return Connection */ public function getConnection() { diff --git a/lib/Doctrine/DBAL/Types/ArrayType.php b/lib/Doctrine/DBAL/Types/ArrayType.php index 994d52a4a6b..9bb8e578b23 100644 --- a/lib/Doctrine/DBAL/Types/ArrayType.php +++ b/lib/Doctrine/DBAL/Types/ArrayType.php @@ -12,8 +12,6 @@ /** * Type that maps a PHP array to a clob SQL type. - * - * @since 2.0 */ class ArrayType extends Type { @@ -43,7 +41,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) return null; } - $value = (is_resource($value)) ? stream_get_contents($value) : $value; + $value = is_resource($value) ? stream_get_contents($value) : $value; set_error_handler(function (int $code, string $message) : void { throw ConversionException::conversionFailedUnserialization($this->getName(), $message); diff --git a/lib/Doctrine/DBAL/Types/BigIntType.php b/lib/Doctrine/DBAL/Types/BigIntType.php index d579af34ad5..1d320d624d4 100644 --- a/lib/Doctrine/DBAL/Types/BigIntType.php +++ b/lib/Doctrine/DBAL/Types/BigIntType.php @@ -7,9 +7,6 @@ /** * Type that maps a database BIGINT to a PHP string. - * - * @author robo - * @since 2.0 */ class BigIntType extends Type implements PhpIntegerMappingType { @@ -42,6 +39,6 @@ public function getBindingType() */ public function convertToPHPValue($value, AbstractPlatform $platform) { - return (null === $value) ? null : (string) $value; + return $value === null ? null : (string) $value; } } diff --git a/lib/Doctrine/DBAL/Types/BinaryType.php b/lib/Doctrine/DBAL/Types/BinaryType.php index 418ed2ff0cc..14362e840ae 100644 --- a/lib/Doctrine/DBAL/Types/BinaryType.php +++ b/lib/Doctrine/DBAL/Types/BinaryType.php @@ -12,9 +12,6 @@ /** * Type that maps ab SQL BINARY/VARBINARY to a PHP resource stream. - * - * @author Steve Müller - * @since 2.5 */ class BinaryType extends Type { @@ -31,7 +28,7 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla */ public function convertToPHPValue($value, AbstractPlatform $platform) { - if (null === $value) { + if ($value === null) { return null; } @@ -42,7 +39,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) $value = $fp; } - if ( ! is_resource($value)) { + if (! is_resource($value)) { throw ConversionException::conversionFailed($value, self::BINARY); } diff --git a/lib/Doctrine/DBAL/Types/BlobType.php b/lib/Doctrine/DBAL/Types/BlobType.php index dafe9917dc4..c309f0f0637 100644 --- a/lib/Doctrine/DBAL/Types/BlobType.php +++ b/lib/Doctrine/DBAL/Types/BlobType.php @@ -12,8 +12,6 @@ /** * Type that maps an SQL BLOB to a PHP resource stream. - * - * @since 2.2 */ class BlobType extends Type { @@ -30,7 +28,7 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla */ public function convertToPHPValue($value, AbstractPlatform $platform) { - if (null === $value) { + if ($value === null) { return null; } @@ -41,7 +39,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) $value = $fp; } - if ( ! is_resource($value)) { + if (! is_resource($value)) { throw ConversionException::conversionFailed($value, self::BLOB); } diff --git a/lib/Doctrine/DBAL/Types/BooleanType.php b/lib/Doctrine/DBAL/Types/BooleanType.php index 77dc9eba617..976f00e1fb7 100644 --- a/lib/Doctrine/DBAL/Types/BooleanType.php +++ b/lib/Doctrine/DBAL/Types/BooleanType.php @@ -7,8 +7,6 @@ /** * Type that maps an SQL boolean to a PHP boolean. - * - * @since 2.0 */ class BooleanType extends Type { diff --git a/lib/Doctrine/DBAL/Types/ConversionException.php b/lib/Doctrine/DBAL/Types/ConversionException.php index 5ef88986c19..d618adc8a49 100644 --- a/lib/Doctrine/DBAL/Types/ConversionException.php +++ b/lib/Doctrine/DBAL/Types/ConversionException.php @@ -4,14 +4,12 @@ * Conversion Exception is thrown when the database to PHP conversion fails. * * @link www.doctrine-project.org - * @since 2.0 - * @author Benjamin Eberlei - * @author Guilherme Blanco - * @author Jonathan Wage - * @author Roman Borschel */ + namespace Doctrine\DBAL\Types; +use Doctrine\DBAL\DBALException; +use Throwable; use function get_class; use function gettype; use function implode; @@ -21,7 +19,7 @@ use function strlen; use function substr; -class ConversionException extends \Doctrine\DBAL\DBALException +class ConversionException extends DBALException { /** * Thrown when a Database to Doctrine Type Conversion fails. @@ -33,7 +31,7 @@ class ConversionException extends \Doctrine\DBAL\DBALException */ public static function conversionFailed($value, $toType) { - $value = (strlen($value) > 32) ? substr($value, 0, 20) . '...' : $value; + $value = strlen($value) > 32 ? substr($value, 0, 20) . '...' : $value; return new self('Could not convert database value "' . $value . '" to Doctrine Type ' . $toType); } @@ -42,16 +40,15 @@ public static function conversionFailed($value, $toType) * Thrown when a Database to Doctrine Type Conversion fails and we can make a statement * about the expected format. * - * @param string $value - * @param string $toType - * @param string $expectedFormat - * @param \Exception|null $previous + * @param string $value + * @param string $toType + * @param string $expectedFormat * * @return \Doctrine\DBAL\Types\ConversionException */ - public static function conversionFailedFormat($value, $toType, $expectedFormat, \Exception $previous = null) + public static function conversionFailedFormat($value, $toType, $expectedFormat, ?Throwable $previous = null) { - $value = (strlen($value) > 32) ? substr($value, 0, 20) . '...' : $value; + $value = strlen($value) > 32 ? substr($value, 0, 20) . '...' : $value; return new self( 'Could not convert database value "' . $value . '" to Doctrine Type ' . diff --git a/lib/Doctrine/DBAL/Types/DateImmutableType.php b/lib/Doctrine/DBAL/Types/DateImmutableType.php index 9438efd9781..196fc88c7b4 100644 --- a/lib/Doctrine/DBAL/Types/DateImmutableType.php +++ b/lib/Doctrine/DBAL/Types/DateImmutableType.php @@ -2,13 +2,11 @@ namespace Doctrine\DBAL\Types; +use DateTimeImmutable; use Doctrine\DBAL\Platforms\AbstractPlatform; /** * Immutable type of {@see DateType}. - * - * @since 2.6 - * @author Steve Müller */ class DateImmutableType extends DateType { @@ -25,18 +23,18 @@ public function getName() */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { - if (null === $value) { + if ($value === null) { return $value; } - if ($value instanceof \DateTimeImmutable) { + if ($value instanceof DateTimeImmutable) { return $value->format($platform->getDateFormatString()); } throw ConversionException::conversionFailedInvalidType( $value, $this->getName(), - ['null', \DateTimeImmutable::class] + ['null', DateTimeImmutable::class] ); } @@ -45,11 +43,11 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) */ public function convertToPHPValue($value, AbstractPlatform $platform) { - if ($value === null || $value instanceof \DateTimeImmutable) { + if ($value === null || $value instanceof DateTimeImmutable) { return $value; } - $dateTime = \DateTimeImmutable::createFromFormat('!' . $platform->getDateFormatString(), $value); + $dateTime = DateTimeImmutable::createFromFormat('!' . $platform->getDateFormatString(), $value); if (! $dateTime) { throw ConversionException::conversionFailedFormat( diff --git a/lib/Doctrine/DBAL/Types/DateIntervalType.php b/lib/Doctrine/DBAL/Types/DateIntervalType.php index 89425aa4547..30e61c9eaa5 100644 --- a/lib/Doctrine/DBAL/Types/DateIntervalType.php +++ b/lib/Doctrine/DBAL/Types/DateIntervalType.php @@ -2,7 +2,9 @@ namespace Doctrine\DBAL\Types; +use DateInterval; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Throwable; use function substr; /** @@ -35,11 +37,11 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { - if (null === $value) { + if ($value === null) { return null; } - if ($value instanceof \DateInterval) { + if ($value instanceof DateInterval) { return $value->format(self::FORMAT); } @@ -51,7 +53,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) */ public function convertToPHPValue($value, AbstractPlatform $platform) { - if ($value === null || $value instanceof \DateInterval) { + if ($value === null || $value instanceof DateInterval) { return $value; } @@ -63,14 +65,14 @@ public function convertToPHPValue($value, AbstractPlatform $platform) } try { - $interval = new \DateInterval($value); + $interval = new DateInterval($value); if ($negative) { $interval->invert = 1; } return $interval; - } catch (\Exception $exception) { + } catch (Throwable $exception) { throw ConversionException::conversionFailedFormat($value, $this->getName(), self::FORMAT, $exception); } } diff --git a/lib/Doctrine/DBAL/Types/DateTimeImmutableType.php b/lib/Doctrine/DBAL/Types/DateTimeImmutableType.php index 33a6841c9e2..fdda50faa44 100644 --- a/lib/Doctrine/DBAL/Types/DateTimeImmutableType.php +++ b/lib/Doctrine/DBAL/Types/DateTimeImmutableType.php @@ -2,13 +2,12 @@ namespace Doctrine\DBAL\Types; +use DateTimeImmutable; use Doctrine\DBAL\Platforms\AbstractPlatform; +use function date_create_immutable; /** * Immutable type of {@see DateTimeType}. - * - * @since 2.6 - * @author Steve Müller */ class DateTimeImmutableType extends DateTimeType { @@ -25,18 +24,18 @@ public function getName() */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { - if (null === $value) { + if ($value === null) { return $value; } - if ($value instanceof \DateTimeImmutable) { + if ($value instanceof DateTimeImmutable) { return $value->format($platform->getDateTimeFormatString()); } throw ConversionException::conversionFailedInvalidType( $value, $this->getName(), - ['null', \DateTimeImmutable::class] + ['null', DateTimeImmutable::class] ); } @@ -45,14 +44,14 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) */ public function convertToPHPValue($value, AbstractPlatform $platform) { - if ($value === null || $value instanceof \DateTimeImmutable) { + if ($value === null || $value instanceof DateTimeImmutable) { return $value; } - $dateTime = \DateTimeImmutable::createFromFormat($platform->getDateTimeFormatString(), $value); + $dateTime = DateTimeImmutable::createFromFormat($platform->getDateTimeFormatString(), $value); if (! $dateTime) { - $dateTime = \date_create_immutable($value); + $dateTime = date_create_immutable($value); } if (! $dateTime) { diff --git a/lib/Doctrine/DBAL/Types/DateTimeType.php b/lib/Doctrine/DBAL/Types/DateTimeType.php index 57db8afa9c8..962d9d38da0 100644 --- a/lib/Doctrine/DBAL/Types/DateTimeType.php +++ b/lib/Doctrine/DBAL/Types/DateTimeType.php @@ -2,13 +2,13 @@ namespace Doctrine\DBAL\Types; +use DateTime; +use DateTimeInterface; use Doctrine\DBAL\Platforms\AbstractPlatform; use function date_create; /** * Type that maps an SQL DATETIME/TIMESTAMP to a PHP DateTime object. - * - * @since 2.0 */ class DateTimeType extends Type implements PhpDateTimeMappingType { @@ -33,11 +33,11 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { - if (null === $value) { + if ($value === null) { return $value; } - if ($value instanceof \DateTimeInterface) { + if ($value instanceof DateTimeInterface) { return $value->format($platform->getDateTimeFormatString()); } @@ -49,17 +49,17 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) */ public function convertToPHPValue($value, AbstractPlatform $platform) { - if ($value === null || $value instanceof \DateTimeInterface) { + if ($value === null || $value instanceof DateTimeInterface) { return $value; } - $val = \DateTime::createFromFormat($platform->getDateTimeFormatString(), $value); + $val = DateTime::createFromFormat($platform->getDateTimeFormatString(), $value); - if ( ! $val) { + if (! $val) { $val = date_create($value); } - if ( ! $val) { + if (! $val) { throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeFormatString()); } diff --git a/lib/Doctrine/DBAL/Types/DateTimeTzImmutableType.php b/lib/Doctrine/DBAL/Types/DateTimeTzImmutableType.php index 78111f09b33..253c02e002b 100644 --- a/lib/Doctrine/DBAL/Types/DateTimeTzImmutableType.php +++ b/lib/Doctrine/DBAL/Types/DateTimeTzImmutableType.php @@ -2,13 +2,11 @@ namespace Doctrine\DBAL\Types; +use DateTimeImmutable; use Doctrine\DBAL\Platforms\AbstractPlatform; /** * Immutable type of {@see DateTimeTzType}. - * - * @since 2.6 - * @author Steve Müller */ class DateTimeTzImmutableType extends DateTimeTzType { @@ -25,18 +23,18 @@ public function getName() */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { - if (null === $value) { + if ($value === null) { return $value; } - if ($value instanceof \DateTimeImmutable) { + if ($value instanceof DateTimeImmutable) { return $value->format($platform->getDateTimeTzFormatString()); } throw ConversionException::conversionFailedInvalidType( $value, $this->getName(), - ['null', \DateTimeImmutable::class] + ['null', DateTimeImmutable::class] ); } @@ -45,11 +43,11 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) */ public function convertToPHPValue($value, AbstractPlatform $platform) { - if ($value === null || $value instanceof \DateTimeImmutable) { + if ($value === null || $value instanceof DateTimeImmutable) { return $value; } - $dateTime = \DateTimeImmutable::createFromFormat($platform->getDateTimeTzFormatString(), $value); + $dateTime = DateTimeImmutable::createFromFormat($platform->getDateTimeTzFormatString(), $value); if (! $dateTime) { throw ConversionException::conversionFailedFormat( diff --git a/lib/Doctrine/DBAL/Types/DateTimeTzType.php b/lib/Doctrine/DBAL/Types/DateTimeTzType.php index 8242819eebc..e1b9afa1565 100644 --- a/lib/Doctrine/DBAL/Types/DateTimeTzType.php +++ b/lib/Doctrine/DBAL/Types/DateTimeTzType.php @@ -2,6 +2,8 @@ namespace Doctrine\DBAL\Types; +use DateTime; +use DateTimeInterface; use Doctrine\DBAL\Platforms\AbstractPlatform; /** @@ -21,11 +23,6 @@ * attached. * * @link www.doctrine-project.org - * @since 1.0 - * @author Benjamin Eberlei - * @author Guilherme Blanco - * @author Jonathan Wage - * @author Roman Borschel */ class DateTimeTzType extends Type implements PhpDateTimeMappingType { @@ -50,11 +47,11 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { - if (null === $value) { + if ($value === null) { return $value; } - if ($value instanceof \DateTimeInterface) { + if ($value instanceof DateTimeInterface) { return $value->format($platform->getDateTimeTzFormatString()); } @@ -66,12 +63,12 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) */ public function convertToPHPValue($value, AbstractPlatform $platform) { - if ($value === null || $value instanceof \DateTimeInterface) { + if ($value === null || $value instanceof DateTimeInterface) { return $value; } - $val = \DateTime::createFromFormat($platform->getDateTimeTzFormatString(), $value); - if ( ! $val) { + $val = DateTime::createFromFormat($platform->getDateTimeTzFormatString(), $value); + if (! $val) { throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeTzFormatString()); } diff --git a/lib/Doctrine/DBAL/Types/DateType.php b/lib/Doctrine/DBAL/Types/DateType.php index 8794706c4ce..b5ad5356f69 100644 --- a/lib/Doctrine/DBAL/Types/DateType.php +++ b/lib/Doctrine/DBAL/Types/DateType.php @@ -2,12 +2,12 @@ namespace Doctrine\DBAL\Types; +use DateTime; +use DateTimeInterface; use Doctrine\DBAL\Platforms\AbstractPlatform; /** * Type that maps an SQL DATE to a PHP Date object. - * - * @since 2.0 */ class DateType extends Type { @@ -32,11 +32,11 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { - if (null === $value) { + if ($value === null) { return $value; } - if ($value instanceof \DateTimeInterface) { + if ($value instanceof DateTimeInterface) { return $value->format($platform->getDateFormatString()); } @@ -48,12 +48,12 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) */ public function convertToPHPValue($value, AbstractPlatform $platform) { - if ($value === null || $value instanceof \DateTimeInterface) { + if ($value === null || $value instanceof DateTimeInterface) { return $value; } - $val = \DateTime::createFromFormat('!'.$platform->getDateFormatString(), $value); - if ( ! $val) { + $val = DateTime::createFromFormat('!' . $platform->getDateFormatString(), $value); + if (! $val) { throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateFormatString()); } diff --git a/lib/Doctrine/DBAL/Types/DecimalType.php b/lib/Doctrine/DBAL/Types/DecimalType.php index 45a8e233f02..318cb2476b7 100644 --- a/lib/Doctrine/DBAL/Types/DecimalType.php +++ b/lib/Doctrine/DBAL/Types/DecimalType.php @@ -6,8 +6,6 @@ /** * Type that maps an SQL DECIMAL to a PHP string. - * - * @since 2.0 */ class DecimalType extends Type { diff --git a/lib/Doctrine/DBAL/Types/FloatType.php b/lib/Doctrine/DBAL/Types/FloatType.php index ea1dc3b9ad3..3ad9aa737fa 100644 --- a/lib/Doctrine/DBAL/Types/FloatType.php +++ b/lib/Doctrine/DBAL/Types/FloatType.php @@ -27,6 +27,6 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla */ public function convertToPHPValue($value, AbstractPlatform $platform) { - return (null === $value) ? null : (double) $value; + return $value === null ? null : (float) $value; } } diff --git a/lib/Doctrine/DBAL/Types/GuidType.php b/lib/Doctrine/DBAL/Types/GuidType.php index c522aa8ca50..a9ab21537c5 100644 --- a/lib/Doctrine/DBAL/Types/GuidType.php +++ b/lib/Doctrine/DBAL/Types/GuidType.php @@ -6,9 +6,6 @@ /** * Represents a GUID/UUID datatype (both are actually synonyms) in the database. - * - * @author Benjamin Eberlei - * @since 2.3 */ class GuidType extends StringType { @@ -33,6 +30,6 @@ public function getName() */ public function requiresSQLCommentHint(AbstractPlatform $platform) { - return !$platform->hasNativeGuidType(); + return ! $platform->hasNativeGuidType(); } } diff --git a/lib/Doctrine/DBAL/Types/IntegerType.php b/lib/Doctrine/DBAL/Types/IntegerType.php index 60b183a009a..f04f3c7e008 100644 --- a/lib/Doctrine/DBAL/Types/IntegerType.php +++ b/lib/Doctrine/DBAL/Types/IntegerType.php @@ -7,9 +7,6 @@ /** * Type that maps an SQL INT to a PHP integer. - * - * @author Roman Borschel - * @since 2.0 */ class IntegerType extends Type implements PhpIntegerMappingType { @@ -34,7 +31,7 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla */ public function convertToPHPValue($value, AbstractPlatform $platform) { - return (null === $value) ? null : (int) $value; + return $value === null ? null : (int) $value; } /** diff --git a/lib/Doctrine/DBAL/Types/JsonArrayType.php b/lib/Doctrine/DBAL/Types/JsonArrayType.php index 0e62688251b..beae8038737 100644 --- a/lib/Doctrine/DBAL/Types/JsonArrayType.php +++ b/lib/Doctrine/DBAL/Types/JsonArrayType.php @@ -10,9 +10,7 @@ /** * Array Type which can be used to generate json arrays. * - * @since 2.3 * @deprecated Use JsonType instead - * @author Johannes M. Schmitt */ class JsonArrayType extends JsonType { @@ -25,7 +23,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) return []; } - $value = (is_resource($value)) ? stream_get_contents($value) : $value; + $value = is_resource($value) ? stream_get_contents($value) : $value; return json_decode($value, true); } diff --git a/lib/Doctrine/DBAL/Types/JsonType.php b/lib/Doctrine/DBAL/Types/JsonType.php index e7f0ed0869d..00cd3f80fcf 100644 --- a/lib/Doctrine/DBAL/Types/JsonType.php +++ b/lib/Doctrine/DBAL/Types/JsonType.php @@ -13,9 +13,6 @@ /** * Type generating json objects values - * - * @since 2.6 - * @author Baptiste Clavié */ class JsonType extends Type { @@ -32,13 +29,13 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { - if (null === $value) { + if ($value === null) { return null; } $encoded = json_encode($value); - if (JSON_ERROR_NONE !== json_last_error()) { + if (json_last_error() !== JSON_ERROR_NONE) { throw ConversionException::conversionFailedSerialization($value, 'json', json_last_error_msg()); } diff --git a/lib/Doctrine/DBAL/Types/ObjectType.php b/lib/Doctrine/DBAL/Types/ObjectType.php index ed53fb03a73..081ec483b16 100644 --- a/lib/Doctrine/DBAL/Types/ObjectType.php +++ b/lib/Doctrine/DBAL/Types/ObjectType.php @@ -12,8 +12,6 @@ /** * Type that maps a PHP object to a clob SQL type. - * - * @since 2.0 */ class ObjectType extends Type { @@ -42,7 +40,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) return null; } - $value = (is_resource($value)) ? stream_get_contents($value) : $value; + $value = is_resource($value) ? stream_get_contents($value) : $value; set_error_handler(function (int $code, string $message) : void { throw ConversionException::conversionFailedUnserialization($this->getName(), $message); diff --git a/lib/Doctrine/DBAL/Types/PhpDateTimeMappingType.php b/lib/Doctrine/DBAL/Types/PhpDateTimeMappingType.php index 58de0177233..45658505330 100644 --- a/lib/Doctrine/DBAL/Types/PhpDateTimeMappingType.php +++ b/lib/Doctrine/DBAL/Types/PhpDateTimeMappingType.php @@ -4,6 +4,7 @@ /** * Implementations should map a database type to a PHP DateTimeInterface instance. + * * @internal */ interface PhpDateTimeMappingType diff --git a/lib/Doctrine/DBAL/Types/PhpIntegerMappingType.php b/lib/Doctrine/DBAL/Types/PhpIntegerMappingType.php index cd41f5ff6df..b48e29c865a 100644 --- a/lib/Doctrine/DBAL/Types/PhpIntegerMappingType.php +++ b/lib/Doctrine/DBAL/Types/PhpIntegerMappingType.php @@ -4,6 +4,7 @@ /** * Implementations should map a database type to a PHP integer. + * * @internal */ interface PhpIntegerMappingType diff --git a/lib/Doctrine/DBAL/Types/SimpleArrayType.php b/lib/Doctrine/DBAL/Types/SimpleArrayType.php index 8059ef3490f..d23776f5f0a 100644 --- a/lib/Doctrine/DBAL/Types/SimpleArrayType.php +++ b/lib/Doctrine/DBAL/Types/SimpleArrayType.php @@ -12,9 +12,6 @@ * Array Type which can be used for simple values. * * Only use this type if you are sure that your values cannot contain a ",". - * - * @since 2.3 - * @author Johannes M. Schmitt */ class SimpleArrayType extends Type { @@ -31,7 +28,7 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { - if (!$value) { + if (! $value) { return null; } @@ -47,7 +44,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) return []; } - $value = (is_resource($value)) ? stream_get_contents($value) : $value; + $value = is_resource($value) ? stream_get_contents($value) : $value; return explode(',', $value); } diff --git a/lib/Doctrine/DBAL/Types/SmallIntType.php b/lib/Doctrine/DBAL/Types/SmallIntType.php index 4fc2ab96211..bca8a533f06 100644 --- a/lib/Doctrine/DBAL/Types/SmallIntType.php +++ b/lib/Doctrine/DBAL/Types/SmallIntType.php @@ -7,8 +7,6 @@ /** * Type that maps a database SMALLINT to a PHP integer. - * - * @author robo */ class SmallIntType extends Type implements PhpIntegerMappingType { @@ -33,7 +31,7 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla */ public function convertToPHPValue($value, AbstractPlatform $platform) { - return (null === $value) ? null : (int) $value; + return $value === null ? null : (int) $value; } /** diff --git a/lib/Doctrine/DBAL/Types/StringType.php b/lib/Doctrine/DBAL/Types/StringType.php index e56569c4644..879359a13d8 100644 --- a/lib/Doctrine/DBAL/Types/StringType.php +++ b/lib/Doctrine/DBAL/Types/StringType.php @@ -6,8 +6,6 @@ /** * Type that maps an SQL VARCHAR to a PHP string. - * - * @since 2.0 */ class StringType extends Type { diff --git a/lib/Doctrine/DBAL/Types/TextType.php b/lib/Doctrine/DBAL/Types/TextType.php index 19bb875439d..635d4f7de49 100644 --- a/lib/Doctrine/DBAL/Types/TextType.php +++ b/lib/Doctrine/DBAL/Types/TextType.php @@ -8,8 +8,6 @@ /** * Type that maps an SQL CLOB to a PHP string. - * - * @since 2.0 */ class TextType extends Type { @@ -26,7 +24,7 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla */ public function convertToPHPValue($value, AbstractPlatform $platform) { - return (is_resource($value)) ? stream_get_contents($value) : $value; + return is_resource($value) ? stream_get_contents($value) : $value; } /** diff --git a/lib/Doctrine/DBAL/Types/TimeImmutableType.php b/lib/Doctrine/DBAL/Types/TimeImmutableType.php index 8e43e18f934..8cb870fb393 100644 --- a/lib/Doctrine/DBAL/Types/TimeImmutableType.php +++ b/lib/Doctrine/DBAL/Types/TimeImmutableType.php @@ -2,13 +2,11 @@ namespace Doctrine\DBAL\Types; +use DateTimeImmutable; use Doctrine\DBAL\Platforms\AbstractPlatform; /** * Immutable type of {@see TimeType}. - * - * @since 2.6 - * @author Steve Müller */ class TimeImmutableType extends TimeType { @@ -25,18 +23,18 @@ public function getName() */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { - if (null === $value) { + if ($value === null) { return $value; } - if ($value instanceof \DateTimeImmutable) { + if ($value instanceof DateTimeImmutable) { return $value->format($platform->getTimeFormatString()); } throw ConversionException::conversionFailedInvalidType( $value, $this->getName(), - ['null', \DateTimeImmutable::class] + ['null', DateTimeImmutable::class] ); } @@ -45,11 +43,11 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) */ public function convertToPHPValue($value, AbstractPlatform $platform) { - if ($value === null || $value instanceof \DateTimeImmutable) { + if ($value === null || $value instanceof DateTimeImmutable) { return $value; } - $dateTime = \DateTimeImmutable::createFromFormat('!' . $platform->getTimeFormatString(), $value); + $dateTime = DateTimeImmutable::createFromFormat('!' . $platform->getTimeFormatString(), $value); if (! $dateTime) { throw ConversionException::conversionFailedFormat( diff --git a/lib/Doctrine/DBAL/Types/TimeType.php b/lib/Doctrine/DBAL/Types/TimeType.php index b9a5b66cd8a..c9895294e03 100644 --- a/lib/Doctrine/DBAL/Types/TimeType.php +++ b/lib/Doctrine/DBAL/Types/TimeType.php @@ -2,12 +2,12 @@ namespace Doctrine\DBAL\Types; +use DateTime; +use DateTimeInterface; use Doctrine\DBAL\Platforms\AbstractPlatform; /** * Type that maps an SQL TIME to a PHP DateTime object. - * - * @since 2.0 */ class TimeType extends Type { @@ -32,11 +32,11 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { - if (null === $value) { + if ($value === null) { return $value; } - if ($value instanceof \DateTimeInterface) { + if ($value instanceof DateTimeInterface) { return $value->format($platform->getTimeFormatString()); } @@ -48,12 +48,12 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) */ public function convertToPHPValue($value, AbstractPlatform $platform) { - if ($value === null || $value instanceof \DateTimeInterface) { + if ($value === null || $value instanceof DateTimeInterface) { return $value; } - $val = \DateTime::createFromFormat('!' . $platform->getTimeFormatString(), $value); - if ( ! $val) { + $val = DateTime::createFromFormat('!' . $platform->getTimeFormatString(), $value); + if (! $val) { throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getTimeFormatString()); } diff --git a/lib/Doctrine/DBAL/Types/Type.php b/lib/Doctrine/DBAL/Types/Type.php index e75c93242a6..983c1cda191 100644 --- a/lib/Doctrine/DBAL/Types/Type.php +++ b/lib/Doctrine/DBAL/Types/Type.php @@ -2,50 +2,45 @@ namespace Doctrine\DBAL\Types; +use Doctrine\DBAL\DBALException; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; -use Doctrine\DBAL\DBALException; use function end; use function explode; -use function get_class; use function str_replace; /** * The base class for so-called Doctrine mapping types. * * A Type object is obtained by calling the static {@link getType()} method. - * - * @author Roman Borschel - * @author Benjamin Eberlei - * @since 2.0 */ abstract class Type { - const TARRAY = 'array'; - const SIMPLE_ARRAY = 'simple_array'; - const JSON_ARRAY = 'json_array'; - const JSON = 'json'; - const BIGINT = 'bigint'; - const BOOLEAN = 'boolean'; - const DATETIME = 'datetime'; - const DATETIME_IMMUTABLE = 'datetime_immutable'; - const DATETIMETZ = 'datetimetz'; - const DATETIMETZ_IMMUTABLE = 'datetimetz_immutable'; - const DATE = 'date'; - const DATE_IMMUTABLE = 'date_immutable'; - const TIME = 'time'; - const TIME_IMMUTABLE = 'time_immutable'; - const DECIMAL = 'decimal'; - const INTEGER = 'integer'; - const OBJECT = 'object'; - const SMALLINT = 'smallint'; - const STRING = 'string'; - const TEXT = 'text'; - const BINARY = 'binary'; - const BLOB = 'blob'; - const FLOAT = 'float'; - const GUID = 'guid'; - const DATEINTERVAL = 'dateinterval'; + 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 BOOLEAN = 'boolean'; + 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 INTEGER = 'integer'; + public const OBJECT = 'object'; + public const SMALLINT = 'smallint'; + public const STRING = 'string'; + 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). @@ -98,8 +93,8 @@ final private function __construct() * Converts a value from its PHP representation to its database representation * of this type. * - * @param mixed $value The value to convert. - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform The currently used database platform. + * @param mixed $value The value to convert. + * @param AbstractPlatform $platform The currently used database platform. * * @return mixed The database representation of the value. */ @@ -112,8 +107,8 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) * Converts a value from its database representation to its PHP representation * of this type. * - * @param mixed $value The value to convert. - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform The currently used database platform. + * @param mixed $value The value to convert. + * @param AbstractPlatform $platform The currently used database platform. * * @return mixed The PHP representation of the value. */ @@ -125,11 +120,9 @@ public function convertToPHPValue($value, AbstractPlatform $platform) /** * Gets the default length of this type. * - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform + * @deprecated Rely on information provided by the platform instead. * * @return int|null - * - * @deprecated Rely on information provided by the platform instead. */ public function getDefaultLength(AbstractPlatform $platform) { @@ -139,8 +132,8 @@ public function getDefaultLength(AbstractPlatform $platform) /** * Gets the SQL declaration snippet for a field of this type. * - * @param array $fieldDeclaration The field declaration. - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform The currently used database platform. + * @param array $fieldDeclaration The field declaration. + * @param AbstractPlatform $platform The currently used database platform. * * @return string */ @@ -163,12 +156,12 @@ abstract public function getName(); * * @return \Doctrine\DBAL\Types\Type * - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ public static function getType($name) { - if ( ! isset(self::$_typeObjects[$name])) { - if ( ! isset(self::$_typesMap[$name])) { + if (! isset(self::$_typeObjects[$name])) { + if (! isset(self::$_typesMap[$name])) { throw DBALException::unknownColumnType($name); } self::$_typeObjects[$name] = new self::$_typesMap[$name](); @@ -185,7 +178,7 @@ public static function getType($name) * * @return void * - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ public static function addType($name, $className) { @@ -216,11 +209,11 @@ public static function hasType($name) * * @return void * - * @throws \Doctrine\DBAL\DBALException + * @throws DBALException */ public static function overrideType($name, $className) { - if ( ! isset(self::$_typesMap[$name])) { + if (! isset(self::$_typesMap[$name])) { throw DBALException::typeNotFound($name); } @@ -256,13 +249,13 @@ public static function getTypesMap() } /** - * @return string - * * @deprecated Relying on string representation is discouraged and will be removed in DBAL 3.0. + * + * @return string */ public function __toString() { - $e = explode('\\', get_class($this)); + $e = explode('\\', static::class); return str_replace('Type', '', end($e)); } @@ -285,8 +278,7 @@ public function canRequireSQLConversion() /** * Modifies the SQL expression (identifier, parameter) to convert to a database value. * - * @param string $sqlExpr - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform + * @param string $sqlExpr * * @return string */ @@ -298,8 +290,8 @@ public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform) /** * Modifies the SQL expression (identifier, parameter) to convert to a PHP value. * - * @param string $sqlExpr - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform + * @param string $sqlExpr + * @param AbstractPlatform $platform * * @return string */ @@ -311,8 +303,6 @@ public function convertToPHPValueSQL($sqlExpr, $platform) /** * Gets an array of database types that map to this Doctrine type. * - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform - * * @return array */ public function getMappedDatabaseTypes(AbstractPlatform $platform) @@ -326,8 +316,6 @@ public function getMappedDatabaseTypes(AbstractPlatform $platform) * one of those types as commented, which will have Doctrine use an SQL * comment to typehint the actual Doctrine Type. * - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform - * * @return bool */ public function requiresSQLCommentHint(AbstractPlatform $platform) diff --git a/lib/Doctrine/DBAL/Types/VarDateTimeImmutableType.php b/lib/Doctrine/DBAL/Types/VarDateTimeImmutableType.php index a8bf8f2f090..6636f53a5b2 100644 --- a/lib/Doctrine/DBAL/Types/VarDateTimeImmutableType.php +++ b/lib/Doctrine/DBAL/Types/VarDateTimeImmutableType.php @@ -2,14 +2,12 @@ namespace Doctrine\DBAL\Types; +use DateTimeImmutable; use Doctrine\DBAL\Platforms\AbstractPlatform; use function date_create_immutable; /** * Immutable type of {@see VarDateTimeType}. - * - * @since 2.6 - * @author Steve Müller */ class VarDateTimeImmutableType extends VarDateTimeType { @@ -26,18 +24,18 @@ public function getName() */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { - if (null === $value) { + if ($value === null) { return $value; } - if ($value instanceof \DateTimeImmutable) { + if ($value instanceof DateTimeImmutable) { return $value->format($platform->getDateTimeFormatString()); } throw ConversionException::conversionFailedInvalidType( $value, $this->getName(), - ['null', \DateTimeImmutable::class] + ['null', DateTimeImmutable::class] ); } @@ -46,7 +44,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) */ public function convertToPHPValue($value, AbstractPlatform $platform) { - if ($value === null || $value instanceof \DateTimeImmutable) { + if ($value === null || $value instanceof DateTimeImmutable) { return $value; } diff --git a/lib/Doctrine/DBAL/Types/VarDateTimeType.php b/lib/Doctrine/DBAL/Types/VarDateTimeType.php index 2396230c3b5..770b6f1ecd4 100644 --- a/lib/Doctrine/DBAL/Types/VarDateTimeType.php +++ b/lib/Doctrine/DBAL/Types/VarDateTimeType.php @@ -2,6 +2,7 @@ namespace Doctrine\DBAL\Types; +use DateTime; use Doctrine\DBAL\Platforms\AbstractPlatform; use function date_create; @@ -13,11 +14,6 @@ * TIMESTAMP(n) columns where n > 0 it is necessary to use this type. * * @link www.doctrine-project.org - * @since 2.0 - * @author Benjamin Eberlei - * @author Guilherme Blanco - * @author Jonathan Wage - * @author Roman Borschel */ class VarDateTimeType extends DateTimeType { @@ -26,12 +22,12 @@ class VarDateTimeType extends DateTimeType */ public function convertToPHPValue($value, AbstractPlatform $platform) { - if ($value === null || $value instanceof \DateTime) { + if ($value === null || $value instanceof DateTime) { return $value; } $val = date_create($value); - if ( ! $val) { + if (! $val) { throw ConversionException::conversionFailed($value, $this->getName()); } diff --git a/lib/Doctrine/DBAL/Version.php b/lib/Doctrine/DBAL/Version.php index 481e27b4128..9173dc89c00 100644 --- a/lib/Doctrine/DBAL/Version.php +++ b/lib/Doctrine/DBAL/Version.php @@ -10,11 +10,6 @@ * Class to store and retrieve the version of Doctrine. * * @link www.doctrine-project.org - * @since 2.0 - * @author Benjamin Eberlei - * @author Guilherme Blanco - * @author Jonathan Wage - * @author Roman Borschel */ class Version { @@ -33,7 +28,7 @@ class Version public static function compare($version) { $currentVersion = str_replace(' ', '', strtolower(self::VERSION)); - $version = str_replace(' ', '', $version); + $version = str_replace(' ', '', $version); return version_compare($version, $currentVersion); } diff --git a/lib/Doctrine/DBAL/VersionAwarePlatformDriver.php b/lib/Doctrine/DBAL/VersionAwarePlatformDriver.php index 45eb8a91fa2..14ecbc720bb 100644 --- a/lib/Doctrine/DBAL/VersionAwarePlatformDriver.php +++ b/lib/Doctrine/DBAL/VersionAwarePlatformDriver.php @@ -2,6 +2,8 @@ namespace Doctrine\DBAL; +use Doctrine\DBAL\Platforms\AbstractPlatform; + /** * Contract for a driver that is able to create platform instances by version. * @@ -10,9 +12,7 @@ * This interface should be implemented by drivers that are capable to do this * distinction. * - * @author Steve Müller * @link www.doctrine-project.org - * @since 2.5 */ interface VersionAwarePlatformDriver { @@ -22,7 +22,7 @@ interface VersionAwarePlatformDriver * @param string $version The platform/server version string to evaluate. This should be given in the notation * the underlying database vendor uses. * - * @return \Doctrine\DBAL\Platforms\AbstractPlatform + * @return AbstractPlatform * * @throws DBALException if the given version string could not be evaluated. */ diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 2367364b58f..75e6a9c1c04 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -9,6 +9,7 @@ + bin lib tests From 9da1ea3e3524763d6e2a7e5116171e9e19e475a9 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Mon, 1 Oct 2018 22:10:39 -0700 Subject: [PATCH 32/76] Fixed failures introduced by strict comparison --- .../DBAL/Schema/PostgreSqlSchemaManager.php | 2 +- .../DBAL/Schema/SQLServerSchemaManager.php | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php index 201224633dc..8ab1cf908b0 100644 --- a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php @@ -212,7 +212,7 @@ protected function _getPortableTableIndexesList($tableIndexes, $tableName = null { $buffer = []; foreach ($tableIndexes as $row) { - $colNumbers = explode(' ', $row['indkey']); + $colNumbers = array_map('intval', explode(' ', $row['indkey'])); $colNumbersSql = 'IN (' . join(' ,', $colNumbers) . ' )'; $columnNameSql = "SELECT attnum, attname FROM pg_attribute WHERE attrelid={$row['indrelid']} AND attnum $colNumbersSql ORDER BY attnum ASC;"; diff --git a/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php b/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php index 59798aaad5e..e6ec0d0f535 100644 --- a/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php @@ -70,14 +70,16 @@ protected function _getPortableTableColumnDefinition($tableColumn) $tableColumn['name'] = ''; } - while ($default !== ($default2 = preg_replace('/^\((.*)\)$/', '$1', $default))) { - $default = trim($default2, "'"); + if ($default !== null) { + while ($default !== ($default2 = preg_replace('/^\((.*)\)$/', '$1', $default))) { + $default = trim($default2, "'"); - if ($default !== 'getdate()') { - continue; - } + if ($default !== 'getdate()') { + continue; + } - $default = $this->_platform->getCurrentTimestampSQL(); + $default = $this->_platform->getCurrentTimestampSQL(); + } } switch ($dbType) { From 64939c35f219e584dd9e4348265f2a5c3cf3de43 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sat, 29 Sep 2018 13:42:22 -0700 Subject: [PATCH 33/76] Manual coding style fixes --- lib/Doctrine/DBAL/Cache/ArrayStatement.php | 4 +- lib/Doctrine/DBAL/Cache/QueryCacheProfile.php | 10 +- .../DBAL/Cache/ResultCacheStatement.php | 6 +- lib/Doctrine/DBAL/Configuration.php | 2 +- lib/Doctrine/DBAL/Connection.php | 114 +++---- .../Connections/MasterSlaveConnection.php | 6 +- lib/Doctrine/DBAL/DBALException.php | 10 +- lib/Doctrine/DBAL/Driver.php | 4 +- .../DBAL/Driver/AbstractOracleDriver.php | 2 +- .../DBAL/Driver/AbstractSQLServerDriver.php | 1 - lib/Doctrine/DBAL/Driver/Connection.php | 2 +- .../DBAL/Driver/IBMDB2/DB2Connection.php | 8 +- .../DBAL/Driver/IBMDB2/DB2Statement.php | 6 +- .../DBAL/Driver/Mysqli/MysqliConnection.php | 12 +- .../DBAL/Driver/Mysqli/MysqliStatement.php | 19 +- lib/Doctrine/DBAL/Driver/OCI8/Driver.php | 2 +- .../DBAL/Driver/OCI8/OCI8Connection.php | 4 +- .../DBAL/Driver/OCI8/OCI8Exception.php | 2 +- .../DBAL/Driver/OCI8/OCI8Statement.php | 8 +- lib/Doctrine/DBAL/Driver/PDOConnection.php | 10 +- lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php | 2 +- lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php | 2 +- lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php | 2 +- lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php | 4 +- lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php | 4 +- lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php | 6 +- lib/Doctrine/DBAL/Driver/ResultStatement.php | 35 +- .../DBAL/Driver/SQLAnywhere/Driver.php | 20 +- .../SQLAnywhere/SQLAnywhereStatement.php | 2 +- .../DBAL/Driver/SQLSrv/SQLSrvConnection.php | 4 +- .../DBAL/Driver/SQLSrv/SQLSrvStatement.php | 12 +- lib/Doctrine/DBAL/Driver/Statement.php | 8 +- lib/Doctrine/DBAL/DriverManager.php | 48 +-- .../Event/Listeners/OracleSessionInit.php | 4 +- .../SchemaAlterTableAddColumnEventArgs.php | 6 +- .../SchemaAlterTableChangeColumnEventArgs.php | 6 +- .../DBAL/Event/SchemaAlterTableEventArgs.php | 6 +- .../SchemaAlterTableRemoveColumnEventArgs.php | 6 +- .../SchemaAlterTableRenameColumnEventArgs.php | 6 +- .../Event/SchemaColumnDefinitionEventArgs.php | 10 +- .../SchemaCreateTableColumnEventArgs.php | 6 +- .../DBAL/Event/SchemaCreateTableEventArgs.php | 19 +- .../Event/SchemaIndexDefinitionEventArgs.php | 8 +- lib/Doctrine/DBAL/Id/TableGenerator.php | 2 +- lib/Doctrine/DBAL/Logging/DebugStack.php | 2 +- lib/Doctrine/DBAL/Logging/SQLLogger.php | 6 +- .../DBAL/Platforms/AbstractPlatform.php | 119 ++++--- lib/Doctrine/DBAL/Platforms/DB2Platform.php | 6 +- .../DBAL/Platforms/DrizzlePlatform.php | 7 +- .../DBAL/Platforms/Keywords/KeywordList.php | 4 +- .../Keywords/ReservedKeywordsValidator.php | 10 +- lib/Doctrine/DBAL/Platforms/MySqlPlatform.php | 31 +- .../DBAL/Platforms/OraclePlatform.php | 46 ++- .../DBAL/Platforms/PostgreSQL92Platform.php | 8 +- .../DBAL/Platforms/PostgreSqlPlatform.php | 60 ++-- .../DBAL/Platforms/SQLAnywherePlatform.php | 301 ++++++++++-------- .../DBAL/Platforms/SQLServerPlatform.php | 28 +- .../DBAL/Platforms/SqlitePlatform.php | 21 +- lib/Doctrine/DBAL/Portability/Statement.php | 2 +- .../Query/Expression/CompositeExpression.php | 8 +- .../Query/Expression/ExpressionBuilder.php | 8 +- lib/Doctrine/DBAL/Query/QueryBuilder.php | 34 +- lib/Doctrine/DBAL/Query/QueryException.php | 8 +- lib/Doctrine/DBAL/SQLParserUtils.php | 18 +- lib/Doctrine/DBAL/Schema/AbstractAsset.php | 6 +- .../DBAL/Schema/AbstractSchemaManager.php | 124 ++++---- lib/Doctrine/DBAL/Schema/Column.php | 20 +- lib/Doctrine/DBAL/Schema/ColumnDiff.php | 2 +- lib/Doctrine/DBAL/Schema/Comparator.php | 2 +- lib/Doctrine/DBAL/Schema/Constraint.php | 4 +- .../DBAL/Schema/ForeignKeyConstraint.php | 28 +- lib/Doctrine/DBAL/Schema/Index.php | 10 +- .../DBAL/Schema/PostgreSqlSchemaManager.php | 19 +- .../DBAL/Schema/SQLServerSchemaManager.php | 8 +- lib/Doctrine/DBAL/Schema/Schema.php | 16 +- lib/Doctrine/DBAL/Schema/SchemaConfig.php | 6 +- lib/Doctrine/DBAL/Schema/SchemaDiff.php | 6 +- lib/Doctrine/DBAL/Schema/SchemaException.php | 29 +- .../DBAL/Schema/SqliteSchemaManager.php | 22 +- .../AbstractSchemaSynchronizer.php | 4 +- .../Synchronizer/SchemaSynchronizer.php | 24 +- lib/Doctrine/DBAL/Schema/Table.php | 66 ++-- .../Visitor/CreateSchemaSqlCollector.php | 10 +- .../Schema/Visitor/DropSchemaSqlCollector.php | 2 +- lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php | 10 +- .../DBAL/Schema/Visitor/SchemaDiffVisitor.php | 16 +- .../DBAL/Sharding/PoolingShardConnection.php | 2 +- .../DBAL/Sharding/PoolingShardManager.php | 6 +- .../SQLAzureFederationsSynchronizer.php | 4 +- .../SQLAzure/Schema/MultiTenantVisitor.php | 4 +- .../DBAL/Sharding/ShardChoser/ShardChoser.php | 2 +- lib/Doctrine/DBAL/Sharding/ShardManager.php | 20 +- lib/Doctrine/DBAL/Statement.php | 16 +- .../Tools/Console/Command/ImportCommand.php | 8 +- .../Console/Command/ReservedWordsCommand.php | 2 +- .../Tools/Console/Command/RunSqlCommand.php | 4 +- lib/Doctrine/DBAL/Types/Type.php | 10 +- .../DBAL/VersionAwarePlatformDriver.php | 2 +- phpcs.xml.dist | 17 + .../DBAL/Platforms/OraclePlatformTest.php | 69 ++-- 100 files changed, 968 insertions(+), 819 deletions(-) diff --git a/lib/Doctrine/DBAL/Cache/ArrayStatement.php b/lib/Doctrine/DBAL/Cache/ArrayStatement.php index e06998723a8..449a220a2af 100644 --- a/lib/Doctrine/DBAL/Cache/ArrayStatement.php +++ b/lib/Doctrine/DBAL/Cache/ArrayStatement.php @@ -15,7 +15,7 @@ class ArrayStatement implements IteratorAggregate, ResultStatement { - /** @var array */ + /** @var mixed[] */ private $data; /** @var int */ @@ -28,7 +28,7 @@ class ArrayStatement implements IteratorAggregate, ResultStatement private $defaultFetchMode = FetchMode::MIXED; /** - * @param array $data + * @param mixed[] $data */ public function __construct(array $data) { diff --git a/lib/Doctrine/DBAL/Cache/QueryCacheProfile.php b/lib/Doctrine/DBAL/Cache/QueryCacheProfile.php index 8b42c7ce658..9433f982fc5 100644 --- a/lib/Doctrine/DBAL/Cache/QueryCacheProfile.php +++ b/lib/Doctrine/DBAL/Cache/QueryCacheProfile.php @@ -67,12 +67,12 @@ public function getCacheKey() /** * Generates the real cache key from query, params, types and connection parameters. * - * @param string $query - * @param array $params - * @param array $types - * @param array $connectionParams + * @param string $query + * @param mixed[] $params + * @param int[]|string[] $types + * @param mixed[] $connectionParams * - * @return array + * @return string[] */ public function generateCacheKeys($query, $params, $types, array $connectionParams = []) { diff --git a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php index 606df4e7e4e..1636391e697 100644 --- a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php +++ b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php @@ -51,7 +51,7 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement */ private $emptied = false; - /** @var array */ + /** @var mixed[] */ private $data; /** @var int */ @@ -78,7 +78,7 @@ public function closeCursor() { $this->statement->closeCursor(); if (! $this->emptied || $this->data === null) { - return; + return true; } $data = $this->resultCache->fetch($this->cacheKey); @@ -89,6 +89,8 @@ public function closeCursor() $this->resultCache->save($this->cacheKey, $data, $this->lifetime); unset($this->data); + + return true; } /** diff --git a/lib/Doctrine/DBAL/Configuration.php b/lib/Doctrine/DBAL/Configuration.php index 21660affb8e..c05a2c4bcfa 100644 --- a/lib/Doctrine/DBAL/Configuration.php +++ b/lib/Doctrine/DBAL/Configuration.php @@ -17,7 +17,7 @@ class Configuration * The attributes that are contained in the configuration. * Values are default values. * - * @var array + * @var mixed[] */ protected $_attributes = []; diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index b0c30aceabc..c23947aae8c 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -136,7 +136,7 @@ class Connection implements DriverConnection /** * The parameters used during creation of the Connection instance. * - * @var array + * @var mixed[] */ private $_params = []; @@ -175,7 +175,7 @@ class Connection implements DriverConnection /** * Initializes a new instance of the Connection class. * - * @param array $params The connection parameters. + * @param mixed[] $params The connection parameters. * @param Driver $driver The driver to use. * @param Configuration|null $config The configuration, optional. * @param EventManager|null $eventManager The event manager, optional. @@ -226,7 +226,7 @@ public function __construct( /** * Gets the parameters used during instantiation. * - * @return array + * @return mixed[] */ public function getParams() { @@ -375,7 +375,7 @@ public function connect() * * Evaluates custom platform class and version in order to set the correct platform. * - * @throws DBALException if an invalid platform was specified for this connection. + * @throws DBALException If an invalid platform was specified for this connection. */ private function detectDatabasePlatform() { @@ -534,11 +534,11 @@ public function setFetchMode($fetchMode) * Prepares and executes an SQL query and returns the first row of the result * as an associative array. * - * @param string $statement The SQL query. - * @param array $params The query parameters. - * @param array $types The query parameter types. + * @param string $statement The SQL query. + * @param mixed[] $params The query parameters. + * @param int[]|string[] $types The query parameter types. * - * @return array|bool False is returned if no rows are found. + * @return mixed[]|false False is returned if no rows are found. * * @throws DBALException */ @@ -551,11 +551,11 @@ public function fetchAssoc($statement, array $params = [], array $types = []) * Prepares and executes an SQL query and returns the first row of the result * as a numerically indexed array. * - * @param string $statement The SQL query to be executed. - * @param array $params The prepared statement params. - * @param array $types The query parameter types. + * @param string $statement The SQL query to be executed. + * @param mixed[] $params The prepared statement params. + * @param int[]|string[] $types The query parameter types. * - * @return array|bool False is returned if no rows are found. + * @return mixed[]|false False is returned if no rows are found. */ public function fetchArray($statement, array $params = [], array $types = []) { @@ -566,12 +566,12 @@ public function fetchArray($statement, array $params = [], array $types = []) * Prepares and executes an SQL query and returns the value of a single column * of the first row of the result. * - * @param string $statement The SQL query to be executed. - * @param array $params The prepared statement params. - * @param int $column The 0-indexed column number to retrieve. - * @param array $types The query parameter types. + * @param string $statement The SQL query to be executed. + * @param mixed[] $params The prepared statement params. + * @param int $column The 0-indexed column number to retrieve. + * @param int[]|string[] $types The query parameter types. * - * @return mixed|bool False is returned if no rows are found. + * @return mixed|false False is returned if no rows are found. * * @throws DBALException */ @@ -603,7 +603,7 @@ public function isTransactionActive() /** * Gathers conditions for an update or delete call. * - * @param array $identifiers Input array of columns to values + * @param mixed[] $identifiers Input array of columns to values * * @return string[][] a triplet with: * - the first key being the columns @@ -635,9 +635,9 @@ private function gatherConditions(array $identifiers) * * Table expression and columns are not escaped and are not safe for user-input. * - * @param string $tableExpression The expression of the table on which to delete. - * @param array $identifier The deletion criteria. An associative array containing column-value pairs. - * @param array $types The types of identifiers. + * @param string $tableExpression The expression of the table on which to delete. + * @param mixed[] $identifier The deletion criteria. An associative array containing column-value pairs. + * @param int[]|string[] $types The types of identifiers. * * @return int The number of affected rows. * @@ -704,10 +704,10 @@ public function getTransactionIsolation() * * Table expression and columns are not escaped and are not safe for user-input. * - * @param string $tableExpression The expression of the table to update quoted or unquoted. - * @param array $data An associative array containing column-value pairs. - * @param array $identifier The update criteria. An associative array containing column-value pairs. - * @param array $types Types of the merged $data and $identifier arrays in that order. + * @param string $tableExpression The expression of the table to update quoted or unquoted. + * @param mixed[] $data An associative array containing column-value pairs. + * @param mixed[] $identifier The update criteria. An associative array containing column-value pairs. + * @param int[]|string[] $types Types of the merged $data and $identifier arrays in that order. * * @return int The number of affected rows. * @@ -744,9 +744,9 @@ public function update($tableExpression, array $data, array $identifier, array $ * * Table expression and columns are not escaped and are not safe for user-input. * - * @param string $tableExpression The expression of the table to insert data into, quoted or unquoted. - * @param array $data An associative array containing column-value pairs. - * @param array $types Types of the inserted data. + * @param string $tableExpression The expression of the table to insert data into, quoted or unquoted. + * @param mixed[] $data An associative array containing column-value pairs. + * @param int[]|string[] $types Types of the inserted data. * * @return int The number of affected rows. * @@ -755,7 +755,7 @@ public function update($tableExpression, array $data, array $identifier, array $ public function insert($tableExpression, array $data, array $types = []) { if (empty($data)) { - return $this->executeUpdate('INSERT INTO ' . $tableExpression . ' ()' . ' VALUES ()'); + return $this->executeUpdate('INSERT INTO ' . $tableExpression . ' () VALUES ()'); } $columns = []; @@ -779,10 +779,10 @@ public function insert($tableExpression, array $data, array $types = []) /** * Extract ordered type list from an ordered column list and type map. * - * @param array $columnList - * @param array $types + * @param string[] $columnList + * @param int[]|string[] $types * - * @return array + * @return int[]|string[] */ private function extractTypeValues(array $columnList, array $types) { @@ -834,11 +834,11 @@ public function quote($input, $type = null) /** * Prepares and executes an SQL query and returns the result as an associative array. * - * @param string $sql The SQL query. - * @param array $params The query parameters. - * @param array $types The query parameter types. + * @param string $sql The SQL query. + * @param mixed[] $params The query parameters. + * @param int[]|string[] $types The query parameter types. * - * @return array + * @return mixed[] */ public function fetchAll($sql, array $params = [], $types = []) { @@ -874,8 +874,8 @@ public function prepare($statement) * If an SQLLogger is configured, the execution is logged. * * @param string $query The SQL query to execute. - * @param array $params The parameters to bind to the query, if any. - * @param array $types The types the previous parameters are in. + * @param mixed[] $params The parameters to bind to the query, if any. + * @param int[]|string[] $types The types the previous parameters are in. * @param QueryCacheProfile|null $qcp The query cache profile, optional. * * @return ResultStatement The executed statement. @@ -926,8 +926,8 @@ public function executeQuery($query, array $params = [], $types = [], ?QueryCach * Executes a caching query. * * @param string $query The SQL query to execute. - * @param array $params The parameters to bind to the query, if any. - * @param array $types The types the previous parameters are in. + * @param mixed[] $params The parameters to bind to the query, if any. + * @param int[]|string[] $types The types the previous parameters are in. * @param QueryCacheProfile $qcp The query cache profile. * * @return ResultStatement @@ -944,7 +944,9 @@ public function executeCacheQuery($query, $params, $types, QueryCacheProfile $qc [$cacheKey, $realKey] = $qcp->generateCacheKeys($query, $params, $types, $this->getParams()); // fetch the row pointers entry - if ($data = $resultCache->fetch($cacheKey)) { + $data = $resultCache->fetch($cacheKey); + + if ($data !== false) { // is the real key part of this row pointers map or is the cache only pointing to other cache keys? if (isset($data[$realKey])) { $stmt = new ArrayStatement($data[$realKey]); @@ -967,12 +969,12 @@ public function executeCacheQuery($query, $params, $types, QueryCacheProfile $qc * applying a given projection/transformation function on each row of the result. * * @param string $query The SQL query to execute. - * @param array $params The parameters, if any. + * @param mixed[] $params The parameters, if any. * @param Closure $function The transformation function that is applied on each row. * The function receives a single parameter, an array, that * represents a row of the result set. * - * @return array The projected result of the query. + * @return mixed[] The projected result of the query. */ public function project($query, array $params, Closure $function) { @@ -1027,9 +1029,9 @@ public function query() * * This method supports PDO binding types as well as DBAL mapping types. * - * @param string $query The SQL query. - * @param array $params The query parameters. - * @param array $types The parameter types. + * @param string $query The SQL query. + * @param mixed[] $params The query parameters. + * @param int[]|string[] $types The parameter types. * * @return int The number of affected rows. * @@ -1124,9 +1126,7 @@ public function errorCode() } /** - * Fetches extended error information associated with the last database operation. - * - * @return array The last error information. + * {@inheritDoc} */ public function errorInfo() { @@ -1523,8 +1523,8 @@ public function convertToPHPValue($value, $type) * raw PDOStatement instances. * * @param \Doctrine\DBAL\Driver\Statement $stmt The statement to bind the values to. - * @param array $params The map/list of named/positional parameters. - * @param array $types The parameter types (PDO binding types or DBAL mapping types). + * @param mixed[] $params The map/list of named/positional parameters. + * @param int[]|string[] $types The parameter types (PDO binding types or DBAL mapping types). * * @return void */ @@ -1563,10 +1563,10 @@ 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 mixed $type The type to bind (PDO or DBAL). + * @param mixed $value The value to bind. + * @param int|string $type The type to bind (PDO or DBAL). * - * @return array [0] => the (escaped) value, [1] => the binding type. + * @return mixed[] [0] => the (escaped) value, [1] => the binding type. */ private function getBindingInfo($value, $type) { @@ -1589,10 +1589,10 @@ private function getBindingInfo($value, $type) * @internal This is a purely internal method. If you rely on this method, you are advised to * copy/paste the code as this method may change, or be removed without prior notice. * - * @param array $params - * @param array $types + * @param mixed[] $params + * @param int[]|string[] $types * - * @return array + * @return mixed[] */ public function resolveParams(array $params, array $types) { diff --git a/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php b/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php index d01e1344d0c..e9864d6df90 100644 --- a/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php +++ b/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php @@ -85,7 +85,7 @@ class MasterSlaveConnection extends Connection /** * Creates Master Slave Connection. * - * @param array $params + * @param mixed[] $params * * @throws InvalidArgumentException */ @@ -195,8 +195,8 @@ protected function connectTo($connectionName) } /** - * @param string $connectionName - * @param array $params + * @param string $connectionName + * @param mixed[] $params * * @return mixed */ diff --git a/lib/Doctrine/DBAL/DBALException.php b/lib/Doctrine/DBAL/DBALException.php index 8acf6aa1e3f..637e5d341ea 100644 --- a/lib/Doctrine/DBAL/DBALException.php +++ b/lib/Doctrine/DBAL/DBALException.php @@ -29,7 +29,7 @@ class DBALException extends Exception */ public static function notSupported($method) { - return new self("Operation '$method' is not supported by platform."); + return new self(sprintf("Operation '%s' is not supported by platform.", $method)); } public static function invalidPlatformSpecified() : self @@ -117,8 +117,8 @@ public static function driverRequired($url = null) } /** - * @param string $unknownDriverName - * @param array $knownDrivers + * @param string $unknownDriverName + * @param string[] $knownDrivers * * @return \Doctrine\DBAL\DBALException */ @@ -131,7 +131,7 @@ public static function unknownDriver($unknownDriverName, array $knownDrivers) /** * @param Exception $driverEx * @param string $sql - * @param array $params + * @param mixed[] $params * * @return \Doctrine\DBAL\DBALException */ @@ -177,7 +177,7 @@ private static function wrapException(Driver $driver, Throwable $driverEx, $msg) * Returns a human-readable representation of an array of parameters. * This properly handles binary data by returning a hex representation. * - * @param array $params + * @param mixed[] $params * * @return string */ diff --git a/lib/Doctrine/DBAL/Driver.php b/lib/Doctrine/DBAL/Driver.php index 22e9c6781e5..dcb03b29492 100644 --- a/lib/Doctrine/DBAL/Driver.php +++ b/lib/Doctrine/DBAL/Driver.php @@ -14,10 +14,10 @@ interface Driver /** * Attempts to create a connection with the database. * - * @param array $params All connection parameters passed by the user. + * @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. - * @param array $driverOptions The driver options to use when connecting. + * @param mixed[] $driverOptions The driver options to use when connecting. * * @return \Doctrine\DBAL\Driver\Connection The database connection. */ diff --git a/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php b/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php index 0a8771f117f..cda69bb29aa 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php @@ -88,7 +88,7 @@ public function getSchemaManager(Connection $conn) /** * Returns an appropriate Easy Connect String for the given parameters. * - * @param array $params The connection parameters to return the Easy Connect STring for. + * @param mixed[] $params The connection parameters to return the Easy Connect String for. * * @return string */ diff --git a/lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver.php b/lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver.php index 0df1ec62efa..c3e6c450f12 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver.php @@ -76,7 +76,6 @@ public function getDatabasePlatform() /** * {@inheritdoc} */ - public function getSchemaManager(Connection $conn) { return new SQLServerSchemaManager($conn); diff --git a/lib/Doctrine/DBAL/Driver/Connection.php b/lib/Doctrine/DBAL/Driver/Connection.php index d9ce4b4b5d3..1574581c2ad 100644 --- a/lib/Doctrine/DBAL/Driver/Connection.php +++ b/lib/Doctrine/DBAL/Driver/Connection.php @@ -87,7 +87,7 @@ public function errorCode(); /** * Returns extended error information associated with the last operation on the database handle. * - * @return array + * @return mixed[] */ public function errorInfo(); } diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php index fbd369e8483..bc555f8604c 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php @@ -30,10 +30,10 @@ class DB2Connection implements Connection, ServerInfoAwareConnection private $_conn = null; /** - * @param array $params - * @param string $username - * @param string $password - * @param array $driverOptions + * @param mixed[] $params + * @param string $username + * @param string $password + * @param mixed[] $driverOptions * * @throws DB2Exception */ diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php index 181815b522d..9a8baf69bd2 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php @@ -42,7 +42,7 @@ class DB2Statement implements IteratorAggregate, Statement /** @var resource */ private $_stmt; - /** @var array */ + /** @var mixed[] */ private $_bindParam = []; /** @var string Name of the default class to instantiate when fetching class instances. */ @@ -64,7 +64,7 @@ class DB2Statement implements IteratorAggregate, Statement /** * DB2_BINARY, DB2_CHAR, DB2_DOUBLE, or DB2_LONG * - * @var array + * @var int[] */ static private $_typeMap = [ ParameterType::INTEGER => DB2_LONG, @@ -313,7 +313,7 @@ public function rowCount() * * @param stdClass $sourceObject Object to cast from. * @param string|object $destinationClass Name of the class or class instance to cast to. - * @param array $ctorArgs Arguments to use for constructing the destination class instance. + * @param mixed[] $ctorArgs Arguments to use for constructing the destination class instance. * * @return object * diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php index e0ae5f8b2f9..4495cc92d0f 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php @@ -38,10 +38,10 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar private $_conn; /** - * @param array $params - * @param string $username - * @param string $password - * @param array $driverOptions + * @param mixed[] $params + * @param string $username + * @param string $password + * @param mixed[] $driverOptions * * @throws MysqliException */ @@ -217,7 +217,7 @@ public function errorInfo() /** * Apply the driver options to the connection. * - * @param array $driverOptions + * @param mixed[] $driverOptions * * @throws MysqliException When one of of the options is not supported. * @throws MysqliException When applying doesn't work - e.g. due to incorrect value. @@ -277,7 +277,7 @@ public function ping() /** * Establish a secure connection * - * @param array $params + * @param mixed[] $params * * @throws MysqliException */ diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php index 8948a49efc1..2bbe0ca8b20 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php @@ -19,11 +19,12 @@ use function fread; use function get_resource_type; use function is_resource; +use function sprintf; use function str_repeat; class MysqliStatement implements IteratorAggregate, Statement { - /** @var array */ + /** @var string[] */ protected static $_paramTypeMap = [ ParameterType::STRING => 's', ParameterType::BINARY => 's', @@ -39,13 +40,13 @@ class MysqliStatement implements IteratorAggregate, Statement /** @var mysqli_stmt */ protected $_stmt; - /** @var bool|array|null */ + /** @var string[]|bool|null */ protected $_columnNames; - /** @var array|null */ + /** @var mixed[]|null */ protected $_rowBindedValues; - /** @var array */ + /** @var mixed[] */ protected $_bindedValues; /** @var string */ @@ -54,7 +55,7 @@ class MysqliStatement implements IteratorAggregate, Statement /** * Contains ref values for bindValue(). * - * @var array + * @var mixed[] */ protected $_values = []; @@ -99,7 +100,7 @@ public function bindParam($column, &$variable, $type = ParameterType::STRING, $l $type = 's'; } else { if (! isset(self::$_paramTypeMap[$type])) { - throw new MysqliException("Unknown type: '{$type}'"); + throw new MysqliException(sprintf("Unknown type: '%s'", $type)); } $type = self::$_paramTypeMap[$type]; @@ -120,7 +121,7 @@ public function bindValue($param, $value, $type = ParameterType::STRING) $type = 's'; } else { if (! isset(self::$_paramTypeMap[$type])) { - throw new MysqliException("Unknown type: '{$type}'"); + throw new MysqliException(sprintf("Unknown type: '%s'", $type)); } $type = self::$_paramTypeMap[$type]; @@ -265,7 +266,7 @@ private function sendLongData($streams) /** * Binds a array of values to bound parameters. * - * @param array $values + * @param mixed[] $values * * @return bool */ @@ -350,7 +351,7 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX return $ret; default: - throw new MysqliException("Unknown fetch type '{$fetchMode}'"); + throw new MysqliException(sprintf("Unknown fetch type '%s'", $fetchMode)); } } diff --git a/lib/Doctrine/DBAL/Driver/OCI8/Driver.php b/lib/Doctrine/DBAL/Driver/OCI8/Driver.php index c0a792ed7ba..872582d80b7 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/Driver.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/Driver.php @@ -33,7 +33,7 @@ public function connect(array $params, $username = null, $password = null, array /** * Constructs the Oracle DSN. * - * @param array $params + * @param mixed[] $params * * @return string The DSN. */ diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php index 818c4531aa4..5ebc877a898 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php @@ -66,8 +66,8 @@ public function __construct($username, $password, $db, $charset = null, $session /** * {@inheritdoc} * - * @throws UnexpectedValueException if the version string returned by the database server - * does not contain a parsable version number. + * @throws UnexpectedValueException If the version string returned by the database server + * does not contain a parsable version number. */ public function getServerVersion() { diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Exception.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Exception.php index 51e52a51516..9d61ad42d08 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Exception.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Exception.php @@ -7,7 +7,7 @@ class OCI8Exception extends AbstractDriverException { /** - * @param array $error + * @param mixed[] $error * * @return \Doctrine\DBAL\Driver\OCI8\OCI8Exception */ diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php index 51cf3864885..8db54c86aa7 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php @@ -59,7 +59,7 @@ class OCI8Statement implements IteratorAggregate, Statement /** @var string */ protected static $_PARAM = ':param'; - /** @var array */ + /** @var int[] */ protected static $fetchModeMap = [ FetchMode::MIXED => OCI_BOTH, FetchMode::ASSOCIATIVE => OCI_ASSOC, @@ -70,7 +70,7 @@ class OCI8Statement implements IteratorAggregate, Statement /** @var int */ protected $_defaultFetchMode = FetchMode::MIXED; - /** @var array */ + /** @var string[] */ protected $_paramMap = []; /** @@ -78,7 +78,7 @@ class OCI8Statement implements IteratorAggregate, Statement * * This is a new requirement for PHP7's oci8 extension that prevents bound values from being garbage collected. * - * @var array + * @var mixed[] */ private $boundValues = []; @@ -118,7 +118,7 @@ public function __construct($dbh, $statement, OCI8Connection $conn) * * @param string $statement The SQL statement to convert. * - * @return array [0] => the statement value (string), [1] => the paramMap value (array). + * @return mixed[] [0] => the statement value (string), [1] => the paramMap value (array). * * @throws OCI8Exception * diff --git a/lib/Doctrine/DBAL/Driver/PDOConnection.php b/lib/Doctrine/DBAL/Driver/PDOConnection.php index e7bced5e796..f94716e003f 100644 --- a/lib/Doctrine/DBAL/Driver/PDOConnection.php +++ b/lib/Doctrine/DBAL/Driver/PDOConnection.php @@ -14,12 +14,12 @@ class PDOConnection extends PDO implements Connection, ServerInfoAwareConnection { /** - * @param string $dsn - * @param string|null $user - * @param string|null $password - * @param array|null $options + * @param string $dsn + * @param string|null $user + * @param string|null $password + * @param mixed[]|null $options * - * @throws PDOException in case of an error. + * @throws PDOException In case of an error. */ public function __construct($dsn, $user = null, $password = null, ?array $options = null) { diff --git a/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php b/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php index d2e3e506f70..efd4269cbb2 100644 --- a/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php @@ -28,7 +28,7 @@ public function connect(array $params, $username = null, $password = null, array /** * Constructs the IBM PDO DSN. * - * @param array $params + * @param mixed[] $params * * @return string The DSN. */ diff --git a/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php b/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php index bc0727ff3e6..59d27d3844f 100644 --- a/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php @@ -34,7 +34,7 @@ public function connect(array $params, $username = null, $password = null, array /** * Constructs the MySql PDO DSN. * - * @param array $params + * @param mixed[] $params * * @return string The DSN. */ diff --git a/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php b/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php index 57dfbe76688..f1239eafbd4 100644 --- a/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php @@ -37,7 +37,7 @@ public function connect(array $params, $username = null, $password = null, array /** * Constructs the Oracle PDO DSN. * - * @param array $params + * @param mixed[] $params * * @return string The DSN. */ diff --git a/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php b/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php index 914f55348a4..972dbadcd5d 100644 --- a/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php @@ -52,7 +52,7 @@ public function connect(array $params, $username = null, $password = null, array /** * Constructs the Postgres PDO DSN. * - * @param array $params + * @param mixed[] $params * * @return string The DSN. */ @@ -76,7 +76,7 @@ private function _constructPdoDsn(array $params) // Used for temporary connections to allow operations like dropping the database currently connected to. // Connecting without an explicit database does not work, therefore "postgres" database is used // as it is mostly present in every server setup. - $dsn .= 'dbname=postgres' . ';'; + $dsn .= 'dbname=postgres;'; } if (isset($params['sslmode'])) { diff --git a/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php b/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php index 9a23e719140..a28648562a5 100644 --- a/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php @@ -13,7 +13,7 @@ */ class Driver extends AbstractSQLiteDriver { - /** @var array */ + /** @var mixed[] */ protected $_userDefinedFunctions = [ 'sqrt' => ['callback' => ['Doctrine\DBAL\Platforms\SqlitePlatform', 'udfSqrt'], 'numArgs' => 1], 'mod' => ['callback' => ['Doctrine\DBAL\Platforms\SqlitePlatform', 'udfMod'], 'numArgs' => 2], @@ -54,7 +54,7 @@ public function connect(array $params, $username = null, $password = null, array /** * Constructs the Sqlite PDO DSN. * - * @param array $params + * @param mixed[] $params * * @return string The DSN. */ diff --git a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php index 7fb131d27f1..6543e32392e 100644 --- a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php @@ -29,7 +29,7 @@ public function connect(array $params, $username = null, $password = null, array /** * Constructs the Sqlsrv PDO DSN. * - * @param array $params + * @param mixed[] $params * @param string[] $connectionOptions * * @return string The DSN. @@ -54,9 +54,7 @@ private function _constructPdoDsn(array $params, array $connectionOptions) $connectionOptions['MultipleActiveResultSets'] = $params['MultipleActiveResultSets'] ? 'true' : 'false'; } - $dsn .= $this->getConnectionOptionsDsn($connectionOptions); - - return $dsn; + return $dsn . $this->getConnectionOptionsDsn($connectionOptions); } /** diff --git a/lib/Doctrine/DBAL/Driver/ResultStatement.php b/lib/Doctrine/DBAL/Driver/ResultStatement.php index d0258a29b37..1e6df0269b8 100644 --- a/lib/Doctrine/DBAL/Driver/ResultStatement.php +++ b/lib/Doctrine/DBAL/Driver/ResultStatement.php @@ -67,22 +67,22 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX /** * Returns an array containing all of the result set rows. * - * @param int|null $fetchMode Controls how the next row will be returned to the caller. - * The value must be one of the {@link \Doctrine\DBAL\FetchMode} constants, - * defaulting to {@link \Doctrine\DBAL\FetchMode::MIXED}. - * @param int|null $fetchArgument This argument has a different meaning depending on the value of the $fetchMode parameter: - * * {@link \Doctrine\DBAL\FetchMode::COLUMN}: - * Returns the indicated 0-indexed column. - * * {@link \Doctrine\DBAL\FetchMode::CUSTOM_OBJECT}: - * Returns instances of the specified class, mapping the columns of each row - * to named properties in the class. - * * \PDO::FETCH_FUNC: Returns the results of calling the specified function, using each row's - * columns as parameters in the call. - * @param array|null $ctorArgs Controls how the next row will be returned to the caller. - * The value must be one of the {@link \Doctrine\DBAL\FetchMode} constants, - * defaulting to {@link \Doctrine\DBAL\FetchMode::MIXED}. + * @param int|null $fetchMode Controls how the next row will be returned to the caller. + * The value must be one of the {@link \Doctrine\DBAL\FetchMode} constants, + * defaulting to {@link \Doctrine\DBAL\FetchMode::MIXED}. + * @param int|null $fetchArgument This argument has a different meaning depending on the value of the $fetchMode parameter: + * * {@link \Doctrine\DBAL\FetchMode::COLUMN}: + * Returns the indicated 0-indexed column. + * * {@link \Doctrine\DBAL\FetchMode::CUSTOM_OBJECT}: + * Returns instances of the specified class, mapping the columns of each row + * to named properties in the class. + * * \PDO::FETCH_FUNC: Returns the results of calling the specified function, using each row's + * columns as parameters in the call. + * @param mixed[]|null $ctorArgs Controls how the next row will be returned to the caller. + * The value must be one of the {@link \Doctrine\DBAL\FetchMode} constants, + * defaulting to {@link \Doctrine\DBAL\FetchMode::MIXED}. * - * @return array + * @return mixed[] */ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null); @@ -90,10 +90,9 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n * Returns a single column from the next row of a result set or FALSE if there are no more rows. * * @param int $columnIndex 0-indexed number of the column you wish to retrieve from the row. - * If no value is supplied, PDOStatement->fetchColumn() - * fetches the first column. + * If no value is supplied, fetches the first column. * - * @return string|bool A single column in the next row of a result set, or FALSE if there are no more rows. + * @return mixed|false A single column in the next row of a result set, or FALSE if there are no more rows. */ public function fetchColumn($columnIndex = 0); } diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php index 38558702092..d4b73a4723c 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php @@ -18,7 +18,7 @@ class Driver extends AbstractSQLAnywhereDriver /** * {@inheritdoc} * - * @throws DBALException if there was a problem establishing the connection. + * @throws DBALException If there was a problem establishing the connection. */ public function connect(array $params, $username = null, $password = null, array $driverOptions = []) { @@ -51,15 +51,15 @@ public function getName() /** * Build the connection string for given connection parameters and driver options. * - * @param string $host Host address to connect to. - * @param int $port Port to use for the connection (default to SQL Anywhere standard port 2638). - * @param string $server Database server name on the host to connect to. - * SQL Anywhere allows multiple database server instances on the same host, - * therefore specifying the server instance name to use is mandatory. - * @param string $dbname Name of the database on the server instance to connect to. - * @param string $username User name to use for connection authentication. - * @param string $password Password to use for connection authentication. - * @param array $driverOptions Additional parameters to use for the connection. + * @param string $host Host address to connect to. + * @param int $port Port to use for the connection (default to SQL Anywhere standard port 2638). + * @param string $server Database server name on the host to connect to. + * SQL Anywhere allows multiple database server instances on the same host, + * therefore specifying the server instance name to use is mandatory. + * @param string $dbname Name of the database on the server instance to connect to. + * @param string $username User name to use for connection authentication. + * @param string $password Password to use for connection authentication. + * @param mixed[] $driverOptions Additional parameters to use for the connection. * * @return string */ diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php index 78d3fde398b..5290509fef5 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php @@ -315,7 +315,7 @@ public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) * * @param stdClass $sourceObject Object to cast from. * @param string|object $destinationClass Name of the class or class instance to cast to. - * @param array $ctorArgs Arguments to use for constructing the destination class instance. + * @param mixed[] $ctorArgs Arguments to use for constructing the destination class instance. * * @return object * diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php index 243bf7569da..f1f9ddd1d79 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php @@ -33,8 +33,8 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection protected $lastInsertId; /** - * @param string $serverName - * @param array $connectionOptions + * @param string $serverName + * @param mixed[] $connectionOptions * * @throws SQLSrvException */ diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php index 23dfb6c0658..147ef76e1a0 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php @@ -63,21 +63,21 @@ class SQLSrvStatement implements IteratorAggregate, Statement /** * References to the variables bound as statement parameters. * - * @var array + * @var mixed */ private $variables = []; /** * Bound parameter types. * - * @var array + * @var int[] */ private $types = []; /** * Translations. * - * @var array + * @var int[] */ private static $fetchMap = [ FetchMode::MIXED => SQLSRV_FETCH_BOTH, @@ -271,8 +271,8 @@ private function prepare() $params[$column - 1] = [ &$variable, SQLSRV_PARAM_IN, - sqlsrv_phptype_stream(SQLSRV_ENC_BINARY), - sqlsrv_sqltype_varbinary('max'), + SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), + SQLSRV_SQLTYPE_VARBINARY('max'), ]; break; @@ -280,7 +280,7 @@ private function prepare() $params[$column - 1] = [ &$variable, SQLSRV_PARAM_IN, - sqlsrv_phptype_string(SQLSRV_ENC_BINARY), + SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY), ]; break; diff --git a/lib/Doctrine/DBAL/Driver/Statement.php b/lib/Doctrine/DBAL/Driver/Statement.php index 66f17ab7c51..3bfeb6a4c42 100644 --- a/lib/Doctrine/DBAL/Driver/Statement.php +++ b/lib/Doctrine/DBAL/Driver/Statement.php @@ -72,9 +72,7 @@ public function errorCode(); /** * Fetches extended error information associated with the last operation on the statement handle. * - * @see Doctrine_Adapter_Interface::errorInfo() - * - * @return array The error info array. + * @return mixed[] The error info array. */ public function errorInfo(); @@ -87,8 +85,8 @@ public function errorInfo(); * if any, of their associated parameter markers or pass an array of input-only * parameter values. * - * @param array|null $params An array of values with as many elements as there are - * bound parameters in the SQL statement being executed. + * @param mixed[]|null $params An array of values with as many elements as there are + * bound parameters in the SQL statement being executed. * * @return bool TRUE on success or FALSE on failure. */ diff --git a/lib/Doctrine/DBAL/DriverManager.php b/lib/Doctrine/DBAL/DriverManager.php index 1b5d64cc329..4afe0add837 100644 --- a/lib/Doctrine/DBAL/DriverManager.php +++ b/lib/Doctrine/DBAL/DriverManager.php @@ -28,7 +28,7 @@ final class DriverManager * To add your own driver use the 'driverClass' parameter to * {@link DriverManager::getConnection()}. * - * @var array + * @var string[] */ private static $_driverMap = [ 'pdo_mysql' => 'Doctrine\DBAL\Driver\PDOMySql\Driver', @@ -46,6 +46,8 @@ final class DriverManager /** * List of URL schemes from a database URL and their mappings to driver. + * + * @var string[] */ private static $driverSchemeAliases = [ 'db2' => 'ibm_db2', @@ -113,7 +115,7 @@ private function __construct() * driverClass: * The driver class to use. * - * @param array $params The parameters. + * @param mixed[] $params The parameters. * @param Configuration|null $config The configuration to use. * @param EventManager|null $eventManager The event manager to use. * @@ -185,7 +187,7 @@ public static function getConnection( /** * Returns the list of supported drivers. * - * @return array + * @return string[] */ public static function getAvailableDrivers() : array { @@ -195,7 +197,7 @@ public static function getAvailableDrivers() : array /** * Checks the list of parameters. * - * @param array $params The list of parameters. + * @param mixed[] $params The list of parameters. * * @throws DBALException */ @@ -235,10 +237,10 @@ private static function normalizeDatabaseUrlPath(string $urlPath) : string * Extracts parts from a database URL, if present, and returns an * updated list of parameters. * - * @param array $params The list of parameters. + * @param mixed[] $params The list of parameters. * - * @return array A modified list of parameters with info from a database - * URL extracted into indidivual parameter parts. + * @return mixed[] A modified list of parameters with info from a database + * URL extracted into indidivual parameter parts. * * @throws DBALException */ @@ -291,10 +293,10 @@ private static function parseDatabaseUrl(array $params) : array * * @see parseDatabaseUrlScheme * - * @param array $url The URL parts to evaluate. - * @param array $params The connection parameters to resolve. + * @param mixed[] $url The URL parts to evaluate. + * @param mixed[] $params The connection parameters to resolve. * - * @return array The resolved connection parameters. + * @return mixed[] The resolved connection parameters. */ private static function parseDatabaseUrlPath(array $url, array $params) : array { @@ -320,10 +322,10 @@ private static function parseDatabaseUrlPath(array $url, array $params) : array /** * Parses the query part of the given connection URL and resolves the given connection parameters. * - * @param array $url The connection URL parts to evaluate. - * @param array $params The connection parameters to resolve. + * @param mixed[] $url The connection URL parts to evaluate. + * @param mixed[] $params The connection parameters to resolve. * - * @return array The resolved connection parameters. + * @return mixed[] The resolved connection parameters. */ private static function parseDatabaseUrlQuery(array $url, array $params) : array { @@ -345,10 +347,10 @@ private static function parseDatabaseUrlQuery(array $url, array $params) : array * * @see normalizeDatabaseUrlPath * - * @param array $url The regular connection URL parts to evaluate. - * @param array $params The connection parameters to resolve. + * @param mixed[] $url The regular connection URL parts to evaluate. + * @param mixed[] $params The connection parameters to resolve. * - * @return array The resolved connection parameters. + * @return mixed[] The resolved connection parameters. */ private static function parseRegularDatabaseUrlPath(array $url, array $params) : array { @@ -364,10 +366,10 @@ private static function parseRegularDatabaseUrlPath(array $url, array $params) : * * @see normalizeDatabaseUrlPath * - * @param array $url The SQLite connection URL parts to evaluate. - * @param array $params The connection parameters to resolve. + * @param mixed[] $url The SQLite connection URL parts to evaluate. + * @param mixed[] $params The connection parameters to resolve. * - * @return array The resolved connection parameters. + * @return mixed[] The resolved connection parameters. */ private static function parseSqliteDatabaseUrlPath(array $url, array $params) : array { @@ -385,12 +387,12 @@ private static function parseSqliteDatabaseUrlPath(array $url, array $params) : /** * Parses the scheme part from given connection URL and resolves the given connection parameters. * - * @param array $url The connection URL parts to evaluate. - * @param array $params The connection parameters to resolve. + * @param mixed[] $url The connection URL parts to evaluate. + * @param mixed[] $params The connection parameters to resolve. * - * @return array The resolved connection parameters. + * @return mixed[] The resolved connection parameters. * - * @throws DBALException if parsing failed or resolution is not possible. + * @throws DBALException If parsing failed or resolution is not possible. */ private static function parseDatabaseUrlScheme(array $url, array $params) : array { diff --git a/lib/Doctrine/DBAL/Event/Listeners/OracleSessionInit.php b/lib/Doctrine/DBAL/Event/Listeners/OracleSessionInit.php index 8415e2e49d4..e694432600b 100644 --- a/lib/Doctrine/DBAL/Event/Listeners/OracleSessionInit.php +++ b/lib/Doctrine/DBAL/Event/Listeners/OracleSessionInit.php @@ -25,7 +25,7 @@ */ class OracleSessionInit implements EventSubscriber { - /** @var array */ + /** @var string[] */ protected $_defaultSessionVars = [ 'NLS_TIME_FORMAT' => 'HH24:MI:SS', 'NLS_DATE_FORMAT' => 'YYYY-MM-DD HH24:MI:SS', @@ -35,7 +35,7 @@ class OracleSessionInit implements EventSubscriber ]; /** - * @param array $oracleSessionVars + * @param string[] $oracleSessionVars */ public function __construct(array $oracleSessionVars = []) { diff --git a/lib/Doctrine/DBAL/Event/SchemaAlterTableAddColumnEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaAlterTableAddColumnEventArgs.php index 7d07abc1d57..551a2eeec44 100644 --- a/lib/Doctrine/DBAL/Event/SchemaAlterTableAddColumnEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaAlterTableAddColumnEventArgs.php @@ -24,7 +24,7 @@ class SchemaAlterTableAddColumnEventArgs extends SchemaEventArgs /** @var AbstractPlatform */ private $_platform; - /** @var array */ + /** @var string[] */ private $_sql = []; public function __construct(Column $column, TableDiff $tableDiff, AbstractPlatform $platform) @@ -59,7 +59,7 @@ public function getPlatform() } /** - * @param string|array $sql + * @param string|string[] $sql * * @return \Doctrine\DBAL\Event\SchemaAlterTableAddColumnEventArgs */ @@ -75,7 +75,7 @@ public function addSql($sql) } /** - * @return array + * @return string[] */ public function getSql() { diff --git a/lib/Doctrine/DBAL/Event/SchemaAlterTableChangeColumnEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaAlterTableChangeColumnEventArgs.php index b3ecfa78ef2..bb3875bc3fc 100644 --- a/lib/Doctrine/DBAL/Event/SchemaAlterTableChangeColumnEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaAlterTableChangeColumnEventArgs.php @@ -24,7 +24,7 @@ class SchemaAlterTableChangeColumnEventArgs extends SchemaEventArgs /** @var AbstractPlatform */ private $_platform; - /** @var array */ + /** @var string[] */ private $_sql = []; public function __construct(ColumnDiff $columnDiff, TableDiff $tableDiff, AbstractPlatform $platform) @@ -59,7 +59,7 @@ public function getPlatform() } /** - * @param string|array $sql + * @param string|string[] $sql * * @return \Doctrine\DBAL\Event\SchemaAlterTableChangeColumnEventArgs */ @@ -75,7 +75,7 @@ public function addSql($sql) } /** - * @return array + * @return string[] */ public function getSql() { diff --git a/lib/Doctrine/DBAL/Event/SchemaAlterTableEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaAlterTableEventArgs.php index 9684fbae646..a4d411c50c7 100644 --- a/lib/Doctrine/DBAL/Event/SchemaAlterTableEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaAlterTableEventArgs.php @@ -20,7 +20,7 @@ class SchemaAlterTableEventArgs extends SchemaEventArgs /** @var AbstractPlatform */ private $_platform; - /** @var array */ + /** @var string[] */ private $_sql = []; public function __construct(TableDiff $tableDiff, AbstractPlatform $platform) @@ -46,7 +46,7 @@ public function getPlatform() } /** - * @param string|array $sql + * @param string|string[] $sql * * @return \Doctrine\DBAL\Event\SchemaAlterTableEventArgs */ @@ -62,7 +62,7 @@ public function addSql($sql) } /** - * @return array + * @return string[] */ public function getSql() { diff --git a/lib/Doctrine/DBAL/Event/SchemaAlterTableRemoveColumnEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaAlterTableRemoveColumnEventArgs.php index 36798a7661b..c4036b679c3 100644 --- a/lib/Doctrine/DBAL/Event/SchemaAlterTableRemoveColumnEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaAlterTableRemoveColumnEventArgs.php @@ -24,7 +24,7 @@ class SchemaAlterTableRemoveColumnEventArgs extends SchemaEventArgs /** @var AbstractPlatform */ private $_platform; - /** @var array */ + /** @var string[] */ private $_sql = []; public function __construct(Column $column, TableDiff $tableDiff, AbstractPlatform $platform) @@ -59,7 +59,7 @@ public function getPlatform() } /** - * @param string|array $sql + * @param string|string[] $sql * * @return \Doctrine\DBAL\Event\SchemaAlterTableRemoveColumnEventArgs */ @@ -75,7 +75,7 @@ public function addSql($sql) } /** - * @return array + * @return string[] */ public function getSql() { diff --git a/lib/Doctrine/DBAL/Event/SchemaAlterTableRenameColumnEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaAlterTableRenameColumnEventArgs.php index 8b15a270998..16bcef74454 100644 --- a/lib/Doctrine/DBAL/Event/SchemaAlterTableRenameColumnEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaAlterTableRenameColumnEventArgs.php @@ -27,7 +27,7 @@ class SchemaAlterTableRenameColumnEventArgs extends SchemaEventArgs /** @var AbstractPlatform */ private $_platform; - /** @var array */ + /** @var string[] */ private $_sql = []; /** @@ -74,7 +74,7 @@ public function getPlatform() } /** - * @param string|array $sql + * @param string|string[] $sql * * @return \Doctrine\DBAL\Event\SchemaAlterTableRenameColumnEventArgs */ @@ -90,7 +90,7 @@ public function addSql($sql) } /** - * @return array + * @return string[] */ public function getSql() { diff --git a/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php index 270ab8d8027..f311c22f2f9 100644 --- a/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php @@ -19,7 +19,7 @@ class SchemaColumnDefinitionEventArgs extends SchemaEventArgs /** * Raw column data as fetched from the database. * - * @var array + * @var mixed[] */ private $_tableColumn; @@ -33,9 +33,9 @@ class SchemaColumnDefinitionEventArgs extends SchemaEventArgs private $_connection; /** - * @param array $tableColumn - * @param string $table - * @param string $database + * @param mixed[] $tableColumn + * @param string $table + * @param string $database */ public function __construct(array $tableColumn, $table, $database, Connection $connection) { @@ -67,7 +67,7 @@ public function getColumn() } /** - * @return array + * @return mixed[] */ public function getTableColumn() { diff --git a/lib/Doctrine/DBAL/Event/SchemaCreateTableColumnEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaCreateTableColumnEventArgs.php index db1f53e846e..fac12845eac 100644 --- a/lib/Doctrine/DBAL/Event/SchemaCreateTableColumnEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaCreateTableColumnEventArgs.php @@ -24,7 +24,7 @@ class SchemaCreateTableColumnEventArgs extends SchemaEventArgs /** @var AbstractPlatform */ private $_platform; - /** @var array */ + /** @var string[] */ private $_sql = []; public function __construct(Column $column, Table $table, AbstractPlatform $platform) @@ -59,7 +59,7 @@ public function getPlatform() } /** - * @param string|array $sql + * @param string|string[] $sql * * @return \Doctrine\DBAL\Event\SchemaCreateTableColumnEventArgs */ @@ -75,7 +75,7 @@ public function addSql($sql) } /** - * @return array + * @return string[] */ public function getSql() { diff --git a/lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php index 8da2cf68f53..7f2afc4f7fa 100644 --- a/lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php @@ -3,6 +3,7 @@ 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; @@ -17,21 +18,21 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs /** @var Table */ private $_table; - /** @var array */ + /** @var Column[] */ private $_columns; - /** @var array */ + /** @var mixed[] */ private $_options; /** @var AbstractPlatform */ private $_platform; - /** @var array */ + /** @var string[] */ private $_sql = []; /** - * @param array $columns - * @param array $options + * @param Column[] $columns + * @param mixed[] $options */ public function __construct(Table $table, array $columns, array $options, AbstractPlatform $platform) { @@ -50,7 +51,7 @@ public function getTable() } /** - * @return array + * @return Column[] */ public function getColumns() { @@ -58,7 +59,7 @@ public function getColumns() } /** - * @return array + * @return mixed[] */ public function getOptions() { @@ -74,7 +75,7 @@ public function getPlatform() } /** - * @param string|array $sql + * @param string|string[] $sql * * @return \Doctrine\DBAL\Event\SchemaCreateTableEventArgs */ @@ -90,7 +91,7 @@ public function addSql($sql) } /** - * @return array + * @return string[] */ public function getSql() { diff --git a/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php index 84584fcbb6e..ec0d94aecbf 100644 --- a/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php @@ -19,7 +19,7 @@ class SchemaIndexDefinitionEventArgs extends SchemaEventArgs /** * Raw index data as fetched from the database. * - * @var array + * @var mixed[] */ private $_tableIndex; @@ -30,8 +30,8 @@ class SchemaIndexDefinitionEventArgs extends SchemaEventArgs private $_connection; /** - * @param array $tableIndex - * @param string $table + * @param mixed[] $tableIndex + * @param string $table */ public function __construct(array $tableIndex, $table, Connection $connection) { @@ -61,7 +61,7 @@ public function getIndex() } /** - * @return array + * @return mixed[] */ public function getTableIndex() { diff --git a/lib/Doctrine/DBAL/Id/TableGenerator.php b/lib/Doctrine/DBAL/Id/TableGenerator.php index f4fc8a67040..cb34dcd5c4b 100644 --- a/lib/Doctrine/DBAL/Id/TableGenerator.php +++ b/lib/Doctrine/DBAL/Id/TableGenerator.php @@ -56,7 +56,7 @@ class TableGenerator /** @var string */ private $generatorTableName; - /** @var array */ + /** @var mixed[][] */ private $sequences = []; /** diff --git a/lib/Doctrine/DBAL/Logging/DebugStack.php b/lib/Doctrine/DBAL/Logging/DebugStack.php index 6863c8cef59..4372e382416 100644 --- a/lib/Doctrine/DBAL/Logging/DebugStack.php +++ b/lib/Doctrine/DBAL/Logging/DebugStack.php @@ -14,7 +14,7 @@ class DebugStack implements SQLLogger /** * Executed SQL queries. * - * @var array + * @var mixed[][] */ public $queries = []; diff --git a/lib/Doctrine/DBAL/Logging/SQLLogger.php b/lib/Doctrine/DBAL/Logging/SQLLogger.php index 1fc197fccf3..7c1099dfc28 100644 --- a/lib/Doctrine/DBAL/Logging/SQLLogger.php +++ b/lib/Doctrine/DBAL/Logging/SQLLogger.php @@ -12,9 +12,9 @@ interface SQLLogger /** * Logs a SQL statement somewhere. * - * @param string $sql The SQL to be executed. - * @param array|null $params The SQL parameters. - * @param array|null $types The SQL parameter types. + * @param string $sql The SQL to be executed. + * @param mixed[]|null $params The SQL parameters. + * @param int[]|string[]|null $types The SQL parameter types. * * @return void */ diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index 5f929019e51..b97c66d32b3 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -44,7 +44,6 @@ use function is_bool; use function is_int; use function is_string; -use function join; use function preg_quote; use function preg_replace; use function sprintf; @@ -130,14 +129,14 @@ abstract class AbstractPlatform */ public const TRIM_BOTH = TrimMode::BOTH; - /** @var array|null */ + /** @var string[]|null */ protected $doctrineTypeMapping = null; /** * Contains a list of all columns that should generate parseable column comments for type-detection * in reverse engineering scenarios. * - * @var array|null + * @var string[]|null */ protected $doctrineTypeComments = null; @@ -176,7 +175,7 @@ public function getEventManager() /** * Returns the SQL snippet that declares a boolean column. * - * @param array $columnDef + * @param mixed[] $columnDef * * @return string */ @@ -185,7 +184,7 @@ abstract public function getBooleanTypeDeclarationSQL(array $columnDef); /** * Returns the SQL snippet that declares a 4 byte integer column. * - * @param array $columnDef + * @param mixed[] $columnDef * * @return string */ @@ -194,7 +193,7 @@ abstract public function getIntegerTypeDeclarationSQL(array $columnDef); /** * Returns the SQL snippet that declares an 8 byte integer column. * - * @param array $columnDef + * @param mixed[] $columnDef * * @return string */ @@ -203,7 +202,7 @@ abstract public function getBigIntTypeDeclarationSQL(array $columnDef); /** * Returns the SQL snippet that declares a 2 byte integer column. * - * @param array $columnDef + * @param mixed[] $columnDef * * @return string */ @@ -212,7 +211,7 @@ abstract public function getSmallIntTypeDeclarationSQL(array $columnDef); /** * Returns the SQL snippet that declares common properties of an integer column. * - * @param array $columnDef + * @param mixed[] $columnDef * * @return string */ @@ -245,7 +244,7 @@ private function initializeAllDoctrineTypeMappings() /** * Returns the SQL snippet used to declare a VARCHAR column type. * - * @param array $field + * @param mixed[] $field * * @return string */ @@ -271,7 +270,7 @@ public function getVarcharTypeDeclarationSQL(array $field) /** * Returns the SQL snippet used to declare a BINARY/VARBINARY column type. * - * @param array $field The column definition. + * @param mixed[] $field The column definition. * * @return string */ @@ -306,7 +305,7 @@ public function getBinaryTypeDeclarationSQL(array $field) * By default this maps directly to a CHAR(36) and only maps to more * special datatypes when the underlying databases support this datatype. * - * @param array $field + * @param mixed[] $field * * @return string */ @@ -324,7 +323,7 @@ public function getGuidTypeDeclarationSQL(array $field) * By default this maps directly to a CLOB and only maps to more * special datatypes when the underlying databases support this datatype. * - * @param array $field + * @param mixed[] $field * * @return string */ @@ -364,7 +363,7 @@ protected function getBinaryTypeDeclarationSQLSnippet($length, $fixed) /** * Returns the SQL snippet used to declare a CLOB column type. * - * @param array $field + * @param mixed[] $field * * @return string */ @@ -373,7 +372,7 @@ abstract public function getClobTypeDeclarationSQL(array $field); /** * Returns the SQL Snippet used to declare a BLOB column type. * - * @param array $field + * @param mixed[] $field * * @return string */ @@ -615,7 +614,7 @@ public function getBinaryDefaultLength() /** * Gets all SQL wildcard characters of the platform. * - * @return array + * @return string[] */ public function getWildcards() { @@ -921,7 +920,7 @@ public function getSubstringExpression($value, $from, $length = null) */ public function getConcatExpression() { - return join(' || ', func_get_args()); + return implode(' || ', func_get_args()); } /** @@ -1514,7 +1513,7 @@ public function getDropForeignKeySQL($foreignKey, $table) * * @param int $createFlags * - * @return array The sequence of SQL statements. + * @return string[] The sequence of SQL statements. * * @throws DBALException * @throws InvalidArgumentException @@ -1625,8 +1624,12 @@ public function getCommentOnColumnSQL($tableName, $columnName, $comment) $columnName = new Identifier($columnName); $comment = $this->quoteStringLiteral($comment); - return 'COMMENT ON COLUMN ' . $tableName->getQuotedName($this) . '.' . $columnName->getQuotedName($this) . - ' IS ' . $comment; + return sprintf( + 'COMMENT ON COLUMN %s.%s IS %s', + $tableName->getQuotedName($this), + $columnName->getQuotedName($this), + $comment + ); } /** @@ -1650,11 +1653,11 @@ public function getInlineColumnCommentSQL($comment) /** * Returns the SQL used to create a table. * - * @param string $tableName - * @param array $columns - * @param array $options + * @param string $tableName + * @param mixed[][] $columns + * @param mixed[] $options * - * @return array + * @return string[] */ protected function _getCreateTableSQL($tableName, array $columns, array $options = []) { @@ -1901,9 +1904,7 @@ public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table) $table = $table->getQuotedName($this); } - $query = 'ALTER TABLE ' . $table . ' ADD ' . $this->getForeignKeyDeclarationSQL($foreignKey); - - return $query; + return 'ALTER TABLE ' . $table . ' ADD ' . $this->getForeignKeyDeclarationSQL($foreignKey); } /** @@ -1911,7 +1912,7 @@ public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table) * * This method returns an array of SQL statements, since some platforms need several statements. * - * @return array + * @return string[] * * @throws DBALException If not supported on this platform. */ @@ -1921,7 +1922,7 @@ public function getAlterTableSQL(TableDiff $diff) } /** - * @param array $columnSql + * @param mixed[] $columnSql * * @return bool */ @@ -1944,7 +1945,7 @@ protected function onSchemaAlterTableAddColumn(Column $column, TableDiff $diff, } /** - * @param array $columnSql + * @param string[] $columnSql * * @return bool */ @@ -1967,7 +1968,7 @@ protected function onSchemaAlterTableRemoveColumn(Column $column, TableDiff $dif } /** - * @param array $columnSql + * @param string[] $columnSql * * @return bool */ @@ -1990,8 +1991,8 @@ protected function onSchemaAlterTableChangeColumn(ColumnDiff $columnDiff, TableD } /** - * @param string $oldColumnName - * @param array $columnSql + * @param string $oldColumnName + * @param string[] $columnSql * * @return bool */ @@ -2014,7 +2015,7 @@ protected function onSchemaAlterTableRenameColumn($oldColumnName, Column $column } /** - * @param array $sql + * @param string[] $sql * * @return bool */ @@ -2037,7 +2038,7 @@ protected function onSchemaAlterTable(TableDiff $diff, &$sql) } /** - * @return array + * @return string[] */ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) { @@ -2064,7 +2065,7 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) } /** - * @return array + * @return string[] */ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff) { @@ -2110,7 +2111,7 @@ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff) * @param Index $index The definition of the index to rename to. * @param string $tableName The table to rename the given index on. * - * @return array The sequence of SQL statements for renaming the given index. + * @return string[] The sequence of SQL statements for renaming the given index. */ protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName) { @@ -2123,7 +2124,7 @@ protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName) /** * Common code for alter table statement generation that updates the changed Index and Foreign Key definitions. * - * @return array + * @return string[] */ protected function _getAlterTableIndexForeignKeySQL(TableDiff $diff) { @@ -2133,11 +2134,11 @@ protected function _getAlterTableIndexForeignKeySQL(TableDiff $diff) /** * Gets declaration of a number of fields in bulk. * - * @param array $fields A multidimensional associative array. - * The first dimension determines the field name, while the second - * dimension is keyed with the name of the properties - * of the field being declared as array indexes. Currently, the types - * of supported field properties are as follows: + * @param mixed[][] $fields A multidimensional associative array. + * The first dimension determines the field name, while the second + * dimension is keyed with the name of the properties + * of the field being declared as array indexes. Currently, the types + * of supported field properties are as follows: * * length * Integer value that determines the maximum length of the text @@ -2174,10 +2175,10 @@ public function getColumnDeclarationListSQL(array $fields) * Obtains DBMS specific SQL code portion needed to declare a generic type * field to be used in statements like CREATE TABLE. * - * @param string $name The name the field to be declared. - * @param array $field An associative array with the name of the properties - * of the field being declared as array indexes. Currently, the types - * of supported field properties are as follows: + * @param string $name The name the field to be declared. + * @param mixed[] $field An associative array with the name of the properties + * of the field being declared as array indexes. Currently, the types + * of supported field properties are as follows: * * length * Integer value that determines the maximum length of the text @@ -2238,7 +2239,7 @@ public function getColumnDeclarationSQL($name, array $field) /** * Returns the SQL snippet that declares a floating point column of arbitrary precision. * - * @param array $columnDef + * @param mixed[] $columnDef * * @return string */ @@ -2256,7 +2257,7 @@ public function getDecimalTypeDeclarationSQL(array $columnDef) * Obtains DBMS specific SQL code portion needed to set a default value * declaration to be used in statements like CREATE TABLE. * - * @param array $field The field definition array. + * @param mixed[] $field The field definition array. * * @return string DBMS specific SQL code portion needed to set a default value. */ @@ -2301,7 +2302,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 array $definition The check definition. + * @param mixed[][] $definition The check definition. * * @return string DBMS specific SQL code portion needed to set a CHECK constraint. */ @@ -2380,7 +2381,7 @@ public function getIndexDeclarationSQL($name, Index $index) * e.g. when a field has the "columnDefinition" keyword. * Only "AUTOINCREMENT" and "PRIMARY KEY" are added if appropriate. * - * @param array $columnDef + * @param mixed[] $columnDef * * @return string */ @@ -2393,7 +2394,7 @@ public function getCustomTypeDeclarationSQL(array $columnDef) * Obtains DBMS specific SQL code portion needed to set an index * declaration to be used in statements like CREATE TABLE. * - * @param array $fields + * @param mixed[][] $fields * * @return string */ @@ -2486,7 +2487,7 @@ public function getAdvancedForeignKeyOptionsSQL(ForeignKeyConstraint $foreignKey * * @return string * - * @throws InvalidArgumentException if unknown referential action given + * @throws InvalidArgumentException If unknown referential action given. */ public function getForeignKeyReferentialActionSQL($action) { @@ -2529,12 +2530,10 @@ public function getForeignKeyBaseDeclarationSQL(ForeignKeyConstraint $foreignKey throw new InvalidArgumentException("Incomplete definition. 'foreignTable' required."); } - $sql .= implode(', ', $foreignKey->getQuotedLocalColumns($this)) + return $sql . implode(', ', $foreignKey->getQuotedLocalColumns($this)) . ') REFERENCES ' . $foreignKey->getQuotedForeignTableName($this) . ' (' . implode(', ', $foreignKey->getQuotedForeignColumns($this)) . ')'; - - return $sql; } /** @@ -2924,7 +2923,7 @@ public function getSetTransactionIsolationSQL($level) * Obtains DBMS specific SQL to be used to create datetime fields in * statements like CREATE TABLE. * - * @param array $fieldDeclaration + * @param mixed[] $fieldDeclaration * * @return string * @@ -2938,7 +2937,7 @@ public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration) /** * Obtains DBMS specific SQL to be used to create datetime with timezone offset fields. * - * @param array $fieldDeclaration + * @param mixed[] $fieldDeclaration * * @return string */ @@ -2952,7 +2951,7 @@ public function getDateTimeTzTypeDeclarationSQL(array $fieldDeclaration) * Obtains DBMS specific SQL to be used to create date fields in statements * like CREATE TABLE. * - * @param array $fieldDeclaration + * @param mixed[] $fieldDeclaration * * @return string * @@ -2967,7 +2966,7 @@ public function getDateTypeDeclarationSQL(array $fieldDeclaration) * Obtains DBMS specific SQL to be used to create time fields in statements * like CREATE TABLE. * - * @param array $fieldDeclaration + * @param mixed[] $fieldDeclaration * * @return string * @@ -2979,7 +2978,7 @@ public function getTimeTypeDeclarationSQL(array $fieldDeclaration) } /** - * @param array $fieldDeclaration + * @param mixed[] $fieldDeclaration * * @return string */ diff --git a/lib/Doctrine/DBAL/Platforms/DB2Platform.php b/lib/Doctrine/DBAL/Platforms/DB2Platform.php index 56b4d19562e..605122115d4 100644 --- a/lib/Doctrine/DBAL/Platforms/DB2Platform.php +++ b/lib/Doctrine/DBAL/Platforms/DB2Platform.php @@ -618,8 +618,8 @@ public function getAlterTableSQL(TableDiff $diff) * * @param Table $table The table to gather the SQL for. * @param ColumnDiff $columnDiff The column diff to evaluate. - * @param array $sql The sequence of table alteration statements to fill. - * @param array $queryParts The sequence of column alteration clauses to fill. + * @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) { @@ -649,7 +649,7 @@ private function gatherAlterColumnSQL(Table $table, ColumnDiff $columnDiff, arra * * @param ColumnDiff $columnDiff The column diff to evaluate. * - * @return array + * @return string[] */ private function getAlterColumnClausesSQL(ColumnDiff $columnDiff) { diff --git a/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php b/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php index fd23ab011c0..ad148201580 100644 --- a/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php @@ -19,7 +19,6 @@ use function is_bool; use function is_numeric; use function is_string; -use function join; use function sprintf; use function trim; @@ -51,7 +50,7 @@ public function getConcatExpression() { $args = func_get_args(); - return 'CONCAT(' . join(', ', (array) $args) . ')'; + return 'CONCAT(' . implode(', ', (array) $args) . ')'; } /** @@ -237,7 +236,7 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options /** * Build SQL for table options * - * @param array $options + * @param mixed[] $options * * @return string */ @@ -286,7 +285,7 @@ private function buildTableOptions(array $options) /** * Build SQL for partition options. * - * @param array $options + * @param mixed[] $options * * @return string */ diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/KeywordList.php b/lib/Doctrine/DBAL/Platforms/Keywords/KeywordList.php index 0135ff1a31f..c1dbbde4fcc 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/KeywordList.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/KeywordList.php @@ -13,7 +13,7 @@ */ abstract class KeywordList { - /** @var array|null */ + /** @var string[]|null */ private $keywords = null; /** @@ -43,7 +43,7 @@ protected function initializeKeywords() /** * Returns the list of keywords. * - * @return array + * @return string[] */ abstract protected function getKeywords(); diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/ReservedKeywordsValidator.php b/lib/Doctrine/DBAL/Platforms/Keywords/ReservedKeywordsValidator.php index 503765e267f..68cdf3d15d8 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/ReservedKeywordsValidator.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/ReservedKeywordsValidator.php @@ -17,7 +17,7 @@ class ReservedKeywordsValidator implements Visitor /** @var KeywordList[] */ private $keywordLists = []; - /** @var array */ + /** @var string[] */ private $violations = []; /** @@ -29,7 +29,7 @@ public function __construct(array $keywordLists) } /** - * @return array + * @return string[] */ public function getViolations() { @@ -39,7 +39,7 @@ public function getViolations() /** * @param string $word * - * @return array + * @return string[] */ private function isReservedWord($word) { @@ -60,8 +60,8 @@ private function isReservedWord($word) } /** - * @param string $asset - * @param array $violatedPlatforms + * @param string $asset + * @param string[] $violatedPlatforms * * @return void */ diff --git a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php index edbae0fc536..744aa08a4bd 100644 --- a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php @@ -22,7 +22,6 @@ use function in_array; use function is_numeric; use function is_string; -use function join; use function sprintf; use function str_replace; use function strtoupper; @@ -107,9 +106,7 @@ public function getLocateExpression($str, $substr, $startPos = false) */ public function getConcatExpression() { - $args = func_get_args(); - - return 'CONCAT(' . join(', ', (array) $args) . ')'; + return sprintf('CONCAT(%s)', implode(', ', func_get_args())); } /** @@ -194,11 +191,11 @@ public function getListTableForeignKeysSQL($table, $database = null) 'FROM information_schema.key_column_usage k /*!50116 ' . 'INNER JOIN information_schema.referential_constraints c ON ' . ' c.constraint_name = k.constraint_name AND ' . - " c.table_name = $table */ WHERE k.table_name = $table"; + ' c.table_name = ' . $table . ' */ WHERE k.table_name = ' . $table; $databaseNameSql = $database ?? 'DATABASE()'; - $sql .= " AND k.table_schema = $databaseNameSql /*!50116 AND c.constraint_schema = $databaseNameSql */"; + $sql .= ' AND k.table_schema = ' . $databaseNameSql . ' /*!50116 AND c.constraint_schema = ' . $databaseNameSql . ' */'; $sql .= ' AND k.`REFERENCED_COLUMN_NAME` is not NULL'; return $sql; @@ -244,9 +241,7 @@ protected function getBinaryTypeDeclarationSQLSnippet($length, $fixed) * MEDIUMTEXT : 2 ^ 24 - 1 = 16777215 * LONGTEXT : 2 ^ 32 - 1 = 4294967295 * - * @param array $field - * - * @return string + * {@inheritDoc} */ public function getClobTypeDeclarationSQL(array $field) { @@ -470,7 +465,7 @@ public function getDefaultValueDeclarationSQL($field) /** * Build SQL for table options * - * @param array $options + * @param mixed[] $options * * @return string */ @@ -526,7 +521,7 @@ private function buildTableOptions(array $options) /** * Build SQL for partition options. * - * @param array $options + * @param mixed[] $options * * @return string */ @@ -724,7 +719,7 @@ private function getPreAlterTableAlterPrimaryKeySQL(TableDiff $diff, Index $inde /** * @param TableDiff $diff The table diff to gather the SQL for. * - * @return array + * @return string[] */ private function getPreAlterTableAlterIndexForeignKeySQL(TableDiff $diff) { @@ -764,7 +759,7 @@ private function getPreAlterTableAlterIndexForeignKeySQL(TableDiff $diff) /** * @param TableDiff $diff The table diff to gather the SQL for. * - * @return array + * @return string[] */ protected function getPreAlterTableRenameIndexForeignKeySQL(TableDiff $diff) { @@ -790,7 +785,7 @@ protected function getPreAlterTableRenameIndexForeignKeySQL(TableDiff $diff) * * @param TableDiff $diff The table diff to evaluate. * - * @return array + * @return ForeignKeyConstraint[] */ private function getRemainingForeignKeyConstraintsRequiringRenamedIndexes(TableDiff $diff) { @@ -832,7 +827,7 @@ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff) /** * @param TableDiff $diff The table diff to gather the SQL for. * - * @return array + * @return string[] */ protected function getPostAlterTableRenameIndexForeignKeySQL(TableDiff $diff) { @@ -912,7 +907,7 @@ public function getDecimalTypeDeclarationSQL(array $columnDef) /** * Get unsigned declaration for a column. * - * @param array $columnDef + * @param mixed[] $columnDef * * @return string */ @@ -1097,9 +1092,7 @@ public function getDropTemporaryTableSQL($table) * MEDIUMBLOB : 2 ^ 24 - 1 = 16777215 * LONGBLOB : 2 ^ 32 - 1 = 4294967295 * - * @param array $field - * - * @return string + * {@inheritDoc} */ public function getBlobTypeDeclarationSQL(array $field) { diff --git a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php index 4976511b4d7..bc05b241098 100644 --- a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php @@ -54,10 +54,10 @@ public static function assertValidIdentifier($identifier) public function getSubstringExpression($value, $position, $length = null) { if ($length !== null) { - return "SUBSTR($value, $position, $length)"; + return sprintf('SUBSTR(%s, %d, %d)', $value, $position, $length); } - return "SUBSTR($value, $position)"; + return sprintf('SUBSTR(%s, %d)', $value, $position); } /** @@ -478,7 +478,7 @@ public function getDropViewSQL($name) * @param string $table * @param int $start * - * @return array + * @return string[] */ public function getCreateAutoincrementSql($name, $table, $start = 1) { @@ -542,7 +542,7 @@ public function getCreateAutoincrementSql($name, $table, $start = 1) * * @param string $table The table name to drop the autoincrement for. * - * @return array + * @return string[] */ public function getDropAutoincrementSql($table) { @@ -657,20 +657,30 @@ public function getListTableColumnsSQL($table, $database = null) $database = $this->quoteStringLiteral($database->getName()); $tabColumnsTableName = 'all_tab_columns'; $colCommentsTableName = 'all_col_comments'; - $tabColumnsOwnerCondition = 'AND c.owner = ' . $database; - $colCommentsOwnerCondition = 'AND d.OWNER = c.OWNER'; + $tabColumnsOwnerCondition = ' AND c.owner = ' . $database; + $colCommentsOwnerCondition = ' AND d.OWNER = c.OWNER'; } - return "SELECT c.*, - ( - SELECT d.comments - FROM $colCommentsTableName d - WHERE d.TABLE_NAME = c.TABLE_NAME " . $colCommentsOwnerCondition . " - AND d.COLUMN_NAME = c.COLUMN_NAME - ) AS comments - FROM $tabColumnsTableName c - WHERE c.table_name = " . $table . " $tabColumnsOwnerCondition - ORDER BY c.column_id"; + return sprintf( + <<<'SQL' +SELECT c.*, + ( + SELECT d.comments + FROM %s d + WHERE d.TABLE_NAME = c.TABLE_NAME%s + AND d.COLUMN_NAME = c.COLUMN_NAME + ) AS comments +FROM %s c +WHERE c.table_name = %s%s +ORDER BY c.column_id +SQL + , + $colCommentsTableName, + $colCommentsOwnerCondition, + $tabColumnsTableName, + $table, + $tabColumnsOwnerCondition + ); } /** @@ -767,7 +777,9 @@ public function getAlterTableSQL(TableDiff $diff) } $fields[] = $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray()); - if (! $comment = $this->getColumnComment($column)) { + $comment = $this->getColumnComment($column); + + if (! $comment) { continue; } diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSQL92Platform.php b/lib/Doctrine/DBAL/Platforms/PostgreSQL92Platform.php index 76c40e56635..14a68caf81d 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSQL92Platform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSQL92Platform.php @@ -3,6 +3,7 @@ namespace Doctrine\DBAL\Platforms; use Doctrine\DBAL\Types\Type; +use function sprintf; /** * Provides the behavior, features and SQL dialect of the PostgreSQL 9.2 database platform. @@ -62,8 +63,9 @@ protected function initializeDoctrineTypeMappings() */ public function getCloseActiveDatabaseConnectionsSQL($database) { - $database = $this->quoteStringLiteral($database); - - return "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = $database"; + return sprintf( + 'SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = %s', + $this->quoteStringLiteral($database) + ); } } diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php index cacccffd8d2..a891d0d69ee 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php @@ -27,6 +27,7 @@ use function is_bool; use function is_numeric; use function is_string; +use function sprintf; use function str_replace; use function strpos; use function strtolower; @@ -42,7 +43,7 @@ class PostgreSqlPlatform extends AbstractPlatform /** @var bool */ private $useBooleanTrueFalseStrings = true; - /** @var array PostgreSQL booleans literals */ + /** @var string[][] PostgreSQL booleans literals */ private $booleanLiterals = [ 'true' => [ 't', @@ -316,17 +317,23 @@ public function getListTableConstraintsSQL($table) $table = new Identifier($table); $table = $this->quoteStringLiteral($table->getName()); - return "SELECT - quote_ident(relname) as relname - FROM - pg_class - WHERE oid IN ( - SELECT indexrelid - FROM pg_index, pg_class - WHERE pg_class.relname = $table - AND pg_class.oid = pg_index.indrelid - AND (indisunique = 't' OR indisprimary = 't') - )"; + return sprintf( + <<<'SQL' +SELECT + quote_ident(relname) as relname +FROM + pg_class +WHERE oid IN ( + SELECT indexrelid + FROM pg_index, pg_class + WHERE pg_class.relname = %s + AND pg_class.oid = pg_index.indrelid + AND (indisunique = 't' OR indisprimary = 't') + ) +SQL + , + $table + ); } /** @@ -366,7 +373,14 @@ private function getTableWhereClause($table, $classAlias = 'c', $namespaceAlias $table = new Identifier($table); $table = $this->quoteStringLiteral($table->getName()); - return $whereClause . "$classAlias.relname = " . $table . " AND $namespaceAlias.nspname = $schema"; + + return $whereClause . sprintf( + '%s.relname = %s AND %s.nspname = %s', + $classAlias, + $table, + $namespaceAlias, + $schema + ); } /** @@ -425,7 +439,7 @@ public function getCreateDatabaseSQL($name) */ public function getDisallowDatabaseConnectionsSQL($database) { - return "UPDATE pg_database SET datallowconn = 'false' WHERE datname = '$database'"; + return "UPDATE pg_database SET datallowconn = 'false' WHERE datname = '" . $database . "'"; } /** @@ -439,9 +453,8 @@ public function getDisallowDatabaseConnectionsSQL($database) */ public function getCloseActiveDatabaseConnectionsSQL($database) { - $database = $this->quoteStringLiteral($database); - - return "SELECT pg_terminate_backend(procpid) FROM pg_stat_activity WHERE datname = $database"; + return 'SELECT pg_terminate_backend(procpid) FROM pg_stat_activity WHERE datname = ' + . $this->quoteStringLiteral($database); } /** @@ -562,7 +575,7 @@ public function getAlterTableSQL(TableDiff $diff) $sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ' . $query; } else { // Drop autoincrement, but do NOT drop the sequence. It might be re-used by other tables or have - $query = 'ALTER ' . $oldColumnName . ' ' . 'DROP DEFAULT'; + $query = 'ALTER ' . $oldColumnName . ' DROP DEFAULT'; $sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ' . $query; } } @@ -676,8 +689,12 @@ public function getCommentOnColumnSQL($tableName, $columnName, $comment) $columnName = new Identifier($columnName); $comment = $comment === null ? 'NULL' : $this->quoteStringLiteral($comment); - return 'COMMENT ON COLUMN ' . $tableName->getQuotedName($this) . '.' . $columnName->getQuotedName($this) . - " IS $comment"; + return sprintf( + 'COMMENT ON COLUMN %s.%s IS %s', + $tableName->getQuotedName($this), + $columnName->getQuotedName($this), + $comment + ); } /** @@ -1201,6 +1218,9 @@ public function getDefaultValueDeclarationSQL($field) return parent::getDefaultValueDeclarationSQL($field); } + /** + * @param mixed[] $field + */ private function isSerialField(array $field) : bool { return $field['autoincrement'] ?? false === true && isset($field['type']) diff --git a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php index 07f45fd7a59..e0aad4ed55e 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php @@ -24,6 +24,7 @@ use function implode; use function is_string; use function preg_replace; +use function sprintf; use function strlen; use function strpos; use function strtoupper; @@ -361,8 +362,12 @@ public function getCommentOnColumnSQL($tableName, $columnName, $comment) $columnName = new Identifier($columnName); $comment = $comment === null ? 'NULL' : $this->quoteStringLiteral($comment); - return 'COMMENT ON COLUMN ' . $tableName->getQuotedName($this) . '.' . $columnName->getQuotedName($this) . - " IS $comment"; + return sprintf( + 'COMMENT ON COLUMN %s.%s IS %s', + $tableName->getQuotedName($this), + $columnName->getQuotedName($this), + $comment + ); } /** @@ -620,7 +625,7 @@ public function getForeignKeyBaseDeclarationSQL(ForeignKeyConstraint $foreignKey * * @return string * - * @throws InvalidArgumentException if unknown match type given + * @throws InvalidArgumentException If unknown match type given. */ public function getForeignKeyMatchClauseSQL($type) { @@ -719,22 +724,29 @@ public function getListTableColumnsSQL($table, $database = null) $user = $this->quoteStringLiteral($user); } - return "SELECT col.column_name, - COALESCE(def.user_type_name, def.domain_name) AS 'type', - def.declared_width AS 'length', - def.scale, - CHARINDEX('unsigned', def.domain_name) AS 'unsigned', - IF col.nulls = 'Y' THEN 0 ELSE 1 ENDIF AS 'notnull', - col.\"default\", - def.is_autoincrement AS 'autoincrement', - rem.remarks AS 'comment' - FROM sa_describe_query('SELECT * FROM \"$table\"') AS def - JOIN SYS.SYSTABCOL AS col - ON col.table_id = def.base_table_id AND col.column_id = def.base_column_id - LEFT JOIN SYS.SYSREMARK AS rem - ON col.object_id = rem.object_id - WHERE def.base_owner_name = $user - ORDER BY def.base_column_id ASC"; + return sprintf( + <<<'SQL' +SELECT col.column_name, + COALESCE(def.user_type_name, def.domain_name) AS 'type', + def.declared_width AS 'length', + def.scale, + CHARINDEX('unsigned', def.domain_name) AS 'unsigned', + IF col.nulls = 'Y' THEN 0 ELSE 1 ENDIF AS 'notnull', + col."default", + def.is_autoincrement AS 'autoincrement', + rem.remarks AS 'comment' +FROM sa_describe_query('SELECT * FROM "%s"') AS def +JOIN SYS.SYSTABCOL AS col +ON col.table_id = def.base_table_id AND col.column_id = def.base_column_id +LEFT JOIN SYS.SYSREMARK AS rem +ON col.object_id = rem.object_id +WHERE def.base_owner_name = %s +ORDER BY def.base_column_id ASC +SQL + , + $table, + $user + ); } /** @@ -754,11 +766,18 @@ public function getListTableConstraintsSQL($table) $table = $this->quoteStringLiteral($table); } - return "SELECT con.* - FROM SYS.SYSCONSTRAINT AS con - JOIN SYS.SYSTAB AS tab ON con.table_object_id = tab.object_id - WHERE tab.table_name = $table - AND tab.creator = USER_ID($user)"; + return sprintf( + <<<'SQL' +SELECT con.* +FROM SYS.SYSCONSTRAINT AS con +JOIN SYS.SYSTAB AS tab ON con.table_object_id = tab.object_id +WHERE tab.table_name = %s +AND tab.creator = USER_ID(%s) +SQL + , + $table, + $user + ); } /** @@ -776,75 +795,82 @@ public function getListTableForeignKeysSQL($table) $table = $this->quoteStringLiteral($table); } - return "SELECT fcol.column_name AS local_column, - ptbl.table_name AS foreign_table, - pcol.column_name AS foreign_column, - idx.index_name, - IF fk.nulls = 'N' - THEN 1 - ELSE NULL - ENDIF AS notnull, - CASE ut.referential_action - WHEN 'C' THEN 'CASCADE' - WHEN 'D' THEN 'SET DEFAULT' - WHEN 'N' THEN 'SET NULL' - WHEN 'R' THEN 'RESTRICT' - ELSE NULL - END AS on_update, - CASE dt.referential_action - WHEN 'C' THEN 'CASCADE' - WHEN 'D' THEN 'SET DEFAULT' - WHEN 'N' THEN 'SET NULL' - WHEN 'R' THEN 'RESTRICT' - ELSE NULL - END AS on_delete, - IF fk.check_on_commit = 'Y' - THEN 1 - ELSE NULL - ENDIF AS check_on_commit, -- check_on_commit flag - IF ftbl.clustered_index_id = idx.index_id - THEN 1 - ELSE NULL - ENDIF AS 'clustered', -- clustered flag - IF fk.match_type = 0 - THEN NULL - ELSE fk.match_type - ENDIF AS 'match', -- match option - IF pidx.max_key_distance = 1 - THEN 1 - ELSE NULL - ENDIF AS for_olap_workload -- for_olap_workload flag - FROM SYS.SYSFKEY AS fk - JOIN SYS.SYSIDX AS idx - ON fk.foreign_table_id = idx.table_id - AND fk.foreign_index_id = idx.index_id - JOIN SYS.SYSPHYSIDX pidx - ON idx.table_id = pidx.table_id - AND idx.phys_index_id = pidx.phys_index_id - JOIN SYS.SYSTAB AS ptbl - ON fk.primary_table_id = ptbl.table_id - JOIN SYS.SYSTAB AS ftbl - ON fk.foreign_table_id = ftbl.table_id - JOIN SYS.SYSIDXCOL AS idxcol - ON idx.table_id = idxcol.table_id - AND idx.index_id = idxcol.index_id - JOIN SYS.SYSTABCOL AS pcol - ON ptbl.table_id = pcol.table_id - AND idxcol.primary_column_id = pcol.column_id - JOIN SYS.SYSTABCOL AS fcol - ON ftbl.table_id = fcol.table_id - AND idxcol.column_id = fcol.column_id - LEFT JOIN SYS.SYSTRIGGER ut - ON fk.foreign_table_id = ut.foreign_table_id - AND fk.foreign_index_id = ut.foreign_key_id - AND ut.event = 'C' - LEFT JOIN SYS.SYSTRIGGER dt - ON fk.foreign_table_id = dt.foreign_table_id - AND fk.foreign_index_id = dt.foreign_key_id - AND dt.event = 'D' - WHERE ftbl.table_name = $table - AND ftbl.creator = USER_ID($user) - ORDER BY fk.foreign_index_id ASC, idxcol.sequence ASC"; + return sprintf( + <<<'SQL' +SELECT fcol.column_name AS local_column, + ptbl.table_name AS foreign_table, + pcol.column_name AS foreign_column, + idx.index_name, + IF fk.nulls = 'N' + THEN 1 + ELSE NULL + ENDIF AS notnull, + CASE ut.referential_action + WHEN 'C' THEN 'CASCADE' + WHEN 'D' THEN 'SET DEFAULT' + WHEN 'N' THEN 'SET NULL' + WHEN 'R' THEN 'RESTRICT' + ELSE NULL + END AS on_update, + CASE dt.referential_action + WHEN 'C' THEN 'CASCADE' + WHEN 'D' THEN 'SET DEFAULT' + WHEN 'N' THEN 'SET NULL' + WHEN 'R' THEN 'RESTRICT' + ELSE NULL + END AS on_delete, + IF fk.check_on_commit = 'Y' + THEN 1 + ELSE NULL + ENDIF AS check_on_commit, -- check_on_commit flag + IF ftbl.clustered_index_id = idx.index_id + THEN 1 + ELSE NULL + ENDIF AS 'clustered', -- clustered flag + IF fk.match_type = 0 + THEN NULL + ELSE fk.match_type + ENDIF AS 'match', -- match option + IF pidx.max_key_distance = 1 + THEN 1 + ELSE NULL + ENDIF AS for_olap_workload -- for_olap_workload flag +FROM SYS.SYSFKEY AS fk +JOIN SYS.SYSIDX AS idx +ON fk.foreign_table_id = idx.table_id +AND fk.foreign_index_id = idx.index_id +JOIN SYS.SYSPHYSIDX pidx +ON idx.table_id = pidx.table_id +AND idx.phys_index_id = pidx.phys_index_id +JOIN SYS.SYSTAB AS ptbl +ON fk.primary_table_id = ptbl.table_id +JOIN SYS.SYSTAB AS ftbl +ON fk.foreign_table_id = ftbl.table_id +JOIN SYS.SYSIDXCOL AS idxcol +ON idx.table_id = idxcol.table_id +AND idx.index_id = idxcol.index_id +JOIN SYS.SYSTABCOL AS pcol +ON ptbl.table_id = pcol.table_id +AND idxcol.primary_column_id = pcol.column_id +JOIN SYS.SYSTABCOL AS fcol +ON ftbl.table_id = fcol.table_id +AND idxcol.column_id = fcol.column_id +LEFT JOIN SYS.SYSTRIGGER ut +ON fk.foreign_table_id = ut.foreign_table_id +AND fk.foreign_index_id = ut.foreign_key_id +AND ut.event = 'C' +LEFT JOIN SYS.SYSTRIGGER dt +ON fk.foreign_table_id = dt.foreign_table_id +AND fk.foreign_index_id = dt.foreign_key_id +AND dt.event = 'D' +WHERE ftbl.table_name = %s +AND ftbl.creator = USER_ID(%s) +ORDER BY fk.foreign_index_id ASC, idxcol.sequence ASC +SQL + , + $table, + $user + ); } /** @@ -862,42 +888,49 @@ public function getListTableIndexesSQL($table, $currentDatabase = null) $table = $this->quoteStringLiteral($table); } - return "SELECT idx.index_name AS key_name, - IF idx.index_category = 1 - THEN 1 - ELSE 0 - ENDIF AS 'primary', - col.column_name, - IF idx.\"unique\" IN(1, 2, 5) - THEN 0 - ELSE 1 - ENDIF AS non_unique, - IF tbl.clustered_index_id = idx.index_id - THEN 1 - ELSE NULL - ENDIF AS 'clustered', -- clustered flag - IF idx.\"unique\" = 5 - THEN 1 - ELSE NULL - ENDIF AS with_nulls_not_distinct, -- with_nulls_not_distinct flag - IF pidx.max_key_distance = 1 - THEN 1 - ELSE NULL - ENDIF AS for_olap_workload -- for_olap_workload flag - FROM SYS.SYSIDX AS idx - JOIN SYS.SYSPHYSIDX pidx - ON idx.table_id = pidx.table_id - AND idx.phys_index_id = pidx.phys_index_id - JOIN SYS.SYSIDXCOL AS idxcol - ON idx.table_id = idxcol.table_id AND idx.index_id = idxcol.index_id - JOIN SYS.SYSTABCOL AS col - ON idxcol.table_id = col.table_id AND idxcol.column_id = col.column_id - JOIN SYS.SYSTAB AS tbl - ON idx.table_id = tbl.table_id - WHERE tbl.table_name = $table - AND tbl.creator = USER_ID($user) - AND idx.index_category != 2 -- exclude indexes implicitly created by foreign key constraints - ORDER BY idx.index_id ASC, idxcol.sequence ASC"; + return sprintf( + <<<'SQL' +SELECT idx.index_name AS key_name, + IF idx.index_category = 1 + THEN 1 + ELSE 0 + ENDIF AS 'primary', + col.column_name, + IF idx."unique" IN(1, 2, 5) + THEN 0 + ELSE 1 + ENDIF AS non_unique, + IF tbl.clustered_index_id = idx.index_id + THEN 1 + ELSE NULL + ENDIF AS 'clustered', -- clustered flag + IF idx."unique" = 5 + THEN 1 + ELSE NULL + ENDIF AS with_nulls_not_distinct, -- with_nulls_not_distinct flag + IF pidx.max_key_distance = 1 + THEN 1 + ELSE NULL + ENDIF AS for_olap_workload -- for_olap_workload flag +FROM SYS.SYSIDX AS idx +JOIN SYS.SYSPHYSIDX pidx +ON idx.table_id = pidx.table_id +AND idx.phys_index_id = pidx.phys_index_id +JOIN SYS.SYSIDXCOL AS idxcol +ON idx.table_id = idxcol.table_id AND idx.index_id = idxcol.index_id +JOIN SYS.SYSTABCOL AS col +ON idxcol.table_id = col.table_id AND idxcol.column_id = col.column_id +JOIN SYS.SYSTAB AS tbl +ON idx.table_id = tbl.table_id +WHERE tbl.table_name = %s +AND tbl.creator = USER_ID(%s) +AND idx.index_category != 2 -- exclude indexes implicitly created by foreign key constraints +ORDER BY idx.index_id ASC, idxcol.sequence ASC +SQL + , + $table, + $user + ); } /** @@ -984,7 +1017,7 @@ public function getName() * * @return string DBMS specific SQL code portion needed to set a primary key * - * @throws InvalidArgumentException if the given index is not a primary key. + * @throws InvalidArgumentException If the given index is not a primary key. */ public function getPrimaryKeyDeclarationSQL(Index $index, $name = null) { @@ -1106,7 +1139,7 @@ public function getTrimExpression($str, $pos = TrimMode::UNSPECIFIED, $char = fa } } - $pattern = "'%[^' + $char + ']%'"; + $pattern = "'%[^' + " . $char . " + ']%'"; switch ($pos) { case TrimMode::LEADING: @@ -1340,7 +1373,7 @@ protected function getBinaryTypeDeclarationSQLSnippet($length, $fixed) * * @return string * - * @throws InvalidArgumentException if the given table constraint type is not supported by this method. + * @throws InvalidArgumentException If the given table constraint type is not supported by this method. */ protected function getTableConstraintDeclarationSQL(Constraint $constraint, $name = null) { @@ -1458,9 +1491,9 @@ protected function initializeDoctrineTypeMappings() 'unsigned int' => 'integer', 'numeric' => 'decimal', 'smallint' => 'smallint', - 'unsigned smallint', 'smallint', + 'unsigned smallint' => 'smallint', 'tinyint' => 'smallint', - 'unsigned tinyint', 'smallint', + 'unsigned tinyint' => 'smallint', 'money' => 'decimal', 'smallmoney' => 'decimal', 'long varbit' => 'text', diff --git a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php index 12811fa9da7..353cfe0b2a9 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php @@ -225,10 +225,20 @@ public function getDropIndexSQL($index, $table = null) $table = $table->getQuotedName($this); } - return "IF EXISTS (SELECT * FROM sysobjects WHERE name = '$index') - ALTER TABLE " . $table . ' DROP CONSTRAINT ' . $index . ' - ELSE - DROP INDEX ' . $index . ' ON ' . $table; + return sprintf( + <<quoteStringLiteral($table); } - return "({$tableColumn} = {$table} AND {$schemaColumn} = {$schema})"; + return sprintf('(%s = %s AND %s = %s)', $tableColumn, $table, $schemaColumn, $schema); } /** @@ -1067,7 +1075,7 @@ public function getTrimExpression($str, $pos = TrimMode::UNSPECIFIED, $char = fa , reverse(stuff(reverse(@c), 1, patindex(@pat, reverse(@c)) - 1, null)) as trim_trailing , reverse(stuff(reverse(stuff(@c, 1, patindex(@pat, @c) - 1, null)), 1, patindex(@pat, reverse(stuff(@c, 1, patindex(@pat, @c) - 1, null))) - 1, null)) as trim_both; */ - $pattern = "'%[^' + $char + ']%'"; + $pattern = "'%[^' + " . $char . " + ']%'"; if ($pos === TrimMode::LEADING) { return 'stuff(' . $str . ', 1, patindex(' . $pattern . ', ' . $str . ') - 1, null)'; diff --git a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php index fab0410a19f..819421d3469 100644 --- a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php @@ -423,9 +423,11 @@ public function getClobTypeDeclarationSQL(array $field) public function getListTableConstraintsSQL($table) { $table = str_replace('.', '__', $table); - $table = $this->quoteStringLiteral($table); - return "SELECT sql FROM sqlite_master WHERE type='index' AND tbl_name = $table AND sql NOT NULL ORDER BY name"; + return sprintf( + "SELECT sql FROM sqlite_master WHERE type='index' AND tbl_name = %s AND sql NOT NULL ORDER BY name", + $this->quoteStringLiteral($table) + ); } /** @@ -434,9 +436,8 @@ public function getListTableConstraintsSQL($table) public function getListTableColumnsSQL($table, $currentDatabase = null) { $table = str_replace('.', '__', $table); - $table = $this->quoteStringLiteral($table); - return "PRAGMA table_info($table)"; + return sprintf('PRAGMA table_info(%s)', $this->quoteStringLiteral($table)); } /** @@ -445,9 +446,8 @@ public function getListTableColumnsSQL($table, $currentDatabase = null) public function getListTableIndexesSQL($table, $currentDatabase = null) { $table = str_replace('.', '__', $table); - $table = $this->quoteStringLiteral($table); - return "PRAGMA index_list($table)"; + return sprintf('PRAGMA index_list(%s)', $this->quoteStringLiteral($table)); } /** @@ -797,9 +797,8 @@ public function getCreateTableSQL(Table $table, $createFlags = null) public function getListTableForeignKeysSQL($table, $database = null) { $table = str_replace('.', '__', $table); - $table = $this->quoteStringLiteral($table); - return "PRAGMA foreign_key_list($table)"; + return sprintf('PRAGMA foreign_key_list(%s)', $this->quoteStringLiteral($table)); } /** @@ -998,7 +997,7 @@ private function getSimpleAlterTableSQL(TableDiff $diff) } /** - * @return array + * @return string[] */ private function getColumnNamesInAlteredTable(TableDiff $diff) { @@ -1097,7 +1096,7 @@ private function getIndexesInAlteredTable(TableDiff $diff) } /** - * @return array + * @return ForeignKeyConstraint[] */ private function getForeignKeysInAlteredTable(TableDiff $diff) { @@ -1149,7 +1148,7 @@ private function getForeignKeysInAlteredTable(TableDiff $diff) } /** - * @return array + * @return Index[] */ private function getPrimaryIndexInAlteredTable(TableDiff $diff) { diff --git a/lib/Doctrine/DBAL/Portability/Statement.php b/lib/Doctrine/DBAL/Portability/Statement.php index bf137d1eae1..b7de39369c9 100644 --- a/lib/Doctrine/DBAL/Portability/Statement.php +++ b/lib/Doctrine/DBAL/Portability/Statement.php @@ -181,7 +181,7 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n * @param int $iterateRow * @param bool $fixCase * - * @return array + * @return mixed */ protected function fixRow($row, $iterateRow, $fixCase) { diff --git a/lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php b/lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php index 6f2c06621f8..3f4086e5db2 100644 --- a/lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php +++ b/lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php @@ -33,13 +33,13 @@ class CompositeExpression implements Countable /** * Each expression part of the composite expression. * - * @var array + * @var self[]|string[] */ private $parts = []; /** - * @param string $type Instance type of composite expression. - * @param array $parts Composition of expressions to be joined on composite expression. + * @param string $type Instance type of composite expression. + * @param self[]|string[] $parts Composition of expressions to be joined on composite expression. */ public function __construct($type, array $parts = []) { @@ -51,7 +51,7 @@ public function __construct($type, array $parts = []) /** * Adds multiple parts to composite expression. * - * @param array $parts + * @param self[]|string[] $parts * * @return \Doctrine\DBAL\Query\Expression\CompositeExpression */ diff --git a/lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php b/lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php index 19742c9fa04..074ba4aa33f 100644 --- a/lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php +++ b/lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php @@ -262,8 +262,8 @@ public function notLike($x, $y/*, ?string $escapeChar = null */) /** * Creates a IN () comparison expression with the given arguments. * - * @param string $x The field in string format to be inspected by IN() comparison. - * @param string|array $y The placeholder or the array of values to be used by IN() comparison. + * @param string $x The field in string format to be inspected by IN() comparison. + * @param string|string[] $y The placeholder or the array of values to be used by IN() comparison. * * @return string */ @@ -275,8 +275,8 @@ public function in($x, $y) /** * Creates a NOT IN () comparison expression with the given arguments. * - * @param string $x The field in string format to be inspected by NOT IN() comparison. - * @param string|array $y The placeholder or the array of values to be used by NOT IN() comparison. + * @param string $x The field in string format to be inspected by NOT IN() comparison. + * @param string|string[] $y The placeholder or the array of values to be used by NOT IN() comparison. * * @return string */ diff --git a/lib/Doctrine/DBAL/Query/QueryBuilder.php b/lib/Doctrine/DBAL/Query/QueryBuilder.php index e8efa12b1e0..9349330e947 100644 --- a/lib/Doctrine/DBAL/Query/QueryBuilder.php +++ b/lib/Doctrine/DBAL/Query/QueryBuilder.php @@ -54,7 +54,11 @@ class QueryBuilder */ private $connection; - /** @var array The array of SQL parts collected. */ + /** + * The array of SQL parts collected. + * + * @var mixed[] + */ private $sqlParts = [ 'select' => [], 'from' => [], @@ -77,14 +81,14 @@ class QueryBuilder /** * The query parameters. * - * @var array + * @var mixed[] */ private $params = []; /** * The parameter type map of this query. * - * @var array + * @var int[]|string[] */ private $paramTypes = []; @@ -285,8 +289,8 @@ public function setParameter($key, $value, $type = null) * )); * * - * @param array $params The query parameters to set. - * @param array $types The query parameters types to set. + * @param mixed[] $params The query parameters to set. + * @param int[]|string[] $types The query parameters types to set. * * @return $this This QueryBuilder instance. */ @@ -301,7 +305,7 @@ public function setParameters(array $params, array $types = []) /** * Gets all defined query parameters for the query being constructed indexed by parameter index or name. * - * @return array The currently defined query parameters indexed by parameter index or name. + * @return mixed[] The currently defined query parameters indexed by parameter index or name. */ public function getParameters() { @@ -323,7 +327,7 @@ public function getParameter($key) /** * Gets all defined query parameter types for the query being constructed indexed by parameter index or name. * - * @return array The currently defined query parameter types indexed by parameter index or name. + * @return int[]|string[] The currently defined query parameter types indexed by parameter index or name. */ public function getParameterTypes() { @@ -582,9 +586,7 @@ public function insert($insert = null) return $this; } - return $this->add('from', [ - 'table' => $insert, - ]); + return $this->add('from', ['table' => $insert]); } /** @@ -934,7 +936,7 @@ public function setValue($column, $value) * ); * * - * @param array $values The values to specify for the insert query indexed by column names. + * @param mixed[] $values The values to specify for the insert query indexed by column names. * * @return $this This QueryBuilder instance. */ @@ -1048,7 +1050,7 @@ public function getQueryPart($queryPartName) /** * Gets all query parts. * - * @return array + * @return mixed[] */ public function getQueryParts() { @@ -1058,7 +1060,7 @@ public function getQueryParts() /** * Resets SQL parts. * - * @param array|null $queryPartNames + * @param string[]|null $queryPartNames * * @return $this This QueryBuilder instance. */ @@ -1147,7 +1149,7 @@ private function getFromClauses() } /** - * @param array $knownAliases + * @param string[] $knownAliases * * @throws QueryException */ @@ -1285,8 +1287,8 @@ public function createPositionalParameter($value, $type = ParameterType::STRING) } /** - * @param string $fromAlias - * @param array $knownAliases + * @param string $fromAlias + * @param string[] $knownAliases * * @return string * diff --git a/lib/Doctrine/DBAL/Query/QueryException.php b/lib/Doctrine/DBAL/Query/QueryException.php index 266852c7da0..3fcb3b480ec 100644 --- a/lib/Doctrine/DBAL/Query/QueryException.php +++ b/lib/Doctrine/DBAL/Query/QueryException.php @@ -8,8 +8,8 @@ class QueryException extends DBALException { /** - * @param string $alias - * @param array $registeredAliases + * @param string $alias + * @param string[] $registeredAliases * * @return \Doctrine\DBAL\Query\QueryException */ @@ -21,8 +21,8 @@ public static function unknownAlias($alias, $registeredAliases) } /** - * @param string $alias - * @param array $registeredAliases + * @param string $alias + * @param string[] $registeredAliases * * @return \Doctrine\DBAL\Query\QueryException */ diff --git a/lib/Doctrine/DBAL/SQLParserUtils.php b/lib/Doctrine/DBAL/SQLParserUtils.php index 5e8196b0b0b..307336c4ec7 100644 --- a/lib/Doctrine/DBAL/SQLParserUtils.php +++ b/lib/Doctrine/DBAL/SQLParserUtils.php @@ -43,7 +43,7 @@ class SQLParserUtils * @param string $statement * @param bool $isPositional * - * @return array + * @return int[] */ public static function getPlaceholderPositions($statement, $isPositional = true) { @@ -56,7 +56,7 @@ public static function getPlaceholderPositions($statement, $isPositional = true) $paramMap = []; foreach (self::getUnquotedStatementFragments($statement) as $fragment) { - preg_match_all("/$token/", $fragment[0], $matches, PREG_OFFSET_CAPTURE); + preg_match_all('/' . $token . '/', $fragment[0], $matches, PREG_OFFSET_CAPTURE); foreach ($matches[0] as $placeholder) { if ($isPositional) { $paramMap[] = $placeholder[1] + $fragment[1]; @@ -73,11 +73,11 @@ public static function getPlaceholderPositions($statement, $isPositional = true) /** * For a positional query this method can rewrite the sql statement with regard to array parameters. * - * @param string $query The SQL query to execute. - * @param array $params The parameters to bind to the query. - * @param array $types The types the previous parameters are in. + * @param string $query The SQL query to execute. + * @param mixed[] $params The parameters to bind to the query. + * @param int[]|string[] $types The types the previous parameters are in. * - * @return array + * @return mixed[] * * @throws SQLParserUtilsException */ @@ -197,7 +197,7 @@ public static function expandListParameters($query, $params, $types) * * @param string $statement * - * @return array + * @return mixed[][] */ private static function getUnquotedStatementFragments($statement) { @@ -205,14 +205,14 @@ private static function getUnquotedStatementFragments($statement) self::ESCAPED_DOUBLE_QUOTED_TEXT . '|' . self::ESCAPED_BACKTICK_QUOTED_TEXT . '|' . self::ESCAPED_BRACKET_QUOTED_TEXT; - preg_match_all("/([^'\"`\[]+)(?:$literal)?/s", $statement, $fragments, PREG_OFFSET_CAPTURE); + preg_match_all('/([^\'"`\[]+)(?:' . $literal . ')?/s', $statement, $fragments, PREG_OFFSET_CAPTURE); return $fragments[1]; } /** * @param string $paramName The name of the parameter (without a colon in front) - * @param array $paramsOrTypes A hash of parameters or types + * @param mixed $paramsOrTypes A hash of parameters or types * @param bool $isParam * @param mixed $defaultValue An optional default value. If omitted, an exception is thrown * diff --git a/lib/Doctrine/DBAL/Schema/AbstractAsset.php b/lib/Doctrine/DBAL/Schema/AbstractAsset.php index b97d0371c2c..9a7fd7dd4d5 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractAsset.php +++ b/lib/Doctrine/DBAL/Schema/AbstractAsset.php @@ -195,9 +195,9 @@ public function getQuotedName(AbstractPlatform $platform) * however building idents automatically for foreign keys, composite keys or such can easily create * very long names. * - * @param array $columnNames - * @param string $prefix - * @param int $maxSize + * @param string[] $columnNames + * @param string $prefix + * @param int $maxSize * * @return string */ diff --git a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php index becf2e4bf82..cacb0acddd5 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php @@ -90,7 +90,7 @@ public function tryMethod() /** * Lists the available databases for this connection. * - * @return array + * @return string[] */ public function listDatabases() { @@ -104,7 +104,7 @@ public function listDatabases() /** * Returns a list of all namespaces in the current database. * - * @return array + * @return string[] */ public function listNamespaceNames() { @@ -183,7 +183,7 @@ public function listTableIndexes($table) /** * Returns true if all the given tables exist. * - * @param array $tableNames + * @param string[] $tableNames * * @return bool */ @@ -197,7 +197,7 @@ public function tablesExist($tableNames) /** * Returns a list of all tables in the current database. * - * @return array + * @return string[] */ public function listTableNames() { @@ -213,9 +213,9 @@ public function listTableNames() * Filters asset names if they are configured to return only a subset of all * the found elements. * - * @param array $assetNames + * @param mixed[] $assetNames * - * @return array + * @return mixed[] */ protected function filterAssetNames($assetNames) { @@ -621,15 +621,17 @@ public function renameTable($name, $newName) */ /** - * @param array $databases + * @param mixed[] $databases * - * @return array + * @return string[] */ protected function _getPortableDatabasesList($databases) { $list = []; foreach ($databases as $value) { - if (! $value = $this->_getPortableDatabaseDefinition($value)) { + $value = $this->_getPortableDatabaseDefinition($value); + + if (! $value) { continue; } @@ -642,9 +644,9 @@ protected function _getPortableDatabasesList($databases) /** * Converts a list of namespace names from the native DBMS data definition to a portable Doctrine definition. * - * @param array $namespaces The list of namespace names in the native DBMS data definition. + * @param mixed[][] $namespaces The list of namespace names in the native DBMS data definition. * - * @return array + * @return string[] */ protected function getPortableNamespacesList(array $namespaces) { @@ -658,7 +660,7 @@ protected function getPortableNamespacesList(array $namespaces) } /** - * @param array $database + * @param mixed $database * * @return mixed */ @@ -670,7 +672,7 @@ protected function _getPortableDatabaseDefinition($database) /** * Converts a namespace definition from the native DBMS data definition to a portable Doctrine definition. * - * @param array $namespace The native DBMS namespace definition. + * @param mixed[] $namespace The native DBMS namespace definition. * * @return mixed */ @@ -680,15 +682,17 @@ protected function getPortableNamespaceDefinition(array $namespace) } /** - * @param array $functions + * @param mixed[][] $functions * - * @return array + * @return mixed[][] */ protected function _getPortableFunctionsList($functions) { $list = []; foreach ($functions as $value) { - if (! $value = $this->_getPortableFunctionDefinition($value)) { + $value = $this->_getPortableFunctionDefinition($value); + + if (! $value) { continue; } @@ -699,7 +703,7 @@ protected function _getPortableFunctionsList($functions) } /** - * @param array $function + * @param mixed[] $function * * @return mixed */ @@ -709,15 +713,17 @@ protected function _getPortableFunctionDefinition($function) } /** - * @param array $triggers + * @param mixed[][] $triggers * - * @return array + * @return mixed[][] */ protected function _getPortableTriggersList($triggers) { $list = []; foreach ($triggers as $value) { - if (! $value = $this->_getPortableTriggerDefinition($value)) { + $value = $this->_getPortableTriggerDefinition($value); + + if (! $value) { continue; } @@ -728,7 +734,7 @@ protected function _getPortableTriggersList($triggers) } /** - * @param array $trigger + * @param mixed[] $trigger * * @return mixed */ @@ -738,15 +744,17 @@ protected function _getPortableTriggerDefinition($trigger) } /** - * @param array $sequences + * @param mixed[][] $sequences * - * @return array + * @return Sequence[] */ protected function _getPortableSequencesList($sequences) { $list = []; foreach ($sequences as $value) { - if (! $value = $this->_getPortableSequenceDefinition($value)) { + $value = $this->_getPortableSequenceDefinition($value); + + if (! $value) { continue; } @@ -757,7 +765,7 @@ protected function _getPortableSequencesList($sequences) } /** - * @param array $sequence + * @param mixed[] $sequence * * @return Sequence * @@ -773,11 +781,11 @@ protected function _getPortableSequenceDefinition($sequence) * * The name of the created column instance however is kept in its case. * - * @param string $table The name of the table. - * @param string $database - * @param array $tableColumns + * @param string $table The name of the table. + * @param string $database + * @param mixed[][] $tableColumns * - * @return array + * @return Column[] */ protected function _getPortableTableColumnList($table, $database, $tableColumns) { @@ -814,7 +822,7 @@ protected function _getPortableTableColumnList($table, $database, $tableColumns) /** * Gets Table Column Definition. * - * @param array $tableColumn + * @param mixed[] $tableColumn * * @return Column */ @@ -823,10 +831,10 @@ abstract protected function _getPortableTableColumnDefinition($tableColumn); /** * Aggregates and groups the index results according to the required data result. * - * @param array $tableIndexRows + * @param mixed[][] $tableIndexRows * @param string|null $tableName * - * @return array + * @return Index[] */ protected function _getPortableTableIndexesList($tableIndexRows, $tableName = null) { @@ -882,15 +890,17 @@ protected function _getPortableTableIndexesList($tableIndexRows, $tableName = nu } /** - * @param array $tables + * @param mixed[][] $tables * - * @return array + * @return string[] */ protected function _getPortableTablesList($tables) { $list = []; foreach ($tables as $value) { - if (! $value = $this->_getPortableTableDefinition($value)) { + $value = $this->_getPortableTableDefinition($value); + + if (! $value) { continue; } @@ -901,9 +911,9 @@ protected function _getPortableTablesList($tables) } /** - * @param array $table + * @param mixed $table * - * @return array + * @return string */ protected function _getPortableTableDefinition($table) { @@ -911,15 +921,17 @@ protected function _getPortableTableDefinition($table) } /** - * @param array $users + * @param mixed[][] $users * - * @return array + * @return string[][] */ protected function _getPortableUsersList($users) { $list = []; foreach ($users as $value) { - if (! $value = $this->_getPortableUserDefinition($value)) { + $value = $this->_getPortableUserDefinition($value); + + if (! $value) { continue; } @@ -930,9 +942,9 @@ protected function _getPortableUsersList($users) } /** - * @param array $user + * @param mixed[] $user * - * @return mixed + * @return mixed[] */ protected function _getPortableUserDefinition($user) { @@ -940,15 +952,17 @@ protected function _getPortableUserDefinition($user) } /** - * @param array $views + * @param mixed[][] $views * - * @return array + * @return View[] */ protected function _getPortableViewsList($views) { $list = []; foreach ($views as $value) { - if (! $view = $this->_getPortableViewDefinition($value)) { + $view = $this->_getPortableViewDefinition($value); + + if (! $view) { continue; } @@ -960,9 +974,9 @@ protected function _getPortableViewsList($views) } /** - * @param array $view + * @param mixed[] $view * - * @return mixed + * @return View|false */ protected function _getPortableViewDefinition($view) { @@ -970,15 +984,17 @@ protected function _getPortableViewDefinition($view) } /** - * @param array $tableForeignKeys + * @param mixed[][] $tableForeignKeys * - * @return array + * @return ForeignKeyConstraint[] */ protected function _getPortableTableForeignKeysList($tableForeignKeys) { $list = []; foreach ($tableForeignKeys as $value) { - if (! $value = $this->_getPortableTableForeignKeyDefinition($value)) { + $value = $this->_getPortableTableForeignKeyDefinition($value); + + if (! $value) { continue; } @@ -989,9 +1005,9 @@ protected function _getPortableTableForeignKeysList($tableForeignKeys) } /** - * @param array $tableForeignKey + * @param mixed $tableForeignKey * - * @return mixed + * @return ForeignKeyConstraint */ protected function _getPortableTableForeignKeyDefinition($tableForeignKey) { @@ -999,7 +1015,7 @@ protected function _getPortableTableForeignKeyDefinition($tableForeignKey) } /** - * @param array|string $sql + * @param string[]|string $sql * * @return void */ @@ -1071,7 +1087,7 @@ public function createSchemaConfig() * For databases that don't support subschema/namespaces this method * returns the name of the currently connected database. * - * @return array + * @return string[] */ public function getSchemaSearchPaths() { diff --git a/lib/Doctrine/DBAL/Schema/Column.php b/lib/Doctrine/DBAL/Schema/Column.php index f79310bfee1..642f36b2227 100644 --- a/lib/Doctrine/DBAL/Schema/Column.php +++ b/lib/Doctrine/DBAL/Schema/Column.php @@ -44,7 +44,7 @@ class Column extends AbstractAsset /** @var bool */ protected $_autoincrement = false; - /** @var array */ + /** @var mixed[] */ protected $_platformOptions = []; /** @var string|null */ @@ -53,14 +53,14 @@ class Column extends AbstractAsset /** @var string|null */ protected $_comment = null; - /** @var array */ + /** @var mixed[] */ protected $_customSchemaOptions = []; /** * Creates a new Column. * - * @param string $columnName - * @param array $options + * @param string $columnName + * @param mixed[] $options */ public function __construct($columnName, Type $type, array $options = []) { @@ -70,7 +70,7 @@ public function __construct($columnName, Type $type, array $options = []) } /** - * @param array $options + * @param mixed[] $options * * @return Column */ @@ -201,7 +201,7 @@ public function setDefault($default) } /** - * @param array $platformOptions + * @param mixed[] $platformOptions * * @return Column */ @@ -302,7 +302,7 @@ public function getDefault() } /** - * @return array + * @return mixed[] */ public function getPlatformOptions() { @@ -411,7 +411,7 @@ public function getCustomSchemaOption($name) } /** - * @param array $customSchemaOptions + * @param mixed[] $customSchemaOptions * * @return Column */ @@ -423,7 +423,7 @@ public function setCustomSchemaOptions(array $customSchemaOptions) } /** - * @return array + * @return mixed[] */ public function getCustomSchemaOptions() { @@ -431,7 +431,7 @@ public function getCustomSchemaOptions() } /** - * @return array + * @return mixed[] */ public function toArray() { diff --git a/lib/Doctrine/DBAL/Schema/ColumnDiff.php b/lib/Doctrine/DBAL/Schema/ColumnDiff.php index 0204e43db4c..ded22d1af62 100644 --- a/lib/Doctrine/DBAL/Schema/ColumnDiff.php +++ b/lib/Doctrine/DBAL/Schema/ColumnDiff.php @@ -17,7 +17,7 @@ class ColumnDiff /** @var Column */ public $column; - /** @var array */ + /** @var string[] */ public $changedProperties = []; /** @var Column */ diff --git a/lib/Doctrine/DBAL/Schema/Comparator.php b/lib/Doctrine/DBAL/Schema/Comparator.php index 8297e05ccaa..ed339e0a69d 100644 --- a/lib/Doctrine/DBAL/Schema/Comparator.php +++ b/lib/Doctrine/DBAL/Schema/Comparator.php @@ -410,7 +410,7 @@ public function diffForeignKey(ForeignKeyConstraint $key1, ForeignKeyConstraint * If there are differences this method returns $field2, otherwise the * boolean false. * - * @return array + * @return string[] */ public function diffColumn(Column $column1, Column $column2) { diff --git a/lib/Doctrine/DBAL/Schema/Constraint.php b/lib/Doctrine/DBAL/Schema/Constraint.php index 9265e9f2cb6..af0d443ceda 100644 --- a/lib/Doctrine/DBAL/Schema/Constraint.php +++ b/lib/Doctrine/DBAL/Schema/Constraint.php @@ -25,7 +25,7 @@ public function getQuotedName(AbstractPlatform $platform); * Returns the names of the referencing table columns * the constraint is associated with. * - * @return array + * @return string[] */ public function getColumns(); @@ -39,7 +39,7 @@ public function getColumns(); * * @param AbstractPlatform $platform The platform to use for quotation. * - * @return array + * @return string[] */ public function getQuotedColumns(AbstractPlatform $platform); } diff --git a/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php b/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php index 7f07b10551c..02e83b8a656 100644 --- a/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php +++ b/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php @@ -49,17 +49,21 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint */ protected $_foreignColumnNames; - /** @var array Options associated with the foreign key constraint. */ + /** + * Options associated with the foreign key constraint. + * + * @var mixed[] + */ protected $_options; /** * Initializes the foreign key constraint. * - * @param array $localColumnNames Names of the referencing table columns. + * @param string[] $localColumnNames Names of the referencing table columns. * @param Table|string $foreignTableName Referenced table. - * @param array $foreignColumnNames Names of the referenced table columns. + * @param string[] $foreignColumnNames Names of the referenced table columns. * @param string|null $name Name of the foreign key constraint. - * @param array $options Options associated with the foreign key constraint. + * @param mixed[] $options Options associated with the foreign key constraint. */ public function __construct(array $localColumnNames, $foreignTableName, array $foreignColumnNames, $name = null, array $options = []) { @@ -119,7 +123,7 @@ public function getLocalTable() * Returns the names of the referencing table columns * the foreign key constraint is associated with. * - * @return array + * @return string[] */ public function getLocalColumns() { @@ -136,7 +140,7 @@ public function getLocalColumns() * * @param AbstractPlatform $platform The platform to use for quotation. * - * @return array + * @return string[] */ public function getQuotedLocalColumns(AbstractPlatform $platform) { @@ -152,7 +156,7 @@ public function getQuotedLocalColumns(AbstractPlatform $platform) /** * Returns unquoted representation of local table column names for comparison with other FK * - * @return array + * @return string[] */ public function getUnquotedLocalColumns() { @@ -162,7 +166,7 @@ public function getUnquotedLocalColumns() /** * Returns unquoted representation of foreign table column names for comparison with other FK * - * @return array + * @return string[] */ public function getUnquotedForeignColumns() { @@ -191,7 +195,7 @@ public function getColumns() * * @param AbstractPlatform $platform The platform to use for quotation. * - * @return array + * @return string[] */ public function getQuotedColumns(AbstractPlatform $platform) { @@ -242,7 +246,7 @@ public function getQuotedForeignTableName(AbstractPlatform $platform) * Returns the names of the referenced table columns * the foreign key constraint is associated with. * - * @return array + * @return string[] */ public function getForeignColumns() { @@ -259,7 +263,7 @@ public function getForeignColumns() * * @param AbstractPlatform $platform The platform to use for quotation. * - * @return array + * @return string[] */ public function getQuotedForeignColumns(AbstractPlatform $platform) { @@ -300,7 +304,7 @@ public function getOption($name) /** * Returns the options associated with the foreign key constraint. * - * @return array + * @return mixed[] */ public function getOptions() { diff --git a/lib/Doctrine/DBAL/Schema/Index.php b/lib/Doctrine/DBAL/Schema/Index.php index 52f5a29b6ad..cc6bce37a13 100644 --- a/lib/Doctrine/DBAL/Schema/Index.php +++ b/lib/Doctrine/DBAL/Schema/Index.php @@ -31,7 +31,7 @@ class Index extends AbstractAsset implements Constraint * Platform specific flags for indexes. * array($flagName => true) * - * @var array + * @var true[] */ protected $_flags = []; @@ -39,7 +39,7 @@ class Index extends AbstractAsset implements Constraint * Platform specific options * * @todo $_flags should eventually be refactored into options - * @var array + * @var mixed[] */ private $options = []; @@ -49,7 +49,7 @@ class Index extends AbstractAsset implements Constraint * @param bool $isUnique * @param bool $isPrimary * @param string[] $flags - * @param array $options + * @param mixed[] $options */ public function __construct($indexName, array $columns, $isUnique = false, $isPrimary = false, array $flags = [], array $options = []) { @@ -157,7 +157,7 @@ public function hasColumnAtPosition($columnName, $pos = 0) /** * Checks if this index exactly spans the given column names in the correct order. * - * @param array $columnNames + * @param string[] $columnNames * * @return bool */ @@ -304,7 +304,7 @@ public function getOption($name) } /** - * @return array + * @return mixed[] */ public function getOptions() { diff --git a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php index 8ab1cf908b0..168e74ea87f 100644 --- a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php @@ -14,10 +14,11 @@ use function array_shift; use function assert; use function explode; +use function implode; use function in_array; -use function join; use function preg_match; use function preg_replace; +use function sprintf; use function str_replace; use function stripos; use function strlen; @@ -30,13 +31,13 @@ */ class PostgreSqlSchemaManager extends AbstractSchemaManager { - /** @var array */ + /** @var string[] */ private $existingSchemaPaths; /** * Gets all the existing schema names. * - * @return array + * @return string[] */ public function getSchemaNames() { @@ -50,7 +51,7 @@ public function getSchemaNames() * * This is a PostgreSQL only function. * - * @return array + * @return string[] */ public function getSchemaSearchPaths() { @@ -69,7 +70,7 @@ public function getSchemaSearchPaths() * * This is a PostgreSQL only function. * - * @return array + * @return string[] */ public function getExistingSchemaSearchPaths() { @@ -213,9 +214,11 @@ protected function _getPortableTableIndexesList($tableIndexes, $tableName = null $buffer = []; foreach ($tableIndexes as $row) { $colNumbers = array_map('intval', explode(' ', $row['indkey'])); - $colNumbersSql = 'IN (' . join(' ,', $colNumbers) . ' )'; - $columnNameSql = "SELECT attnum, attname FROM pg_attribute - WHERE attrelid={$row['indrelid']} AND attnum $colNumbersSql ORDER BY attnum ASC;"; + $columnNameSql = sprintf( + 'SELECT attnum, attname FROM pg_attribute WHERE attrelid=%d AND attnum IN (%s) ORDER BY attnum ASC', + $row['indrelid'], + implode(' ,', $colNumbers) + ); $stmt = $this->_conn->executeQuery($columnNameSql); $indexColumns = $stmt->fetchAll(); diff --git a/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php b/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php index e6ec0d0f535..6cd82b2ffaf 100644 --- a/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php @@ -254,7 +254,13 @@ public function alterTable(TableDiff $tableDiff) foreach ($tableDiff->removedColumns as $col) { $columnConstraintSql = $this->getColumnConstraintSQL($tableDiff->name, $col->getName()); foreach ($this->_conn->fetchAll($columnConstraintSql) as $constraint) { - $this->_conn->exec("ALTER TABLE $tableDiff->name DROP CONSTRAINT " . $constraint['Name']); + $this->_conn->exec( + sprintf( + 'ALTER TABLE %s DROP CONSTRAINT %s', + $tableDiff->name, + $constraint['Name'] + ) + ); } } } diff --git a/lib/Doctrine/DBAL/Schema/Schema.php b/lib/Doctrine/DBAL/Schema/Schema.php index 7f3fe2304ff..c0d6601cb67 100644 --- a/lib/Doctrine/DBAL/Schema/Schema.php +++ b/lib/Doctrine/DBAL/Schema/Schema.php @@ -42,7 +42,7 @@ class Schema extends AbstractAsset /** * The namespaces in this schema. * - * @var array + * @var string[] */ private $namespaces = []; @@ -58,7 +58,7 @@ class Schema extends AbstractAsset /** * @param Table[] $tables * @param Sequence[] $sequences - * @param array $namespaces + * @param string[] $namespaces */ public function __construct( array $tables = [], @@ -139,7 +139,7 @@ protected function _addSequence(Sequence $sequence) /** * Returns the namespaces of this schema. * - * @return array A list of namespace names. + * @return string[] A list of namespace names. */ public function getNamespaces() { @@ -236,7 +236,7 @@ public function hasTable($tableName) /** * Gets all table names, prefixed with a schema name, even the default one if present. * - * @return array + * @return string[] */ public function getTableNames() { @@ -389,7 +389,7 @@ public function dropSequence($sequenceName) /** * Returns an array of necessary SQL queries to create the schema on the given platform. * - * @return array + * @return string[] */ public function toSql(AbstractPlatform $platform) { @@ -402,7 +402,7 @@ public function toSql(AbstractPlatform $platform) /** * Return an array of necessary SQL queries to drop the schema on the given platform. * - * @return array + * @return string[] */ public function toDropSql(AbstractPlatform $platform) { @@ -413,7 +413,7 @@ public function toDropSql(AbstractPlatform $platform) } /** - * @return array + * @return string[] */ public function getMigrateToSql(Schema $toSchema, AbstractPlatform $platform) { @@ -424,7 +424,7 @@ public function getMigrateToSql(Schema $toSchema, AbstractPlatform $platform) } /** - * @return array + * @return string[] */ public function getMigrateFromSql(Schema $fromSchema, AbstractPlatform $platform) { diff --git a/lib/Doctrine/DBAL/Schema/SchemaConfig.php b/lib/Doctrine/DBAL/Schema/SchemaConfig.php index de3bae5d5e5..3e15efb4c9f 100644 --- a/lib/Doctrine/DBAL/Schema/SchemaConfig.php +++ b/lib/Doctrine/DBAL/Schema/SchemaConfig.php @@ -18,7 +18,7 @@ class SchemaConfig /** @var string */ protected $name; - /** @var array */ + /** @var mixed[] */ protected $defaultTableOptions = []; /** @@ -83,7 +83,7 @@ public function setName($name) * Gets the default options that are passed to Table instances created with * Schema#createTable(). * - * @return array + * @return mixed[] */ public function getDefaultTableOptions() { @@ -91,7 +91,7 @@ public function getDefaultTableOptions() } /** - * @param array $defaultTableOptions + * @param mixed[] $defaultTableOptions * * @return void */ diff --git a/lib/Doctrine/DBAL/Schema/SchemaDiff.php b/lib/Doctrine/DBAL/Schema/SchemaDiff.php index f1102bd4e55..e39a85bf943 100644 --- a/lib/Doctrine/DBAL/Schema/SchemaDiff.php +++ b/lib/Doctrine/DBAL/Schema/SchemaDiff.php @@ -86,7 +86,7 @@ public function __construct($newTables = [], $changedTables = [], $removedTables * * This way it is ensured that assets are deleted which might not be relevant to the metadata schema at all. * - * @return array + * @return string[] */ public function toSaveSql(AbstractPlatform $platform) { @@ -94,7 +94,7 @@ public function toSaveSql(AbstractPlatform $platform) } /** - * @return array + * @return string[] */ public function toSql(AbstractPlatform $platform) { @@ -104,7 +104,7 @@ public function toSql(AbstractPlatform $platform) /** * @param bool $saveMode * - * @return array + * @return string[] */ protected function _toSql(AbstractPlatform $platform, $saveMode = false) { diff --git a/lib/Doctrine/DBAL/Schema/SchemaException.php b/lib/Doctrine/DBAL/Schema/SchemaException.php index afc332ad5c2..213d218475b 100644 --- a/lib/Doctrine/DBAL/Schema/SchemaException.php +++ b/lib/Doctrine/DBAL/Schema/SchemaException.php @@ -37,7 +37,10 @@ public static function tableDoesNotExist($tableName) */ public static function indexNameInvalid($indexName) { - return new self("Invalid index-name $indexName given, has to be [a-zA-Z0-9_]", self::INDEX_INVALID_NAME); + return new self( + sprintf('Invalid index-name %s given, has to be [a-zA-Z0-9_]', $indexName), + self::INDEX_INVALID_NAME + ); } /** @@ -48,7 +51,10 @@ public static function indexNameInvalid($indexName) */ public static function indexDoesNotExist($indexName, $table) { - return new self("Index '$indexName' does not exist on table '$table'.", self::INDEX_DOESNT_EXIST); + return new self( + sprintf("Index '%s' does not exist on table '%s'.", $indexName, $table), + self::INDEX_DOESNT_EXIST + ); } /** @@ -59,7 +65,10 @@ public static function indexDoesNotExist($indexName, $table) */ public static function indexAlreadyExists($indexName, $table) { - return new self("An index with name '$indexName' was already defined on table '$table'.", self::INDEX_ALREADY_EXISTS); + return new self( + sprintf("An index with name '%s' was already defined on table '%s'.", $indexName, $table), + self::INDEX_ALREADY_EXISTS + ); } /** @@ -70,7 +79,10 @@ public static function indexAlreadyExists($indexName, $table) */ public static function columnDoesNotExist($columnName, $table) { - return new self("There is no column with name '$columnName' on table '$table'.", self::COLUMN_DOESNT_EXIST); + return new self( + sprintf("There is no column with name '%s' on table '%s'.", $columnName, $table), + self::COLUMN_DOESNT_EXIST + ); } /** @@ -138,7 +150,10 @@ public static function sequenceDoesNotExist($sequenceName) */ public static function foreignKeyDoesNotExist($fkName, $table) { - return new self("There exists no foreign key with the name '$fkName' on table '$table'.", self::FOREIGNKEY_DOESNT_EXIST); + return new self( + sprintf("There exists no foreign key with the name '%s' on table '%s'.", $fkName, $table), + self::FOREIGNKEY_DOESNT_EXIST + ); } /** @@ -161,6 +176,8 @@ public static function namedForeignKeyRequired(Table $localTable, ForeignKeyCons */ public static function alterTableChangeNotSupported($changeName) { - return new self("Alter table change not supported, given '$changeName'"); + return new self( + sprintf("Alter table change not supported, given '%s'", $changeName) + ); } } diff --git a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php index b42b0e0d4e5..460def2e4b1 100644 --- a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php @@ -117,7 +117,12 @@ public function listTableForeignKeys($table, $database = null) $tableForeignKeys = $this->_conn->fetchAll($sql); if (! empty($tableForeignKeys)) { - $createSql = $this->_conn->fetchAll("SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE type = 'table' AND name = '$table'"); + $createSql = $this->_conn->fetchAll( + sprintf( + "SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE type = 'table' AND name = '%s'", + $table + ) + ); $createSql = $createSql[0]['sql'] ?? ''; if (preg_match_all( @@ -169,7 +174,9 @@ protected function _getPortableTableIndexesList($tableIndexes, $tableName = null $indexBuffer = []; // fetch primary - $stmt = $this->_conn->executeQuery("PRAGMA TABLE_INFO ('$tableName')"); + $stmt = $this->_conn->executeQuery( + sprintf("PRAGMA TABLE_INFO ('%s')", $tableName) + ); $indexArray = $stmt->fetchAll(FetchMode::ASSOCIATIVE); usort($indexArray, static function ($a, $b) { @@ -205,7 +212,9 @@ protected function _getPortableTableIndexesList($tableIndexes, $tableName = null $idx['primary'] = false; $idx['non_unique'] = $tableIndex['unique']?false:true; - $stmt = $this->_conn->executeQuery("PRAGMA INDEX_INFO ('{$keyName}')"); + $stmt = $this->_conn->executeQuery( + sprintf("PRAGMA INDEX_INFO ('%s')", $keyName) + ); $indexArray = $stmt->fetchAll(FetchMode::ASSOCIATIVE); foreach ($indexArray as $indexColumnRow) { @@ -263,7 +272,12 @@ protected function _getPortableTableColumnList($table, $database, $tableColumns) } // inspect column collation and comments - $createSql = $this->_conn->fetchAll("SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE type = 'table' AND name = '$table'"); + $createSql = $this->_conn->fetchAll( + sprintf( + "SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE type = 'table' AND name = '%s'", + $table + ) + ); $createSql = $createSql[0]['sql'] ?? ''; foreach ($list as $columnName => $column) { diff --git a/lib/Doctrine/DBAL/Schema/Synchronizer/AbstractSchemaSynchronizer.php b/lib/Doctrine/DBAL/Schema/Synchronizer/AbstractSchemaSynchronizer.php index 8ed118421d8..b597b8db9b2 100644 --- a/lib/Doctrine/DBAL/Schema/Synchronizer/AbstractSchemaSynchronizer.php +++ b/lib/Doctrine/DBAL/Schema/Synchronizer/AbstractSchemaSynchronizer.php @@ -19,7 +19,7 @@ public function __construct(Connection $conn) } /** - * @param array $sql + * @param string[] $sql */ protected function processSqlSafely(array $sql) { @@ -32,7 +32,7 @@ protected function processSqlSafely(array $sql) } /** - * @param array $sql + * @param string[] $sql */ protected function processSql(array $sql) { diff --git a/lib/Doctrine/DBAL/Schema/Synchronizer/SchemaSynchronizer.php b/lib/Doctrine/DBAL/Schema/Synchronizer/SchemaSynchronizer.php index 4d996515c64..3e7beea7508 100644 --- a/lib/Doctrine/DBAL/Schema/Synchronizer/SchemaSynchronizer.php +++ b/lib/Doctrine/DBAL/Schema/Synchronizer/SchemaSynchronizer.php @@ -13,39 +13,39 @@ interface SchemaSynchronizer /** * Gets the SQL statements that can be executed to create the schema. * - * @return array + * @return string[] */ - function getCreateSchema(Schema $createSchema); + public function getCreateSchema(Schema $createSchema); /** * Gets the SQL Statements to update given schema with the underlying db. * * @param bool $noDrops * - * @return array + * @return string[] */ - function getUpdateSchema(Schema $toSchema, $noDrops = false); + public function getUpdateSchema(Schema $toSchema, $noDrops = false); /** * Gets the SQL Statements to drop the given schema from underlying db. * - * @return array + * @return string[] */ - function getDropSchema(Schema $dropSchema); + public function getDropSchema(Schema $dropSchema); /** * Gets the SQL statements to drop all schema assets from underlying db. * - * @return array + * @return string[] */ - function getDropAllSchema(); + public function getDropAllSchema(); /** * Creates the Schema. * * @return void */ - function createSchema(Schema $createSchema); + public function createSchema(Schema $createSchema); /** * Updates the Schema to new schema version. @@ -54,19 +54,19 @@ function createSchema(Schema $createSchema); * * @return void */ - function updateSchema(Schema $toSchema, $noDrops = false); + public function updateSchema(Schema $toSchema, $noDrops = false); /** * Drops the given database schema from the underlying db. * * @return void */ - function dropSchema(Schema $dropSchema); + public function dropSchema(Schema $dropSchema); /** * Drops all assets from the underlying db. * * @return void */ - function dropAllSchema(); + public function dropAllSchema(); } diff --git a/lib/Doctrine/DBAL/Schema/Table.php b/lib/Doctrine/DBAL/Schema/Table.php index 628f7e303be..85e8d8c6946 100644 --- a/lib/Doctrine/DBAL/Schema/Table.php +++ b/lib/Doctrine/DBAL/Schema/Table.php @@ -40,7 +40,7 @@ class Table extends AbstractAsset /** @var ForeignKeyConstraint[] */ protected $_fkConstraints = []; - /** @var array */ + /** @var mixed[] */ protected $_options = []; /** @var SchemaConfig|null */ @@ -52,7 +52,7 @@ class Table extends AbstractAsset * @param Index[] $indexes * @param ForeignKeyConstraint[] $fkConstraints * @param int $idGeneratorType - * @param array $options + * @param mixed[] $options * * @throws DBALException */ @@ -102,7 +102,7 @@ protected function _getMaxIdentifierLength() /** * Sets the Primary Key. * - * @param array $columns + * @param mixed[][] $columns * @param string|bool $indexName * * @return self @@ -120,10 +120,10 @@ public function setPrimaryKey(array $columns, $indexName = false) } /** - * @param array $columnNames + * @param mixed[][] $columnNames * @param string|null $indexName - * @param array $flags - * @param array $options + * @param string[] $flags + * @param mixed[] $options * * @return self */ @@ -170,9 +170,9 @@ public function dropIndex($indexName) } /** - * @param array $columnNames + * @param mixed[][] $columnNames * @param string|null $indexName - * @param array $options + * @param mixed[] $options * * @return self */ @@ -198,7 +198,7 @@ public function addUniqueIndex(array $columnNames, $indexName = null, array $opt * * @return self This table instance. * - * @throws SchemaException if no index exists for the given current name + * @throws SchemaException If no index exists for the given current name * or if an index with the given new name already exists on this table. */ public function renameIndex($oldIndexName, $newIndexName = null) @@ -238,7 +238,7 @@ public function renameIndex($oldIndexName, $newIndexName = null) /** * Checks if an index begins in the order of the given columns. * - * @param array $columnsNames + * @param mixed[][] $columnsNames * * @return bool */ @@ -255,12 +255,12 @@ public function columnsAreIndexed(array $columnsNames) } /** - * @param array $columnNames - * @param string $indexName - * @param bool $isUnique - * @param bool $isPrimary - * @param array $flags - * @param array $options + * @param mixed[][] $columnNames + * @param string $indexName + * @param bool $isUnique + * @param bool $isPrimary + * @param string[] $flags + * @param mixed[] $options * * @return Index * @@ -286,9 +286,9 @@ private function _createIndex(array $columnNames, $indexName, $isUnique, $isPrim } /** - * @param string $columnName - * @param string $typeName - * @param array $options + * @param string $columnName + * @param string $typeName + * @param mixed[] $options * * @return Column */ @@ -321,8 +321,8 @@ public function renameColumn($oldColumnName, $newColumnName) /** * Change Column Details. * - * @param string $columnName - * @param array $options + * @param string $columnName + * @param mixed[] $options * * @return self */ @@ -355,9 +355,9 @@ public function dropColumn($columnName) * Name is inferred from the local columns. * * @param Table|string $foreignTable Table schema instance or table name - * @param array $localColumnNames - * @param array $foreignColumnNames - * @param array $options + * @param string[] $localColumnNames + * @param string[] $foreignColumnNames + * @param mixed[] $options * @param string|null $constraintName * * @return self @@ -377,9 +377,9 @@ public function addForeignKeyConstraint($foreignTable, array $localColumnNames, * @deprecated Use {@link addForeignKeyConstraint} * * @param Table|string $foreignTable Table schema instance or table name - * @param array $localColumnNames - * @param array $foreignColumnNames - * @param array $options + * @param string[] $localColumnNames + * @param string[] $foreignColumnNames + * @param mixed[] $options * * @return self */ @@ -395,9 +395,9 @@ public function addUnnamedForeignKeyConstraint($foreignTable, array $localColumn * * @param string $name * @param Table|string $foreignTable Table schema instance or table name - * @param array $localColumnNames - * @param array $foreignColumnNames - * @param array $options + * @param string[] $localColumnNames + * @param string[] $foreignColumnNames + * @param mixed[] $options * * @return self * @@ -626,7 +626,7 @@ private function getForeignKeyColumns() /** * Returns only columns that have specified names * - * @param array $columnNames + * @param string[] $columnNames * * @return Column[] */ @@ -687,7 +687,7 @@ public function getPrimaryKey() /** * Returns the primary key columns. * - * @return array + * @return string[] * * @throws DBALException */ @@ -781,7 +781,7 @@ public function getOption($name) } /** - * @return array + * @return mixed[] */ public function getOptions() { diff --git a/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php b/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php index 673592d4c38..318c8b26222 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php @@ -10,16 +10,16 @@ class CreateSchemaSqlCollector extends AbstractVisitor { - /** @var array */ + /** @var string[] */ private $createNamespaceQueries = []; - /** @var array */ + /** @var string[] */ private $createTableQueries = []; - /** @var array */ + /** @var string[] */ private $createSequenceQueries = []; - /** @var array */ + /** @var string[] */ private $createFkConstraintQueries = []; /** @var AbstractPlatform */ @@ -84,7 +84,7 @@ public function resetQueries() /** * Gets all queries collected so far. * - * @return array + * @return string[] */ public function getQueries() { diff --git a/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php b/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php index 33364de0c1a..f1041ed13f6 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php @@ -74,7 +74,7 @@ public function clearQueries() } /** - * @return array + * @return string[] */ public function getQueries() { diff --git a/lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php b/lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php index f07c4301f32..889f9611254 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php @@ -96,8 +96,8 @@ private function createTableLabel(Table $table) } /** - * @param string $name - * @param array $options + * @param string $name + * @param string[] $options * * @return string */ @@ -113,9 +113,9 @@ private function createNode($name, $options) } /** - * @param string $node1 - * @param string $node2 - * @param array $options + * @param string $node1 + * @param string $node2 + * @param string[] $options * * @return string */ diff --git a/lib/Doctrine/DBAL/Schema/Visitor/SchemaDiffVisitor.php b/lib/Doctrine/DBAL/Schema/Visitor/SchemaDiffVisitor.php index 593075816a8..695ccdb68c3 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/SchemaDiffVisitor.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/SchemaDiffVisitor.php @@ -17,25 +17,25 @@ interface SchemaDiffVisitor /** * Visit an orphaned foreign key whose table was deleted. */ - function visitOrphanedForeignKey(ForeignKeyConstraint $foreignKey); + public function visitOrphanedForeignKey(ForeignKeyConstraint $foreignKey); /** * Visit a sequence that has changed. */ - function visitChangedSequence(Sequence $sequence); + public function visitChangedSequence(Sequence $sequence); /** * Visit a sequence that has been removed. */ - function visitRemovedSequence(Sequence $sequence); + public function visitRemovedSequence(Sequence $sequence); - function visitNewSequence(Sequence $sequence); + public function visitNewSequence(Sequence $sequence); - function visitNewTable(Table $table); + public function visitNewTable(Table $table); - function visitNewTableForeignKey(Table $table, ForeignKeyConstraint $foreignKey); + public function visitNewTableForeignKey(Table $table, ForeignKeyConstraint $foreignKey); - function visitRemovedTable(Table $table); + public function visitRemovedTable(Table $table); - function visitChangedTable(TableDiff $tableDiff); + public function visitChangedTable(TableDiff $tableDiff); } diff --git a/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php b/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php index 02f124cc443..abb5b4004e2 100644 --- a/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php +++ b/lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php @@ -60,7 +60,7 @@ class PoolingShardConnection extends Connection private $connectionParameters = []; /** - * @param array $params + * {@inheritDoc} * * @throws InvalidArgumentException */ diff --git a/lib/Doctrine/DBAL/Sharding/PoolingShardManager.php b/lib/Doctrine/DBAL/Sharding/PoolingShardManager.php index 7d3dc9b822b..5edc56b8778 100644 --- a/lib/Doctrine/DBAL/Sharding/PoolingShardManager.php +++ b/lib/Doctrine/DBAL/Sharding/PoolingShardManager.php @@ -69,11 +69,7 @@ public function getShards() } /** - * @param string $sql - * @param array $params - * @param array $types - * - * @return array + * {@inheritDoc} * * @throws RuntimeException */ diff --git a/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php b/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php index 139cbd24eaf..32d642365b0 100644 --- a/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php +++ b/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php @@ -153,7 +153,7 @@ public function dropAllSchema() } /** - * @return array + * @return Schema[] */ private function partitionSchema(Schema $schema) { @@ -199,7 +199,7 @@ private function extractSchemaFederation(Schema $schema, $isFederation) * perform the given operation on the underlying schema synchronizer given * the different partitioned schema instances. * - * @return array + * @return string[] */ private function work(Schema $schema, Closure $operation) { diff --git a/lib/Doctrine/DBAL/Sharding/SQLAzure/Schema/MultiTenantVisitor.php b/lib/Doctrine/DBAL/Sharding/SQLAzure/Schema/MultiTenantVisitor.php index 065af56ab09..a83b401c2cd 100644 --- a/lib/Doctrine/DBAL/Sharding/SQLAzure/Schema/MultiTenantVisitor.php +++ b/lib/Doctrine/DBAL/Sharding/SQLAzure/Schema/MultiTenantVisitor.php @@ -33,7 +33,7 @@ */ class MultiTenantVisitor implements Visitor { - /** @var array */ + /** @var string[] */ private $excludedTables = []; /** @var string */ @@ -51,7 +51,7 @@ class MultiTenantVisitor implements Visitor private $distributionName; /** - * @param array $excludedTables + * @param string[] $excludedTables * @param string $tenantColumnName * @param string|null $distributionName */ diff --git a/lib/Doctrine/DBAL/Sharding/ShardChoser/ShardChoser.php b/lib/Doctrine/DBAL/Sharding/ShardChoser/ShardChoser.php index d7db3b8615f..6f8a9d47702 100644 --- a/lib/Doctrine/DBAL/Sharding/ShardChoser/ShardChoser.php +++ b/lib/Doctrine/DBAL/Sharding/ShardChoser/ShardChoser.php @@ -17,5 +17,5 @@ interface ShardChoser * * @return string|int */ - function pickShard($distributionValue, PoolingShardConnection $conn); + public function pickShard($distributionValue, PoolingShardConnection $conn); } diff --git a/lib/Doctrine/DBAL/Sharding/ShardManager.php b/lib/Doctrine/DBAL/Sharding/ShardManager.php index 843db03ff7a..7b37bb2c7e1 100644 --- a/lib/Doctrine/DBAL/Sharding/ShardManager.php +++ b/lib/Doctrine/DBAL/Sharding/ShardManager.php @@ -28,7 +28,7 @@ interface ShardManager * * @return void */ - function selectGlobal(); + public function selectGlobal(); /** * Selects the shard against which the queries after this statement will be issued. @@ -39,14 +39,14 @@ function selectGlobal(); * * @throws ShardingException If no value is passed as shard identifier. */ - function selectShard($distributionValue); + public function selectShard($distributionValue); /** * Gets the distribution value currently used for sharding. * * @return string|null */ - function getCurrentDistributionValue(); + public function getCurrentDistributionValue(); /** * Gets information about the amount of shards and other details. @@ -54,9 +54,9 @@ function getCurrentDistributionValue(); * Format is implementation specific, each shard is one element and has an * 'id' attribute at least. * - * @return array + * @return mixed[][] */ - function getShards(); + public function getShards(); /** * Queries all shards in undefined order and return the results appended to @@ -64,11 +64,11 @@ function getShards(); * * Using {@link \Doctrine\DBAL\Connection::fetchAll} to retrieve rows internally. * - * @param string $sql - * @param array $params - * @param array $types + * @param string $sql + * @param mixed[] $params + * @param int[]|string[] $types * - * @return array + * @return mixed[] */ - function queryAll($sql, array $params, array $types); + public function queryAll($sql, array $params, array $types); } diff --git a/lib/Doctrine/DBAL/Statement.php b/lib/Doctrine/DBAL/Statement.php index 4b25274e65e..b65fa95e33a 100644 --- a/lib/Doctrine/DBAL/Statement.php +++ b/lib/Doctrine/DBAL/Statement.php @@ -27,14 +27,14 @@ class Statement implements IteratorAggregate, DriverStatement /** * The bound parameters. * - * @var array + * @var mixed[] */ protected $params = []; /** * The parameter types. * - * @var array + * @var int[]|string[] */ protected $types = []; @@ -132,7 +132,7 @@ public function bindParam($name, &$var, $type = ParameterType::STRING, $length = /** * Executes the statement with the currently bound parameters. * - * @param array|null $params + * @param mixed[]|null $params * * @return bool TRUE on success, FALSE on failure. * @@ -203,9 +203,7 @@ public function errorCode() } /** - * Fetches extended error information associated with the last operation on the statement. - * - * @return array + * {@inheritDoc} */ public function errorInfo() { @@ -257,11 +255,7 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n } /** - * Returns a single column from the next row of a result set. - * - * @param int $columnIndex - * - * @return mixed A single column from the next row of a result set or FALSE if there are no more rows. + * {@inheritDoc} */ public function fetchColumn($columnIndex = 0) { diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php index 37a1ecbb3da..9a4279d3f5c 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php @@ -56,8 +56,10 @@ protected function execute(InputInterface $input, OutputInterface $output) { $conn = $this->getHelper('db')->getConnection(); - if (($fileNames = $input->getArgument('file')) === null) { - return; + $fileNames = $input->getArgument('file'); + + if ($fileNames === null) { + return null; } foreach ((array) $fileNames as $fileName) { @@ -123,5 +125,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $stmt->closeCursor(); } } + + return null; } } diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php index 9c560c5179d..edeb1f448a3 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php @@ -16,7 +16,7 @@ class ReservedWordsCommand extends Command { - /** @var array */ + /** @var string[] */ private $keywordListClasses = [ 'mysql' => 'Doctrine\DBAL\Platforms\Keywords\MySQLKeywords', 'mysql57' => 'Doctrine\DBAL\Platforms\Keywords\MySQL57Keywords', diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php index e3e56f67eaf..f99684122be 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php @@ -47,7 +47,9 @@ protected function execute(InputInterface $input, OutputInterface $output) { $conn = $this->getHelper('db')->getConnection(); - if (($sql = $input->getArgument('sql')) === null) { + $sql = $input->getArgument('sql'); + + if ($sql === null) { throw new RuntimeException("Argument 'SQL' is required in order to execute this command correctly."); } diff --git a/lib/Doctrine/DBAL/Types/Type.php b/lib/Doctrine/DBAL/Types/Type.php index 983c1cda191..ec1ab681356 100644 --- a/lib/Doctrine/DBAL/Types/Type.php +++ b/lib/Doctrine/DBAL/Types/Type.php @@ -45,14 +45,14 @@ abstract class Type /** * Map of already instantiated type objects. One instance per type (flyweight). * - * @var array + * @var self[] */ private static $_typeObjects = []; /** * The map of supported doctrine mapping types. * - * @var array + * @var string[] */ private static $_typesMap = [ self::TARRAY => ArrayType::class, @@ -132,7 +132,7 @@ public function getDefaultLength(AbstractPlatform $platform) /** * Gets the SQL declaration snippet for a field of this type. * - * @param array $fieldDeclaration The field declaration. + * @param mixed[] $fieldDeclaration The field declaration. * @param AbstractPlatform $platform The currently used database platform. * * @return string @@ -241,7 +241,7 @@ public function getBindingType() * Gets the types array map which holds all registered types and the corresponding * type class * - * @return array + * @return string[] */ public static function getTypesMap() { @@ -303,7 +303,7 @@ public function convertToPHPValueSQL($sqlExpr, $platform) /** * Gets an array of database types that map to this Doctrine type. * - * @return array + * @return string[] */ public function getMappedDatabaseTypes(AbstractPlatform $platform) { diff --git a/lib/Doctrine/DBAL/VersionAwarePlatformDriver.php b/lib/Doctrine/DBAL/VersionAwarePlatformDriver.php index 14ecbc720bb..b140a30d062 100644 --- a/lib/Doctrine/DBAL/VersionAwarePlatformDriver.php +++ b/lib/Doctrine/DBAL/VersionAwarePlatformDriver.php @@ -24,7 +24,7 @@ interface VersionAwarePlatformDriver * * @return AbstractPlatform * - * @throws DBALException if the given version string could not be evaluated. + * @throws DBALException If the given version string could not be evaluated. */ public function createDatabasePlatformForVersion($version); } diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 75e6a9c1c04..aaa6b5f04a5 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -37,8 +37,25 @@ tests/Doctrine/Tests/DBAL/Tools/TestAsset/* + + + lib/Doctrine/DBAL/Platforms/AbstractPlatform.php + lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php + + + + + lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php + + + + + lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php + + + tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php diff --git a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php index 5af2b0cf571..051b3e68dd9 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php @@ -781,42 +781,51 @@ public function getReturnsGetListTableColumnsSQL() return [ [ null, - "SELECT c.*, - ( - SELECT d.comments - FROM user_col_comments d - WHERE d.TABLE_NAME = c.TABLE_NAME - AND d.COLUMN_NAME = c.COLUMN_NAME - ) AS comments - FROM user_tab_columns c - WHERE c.table_name = 'test' - ORDER BY c.column_id", + <<<'SQL' +SELECT c.*, + ( + SELECT d.comments + FROM user_col_comments d + WHERE d.TABLE_NAME = c.TABLE_NAME + AND d.COLUMN_NAME = c.COLUMN_NAME + ) AS comments +FROM user_tab_columns c +WHERE c.table_name = 'test' +ORDER BY c.column_id +SQL + , ], [ '/', - "SELECT c.*, - ( - SELECT d.comments - FROM user_col_comments d - WHERE d.TABLE_NAME = c.TABLE_NAME - AND d.COLUMN_NAME = c.COLUMN_NAME - ) AS comments - FROM user_tab_columns c - WHERE c.table_name = 'test' - ORDER BY c.column_id", + <<<'SQL' +SELECT c.*, + ( + SELECT d.comments + FROM user_col_comments d + WHERE d.TABLE_NAME = c.TABLE_NAME + AND d.COLUMN_NAME = c.COLUMN_NAME + ) AS comments +FROM user_tab_columns c +WHERE c.table_name = 'test' +ORDER BY c.column_id +SQL + , ], [ 'scott', - "SELECT c.*, - ( - SELECT d.comments - FROM all_col_comments d - WHERE d.TABLE_NAME = c.TABLE_NAME AND d.OWNER = c.OWNER - AND d.COLUMN_NAME = c.COLUMN_NAME - ) AS comments - FROM all_tab_columns c - WHERE c.table_name = 'test' AND c.owner = 'SCOTT' - ORDER BY c.column_id", + <<<'SQL' +SELECT c.*, + ( + SELECT d.comments + FROM all_col_comments d + WHERE d.TABLE_NAME = c.TABLE_NAME AND d.OWNER = c.OWNER + AND d.COLUMN_NAME = c.COLUMN_NAME + ) AS comments +FROM all_tab_columns c +WHERE c.table_name = 'test' AND c.owner = 'SCOTT' +ORDER BY c.column_id +SQL + , ], ]; } From 1cbadb3e4821f10db4eb17b93dc3eed487751231 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Mon, 1 Oct 2018 20:25:06 -0700 Subject: [PATCH 34/76] Removed leading underscore from private class memeber names --- lib/Doctrine/DBAL/Connection.php | 132 +++++++++--------- .../DBAL/Driver/IBMDB2/DB2Connection.php | 34 ++--- .../DBAL/Driver/IBMDB2/DB2Statement.php | 52 +++---- .../DBAL/Driver/Mysqli/MysqliConnection.php | 54 +++---- .../DBAL/Event/ConnectionEventArgs.php | 12 +- .../DBAL/Event/Listeners/MysqlSessionInit.php | 12 +- .../SchemaAlterTableAddColumnEventArgs.php | 26 ++-- .../SchemaAlterTableChangeColumnEventArgs.php | 26 ++-- .../DBAL/Event/SchemaAlterTableEventArgs.php | 20 +-- .../SchemaAlterTableRemoveColumnEventArgs.php | 26 ++-- .../SchemaAlterTableRenameColumnEventArgs.php | 32 ++--- .../Event/SchemaColumnDefinitionEventArgs.php | 32 ++--- .../SchemaCreateTableColumnEventArgs.php | 26 ++-- .../DBAL/Event/SchemaCreateTableEventArgs.php | 32 ++--- .../DBAL/Event/SchemaDropTableEventArgs.php | 18 +-- lib/Doctrine/DBAL/Event/SchemaEventArgs.php | 6 +- .../Event/SchemaIndexDefinitionEventArgs.php | 26 ++-- lib/Doctrine/DBAL/Schema/View.php | 6 +- 18 files changed, 286 insertions(+), 286 deletions(-) diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index c23947aae8c..afe4382b6de 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -103,7 +103,7 @@ class Connection implements DriverConnection * * @var bool */ - private $_isConnected = false; + private $isConnected = false; /** * The current auto-commit mode of this connection. @@ -117,28 +117,28 @@ class Connection implements DriverConnection * * @var int */ - private $_transactionNestingLevel = 0; + private $transactionNestingLevel = 0; /** * The currently active transaction isolation level. * * @var int */ - private $_transactionIsolationLevel; + private $transactionIsolationLevel; /** * If nested transactions should use savepoints. * * @var bool */ - private $_nestTransactionsWithSavepoints = false; + private $nestTransactionsWithSavepoints = false; /** * The parameters used during creation of the Connection instance. * * @var mixed[] */ - private $_params = []; + private $params = []; /** * The DatabasePlatform object that provides information about the @@ -167,7 +167,7 @@ class Connection implements DriverConnection * * @var bool */ - private $_isRollbackOnly = false; + private $isRollbackOnly = false; /** @var int */ protected $defaultFetchMode = FetchMode::ASSOCIATIVE; @@ -189,12 +189,12 @@ public function __construct( ?EventManager $eventManager = null ) { $this->_driver = $driver; - $this->_params = $params; + $this->params = $params; if (isset($params['pdo'])) { - $this->_conn = $params['pdo']; - $this->_isConnected = true; - unset($this->_params['pdo']); + $this->_conn = $params['pdo']; + $this->isConnected = true; + unset($this->params['pdo']); } if (isset($params['platform'])) { @@ -203,7 +203,7 @@ public function __construct( } $this->platform = $params['platform']; - unset($this->_params['platform']); + unset($this->params['platform']); } // Create default config and event manager if none given @@ -230,7 +230,7 @@ public function __construct( */ public function getParams() { - return $this->_params; + return $this->params; } /** @@ -250,7 +250,7 @@ public function getDatabase() */ public function getHost() { - return $this->_params['host'] ?? null; + return $this->params['host'] ?? null; } /** @@ -260,7 +260,7 @@ public function getHost() */ public function getPort() { - return $this->_params['port'] ?? null; + return $this->params['port'] ?? null; } /** @@ -270,7 +270,7 @@ public function getPort() */ public function getUsername() { - return $this->_params['user'] ?? null; + return $this->params['user'] ?? null; } /** @@ -280,7 +280,7 @@ public function getUsername() */ public function getPassword() { - return $this->_params['password'] ?? null; + return $this->params['password'] ?? null; } /** @@ -347,16 +347,16 @@ public function getExpressionBuilder() */ public function connect() { - if ($this->_isConnected) { + if ($this->isConnected) { return false; } - $driverOptions = $this->_params['driverOptions'] ?? []; - $user = $this->_params['user'] ?? null; - $password = $this->_params['password'] ?? null; + $driverOptions = $this->params['driverOptions'] ?? []; + $user = $this->params['user'] ?? null; + $password = $this->params['password'] ?? null; - $this->_conn = $this->_driver->connect($this->_params, $user, $password, $driverOptions); - $this->_isConnected = true; + $this->_conn = $this->_driver->connect($this->params, $user, $password, $driverOptions); + $this->isConnected = true; if ($this->autoCommit === false) { $this->beginTransaction(); @@ -412,8 +412,8 @@ private function getDatabasePlatformVersion() } // Explicit platform version requested (supersedes auto-detection). - if (isset($this->_params['serverVersion'])) { - return $this->_params['serverVersion']; + if (isset($this->params['serverVersion'])) { + return $this->params['serverVersion']; } // If not connected, we need to connect now to determine the platform version. @@ -421,14 +421,14 @@ private function getDatabasePlatformVersion() try { $this->connect(); } catch (Throwable $originalException) { - if (empty($this->_params['dbname'])) { + if (empty($this->params['dbname'])) { throw $originalException; } // The database to connect to might not yet exist. // Retry detection without database name connection parameter. - $databaseName = $this->_params['dbname']; - $this->_params['dbname'] = null; + $databaseName = $this->params['dbname']; + $this->params['dbname'] = null; try { $this->connect(); @@ -436,14 +436,14 @@ private function getDatabasePlatformVersion() // Either the platform does not support database-less connections // or something else went wrong. // Reset connection parameters and rethrow the original exception. - $this->_params['dbname'] = $databaseName; + $this->params['dbname'] = $databaseName; throw $originalException; } // Reset connection parameters. - $this->_params['dbname'] = $databaseName; - $serverVersion = $this->getServerVersion(); + $this->params['dbname'] = $databaseName; + $serverVersion = $this->getServerVersion(); // Close "temporary" connection to allow connecting to the real database again. $this->close(); @@ -511,7 +511,7 @@ public function setAutoCommit($autoCommit) $this->autoCommit = $autoCommit; // Commit all currently active transactions if any when switching auto-commit mode. - if ($this->_isConnected !== true || $this->_transactionNestingLevel === 0) { + if ($this->isConnected !== true || $this->transactionNestingLevel === 0) { return; } @@ -587,7 +587,7 @@ public function fetchColumn($statement, array $params = [], $column = 0, array $ */ public function isConnected() { - return $this->_isConnected; + return $this->isConnected; } /** @@ -597,7 +597,7 @@ public function isConnected() */ public function isTransactionActive() { - return $this->_transactionNestingLevel > 0; + return $this->transactionNestingLevel > 0; } /** @@ -668,7 +668,7 @@ public function close() { $this->_conn = null; - $this->_isConnected = false; + $this->isConnected = false; } /** @@ -680,7 +680,7 @@ public function close() */ public function setTransactionIsolation($level) { - $this->_transactionIsolationLevel = $level; + $this->transactionIsolationLevel = $level; return $this->executeUpdate($this->getDatabasePlatform()->getSetTransactionIsolationSQL($level)); } @@ -692,11 +692,11 @@ public function setTransactionIsolation($level) */ public function getTransactionIsolation() { - if ($this->_transactionIsolationLevel === null) { - $this->_transactionIsolationLevel = $this->getDatabasePlatform()->getDefaultTransactionIsolationLevel(); + if ($this->transactionIsolationLevel === null) { + $this->transactionIsolationLevel = $this->getDatabasePlatform()->getDefaultTransactionIsolationLevel(); } - return $this->_transactionIsolationLevel; + return $this->transactionIsolationLevel; } /** @@ -1110,7 +1110,7 @@ public function exec($statement) */ public function getTransactionNestingLevel() { - return $this->_transactionNestingLevel; + return $this->transactionNestingLevel; } /** @@ -1196,7 +1196,7 @@ public function transactional(Closure $func) */ public function setNestTransactionsWithSavepoints($nestTransactionsWithSavepoints) { - if ($this->_transactionNestingLevel > 0) { + if ($this->transactionNestingLevel > 0) { throw ConnectionException::mayNotAlterNestedTransactionWithSavepointsInTransaction(); } @@ -1204,7 +1204,7 @@ public function setNestTransactionsWithSavepoints($nestTransactionsWithSavepoint throw ConnectionException::savepointsNotSupported(); } - $this->_nestTransactionsWithSavepoints = (bool) $nestTransactionsWithSavepoints; + $this->nestTransactionsWithSavepoints = (bool) $nestTransactionsWithSavepoints; } /** @@ -1214,7 +1214,7 @@ public function setNestTransactionsWithSavepoints($nestTransactionsWithSavepoint */ public function getNestTransactionsWithSavepoints() { - return $this->_nestTransactionsWithSavepoints; + return $this->nestTransactionsWithSavepoints; } /** @@ -1225,7 +1225,7 @@ public function getNestTransactionsWithSavepoints() */ protected function _getNestedTransactionSavePointName() { - return 'DOCTRINE2_SAVEPOINT_' . $this->_transactionNestingLevel; + return 'DOCTRINE2_SAVEPOINT_' . $this->transactionNestingLevel; } /** @@ -1237,11 +1237,11 @@ public function beginTransaction() { $this->connect(); - ++$this->_transactionNestingLevel; + ++$this->transactionNestingLevel; $logger = $this->_config->getSQLLogger(); - if ($this->_transactionNestingLevel === 1) { + if ($this->transactionNestingLevel === 1) { if ($logger) { $logger->startQuery('"START TRANSACTION"'); } @@ -1249,7 +1249,7 @@ public function beginTransaction() if ($logger) { $logger->stopQuery(); } - } elseif ($this->_nestTransactionsWithSavepoints) { + } elseif ($this->nestTransactionsWithSavepoints) { if ($logger) { $logger->startQuery('"SAVEPOINT"'); } @@ -1270,10 +1270,10 @@ public function beginTransaction() */ public function commit() { - if ($this->_transactionNestingLevel === 0) { + if ($this->transactionNestingLevel === 0) { throw ConnectionException::noActiveTransaction(); } - if ($this->_isRollbackOnly) { + if ($this->isRollbackOnly) { throw ConnectionException::commitFailedRollbackOnly(); } @@ -1281,7 +1281,7 @@ public function commit() $logger = $this->_config->getSQLLogger(); - if ($this->_transactionNestingLevel === 1) { + if ($this->transactionNestingLevel === 1) { if ($logger) { $logger->startQuery('"COMMIT"'); } @@ -1289,7 +1289,7 @@ public function commit() if ($logger) { $logger->stopQuery(); } - } elseif ($this->_nestTransactionsWithSavepoints) { + } elseif ($this->nestTransactionsWithSavepoints) { if ($logger) { $logger->startQuery('"RELEASE SAVEPOINT"'); } @@ -1299,9 +1299,9 @@ public function commit() } } - --$this->_transactionNestingLevel; + --$this->transactionNestingLevel; - if ($this->autoCommit !== false || $this->_transactionNestingLevel !== 0) { + if ($this->autoCommit !== false || $this->transactionNestingLevel !== 0) { return; } @@ -1313,8 +1313,8 @@ public function commit() */ private function commitAll() { - while ($this->_transactionNestingLevel !== 0) { - if ($this->autoCommit === false && $this->_transactionNestingLevel === 1) { + while ($this->transactionNestingLevel !== 0) { + if ($this->autoCommit === false && $this->transactionNestingLevel === 1) { // When in no auto-commit mode, the last nesting commit immediately starts a new transaction. // Therefore we need to do the final commit here and then leave to avoid an infinite loop. $this->commit(); @@ -1333,7 +1333,7 @@ private function commitAll() */ public function rollBack() { - if ($this->_transactionNestingLevel === 0) { + if ($this->transactionNestingLevel === 0) { throw ConnectionException::noActiveTransaction(); } @@ -1341,13 +1341,13 @@ public function rollBack() $logger = $this->_config->getSQLLogger(); - if ($this->_transactionNestingLevel === 1) { + if ($this->transactionNestingLevel === 1) { if ($logger) { $logger->startQuery('"ROLLBACK"'); } - $this->_transactionNestingLevel = 0; + $this->transactionNestingLevel = 0; $this->_conn->rollBack(); - $this->_isRollbackOnly = false; + $this->isRollbackOnly = false; if ($logger) { $logger->stopQuery(); } @@ -1355,18 +1355,18 @@ public function rollBack() if ($this->autoCommit === false) { $this->beginTransaction(); } - } elseif ($this->_nestTransactionsWithSavepoints) { + } elseif ($this->nestTransactionsWithSavepoints) { if ($logger) { $logger->startQuery('"ROLLBACK TO SAVEPOINT"'); } $this->rollbackSavepoint($this->_getNestedTransactionSavePointName()); - --$this->_transactionNestingLevel; + --$this->transactionNestingLevel; if ($logger) { $logger->stopQuery(); } } else { - $this->_isRollbackOnly = true; - --$this->_transactionNestingLevel; + $this->isRollbackOnly = true; + --$this->transactionNestingLevel; } } @@ -1465,10 +1465,10 @@ public function getSchemaManager() */ public function setRollbackOnly() { - if ($this->_transactionNestingLevel === 0) { + if ($this->transactionNestingLevel === 0) { throw ConnectionException::noActiveTransaction(); } - $this->_isRollbackOnly = true; + $this->isRollbackOnly = true; } /** @@ -1480,11 +1480,11 @@ public function setRollbackOnly() */ public function isRollbackOnly() { - if ($this->_transactionNestingLevel === 0) { + if ($this->transactionNestingLevel === 0) { throw ConnectionException::noActiveTransaction(); } - return $this->_isRollbackOnly; + return $this->isRollbackOnly; } /** diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php index bc555f8604c..bd80e6e49a7 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php @@ -27,7 +27,7 @@ class DB2Connection implements Connection, ServerInfoAwareConnection { /** @var resource */ - private $_conn = null; + private $conn = null; /** * @param mixed[] $params @@ -42,11 +42,11 @@ 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); + $this->conn = db2_pconnect($params['dbname'], $username, $password, $driverOptions); } else { - $this->_conn = db2_connect($params['dbname'], $username, $password, $driverOptions); + $this->conn = db2_connect($params['dbname'], $username, $password, $driverOptions); } - if (! $this->_conn) { + if (! $this->conn) { throw new DB2Exception(db2_conn_errormsg()); } } @@ -57,7 +57,7 @@ public function __construct(array $params, $username, $password, $driverOptions public function getServerVersion() { /** @var stdClass $serverInfo */ - $serverInfo = db2_server_info($this->_conn); + $serverInfo = db2_server_info($this->conn); return $serverInfo->DBMS_VER; } @@ -75,7 +75,7 @@ public function requiresQueryForServerVersion() */ public function prepare($sql) { - $stmt = @db2_prepare($this->_conn, $sql); + $stmt = @db2_prepare($this->conn, $sql); if (! $stmt) { throw new DB2Exception(db2_stmt_errormsg()); } @@ -115,7 +115,7 @@ public function quote($input, $type = ParameterType::STRING) */ public function exec($statement) { - $stmt = @db2_exec($this->_conn, $statement); + $stmt = @db2_exec($this->conn, $statement); if ($stmt === false) { throw new DB2Exception(db2_stmt_errormsg()); @@ -129,7 +129,7 @@ public function exec($statement) */ public function lastInsertId($name = null) { - return db2_last_insert_id($this->_conn); + return db2_last_insert_id($this->conn); } /** @@ -137,7 +137,7 @@ public function lastInsertId($name = null) */ public function beginTransaction() { - db2_autocommit($this->_conn, DB2_AUTOCOMMIT_OFF); + db2_autocommit($this->conn, DB2_AUTOCOMMIT_OFF); } /** @@ -145,10 +145,10 @@ public function beginTransaction() */ public function commit() { - if (! db2_commit($this->_conn)) { - throw new DB2Exception(db2_conn_errormsg($this->_conn)); + if (! db2_commit($this->conn)) { + throw new DB2Exception(db2_conn_errormsg($this->conn)); } - db2_autocommit($this->_conn, DB2_AUTOCOMMIT_ON); + db2_autocommit($this->conn, DB2_AUTOCOMMIT_ON); } /** @@ -156,10 +156,10 @@ public function commit() */ public function rollBack() { - if (! db2_rollback($this->_conn)) { - throw new DB2Exception(db2_conn_errormsg($this->_conn)); + if (! db2_rollback($this->conn)) { + throw new DB2Exception(db2_conn_errormsg($this->conn)); } - db2_autocommit($this->_conn, DB2_AUTOCOMMIT_ON); + db2_autocommit($this->conn, DB2_AUTOCOMMIT_ON); } /** @@ -167,7 +167,7 @@ public function rollBack() */ public function errorCode() { - return db2_conn_error($this->_conn); + return db2_conn_error($this->conn); } /** @@ -176,7 +176,7 @@ public function errorCode() public function errorInfo() { return [ - 0 => db2_conn_errormsg($this->_conn), + 0 => db2_conn_errormsg($this->conn), 1 => $this->errorCode(), ]; } diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php index 9a8baf69bd2..5a303ceb856 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php @@ -40,10 +40,10 @@ class DB2Statement implements IteratorAggregate, Statement { /** @var resource */ - private $_stmt; + private $stmt; /** @var mixed[] */ - private $_bindParam = []; + private $bindParam = []; /** @var string Name of the default class to instantiate when fetching class instances. */ private $defaultFetchClass = '\stdClass'; @@ -52,7 +52,7 @@ class DB2Statement implements IteratorAggregate, Statement private $defaultFetchClassCtorArgs = []; /** @var int */ - private $_defaultFetchMode = FetchMode::MIXED; + private $defaultFetchMode = FetchMode::MIXED; /** * Indicates whether the statement is in the state when fetching results is possible @@ -66,7 +66,7 @@ class DB2Statement implements IteratorAggregate, Statement * * @var int[] */ - static private $_typeMap = [ + static private $typeMap = [ ParameterType::INTEGER => DB2_LONG, ParameterType::STRING => DB2_CHAR, ]; @@ -76,7 +76,7 @@ class DB2Statement implements IteratorAggregate, Statement */ public function __construct($stmt) { - $this->_stmt = $stmt; + $this->stmt = $stmt; } /** @@ -92,15 +92,15 @@ public function bindValue($param, $value, $type = ParameterType::STRING) */ public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null) { - $this->_bindParam[$column] =& $variable; + $this->bindParam[$column] =& $variable; - if ($type && isset(self::$_typeMap[$type])) { - $type = self::$_typeMap[$type]; + if ($type && isset(self::$typeMap[$type])) { + $type = self::$typeMap[$type]; } else { $type = DB2_CHAR; } - if (! db2_bind_param($this->_stmt, $column, 'variable', DB2_PARAM_IN, $type)) { + if (! db2_bind_param($this->stmt, $column, 'variable', DB2_PARAM_IN, $type)) { throw new DB2Exception(db2_stmt_errormsg()); } @@ -112,13 +112,13 @@ public function bindParam($column, &$variable, $type = ParameterType::STRING, $l */ public function closeCursor() { - if (! $this->_stmt) { + if (! $this->stmt) { return false; } - $this->_bindParam = []; + $this->bindParam = []; - if (! db2_free_result($this->_stmt)) { + if (! db2_free_result($this->stmt)) { return false; } @@ -132,11 +132,11 @@ public function closeCursor() */ public function columnCount() { - if (! $this->_stmt) { + if (! $this->stmt) { return false; } - return db2_num_fields($this->_stmt); + return db2_num_fields($this->stmt); } /** @@ -163,21 +163,21 @@ public function errorInfo() */ public function execute($params = null) { - if (! $this->_stmt) { + if (! $this->stmt) { return false; } if ($params === null) { - ksort($this->_bindParam); + ksort($this->bindParam); $params = []; - foreach ($this->_bindParam as $column => $value) { + foreach ($this->bindParam as $column => $value) { $params[] = $value; } } - $retval = db2_execute($this->_stmt, $params); + $retval = db2_execute($this->stmt, $params); if ($retval === false) { throw new DB2Exception(db2_stmt_errormsg()); @@ -193,7 +193,7 @@ public function execute($params = null) */ public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) { - $this->_defaultFetchMode = $fetchMode; + $this->defaultFetchMode = $fetchMode; $this->defaultFetchClass = $arg2 ?: $this->defaultFetchClass; $this->defaultFetchClassCtorArgs = $arg3 ? (array) $arg3 : $this->defaultFetchClassCtorArgs; @@ -219,16 +219,16 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX return false; } - $fetchMode = $fetchMode ?: $this->_defaultFetchMode; + $fetchMode = $fetchMode ?: $this->defaultFetchMode; switch ($fetchMode) { case FetchMode::COLUMN: return $this->fetchColumn(); case FetchMode::MIXED: - return db2_fetch_both($this->_stmt); + return db2_fetch_both($this->stmt); case FetchMode::ASSOCIATIVE: - return db2_fetch_assoc($this->_stmt); + return db2_fetch_assoc($this->stmt); case FetchMode::CUSTOM_OBJECT: $className = $this->defaultFetchClass; @@ -240,7 +240,7 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX $ctorArgs = $args[2] ?? []; } - $result = db2_fetch_object($this->_stmt); + $result = db2_fetch_object($this->stmt); if ($result instanceof stdClass) { $result = $this->castObject($result, $className, $ctorArgs); @@ -249,10 +249,10 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX return $result; case FetchMode::NUMERIC: - return db2_fetch_array($this->_stmt); + return db2_fetch_array($this->stmt); case FetchMode::STANDARD_OBJECT: - return db2_fetch_object($this->_stmt); + return db2_fetch_object($this->stmt); default: throw new DB2Exception('Given Fetch-Style ' . $fetchMode . ' is not supported.'); @@ -305,7 +305,7 @@ public function fetchColumn($columnIndex = 0) */ public function rowCount() { - return @db2_num_rows($this->_stmt) ? : 0; + return @db2_num_rows($this->stmt) ? : 0; } /** diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php index 4495cc92d0f..1f1a1d218c3 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php @@ -35,7 +35,7 @@ class MysqliConnection implements Connection, PingableConnection, ServerInfoAwar public const OPTION_FLAGS = 'flags'; /** @var mysqli */ - private $_conn; + private $conn; /** * @param mixed[] $params @@ -59,7 +59,7 @@ public function __construct(array $params, $username, $password, array $driverOp $flags = $driverOptions[static::OPTION_FLAGS] ?? null; - $this->_conn = mysqli_init(); + $this->conn = mysqli_init(); $this->setSecureConnection($params); $this->setDriverOptions($driverOptions); @@ -67,8 +67,8 @@ public function __construct(array $params, $username, $password, array $driverOp set_error_handler(static function () { }); try { - if (! $this->_conn->real_connect($params['host'], $username, $password, $dbname, $port, $socket, $flags)) { - throw new MysqliException($this->_conn->connect_error, $this->_conn->sqlstate ?? 'HY000', $this->_conn->connect_errno); + if (! $this->conn->real_connect($params['host'], $username, $password, $dbname, $port, $socket, $flags)) { + throw new MysqliException($this->conn->connect_error, $this->conn->sqlstate ?? 'HY000', $this->conn->connect_errno); } } finally { restore_error_handler(); @@ -78,7 +78,7 @@ public function __construct(array $params, $username, $password, array $driverOp return; } - $this->_conn->set_charset($params['charset']); + $this->conn->set_charset($params['charset']); } /** @@ -90,7 +90,7 @@ public function __construct(array $params, $username, $password, array $driverOp */ public function getWrappedResourceHandle() { - return $this->_conn; + return $this->conn; } /** @@ -103,14 +103,14 @@ public function getWrappedResourceHandle() */ public function getServerVersion() { - $serverInfos = $this->_conn->get_server_info(); + $serverInfos = $this->conn->get_server_info(); if (stripos($serverInfos, 'mariadb') !== false) { return $serverInfos; } - $majorVersion = floor($this->_conn->server_version / 10000); - $minorVersion = floor(($this->_conn->server_version - $majorVersion * 10000) / 100); - $patchVersion = floor($this->_conn->server_version - $majorVersion * 10000 - $minorVersion * 100); + $majorVersion = floor($this->conn->server_version / 10000); + $minorVersion = floor(($this->conn->server_version - $majorVersion * 10000) / 100); + $patchVersion = floor($this->conn->server_version - $majorVersion * 10000 - $minorVersion * 100); return $majorVersion . '.' . $minorVersion . '.' . $patchVersion; } @@ -128,7 +128,7 @@ public function requiresQueryForServerVersion() */ public function prepare($prepareString) { - return new MysqliStatement($this->_conn, $prepareString); + return new MysqliStatement($this->conn, $prepareString); } /** @@ -149,7 +149,7 @@ public function query() */ public function quote($input, $type = ParameterType::STRING) { - return "'" . $this->_conn->escape_string($input) . "'"; + return "'" . $this->conn->escape_string($input) . "'"; } /** @@ -157,11 +157,11 @@ public function quote($input, $type = ParameterType::STRING) */ public function exec($statement) { - if ($this->_conn->query($statement) === false) { - throw new MysqliException($this->_conn->error, $this->_conn->sqlstate, $this->_conn->errno); + if ($this->conn->query($statement) === false) { + throw new MysqliException($this->conn->error, $this->conn->sqlstate, $this->conn->errno); } - return $this->_conn->affected_rows; + return $this->conn->affected_rows; } /** @@ -169,7 +169,7 @@ public function exec($statement) */ public function lastInsertId($name = null) { - return $this->_conn->insert_id; + return $this->conn->insert_id; } /** @@ -177,7 +177,7 @@ public function lastInsertId($name = null) */ public function beginTransaction() { - $this->_conn->query('START TRANSACTION'); + $this->conn->query('START TRANSACTION'); return true; } @@ -187,7 +187,7 @@ public function beginTransaction() */ public function commit() { - return $this->_conn->commit(); + return $this->conn->commit(); } /** @@ -195,7 +195,7 @@ public function commit() */ public function rollBack() { - return $this->_conn->rollback(); + return $this->conn->rollback(); } /** @@ -203,7 +203,7 @@ public function rollBack() */ public function errorCode() { - return $this->_conn->errno; + return $this->conn->errno; } /** @@ -211,7 +211,7 @@ public function errorCode() */ public function errorInfo() { - return $this->_conn->error; + return $this->conn->error; } /** @@ -249,17 +249,17 @@ private function setDriverOptions(array $driverOptions = []) ); } - if (@mysqli_options($this->_conn, $option, $value)) { + if (@mysqli_options($this->conn, $option, $value)) { continue; } $msg = sprintf($exceptionMsg, 'Failed to set', $option, $value); - $msg .= sprintf(', error: %s (%d)', mysqli_error($this->_conn), mysqli_errno($this->_conn)); + $msg .= sprintf(', error: %s (%d)', mysqli_error($this->conn), mysqli_errno($this->conn)); throw new MysqliException( $msg, - $this->_conn->sqlstate, - $this->_conn->errno + $this->conn->sqlstate, + $this->conn->errno ); } } @@ -271,7 +271,7 @@ private function setDriverOptions(array $driverOptions = []) */ public function ping() { - return $this->_conn->ping(); + return $this->conn->ping(); } /** @@ -292,7 +292,7 @@ private function setSecureConnection(array $params) return; } - $this->_conn->ssl_set( + $this->conn->ssl_set( $params['ssl_key'] ?? null, $params['ssl_cert'] ?? null, $params['ssl_ca'] ?? null, diff --git a/lib/Doctrine/DBAL/Event/ConnectionEventArgs.php b/lib/Doctrine/DBAL/Event/ConnectionEventArgs.php index 9492005ad6b..07620e9e40d 100644 --- a/lib/Doctrine/DBAL/Event/ConnectionEventArgs.php +++ b/lib/Doctrine/DBAL/Event/ConnectionEventArgs.php @@ -16,11 +16,11 @@ class ConnectionEventArgs extends EventArgs { /** @var Connection */ - private $_connection; + private $connection; public function __construct(Connection $connection) { - $this->_connection = $connection; + $this->connection = $connection; } /** @@ -28,7 +28,7 @@ public function __construct(Connection $connection) */ public function getConnection() { - return $this->_connection; + return $this->connection; } /** @@ -36,7 +36,7 @@ public function getConnection() */ public function getDriver() { - return $this->_connection->getDriver(); + return $this->connection->getDriver(); } /** @@ -44,7 +44,7 @@ public function getDriver() */ public function getDatabasePlatform() { - return $this->_connection->getDatabasePlatform(); + return $this->connection->getDatabasePlatform(); } /** @@ -52,6 +52,6 @@ public function getDatabasePlatform() */ public function getSchemaManager() { - return $this->_connection->getSchemaManager(); + return $this->connection->getSchemaManager(); } } diff --git a/lib/Doctrine/DBAL/Event/Listeners/MysqlSessionInit.php b/lib/Doctrine/DBAL/Event/Listeners/MysqlSessionInit.php index c16d4aea329..53bc6e36479 100644 --- a/lib/Doctrine/DBAL/Event/Listeners/MysqlSessionInit.php +++ b/lib/Doctrine/DBAL/Event/Listeners/MysqlSessionInit.php @@ -20,14 +20,14 @@ class MysqlSessionInit implements EventSubscriber * * @var string */ - private $_charset; + private $charset; /** * The collation, or FALSE if no collation. * * @var string|bool */ - private $_collation; + private $collation; /** * Configure Charset and Collation options of MySQL Client for each Connection. @@ -37,8 +37,8 @@ class MysqlSessionInit implements EventSubscriber */ public function __construct($charset = 'utf8', $collation = false) { - $this->_charset = $charset; - $this->_collation = $collation; + $this->charset = $charset; + $this->collation = $collation; } /** @@ -46,8 +46,8 @@ public function __construct($charset = 'utf8', $collation = false) */ public function postConnect(ConnectionEventArgs $args) { - $collation = $this->_collation ? ' COLLATE ' . $this->_collation : ''; - $args->getConnection()->executeUpdate('SET NAMES ' . $this->_charset . $collation); + $collation = $this->collation ? ' COLLATE ' . $this->collation : ''; + $args->getConnection()->executeUpdate('SET NAMES ' . $this->charset . $collation); } /** diff --git a/lib/Doctrine/DBAL/Event/SchemaAlterTableAddColumnEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaAlterTableAddColumnEventArgs.php index 551a2eeec44..8ec240a50d8 100644 --- a/lib/Doctrine/DBAL/Event/SchemaAlterTableAddColumnEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaAlterTableAddColumnEventArgs.php @@ -16,22 +16,22 @@ class SchemaAlterTableAddColumnEventArgs extends SchemaEventArgs { /** @var Column */ - private $_column; + private $column; /** @var TableDiff */ - private $_tableDiff; + private $tableDiff; /** @var AbstractPlatform */ - private $_platform; + private $platform; /** @var string[] */ - private $_sql = []; + private $sql = []; public function __construct(Column $column, TableDiff $tableDiff, AbstractPlatform $platform) { - $this->_column = $column; - $this->_tableDiff = $tableDiff; - $this->_platform = $platform; + $this->column = $column; + $this->tableDiff = $tableDiff; + $this->platform = $platform; } /** @@ -39,7 +39,7 @@ public function __construct(Column $column, TableDiff $tableDiff, AbstractPlatfo */ public function getColumn() { - return $this->_column; + return $this->column; } /** @@ -47,7 +47,7 @@ public function getColumn() */ public function getTableDiff() { - return $this->_tableDiff; + return $this->tableDiff; } /** @@ -55,7 +55,7 @@ public function getTableDiff() */ public function getPlatform() { - return $this->_platform; + return $this->platform; } /** @@ -66,9 +66,9 @@ public function getPlatform() public function addSql($sql) { if (is_array($sql)) { - $this->_sql = array_merge($this->_sql, $sql); + $this->sql = array_merge($this->sql, $sql); } else { - $this->_sql[] = $sql; + $this->sql[] = $sql; } return $this; @@ -79,6 +79,6 @@ public function addSql($sql) */ public function getSql() { - return $this->_sql; + return $this->sql; } } diff --git a/lib/Doctrine/DBAL/Event/SchemaAlterTableChangeColumnEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaAlterTableChangeColumnEventArgs.php index bb3875bc3fc..c1283471c2a 100644 --- a/lib/Doctrine/DBAL/Event/SchemaAlterTableChangeColumnEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaAlterTableChangeColumnEventArgs.php @@ -16,22 +16,22 @@ class SchemaAlterTableChangeColumnEventArgs extends SchemaEventArgs { /** @var ColumnDiff */ - private $_columnDiff; + private $columnDiff; /** @var TableDiff */ - private $_tableDiff; + private $tableDiff; /** @var AbstractPlatform */ - private $_platform; + private $platform; /** @var string[] */ - private $_sql = []; + private $sql = []; public function __construct(ColumnDiff $columnDiff, TableDiff $tableDiff, AbstractPlatform $platform) { - $this->_columnDiff = $columnDiff; - $this->_tableDiff = $tableDiff; - $this->_platform = $platform; + $this->columnDiff = $columnDiff; + $this->tableDiff = $tableDiff; + $this->platform = $platform; } /** @@ -39,7 +39,7 @@ public function __construct(ColumnDiff $columnDiff, TableDiff $tableDiff, Abstra */ public function getColumnDiff() { - return $this->_columnDiff; + return $this->columnDiff; } /** @@ -47,7 +47,7 @@ public function getColumnDiff() */ public function getTableDiff() { - return $this->_tableDiff; + return $this->tableDiff; } /** @@ -55,7 +55,7 @@ public function getTableDiff() */ public function getPlatform() { - return $this->_platform; + return $this->platform; } /** @@ -66,9 +66,9 @@ public function getPlatform() public function addSql($sql) { if (is_array($sql)) { - $this->_sql = array_merge($this->_sql, $sql); + $this->sql = array_merge($this->sql, $sql); } else { - $this->_sql[] = $sql; + $this->sql[] = $sql; } return $this; @@ -79,6 +79,6 @@ public function addSql($sql) */ public function getSql() { - return $this->_sql; + return $this->sql; } } diff --git a/lib/Doctrine/DBAL/Event/SchemaAlterTableEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaAlterTableEventArgs.php index a4d411c50c7..de6af93f44e 100644 --- a/lib/Doctrine/DBAL/Event/SchemaAlterTableEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaAlterTableEventArgs.php @@ -15,18 +15,18 @@ class SchemaAlterTableEventArgs extends SchemaEventArgs { /** @var TableDiff */ - private $_tableDiff; + private $tableDiff; /** @var AbstractPlatform */ - private $_platform; + private $platform; /** @var string[] */ - private $_sql = []; + private $sql = []; public function __construct(TableDiff $tableDiff, AbstractPlatform $platform) { - $this->_tableDiff = $tableDiff; - $this->_platform = $platform; + $this->tableDiff = $tableDiff; + $this->platform = $platform; } /** @@ -34,7 +34,7 @@ public function __construct(TableDiff $tableDiff, AbstractPlatform $platform) */ public function getTableDiff() { - return $this->_tableDiff; + return $this->tableDiff; } /** @@ -42,7 +42,7 @@ public function getTableDiff() */ public function getPlatform() { - return $this->_platform; + return $this->platform; } /** @@ -53,9 +53,9 @@ public function getPlatform() public function addSql($sql) { if (is_array($sql)) { - $this->_sql = array_merge($this->_sql, $sql); + $this->sql = array_merge($this->sql, $sql); } else { - $this->_sql[] = $sql; + $this->sql[] = $sql; } return $this; @@ -66,6 +66,6 @@ public function addSql($sql) */ public function getSql() { - return $this->_sql; + return $this->sql; } } diff --git a/lib/Doctrine/DBAL/Event/SchemaAlterTableRemoveColumnEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaAlterTableRemoveColumnEventArgs.php index c4036b679c3..ac57c8c3be6 100644 --- a/lib/Doctrine/DBAL/Event/SchemaAlterTableRemoveColumnEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaAlterTableRemoveColumnEventArgs.php @@ -16,22 +16,22 @@ class SchemaAlterTableRemoveColumnEventArgs extends SchemaEventArgs { /** @var Column */ - private $_column; + private $column; /** @var TableDiff */ - private $_tableDiff; + private $tableDiff; /** @var AbstractPlatform */ - private $_platform; + private $platform; /** @var string[] */ - private $_sql = []; + private $sql = []; public function __construct(Column $column, TableDiff $tableDiff, AbstractPlatform $platform) { - $this->_column = $column; - $this->_tableDiff = $tableDiff; - $this->_platform = $platform; + $this->column = $column; + $this->tableDiff = $tableDiff; + $this->platform = $platform; } /** @@ -39,7 +39,7 @@ public function __construct(Column $column, TableDiff $tableDiff, AbstractPlatfo */ public function getColumn() { - return $this->_column; + return $this->column; } /** @@ -47,7 +47,7 @@ public function getColumn() */ public function getTableDiff() { - return $this->_tableDiff; + return $this->tableDiff; } /** @@ -55,7 +55,7 @@ public function getTableDiff() */ public function getPlatform() { - return $this->_platform; + return $this->platform; } /** @@ -66,9 +66,9 @@ public function getPlatform() public function addSql($sql) { if (is_array($sql)) { - $this->_sql = array_merge($this->_sql, $sql); + $this->sql = array_merge($this->sql, $sql); } else { - $this->_sql[] = $sql; + $this->sql[] = $sql; } return $this; @@ -79,6 +79,6 @@ public function addSql($sql) */ public function getSql() { - return $this->_sql; + return $this->sql; } } diff --git a/lib/Doctrine/DBAL/Event/SchemaAlterTableRenameColumnEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaAlterTableRenameColumnEventArgs.php index 16bcef74454..74f7022becb 100644 --- a/lib/Doctrine/DBAL/Event/SchemaAlterTableRenameColumnEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaAlterTableRenameColumnEventArgs.php @@ -16,29 +16,29 @@ class SchemaAlterTableRenameColumnEventArgs extends SchemaEventArgs { /** @var string */ - private $_oldColumnName; + private $oldColumnName; /** @var Column */ - private $_column; + private $column; /** @var TableDiff */ - private $_tableDiff; + private $tableDiff; /** @var AbstractPlatform */ - private $_platform; + private $platform; /** @var string[] */ - private $_sql = []; + private $sql = []; /** * @param string $oldColumnName */ public function __construct($oldColumnName, Column $column, TableDiff $tableDiff, AbstractPlatform $platform) { - $this->_oldColumnName = $oldColumnName; - $this->_column = $column; - $this->_tableDiff = $tableDiff; - $this->_platform = $platform; + $this->oldColumnName = $oldColumnName; + $this->column = $column; + $this->tableDiff = $tableDiff; + $this->platform = $platform; } /** @@ -46,7 +46,7 @@ public function __construct($oldColumnName, Column $column, TableDiff $tableDiff */ public function getOldColumnName() { - return $this->_oldColumnName; + return $this->oldColumnName; } /** @@ -54,7 +54,7 @@ public function getOldColumnName() */ public function getColumn() { - return $this->_column; + return $this->column; } /** @@ -62,7 +62,7 @@ public function getColumn() */ public function getTableDiff() { - return $this->_tableDiff; + return $this->tableDiff; } /** @@ -70,7 +70,7 @@ public function getTableDiff() */ public function getPlatform() { - return $this->_platform; + return $this->platform; } /** @@ -81,9 +81,9 @@ public function getPlatform() public function addSql($sql) { if (is_array($sql)) { - $this->_sql = array_merge($this->_sql, $sql); + $this->sql = array_merge($this->sql, $sql); } else { - $this->_sql[] = $sql; + $this->sql[] = $sql; } return $this; @@ -94,6 +94,6 @@ public function addSql($sql) */ public function getSql() { - return $this->_sql; + return $this->sql; } } diff --git a/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php index f311c22f2f9..906ba1d3487 100644 --- a/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php @@ -14,23 +14,23 @@ class SchemaColumnDefinitionEventArgs extends SchemaEventArgs { /** @var Column|null */ - private $_column = null; + private $column = null; /** * Raw column data as fetched from the database. * * @var mixed[] */ - private $_tableColumn; + private $tableColumn; /** @var string */ - private $_table; + private $table; /** @var string */ - private $_database; + private $database; /** @var Connection */ - private $_connection; + private $connection; /** * @param mixed[] $tableColumn @@ -39,10 +39,10 @@ class SchemaColumnDefinitionEventArgs extends SchemaEventArgs */ public function __construct(array $tableColumn, $table, $database, Connection $connection) { - $this->_tableColumn = $tableColumn; - $this->_table = $table; - $this->_database = $database; - $this->_connection = $connection; + $this->tableColumn = $tableColumn; + $this->table = $table; + $this->database = $database; + $this->connection = $connection; } /** @@ -53,7 +53,7 @@ public function __construct(array $tableColumn, $table, $database, Connection $c */ public function setColumn(?Column $column = null) { - $this->_column = $column; + $this->column = $column; return $this; } @@ -63,7 +63,7 @@ public function setColumn(?Column $column = null) */ public function getColumn() { - return $this->_column; + return $this->column; } /** @@ -71,7 +71,7 @@ public function getColumn() */ public function getTableColumn() { - return $this->_tableColumn; + return $this->tableColumn; } /** @@ -79,7 +79,7 @@ public function getTableColumn() */ public function getTable() { - return $this->_table; + return $this->table; } /** @@ -87,7 +87,7 @@ public function getTable() */ public function getDatabase() { - return $this->_database; + return $this->database; } /** @@ -95,7 +95,7 @@ public function getDatabase() */ public function getConnection() { - return $this->_connection; + return $this->connection; } /** @@ -103,6 +103,6 @@ public function getConnection() */ public function getDatabasePlatform() { - return $this->_connection->getDatabasePlatform(); + return $this->connection->getDatabasePlatform(); } } diff --git a/lib/Doctrine/DBAL/Event/SchemaCreateTableColumnEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaCreateTableColumnEventArgs.php index fac12845eac..5e1d9afe0df 100644 --- a/lib/Doctrine/DBAL/Event/SchemaCreateTableColumnEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaCreateTableColumnEventArgs.php @@ -16,22 +16,22 @@ class SchemaCreateTableColumnEventArgs extends SchemaEventArgs { /** @var Column */ - private $_column; + private $column; /** @var Table */ - private $_table; + private $table; /** @var AbstractPlatform */ - private $_platform; + private $platform; /** @var string[] */ - private $_sql = []; + private $sql = []; public function __construct(Column $column, Table $table, AbstractPlatform $platform) { - $this->_column = $column; - $this->_table = $table; - $this->_platform = $platform; + $this->column = $column; + $this->table = $table; + $this->platform = $platform; } /** @@ -39,7 +39,7 @@ public function __construct(Column $column, Table $table, AbstractPlatform $plat */ public function getColumn() { - return $this->_column; + return $this->column; } /** @@ -47,7 +47,7 @@ public function getColumn() */ public function getTable() { - return $this->_table; + return $this->table; } /** @@ -55,7 +55,7 @@ public function getTable() */ public function getPlatform() { - return $this->_platform; + return $this->platform; } /** @@ -66,9 +66,9 @@ public function getPlatform() public function addSql($sql) { if (is_array($sql)) { - $this->_sql = array_merge($this->_sql, $sql); + $this->sql = array_merge($this->sql, $sql); } else { - $this->_sql[] = $sql; + $this->sql[] = $sql; } return $this; @@ -79,6 +79,6 @@ public function addSql($sql) */ public function getSql() { - return $this->_sql; + return $this->sql; } } diff --git a/lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php index 7f2afc4f7fa..fc8ab830460 100644 --- a/lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php @@ -16,19 +16,19 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs { /** @var Table */ - private $_table; + private $table; /** @var Column[] */ - private $_columns; + private $columns; /** @var mixed[] */ - private $_options; + private $options; /** @var AbstractPlatform */ - private $_platform; + private $platform; /** @var string[] */ - private $_sql = []; + private $sql = []; /** * @param Column[] $columns @@ -36,10 +36,10 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs */ public function __construct(Table $table, array $columns, array $options, AbstractPlatform $platform) { - $this->_table = $table; - $this->_columns = $columns; - $this->_options = $options; - $this->_platform = $platform; + $this->table = $table; + $this->columns = $columns; + $this->options = $options; + $this->platform = $platform; } /** @@ -47,7 +47,7 @@ public function __construct(Table $table, array $columns, array $options, Abstra */ public function getTable() { - return $this->_table; + return $this->table; } /** @@ -55,7 +55,7 @@ public function getTable() */ public function getColumns() { - return $this->_columns; + return $this->columns; } /** @@ -63,7 +63,7 @@ public function getColumns() */ public function getOptions() { - return $this->_options; + return $this->options; } /** @@ -71,7 +71,7 @@ public function getOptions() */ public function getPlatform() { - return $this->_platform; + return $this->platform; } /** @@ -82,9 +82,9 @@ public function getPlatform() public function addSql($sql) { if (is_array($sql)) { - $this->_sql = array_merge($this->_sql, $sql); + $this->sql = array_merge($this->sql, $sql); } else { - $this->_sql[] = $sql; + $this->sql[] = $sql; } return $this; @@ -95,6 +95,6 @@ public function addSql($sql) */ public function getSql() { - return $this->_sql; + return $this->sql; } } diff --git a/lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php index cc77805ca83..97888b3f60a 100644 --- a/lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php @@ -15,13 +15,13 @@ class SchemaDropTableEventArgs extends SchemaEventArgs { /** @var string|Table */ - private $_table; + private $table; /** @var AbstractPlatform */ - private $_platform; + private $platform; /** @var string|null */ - private $_sql = null; + private $sql = null; /** * @param string|Table $table @@ -34,8 +34,8 @@ public function __construct($table, AbstractPlatform $platform) throw new InvalidArgumentException('SchemaDropTableEventArgs expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.'); } - $this->_table = $table; - $this->_platform = $platform; + $this->table = $table; + $this->platform = $platform; } /** @@ -43,7 +43,7 @@ public function __construct($table, AbstractPlatform $platform) */ public function getTable() { - return $this->_table; + return $this->table; } /** @@ -51,7 +51,7 @@ public function getTable() */ public function getPlatform() { - return $this->_platform; + return $this->platform; } /** @@ -61,7 +61,7 @@ public function getPlatform() */ public function setSql($sql) { - $this->_sql = $sql; + $this->sql = $sql; return $this; } @@ -71,6 +71,6 @@ public function setSql($sql) */ public function getSql() { - return $this->_sql; + return $this->sql; } } diff --git a/lib/Doctrine/DBAL/Event/SchemaEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaEventArgs.php index a47bde72916..30e1e65e24e 100644 --- a/lib/Doctrine/DBAL/Event/SchemaEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaEventArgs.php @@ -12,14 +12,14 @@ class SchemaEventArgs extends EventArgs { /** @var bool */ - private $_preventDefault = false; + private $preventDefault = false; /** * @return \Doctrine\DBAL\Event\SchemaEventArgs */ public function preventDefault() { - $this->_preventDefault = true; + $this->preventDefault = true; return $this; } @@ -29,6 +29,6 @@ public function preventDefault() */ public function isDefaultPrevented() { - return $this->_preventDefault; + return $this->preventDefault; } } diff --git a/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php index ec0d94aecbf..f89864158ce 100644 --- a/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php @@ -14,20 +14,20 @@ class SchemaIndexDefinitionEventArgs extends SchemaEventArgs { /** @var Index|null */ - private $_index = null; + private $index = null; /** * Raw index data as fetched from the database. * * @var mixed[] */ - private $_tableIndex; + private $tableIndex; /** @var string */ - private $_table; + private $table; /** @var Connection */ - private $_connection; + private $connection; /** * @param mixed[] $tableIndex @@ -35,9 +35,9 @@ class SchemaIndexDefinitionEventArgs extends SchemaEventArgs */ public function __construct(array $tableIndex, $table, Connection $connection) { - $this->_tableIndex = $tableIndex; - $this->_table = $table; - $this->_connection = $connection; + $this->tableIndex = $tableIndex; + $this->table = $table; + $this->connection = $connection; } /** @@ -47,7 +47,7 @@ public function __construct(array $tableIndex, $table, Connection $connection) */ public function setIndex(?Index $index = null) { - $this->_index = $index; + $this->index = $index; return $this; } @@ -57,7 +57,7 @@ public function setIndex(?Index $index = null) */ public function getIndex() { - return $this->_index; + return $this->index; } /** @@ -65,7 +65,7 @@ public function getIndex() */ public function getTableIndex() { - return $this->_tableIndex; + return $this->tableIndex; } /** @@ -73,7 +73,7 @@ public function getTableIndex() */ public function getTable() { - return $this->_table; + return $this->table; } /** @@ -81,7 +81,7 @@ public function getTable() */ public function getConnection() { - return $this->_connection; + return $this->connection; } /** @@ -89,6 +89,6 @@ public function getConnection() */ public function getDatabasePlatform() { - return $this->_connection->getDatabasePlatform(); + return $this->connection->getDatabasePlatform(); } } diff --git a/lib/Doctrine/DBAL/Schema/View.php b/lib/Doctrine/DBAL/Schema/View.php index 6170f63680b..bee0a019a0e 100644 --- a/lib/Doctrine/DBAL/Schema/View.php +++ b/lib/Doctrine/DBAL/Schema/View.php @@ -10,7 +10,7 @@ class View extends AbstractAsset { /** @var string */ - private $_sql; + private $sql; /** * @param string $name @@ -19,7 +19,7 @@ class View extends AbstractAsset public function __construct($name, $sql) { $this->_setName($name); - $this->_sql = $sql; + $this->sql = $sql; } /** @@ -27,6 +27,6 @@ public function __construct($name, $sql) */ public function getSql() { - return $this->_sql; + return $this->sql; } } From 6350b9df670086b5e0d0b9f45060c73a82f0ad45 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Mon, 1 Oct 2018 20:46:36 -0700 Subject: [PATCH 35/76] Replaced class names represented by strings with the ::class syntax --- lib/Doctrine/DBAL/DBALException.php | 6 +-- lib/Doctrine/DBAL/Driver/PDOConnection.php | 2 +- lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php | 7 +-- lib/Doctrine/DBAL/DriverManager.php | 37 +++++++++----- .../DBAL/Platforms/SQLAnywherePlatform.php | 6 +-- lib/Doctrine/DBAL/Portability/Statement.php | 7 +-- .../Console/Command/ReservedWordsCommand.php | 51 ++++++++++++------- .../Tests/DBAL/Portability/StatementTest.php | 7 +-- 8 files changed, 75 insertions(+), 48 deletions(-) diff --git a/lib/Doctrine/DBAL/DBALException.php b/lib/Doctrine/DBAL/DBALException.php index 637e5d341ea..15bac7f0f66 100644 --- a/lib/Doctrine/DBAL/DBALException.php +++ b/lib/Doctrine/DBAL/DBALException.php @@ -35,8 +35,7 @@ public static function notSupported($method) public static function invalidPlatformSpecified() : self { return new self( - "Invalid 'platform' option specified, need to give an instance of " . - '\Doctrine\DBAL\Platforms\AbstractPlatform.' + "Invalid 'platform' option specified, need to give an instance of " . AbstractPlatform::class . '.' ); } @@ -217,8 +216,7 @@ public static function invalidWrapperClass($wrapperClass) */ public static function invalidDriverClass($driverClass) { - return new self("The given 'driverClass' " . $driverClass . ' has to implement the ' . - '\Doctrine\DBAL\Driver interface.'); + return new self("The given 'driverClass' " . $driverClass . ' has to implement the ' . Driver::class . ' interface.'); } /** diff --git a/lib/Doctrine/DBAL/Driver/PDOConnection.php b/lib/Doctrine/DBAL/Driver/PDOConnection.php index f94716e003f..3368c0d94dc 100644 --- a/lib/Doctrine/DBAL/Driver/PDOConnection.php +++ b/lib/Doctrine/DBAL/Driver/PDOConnection.php @@ -25,7 +25,7 @@ public function __construct($dsn, $user = null, $password = null, ?array $option { try { parent::__construct($dsn, $user, $password, $options); - $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, ['Doctrine\DBAL\Driver\PDOStatement', []]); + $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, [PDOStatement::class, []]); $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (\PDOException $exception) { throw new PDOException($exception); diff --git a/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php b/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php index a28648562a5..7a28b831027 100644 --- a/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php @@ -5,6 +5,7 @@ use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\AbstractSQLiteDriver; use Doctrine\DBAL\Driver\PDOConnection; +use Doctrine\DBAL\Platforms\SqlitePlatform; use PDOException; use function array_merge; @@ -15,9 +16,9 @@ class Driver extends AbstractSQLiteDriver { /** @var mixed[] */ protected $_userDefinedFunctions = [ - 'sqrt' => ['callback' => ['Doctrine\DBAL\Platforms\SqlitePlatform', 'udfSqrt'], 'numArgs' => 1], - 'mod' => ['callback' => ['Doctrine\DBAL\Platforms\SqlitePlatform', 'udfMod'], 'numArgs' => 2], - 'locate' => ['callback' => ['Doctrine\DBAL\Platforms\SqlitePlatform', 'udfLocate'], 'numArgs' => -1], + 'sqrt' => ['callback' => [SqlitePlatform::class, 'udfSqrt'], 'numArgs' => 1], + 'mod' => ['callback' => [SqlitePlatform::class, 'udfMod'], 'numArgs' => 2], + 'locate' => ['callback' => [SqlitePlatform::class, 'udfLocate'], 'numArgs' => -1], ]; /** diff --git a/lib/Doctrine/DBAL/DriverManager.php b/lib/Doctrine/DBAL/DriverManager.php index 4afe0add837..658123199c0 100644 --- a/lib/Doctrine/DBAL/DriverManager.php +++ b/lib/Doctrine/DBAL/DriverManager.php @@ -3,6 +3,17 @@ namespace Doctrine\DBAL; use Doctrine\Common\EventManager; +use Doctrine\DBAL\Driver\DrizzlePDOMySql\Driver as DrizzlePDOMySQLDriver; +use Doctrine\DBAL\Driver\IBMDB2\DB2Driver; +use Doctrine\DBAL\Driver\Mysqli\Driver as MySQLiDriver; +use Doctrine\DBAL\Driver\OCI8\Driver as OCI8Driver; +use Doctrine\DBAL\Driver\PDOMySql\Driver as PDOMySQLDriver; +use Doctrine\DBAL\Driver\PDOOracle\Driver as PDOOCIDriver; +use Doctrine\DBAL\Driver\PDOPgSql\Driver as PDOPgSQLDriver; +use Doctrine\DBAL\Driver\PDOSqlite\Driver as PDOSQLiteDriver; +use Doctrine\DBAL\Driver\PDOSqlsrv\Driver as PDOSQLSrvDriver; +use Doctrine\DBAL\Driver\SQLAnywhere\Driver as SQLAnywhereDriver; +use Doctrine\DBAL\Driver\SQLSrv\Driver as SQLSrvDriver; use PDO; use function array_keys; use function array_map; @@ -31,17 +42,17 @@ final class DriverManager * @var string[] */ private static $_driverMap = [ - 'pdo_mysql' => 'Doctrine\DBAL\Driver\PDOMySql\Driver', - 'pdo_sqlite' => 'Doctrine\DBAL\Driver\PDOSqlite\Driver', - 'pdo_pgsql' => 'Doctrine\DBAL\Driver\PDOPgSql\Driver', - 'pdo_oci' => 'Doctrine\DBAL\Driver\PDOOracle\Driver', - 'oci8' => 'Doctrine\DBAL\Driver\OCI8\Driver', - 'ibm_db2' => 'Doctrine\DBAL\Driver\IBMDB2\DB2Driver', - 'pdo_sqlsrv' => 'Doctrine\DBAL\Driver\PDOSqlsrv\Driver', - 'mysqli' => 'Doctrine\DBAL\Driver\Mysqli\Driver', - 'drizzle_pdo_mysql' => 'Doctrine\DBAL\Driver\DrizzlePDOMySql\Driver', - 'sqlanywhere' => 'Doctrine\DBAL\Driver\SQLAnywhere\Driver', - 'sqlsrv' => 'Doctrine\DBAL\Driver\SQLSrv\Driver', + 'pdo_mysql' => PDOMySQLDriver::class, + 'pdo_sqlite' => PDOSQLiteDriver::class, + 'pdo_pgsql' => PDOPgSQLDriver::class, + 'pdo_oci' => PDOOCIDriver::class, + 'oci8' => OCI8Driver::class, + 'ibm_db2' => DB2Driver::class, + 'pdo_sqlsrv' => PDOSQLSrvDriver::class, + 'mysqli' => MySQLiDriver::class, + 'drizzle_pdo_mysql' => DrizzlePDOMySQLDriver::class, + 'sqlanywhere' => SQLAnywhereDriver::class, + 'sqlsrv' => SQLSrvDriver::class, ]; /** @@ -172,7 +183,7 @@ public static function getConnection( $driver = new $className(); - $wrapperClass = 'Doctrine\DBAL\Connection'; + $wrapperClass = Connection::class; if (isset($params['wrapperClass'])) { if (! is_subclass_of($params['wrapperClass'], $wrapperClass)) { throw DBALException::invalidWrapperClass($params['wrapperClass']); @@ -217,7 +228,7 @@ private static function _checkParams(array $params) : void throw DBALException::unknownDriver($params['driver'], array_keys(self::$_driverMap)); } - if (isset($params['driverClass']) && ! in_array('Doctrine\DBAL\Driver', class_implements($params['driverClass'], true))) { + if (isset($params['driverClass']) && ! in_array(Driver::class, class_implements($params['driverClass'], true))) { throw DBALException::invalidDriverClass($params['driverClass']); } } diff --git a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php index e0aad4ed55e..b538881a967 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php @@ -550,8 +550,7 @@ public function getDropIndexSQL($index, $table = null) if (! is_string($index)) { throw new InvalidArgumentException( - 'SQLAnywherePlatform::getDropIndexSQL() expects $index parameter to be string or ' . - '\Doctrine\DBAL\Schema\Index.' + 'SQLAnywherePlatform::getDropIndexSQL() expects $index parameter to be string or ' . Index::class . '.' ); } @@ -565,8 +564,7 @@ public function getDropIndexSQL($index, $table = null) if (! is_string($table)) { throw new InvalidArgumentException( - 'SQLAnywherePlatform::getDropIndexSQL() expects $table parameter to be string or ' . - '\Doctrine\DBAL\Schema\Table.' + 'SQLAnywherePlatform::getDropIndexSQL() expects $table parameter to be string or ' . Index::class . '.' ); } diff --git a/lib/Doctrine/DBAL/Portability/Statement.php b/lib/Doctrine/DBAL/Portability/Statement.php index b7de39369c9..1049ff1d633 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\Statement as DriverStatement; use Doctrine\DBAL\Driver\StatementIterator; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; @@ -16,12 +17,12 @@ * * @link www.doctrine-project.org */ -class Statement implements IteratorAggregate, \Doctrine\DBAL\Driver\Statement +class Statement implements IteratorAggregate, DriverStatement { /** @var int */ private $portability; - /** @var \Doctrine\DBAL\Driver\Statement */ + /** @var DriverStatement */ private $stmt; /** @var int */ @@ -33,7 +34,7 @@ class Statement implements IteratorAggregate, \Doctrine\DBAL\Driver\Statement /** * Wraps Statement and applies portability measures. * - * @param \Doctrine\DBAL\Driver\Statement $stmt + * @param DriverStatement $stmt */ public function __construct($stmt, Connection $conn) { diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php index edeb1f448a3..fb8b6b5c46f 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php @@ -3,7 +3,24 @@ namespace Doctrine\DBAL\Tools\Console\Command; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Platforms\Keywords\DB2Keywords; +use Doctrine\DBAL\Platforms\Keywords\MySQL57Keywords; +use Doctrine\DBAL\Platforms\Keywords\MySQL80Keywords; +use Doctrine\DBAL\Platforms\Keywords\MySQLKeywords; +use Doctrine\DBAL\Platforms\Keywords\OracleKeywords; +use Doctrine\DBAL\Platforms\Keywords\PostgreSQL91Keywords; +use Doctrine\DBAL\Platforms\Keywords\PostgreSQL92Keywords; +use Doctrine\DBAL\Platforms\Keywords\PostgreSQLKeywords; use Doctrine\DBAL\Platforms\Keywords\ReservedKeywordsValidator; +use Doctrine\DBAL\Platforms\Keywords\SQLAnywhere11Keywords; +use Doctrine\DBAL\Platforms\Keywords\SQLAnywhere12Keywords; +use Doctrine\DBAL\Platforms\Keywords\SQLAnywhere16Keywords; +use Doctrine\DBAL\Platforms\Keywords\SQLAnywhereKeywords; +use Doctrine\DBAL\Platforms\Keywords\SQLiteKeywords; +use Doctrine\DBAL\Platforms\Keywords\SQLServer2005Keywords; +use Doctrine\DBAL\Platforms\Keywords\SQLServer2008Keywords; +use Doctrine\DBAL\Platforms\Keywords\SQLServer2012Keywords; +use Doctrine\DBAL\Platforms\Keywords\SQLServerKeywords; use Doctrine\DBAL\Schema\Schema; use InvalidArgumentException; use Symfony\Component\Console\Command\Command; @@ -18,23 +35,23 @@ class ReservedWordsCommand extends Command { /** @var string[] */ private $keywordListClasses = [ - 'mysql' => 'Doctrine\DBAL\Platforms\Keywords\MySQLKeywords', - 'mysql57' => 'Doctrine\DBAL\Platforms\Keywords\MySQL57Keywords', - 'mysql80' => 'Doctrine\DBAL\Platforms\Keywords\MySQL80Keywords', - 'sqlserver' => 'Doctrine\DBAL\Platforms\Keywords\SQLServerKeywords', - 'sqlserver2005' => 'Doctrine\DBAL\Platforms\Keywords\SQLServer2005Keywords', - 'sqlserver2008' => 'Doctrine\DBAL\Platforms\Keywords\SQLServer2008Keywords', - 'sqlserver2012' => 'Doctrine\DBAL\Platforms\Keywords\SQLServer2012Keywords', - 'sqlite' => 'Doctrine\DBAL\Platforms\Keywords\SQLiteKeywords', - 'pgsql' => 'Doctrine\DBAL\Platforms\Keywords\PostgreSQLKeywords', - 'pgsql91' => 'Doctrine\DBAL\Platforms\Keywords\PostgreSQL91Keywords', - 'pgsql92' => 'Doctrine\DBAL\Platforms\Keywords\PostgreSQL92Keywords', - 'oracle' => 'Doctrine\DBAL\Platforms\Keywords\OracleKeywords', - 'db2' => 'Doctrine\DBAL\Platforms\Keywords\DB2Keywords', - 'sqlanywhere' => 'Doctrine\DBAL\Platforms\Keywords\SQLAnywhereKeywords', - 'sqlanywhere11' => 'Doctrine\DBAL\Platforms\Keywords\SQLAnywhere11Keywords', - 'sqlanywhere12' => 'Doctrine\DBAL\Platforms\Keywords\SQLAnywhere12Keywords', - 'sqlanywhere16' => 'Doctrine\DBAL\Platforms\Keywords\SQLAnywhere16Keywords', + 'mysql' => MySQLKeywords::class, + 'mysql57' => MySQL57Keywords::class, + 'mysql80' => MySQL80Keywords::class, + 'sqlserver' => SQLServerKeywords::class, + 'sqlserver2005' => SQLServer2005Keywords::class, + 'sqlserver2008' => SQLServer2008Keywords::class, + 'sqlserver2012' => SQLServer2012Keywords::class, + 'sqlite' => SQLiteKeywords::class, + 'pgsql' => PostgreSQLKeywords::class, + 'pgsql91' => PostgreSQL91Keywords::class, + 'pgsql92' => PostgreSQL92Keywords::class, + 'oracle' => OracleKeywords::class, + 'db2' => DB2Keywords::class, + 'sqlanywhere' => SQLAnywhereKeywords::class, + 'sqlanywhere11' => SQLAnywhere11Keywords::class, + 'sqlanywhere12' => SQLAnywhere12Keywords::class, + 'sqlanywhere16' => SQLAnywhere16Keywords::class, ]; /** diff --git a/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php b/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php index 88676130a52..b4d5168d497 100644 --- a/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Portability; +use Doctrine\DBAL\Driver\Statement as DriverStatement; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Portability\Connection; @@ -19,7 +20,7 @@ class StatementTest extends DbalTestCase /** @var Statement */ protected $stmt; - /** @var \Doctrine\DBAL\Driver\Statement|PHPUnit_Framework_MockObject_MockObject */ + /** @var DriverStatement|PHPUnit_Framework_MockObject_MockObject */ protected $wrappedStmt; /** @@ -170,13 +171,13 @@ protected function createConnection() /** * @return Statement */ - protected function createStatement(\Doctrine\DBAL\Driver\Statement $wrappedStatement, Connection $connection) + protected function createStatement(DriverStatement $wrappedStatement, Connection $connection) { return new Statement($wrappedStatement, $connection); } /** - * @return \Doctrine\DBAL\Driver\Statement|PHPUnit_Framework_MockObject_MockObject + * @return DriverStatement|PHPUnit_Framework_MockObject_MockObject */ protected function createWrappedStatement() { From 4d509109c6421b614fc1de7a466450c541571a32 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Mon, 1 Oct 2018 21:05:18 -0700 Subject: [PATCH 36/76] Validate pull requests by PHPCS, do not allow failure --- .travis.yml | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0162cd7808d..461a52b872f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -53,7 +53,6 @@ after_script: jobs: allow_failures: - php: nightly - - stage: Coding standard - env: DB=pgsql POSTGRESQL_VERSION=11.0 exclude: @@ -431,22 +430,7 @@ jobs: install: travis_retry composer update --prefer-dist script: vendor/bin/phpstan analyse - - stage: Pull request coding standard - if: type = pull_request - php: 7.1 - install: travis_retry composer install --prefer-dist - script: - - | - if [ $TRAVIS_BRANCH != "master" ]; then - git remote set-branches --add origin $TRAVIS_BRANCH; - git fetch origin $TRAVIS_BRANCH; - fi - - git merge-base origin/$TRAVIS_BRANCH $TRAVIS_PULL_REQUEST_SHA || git fetch origin +refs/pull/$TRAVIS_PULL_REQUEST/merge --unshallow - - wget https://github.com/diff-sniffer/git/releases/download/0.2.0/git-phpcs.phar - - php git-phpcs.phar origin/$TRAVIS_BRANCH...$TRAVIS_PULL_REQUEST_SHA - - stage: Coding standard - if: NOT type = pull_request php: 7.1 install: travis_retry composer install --prefer-dist script: From 66685dc4ff624bd40795eab6c0f5de7fe2b15786 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Tue, 2 Oct 2018 23:22:04 -0700 Subject: [PATCH 37/76] Test against the latest stable sqlsrv extension --- .appveyor.yml | 4 ++-- tests/travis/install-mssql-pdo_sqlsrv.sh | 2 +- tests/travis/install-mssql-sqlsrv.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 546ae92e554..636c269d846 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -68,8 +68,8 @@ 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 MSSQL DLL's - $DLLVersion = "5.2.0" + # Get and install the latest stable sqlsrv DLL's + $DLLVersion = (Invoke-WebRequest "https://pecl.php.net/rest/r/sqlsrv/stable.txt").Content 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" diff --git a/tests/travis/install-mssql-pdo_sqlsrv.sh b/tests/travis/install-mssql-pdo_sqlsrv.sh index 4f4384607c4..e9165549f6f 100644 --- a/tests/travis/install-mssql-pdo_sqlsrv.sh +++ b/tests/travis/install-mssql-pdo_sqlsrv.sh @@ -3,4 +3,4 @@ set -ex echo "Installing extension" -pecl install pdo_sqlsrv-5.2.0 +pecl install pdo_sqlsrv diff --git a/tests/travis/install-mssql-sqlsrv.sh b/tests/travis/install-mssql-sqlsrv.sh index 2921d5a922a..dede9458f7c 100644 --- a/tests/travis/install-mssql-sqlsrv.sh +++ b/tests/travis/install-mssql-sqlsrv.sh @@ -3,4 +3,4 @@ set -ex echo "Installing extension" -pecl install sqlsrv-5.2.0 +pecl install sqlsrv From 5110a1929b1a448b5cd463058339bd27f3727b75 Mon Sep 17 00:00:00 2001 From: Bez Hermoso Date: Wed, 3 Oct 2018 19:13:47 -0700 Subject: [PATCH 38/76] Implement {Configuration#getSchemaAssetsFilter} --- lib/Doctrine/DBAL/Configuration.php | 37 +++++ .../DBAL/Schema/AbstractSchemaManager.php | 12 +- .../DBAL/Schema/DB2SchemaManagerTest.php | 136 ++++++++++++++++++ 3 files changed, 176 insertions(+), 9 deletions(-) diff --git a/lib/Doctrine/DBAL/Configuration.php b/lib/Doctrine/DBAL/Configuration.php index c05a2c4bcfa..0e34e87dcea 100644 --- a/lib/Doctrine/DBAL/Configuration.php +++ b/lib/Doctrine/DBAL/Configuration.php @@ -4,6 +4,8 @@ use Doctrine\Common\Cache\Cache; use Doctrine\DBAL\Logging\SQLLogger; +use Doctrine\DBAL\Schema\AbstractAsset; +use function preg_match; /** * Configuration container for the Doctrine DBAL. @@ -75,6 +77,11 @@ public function setResultCacheImpl(Cache $cacheImpl) public function setFilterSchemaAssetsExpression($filterExpression) { $this->_attributes['filterSchemaAssetsExpression'] = $filterExpression; + if ($filterExpression) { + $this->_attributes['filterSchemaAssetsExpressionCallable'] = $this->buildSchemaAssetsFilterFromExpression($filterExpression); + } else { + $this->_attributes['filterSchemaAssetsExpressionCallable'] = null; + } } /** @@ -87,6 +94,36 @@ public function getFilterSchemaAssetsExpression() return $this->_attributes['filterSchemaAssetsExpression'] ?? null; } + /** + * @param string $filterExpression + */ + private function buildSchemaAssetsFilterFromExpression($filterExpression) : callable + { + return static function ($assetName) use ($filterExpression) { + if ($assetName instanceof AbstractAsset) { + $assetName = $assetName->getName(); + } + return preg_match($filterExpression, $assetName); + }; + } + + /** + * Sets the callable to use to filter schema assets. + */ + public function setSchemaAssetsFilter(?callable $callable = null) : ?callable + { + $this->_attributes['filterSchemaAssetsExpression'] = null; + return $this->_attributes['filterSchemaAssetsExpressionCallable'] = $callable; + } + + /** + * Returns the callable to use to filter schema assets. + */ + public function getSchemaAssetsFilter() : ?callable + { + return $this->_attributes['filterSchemaAssetsExpressionCallable'] ?? null; + } + /** * Sets the default auto-commit mode for connections. * diff --git a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php index cacb0acddd5..0858e6771f1 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php @@ -219,18 +219,12 @@ public function listTableNames() */ protected function filterAssetNames($assetNames) { - $filterExpr = $this->getFilterSchemaAssetsExpression(); - if (! $filterExpr) { + $filter = $this->_conn->getConfiguration()->getSchemaAssetsFilter(); + if (! $filter) { return $assetNames; } - return array_values( - array_filter($assetNames, static function ($assetName) use ($filterExpr) { - $assetName = $assetName instanceof AbstractAsset ? $assetName->getName() : $assetName; - - return preg_match($filterExpr, $assetName); - }) - ); + return array_values(array_filter($assetNames, $filter)); } /** diff --git a/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php index 053ead6c1bc..676c02cd413 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php @@ -10,6 +10,7 @@ use Doctrine\DBAL\Schema\DB2SchemaManager; use PHPUnit\Framework\TestCase; use PHPUnit_Framework_MockObject_MockObject; +use function in_array; /** * @covers \Doctrine\DBAL\Schema\DB2SchemaManager @@ -60,4 +61,139 @@ public function testListTableNamesFiltersAssetNamesCorrectly() $this->manager->listTableNames() ); } + + /** + * @return void + * + * @group DBAL-2701 + */ + public function testAssetFilteringSetsACallable() + { + $filterExpression = '/^(?!T_)/'; + $this->conn->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); + $this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue([ + ['name' => 'FOO'], + ['name' => 'T_FOO'], + ['name' => 'BAR'], + ['name' => 'T_BAR'], + ])); + + self::assertSame( + [ + 'FOO', + 'BAR', + ], + $this->manager->listTableNames() + ); + + $callable = $this->conn->getConfiguration()->getSchemaAssetsFilter(); + $this->assertInternalType('callable', $callable); + + // BC check: Test that regexp expression is still preserved & accessible. + $this->assertEquals($filterExpression, $this->conn->getConfiguration()->getFilterSchemaAssetsExpression()); + } + + /** + * @return void + */ + public function testListTableNamesFiltersAssetNamesCorrectlyWithCallable() + { + $accepted = ['T_FOO', 'T_BAR']; + $this->conn->getConfiguration()->setSchemaAssetsFilter(static function ($assetName) use ($accepted) { + return in_array($assetName, $accepted); + }); + $this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue([ + ['name' => 'FOO'], + ['name' => 'T_FOO'], + ['name' => 'BAR'], + ['name' => 'T_BAR'], + ])); + + self::assertSame( + [ + 'T_FOO', + 'T_BAR', + ], + $this->manager->listTableNames() + ); + + $this->assertNull($this->conn->getConfiguration()->getFilterSchemaAssetsExpression()); + } + + /** + * @return void + */ + public function testSettingNullExpressionWillResetCallable() + { + $accepted = ['T_FOO', 'T_BAR']; + $this->conn->getConfiguration()->setSchemaAssetsFilter(static function ($assetName) use ($accepted) { + return in_array($assetName, $accepted); + }); + $this->conn->expects($this->atLeastOnce())->method('fetchAll')->will($this->returnValue([ + ['name' => 'FOO'], + ['name' => 'T_FOO'], + ['name' => 'BAR'], + ['name' => 'T_BAR'], + ])); + + self::assertSame( + [ + 'T_FOO', + 'T_BAR', + ], + $this->manager->listTableNames() + ); + + $this->conn->getConfiguration()->setFilterSchemaAssetsExpression(null); + + self::assertSame( + [ + 'FOO', + 'T_FOO', + 'BAR', + 'T_BAR', + ], + $this->manager->listTableNames() + ); + + $this->assertNull($this->conn->getConfiguration()->getSchemaAssetsFilter()); + } + + /** + * @return void + */ + public function testSettingNullAsCallableClearsExpression() + { + $filterExpression = '/^(?!T_)/'; + $this->conn->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); + + $this->conn->expects($this->exactly(2))->method('fetchAll')->will($this->returnValue([ + ['name' => 'FOO'], + ['name' => 'T_FOO'], + ['name' => 'BAR'], + ['name' => 'T_BAR'], + ])); + + self::assertSame( + [ + 'FOO', + 'BAR', + ], + $this->manager->listTableNames() + ); + + $this->conn->getConfiguration()->setSchemaAssetsFilter(null); + + self::assertSame( + [ + 'FOO', + 'T_FOO', + 'BAR', + 'T_BAR', + ], + $this->manager->listTableNames() + ); + + $this->assertNull($this->conn->getConfiguration()->getFilterSchemaAssetsExpression()); + } } From 423b03d57254765b15a4a11735d3298213438bfb Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Mon, 1 Oct 2018 22:57:05 -0700 Subject: [PATCH 39/76] Implemented proper escaping of string literals in platforms and schema managers --- .../DBAL/Platforms/DrizzlePlatform.php | 18 +++---- .../DBAL/Platforms/PostgreSqlPlatform.php | 2 +- lib/Doctrine/DBAL/Schema/DB2SchemaManager.php | 2 +- .../DBAL/Schema/SqliteSchemaManager.php | 54 +++++++++++-------- .../DBAL/Schema/DB2SchemaManagerTest.php | 4 +- 5 files changed, 46 insertions(+), 34 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php b/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php index ad148201580..2ba8c03b3b3 100644 --- a/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php @@ -326,15 +326,15 @@ public function getListTablesSQL() public function getListTableColumnsSQL($table, $database = null) { if ($database) { - $database = "'" . $database . "'"; + $databaseSQL = $this->quoteStringLiteral($database); } else { - $database = 'DATABASE()'; + $databaseSQL = 'DATABASE()'; } return 'SELECT COLUMN_NAME, DATA_TYPE, COLUMN_COMMENT, IS_NULLABLE, IS_AUTO_INCREMENT, CHARACTER_MAXIMUM_LENGTH, COLUMN_DEFAULT,' . ' NUMERIC_PRECISION, NUMERIC_SCALE, COLLATION_NAME' . ' FROM DATA_DICTIONARY.COLUMNS' . - ' WHERE TABLE_SCHEMA=' . $database . " AND TABLE_NAME = '" . $table . "'"; + ' WHERE TABLE_SCHEMA=' . $databaseSQL . ' AND TABLE_NAME = ' . $this->quoteStringLiteral($table); } /** @@ -343,14 +343,14 @@ public function getListTableColumnsSQL($table, $database = null) public function getListTableForeignKeysSQL($table, $database = null) { if ($database) { - $database = "'" . $database . "'"; + $databaseSQL = $this->quoteStringLiteral($database); } else { - $database = 'DATABASE()'; + $databaseSQL = 'DATABASE()'; } return 'SELECT CONSTRAINT_NAME, CONSTRAINT_COLUMNS, REFERENCED_TABLE_NAME, REFERENCED_TABLE_COLUMNS, UPDATE_RULE, DELETE_RULE' . ' FROM DATA_DICTIONARY.FOREIGN_KEYS' . - ' WHERE CONSTRAINT_SCHEMA=' . $database . " AND CONSTRAINT_TABLE='" . $table . "'"; + ' WHERE CONSTRAINT_SCHEMA=' . $databaseSQL . ' AND CONSTRAINT_TABLE=' . $this->quoteStringLiteral($table); } /** @@ -359,14 +359,14 @@ public function getListTableForeignKeysSQL($table, $database = null) public function getListTableIndexesSQL($table, $database = null) { if ($database) { - $database = "'" . $database . "'"; + $databaseSQL = $this->quoteStringLiteral($database); } else { - $database = 'DATABASE()'; + $databaseSQL = 'DATABASE()'; } return "SELECT INDEX_NAME AS 'key_name', COLUMN_NAME AS 'column_name', IS_USED_IN_PRIMARY AS 'primary', IS_UNIQUE=0 AS 'non_unique'" . ' FROM DATA_DICTIONARY.INDEX_PARTS' . - ' WHERE TABLE_SCHEMA=' . $database . " AND TABLE_NAME='" . $table . "'"; + ' WHERE TABLE_SCHEMA=' . $databaseSQL . ' AND TABLE_NAME=' . $this->quoteStringLiteral($table); } /** diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php index a891d0d69ee..165b40e0ed3 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php @@ -439,7 +439,7 @@ public function getCreateDatabaseSQL($name) */ public function getDisallowDatabaseConnectionsSQL($database) { - return "UPDATE pg_database SET datallowconn = 'false' WHERE datname = '" . $database . "'"; + return "UPDATE pg_database SET datallowconn = 'false' WHERE datname = " . $this->quoteStringLiteral($database); } /** diff --git a/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php b/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php index ffb471bb543..7e1f9d62bab 100644 --- a/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php @@ -27,7 +27,7 @@ class DB2SchemaManager extends AbstractSchemaManager public function listTableNames() { $sql = $this->_platform->getListTablesSQL(); - $sql .= " AND CREATOR = UPPER('" . $this->_conn->getUsername() . "')"; + $sql .= ' AND CREATOR = UPPER(' . $this->_conn->quote($this->_conn->getUsername()) . ')'; $tables = $this->_conn->fetchAll($sql); diff --git a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php index 460def2e4b1..744acedabb5 100644 --- a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php @@ -117,15 +117,9 @@ public function listTableForeignKeys($table, $database = null) $tableForeignKeys = $this->_conn->fetchAll($sql); if (! empty($tableForeignKeys)) { - $createSql = $this->_conn->fetchAll( - sprintf( - "SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE type = 'table' AND name = '%s'", - $table - ) - ); - $createSql = $createSql[0]['sql'] ?? ''; + $createSql = $this->getCreateTableSQL($table); - if (preg_match_all( + if ($createSql !== null && preg_match_all( '# (?:CONSTRAINT\s+([^\s]+)\s+)? (?:FOREIGN\s+KEY[^\)]+\)\s*)? @@ -174,9 +168,10 @@ protected function _getPortableTableIndexesList($tableIndexes, $tableName = null $indexBuffer = []; // fetch primary - $stmt = $this->_conn->executeQuery( - sprintf("PRAGMA TABLE_INFO ('%s')", $tableName) - ); + $stmt = $this->_conn->executeQuery(sprintf( + 'PRAGMA TABLE_INFO (%s)', + $this->_conn->quote($tableName) + )); $indexArray = $stmt->fetchAll(FetchMode::ASSOCIATIVE); usort($indexArray, static function ($a, $b) { @@ -212,10 +207,11 @@ protected function _getPortableTableIndexesList($tableIndexes, $tableName = null $idx['primary'] = false; $idx['non_unique'] = $tableIndex['unique']?false:true; - $stmt = $this->_conn->executeQuery( - sprintf("PRAGMA INDEX_INFO ('%s')", $keyName) - ); - $indexArray = $stmt->fetchAll(FetchMode::ASSOCIATIVE); + $stmt = $this->_conn->executeQuery(sprintf( + 'PRAGMA INDEX_INFO (%s)', + $this->_conn->quote($keyName) + )); + $indexArray = $stmt->fetchAll(FetchMode::ASSOCIATIVE); foreach ($indexArray as $indexColumnRow) { $idx['column_name'] = $indexColumnRow['name']; @@ -272,13 +268,7 @@ protected function _getPortableTableColumnList($table, $database, $tableColumns) } // inspect column collation and comments - $createSql = $this->_conn->fetchAll( - sprintf( - "SELECT sql FROM (SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master) WHERE type = 'table' AND name = '%s'", - $table - ) - ); - $createSql = $createSql[0]['sql'] ?? ''; + $createSql = $this->getCreateTableSQL($table) ?? ''; foreach ($list as $columnName => $column) { $type = $column->getType(); @@ -488,4 +478,24 @@ private function parseColumnCommentFromSQL(string $column, string $sql) : ?strin return $comment === '' ? null : $comment; } + + private function getCreateTableSQL(string $table) : ?string + { + return $this->_conn->fetchColumn( + <<<'SQL' +SELECT sql + FROM ( + SELECT * + FROM sqlite_master + UNION ALL + SELECT * + FROM sqlite_temp_master + ) +WHERE type = 'table' +AND name = ? +SQL + , + [$table] + ) ?: null; + } } diff --git a/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php index 676c02cd413..bdde3d4fbcb 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php @@ -30,7 +30,7 @@ protected function setUp() $platform = $this->createMock(DB2Platform::class); $this->conn = $this ->getMockBuilder(Connection::class) - ->setMethods(['fetchAll']) + ->setMethods(['fetchAll', 'quote']) ->setConstructorArgs([['platform' => $platform], $driverMock, new Configuration(), $eventManager]) ->getMock(); $this->manager = new DB2SchemaManager($this->conn); @@ -102,6 +102,7 @@ public function testListTableNamesFiltersAssetNamesCorrectlyWithCallable() $this->conn->getConfiguration()->setSchemaAssetsFilter(static function ($assetName) use ($accepted) { return in_array($assetName, $accepted); }); + $this->conn->expects($this->any())->method('quote'); $this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue([ ['name' => 'FOO'], ['name' => 'T_FOO'], @@ -129,6 +130,7 @@ public function testSettingNullExpressionWillResetCallable() $this->conn->getConfiguration()->setSchemaAssetsFilter(static function ($assetName) use ($accepted) { return in_array($assetName, $accepted); }); + $this->conn->expects($this->any())->method('quote'); $this->conn->expects($this->atLeastOnce())->method('fetchAll')->will($this->returnValue([ ['name' => 'FOO'], ['name' => 'T_FOO'], From 111e42dfb43d1ea0853a449c254df20df2cced37 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 5 Oct 2018 22:58:12 -0700 Subject: [PATCH 40/76] Deprecated regex-based asset filters --- UPGRADE.md | 4 ++++ lib/Doctrine/DBAL/Configuration.php | 4 ++++ lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php | 2 ++ 3 files changed, 10 insertions(+) diff --git a/UPGRADE.md b/UPGRADE.md index 31d3fd94955..bf079383657 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,9 @@ # Upgrade to 2.9 +## Deprecated `Configuration::getFilterSchemaAssetsExpression()`, `::setFilterSchemaAssetsExpression()` and `AbstractSchemaManager::getFilterSchemaAssetsExpression()`. + +Regular expression-based filters are hard to extend by combining together. Instead, you may use callback-based filers via `::getSchemaAssetsFilter()` and `::getSchemaAssetsFilter()`. Callbacks can use regular expressions internally. + ## Deprecated `Doctrine\DBAL\Types\Type::getDefaultLength()` This method was never used by DBAL internally. It is now deprecated and will be removed in DBAL 3.0. diff --git a/lib/Doctrine/DBAL/Configuration.php b/lib/Doctrine/DBAL/Configuration.php index 0e34e87dcea..9b7b21fb21e 100644 --- a/lib/Doctrine/DBAL/Configuration.php +++ b/lib/Doctrine/DBAL/Configuration.php @@ -70,6 +70,8 @@ public function setResultCacheImpl(Cache $cacheImpl) * schema instances generated for the active connection when calling * {AbstractSchemaManager#createSchema()}. * + * @deprecated Use Configuration::setSchemaAssetsFilter() instead + * * @param string $filterExpression * * @return void @@ -87,6 +89,8 @@ public function setFilterSchemaAssetsExpression($filterExpression) /** * Returns filter schema assets expression. * + * @deprecated Use Configuration::getSchemaAssetsFilter() instead + * * @return string|null */ public function getFilterSchemaAssetsExpression() diff --git a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php index 0858e6771f1..06ee2c2b2aa 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php @@ -228,6 +228,8 @@ protected function filterAssetNames($assetNames) } /** + * @deprecated Use Configuration::getSchemaAssetsFilter() instead + * * @return string|null */ protected function getFilterSchemaAssetsExpression() From 72b4e777543e19a67c9b94edb3f23d7b3e523be5 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sun, 7 Oct 2018 14:30:03 -0700 Subject: [PATCH 41/76] Removed link to www.doctrine-project.org from doc blocks --- bin/doctrine-dbal.php | 17 ----------------- lib/Doctrine/DBAL/Connection.php | 2 -- lib/Doctrine/DBAL/ConnectionException.php | 3 --- lib/Doctrine/DBAL/Driver/AbstractDB2Driver.php | 2 -- .../DBAL/Driver/AbstractDriverException.php | 2 -- .../DBAL/Driver/AbstractMySQLDriver.php | 2 -- .../DBAL/Driver/AbstractOracleDriver.php | 2 -- .../DBAL/Driver/AbstractPostgreSQLDriver.php | 2 -- .../DBAL/Driver/AbstractSQLAnywhereDriver.php | 2 -- .../DBAL/Driver/AbstractSQLServerDriver.php | 2 -- .../DBAL/Driver/AbstractSQLiteDriver.php | 2 -- lib/Doctrine/DBAL/Driver/DriverException.php | 2 -- .../DBAL/Driver/ExceptionConverterDriver.php | 2 -- lib/Doctrine/DBAL/Driver/PDOException.php | 2 -- lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php | 2 -- .../DBAL/Driver/PingableConnection.php | 2 -- .../DBAL/Driver/SQLAnywhere/Driver.php | 2 -- .../SQLAnywhere/SQLAnywhereConnection.php | 2 -- .../SQLAnywhere/SQLAnywhereException.php | 2 -- .../SQLAnywhere/SQLAnywhereStatement.php | 2 -- .../DBAL/Driver/ServerInfoAwareConnection.php | 2 -- lib/Doctrine/DBAL/Driver/Statement.php | 2 -- .../DBAL/Event/ConnectionEventArgs.php | 2 -- .../DBAL/Event/Listeners/MysqlSessionInit.php | 2 -- .../DBAL/Event/Listeners/OracleSessionInit.php | 2 -- .../DBAL/Event/Listeners/SQLSessionInit.php | 2 -- .../SchemaAlterTableAddColumnEventArgs.php | 2 -- .../SchemaAlterTableChangeColumnEventArgs.php | 2 -- .../DBAL/Event/SchemaAlterTableEventArgs.php | 2 -- .../SchemaAlterTableRemoveColumnEventArgs.php | 2 -- .../SchemaAlterTableRenameColumnEventArgs.php | 2 -- .../Event/SchemaColumnDefinitionEventArgs.php | 2 -- .../Event/SchemaCreateTableColumnEventArgs.php | 2 -- .../DBAL/Event/SchemaCreateTableEventArgs.php | 2 -- .../DBAL/Event/SchemaDropTableEventArgs.php | 2 -- lib/Doctrine/DBAL/Event/SchemaEventArgs.php | 2 -- .../Event/SchemaIndexDefinitionEventArgs.php | 2 -- .../DBAL/Exception/ConnectionException.php | 2 -- .../Exception/ConstraintViolationException.php | 2 -- .../DatabaseObjectExistsException.php | 2 -- .../DatabaseObjectNotFoundException.php | 2 -- .../DBAL/Exception/DeadlockException.php | 2 -- .../DBAL/Exception/DriverException.php | 2 -- .../ForeignKeyConstraintViolationException.php | 2 -- .../Exception/InvalidArgumentException.php | 2 -- .../Exception/InvalidFieldNameException.php | 2 -- .../Exception/LockWaitTimeoutException.php | 2 -- .../Exception/NonUniqueFieldNameException.php | 2 -- .../NotNullConstraintViolationException.php | 2 -- .../DBAL/Exception/ReadOnlyException.php | 2 -- .../DBAL/Exception/RetryableException.php | 2 -- .../DBAL/Exception/ServerException.php | 2 -- .../DBAL/Exception/SyntaxErrorException.php | 2 -- .../DBAL/Exception/TableExistsException.php | 2 -- .../DBAL/Exception/TableNotFoundException.php | 2 -- .../UniqueConstraintViolationException.php | 2 -- lib/Doctrine/DBAL/LockMode.php | 2 -- lib/Doctrine/DBAL/Logging/DebugStack.php | 2 -- lib/Doctrine/DBAL/Logging/EchoSQLLogger.php | 2 -- lib/Doctrine/DBAL/Logging/LoggerChain.php | 2 -- lib/Doctrine/DBAL/Logging/SQLLogger.php | 2 -- .../DBAL/Platforms/AbstractPlatform.php | 4 +--- .../DBAL/Platforms/Keywords/DB2Keywords.php | 2 -- .../DBAL/Platforms/Keywords/KeywordList.php | 2 -- .../Platforms/Keywords/MySQL57Keywords.php | 2 -- .../Platforms/Keywords/MySQL80Keywords.php | 2 -- .../DBAL/Platforms/Keywords/MySQLKeywords.php | 2 -- .../DBAL/Platforms/Keywords/OracleKeywords.php | 2 -- .../Keywords/PostgreSQL91Keywords.php | 2 -- .../Keywords/PostgreSQL92Keywords.php | 2 -- .../Keywords/PostgreSQL94Keywords.php | 2 -- .../Platforms/Keywords/PostgreSQLKeywords.php | 2 -- .../DBAL/Platforms/Keywords/SQLiteKeywords.php | 2 -- .../DBAL/Platforms/MariaDb1027Platform.php | 2 -- .../DBAL/Platforms/MySQL57Platform.php | 2 -- .../DBAL/Platforms/MySQL80Platform.php | 2 -- .../DBAL/Platforms/PostgreSQL91Platform.php | 2 -- .../DBAL/Platforms/PostgreSQL92Platform.php | 2 -- .../DBAL/Platforms/PostgreSQL94Platform.php | 2 -- .../DBAL/Platforms/SQLAnywhere11Platform.php | 2 -- .../DBAL/Platforms/SQLAnywhere12Platform.php | 2 -- .../DBAL/Platforms/SQLAnywhere16Platform.php | 2 -- .../DBAL/Platforms/SQLAnywherePlatform.php | 2 -- lib/Doctrine/DBAL/Portability/Connection.php | 2 -- lib/Doctrine/DBAL/Portability/Statement.php | 2 -- .../Query/Expression/CompositeExpression.php | 2 -- .../Query/Expression/ExpressionBuilder.php | 2 -- lib/Doctrine/DBAL/Query/QueryBuilder.php | 2 -- lib/Doctrine/DBAL/SQLParserUtils.php | 2 -- lib/Doctrine/DBAL/SQLParserUtilsException.php | 2 -- lib/Doctrine/DBAL/Schema/AbstractAsset.php | 2 -- lib/Doctrine/DBAL/Schema/Column.php | 2 -- lib/Doctrine/DBAL/Schema/ColumnDiff.php | 2 -- lib/Doctrine/DBAL/Schema/Comparator.php | 2 -- lib/Doctrine/DBAL/Schema/Constraint.php | 2 -- lib/Doctrine/DBAL/Schema/DB2SchemaManager.php | 2 -- .../DBAL/Schema/ForeignKeyConstraint.php | 2 -- lib/Doctrine/DBAL/Schema/Identifier.php | 2 -- .../DBAL/Schema/SQLAnywhereSchemaManager.php | 2 -- lib/Doctrine/DBAL/Schema/Schema.php | 2 -- lib/Doctrine/DBAL/Schema/SchemaConfig.php | 2 -- lib/Doctrine/DBAL/Schema/SchemaDiff.php | 2 -- lib/Doctrine/DBAL/Schema/Sequence.php | 2 -- lib/Doctrine/DBAL/Schema/Table.php | 2 -- lib/Doctrine/DBAL/Schema/TableDiff.php | 2 -- lib/Doctrine/DBAL/Schema/View.php | 2 -- .../Schema/Visitor/DropSchemaSqlCollector.php | 2 -- .../DBAL/Schema/Visitor/NamespaceVisitor.php | 2 -- .../DBAL/Schema/Visitor/SchemaDiffVisitor.php | 2 -- lib/Doctrine/DBAL/Schema/Visitor/Visitor.php | 2 -- .../Tools/Console/Command/ImportCommand.php | 2 -- .../Tools/Console/Command/RunSqlCommand.php | 2 -- .../Tools/Console/Helper/ConnectionHelper.php | 2 -- .../DBAL/Types/ConversionException.php | 9 +++------ lib/Doctrine/DBAL/Types/DateTimeTzType.php | 2 -- lib/Doctrine/DBAL/Types/VarDateTimeType.php | 2 -- lib/Doctrine/DBAL/Version.php | 2 -- .../DBAL/VersionAwarePlatformDriver.php | 2 -- .../Tests/DBAL/Schema/ComparatorTest.php | 3 --- .../DBAL/Sharding/PoolingShardManagerTest.php | 18 +----------------- 120 files changed, 5 insertions(+), 277 deletions(-) diff --git a/bin/doctrine-dbal.php b/bin/doctrine-dbal.php index f785c1b12a2..f3e064ffd62 100644 --- a/bin/doctrine-dbal.php +++ b/bin/doctrine-dbal.php @@ -1,21 +1,4 @@ . - */ use Doctrine\DBAL\Tools\Console\ConsoleRunner; use Symfony\Component\Console\Helper\HelperSet; diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index afe4382b6de..85761fcca9b 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -34,8 +34,6 @@ * A wrapper around a Doctrine\DBAL\Driver\Connection that adds features like * events, transaction isolation levels, configuration, emulated transaction nesting, * lazy connecting and more. - * - * @link www.doctrine-project.org */ class Connection implements DriverConnection { diff --git a/lib/Doctrine/DBAL/ConnectionException.php b/lib/Doctrine/DBAL/ConnectionException.php index 3d9c841bec8..d3d11bc6743 100644 --- a/lib/Doctrine/DBAL/ConnectionException.php +++ b/lib/Doctrine/DBAL/ConnectionException.php @@ -2,9 +2,6 @@ namespace Doctrine\DBAL; -/** - * @link www.doctrine-project.org - */ class ConnectionException extends DBALException { /** diff --git a/lib/Doctrine/DBAL/Driver/AbstractDB2Driver.php b/lib/Doctrine/DBAL/Driver/AbstractDB2Driver.php index a58fc339802..c6e0565343a 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractDB2Driver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractDB2Driver.php @@ -9,8 +9,6 @@ /** * Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for IBM DB2 based drivers. - * - * @link www.doctrine-project.org */ abstract class AbstractDB2Driver implements Driver { diff --git a/lib/Doctrine/DBAL/Driver/AbstractDriverException.php b/lib/Doctrine/DBAL/Driver/AbstractDriverException.php index b42159181b3..d9af92d1744 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractDriverException.php +++ b/lib/Doctrine/DBAL/Driver/AbstractDriverException.php @@ -6,8 +6,6 @@ /** * Abstract base implementation of the {@link DriverException} interface. - * - * @link www.doctrine-project.org */ abstract class AbstractDriverException extends Exception implements DriverException { diff --git a/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php b/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php index 97d97b57d62..c46ddc63dd7 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php @@ -18,8 +18,6 @@ /** * Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for MySQL based drivers. - * - * @link www.doctrine-project.org */ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver, VersionAwarePlatformDriver { diff --git a/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php b/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php index cda69bb29aa..dcbaaf097f7 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php @@ -11,8 +11,6 @@ /** * Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for Oracle based drivers. - * - * @link www.doctrine-project.org */ abstract class AbstractOracleDriver implements Driver, ExceptionConverterDriver { diff --git a/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php b/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php index bab33e0f95f..916d924980c 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php @@ -19,8 +19,6 @@ /** * Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for PostgreSQL based drivers. - * - * @link www.doctrine-project.org */ abstract class AbstractPostgreSQLDriver implements Driver, ExceptionConverterDriver, VersionAwarePlatformDriver { diff --git a/lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php b/lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php index 2d5d196238a..88f26ce7def 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php @@ -17,8 +17,6 @@ /** * Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for SAP Sybase SQL Anywhere based drivers. - * - * @link www.doctrine-project.org */ abstract class AbstractSQLAnywhereDriver implements Driver, ExceptionConverterDriver, VersionAwarePlatformDriver { diff --git a/lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver.php b/lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver.php index c3e6c450f12..421d82b3951 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver.php @@ -16,8 +16,6 @@ /** * Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for Microsoft SQL Server based drivers. - * - * @link www.doctrine-project.org */ abstract class AbstractSQLServerDriver implements Driver, VersionAwarePlatformDriver { diff --git a/lib/Doctrine/DBAL/Driver/AbstractSQLiteDriver.php b/lib/Doctrine/DBAL/Driver/AbstractSQLiteDriver.php index a5a22b12ea9..582f7cae20a 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractSQLiteDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractSQLiteDriver.php @@ -11,8 +11,6 @@ /** * Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for SQLite based drivers. - * - * @link www.doctrine-project.org */ abstract class AbstractSQLiteDriver implements Driver, ExceptionConverterDriver { diff --git a/lib/Doctrine/DBAL/Driver/DriverException.php b/lib/Doctrine/DBAL/Driver/DriverException.php index d23cc3f3081..79480ac72be 100644 --- a/lib/Doctrine/DBAL/Driver/DriverException.php +++ b/lib/Doctrine/DBAL/Driver/DriverException.php @@ -9,8 +9,6 @@ * * Driver exceptions provide the SQLSTATE of the driver * and the driver specific error code at the time the error occurred. - * - * @link www.doctrine-project.org */ interface DriverException extends Throwable { diff --git a/lib/Doctrine/DBAL/Driver/ExceptionConverterDriver.php b/lib/Doctrine/DBAL/Driver/ExceptionConverterDriver.php index fd594c2ad79..9b79e240c4e 100644 --- a/lib/Doctrine/DBAL/Driver/ExceptionConverterDriver.php +++ b/lib/Doctrine/DBAL/Driver/ExceptionConverterDriver.php @@ -4,8 +4,6 @@ /** * Contract for a driver that is capable of converting DBAL driver exceptions into standardized DBAL driver exceptions. - * - * @link www.doctrine-project.org */ interface ExceptionConverterDriver { diff --git a/lib/Doctrine/DBAL/Driver/PDOException.php b/lib/Doctrine/DBAL/Driver/PDOException.php index ee677e3832b..277d7a62500 100644 --- a/lib/Doctrine/DBAL/Driver/PDOException.php +++ b/lib/Doctrine/DBAL/Driver/PDOException.php @@ -4,8 +4,6 @@ /** * Tiny wrapper for PDOException instances to implement the {@link DriverException} interface. - * - * @link www.doctrine-project.org */ class PDOException extends \PDOException implements DriverException { diff --git a/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php b/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php index efd4269cbb2..4291e1e17f0 100644 --- a/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php @@ -7,8 +7,6 @@ /** * Driver for the PDO IBM extension. - * - * @link www.doctrine-project.org */ class Driver extends AbstractDB2Driver { diff --git a/lib/Doctrine/DBAL/Driver/PingableConnection.php b/lib/Doctrine/DBAL/Driver/PingableConnection.php index 8586bce2239..06bfb9a7f26 100644 --- a/lib/Doctrine/DBAL/Driver/PingableConnection.php +++ b/lib/Doctrine/DBAL/Driver/PingableConnection.php @@ -4,8 +4,6 @@ /** * An interface for connections which support a "native" ping method. - * - * @link www.doctrine-project.org */ interface PingableConnection { diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php index d4b73a4723c..294d5c7a5e9 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php @@ -10,8 +10,6 @@ /** * A Doctrine DBAL driver for the SAP Sybase SQL Anywhere PHP extension. - * - * @link www.doctrine-project.org */ class Driver extends AbstractSQLAnywhereDriver { diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php index 8e977e2d077..00295a2af1a 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php @@ -25,8 +25,6 @@ /** * SAP Sybase SQL Anywhere implementation of the Connection interface. - * - * @link www.doctrine-project.org */ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection { diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereException.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereException.php index dfe9187bb93..9f8aac0608d 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereException.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereException.php @@ -13,8 +13,6 @@ /** * SAP Sybase SQL Anywhere driver exception. - * - * @link www.doctrine-project.org */ class SQLAnywhereException extends AbstractDriverException { diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php index 5290509fef5..0ed2d454624 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php @@ -38,8 +38,6 @@ /** * SAP SQL Anywhere implementation of the Statement interface. - * - * @link www.doctrine-project.org */ class SQLAnywhereStatement implements IteratorAggregate, Statement { diff --git a/lib/Doctrine/DBAL/Driver/ServerInfoAwareConnection.php b/lib/Doctrine/DBAL/Driver/ServerInfoAwareConnection.php index 35bf9ebd094..c97a60fa356 100644 --- a/lib/Doctrine/DBAL/Driver/ServerInfoAwareConnection.php +++ b/lib/Doctrine/DBAL/Driver/ServerInfoAwareConnection.php @@ -4,8 +4,6 @@ /** * Contract for a connection that is able to provide information about the server it is connected to. - * - * @link www.doctrine-project.org */ interface ServerInfoAwareConnection { diff --git a/lib/Doctrine/DBAL/Driver/Statement.php b/lib/Doctrine/DBAL/Driver/Statement.php index 3bfeb6a4c42..a3ea74a4df5 100644 --- a/lib/Doctrine/DBAL/Driver/Statement.php +++ b/lib/Doctrine/DBAL/Driver/Statement.php @@ -9,8 +9,6 @@ * Drivers must implement this interface. * * This resembles (a subset of) the PDOStatement interface. - * - * @link www.doctrine-project.org */ interface Statement extends ResultStatement { diff --git a/lib/Doctrine/DBAL/Event/ConnectionEventArgs.php b/lib/Doctrine/DBAL/Event/ConnectionEventArgs.php index 07620e9e40d..bb0ca886d99 100644 --- a/lib/Doctrine/DBAL/Event/ConnectionEventArgs.php +++ b/lib/Doctrine/DBAL/Event/ConnectionEventArgs.php @@ -10,8 +10,6 @@ /** * Event Arguments used when a Driver connection is established inside Doctrine\DBAL\Connection. - * - * @link www.doctrine-project.org */ class ConnectionEventArgs extends EventArgs { diff --git a/lib/Doctrine/DBAL/Event/Listeners/MysqlSessionInit.php b/lib/Doctrine/DBAL/Event/Listeners/MysqlSessionInit.php index 53bc6e36479..9e722904050 100644 --- a/lib/Doctrine/DBAL/Event/Listeners/MysqlSessionInit.php +++ b/lib/Doctrine/DBAL/Event/Listeners/MysqlSessionInit.php @@ -10,8 +10,6 @@ * MySQL Session Init Event Subscriber which allows to set the Client Encoding of the Connection. * * @deprecated Use "charset" option to PDO MySQL Connection instead. - * - * @link www.doctrine-project.org */ class MysqlSessionInit implements EventSubscriber { diff --git a/lib/Doctrine/DBAL/Event/Listeners/OracleSessionInit.php b/lib/Doctrine/DBAL/Event/Listeners/OracleSessionInit.php index e694432600b..19f2b3fd335 100644 --- a/lib/Doctrine/DBAL/Event/Listeners/OracleSessionInit.php +++ b/lib/Doctrine/DBAL/Event/Listeners/OracleSessionInit.php @@ -20,8 +20,6 @@ * NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS" * NLS_TIMESTAMP_FORMAT="YYYY-MM-DD HH24:MI:SS" * NLS_TIMESTAMP_TZ_FORMAT="YYYY-MM-DD HH24:MI:SS TZH:TZM" - * - * @link www.doctrine-project.org */ class OracleSessionInit implements EventSubscriber { diff --git a/lib/Doctrine/DBAL/Event/Listeners/SQLSessionInit.php b/lib/Doctrine/DBAL/Event/Listeners/SQLSessionInit.php index 8b25489ca7f..ea63cab43d7 100644 --- a/lib/Doctrine/DBAL/Event/Listeners/SQLSessionInit.php +++ b/lib/Doctrine/DBAL/Event/Listeners/SQLSessionInit.php @@ -8,8 +8,6 @@ /** * Session init listener for executing a single SQL statement right after a connection is opened. - * - * @link www.doctrine-project.org */ class SQLSessionInit implements EventSubscriber { diff --git a/lib/Doctrine/DBAL/Event/SchemaAlterTableAddColumnEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaAlterTableAddColumnEventArgs.php index 8ec240a50d8..2f9edfea688 100644 --- a/lib/Doctrine/DBAL/Event/SchemaAlterTableAddColumnEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaAlterTableAddColumnEventArgs.php @@ -10,8 +10,6 @@ /** * Event Arguments used when SQL queries for adding table columns are generated inside Doctrine\DBAL\Platform\*Platform. - * - * @link www.doctrine-project.org */ class SchemaAlterTableAddColumnEventArgs extends SchemaEventArgs { diff --git a/lib/Doctrine/DBAL/Event/SchemaAlterTableChangeColumnEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaAlterTableChangeColumnEventArgs.php index c1283471c2a..55661d5d307 100644 --- a/lib/Doctrine/DBAL/Event/SchemaAlterTableChangeColumnEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaAlterTableChangeColumnEventArgs.php @@ -10,8 +10,6 @@ /** * Event Arguments used when SQL queries for changing table columns are generated inside Doctrine\DBAL\Platform\*Platform. - * - * @link www.doctrine-project.org */ class SchemaAlterTableChangeColumnEventArgs extends SchemaEventArgs { diff --git a/lib/Doctrine/DBAL/Event/SchemaAlterTableEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaAlterTableEventArgs.php index de6af93f44e..8f5f0ecf563 100644 --- a/lib/Doctrine/DBAL/Event/SchemaAlterTableEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaAlterTableEventArgs.php @@ -9,8 +9,6 @@ /** * Event Arguments used when SQL queries for creating tables are generated inside Doctrine\DBAL\Platform\*Platform. - * - * @link www.doctrine-project.org */ class SchemaAlterTableEventArgs extends SchemaEventArgs { diff --git a/lib/Doctrine/DBAL/Event/SchemaAlterTableRemoveColumnEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaAlterTableRemoveColumnEventArgs.php index ac57c8c3be6..1bc9f590187 100644 --- a/lib/Doctrine/DBAL/Event/SchemaAlterTableRemoveColumnEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaAlterTableRemoveColumnEventArgs.php @@ -10,8 +10,6 @@ /** * Event Arguments used when SQL queries for removing table columns are generated inside Doctrine\DBAL\Platform\*Platform. - * - * @link www.doctrine-project.org */ class SchemaAlterTableRemoveColumnEventArgs extends SchemaEventArgs { diff --git a/lib/Doctrine/DBAL/Event/SchemaAlterTableRenameColumnEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaAlterTableRenameColumnEventArgs.php index 74f7022becb..911ea8b4ab6 100644 --- a/lib/Doctrine/DBAL/Event/SchemaAlterTableRenameColumnEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaAlterTableRenameColumnEventArgs.php @@ -10,8 +10,6 @@ /** * Event Arguments used when SQL queries for renaming table columns are generated inside Doctrine\DBAL\Platform\*Platform. - * - * @link www.doctrine-project.org */ class SchemaAlterTableRenameColumnEventArgs extends SchemaEventArgs { diff --git a/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php index 906ba1d3487..19d9f93a329 100644 --- a/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php @@ -8,8 +8,6 @@ /** * Event Arguments used when the portable column definition is generated inside Doctrine\DBAL\Schema\AbstractSchemaManager. - * - * @link www.doctrine-project.org */ class SchemaColumnDefinitionEventArgs extends SchemaEventArgs { diff --git a/lib/Doctrine/DBAL/Event/SchemaCreateTableColumnEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaCreateTableColumnEventArgs.php index 5e1d9afe0df..9d24b8b9049 100644 --- a/lib/Doctrine/DBAL/Event/SchemaCreateTableColumnEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaCreateTableColumnEventArgs.php @@ -10,8 +10,6 @@ /** * Event Arguments used when SQL queries for creating table columns are generated inside Doctrine\DBAL\Platform\AbstractPlatform. - * - * @link www.doctrine-project.org */ class SchemaCreateTableColumnEventArgs extends SchemaEventArgs { diff --git a/lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php index fc8ab830460..538617cc328 100644 --- a/lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php @@ -10,8 +10,6 @@ /** * Event Arguments used when SQL queries for creating tables are generated inside Doctrine\DBAL\Platform\AbstractPlatform. - * - * @link www.doctrine-project.org */ class SchemaCreateTableEventArgs extends SchemaEventArgs { diff --git a/lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php index 97888b3f60a..900b9fbfd71 100644 --- a/lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php @@ -9,8 +9,6 @@ /** * Event Arguments used when the SQL query for dropping tables are generated inside Doctrine\DBAL\Platform\AbstractPlatform. - * - * @link www.doctrine-project.org */ class SchemaDropTableEventArgs extends SchemaEventArgs { diff --git a/lib/Doctrine/DBAL/Event/SchemaEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaEventArgs.php index 30e1e65e24e..0db0689c5ad 100644 --- a/lib/Doctrine/DBAL/Event/SchemaEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaEventArgs.php @@ -6,8 +6,6 @@ /** * Base class for schema related events. - * - * @link www.doctrine-project.org */ class SchemaEventArgs extends EventArgs { diff --git a/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php index f89864158ce..317f352b87a 100644 --- a/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php @@ -8,8 +8,6 @@ /** * Event Arguments used when the portable index definition is generated inside Doctrine\DBAL\Schema\AbstractSchemaManager. - * - * @link www.doctrine-project.org */ class SchemaIndexDefinitionEventArgs extends SchemaEventArgs { diff --git a/lib/Doctrine/DBAL/Exception/ConnectionException.php b/lib/Doctrine/DBAL/Exception/ConnectionException.php index 3b17d09d52a..e96a29191e4 100644 --- a/lib/Doctrine/DBAL/Exception/ConnectionException.php +++ b/lib/Doctrine/DBAL/Exception/ConnectionException.php @@ -4,8 +4,6 @@ /** * Base class for all connection related errors detected in the driver. - * - * @link www.doctrine-project.org */ class ConnectionException extends DriverException { diff --git a/lib/Doctrine/DBAL/Exception/ConstraintViolationException.php b/lib/Doctrine/DBAL/Exception/ConstraintViolationException.php index ed7865a998d..3959f39af95 100644 --- a/lib/Doctrine/DBAL/Exception/ConstraintViolationException.php +++ b/lib/Doctrine/DBAL/Exception/ConstraintViolationException.php @@ -4,8 +4,6 @@ /** * Base class for all constraint violation related errors detected in the driver. - * - * @link www.doctrine-project.org */ class ConstraintViolationException extends ServerException { diff --git a/lib/Doctrine/DBAL/Exception/DatabaseObjectExistsException.php b/lib/Doctrine/DBAL/Exception/DatabaseObjectExistsException.php index e1932de88a3..7e0ba0299e9 100644 --- a/lib/Doctrine/DBAL/Exception/DatabaseObjectExistsException.php +++ b/lib/Doctrine/DBAL/Exception/DatabaseObjectExistsException.php @@ -8,8 +8,6 @@ * A database object is considered any asset that can be created in a database * such as schemas, tables, views, sequences, triggers, constraints, indexes, * functions, stored procedures etc. - * - * @link www.doctrine-project.org */ class DatabaseObjectExistsException extends ServerException { diff --git a/lib/Doctrine/DBAL/Exception/DatabaseObjectNotFoundException.php b/lib/Doctrine/DBAL/Exception/DatabaseObjectNotFoundException.php index 4b0f96b5cf6..3342bce8d58 100644 --- a/lib/Doctrine/DBAL/Exception/DatabaseObjectNotFoundException.php +++ b/lib/Doctrine/DBAL/Exception/DatabaseObjectNotFoundException.php @@ -8,8 +8,6 @@ * A database object is considered any asset that can be created in a database * such as schemas, tables, views, sequences, triggers, constraints, indexes, * functions, stored procedures etc. - * - * @link www.doctrine-project.org */ class DatabaseObjectNotFoundException extends ServerException { diff --git a/lib/Doctrine/DBAL/Exception/DeadlockException.php b/lib/Doctrine/DBAL/Exception/DeadlockException.php index 95ba4467f1c..fd0550a56b0 100644 --- a/lib/Doctrine/DBAL/Exception/DeadlockException.php +++ b/lib/Doctrine/DBAL/Exception/DeadlockException.php @@ -4,8 +4,6 @@ /** * Exception for a deadlock error of a transaction detected in the driver. - * - * @link www.doctrine-project.org */ class DeadlockException extends ServerException implements RetryableException { diff --git a/lib/Doctrine/DBAL/Exception/DriverException.php b/lib/Doctrine/DBAL/Exception/DriverException.php index 69fb4dafdee..d3753329882 100644 --- a/lib/Doctrine/DBAL/Exception/DriverException.php +++ b/lib/Doctrine/DBAL/Exception/DriverException.php @@ -7,8 +7,6 @@ /** * Base class for all errors detected in the driver. - * - * @link www.doctrine-project.org */ class DriverException extends DBALException { diff --git a/lib/Doctrine/DBAL/Exception/ForeignKeyConstraintViolationException.php b/lib/Doctrine/DBAL/Exception/ForeignKeyConstraintViolationException.php index ba60e1c93c0..48d736f9e28 100644 --- a/lib/Doctrine/DBAL/Exception/ForeignKeyConstraintViolationException.php +++ b/lib/Doctrine/DBAL/Exception/ForeignKeyConstraintViolationException.php @@ -4,8 +4,6 @@ /** * Exception for a foreign key constraint violation detected in the driver. - * - * @link www.doctrine-project.org */ class ForeignKeyConstraintViolationException extends ConstraintViolationException { diff --git a/lib/Doctrine/DBAL/Exception/InvalidArgumentException.php b/lib/Doctrine/DBAL/Exception/InvalidArgumentException.php index 8363d172266..5d431e6031d 100644 --- a/lib/Doctrine/DBAL/Exception/InvalidArgumentException.php +++ b/lib/Doctrine/DBAL/Exception/InvalidArgumentException.php @@ -6,8 +6,6 @@ /** * Exception to be thrown when invalid arguments are passed to any DBAL API - * - * @link www.doctrine-project.org */ class InvalidArgumentException extends DBALException { diff --git a/lib/Doctrine/DBAL/Exception/InvalidFieldNameException.php b/lib/Doctrine/DBAL/Exception/InvalidFieldNameException.php index a35f3e7dc29..d960feaf869 100644 --- a/lib/Doctrine/DBAL/Exception/InvalidFieldNameException.php +++ b/lib/Doctrine/DBAL/Exception/InvalidFieldNameException.php @@ -4,8 +4,6 @@ /** * Exception for an invalid specified field name in a statement detected in the driver. - * - * @link www.doctrine-project.org */ class InvalidFieldNameException extends ServerException { diff --git a/lib/Doctrine/DBAL/Exception/LockWaitTimeoutException.php b/lib/Doctrine/DBAL/Exception/LockWaitTimeoutException.php index c26b59fc676..bfc3a498a3c 100644 --- a/lib/Doctrine/DBAL/Exception/LockWaitTimeoutException.php +++ b/lib/Doctrine/DBAL/Exception/LockWaitTimeoutException.php @@ -4,8 +4,6 @@ /** * Exception for a lock wait timeout error of a transaction detected in the driver. - * - * @link www.doctrine-project.org */ class LockWaitTimeoutException extends ServerException implements RetryableException { diff --git a/lib/Doctrine/DBAL/Exception/NonUniqueFieldNameException.php b/lib/Doctrine/DBAL/Exception/NonUniqueFieldNameException.php index cde6f2bf860..fd56f89691f 100644 --- a/lib/Doctrine/DBAL/Exception/NonUniqueFieldNameException.php +++ b/lib/Doctrine/DBAL/Exception/NonUniqueFieldNameException.php @@ -4,8 +4,6 @@ /** * Exception for a non-unique/ambiguous specified field name in a statement detected in the driver. - * - * @link www.doctrine-project.org */ class NonUniqueFieldNameException extends ServerException { diff --git a/lib/Doctrine/DBAL/Exception/NotNullConstraintViolationException.php b/lib/Doctrine/DBAL/Exception/NotNullConstraintViolationException.php index 235239a6163..e327bc94d4d 100644 --- a/lib/Doctrine/DBAL/Exception/NotNullConstraintViolationException.php +++ b/lib/Doctrine/DBAL/Exception/NotNullConstraintViolationException.php @@ -4,8 +4,6 @@ /** * Exception for a NOT NULL constraint violation detected in the driver. - * - * @link www.doctrine-project.org */ class NotNullConstraintViolationException extends ConstraintViolationException { diff --git a/lib/Doctrine/DBAL/Exception/ReadOnlyException.php b/lib/Doctrine/DBAL/Exception/ReadOnlyException.php index cd8f2c757f7..a846f2501c8 100644 --- a/lib/Doctrine/DBAL/Exception/ReadOnlyException.php +++ b/lib/Doctrine/DBAL/Exception/ReadOnlyException.php @@ -4,8 +4,6 @@ /** * Exception for a write operation attempt on a read-only database element detected in the driver. - * - * @link www.doctrine-project.org */ class ReadOnlyException extends ServerException { diff --git a/lib/Doctrine/DBAL/Exception/RetryableException.php b/lib/Doctrine/DBAL/Exception/RetryableException.php index b84863fcb61..e1ccd02ffd9 100644 --- a/lib/Doctrine/DBAL/Exception/RetryableException.php +++ b/lib/Doctrine/DBAL/Exception/RetryableException.php @@ -4,8 +4,6 @@ /** * Marker interface for all exceptions where retrying the transaction makes sense. - * - * @link www.doctrine-project.org */ interface RetryableException { diff --git a/lib/Doctrine/DBAL/Exception/ServerException.php b/lib/Doctrine/DBAL/Exception/ServerException.php index 30c8288fc7e..c88c3863b62 100644 --- a/lib/Doctrine/DBAL/Exception/ServerException.php +++ b/lib/Doctrine/DBAL/Exception/ServerException.php @@ -4,8 +4,6 @@ /** * Base class for all server related errors detected in the driver. - * - * @link www.doctrine-project.org */ class ServerException extends DriverException { diff --git a/lib/Doctrine/DBAL/Exception/SyntaxErrorException.php b/lib/Doctrine/DBAL/Exception/SyntaxErrorException.php index 2dedd689b7a..0b413b71971 100644 --- a/lib/Doctrine/DBAL/Exception/SyntaxErrorException.php +++ b/lib/Doctrine/DBAL/Exception/SyntaxErrorException.php @@ -4,8 +4,6 @@ /** * Exception for a syntax error in a statement detected in the driver. - * - * @link www.doctrine-project.org */ class SyntaxErrorException extends ServerException { diff --git a/lib/Doctrine/DBAL/Exception/TableExistsException.php b/lib/Doctrine/DBAL/Exception/TableExistsException.php index 93405890d4f..ff0df89afac 100644 --- a/lib/Doctrine/DBAL/Exception/TableExistsException.php +++ b/lib/Doctrine/DBAL/Exception/TableExistsException.php @@ -4,8 +4,6 @@ /** * Exception for an already existing table referenced in a statement detected in the driver. - * - * @link www.doctrine-project.org */ class TableExistsException extends DatabaseObjectExistsException { diff --git a/lib/Doctrine/DBAL/Exception/TableNotFoundException.php b/lib/Doctrine/DBAL/Exception/TableNotFoundException.php index 32349aa3b20..aeaa0057d49 100644 --- a/lib/Doctrine/DBAL/Exception/TableNotFoundException.php +++ b/lib/Doctrine/DBAL/Exception/TableNotFoundException.php @@ -4,8 +4,6 @@ /** * Exception for an unknown table referenced in a statement detected in the driver. - * - * @link www.doctrine-project.org */ class TableNotFoundException extends DatabaseObjectNotFoundException { diff --git a/lib/Doctrine/DBAL/Exception/UniqueConstraintViolationException.php b/lib/Doctrine/DBAL/Exception/UniqueConstraintViolationException.php index a202245094c..c762ad3c78a 100644 --- a/lib/Doctrine/DBAL/Exception/UniqueConstraintViolationException.php +++ b/lib/Doctrine/DBAL/Exception/UniqueConstraintViolationException.php @@ -4,8 +4,6 @@ /** * Exception for a unique constraint violation detected in the driver. - * - * @link www.doctrine-project.org */ class UniqueConstraintViolationException extends ConstraintViolationException { diff --git a/lib/Doctrine/DBAL/LockMode.php b/lib/Doctrine/DBAL/LockMode.php index 6016bb0f36c..14e81432b43 100644 --- a/lib/Doctrine/DBAL/LockMode.php +++ b/lib/Doctrine/DBAL/LockMode.php @@ -4,8 +4,6 @@ /** * Contains all DBAL LockModes. - * - * @link www.doctrine-project.org */ class LockMode { diff --git a/lib/Doctrine/DBAL/Logging/DebugStack.php b/lib/Doctrine/DBAL/Logging/DebugStack.php index 4372e382416..e1ccaad6ba0 100644 --- a/lib/Doctrine/DBAL/Logging/DebugStack.php +++ b/lib/Doctrine/DBAL/Logging/DebugStack.php @@ -6,8 +6,6 @@ /** * Includes executed SQLs in a Debug Stack. - * - * @link www.doctrine-project.org */ class DebugStack implements SQLLogger { diff --git a/lib/Doctrine/DBAL/Logging/EchoSQLLogger.php b/lib/Doctrine/DBAL/Logging/EchoSQLLogger.php index 5f422bd0a41..657abb4d378 100644 --- a/lib/Doctrine/DBAL/Logging/EchoSQLLogger.php +++ b/lib/Doctrine/DBAL/Logging/EchoSQLLogger.php @@ -7,8 +7,6 @@ /** * A SQL logger that logs to the standard output using echo/var_dump. - * - * @link www.doctrine-project.org */ class EchoSQLLogger implements SQLLogger { diff --git a/lib/Doctrine/DBAL/Logging/LoggerChain.php b/lib/Doctrine/DBAL/Logging/LoggerChain.php index fc944815527..2b5404b25c7 100644 --- a/lib/Doctrine/DBAL/Logging/LoggerChain.php +++ b/lib/Doctrine/DBAL/Logging/LoggerChain.php @@ -4,8 +4,6 @@ /** * Chains multiple SQLLogger. - * - * @link www.doctrine-project.org */ class LoggerChain implements SQLLogger { diff --git a/lib/Doctrine/DBAL/Logging/SQLLogger.php b/lib/Doctrine/DBAL/Logging/SQLLogger.php index 7c1099dfc28..2e94611b6a2 100644 --- a/lib/Doctrine/DBAL/Logging/SQLLogger.php +++ b/lib/Doctrine/DBAL/Logging/SQLLogger.php @@ -4,8 +4,6 @@ /** * Interface for SQL loggers. - * - * @link www.doctrine-project.org */ interface SQLLogger { diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index b97c66d32b3..aeac616d514 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -59,9 +59,7 @@ * point of abstraction of platform-specific behaviors, features and SQL dialects. * They are a passive source of information. * - * @link www.doctrine-project.org - * - * @todo Remove any unnecessary methods. + * @todo Remove any unnecessary methods. */ abstract class AbstractPlatform { diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/DB2Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/DB2Keywords.php index d2c09878dda..8533f579d71 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/DB2Keywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/DB2Keywords.php @@ -4,8 +4,6 @@ /** * DB2 Keywords. - * - * @link www.doctrine-project.org */ class DB2Keywords extends KeywordList { diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/KeywordList.php b/lib/Doctrine/DBAL/Platforms/Keywords/KeywordList.php index c1dbbde4fcc..860d9f21099 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/KeywordList.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/KeywordList.php @@ -8,8 +8,6 @@ /** * Abstract interface for a SQL reserved keyword dictionary. - * - * @link www.doctrine-project.org */ abstract class KeywordList { diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/MySQL57Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/MySQL57Keywords.php index da856d84ab0..9b60a3f1c54 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/MySQL57Keywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/MySQL57Keywords.php @@ -4,8 +4,6 @@ /** * MySQL 5.7 reserved keywords list. - * - * @link www.doctrine-project.org */ class MySQL57Keywords extends MySQLKeywords { diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/MySQL80Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/MySQL80Keywords.php index 37616b0d457..4b595d53a08 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/MySQL80Keywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/MySQL80Keywords.php @@ -6,8 +6,6 @@ /** * MySQL 8.0 reserved keywords list. - * - * @link www.doctrine-project.org */ class MySQL80Keywords extends MySQL57Keywords { diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/MySQLKeywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/MySQLKeywords.php index dd80d647081..84ca1446a8b 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/MySQLKeywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/MySQLKeywords.php @@ -4,8 +4,6 @@ /** * MySQL Keywordlist. - * - * @link www.doctrine-project.org */ class MySQLKeywords extends KeywordList { diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/OracleKeywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/OracleKeywords.php index 0441e99d72f..92ca81a079b 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/OracleKeywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/OracleKeywords.php @@ -4,8 +4,6 @@ /** * Oracle Keywordlist. - * - * @link www.doctrine-project.org */ class OracleKeywords extends KeywordList { diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL91Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL91Keywords.php index 9f7ccef1c7b..75a93f5f197 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL91Keywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL91Keywords.php @@ -4,8 +4,6 @@ /** * PostgreSQL 9.1 reserved keywords list. - * - * @link www.doctrine-project.org */ class PostgreSQL91Keywords extends PostgreSQLKeywords { diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL92Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL92Keywords.php index e7d197d9e0f..5179462fdf3 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL92Keywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL92Keywords.php @@ -6,8 +6,6 @@ /** * PostgreSQL 9.2 reserved keywords list. - * - * @link www.doctrine-project.org */ class PostgreSQL92Keywords extends PostgreSQL91Keywords { diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL94Keywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL94Keywords.php index eda90731fef..b33b8a8c00b 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL94Keywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQL94Keywords.php @@ -7,8 +7,6 @@ /** * PostgreSQL 9.4 reserved keywords list. - * - * @link www.doctrine-project.org */ class PostgreSQL94Keywords extends PostgreSQL92Keywords { diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQLKeywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQLKeywords.php index 0baabe87475..8c699e25380 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQLKeywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/PostgreSQLKeywords.php @@ -4,8 +4,6 @@ /** * PostgreSQL Keywordlist. - * - * @link www.doctrine-project.org */ class PostgreSQLKeywords extends KeywordList { diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/SQLiteKeywords.php b/lib/Doctrine/DBAL/Platforms/Keywords/SQLiteKeywords.php index 343b5ed813f..a0c9c797ef9 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/SQLiteKeywords.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/SQLiteKeywords.php @@ -4,8 +4,6 @@ /** * SQLite Keywordlist. - * - * @link www.doctrine-project.org */ class SQLiteKeywords extends KeywordList { diff --git a/lib/Doctrine/DBAL/Platforms/MariaDb1027Platform.php b/lib/Doctrine/DBAL/Platforms/MariaDb1027Platform.php index 9489c127b74..25420a0476e 100644 --- a/lib/Doctrine/DBAL/Platforms/MariaDb1027Platform.php +++ b/lib/Doctrine/DBAL/Platforms/MariaDb1027Platform.php @@ -8,8 +8,6 @@ * Provides the behavior, features and SQL dialect of the MariaDB 10.2 (10.2.7 GA) database platform. * * Note: Should not be used with versions prior to 10.2.7. - * - * @link www.doctrine-project.org */ final class MariaDb1027Platform extends MySqlPlatform { diff --git a/lib/Doctrine/DBAL/Platforms/MySQL57Platform.php b/lib/Doctrine/DBAL/Platforms/MySQL57Platform.php index 1d0dbfc3caa..71ef6ca96c7 100644 --- a/lib/Doctrine/DBAL/Platforms/MySQL57Platform.php +++ b/lib/Doctrine/DBAL/Platforms/MySQL57Platform.php @@ -8,8 +8,6 @@ /** * Provides the behavior, features and SQL dialect of the MySQL 5.7 (5.7.9 GA) database platform. - * - * @link www.doctrine-project.org */ class MySQL57Platform extends MySqlPlatform { diff --git a/lib/Doctrine/DBAL/Platforms/MySQL80Platform.php b/lib/Doctrine/DBAL/Platforms/MySQL80Platform.php index 49dd5761e6f..f6d4be9dc4c 100644 --- a/lib/Doctrine/DBAL/Platforms/MySQL80Platform.php +++ b/lib/Doctrine/DBAL/Platforms/MySQL80Platform.php @@ -4,8 +4,6 @@ /** * Provides the behavior, features and SQL dialect of the MySQL 8.0 (8.0 GA) database platform. - * - * @link www.doctrine-project.org */ class MySQL80Platform extends MySQL57Platform { diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSQL91Platform.php b/lib/Doctrine/DBAL/Platforms/PostgreSQL91Platform.php index e81f08ea60a..f558409831c 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSQL91Platform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSQL91Platform.php @@ -6,8 +6,6 @@ /** * Provides the behavior, features and SQL dialect of the PostgreSQL 9.1 database platform. - * - * @link www.doctrine-project.org */ class PostgreSQL91Platform extends PostgreSqlPlatform { diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSQL92Platform.php b/lib/Doctrine/DBAL/Platforms/PostgreSQL92Platform.php index 14a68caf81d..b302c0ceb83 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSQL92Platform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSQL92Platform.php @@ -7,8 +7,6 @@ /** * Provides the behavior, features and SQL dialect of the PostgreSQL 9.2 database platform. - * - * @link www.doctrine-project.org */ class PostgreSQL92Platform extends PostgreSQL91Platform { diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSQL94Platform.php b/lib/Doctrine/DBAL/Platforms/PostgreSQL94Platform.php index a607fae1d21..9db0ecbbd2a 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSQL94Platform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSQL94Platform.php @@ -6,8 +6,6 @@ /** * Provides the behavior, features and SQL dialect of the PostgreSQL 9.4 database platform. - * - * @link www.doctrine-project.org */ class PostgreSQL94Platform extends PostgreSQL92Platform { diff --git a/lib/Doctrine/DBAL/Platforms/SQLAnywhere11Platform.php b/lib/Doctrine/DBAL/Platforms/SQLAnywhere11Platform.php index 6c9b10ec535..a46ae9352c4 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLAnywhere11Platform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLAnywhere11Platform.php @@ -5,8 +5,6 @@ /** * The SQLAnywhere11Platform provides the behavior, features and SQL dialect of the * SAP Sybase SQL Anywhere 11 database platform. - * - * @link www.doctrine-project.org */ class SQLAnywhere11Platform extends SQLAnywherePlatform { diff --git a/lib/Doctrine/DBAL/Platforms/SQLAnywhere12Platform.php b/lib/Doctrine/DBAL/Platforms/SQLAnywhere12Platform.php index 1e793038311..dd73ef736ad 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLAnywhere12Platform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLAnywhere12Platform.php @@ -8,8 +8,6 @@ /** * The SQLAnywhere12Platform provides the behavior, features and SQL dialect of the * SAP Sybase SQL Anywhere 12 database platform. - * - * @link www.doctrine-project.org */ class SQLAnywhere12Platform extends SQLAnywhere11Platform { diff --git a/lib/Doctrine/DBAL/Platforms/SQLAnywhere16Platform.php b/lib/Doctrine/DBAL/Platforms/SQLAnywhere16Platform.php index b58b5740c5f..35d4238e4a3 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLAnywhere16Platform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLAnywhere16Platform.php @@ -8,8 +8,6 @@ /** * The SQLAnywhere16Platform provides the behavior, features and SQL dialect of the * SAP Sybase SQL Anywhere 16 database platform. - * - * @link www.doctrine-project.org */ class SQLAnywhere16Platform extends SQLAnywhere12Platform { diff --git a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php index b538881a967..b1105e90faa 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php @@ -33,8 +33,6 @@ /** * The SQLAnywherePlatform provides the behavior, features and SQL dialect of the * SAP Sybase SQL Anywhere 10 database platform. - * - * @link www.doctrine-project.org */ class SQLAnywherePlatform extends AbstractPlatform { diff --git a/lib/Doctrine/DBAL/Portability/Connection.php b/lib/Doctrine/DBAL/Portability/Connection.php index a7446cf89ea..32186dcb0ec 100644 --- a/lib/Doctrine/DBAL/Portability/Connection.php +++ b/lib/Doctrine/DBAL/Portability/Connection.php @@ -12,8 +12,6 @@ /** * Portability wrapper for a Connection. - * - * @link www.doctrine-project.org */ class Connection extends \Doctrine\DBAL\Connection { diff --git a/lib/Doctrine/DBAL/Portability/Statement.php b/lib/Doctrine/DBAL/Portability/Statement.php index 1049ff1d633..1499ff1bf48 100644 --- a/lib/Doctrine/DBAL/Portability/Statement.php +++ b/lib/Doctrine/DBAL/Portability/Statement.php @@ -14,8 +14,6 @@ /** * Portability wrapper for a Statement. - * - * @link www.doctrine-project.org */ class Statement implements IteratorAggregate, DriverStatement { diff --git a/lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php b/lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php index 3f4086e5db2..443d71bc37e 100644 --- a/lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php +++ b/lib/Doctrine/DBAL/Query/Expression/CompositeExpression.php @@ -8,8 +8,6 @@ /** * Composite expression is responsible to build a group of similar expression. - * - * @link www.doctrine-project.org */ class CompositeExpression implements Countable { diff --git a/lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php b/lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php index 074ba4aa33f..91f370aecb6 100644 --- a/lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php +++ b/lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php @@ -11,8 +11,6 @@ /** * ExpressionBuilder class is responsible to dynamically create SQL query parts. - * - * @link www.doctrine-project.org */ class ExpressionBuilder { diff --git a/lib/Doctrine/DBAL/Query/QueryBuilder.php b/lib/Doctrine/DBAL/Query/QueryBuilder.php index 9349330e947..12584d960ab 100644 --- a/lib/Doctrine/DBAL/Query/QueryBuilder.php +++ b/lib/Doctrine/DBAL/Query/QueryBuilder.php @@ -28,8 +28,6 @@ * The query builder does no validation whatsoever if certain features even work with the * underlying database vendor. Limit queries and joins are NOT applied to UPDATE and DELETE statements * even if some vendors such as MySQL support it. - * - * @link www.doctrine-project.org */ class QueryBuilder { diff --git a/lib/Doctrine/DBAL/SQLParserUtils.php b/lib/Doctrine/DBAL/SQLParserUtils.php index 307336c4ec7..3bf9e4720b7 100644 --- a/lib/Doctrine/DBAL/SQLParserUtils.php +++ b/lib/Doctrine/DBAL/SQLParserUtils.php @@ -20,8 +20,6 @@ /** * Utility class that parses sql statements with regard to types and parameters. - * - * @link www.doctrine-project.org */ class SQLParserUtils { diff --git a/lib/Doctrine/DBAL/SQLParserUtilsException.php b/lib/Doctrine/DBAL/SQLParserUtilsException.php index 271a9929a93..a500ed52dd3 100644 --- a/lib/Doctrine/DBAL/SQLParserUtilsException.php +++ b/lib/Doctrine/DBAL/SQLParserUtilsException.php @@ -6,8 +6,6 @@ /** * Doctrine\DBAL\ConnectionException - * - * @link www.doctrine-project.org */ class SQLParserUtilsException extends DBALException { diff --git a/lib/Doctrine/DBAL/Schema/AbstractAsset.php b/lib/Doctrine/DBAL/Schema/AbstractAsset.php index 9a7fd7dd4d5..eb7262e32a6 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractAsset.php +++ b/lib/Doctrine/DBAL/Schema/AbstractAsset.php @@ -19,8 +19,6 @@ * * This encapsulation hack is necessary to keep a consistent state of the database schema. Say we have a list of tables * array($tableName => Table($tableName)); if you want to rename the table, you have to make sure - * - * @link www.doctrine-project.org */ abstract class AbstractAsset { diff --git a/lib/Doctrine/DBAL/Schema/Column.php b/lib/Doctrine/DBAL/Schema/Column.php index 642f36b2227..aef471e06fe 100644 --- a/lib/Doctrine/DBAL/Schema/Column.php +++ b/lib/Doctrine/DBAL/Schema/Column.php @@ -12,8 +12,6 @@ /** * Object representation of a database column. - * - * @link www.doctrine-project.org */ class Column extends AbstractAsset { diff --git a/lib/Doctrine/DBAL/Schema/ColumnDiff.php b/lib/Doctrine/DBAL/Schema/ColumnDiff.php index ded22d1af62..cb64592109b 100644 --- a/lib/Doctrine/DBAL/Schema/ColumnDiff.php +++ b/lib/Doctrine/DBAL/Schema/ColumnDiff.php @@ -6,8 +6,6 @@ /** * Represents the change of a column. - * - * @link www.doctrine-project.org */ class ColumnDiff { diff --git a/lib/Doctrine/DBAL/Schema/Comparator.php b/lib/Doctrine/DBAL/Schema/Comparator.php index ed339e0a69d..f95417face2 100644 --- a/lib/Doctrine/DBAL/Schema/Comparator.php +++ b/lib/Doctrine/DBAL/Schema/Comparator.php @@ -15,8 +15,6 @@ /** * Compares two Schemas and return an instance of SchemaDiff. - * - * @link www.doctrine-project.org */ class Comparator { diff --git a/lib/Doctrine/DBAL/Schema/Constraint.php b/lib/Doctrine/DBAL/Schema/Constraint.php index af0d443ceda..65e239ec119 100644 --- a/lib/Doctrine/DBAL/Schema/Constraint.php +++ b/lib/Doctrine/DBAL/Schema/Constraint.php @@ -6,8 +6,6 @@ /** * Marker interface for constraints. - * - * @link www.doctrine-project.org */ interface Constraint { diff --git a/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php b/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php index 7e1f9d62bab..f5e225512ab 100644 --- a/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php @@ -13,8 +13,6 @@ /** * IBM Db2 Schema Manager. - * - * @link www.doctrine-project.org */ class DB2SchemaManager extends AbstractSchemaManager { diff --git a/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php b/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php index 02e83b8a656..31850d7f23e 100644 --- a/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php +++ b/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php @@ -14,8 +14,6 @@ /** * An abstraction class for a foreign key constraint. - * - * @link www.doctrine-project.org */ class ForeignKeyConstraint extends AbstractAsset implements Constraint { diff --git a/lib/Doctrine/DBAL/Schema/Identifier.php b/lib/Doctrine/DBAL/Schema/Identifier.php index a688be8e460..f34465e9efb 100644 --- a/lib/Doctrine/DBAL/Schema/Identifier.php +++ b/lib/Doctrine/DBAL/Schema/Identifier.php @@ -7,8 +7,6 @@ * * Wraps identifier names like column names in indexes / foreign keys * in an abstract class for proper quotation capabilities. - * - * @link www.doctrine-project.org */ class Identifier extends AbstractAsset { diff --git a/lib/Doctrine/DBAL/Schema/SQLAnywhereSchemaManager.php b/lib/Doctrine/DBAL/Schema/SQLAnywhereSchemaManager.php index e88051db8d1..62d5fa88e89 100644 --- a/lib/Doctrine/DBAL/Schema/SQLAnywhereSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SQLAnywhereSchemaManager.php @@ -9,8 +9,6 @@ /** * SAP Sybase SQL Anywhere schema manager. - * - * @link www.doctrine-project.org */ class SQLAnywhereSchemaManager extends AbstractSchemaManager { diff --git a/lib/Doctrine/DBAL/Schema/Schema.php b/lib/Doctrine/DBAL/Schema/Schema.php index c0d6601cb67..7b75f4fb743 100644 --- a/lib/Doctrine/DBAL/Schema/Schema.php +++ b/lib/Doctrine/DBAL/Schema/Schema.php @@ -34,8 +34,6 @@ * the CREATE/DROP SQL visitors will just filter this queries and do not * execute them. Only the queries for the currently connected database are * executed. - * - * @link www.doctrine-project.org */ class Schema extends AbstractAsset { diff --git a/lib/Doctrine/DBAL/Schema/SchemaConfig.php b/lib/Doctrine/DBAL/Schema/SchemaConfig.php index 3e15efb4c9f..b8c3502f758 100644 --- a/lib/Doctrine/DBAL/Schema/SchemaConfig.php +++ b/lib/Doctrine/DBAL/Schema/SchemaConfig.php @@ -4,8 +4,6 @@ /** * Configuration for a Schema. - * - * @link www.doctrine-project.org */ class SchemaConfig { diff --git a/lib/Doctrine/DBAL/Schema/SchemaDiff.php b/lib/Doctrine/DBAL/Schema/SchemaDiff.php index e39a85bf943..0f2e25fb32b 100644 --- a/lib/Doctrine/DBAL/Schema/SchemaDiff.php +++ b/lib/Doctrine/DBAL/Schema/SchemaDiff.php @@ -7,8 +7,6 @@ /** * Schema Diff. - * - * @link www.doctrine-project.org */ class SchemaDiff { diff --git a/lib/Doctrine/DBAL/Schema/Sequence.php b/lib/Doctrine/DBAL/Schema/Sequence.php index c88f4b2f3c0..24cf4aae0b4 100644 --- a/lib/Doctrine/DBAL/Schema/Sequence.php +++ b/lib/Doctrine/DBAL/Schema/Sequence.php @@ -9,8 +9,6 @@ /** * Sequence structure. - * - * @link www.doctrine-project.org */ class Sequence extends AbstractAsset { diff --git a/lib/Doctrine/DBAL/Schema/Table.php b/lib/Doctrine/DBAL/Schema/Table.php index 85e8d8c6946..4822cf6b17d 100644 --- a/lib/Doctrine/DBAL/Schema/Table.php +++ b/lib/Doctrine/DBAL/Schema/Table.php @@ -17,8 +17,6 @@ /** * Object Representation of a table. - * - * @link www.doctrine-project.org */ class Table extends AbstractAsset { diff --git a/lib/Doctrine/DBAL/Schema/TableDiff.php b/lib/Doctrine/DBAL/Schema/TableDiff.php index 75ca75ff4b3..457e1b6a963 100644 --- a/lib/Doctrine/DBAL/Schema/TableDiff.php +++ b/lib/Doctrine/DBAL/Schema/TableDiff.php @@ -6,8 +6,6 @@ /** * Table Diff. - * - * @link www.doctrine-project.org */ class TableDiff { diff --git a/lib/Doctrine/DBAL/Schema/View.php b/lib/Doctrine/DBAL/Schema/View.php index bee0a019a0e..ac8d6cb5cb4 100644 --- a/lib/Doctrine/DBAL/Schema/View.php +++ b/lib/Doctrine/DBAL/Schema/View.php @@ -4,8 +4,6 @@ /** * Representation of a Database View. - * - * @link www.doctrine-project.org */ class View extends AbstractAsset { diff --git a/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php b/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php index f1041ed13f6..44f5ea80af5 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php @@ -12,8 +12,6 @@ /** * Gathers SQL statements that allow to completely drop the current schema. - * - * @link www.doctrine-project.org */ class DropSchemaSqlCollector extends AbstractVisitor { diff --git a/lib/Doctrine/DBAL/Schema/Visitor/NamespaceVisitor.php b/lib/Doctrine/DBAL/Schema/Visitor/NamespaceVisitor.php index 35d18d6c4b8..186fe1b4213 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/NamespaceVisitor.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/NamespaceVisitor.php @@ -4,8 +4,6 @@ /** * Visitor that can visit schema namespaces. - * - * @link www.doctrine-project.org */ interface NamespaceVisitor { diff --git a/lib/Doctrine/DBAL/Schema/Visitor/SchemaDiffVisitor.php b/lib/Doctrine/DBAL/Schema/Visitor/SchemaDiffVisitor.php index 695ccdb68c3..5ec843d9be6 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/SchemaDiffVisitor.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/SchemaDiffVisitor.php @@ -9,8 +9,6 @@ /** * Visit a SchemaDiff. - * - * @link www.doctrine-project.org */ interface SchemaDiffVisitor { diff --git a/lib/Doctrine/DBAL/Schema/Visitor/Visitor.php b/lib/Doctrine/DBAL/Schema/Visitor/Visitor.php index 9cdea2d6d8a..05c842830c5 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/Visitor.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/Visitor.php @@ -11,8 +11,6 @@ /** * Schema Visitor used for Validation or Generation purposes. - * - * @link www.doctrine-project.org */ interface Visitor { diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php index 9a4279d3f5c..0e815663786 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php @@ -24,8 +24,6 @@ * the command line. * * @deprecated Use a database client application instead - * - * @link www.doctrine-project.org */ class ImportCommand extends Command { diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php index f99684122be..8361219ad08 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php @@ -16,8 +16,6 @@ /** * Task for executing arbitrary SQL that can come from a file or directly from * the command line. - * - * @link www.doctrine-project.org */ class RunSqlCommand extends Command { diff --git a/lib/Doctrine/DBAL/Tools/Console/Helper/ConnectionHelper.php b/lib/Doctrine/DBAL/Tools/Console/Helper/ConnectionHelper.php index 5aa2ea9a5d1..b5497d068a0 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Helper/ConnectionHelper.php +++ b/lib/Doctrine/DBAL/Tools/Console/Helper/ConnectionHelper.php @@ -7,8 +7,6 @@ /** * Doctrine CLI Connection Helper. - * - * @link www.doctrine-project.org */ class ConnectionHelper extends Helper { diff --git a/lib/Doctrine/DBAL/Types/ConversionException.php b/lib/Doctrine/DBAL/Types/ConversionException.php index d618adc8a49..b9f8a82e7ec 100644 --- a/lib/Doctrine/DBAL/Types/ConversionException.php +++ b/lib/Doctrine/DBAL/Types/ConversionException.php @@ -1,11 +1,5 @@ 0 it is necessary to use this type. - * - * @link www.doctrine-project.org */ class VarDateTimeType extends DateTimeType { diff --git a/lib/Doctrine/DBAL/Version.php b/lib/Doctrine/DBAL/Version.php index 9173dc89c00..60530e69a76 100644 --- a/lib/Doctrine/DBAL/Version.php +++ b/lib/Doctrine/DBAL/Version.php @@ -8,8 +8,6 @@ /** * Class to store and retrieve the version of Doctrine. - * - * @link www.doctrine-project.org */ class Version { diff --git a/lib/Doctrine/DBAL/VersionAwarePlatformDriver.php b/lib/Doctrine/DBAL/VersionAwarePlatformDriver.php index b140a30d062..a4864d0b287 100644 --- a/lib/Doctrine/DBAL/VersionAwarePlatformDriver.php +++ b/lib/Doctrine/DBAL/VersionAwarePlatformDriver.php @@ -11,8 +11,6 @@ * support the correct features and SQL syntax of each version. * This interface should be implemented by drivers that are capable to do this * distinction. - * - * @link www.doctrine-project.org */ interface VersionAwarePlatformDriver { diff --git a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php index 43431ea9f9d..d8b0c375801 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php @@ -17,9 +17,6 @@ use PHPUnit\Framework\TestCase; use function array_keys; -/** - * @link www.doctrine-project.org - */ class ComparatorTest extends TestCase { public function testCompareSame1() diff --git a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php index fc1b1ddb0c7..78fd894de05 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php @@ -1,21 +1,5 @@ . - */ + namespace Doctrine\Tests\DBAL\Sharding; use Doctrine\DBAL\Sharding\PoolingShardConnection; From bae46abfbfa022f80d0117ced9722a1f0b6229ac Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 11 Oct 2018 22:11:45 -0700 Subject: [PATCH 42/76] Trying to fix failing DB builds Currently, builds like https://travis-ci.org/doctrine/dbal/jobs/440354436 are failing do to an APT issue. Trying to update APT packages as per support recommendation. --- tests/travis/install-db2-ibm_db2.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/travis/install-db2-ibm_db2.sh b/tests/travis/install-db2-ibm_db2.sh index 7f9a11b38f7..b59bb6396fd 100644 --- a/tests/travis/install-db2-ibm_db2.sh +++ b/tests/travis/install-db2-ibm_db2.sh @@ -4,6 +4,8 @@ set -ex echo "Installing extension" ( + # updating APT packages as per support recommendation + sudo apt -y -q update sudo apt install ksh cd /tmp From 7034013334ddc7c1e36961ea8b78b76669827faa Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 28 Sep 2018 08:54:15 -0700 Subject: [PATCH 43/76] Implemented handling BLOBs represented as stream resources for IBM DB2 --- .../DBAL/Driver/IBMDB2/DB2Statement.php | 127 +++++++++++++++--- .../Tests/DBAL/Functional/BlobTest.php | 22 ++- 2 files changed, 118 insertions(+), 31 deletions(-) diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php index 5a303ceb856..9c87d46319b 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php @@ -13,8 +13,10 @@ use ReflectionProperty; use stdClass; use const CASE_LOWER; +use const DB2_BINARY; use const DB2_CHAR; use const DB2_LONG; +use const DB2_PARAM_FILE; use const DB2_PARAM_IN; use function array_change_key_case; use function db2_bind_param; @@ -28,14 +30,21 @@ use function db2_num_rows; use function db2_stmt_error; use function db2_stmt_errormsg; +use function error_get_last; +use function fclose; use function func_get_args; use function func_num_args; +use function fwrite; use function gettype; use function is_object; +use function is_resource; use function is_string; use function ksort; use function sprintf; +use function stream_copy_to_stream; +use function stream_get_meta_data; use function strtolower; +use function tmpfile; class DB2Statement implements IteratorAggregate, Statement { @@ -45,6 +54,14 @@ class DB2Statement implements IteratorAggregate, Statement /** @var mixed[] */ private $bindParam = []; + /** + * Map of LOB parameter positions to the tuples containing reference to the variable bound to the driver statement + * and the temporary file handle bound to the underlying statement + * + * @var mixed[][] + */ + private $lobs = []; + /** @var string Name of the default class to instantiate when fetching class instances. */ private $defaultFetchClass = '\stdClass'; @@ -61,16 +78,6 @@ class DB2Statement implements IteratorAggregate, Statement */ private $result = false; - /** - * DB2_BINARY, DB2_CHAR, DB2_DOUBLE, or DB2_LONG - * - * @var int[] - */ - static private $typeMap = [ - ParameterType::INTEGER => DB2_LONG, - ParameterType::STRING => DB2_CHAR, - ]; - /** * @param resource $stmt */ @@ -92,21 +99,48 @@ public function bindValue($param, $value, $type = ParameterType::STRING) */ public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null) { - $this->bindParam[$column] =& $variable; + switch ($type) { + case ParameterType::INTEGER: + $this->bind($column, $variable, DB2_PARAM_IN, DB2_LONG); + break; - if ($type && isset(self::$typeMap[$type])) { - $type = self::$typeMap[$type]; - } else { - $type = DB2_CHAR; - } + case ParameterType::LARGE_OBJECT: + if (isset($this->lobs[$column])) { + [, $handle] = $this->lobs[$column]; + fclose($handle); + } - if (! db2_bind_param($this->stmt, $column, 'variable', DB2_PARAM_IN, $type)) { - throw new DB2Exception(db2_stmt_errormsg()); + $handle = $this->createTemporaryFile(); + $path = stream_get_meta_data($handle)['uri']; + + $this->bind($column, $path, DB2_PARAM_FILE, DB2_BINARY); + + $this->lobs[$column] = [&$variable, $handle]; + break; + + default: + $this->bind($column, $variable, DB2_PARAM_IN, DB2_CHAR); + break; } return true; } + /** + * @param int|string $parameter Parameter position or name + * @param mixed $variable + * + * @throws DB2Exception + */ + private function bind($parameter, &$variable, int $parameterType, int $dataType) : void + { + $this->bindParam[$parameter] =& $variable; + + if (! db2_bind_param($this->stmt, $parameter, 'variable', $parameterType, $dataType)) { + throw new DB2Exception(db2_stmt_errormsg()); + } + } + /** * {@inheritdoc} */ @@ -177,8 +211,24 @@ public function execute($params = null) } } + foreach ($this->lobs as [$source, $target]) { + if (is_resource($source)) { + $this->copyStreamToStream($source, $target); + + continue; + } + + $this->writeStringToStream($source, $target); + } + $retval = db2_execute($this->stmt, $params); + foreach ($this->lobs as [, $handle]) { + fclose($handle); + } + + $this->lobs = []; + if ($retval === false) { throw new DB2Exception(db2_stmt_errormsg()); } @@ -372,4 +422,45 @@ private function castObject(stdClass $sourceObject, $destinationClass, array $ct return $destinationClass; } + + /** + * @return resource + * + * @throws DB2Exception + */ + private function createTemporaryFile() + { + $handle = @tmpfile(); + + if ($handle === false) { + throw new DB2Exception('Could not create temporary file: ' . error_get_last()['message']); + } + + return $handle; + } + + /** + * @param resource $source + * @param resource $target + * + * @throws DB2Exception + */ + private function copyStreamToStream($source, $target) : void + { + if (@stream_copy_to_stream($source, $target) === false) { + throw new DB2Exception('Could not copy source stream to temporary file: ' . error_get_last()['message']); + } + } + + /** + * @param resource $target + * + * @throws DB2Exception + */ + private function writeStringToStream(string $string, $target) : void + { + if (@fwrite($target, $string) === false) { + throw new DB2Exception('Could not write string to temporary file: ' . error_get_last()['message']); + } + } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php b/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php index 779f33254b5..1b3df42ec8b 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Functional; +use Doctrine\DBAL\Driver\OCI8\Driver as OCI8Driver; use Doctrine\DBAL\Driver\PDOSqlsrv\Driver as PDOSQLSrvDriver; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; @@ -10,7 +11,6 @@ use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DbalFunctionalTestCase; use function fopen; -use function in_array; use function str_repeat; use function stream_get_contents; @@ -55,10 +55,9 @@ public function testInsert() public function testInsertProcessesStream() { - if (in_array($this->connection->getDatabasePlatform()->getName(), ['oracle', 'db2'], true)) { - // https://github.com/doctrine/dbal/issues/3288 for DB2 - // https://github.com/doctrine/dbal/issues/3290 for Oracle - $this->markTestIncomplete('Platform does not support stream resources as parameters'); + // https://github.com/doctrine/dbal/issues/3290 + if ($this->connection->getDriver() instanceof OCI8Driver) { + $this->markTestIncomplete('The oci8 driver does not support stream resources as parameters'); } $longBlob = str_repeat('x', 4 * 8192); // send 4 chunks @@ -112,10 +111,9 @@ public function testUpdate() public function testUpdateProcessesStream() { - if (in_array($this->connection->getDatabasePlatform()->getName(), ['oracle', 'db2'], true)) { - // https://github.com/doctrine/dbal/issues/3288 for DB2 - // https://github.com/doctrine/dbal/issues/3290 for Oracle - $this->markTestIncomplete('Platform does not support stream resources as parameters'); + // https://github.com/doctrine/dbal/issues/3290 + if ($this->connection->getDriver() instanceof OCI8Driver) { + $this->markTestIncomplete('The oci8 driver does not support stream resources as parameters'); } $this->connection->insert('blob_table', [ @@ -141,10 +139,8 @@ public function testUpdateProcessesStream() public function testBindParamProcessesStream() { - if (in_array($this->connection->getDatabasePlatform()->getName(), ['oracle', 'db2'], true)) { - // https://github.com/doctrine/dbal/issues/3288 for DB2 - // https://github.com/doctrine/dbal/issues/3290 for Oracle - $this->markTestIncomplete('Platform does not support stream resources as parameters'); + if ($this->connection->getDriver() instanceof OCI8Driver) { + $this->markTestIncomplete('The oci8 driver does not support stream resources as parameters'); } $stmt = $this->connection->prepare("INSERT INTO blob_table(id, clobfield, blobfield) VALUES (1, 'ignored', ?)"); From 0da71631839202f75ab8023c1bf62c7278fa0264 Mon Sep 17 00:00:00 2001 From: Massimiliano Arione Date: Thu, 11 Oct 2018 18:04:30 +0200 Subject: [PATCH 44/76] remove ClassLoader --- docs/en/reference/introduction.rst | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/docs/en/reference/introduction.rst b/docs/en/reference/introduction.rst index e52f7fff858..ae495ea9815 100644 --- a/docs/en/reference/introduction.rst +++ b/docs/en/reference/introduction.rst @@ -25,19 +25,13 @@ The following database vendors are currently supported: The Doctrine 2 database layer can be used independently of the object-relational mapper. In order to use the DBAL all you need is -the ``Doctrine\Common`` and ``Doctrine\DBAL`` namespaces. Once you -have the Common and DBAL namespaces you must setup a class loader -to be able to autoload the classes: +the class loader provided by Composer, to be able to autoload the classes: .. code-block:: php register(); + + require_once 'vendor/autoload.php'; Now you are able to load classes that are in the ``/path/to/doctrine`` directory like From 465c929130bc6d817a2f23daaa7ab845ee5ee6aa Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Mon, 15 Oct 2018 19:23:02 -0700 Subject: [PATCH 45/76] Updated PHPUnit to 7.4 --- composer.json | 3 +- composer.lock | 218 ++++++++++++++++++++------------------------------ 2 files changed, 87 insertions(+), 134 deletions(-) diff --git a/composer.json b/composer.json index c0a35f4d9cb..9d5f610c2b8 100644 --- a/composer.json +++ b/composer.json @@ -30,8 +30,7 @@ "doctrine/coding-standard": "^5.0", "jetbrains/phpstorm-stubs": "^2018.1.2", "phpstan/phpstan": "^0.10.1", - "phpunit/phpunit": "^7.1.2", - "phpunit/phpunit-mock-objects": "!=3.2.4,!=3.2.5", + "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 0ac48fe1249..0c15627967d 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": "a6e554864457c4bf9babe37f88174255", + "content-hash": "1147a9427c03f98ca063806250633645", "packages": [ { "name": "doctrine/cache", @@ -474,25 +474,28 @@ }, { "name": "myclabs/deep-copy", - "version": "1.7.0", + "version": "1.8.1", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e" + "reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e", - "reference": "3b8a3a99ba1f6a3952ac2747d989303cbd6b7a3e", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8", + "reference": "3e01bdad3e18354c3dce54466b7fbe33a9f9f7f8", "shasum": "" }, "require": { - "php": "^5.6 || ^7.0" + "php": "^7.1" + }, + "replace": { + "myclabs/deep-copy": "self.version" }, "require-dev": { "doctrine/collections": "^1.0", "doctrine/common": "^2.6", - "phpunit/phpunit": "^4.1" + "phpunit/phpunit": "^7.1" }, "type": "library", "autoload": { @@ -515,7 +518,7 @@ "object", "object graph" ], - "time": "2017-10-19T19:58:43+00:00" + "time": "2018-06-11T23:09:50+00:00" }, { "name": "nette/bootstrap", @@ -1096,22 +1099,22 @@ }, { "name": "phar-io/manifest", - "version": "1.0.1", + "version": "1.0.3", "source": { "type": "git", "url": "https://github.com/phar-io/manifest.git", - "reference": "2df402786ab5368a0169091f61a7c1e0eb6852d0" + "reference": "7761fcacf03b4d4f16e7ccb606d4879ca431fcf4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/manifest/zipball/2df402786ab5368a0169091f61a7c1e0eb6852d0", - "reference": "2df402786ab5368a0169091f61a7c1e0eb6852d0", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/7761fcacf03b4d4f16e7ccb606d4879ca431fcf4", + "reference": "7761fcacf03b4d4f16e7ccb606d4879ca431fcf4", "shasum": "" }, "require": { "ext-dom": "*", "ext-phar": "*", - "phar-io/version": "^1.0.1", + "phar-io/version": "^2.0", "php": "^5.6 || ^7.0" }, "type": "library", @@ -1147,20 +1150,20 @@ } ], "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", - "time": "2017-03-05T18:14:27+00:00" + "time": "2018-07-08T19:23:20+00:00" }, { "name": "phar-io/version", - "version": "1.0.1", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/phar-io/version.git", - "reference": "a70c0ced4be299a63d32fa96d9281d03e94041df" + "reference": "45a2ec53a73c70ce41d55cedef9063630abaf1b6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/version/zipball/a70c0ced4be299a63d32fa96d9281d03e94041df", - "reference": "a70c0ced4be299a63d32fa96d9281d03e94041df", + "url": "https://api.github.com/repos/phar-io/version/zipball/45a2ec53a73c70ce41d55cedef9063630abaf1b6", + "reference": "45a2ec53a73c70ce41d55cedef9063630abaf1b6", "shasum": "" }, "require": { @@ -1194,7 +1197,7 @@ } ], "description": "Library for handling version information and constraints", - "time": "2017-03-05T17:38:23+00:00" + "time": "2018-07-08T19:19:57+00:00" }, { "name": "phpdocumentor/reflection-common", @@ -1350,33 +1353,33 @@ }, { "name": "phpspec/prophecy", - "version": "1.7.5", + "version": "1.8.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "dfd6be44111a7c41c2e884a336cc4f461b3b2401" + "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/dfd6be44111a7c41c2e884a336cc4f461b3b2401", - "reference": "dfd6be44111a7c41c2e884a336cc4f461b3b2401", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/4ba436b55987b4bf311cb7c6ba82aa528aac0a06", + "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06", "shasum": "" }, "require": { "doctrine/instantiator": "^1.0.2", "php": "^5.3|^7.0", "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0", - "sebastian/comparator": "^1.1|^2.0", + "sebastian/comparator": "^1.1|^2.0|^3.0", "sebastian/recursion-context": "^1.0|^2.0|^3.0" }, "require-dev": { "phpspec/phpspec": "^2.5|^3.2", - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5" + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5 || ^7.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.7.x-dev" + "dev-master": "1.8.x-dev" } }, "autoload": { @@ -1409,7 +1412,7 @@ "spy", "stub" ], - "time": "2018-02-19T10:16:54+00:00" + "time": "2018-08-05T17:53:17+00:00" }, { "name": "phpstan/phpdoc-parser", @@ -1527,23 +1530,23 @@ }, { "name": "phpunit/php-code-coverage", - "version": "6.0.5", + "version": "6.0.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "4cab20a326d14de7575a8e235c70d879b569a57a" + "reference": "848f78b3309780fef7ec8c4666b7ab4e6b09b22f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/4cab20a326d14de7575a8e235c70d879b569a57a", - "reference": "4cab20a326d14de7575a8e235c70d879b569a57a", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/848f78b3309780fef7ec8c4666b7ab4e6b09b22f", + "reference": "848f78b3309780fef7ec8c4666b7ab4e6b09b22f", "shasum": "" }, "require": { "ext-dom": "*", "ext-xmlwriter": "*", "php": "^7.1", - "phpunit/php-file-iterator": "^1.4.2", + "phpunit/php-file-iterator": "^2.0", "phpunit/php-text-template": "^1.2.1", "phpunit/php-token-stream": "^3.0", "sebastian/code-unit-reverse-lookup": "^1.0.1", @@ -1586,29 +1589,32 @@ "testing", "xunit" ], - "time": "2018-05-28T11:49:20+00:00" + "time": "2018-10-04T03:41:23+00:00" }, { "name": "phpunit/php-file-iterator", - "version": "1.4.5", + "version": "2.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4" + "reference": "050bedf145a257b1ff02746c31894800e5122946" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/730b01bc3e867237eaac355e06a36b85dd93a8b4", - "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/050bedf145a257b1ff02746c31894800e5122946", + "reference": "050bedf145a257b1ff02746c31894800e5122946", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": "^7.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.4.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { @@ -1623,7 +1629,7 @@ "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", + "email": "sebastian@phpunit.de", "role": "lead" } ], @@ -1633,7 +1639,7 @@ "filesystem", "iterator" ], - "time": "2017-11-27T13:52:08+00:00" + "time": "2018-09-13T20:33:42+00:00" }, { "name": "phpunit/php-text-template", @@ -1776,47 +1782,51 @@ }, { "name": "phpunit/phpunit", - "version": "7.1.4", + "version": "7.4.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "6d51299e307dc510149e0b7cd1931dd11770e1cb" + "reference": "f3837fa1e07758057ae06e8ddec6d06ba183f126" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/6d51299e307dc510149e0b7cd1931dd11770e1cb", - "reference": "6d51299e307dc510149e0b7cd1931dd11770e1cb", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/f3837fa1e07758057ae06e8ddec6d06ba183f126", + "reference": "f3837fa1e07758057ae06e8ddec6d06ba183f126", "shasum": "" }, "require": { + "doctrine/instantiator": "^1.1", "ext-dom": "*", "ext-json": "*", "ext-libxml": "*", "ext-mbstring": "*", "ext-xml": "*", - "myclabs/deep-copy": "^1.6.1", - "phar-io/manifest": "^1.0.1", - "phar-io/version": "^1.0", + "myclabs/deep-copy": "^1.7", + "phar-io/manifest": "^1.0.2", + "phar-io/version": "^2.0", "php": "^7.1", "phpspec/prophecy": "^1.7", - "phpunit/php-code-coverage": "^6.0.1", - "phpunit/php-file-iterator": "^1.4.3", + "phpunit/php-code-coverage": "^6.0.7", + "phpunit/php-file-iterator": "^2.0.1", "phpunit/php-text-template": "^1.2.1", "phpunit/php-timer": "^2.0", - "phpunit/phpunit-mock-objects": "^6.1.1", - "sebastian/comparator": "^2.1 || ^3.0", + "sebastian/comparator": "^3.0", "sebastian/diff": "^3.0", "sebastian/environment": "^3.1", "sebastian/exporter": "^3.1", "sebastian/global-state": "^2.0", "sebastian/object-enumerator": "^3.0.3", - "sebastian/resource-operations": "^1.0", + "sebastian/resource-operations": "^2.0", "sebastian/version": "^2.0.1" }, + "conflict": { + "phpunit/phpunit-mock-objects": "*" + }, "require-dev": { "ext-pdo": "*" }, "suggest": { + "ext-soap": "*", "ext-xdebug": "*", "phpunit/php-invoker": "^2.0" }, @@ -1826,7 +1836,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "7.1-dev" + "dev-master": "7.4-dev" } }, "autoload": { @@ -1852,63 +1862,7 @@ "testing", "xunit" ], - "time": "2018-04-18T13:41:53+00:00" - }, - { - "name": "phpunit/phpunit-mock-objects", - "version": "6.1.2", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "f9756fd4f43f014cb2dca98deeaaa8ce5500a36e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/f9756fd4f43f014cb2dca98deeaaa8ce5500a36e", - "reference": "f9756fd4f43f014cb2dca98deeaaa8ce5500a36e", - "shasum": "" - }, - "require": { - "doctrine/instantiator": "^1.0.5", - "php": "^7.1", - "phpunit/php-text-template": "^1.2.1", - "sebastian/exporter": "^3.1" - }, - "require-dev": { - "phpunit/phpunit": "^7.0" - }, - "suggest": { - "ext-soap": "*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "6.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": "Mock Object library for PHPUnit", - "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", - "keywords": [ - "mock", - "xunit" - ], - "time": "2018-05-29T13:54:20+00:00" + "time": "2018-10-05T04:05:24+00:00" }, { "name": "psr/log", @@ -2004,30 +1958,30 @@ }, { "name": "sebastian/comparator", - "version": "2.1.3", + "version": "3.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "34369daee48eafb2651bea869b4b15d75ccc35f9" + "reference": "5de4fc177adf9bce8df98d8d141a7559d7ccf6da" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/34369daee48eafb2651bea869b4b15d75ccc35f9", - "reference": "34369daee48eafb2651bea869b4b15d75ccc35f9", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/5de4fc177adf9bce8df98d8d141a7559d7ccf6da", + "reference": "5de4fc177adf9bce8df98d8d141a7559d7ccf6da", "shasum": "" }, "require": { - "php": "^7.0", - "sebastian/diff": "^2.0 || ^3.0", + "php": "^7.1", + "sebastian/diff": "^3.0", "sebastian/exporter": "^3.1" }, "require-dev": { - "phpunit/phpunit": "^6.4" + "phpunit/phpunit": "^7.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.1.x-dev" + "dev-master": "3.0-dev" } }, "autoload": { @@ -2064,20 +2018,20 @@ "compare", "equality" ], - "time": "2018-02-01T13:46:46+00:00" + "time": "2018-07-12T15:12:46+00:00" }, { "name": "sebastian/diff", - "version": "3.0.0", + "version": "3.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "e09160918c66281713f1c324c1f4c4c3037ba1e8" + "reference": "366541b989927187c4ca70490a35615d3fef2dce" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/e09160918c66281713f1c324c1f4c4c3037ba1e8", - "reference": "e09160918c66281713f1c324c1f4c4c3037ba1e8", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/366541b989927187c4ca70490a35615d3fef2dce", + "reference": "366541b989927187c4ca70490a35615d3fef2dce", "shasum": "" }, "require": { @@ -2120,7 +2074,7 @@ "unidiff", "unified diff" ], - "time": "2018-02-01T13:45:15+00:00" + "time": "2018-06-10T07:54:39+00:00" }, { "name": "sebastian/environment", @@ -2437,25 +2391,25 @@ }, { "name": "sebastian/resource-operations", - "version": "1.0.0", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/resource-operations.git", - "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52" + "reference": "4d7a795d35b889bf80a0cc04e08d77cedfa917a9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", - "reference": "ce990bb21759f94aeafd30209e8cfcdfa8bc3f52", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/4d7a795d35b889bf80a0cc04e08d77cedfa917a9", + "reference": "4d7a795d35b889bf80a0cc04e08d77cedfa917a9", "shasum": "" }, "require": { - "php": ">=5.6.0" + "php": "^7.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.0-dev" } }, "autoload": { @@ -2475,7 +2429,7 @@ ], "description": "Provides a list of PHP built-in functions that operate on resources", "homepage": "https://www.github.com/sebastianbergmann/resource-operations", - "time": "2015-07-28T20:34:47+00:00" + "time": "2018-10-04T04:07:39+00:00" }, { "name": "sebastian/version", From 770202319147a9626003ce91c3209df88f6cbbff Mon Sep 17 00:00:00 2001 From: Ben Davies Date: Mon, 21 May 2018 12:49:26 +0100 Subject: [PATCH 46/76] correctly produce alter table sql to update column comment under postgres --- .../DBAL/Platforms/PostgreSqlPlatform.php | 10 ++++++-- .../AbstractPostgreSqlPlatformTestCase.php | 23 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php index 165b40e0ed3..7643bd67df0 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php @@ -580,11 +580,17 @@ public function getAlterTableSQL(TableDiff $diff) } } - if ($columnDiff->hasChanged('comment')) { + $oldComment = null; + $newComment = $this->getColumnComment($column); + if (null !== $columnDiff->fromColumn) { + $oldComment = $this->getColumnComment($columnDiff->fromColumn); + } + + if ($columnDiff->hasChanged('comment') || ($columnDiff->fromColumn !== null && $oldComment !== $newComment)) { $commentsSQL[] = $this->getCommentOnColumnSQL( $diff->getName($this)->getQuotedName($this), $column->getQuotedName($this), - $this->getColumnComment($column) + $newComment ); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php index 5c0da268107..b7312f376ad 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php @@ -853,6 +853,29 @@ public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() ); } + /** + * @group 3158 + */ + public function testAltersTableColumnCommentIfRequiredByType() + { + $table1 = new Table('"foo"', [new Column('"bar"', Type::getType('datetime'))]); + $table2 = new Table('"foo"', [new Column('"bar"', Type::getType('datetime_immutable'))]); + + $comparator = new Comparator(); + + $tableDiff = $comparator->diffTable($table1, $table2); + + $this->assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); + $this->assertSame( + [ + 'ALTER TABLE "foo" ALTER "bar" TYPE TIMESTAMP(0) WITHOUT TIME ZONE', + 'ALTER TABLE "foo" ALTER "bar" DROP DEFAULT', + 'COMMENT ON COLUMN "foo"."bar" IS \'(DC2Type:datetime_immutable)\'', + ], + $this->platform->getAlterTableSQL($tableDiff) + ); + } + /** * {@inheritdoc} */ From 8a7208d18072b187bd879bb8910af95afdb76bb7 Mon Sep 17 00:00:00 2001 From: Ben Davies Date: Sat, 16 Jun 2018 17:34:58 +0100 Subject: [PATCH 47/76] refactor out getting old column comment --- lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php index 7643bd67df0..242c0fd4f28 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php @@ -580,11 +580,8 @@ public function getAlterTableSQL(TableDiff $diff) } } - $oldComment = null; $newComment = $this->getColumnComment($column); - if (null !== $columnDiff->fromColumn) { - $oldComment = $this->getColumnComment($columnDiff->fromColumn); - } + $oldComment = $this->getOldColumnComment($columnDiff); if ($columnDiff->hasChanged('comment') || ($columnDiff->fromColumn !== null && $oldComment !== $newComment)) { $commentsSQL[] = $this->getCommentOnColumnSQL( @@ -1254,4 +1251,9 @@ private function isNumericType(Type $type) : bool { return $type instanceof IntegerType || $type instanceof BigIntType; } + + private function getOldColumnComment(ColumnDiff $columnDiff) : ?string + { + return $columnDiff->fromColumn ? $this->getColumnComment($columnDiff->fromColumn) : null; + } } From 0a7d5f0c264e9cd2122a9efb6cd20ee0fe8ba1b9 Mon Sep 17 00:00:00 2001 From: Bruno Date: Sun, 2 Sep 2018 10:48:28 +0200 Subject: [PATCH 48/76] Include statements that contain the ARRAY[] notation The first capturing group of the parser regex was stopping form the moment it would find a `[` character. --- lib/Doctrine/DBAL/SQLParserUtils.php | 13 ++++++++----- tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php | 4 ++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/DBAL/SQLParserUtils.php b/lib/Doctrine/DBAL/SQLParserUtils.php index 3bf9e4720b7..537cd9e4884 100644 --- a/lib/Doctrine/DBAL/SQLParserUtils.php +++ b/lib/Doctrine/DBAL/SQLParserUtils.php @@ -14,6 +14,7 @@ use function key; use function ksort; use function preg_match_all; +use function sprintf; use function strlen; use function strpos; use function substr; @@ -199,11 +200,13 @@ public static function expandListParameters($query, $params, $types) */ private static function getUnquotedStatementFragments($statement) { - $literal = self::ESCAPED_SINGLE_QUOTED_TEXT . '|' . - self::ESCAPED_DOUBLE_QUOTED_TEXT . '|' . - self::ESCAPED_BACKTICK_QUOTED_TEXT . '|' . - self::ESCAPED_BRACKET_QUOTED_TEXT; - preg_match_all('/([^\'"`\[]+)(?:' . $literal . ')?/s', $statement, $fragments, PREG_OFFSET_CAPTURE); + $literal = self::ESCAPED_SINGLE_QUOTED_TEXT . '|' . + self::ESCAPED_DOUBLE_QUOTED_TEXT . '|' . + self::ESCAPED_BACKTICK_QUOTED_TEXT . '|' . + self::ESCAPED_BRACKET_QUOTED_TEXT; + $expression = sprintf('/((.+(?i:ARRAY)\\[.+\\])|([^\'"`\\[]+))(?:%s)?/s', $literal); + + preg_match_all($expression, $statement, $fragments, PREG_OFFSET_CAPTURE); return $fragments[1]; } diff --git a/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php b/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php index 68d3cbcedd3..414f909f870 100644 --- a/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php +++ b/tests/Doctrine/Tests/DBAL/SQLParserUtilsTest.php @@ -59,6 +59,10 @@ public function dataGetPlaceholderPositions() ['SELECT [d.ns:col_name] FROM my_table d WHERE [d.date] >= :param1', false, [57 => 'param1']], // Ticket DBAL-552 ['SELECT * FROM foo WHERE jsonb_exists_any(foo.bar, ARRAY[:foo])', false, [56 => 'foo']], // Ticket GH-2295 ['SELECT * FROM foo WHERE jsonb_exists_any(foo.bar, array[:foo])', false, [56 => 'foo']], + ['SELECT table.field1, ARRAY[\'3\'] FROM schema.table table WHERE table.f1 = :foo AND ARRAY[\'3\']', false, [73 => 'foo']], + ['SELECT table.field1, ARRAY[\'3\']::integer[] FROM schema.table table WHERE table.f1 = :foo AND ARRAY[\'3\']::integer[]', false, [84 => 'foo']], + ['SELECT table.field1, ARRAY[:foo] FROM schema.table table WHERE table.f1 = :bar AND ARRAY[\'3\']', false, [27 => 'foo', 74 => 'bar']], + ['SELECT table.field1, ARRAY[:foo]::integer[] FROM schema.table table WHERE table.f1 = :bar AND ARRAY[\'3\']::integer[]', false, [27 => 'foo', 85 => 'bar']], [ <<<'SQLDATA' SELECT * FROM foo WHERE From efbaa87cd04bb14e677dee5db1cdef4b656db9df Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Tue, 23 Oct 2018 09:22:03 +0300 Subject: [PATCH 49/76] Use locked version of PHPStan to avoid accidental build failures --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 461a52b872f..854eb02728b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -427,7 +427,7 @@ jobs: - stage: Code Quality env: DB=none STATIC_ANALYSIS - install: travis_retry composer update --prefer-dist + install: travis_retry composer install --prefer-dist script: vendor/bin/phpstan analyse - stage: Coding standard From aaf2b6312f32af913a68415150c2b799bf9d77bb Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 24 Oct 2018 06:22:59 +0300 Subject: [PATCH 50/76] Fixed quoting of string literals containing backslash --- .../DBAL/Platforms/OraclePlatform.php | 11 ------- .../DBAL/Platforms/PostgreSqlPlatform.php | 11 ------- .../DBAL/Functional/Platform/QuotingTest.php | 32 +++++++++++++++++++ .../AbstractPostgreSqlPlatformTestCase.php | 16 +++++----- .../DBAL/Platforms/OraclePlatformTest.php | 12 +++---- 5 files changed, 46 insertions(+), 36 deletions(-) create mode 100644 tests/Doctrine/Tests/DBAL/Functional/Platform/QuotingTest.php diff --git a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php index bc05b241098..1d249e9aa10 100644 --- a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php @@ -21,7 +21,6 @@ use function implode; use function preg_match; use function sprintf; -use function str_replace; use function strlen; use function strpos; use function strtoupper; @@ -1175,14 +1174,4 @@ public function getBlobTypeDeclarationSQL(array $field) { return 'BLOB'; } - - /** - * {@inheritdoc} - */ - public function quoteStringLiteral($str) - { - $str = str_replace('\\', '\\\\', $str); // Oracle requires backslashes to be escaped aswell. - - return parent::quoteStringLiteral($str); - } } diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php index 242c0fd4f28..cb4603f5199 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php @@ -28,7 +28,6 @@ use function is_numeric; use function is_string; use function sprintf; -use function str_replace; use function strpos; use function strtolower; use function trim; @@ -1199,16 +1198,6 @@ public function getBlobTypeDeclarationSQL(array $field) return 'BYTEA'; } - /** - * {@inheritdoc} - */ - public function quoteStringLiteral($str) - { - $str = str_replace('\\', '\\\\', $str); // PostgreSQL requires backslashes to be escaped aswell. - - return parent::quoteStringLiteral($str); - } - /** * {@inheritdoc} */ diff --git a/tests/Doctrine/Tests/DBAL/Functional/Platform/QuotingTest.php b/tests/Doctrine/Tests/DBAL/Functional/Platform/QuotingTest.php new file mode 100644 index 00000000000..3a1ae7c8440 --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Functional/Platform/QuotingTest.php @@ -0,0 +1,32 @@ +connection->getDatabasePlatform(); + $query = $platform->getDummySelectSQL( + $platform->quoteStringLiteral($string) + ); + + self::assertSame($string, $this->connection->fetchColumn($query)); + } + + /** + * @return mixed[][] + */ + public static function stringLiteralProvider() : iterable + { + return [ + 'backslash' => ['\\'], + 'single-quote' => ["'"], + ]; + } +} diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php index b7312f376ad..2624de8f71c 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php @@ -952,7 +952,7 @@ public function testReturnsCloseActiveDatabaseConnectionsSQL() */ public function testQuotesTableNameInListTableForeignKeysSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true); } /** @@ -961,7 +961,7 @@ public function testQuotesTableNameInListTableForeignKeysSQL() public function testQuotesSchemaNameInListTableForeignKeysSQL() { self::assertContains( - "'Foo''Bar\\\\'", + "'Foo''Bar\\'", $this->platform->getListTableForeignKeysSQL("Foo'Bar\\.baz_table"), '', true @@ -973,7 +973,7 @@ public function testQuotesSchemaNameInListTableForeignKeysSQL() */ public function testQuotesTableNameInListTableConstraintsSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true); } /** @@ -981,7 +981,7 @@ public function testQuotesTableNameInListTableConstraintsSQL() */ public function testQuotesTableNameInListTableIndexesSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\"), '', true); } /** @@ -990,7 +990,7 @@ public function testQuotesTableNameInListTableIndexesSQL() public function testQuotesSchemaNameInListTableIndexesSQL() { self::assertContains( - "'Foo''Bar\\\\'", + "'Foo''Bar\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\.baz_table"), '', true @@ -1002,7 +1002,7 @@ public function testQuotesSchemaNameInListTableIndexesSQL() */ public function testQuotesTableNameInListTableColumnsSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableColumnsSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->platform->getListTableColumnsSQL("Foo'Bar\\"), '', true); } /** @@ -1011,7 +1011,7 @@ public function testQuotesTableNameInListTableColumnsSQL() public function testQuotesSchemaNameInListTableColumnsSQL() { self::assertContains( - "'Foo''Bar\\\\'", + "'Foo''Bar\\'", $this->platform->getListTableColumnsSQL("Foo'Bar\\.baz_table"), '', true @@ -1024,7 +1024,7 @@ public function testQuotesSchemaNameInListTableColumnsSQL() public function testQuotesDatabaseNameInCloseActiveDatabaseConnectionsSQL() { self::assertContains( - "'Foo''Bar\\\\'", + "'Foo''Bar\\'", $this->platform->getCloseActiveDatabaseConnectionsSQL("Foo'Bar\\"), '', true diff --git a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php index 051b3e68dd9..e8f8f0cdd7f 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php @@ -875,7 +875,7 @@ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() */ public function testQuotesDatabaseNameInListSequencesSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->platform->getListSequencesSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->platform->getListSequencesSQL("Foo'Bar\\"), '', true); } /** @@ -883,7 +883,7 @@ public function testQuotesDatabaseNameInListSequencesSQL() */ public function testQuotesTableNameInListTableIndexesSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\"), '', true); } /** @@ -891,7 +891,7 @@ public function testQuotesTableNameInListTableIndexesSQL() */ public function testQuotesTableNameInListTableForeignKeysSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true); } /** @@ -899,7 +899,7 @@ public function testQuotesTableNameInListTableForeignKeysSQL() */ public function testQuotesTableNameInListTableConstraintsSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true); } /** @@ -907,7 +907,7 @@ public function testQuotesTableNameInListTableConstraintsSQL() */ public function testQuotesTableNameInListTableColumnsSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableColumnsSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->platform->getListTableColumnsSQL("Foo'Bar\\"), '', true); } /** @@ -915,6 +915,6 @@ public function testQuotesTableNameInListTableColumnsSQL() */ public function testQuotesDatabaseNameInListTableColumnsSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableColumnsSQL('foo_table', "Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->platform->getListTableColumnsSQL('foo_table', "Foo'Bar\\"), '', true); } } From e35d5e12eadf567d61e0e8295991d0d8b71deba9 Mon Sep 17 00:00:00 2001 From: MichaelC Date: Thu, 25 Oct 2018 16:40:08 +0100 Subject: [PATCH 51/76] Fetch all should use the driver statement's fetchAll method --- lib/Doctrine/DBAL/Cache/ResultCacheStatement.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php index 1636391e697..872f3e71fc9 100644 --- a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php +++ b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php @@ -166,12 +166,7 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX */ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null) { - $rows = []; - while ($row = $this->fetch($fetchMode)) { - $rows[] = $row; - } - - return $rows; + return $this->statement->fetchAll($fetchMode, $fetchArgument, $ctorArgs); } /** From 2e9a2627cfbdc32f1bad1279a2d93652510933d9 Mon Sep 17 00:00:00 2001 From: Nicolas PAJON Date: Wed, 31 Oct 2018 10:20:58 +0100 Subject: [PATCH 52/76] Update Driver.php Adding Windows Authentication compatibility according to http://php.net/manual/en/function.sqlsrv-connect.php "By default, the connection is attempted using Windows Authentication. To connect using SQL Server Authentication, include "UID" and "PWD" in the connection options array." --- lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php b/lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php index 2b84a0fcf81..5b4871b4484 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php @@ -31,8 +31,13 @@ public function connect(array $params, $username = null, $password = null, array $driverOptions['CharacterSet'] = $params['charset']; } - $driverOptions['UID'] = $username; - $driverOptions['PWD'] = $password; + if ($username !== null) { + $driverOptions['UID'] = $username; + } + + if ($password !== null) { + $driverOptions['PWD'] = $password; + } if (! isset($driverOptions['ReturnDatesAsStrings'])) { $driverOptions['ReturnDatesAsStrings'] = 1; From 7cd248c3740b8321e0cce4533ff7d90af8a009a6 Mon Sep 17 00:00:00 2001 From: Nicolas PAJON Date: Wed, 31 Oct 2018 11:30:06 +0100 Subject: [PATCH 53/76] Update Driver.php fix code style --- lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php b/lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php index 5b4871b4484..a9be26e9dea 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/Driver.php @@ -34,7 +34,7 @@ public function connect(array $params, $username = null, $password = null, array if ($username !== null) { $driverOptions['UID'] = $username; } - + if ($password !== null) { $driverOptions['PWD'] = $password; } From 2154f0e35e84b0b26480dd1c2f7a05e11ef42c6d Mon Sep 17 00:00:00 2001 From: Claudio Zizza Date: Sun, 4 Nov 2018 20:02:38 +0100 Subject: [PATCH 54/76] Fix of link rst format --- docs/en/reference/sharding.rst | 6 ++---- docs/en/reference/sharding_azure_tutorial.rst | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/docs/en/reference/sharding.rst b/docs/en/reference/sharding.rst index 0bade11ccbd..dcdd7d8f660 100644 --- a/docs/en/reference/sharding.rst +++ b/docs/en/reference/sharding.rst @@ -84,8 +84,7 @@ Use GUID/UUIDs The most simple ID-generation mechanism for sharding are universally unique identifiers. These are 16-byte (128-bit) numbers that are guaranteed to be unique across different servers. -You can `read up on UUIDs on Wikipedia -`_. +You can `read up on UUIDs on Wikipedia `_. The drawback of UUIDs is the segmentation they cause on indexes. Because UUIDs are not sequentially generated, they can have negative impact on index access @@ -128,8 +127,7 @@ In your application you should hide this details in Id-Generation services: } A good starting point to read up on GUIDs (vs numerical ids) is this blog post -`Coding Horror: Primary Keys: IDs vs GUIDs -`_. +`Coding Horror: Primary Keys: IDs vs GUIDs `_. Table Generator ~~~~~~~~~~~~~~~ diff --git a/docs/en/reference/sharding_azure_tutorial.rst b/docs/en/reference/sharding_azure_tutorial.rst index 761ed401cbb..71a4fab5594 100644 --- a/docs/en/reference/sharding_azure_tutorial.rst +++ b/docs/en/reference/sharding_azure_tutorial.rst @@ -6,8 +6,7 @@ SQLAzure Sharding Tutorial The sharding extension is currently in transition from a separate Project into DBAL. Class names may differ. -This tutorial builds upon the `Brian Swans tutorial -`_ +This tutorial builds upon the `Brian Swans tutorial `_ on SQLAzure Sharding and turns all the examples into examples using the Doctrine Sharding support. It introduces SQL Azure Sharding, which is an abstraction layer in SQL Azure to From 99bb3c0c3e3246f336b36cf6e9b05a1f30901c2b Mon Sep 17 00:00:00 2001 From: Claudio Zizza Date: Sun, 4 Nov 2018 20:10:59 +0100 Subject: [PATCH 55/76] Remove unnecessary backslashs --- docs/en/reference/configuration.rst | 36 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/docs/en/reference/configuration.rst b/docs/en/reference/configuration.rst index 88f0069506a..f8eb141ba4c 100644 --- a/docs/en/reference/configuration.rst +++ b/docs/en/reference/configuration.rst @@ -126,19 +126,19 @@ interfaces to use. It can be configured in one of three ways: - ``driver``: The built-in driver implementation to use. The following drivers are currently available: - - ``pdo_mysql``: A MySQL driver that uses the pdo\_mysql PDO + - ``pdo_mysql``: A MySQL driver that uses the pdo_mysql PDO extension. - - ``drizzle_pdo_mysql``: A Drizzle driver that uses pdo\_mysql PDO + - ``drizzle_pdo_mysql``: A Drizzle driver that uses pdo_mysql PDO extension. - ``mysqli``: A MySQL driver that uses the mysqli extension. - - ``pdo_sqlite``: An SQLite driver that uses the pdo\_sqlite PDO + - ``pdo_sqlite``: An SQLite driver that uses the pdo_sqlite PDO extension. - - ``pdo_pgsql``: A PostgreSQL driver that uses the pdo\_pgsql PDO + - ``pdo_pgsql``: A PostgreSQL driver that uses the pdo_pgsql PDO extension. - - ``pdo_oci``: An Oracle driver that uses the pdo\_oci PDO + - ``pdo_oci``: An Oracle driver that uses the pdo_oci PDO extension. **Note that this driver caused problems in our tests. Prefer the oci8 driver if possible.** - - ``pdo_sqlsrv``: A Microsoft SQL Server driver that uses pdo\_sqlsrv PDO + - ``pdo_sqlsrv``: A Microsoft SQL Server driver that uses pdo_sqlsrv PDO **Note that this driver caused problems in our tests. Prefer the sqlsrv driver if possible.** - ``sqlsrv``: A Microsoft SQL Server driver that uses the sqlsrv PHP extension. - ``oci8``: An Oracle driver that uses the oci8 PHP extension. @@ -170,8 +170,8 @@ options recognized by each built-in driver. When using an existing PDO instance through the ``pdo`` option, specifying connection details is obviously not necessary. -pdo\_sqlite -^^^^^^^^^^^ +pdo_sqlite +^^^^^^^^^^ - ``user`` (string): Username to use when connecting to the database. @@ -183,8 +183,8 @@ pdo\_sqlite in-memory (non-persistent). Mutually exclusive with ``path``. ``path`` takes precedence. -pdo\_mysql -^^^^^^^^^^ +pdo_mysql +^^^^^^^^^ - ``user`` (string): Username to use when connecting to the database. @@ -198,8 +198,8 @@ pdo\_mysql - ``charset`` (string): The charset used when connecting to the database. -drizzle\_pdo\_mysql -^^^^^^^^^^^^^^^^^^^ +drizzle_pdo_mysql +^^^^^^^^^^^^^^^^^ **Requires** drizzle plugin ``mysql_protocol`` or ``mysql_unix_socket_protocol`` to be enabled. On Ubuntu this can be done by editing ``/etc/drizzle/conf.d/mysql-protocol.cnf`` @@ -236,8 +236,8 @@ mysqli - ``ssl_cipher`` (string): A list of allowable ciphers to use for SSL encryption. - ``driverOptions`` Any supported flags for mysqli found on `http://www.php.net/manual/en/mysqli.real-connect.php` -pdo\_pgsql -^^^^^^^^^^ +pdo_pgsql +^^^^^^^^^ - ``user`` (string): Username to use when connecting to the database. @@ -275,8 +275,8 @@ PostgreSQL behaves differently with regard to booleans when you use and ``'false'`` as strings you can change to integers by using: ``$conn->getDatabasePlatform()->setUseBooleanTrueFalseStrings($flag)``. -pdo\_oci / oci8 -^^^^^^^^^^^^^^^ +pdo_oci / oci8 +^^^^^^^^^^^^^^ - ``user`` (string): Username to use when connecting to the database. @@ -307,8 +307,8 @@ pdo\_oci / oci8 and ``getPort`` methods from ``Doctrine\DBAL\Connection`` will no longer function as expected. - ``persistent`` (boolean): Whether to establish a persistent connection. -pdo\_sqlsrv / sqlsrv -^^^^^^^^^^^^^^^^^^^^ +pdo_sqlsrv / sqlsrv +^^^^^^^^^^^^^^^^^^^ - ``user`` (string): Username to use when connecting to the database. From e37fc54d91a9bad1a7579520f2ee63c90e9099e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Burnichon?= Date: Thu, 8 Nov 2018 19:17:09 +0100 Subject: [PATCH 56/76] Add mysql specific indexes with lengths --- .../DBAL/Platforms/AbstractPlatform.php | 44 +++++++++++++------ lib/Doctrine/DBAL/Platforms/MySqlPlatform.php | 10 ++++- .../DBAL/Platforms/SQLServerPlatform.php | 2 +- .../DBAL/Schema/AbstractSchemaManager.php | 17 +++++-- lib/Doctrine/DBAL/Schema/Index.php | 14 +++++- .../DBAL/Schema/MySqlSchemaManager.php | 2 + .../SchemaManagerFunctionalTestCase.php | 20 +++++++++ 7 files changed, 88 insertions(+), 21 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index aeac616d514..80a002b6072 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -1408,7 +1408,9 @@ public function getDropTableSQL($table) if ($table instanceof Table) { $table = $table->getQuotedName($this); - } elseif (! is_string($table)) { + } + + if (! is_string($table)) { throw new InvalidArgumentException('getDropTableSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.'); } @@ -1784,7 +1786,7 @@ public function getCreateIndexSQL(Index $index, $table) $table = $table->getQuotedName($this); } $name = $index->getQuotedName($this); - $columns = $index->getQuotedColumns($this); + $columns = $index->getColumns(); if (count($columns) === 0) { throw new InvalidArgumentException("Incomplete definition. 'columns' required."); @@ -1795,7 +1797,7 @@ public function getCreateIndexSQL(Index $index, $table) } $query = 'CREATE ' . $this->getCreateIndexSQLFlags($index) . 'INDEX ' . $name . ' ON ' . $table; - $query .= ' (' . $this->getIndexFieldDeclarationListSQL($columns) . ')' . $this->getPartialIndexSQL($index); + $query .= ' (' . $this->getIndexFieldDeclarationListSQL($index) . ')' . $this->getPartialIndexSQL($index); return $query; } @@ -1833,7 +1835,7 @@ protected function getCreateIndexSQLFlags(Index $index) */ public function getCreatePrimaryKeySQL(Index $index, $table) { - return 'ALTER TABLE ' . $table . ' ADD PRIMARY KEY (' . $this->getIndexFieldDeclarationListSQL($index->getQuotedColumns($this)) . ')'; + return 'ALTER TABLE ' . $table . ' ADD PRIMARY KEY (' . $this->getIndexFieldDeclarationListSQL($index) . ')'; } /** @@ -2337,7 +2339,7 @@ public function getCheckDeclarationSQL(array $definition) */ public function getUniqueConstraintDeclarationSQL($name, Index $index) { - $columns = $index->getQuotedColumns($this); + $columns = $index->getColumns(); $name = new Identifier($name); if (count($columns) === 0) { @@ -2345,7 +2347,7 @@ public function getUniqueConstraintDeclarationSQL($name, Index $index) } return 'CONSTRAINT ' . $name->getQuotedName($this) . ' UNIQUE (' - . $this->getIndexFieldDeclarationListSQL($columns) + . $this->getIndexFieldDeclarationListSQL($index) . ')' . $this->getPartialIndexSQL($index); } @@ -2362,7 +2364,7 @@ public function getUniqueConstraintDeclarationSQL($name, Index $index) */ public function getIndexDeclarationSQL($name, Index $index) { - $columns = $index->getQuotedColumns($this); + $columns = $index->getColumns(); $name = new Identifier($name); if (count($columns) === 0) { @@ -2370,7 +2372,7 @@ public function getIndexDeclarationSQL($name, Index $index) } return $this->getCreateIndexSQLFlags($index) . 'INDEX ' . $name->getQuotedName($this) . ' (' - . $this->getIndexFieldDeclarationListSQL($columns) + . $this->getIndexFieldDeclarationListSQL($index) . ')' . $this->getPartialIndexSQL($index); } @@ -2392,17 +2394,23 @@ public function getCustomTypeDeclarationSQL(array $columnDef) * Obtains DBMS specific SQL code portion needed to set an index * declaration to be used in statements like CREATE TABLE. * - * @param mixed[][] $fields - * - * @return string + * @param mixed[]|Index $columnsOrIndex array declaration is deprecated, prefer passing Index to this method */ - public function getIndexFieldDeclarationListSQL(array $fields) + public function getIndexFieldDeclarationListSQL($columnsOrIndex) : string { + if ($columnsOrIndex instanceof Index) { + return implode(', ', $columnsOrIndex->getQuotedColumns($this)); + } + + if (! is_array($columnsOrIndex)) { + throw new InvalidArgumentException('Fields argument should be an Index or array.'); + } + $ret = []; - foreach ($fields as $field => $definition) { + foreach ($columnsOrIndex as $column => $definition) { if (is_array($definition)) { - $ret[] = $field; + $ret[] = $column; } else { $ret[] = $definition; } @@ -3073,6 +3081,14 @@ public function supportsPartialIndexes() return false; } + /** + * Whether the platform supports indexes with column length definitions. + */ + public function supportsColumnLengthIndexes() : bool + { + return false; + } + /** * Whether the platform supports altering tables. * diff --git a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php index 744aa08a4bd..e17d3736041 100644 --- a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php @@ -645,7 +645,7 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) $query = 'ALTER TABLE ' . $table . ' DROP INDEX ' . $remIndex->getName() . ', '; $query .= 'ADD ' . $indexClause; - $query .= ' (' . $this->getIndexFieldDeclarationListSQL($addIndex->getQuotedColumns($this)) . ')'; + $query .= ' (' . $this->getIndexFieldDeclarationListSQL($addIndex) . ')'; $sql[] = $query; @@ -1132,4 +1132,12 @@ public function getDefaultTransactionIsolationLevel() { return TransactionIsolationLevel::REPEATABLE_READ; } + + /** + * {@inheritdoc} + */ + public function supportsColumnLengthIndexes() : bool + { + return true; + } } diff --git a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php index 353cfe0b2a9..88578690d77 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php @@ -320,7 +320,7 @@ public function getCreatePrimaryKeySQL(Index $index, $table) $flags = ' NONCLUSTERED'; } - return 'ALTER TABLE ' . $table . ' ADD PRIMARY KEY' . $flags . ' (' . $this->getIndexFieldDeclarationListSQL($index->getQuotedColumns($this)) . ')'; + return 'ALTER TABLE ' . $table . ' ADD PRIMARY KEY' . $flags . ' (' . $this->getIndexFieldDeclarationListSQL($index) . ')'; } /** diff --git a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php index 06ee2c2b2aa..9b917427fd8 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php @@ -843,17 +843,26 @@ protected function _getPortableTableIndexesList($tableIndexRows, $tableName = nu $keyName = strtolower($keyName); if (! isset($result[$keyName])) { + $options = [ + 'lengths' => [], + ]; + + if (isset($tableIndex['where'])) { + $options['where'] = $tableIndex['where']; + } + $result[$keyName] = [ 'name' => $indexName, - 'columns' => [$tableIndex['column_name']], + 'columns' => [], 'unique' => $tableIndex['non_unique'] ? false : true, 'primary' => $tableIndex['primary'], 'flags' => $tableIndex['flags'] ?? [], - 'options' => isset($tableIndex['where']) ? ['where' => $tableIndex['where']] : [], + 'options' => $options, ]; - } else { - $result[$keyName]['columns'][] = $tableIndex['column_name']; } + + $result[$keyName]['columns'][] = $tableIndex['column_name']; + $result[$keyName]['options']['lengths'][] = $tableIndex['length'] ?? null; } $eventManager = $this->_platform->getEventManager(); diff --git a/lib/Doctrine/DBAL/Schema/Index.php b/lib/Doctrine/DBAL/Schema/Index.php index cc6bce37a13..bae6d218cb6 100644 --- a/lib/Doctrine/DBAL/Schema/Index.php +++ b/lib/Doctrine/DBAL/Schema/Index.php @@ -7,6 +7,7 @@ use function array_keys; use function array_map; use function array_search; +use function array_shift; use function count; use function is_string; use function strtolower; @@ -97,10 +98,21 @@ public function getColumns() */ public function getQuotedColumns(AbstractPlatform $platform) { + $subParts = $platform->supportsColumnLengthIndexes() && $this->hasOption('lengths') + ? $this->getOption('lengths') : []; + $columns = []; foreach ($this->_columns as $column) { - $columns[] = $column->getQuotedName($platform); + $length = array_shift($subParts); + + $quotedColumn = $column->getQuotedName($platform); + + if ($length !== null) { + $quotedColumn .= '(' . $length . ')'; + } + + $columns[] = $quotedColumn; } return $columns; diff --git a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php index 37518cc15ce..d0f25cb6f79 100644 --- a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php @@ -67,6 +67,8 @@ protected function _getPortableTableIndexesList($tableIndexes, $tableName = null } elseif (strpos($v['index_type'], 'SPATIAL') !== false) { $v['flags'] = ['SPATIAL']; } + $v['length'] = $v['sub_part'] ?? null; + $tableIndexes[$k] = $v; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index 425039fa023..1c0afc93e66 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -1555,4 +1555,24 @@ public function testPrimaryKeyAutoIncrement() $this->assertGreaterThan($lastUsedIdBeforeDelete, $lastUsedIdAfterDelete); } + + public function testGenerateAnIndexWithPartialColumnLength() : void + { + if (! $this->schemaManager->getDatabasePlatform()->supportsColumnLengthIndexes()) { + self::markTestSkipped('This test is only supported on platforms that support indexes with column length definitions.'); + } + + $table = new Table('test_partial_column_index'); + $table->addColumn('long_column', 'string', ['length' => 40]); + $table->addColumn('standard_column', 'integer'); + $table->addIndex(['long_column'], 'partial_long_column_idx', [], ['lengths' => [4]]); + $table->addIndex(['standard_column', 'long_column'], 'standard_and_partial_idx', [], ['lengths' => [null, 2]]); + + $expected = $table->getIndexes(); + + $this->schemaManager->dropAndCreateTable($table); + + $onlineTable = $this->schemaManager->listTableDetails('test_partial_column_index'); + self::assertEquals($expected, $onlineTable->getIndexes()); + } } From a7cffda89e6154cf75502f250d0120523e73fac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Burnichon?= Date: Fri, 16 Nov 2018 09:44:14 +0100 Subject: [PATCH 57/76] Add some MySQL platform data in Tables --- lib/Doctrine/DBAL/Platforms/MySqlPlatform.php | 14 +++++++ .../DBAL/Schema/MySqlSchemaManager.php | 42 +++++++++++++++++++ .../Schema/MySqlSchemaManagerTest.php | 39 +++++++++++++++++ 3 files changed, 95 insertions(+) diff --git a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php index e17d3736041..cafdc6eb05c 100644 --- a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php @@ -380,6 +380,20 @@ public function getListTableColumnsSQL($table, $database = null) 'FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = ' . $database . ' AND TABLE_NAME = ' . $table; } + public function getListTableMetadataSQL(string $table, ?string $database = null) : string + { + return sprintf( + <<<'SQL' +SELECT ENGINE, AUTO_INCREMENT, TABLE_COLLATION, TABLE_COMMENT, CREATE_OPTIONS +FROM information_schema.TABLES +WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA = %s AND TABLE_NAME = %s +SQL + , + $database ? $this->quoteStringLiteral($database) : 'DATABASE()', + $this->quoteStringLiteral($table) + ); + } + /** * {@inheritDoc} */ diff --git a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php index d0f25cb6f79..b6332026cdd 100644 --- a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php @@ -10,6 +10,7 @@ use function array_shift; use function array_values; use function end; +use function explode; use function preg_match; use function preg_replace; use function str_replace; @@ -17,6 +18,7 @@ use function strpos; use function strtok; use function strtolower; +use function trim; /** * Schema manager for the MySql RDBMS. @@ -284,4 +286,44 @@ protected function _getPortableTableForeignKeysList($tableForeignKeys) return $result; } + + public function listTableDetails($tableName) + { + $table = parent::listTableDetails($tableName); + + /** @var MySqlPlatform $platform */ + $platform = $this->_platform; + $sql = $platform->getListTableMetadataSQL($tableName); + + $tableOptions = $this->_conn->fetchAssoc($sql); + + $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']); + + if ($tableOptions['CREATE_OPTIONS'] === null) { + return $table; + } + + $createOptionsString = trim($tableOptions['CREATE_OPTIONS']); + + $createOptions = []; + + if ($createOptionsString !== '') { + foreach (explode(' ', $createOptionsString) as $option) { + [$createOption, $value] = explode('=', $option); + + $createOptions[$createOption] = $value; + } + } + + $table->addOption('create_options', $createOptions); + + return $table; + } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php index 7dd9409b30c..b1669e345f5 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php @@ -486,4 +486,43 @@ public function testEnsureDefaultsAreUnescapedFromSchemaIntrospection() : void $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'); + + $sql = <<<'SQL' +CREATE TABLE test_table_metadata( + col1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY +) +COLLATE utf8_general_ci +ENGINE InnoDB +ROW_FORMAT COMPRESSED +COMMENT 'This is a test' +AUTO_INCREMENT=42 +SQL; + + $this->connection->query($sql); + $onlineTable = $this->schemaManager->listTableDetails('test_table_metadata'); + + self::assertEquals('InnoDB', $onlineTable->getOption('engine')); + 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')); + } + + public function testEnsureTableWithoutOptionsAreReflectedInMetadata() : void + { + $this->connection->query('DROP TABLE IF EXISTS test_table_empty_metadata'); + + $this->connection->query('CREATE TABLE test_table_empty_metadata(col1 INT NOT NULL)'); + $onlineTable = $this->schemaManager->listTableDetails('test_table_empty_metadata'); + + self::assertNotEmpty($onlineTable->getOption('engine')); + // collation could be set to default or not set, information_schema indicate a possibly null value + self::assertFalse($onlineTable->hasOption('autoincrement')); + self::assertEquals('', $onlineTable->getOption('comment')); + self::assertEquals([], $onlineTable->getOption('create_options')); + } } From ed87ee6ab8354155c60fec0c48cf8313778f1d76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Ostroluck=C3=BD?= Date: Sat, 17 Nov 2018 15:19:53 +0100 Subject: [PATCH 58/76] Remove pdo_sqlsrv from known vendor issues list --- docs/en/reference/configuration.rst | 1 - docs/en/reference/known-vendor-issues.rst | 11 ----------- tests/Doctrine/Tests/DBAL/Functional/BlobTest.php | 5 ----- 3 files changed, 17 deletions(-) diff --git a/docs/en/reference/configuration.rst b/docs/en/reference/configuration.rst index f8eb141ba4c..4fa8991ec33 100644 --- a/docs/en/reference/configuration.rst +++ b/docs/en/reference/configuration.rst @@ -139,7 +139,6 @@ interfaces to use. It can be configured in one of three ways: extension. **Note that this driver caused problems in our tests. Prefer the oci8 driver if possible.** - ``pdo_sqlsrv``: A Microsoft SQL Server driver that uses pdo_sqlsrv PDO - **Note that this driver caused problems in our tests. Prefer the sqlsrv driver if possible.** - ``sqlsrv``: A Microsoft SQL Server driver that uses the sqlsrv PHP extension. - ``oci8``: An Oracle driver that uses the oci8 PHP extension. - ``sqlanywhere``: A SAP Sybase SQL Anywhere driver that uses the sqlanywhere PHP extension. diff --git a/docs/en/reference/known-vendor-issues.rst b/docs/en/reference/known-vendor-issues.rst index b33e80930ac..0ff6824e1db 100644 --- a/docs/en/reference/known-vendor-issues.rst +++ b/docs/en/reference/known-vendor-issues.rst @@ -179,14 +179,3 @@ liberal DateTime parser that detects the format automatically: Type::overrideType('datetime_immutable', 'Doctrine\DBAL\Types\VarDateTimeImmutableType'); Type::overrideType('datetimetz_immutable', 'Doctrine\DBAL\Types\VarDateTimeImmutableType'); Type::overrideType('time_immutable', 'Doctrine\DBAL\Types\VarDateTimeImmutableType'); - -PDO_SQLSRV: VARBINARY/BLOB columns -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -The ``PDO_SQLSRV`` driver currently has a bug when binding values to -VARBINARY/BLOB columns with ``bindValue`` in prepared statements. -This raises an implicit conversion from data type error as it tries -to convert a character type value to a binary type value even if -you explicitly define the value as ``ParameterType::LARGE_OBJECT`` type. -Therefore it is highly encouraged to use the native ``sqlsrv`` -driver instead which does not have this limitation. diff --git a/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php b/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php index 1b3df42ec8b..02519634007 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/BlobTest.php @@ -3,7 +3,6 @@ namespace Doctrine\Tests\DBAL\Functional; use Doctrine\DBAL\Driver\OCI8\Driver as OCI8Driver; -use Doctrine\DBAL\Driver\PDOSqlsrv\Driver as PDOSQLSrvDriver; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Schema\AbstractSchemaManager; @@ -23,10 +22,6 @@ protected function setUp() { parent::setUp(); - if ($this->connection->getDriver() instanceof PDOSQLSrvDriver) { - $this->markTestSkipped('This test does not work on pdo_sqlsrv driver due to a bug. See: http://social.msdn.microsoft.com/Forums/sqlserver/en-US/5a755bdd-41e9-45cb-9166-c9da4475bb94/how-to-set-null-for-varbinarymax-using-bindvalue-using-pdosqlsrv?forum=sqldriverforphp'); - } - /** @var AbstractSchemaManager $sm */ $table = new Table('blob_table'); $table->addColumn('id', 'integer'); From c9daea6f1b769b73db4678bcb2a823fd3c308e82 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Sun, 26 Aug 2018 22:04:27 +0200 Subject: [PATCH 59/76] CI: Test against PHP 7.3 on Travis Co-authored-by: Michael Moravec Co-authored-by: Benjamin Morel --- .scrutinizer.yml | 2 +- .travis.yml | 266 +++++++++++------------ tests/travis/install-mssql-pdo_sqlsrv.sh | 7 +- tests/travis/install-mssql-sqlsrv.sh | 7 +- 4 files changed, 144 insertions(+), 138 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 125becc5263..f51cf15b63f 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -21,7 +21,7 @@ before_commands: tools: external_code_coverage: timeout: 3600 - runs: 22 # 18x Travis (jobs with COVERAGE=yes) + 3x AppVeyor (jobs with coverage=yes) + 1x ContinuousPHP + runs: 27 # 23x Travis (jobs with COVERAGE=yes) + 3x AppVeyor (jobs with coverage=yes) + 1x ContinuousPHP filter: excluded_paths: diff --git a/.travis.yml b/.travis.yml index 854eb02728b..de5c5dcd9b8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,7 @@ cache: php: - 7.1 - 7.2 + - 7.3 - nightly env: @@ -62,28 +63,52 @@ jobs: env: DB=mysql - php: 7.1 env: DB=mysqli + - php: 7.2 + env: DB=sqlite + - php: 7.2 + env: DB=mysql + - php: 7.2 + env: DB=mysqli + - php: 7.3 + env: DB=mysql + - php: 7.3 + env: DB=mysqli + - php: nightly + env: DB=mysql + - php: nightly + env: DB=mysqli include: - stage: Test php: 7.1 + env: DB=sqlite + + - stage: Test + php: 7.2 env: DB=sqlite COVERAGE=yes - stage: Test - php: 7.1 + php: 7.2 env: DB=mysql COVERAGE=yes - stage: Test - php: 7.1 + php: 7.2 env: DB=mysqli COVERAGE=yes - stage: Test php: 7.1 - env: DB=mysql MYSQL_VERSION=5.7 COVERAGE=yes + env: DB=mysql MYSQL_VERSION=5.7 sudo: required before_script: - bash ./tests/travis/install-mysql-5.7.sh - stage: Test php: 7.2 + env: DB=mysql MYSQL_VERSION=5.7 COVERAGE=yes + sudo: required + before_script: + - bash ./tests/travis/install-mysql-5.7.sh + - stage: Test + php: 7.3 env: DB=mysql MYSQL_VERSION=5.7 sudo: required before_script: @@ -97,12 +122,18 @@ jobs: - stage: Test php: 7.1 - env: DB=mysqli MYSQL_VERSION=5.7 COVERAGE=yes + env: DB=mysqli MYSQL_VERSION=5.7 sudo: required before_script: - bash ./tests/travis/install-mysql-5.7.sh - stage: Test php: 7.2 + env: DB=mysqli MYSQL_VERSION=5.7 COVERAGE=yes + sudo: required + before_script: + - bash ./tests/travis/install-mysql-5.7.sh + - stage: Test + php: 7.3 env: DB=mysqli MYSQL_VERSION=5.7 sudo: required before_script: @@ -114,194 +145,132 @@ jobs: before_script: - bash ./tests/travis/install-mysql-5.7.sh - - stage: Test - php: 7.1 - env: DB=mariadb MARIADB_VERSION=10.0 COVERAGE=yes - addons: - mariadb: 10.0 - stage: Test php: 7.2 - env: DB=mariadb MARIADB_VERSION=10.0 - addons: - mariadb: 10.0 - - stage: Test - php: nightly - env: DB=mariadb MARIADB_VERSION=10.0 + env: DB=mariadb MARIADB_VERSION=10.0 COVERAGE=yes addons: mariadb: 10.0 - - stage: Test - php: 7.1 - env: DB=mariadb MARIADB_VERSION=10.1 COVERAGE=yes - addons: - mariadb: 10.1 - stage: Test php: 7.2 - env: DB=mariadb MARIADB_VERSION=10.1 - addons: - mariadb: 10.1 - - stage: Test - php: nightly - env: DB=mariadb MARIADB_VERSION=10.1 + env: DB=mariadb MARIADB_VERSION=10.1 COVERAGE=yes addons: mariadb: 10.1 - stage: Test - php: 7.1 + php: 7.2 env: DB=mariadb MARIADB_VERSION=10.2 COVERAGE=yes addons: mariadb: 10.2 + - stage: Test php: 7.2 - env: DB=mariadb MARIADB_VERSION=10.2 + env: DB=mariadb.mysqli MARIADB_VERSION=10.0 COVERAGE=yes addons: - mariadb: 10.2 + mariadb: 10.0 + - stage: Test - php: nightly - env: DB=mariadb MARIADB_VERSION=10.2 + php: 7.2 + env: DB=mariadb.mysqli MARIADB_VERSION=10.1 COVERAGE=yes addons: - mariadb: 10.2 + mariadb: 10.1 - stage: Test - php: 7.1 + php: 7.2 env: DB=mariadb.mysqli MARIADB_VERSION=10.2 COVERAGE=yes addons: mariadb: 10.2 + - stage: Test - php: 7.2 - env: DB=mariadb.mysqli MARIADB_VERSION=10.2 + php: 7.1 + env: DB=mariadb MARIADB_VERSION=10.3 addons: - mariadb: 10.2 + mariadb: 10.3 + - stage: Test - php: nightly - env: DB=mariadb.mysqli MARIADB_VERSION=10.2 + php: 7.2 + env: DB=mariadb MARIADB_VERSION=10.3 COVERAGE=yes addons: - mariadb: 10.2 + mariadb: 10.3 - stage: Test - php: 7.2 + php: 7.3 env: DB=mariadb MARIADB_VERSION=10.3 addons: mariadb: 10.3 - stage: Test - php: 7.2 - env: DB=mariadb.mysqli MARIADB_VERSION=10.3 + php: nightly + env: DB=mariadb MARIADB_VERSION=10.3 addons: mariadb: 10.3 - stage: Test php: 7.1 - env: DB=pgsql POSTGRESQL_VERSION=9.2 COVERAGE=yes - services: - - postgresql + env: DB=mariadb.mysqli MARIADB_VERSION=10.3 addons: - postgresql: "9.2" + mariadb: 10.3 + - stage: Test php: 7.2 - env: DB=pgsql POSTGRESQL_VERSION=9.2 - services: - - postgresql + env: DB=mariadb.mysqli MARIADB_VERSION=10.3 COVERAGE=yes addons: - postgresql: "9.2" + mariadb: 10.3 + - stage: Test - php: nightly - env: DB=pgsql POSTGRESQL_VERSION=9.2 - services: - - postgresql + php: 7.3 + env: DB=mariadb.mysqli MARIADB_VERSION=10.3 addons: - postgresql: "9.2" + mariadb: 10.3 - stage: Test - php: 7.1 - env: DB=pgsql POSTGRESQL_VERSION=9.3 COVERAGE=yes - services: - - postgresql + php: nightly + env: DB=mariadb.mysqli MARIADB_VERSION=10.3 addons: - postgresql: "9.3" + mariadb: 10.3 + - stage: Test php: 7.2 - env: DB=pgsql POSTGRESQL_VERSION=9.3 + env: DB=pgsql POSTGRESQL_VERSION=9.2 COVERAGE=yes services: - postgresql addons: - postgresql: "9.3" + postgresql: "9.2" + - stage: Test - php: nightly - env: DB=pgsql POSTGRESQL_VERSION=9.3 + php: 7.2 + env: DB=pgsql POSTGRESQL_VERSION=9.3 COVERAGE=yes services: - postgresql addons: postgresql: "9.3" - - stage: Test - php: 7.1 - env: DB=pgsql POSTGRESQL_VERSION=9.4 COVERAGE=yes - services: - - postgresql - addons: - postgresql: "9.4" - stage: Test php: 7.2 - env: DB=pgsql POSTGRESQL_VERSION=9.4 - services: - - postgresql - addons: - postgresql: "9.4" - - stage: Test - php: nightly - env: DB=pgsql POSTGRESQL_VERSION=9.4 + env: DB=pgsql POSTGRESQL_VERSION=9.4 COVERAGE=yes services: - postgresql addons: postgresql: "9.4" - - stage: Test - php: 7.1 - env: DB=pgsql POSTGRESQL_VERSION=9.5 COVERAGE=yes - services: - - postgresql - addons: - postgresql: "9.5" - stage: Test php: 7.2 - env: DB=pgsql POSTGRESQL_VERSION=9.5 - services: - - postgresql - addons: - postgresql: "9.5" - - stage: Test - php: nightly - env: DB=pgsql POSTGRESQL_VERSION=9.5 + env: DB=pgsql POSTGRESQL_VERSION=9.5 COVERAGE=yes services: - postgresql addons: postgresql: "9.5" - - stage: Test - php: 7.1 - env: DB=pgsql POSTGRESQL_VERSION=9.6 COVERAGE=yes - services: - - postgresql - addons: - postgresql: "9.6" - stage: Test php: 7.2 - env: DB=pgsql POSTGRESQL_VERSION=9.6 - services: - - postgresql - addons: - postgresql: "9.6" - - stage: Test - php: nightly - env: DB=pgsql POSTGRESQL_VERSION=9.6 + env: DB=pgsql POSTGRESQL_VERSION=9.6 COVERAGE=yes services: - postgresql addons: postgresql: "9.6" - stage: Test - php: 7.1 + php: 7.2 env: DB=pgsql POSTGRESQL_VERSION=10.0 COVERAGE=yes sudo: required services: @@ -310,29 +279,25 @@ jobs: postgresql: "9.6" before_script: - bash ./tests/travis/install-postgres-10.sh + - stage: Test - php: 7.2 - env: DB=pgsql POSTGRESQL_VERSION=10.0 + php: 7.1 + env: DB=pgsql POSTGRESQL_VERSION=11.0 sudo: required services: - - postgresql - addons: - postgresql: "9.6" + - docker before_script: - - bash ./tests/travis/install-postgres-10.sh + - bash ./tests/travis/install-postgres-11.sh - stage: Test - php: nightly - env: DB=pgsql POSTGRESQL_VERSION=10.0 + php: 7.2 + env: DB=pgsql POSTGRESQL_VERSION=11.0 COVERAGE=yes sudo: required services: - - postgresql - addons: - postgresql: "9.6" + - docker before_script: - - bash ./tests/travis/install-postgres-10.sh - + - bash ./tests/travis/install-postgres-11.sh - stage: Test - php: 7.1 + php: 7.3 env: DB=pgsql POSTGRESQL_VERSION=11.0 sudo: required services: @@ -340,23 +305,25 @@ jobs: before_script: - bash ./tests/travis/install-postgres-11.sh - stage: Test - php: 7.2 + php: nightly env: DB=pgsql POSTGRESQL_VERSION=11.0 sudo: required services: - docker before_script: - bash ./tests/travis/install-postgres-11.sh + - stage: Test - php: nightly - env: DB=pgsql POSTGRESQL_VERSION=11.0 + php: 7.1 + env: DB=sqlsrv sudo: required services: - docker before_script: - - bash ./tests/travis/install-postgres-11.sh - + - bash ./tests/travis/install-mssql-$DB.sh + - bash ./tests/travis/install-mssql.sh - stage: Test + php: 7.2 env: DB=sqlsrv COVERAGE=yes sudo: required services: @@ -365,7 +332,16 @@ jobs: - bash ./tests/travis/install-mssql-$DB.sh - bash ./tests/travis/install-mssql.sh - stage: Test - php: 7.2 + php: 7.3 + env: DB=sqlsrv + sudo: required + services: + - docker + before_script: + - bash ./tests/travis/install-mssql-$DB.sh + - bash ./tests/travis/install-mssql.sh + - stage: Test + php: nightly env: DB=sqlsrv sudo: required services: @@ -376,7 +352,7 @@ jobs: - stage: Test php: 7.1 - env: DB=pdo_sqlsrv COVERAGE=yes + env: DB=pdo_sqlsrv sudo: required services: - docker @@ -385,16 +361,35 @@ jobs: - bash ./tests/travis/install-mssql.sh - stage: Test php: 7.2 - env: DB=pdo_sqlsrv + env: DB=pdo_sqlsrv COVERAGE=yes sudo: required services: - docker before_script: - bash ./tests/travis/install-mssql-$DB.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-$DB.sh + - bash ./tests/travis/install-mssql.sh + - stage: Test + php: nightly + env: DB=pdo_sqlsrv + sudo: required + services: + - docker + before_script: + - bash ./tests/travis/install-mssql-$DB.sh + - bash ./tests/travis/install-mssql.sh - stage: Test - env: DB=ibm_db2 COVERAGE=yes + php: 7.1 + env: DB=ibm_db2 sudo: required services: - docker @@ -403,7 +398,7 @@ jobs: - bash ./tests/travis/install-db2-$DB.sh - stage: Test php: 7.2 - env: DB=ibm_db2 + env: DB=ibm_db2 COVERAGE=yes sudo: required services: - docker @@ -426,12 +421,13 @@ jobs: - travis_retry composer update --prefer-dist - stage: Code Quality + php: 7.2 env: DB=none STATIC_ANALYSIS install: travis_retry composer install --prefer-dist script: vendor/bin/phpstan analyse - stage: Coding standard - php: 7.1 + php: 7.2 install: travis_retry composer install --prefer-dist script: - ./vendor/bin/phpcs diff --git a/tests/travis/install-mssql-pdo_sqlsrv.sh b/tests/travis/install-mssql-pdo_sqlsrv.sh index e9165549f6f..6a82459cc6c 100644 --- a/tests/travis/install-mssql-pdo_sqlsrv.sh +++ b/tests/travis/install-mssql-pdo_sqlsrv.sh @@ -3,4 +3,9 @@ set -ex echo "Installing extension" -pecl install pdo_sqlsrv + +if [ "$TRAVIS_PHP_VERSION" == "7.3" ] || [ "$TRAVIS_PHP_VERSION" == "nightly" ] ; then + pecl install pdo_sqlsrv-5.4.0preview +else + pecl install pdo_sqlsrv +fi diff --git a/tests/travis/install-mssql-sqlsrv.sh b/tests/travis/install-mssql-sqlsrv.sh index dede9458f7c..18c9453a866 100644 --- a/tests/travis/install-mssql-sqlsrv.sh +++ b/tests/travis/install-mssql-sqlsrv.sh @@ -3,4 +3,9 @@ set -ex echo "Installing extension" -pecl install sqlsrv + +if [ "$TRAVIS_PHP_VERSION" == "7.3" ] || [ "$TRAVIS_PHP_VERSION" == "nightly" ] ; then + pecl install sqlsrv-5.4.0preview +else + pecl install sqlsrv +fi From 4389a258c0b6a6c47099e65a54db98904d7235b2 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 23 Nov 2018 20:01:42 -0800 Subject: [PATCH 60/76] Implemented comparison of default values as strings regardless of their PHP types Fixes #3336. --- lib/Doctrine/DBAL/Schema/Comparator.php | 10 ++--- .../DBAL/Functional/Schema/ComparatorTest.php | 39 +++++++++++++++++++ .../Schema/MySqlSchemaManagerTest.php | 2 + 3 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 tests/Doctrine/Tests/DBAL/Functional/Schema/ComparatorTest.php diff --git a/lib/Doctrine/DBAL/Schema/Comparator.php b/lib/Doctrine/DBAL/Schema/Comparator.php index f95417face2..3b5a0b155d0 100644 --- a/lib/Doctrine/DBAL/Schema/Comparator.php +++ b/lib/Doctrine/DBAL/Schema/Comparator.php @@ -432,12 +432,10 @@ public function diffColumn(Column $column1, Column $column2) $changedProperties[] = 'comment'; } - if ($properties1['default'] !== $properties2['default'] || - // 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. - ($properties1['default'] === null && $properties2['default'] !== null) || - ($properties2['default'] === null && $properties1['default'] !== null) - ) { + // 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']) { $changedProperties[] = 'default'; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/ComparatorTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/ComparatorTest.php new file mode 100644 index 00000000000..a97eb90bbce --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/ComparatorTest.php @@ -0,0 +1,39 @@ +schemaManager = $this->connection->getSchemaManager(); + $this->comparator = new Comparator(); + } + + public function testDefaultValueComparison() + { + $table = new Table('default_value'); + $table->addColumn('id', 'integer', ['default' => 1]); + + $this->schemaManager->createTable($table); + + $onlineTable = $this->schemaManager->listTableDetails('default_value'); + + self::assertFalse($this->comparator->diffTable($table, $onlineTable)); + } +} diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php index b1669e345f5..475dcee3ee6 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php @@ -23,6 +23,8 @@ protected function setUp() return; } + $this->resetSharedConn(); + Type::addType('point', MySqlPointType::class); } From 401fe0415378102850b4b4ae13111b213b5b74db Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Sun, 25 Nov 2018 18:53:50 +0100 Subject: [PATCH 61/76] Fix typo --- phpunit.xml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 9dab4abdaa5..b212ccf7e0d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -2,7 +2,7 @@