From 16878650d79934c31e27a13618ed6f3effee80d8 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sat, 26 Sep 2020 21:44:00 -0700 Subject: [PATCH 01/56] Bump version to 2.11.2-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 044b85e54aa..a592257a602 100644 --- a/lib/Doctrine/DBAL/Version.php +++ b/lib/Doctrine/DBAL/Version.php @@ -17,7 +17,7 @@ class Version /** * Current Doctrine Version. */ - public const VERSION = '2.11.1'; + public const VERSION = '2.11.2-DEV'; /** * Compares a Doctrine version with the current one. From c50a58e3b841537fcb2ee11cb641c1346bab876d Mon Sep 17 00:00:00 2001 From: Joe Bennett Date: Mon, 28 Sep 2020 19:44:00 +1000 Subject: [PATCH 02/56] #4295 Restored master, slaves, keepReplica params in MasterSlaveConnection --- .../Connections/MasterSlaveConnection.php | 3 -- .../Connections/MasterSlaveConnectionTest.php | 39 +++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 tests/Doctrine/Tests/DBAL/Connections/MasterSlaveConnectionTest.php diff --git a/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php b/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php index 0e97267643b..984736fd633 100644 --- a/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php +++ b/lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php @@ -38,21 +38,18 @@ public function __construct( $this->deprecated('Params key "master"', '"primary"'); $params['primary'] = $params['master']; - unset($params['master']); } if (isset($params['slaves'])) { $this->deprecated('Params key "slaves"', '"replica"'); $params['replica'] = $params['slaves']; - unset($params['slaves']); } if (isset($params['keepSlave'])) { $this->deprecated('Params key "keepSlave"', '"keepReplica"'); $params['keepReplica'] = $params['keepSlave']; - unset($params['keepSlave']); } parent::__construct($params, $driver, $config, $eventManager); diff --git a/tests/Doctrine/Tests/DBAL/Connections/MasterSlaveConnectionTest.php b/tests/Doctrine/Tests/DBAL/Connections/MasterSlaveConnectionTest.php new file mode 100644 index 00000000000..c29b8b05a40 --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Connections/MasterSlaveConnectionTest.php @@ -0,0 +1,39 @@ + 'pdo_mysql', + 'keepSlave' => true, + 'master' => [ + 'host' => 'master.host', + 'user' => 'root', + 'password' => 'password', + 'port' => '1234', + ], + 'slaves' => [ + [ + 'host' => 'slave1.host', + 'user' => 'root', + 'password' => 'password', + 'port' => '1234', + ], + ], + ]; + + $connection = new MasterSlaveConnection($constructionParams, $this->createStub(Driver::class)); + + $connectionParams = $connection->getParams(); + foreach ($constructionParams as $key => $value) { + self::assertSame($value, $connectionParams[$key]); + } + } +} From 7e424f2da2bc4fbf72b75f89b3f57e0494ae957f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Mon, 28 Sep 2020 14:32:26 +0200 Subject: [PATCH 03/56] Use cache action v2 --- .github/workflows/continuous-integration.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 1b38ac3651c..696fb85d18c 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -57,7 +57,7 @@ jobs: php-version: "${{ matrix.php-version }}" - name: "Cache dependencies installed with composer" - uses: "actions/cache@v1" + uses: "actions/cache@v2" with: path: "~/.composer/cache" key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}" @@ -98,7 +98,7 @@ jobs: coverage: "pcov" - name: "Cache dependencies installed with composer" - uses: "actions/cache@v1" + uses: "actions/cache@v2" with: path: "~/.composer/cache" key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}" From 4bf867f6d5f446300e416e930f2b3574d786d437 Mon Sep 17 00:00:00 2001 From: Claudio Zizza Date: Mon, 28 Sep 2020 20:08:00 +0200 Subject: [PATCH 04/56] Move website config to default branch Adapts the website config to be compatible with the doctrine/doctrine-website#356 changes --- .doctrine-project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.doctrine-project.json b/.doctrine-project.json index f68f2fd0bc3..ff81ef1e9f0 100644 --- a/.doctrine-project.json +++ b/.doctrine-project.json @@ -7,7 +7,7 @@ "versions": [ { "name": "3.0", - "branchName": "develop", + "branchName": "3.0.x", "slug": "latest", "upcoming": true }, From b2d270496fab79054f5ccda8051ae2e93a282469 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 2 Oct 2020 13:32:04 -0700 Subject: [PATCH 05/56] Improve statement parameter type annotations --- lib/Doctrine/DBAL/Connection.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index af803e5db26..5eb4ae23924 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -905,6 +905,8 @@ public function quoteIdentifier($str) /** * {@inheritDoc} + * + * @param int|string|Type|null $type */ public function quote($value, $type = ParameterType::STRING) { @@ -1882,8 +1884,8 @@ private function _bindTypedValues($stmt, array $params, array $types) /** * Gets the binding type of a given type. The given type can be a PDO or DBAL mapping type. * - * @param mixed $value The value to bind. - * @param int|string|null $type The type to bind (PDO or DBAL). + * @param mixed $value The value to bind. + * @param int|string|Type|null $type The type to bind (PDO or DBAL). * * @return mixed[] [0] => the (escaped) value, [1] => the binding type. */ From 37668e5f7169ca8b868092035075caf4bedfaea6 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 2 Oct 2020 13:33:27 -0700 Subject: [PATCH 06/56] The second parameter of Statement::fetchAll() can be a string --- lib/Doctrine/DBAL/Driver/ResultStatement.php | 32 ++++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/Doctrine/DBAL/Driver/ResultStatement.php b/lib/Doctrine/DBAL/Driver/ResultStatement.php index f31f960f5e0..5373ee39907 100644 --- a/lib/Doctrine/DBAL/Driver/ResultStatement.php +++ b/lib/Doctrine/DBAL/Driver/ResultStatement.php @@ -75,22 +75,22 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX * * @deprecated Use fetchAllNumeric(), fetchAllAssociative() or fetchFirstColumn() instead. * - * @param int|null $fetchMode Controls how the next row will be returned to the caller. - * The value must be one of the {@link FetchMode} constants, - * defaulting to {@link FetchMode::MIXED}. - * @param int|null $fetchArgument This argument has a different meaning depending on the value - * of the $fetchMode parameter: - * * {@link FetchMode::COLUMN}: - * Returns the indicated 0-indexed column. - * * {@link FetchMode::CUSTOM_OBJECT}: - * Returns instances of the specified class, mapping the columns of each row - * to named properties in the class. - * * {@link 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 FetchMode} constants, - * defaulting to {@link 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 FetchMode} constants, + * defaulting to {@link FetchMode::MIXED}. + * @param int|string|null $fetchArgument This argument has a different meaning depending on the value + * of the $fetchMode parameter: + * * {@link FetchMode::COLUMN}: + * Returns the indicated 0-indexed column. + * * {@link FetchMode::CUSTOM_OBJECT}: + * Returns instances of the specified class, mapping the columns of each row + * to named properties in the class. + * * {@link 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 FetchMode} constants, + * defaulting to {@link FetchMode::MIXED}. * * @return mixed[] */ From d2f92635a52b1d6d5076e3bf49311b183c68c77e Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 2 Oct 2020 13:33:51 -0700 Subject: [PATCH 07/56] Rework handling connection URL --- lib/Doctrine/DBAL/DriverManager.php | 23 ++++++++++++++--------- phpstan.neon.dist | 6 ++++++ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/Doctrine/DBAL/DriverManager.php b/lib/Doctrine/DBAL/DriverManager.php index 6c21d806580..5b12e4871bb 100644 --- a/lib/Doctrine/DBAL/DriverManager.php +++ b/lib/Doctrine/DBAL/DriverManager.php @@ -12,7 +12,6 @@ use Doctrine\DBAL\Driver\SQLSrv; use function array_keys; -use function array_map; use function array_merge; use function assert; use function class_implements; @@ -22,6 +21,7 @@ use function parse_str; use function parse_url; use function preg_replace; +use function rawurldecode; use function str_replace; use function strpos; use function substr; @@ -280,13 +280,19 @@ private static function parseDatabaseUrl(array $params): array throw new Exception('Malformed parameter "url".'); } - $url = array_map('rawurldecode', $url); + foreach ($url as $param => $value) { + if (! is_string($value)) { + continue; + } + + $url[$param] = rawurldecode($value); + } // If we have a connection URL, we have to unset the default PDO instance connection parameter (if any) // as we cannot merge connection details from the URL into the PDO instance (URL takes precedence). unset($params['pdo']); - $params = self::parseDatabaseUrlScheme($url, $params); + $params = self::parseDatabaseUrlScheme($url['scheme'] ?? null, $params); if (isset($url['host'])) { $params['host'] = $url['host']; @@ -412,23 +418,22 @@ private static function parseSqliteDatabaseUrlPath(array $url, array $params): a /** * Parses the scheme part from given connection URL and resolves the given connection parameters. * - * @param mixed[] $url The connection URL parts to evaluate. - * @param mixed[] $params The connection parameters to resolve. + * @param string|null $scheme The connection URL scheme, if available + * @param mixed[] $params The connection parameters to resolve. * * @return mixed[] The resolved connection parameters. * * @throws Exception If parsing failed or resolution is not possible. */ - private static function parseDatabaseUrlScheme(array $url, array $params): array + private static function parseDatabaseUrlScheme($scheme, array $params): array { - if (isset($url['scheme'])) { + if ($scheme !== null) { // The requested driver from the URL scheme takes precedence // over the default custom driver from the connection parameters (if any). unset($params['driverClass']); // URL schemes must not contain underscores, but dashes are ok - $driver = str_replace('-', '_', $url['scheme']); - assert(is_string($driver)); + $driver = str_replace('-', '_', $scheme); // The requested driver from the URL scheme takes precedence over the // default driver from the connection parameters. If the driver is diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 38c7bdace8c..59a0a7442f3 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -111,3 +111,9 @@ parameters: message: '~Return type \(Doctrine\\DBAL\\Portability\\Statement\) of method Doctrine\\DBAL\\Portability\\Connection::prepare\(\) should be compatible with return type \(Doctrine\\DBAL\\Statement\) of method Doctrine\\DBAL\\Connection::prepare\(\)~' paths: - %currentWorkingDirectory%/lib/Doctrine/DBAL/Portability/Connection.php + + # Unlike Psalm, PHPStan doesn't understand the shape of the parse_str() return value + - + message: '~^Parameter #1 \$scheme of static method Doctrine\\DBAL\\DriverManager::parseDatabaseUrlScheme\(\) expects string\|null, int\|string\|null given\.$~' + paths: + - %currentWorkingDirectory%/lib/Doctrine/DBAL/DriverManager.php From 408975dadb63522315ca796d6ddd0c7aa1d555af Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 2 Oct 2020 14:11:41 -0700 Subject: [PATCH 08/56] Make return type annotations in SQL Parser more accurate --- lib/Doctrine/DBAL/SQLParserUtils.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/DBAL/SQLParserUtils.php b/lib/Doctrine/DBAL/SQLParserUtils.php index b469741ca0e..16ed8a812c1 100644 --- a/lib/Doctrine/DBAL/SQLParserUtils.php +++ b/lib/Doctrine/DBAL/SQLParserUtils.php @@ -64,7 +64,7 @@ public static function getPlaceholderPositions($statement, $isPositional = true) /** * Returns a zero-indexed list of placeholder position. * - * @return int[] + * @return list */ private static function getPositionalPlaceholderPositions(string $statement): array { @@ -81,7 +81,7 @@ static function (string $_, int $placeholderPosition, int $fragmentPosition, arr /** * Returns a map of placeholder positions to their parameter names. * - * @return string[] + * @return array */ private static function getNamedPlaceholderPositions(string $statement): array { From b858561ba4230db1d3f3299d14ebcebfd98fa950 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 2 Oct 2020 14:28:16 -0700 Subject: [PATCH 09/56] Fix the tests that violate the type system --- tests/Doctrine/Tests/DBAL/ConfigurationTest.php | 4 ---- tests/Doctrine/Tests/DBAL/ConnectionTest.php | 2 -- tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php | 2 +- .../Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php | 6 +----- tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php | 2 +- 5 files changed, 3 insertions(+), 13 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/ConfigurationTest.php b/tests/Doctrine/Tests/DBAL/ConfigurationTest.php index 9a969bc1d5c..b1d36c66d36 100644 --- a/tests/Doctrine/Tests/DBAL/ConfigurationTest.php +++ b/tests/Doctrine/Tests/DBAL/ConfigurationTest.php @@ -38,9 +38,5 @@ public function testSetsDefaultConnectionAutoCommitMode(): void $this->config->setAutoCommit(false); self::assertFalse($this->config->getAutoCommit()); - - $this->config->setAutoCommit(0); - - self::assertFalse($this->config->getAutoCommit()); } } diff --git a/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/ConnectionTest.php index 8bcf1b817fe..5543a42dec7 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -241,8 +241,6 @@ public function testSetAutoCommit(): void { $this->connection->setAutoCommit(false); self::assertFalse($this->connection->isAutoCommit()); - $this->connection->setAutoCommit(0); - self::assertFalse($this->connection->isAutoCommit()); } public function testConnectStartsTransactionInNoAutoCommitMode(): void diff --git a/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php b/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php index b1a88e8a26c..f0ad89be7e7 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php @@ -232,7 +232,7 @@ public function testFetchAllColumn(): void $query = $this->connection->getDatabasePlatform() ->getDummySelectSQL('1'); - $qcp = new QueryCacheProfile(0, 0, new ArrayCache()); + $qcp = new QueryCacheProfile(0, null, new ArrayCache()); $stmt = $this->connection->executeCacheQuery($query, [], [], $qcp); $stmt->fetchAll(FetchMode::COLUMN); diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php index 88f37d27ca2..2357c1a796b 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php @@ -14,11 +14,9 @@ public function createPlatform(): AbstractPlatform } /** - * @param int|bool|null $lockMode - * * @dataProvider getLockHints */ - public function testAppendsLockHint($lockMode, string $lockHint): void + public function testAppendsLockHint(?int $lockMode, string $lockHint): void { $fromClause = 'FROM users'; $expectedResult = $fromClause . $lockHint; @@ -41,8 +39,6 @@ public static function getLockHints(): iterable { return [ [null, ''], - [false, ''], - [true, ''], [LockMode::NONE, ' WITH (NOLOCK)'], [LockMode::OPTIMISTIC, ''], [LockMode::PESSIMISTIC_READ, ' WITH (HOLDLOCK, ROWLOCK)'], diff --git a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php index f2a8ec2fd15..df2874a535a 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php @@ -485,7 +485,7 @@ public function testCompareSequences(): void $seq1 = new Sequence('foo', 1, 1); $seq2 = new Sequence('foo', 1, 2); $seq3 = new Sequence('foo', 2, 1); - $seq4 = new Sequence('foo', '1', '1'); + $seq4 = new Sequence('foo', 1, 1); $c = new Comparator(); From 230b95b293bbab4416bbe3ea3b9823399dbaf754 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 2 Oct 2020 14:38:14 -0700 Subject: [PATCH 10/56] Rework the tests that do not actually perform assertions --- .../Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php | 4 ++-- tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php index a7cb0686ebf..08a356704ee 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php @@ -32,8 +32,8 @@ public function testDriverOptions(): void { $driverOptions = [MYSQLI_OPT_CONNECT_TIMEOUT => 1]; - $connection = $this->getConnection($driverOptions); - self::assertInstanceOf(Connection::class, $connection); + $this->getConnection($driverOptions); + $this->expectNotToPerformAssertions(); } public function testUnsupportedDriverOption(): void diff --git a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php index 092c073551d..9cd147026b1 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php @@ -52,7 +52,7 @@ public function testValidIdentifiers(string $identifier): void $platform = $this->createPlatform(); $platform->assertValidIdentifier($identifier); - $this->addToAssertionCount(1); + $this->expectNotToPerformAssertions(); } /** From ce651841a96332148dfa6568fc3335bf5bb01100 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 2 Oct 2020 14:56:59 -0700 Subject: [PATCH 11/56] Remove redundant method arguments --- .../Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php index 41306d4ef04..570ec8ad63e 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php @@ -43,7 +43,7 @@ public function testRenameTable(): void $tables = $this->schemaManager->listTables(); - self::assertHasTable($tables, 'list_tables_test_new_name'); + self::assertHasTable($tables); } public function testListTableWithBinary(): void From 9e97067b46689358a73c4ebf63db3ca18bb7712b Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 2 Oct 2020 15:02:36 -0700 Subject: [PATCH 12/56] Loosen an unnecessarily strict type --- tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php b/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php index f0ad89be7e7..05d3ff70cd2 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php @@ -243,7 +243,7 @@ public function testFetchAllColumn(): void } /** - * @param array>|list $expectedResult + * @param list $expectedResult */ private function assertCacheNonCacheSelectSameFetchModeAreEqual(array $expectedResult, int $fetchMode): void { From 41dc63a4a102dd3d973bb0bcec214fa7b64fe2ab Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 2 Oct 2020 18:17:50 -0700 Subject: [PATCH 13/56] Fix invalid parameter type annotations --- lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php | 4 ++-- lib/Doctrine/DBAL/Query/QueryBuilder.php | 6 +++--- phpstan.neon.dist | 3 +++ .../Tests/DBAL/Sharding/PoolingShardManagerTest.php | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php index 3c34a8767c3..d019d74576f 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php @@ -181,7 +181,7 @@ public static function convertPositionalToNamedPlaceholders($statement) * Finds next placeholder or opening quote. * * @param string $statement The SQL statement to parse - * @param string $tokenOffset The offset to start searching from + * @param int $tokenOffset The offset to start searching from * @param int $fragmentOffset The offset to build the next fragment from * @param string[] $fragments Fragments of the original statement * not containing placeholders @@ -228,7 +228,7 @@ private static function findPlaceholderOrOpeningQuote( * Finds closing quote * * @param string $statement The SQL statement to parse - * @param string $tokenOffset The offset to start searching from + * @param int $tokenOffset The offset to start searching from * @param string $currentLiteralDelimiter The delimiter of the current string literal * * @return bool Whether the token was found diff --git a/lib/Doctrine/DBAL/Query/QueryBuilder.php b/lib/Doctrine/DBAL/Query/QueryBuilder.php index a1306754836..bb8dce8187e 100644 --- a/lib/Doctrine/DBAL/Query/QueryBuilder.php +++ b/lib/Doctrine/DBAL/Query/QueryBuilder.php @@ -1191,7 +1191,7 @@ private function getFromClauses() } /** - * @param string[] $knownAliases + * @param array $knownAliases * * @throws QueryException */ @@ -1335,8 +1335,8 @@ public function createPositionalParameter($value, $type = ParameterType::STRING) } /** - * @param string $fromAlias - * @param string[] $knownAliases + * @param string $fromAlias + * @param array $knownAliases * * @return string * diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 59a0a7442f3..93597bd6f52 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -21,6 +21,9 @@ parameters: - '~^Property Doctrine\\DBAL\\Schema\\Schema::\$_schemaConfig \(Doctrine\\DBAL\\Schema\\SchemaConfig\) does not accept default value of type false\.\z~' - '~^Return type \(int\|false\) of method Doctrine\\DBAL\\Driver\\OCI8\\OCI8Connection\:\:lastInsertId\(\) should be compatible with return type \(string\) of method Doctrine\\DBAL\\Driver\\Connection::lastInsertId\(\)~' + # https://github.com/phpstan/phpstan/issues/2857 + - '~^Parameter #2 \$registeredAliases of static method Doctrine\\DBAL\\Query\\QueryException::nonUniqueAlias\(\) expects array, array given\.\z~' + # legacy variadic-like signature # TODO: remove in 3.0.0 - '~^Method Doctrine\\DBAL(\\.*)?Connection::query\(\) invoked with \d+ parameters?, 0 required\.\z~' diff --git a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php index d2ce7b7f94f..8ac09bd4e0c 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php @@ -11,7 +11,7 @@ class PoolingShardManagerTest extends TestCase { /** - * @return PoolingShardConnection|MockObject + * @return PoolingShardConnection&MockObject */ private function createConnectionMock(): PoolingShardConnection { From 90a459ff19a4089ec69dc99f90a328bdf37bfbab Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 2 Oct 2020 15:16:24 -0700 Subject: [PATCH 14/56] Bump Psalm level to 4 --- psalm.xml | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/psalm.xml b/psalm.xml index c813b8ce45d..f67b67c6566 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,7 +1,7 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -95,6 +146,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 536ad5110e65d70d26c14c3fefb6d0670c58eb0e Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 2 Oct 2020 21:30:12 -0700 Subject: [PATCH 15/56] Update PHPUnit to 9.4 --- ci/github/phpunit.oci8.xml | 2 +- ci/github/phpunit.pdo-oci.xml | 2 +- composer.json | 3 +- composer.lock | 447 ++++++++++-------- phpunit.xml.dist | 2 +- .../mssql.sql2008r2sp2.sqlsrv.appveyor.xml | 4 +- .../mssql.sql2012sp1.sqlsrv.appveyor.xml | 4 +- .../mssql.sql2017.pdo_sqlsrv.appveyor.xml | 4 +- .../mssql.sql2017.sqlsrv.appveyor.xml | 4 +- tests/travis/ibm_db2.travis.xml | 4 +- tests/travis/mariadb.docker.travis.xml | 4 +- tests/travis/mariadb.mysqli.docker.travis.xml | 4 +- tests/travis/mysql.docker.travis.xml | 4 +- tests/travis/mysqli-tls.docker.travis.xml | 2 +- tests/travis/mysqli.docker.travis.xml | 4 +- tests/travis/pdo_sqlsrv.travis.xml | 4 +- tests/travis/pgsql.travis.xml | 4 +- tests/travis/sqlite.travis.xml | 6 +- tests/travis/sqlsrv.travis.xml | 4 +- 19 files changed, 270 insertions(+), 242 deletions(-) diff --git a/ci/github/phpunit.oci8.xml b/ci/github/phpunit.oci8.xml index f4454b2f9c4..bbe76733cac 100644 --- a/ci/github/phpunit.oci8.xml +++ b/ci/github/phpunit.oci8.xml @@ -1,6 +1,6 @@ =7.3", "phpunit/php-file-iterator": "^3.0.3", "phpunit/php-text-template": "^2.0.2", "sebastian/code-unit-reverse-lookup": "^2.0.2", @@ -1579,7 +1579,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "9.0-dev" + "dev-master": "9.2-dev" } }, "autoload": { @@ -1607,7 +1607,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.0.0" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.0" }, "funding": [ { @@ -1615,27 +1615,27 @@ "type": "github" } ], - "time": "2020-08-07T04:12:30+00:00" + "time": "2020-10-02T03:37:32+00:00" }, { "name": "phpunit/php-file-iterator", - "version": "3.0.4", + "version": "3.0.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "25fefc5b19835ca653877fe081644a3f8c1d915e" + "reference": "aa4be8575f26070b100fccb67faabb28f21f66f8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/25fefc5b19835ca653877fe081644a3f8c1d915e", - "reference": "25fefc5b19835ca653877fe081644a3f8c1d915e", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/aa4be8575f26070b100fccb67faabb28f21f66f8", + "reference": "aa4be8575f26070b100fccb67faabb28f21f66f8", "shasum": "" }, "require": { - "php": "^7.3 || ^8.0" + "php": ">=7.3" }, "require-dev": { - "phpunit/phpunit": "^9.0" + "phpunit/phpunit": "^9.3" }, "type": "library", "extra": { @@ -1667,7 +1667,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", - "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/3.0.4" + "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/3.0.5" }, "funding": [ { @@ -1675,28 +1675,28 @@ "type": "github" } ], - "time": "2020-07-11T05:18:21+00:00" + "time": "2020-09-28T05:57:25+00:00" }, { "name": "phpunit/php-invoker", - "version": "3.1.0", + "version": "3.1.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-invoker.git", - "reference": "7a85b66acc48cacffdf87dadd3694e7123674298" + "reference": "5a10147d0aaf65b58940a0b72f71c9ac0423cc67" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/7a85b66acc48cacffdf87dadd3694e7123674298", - "reference": "7a85b66acc48cacffdf87dadd3694e7123674298", + "url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/5a10147d0aaf65b58940a0b72f71c9ac0423cc67", + "reference": "5a10147d0aaf65b58940a0b72f71c9ac0423cc67", "shasum": "" }, "require": { - "php": "^7.3 || ^8.0" + "php": ">=7.3" }, "require-dev": { "ext-pcntl": "*", - "phpunit/phpunit": "^9.0" + "phpunit/phpunit": "^9.3" }, "suggest": { "ext-pcntl": "*" @@ -1730,7 +1730,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-invoker/issues", - "source": "https://github.com/sebastianbergmann/php-invoker/tree/3.1.0" + "source": "https://github.com/sebastianbergmann/php-invoker/tree/3.1.1" }, "funding": [ { @@ -1738,27 +1738,27 @@ "type": "github" } ], - "time": "2020-08-06T07:04:15+00:00" + "time": "2020-09-28T05:58:55+00:00" }, { "name": "phpunit/php-text-template", - "version": "2.0.2", + "version": "2.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-text-template.git", - "reference": "6ff9c8ea4d3212b88fcf74e25e516e2c51c99324" + "reference": "18c887016e60e52477e54534956d7b47bc52cd84" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/6ff9c8ea4d3212b88fcf74e25e516e2c51c99324", - "reference": "6ff9c8ea4d3212b88fcf74e25e516e2c51c99324", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/18c887016e60e52477e54534956d7b47bc52cd84", + "reference": "18c887016e60e52477e54534956d7b47bc52cd84", "shasum": "" }, "require": { - "php": "^7.3 || ^8.0" + "php": ">=7.3" }, "require-dev": { - "phpunit/phpunit": "^9.0" + "phpunit/phpunit": "^9.3" }, "type": "library", "extra": { @@ -1789,7 +1789,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-text-template/issues", - "source": "https://github.com/sebastianbergmann/php-text-template/tree/master" + "source": "https://github.com/sebastianbergmann/php-text-template/tree/2.0.3" }, "funding": [ { @@ -1797,27 +1797,27 @@ "type": "github" } ], - "time": "2020-06-26T11:55:37+00:00" + "time": "2020-09-28T06:03:05+00:00" }, { "name": "phpunit/php-timer", - "version": "5.0.1", + "version": "5.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "cc49734779cbb302bf51a44297dab8c4bbf941e7" + "reference": "c9ff14f493699e2f6adee9fd06a0245b276643b7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/cc49734779cbb302bf51a44297dab8c4bbf941e7", - "reference": "cc49734779cbb302bf51a44297dab8c4bbf941e7", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/c9ff14f493699e2f6adee9fd06a0245b276643b7", + "reference": "c9ff14f493699e2f6adee9fd06a0245b276643b7", "shasum": "" }, "require": { - "php": "^7.3 || ^8.0" + "php": ">=7.3" }, "require-dev": { - "phpunit/phpunit": "^9.2" + "phpunit/phpunit": "^9.3" }, "type": "library", "extra": { @@ -1848,7 +1848,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-timer/issues", - "source": "https://github.com/sebastianbergmann/php-timer/tree/master" + "source": "https://github.com/sebastianbergmann/php-timer/tree/5.0.2" }, "funding": [ { @@ -1856,20 +1856,20 @@ "type": "github" } ], - "time": "2020-06-26T11:58:13+00:00" + "time": "2020-09-28T06:00:25+00:00" }, { "name": "phpunit/phpunit", - "version": "9.3.2", + "version": "9.4.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "eacb57f3857cb6706550bd39ea500f9b1097b0bf" + "reference": "ef533467a7974c4b6c354f3eff42a115910bd4e5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/eacb57f3857cb6706550bd39ea500f9b1097b0bf", - "reference": "eacb57f3857cb6706550bd39ea500f9b1097b0bf", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/ef533467a7974c4b6c354f3eff42a115910bd4e5", + "reference": "ef533467a7974c4b6c354f3eff42a115910bd4e5", "shasum": "" }, "require": { @@ -1883,13 +1883,14 @@ "myclabs/deep-copy": "^1.10.1", "phar-io/manifest": "^2.0.1", "phar-io/version": "^3.0.2", - "php": "^7.3 || ^8.0", + "php": ">=7.3", "phpspec/prophecy": "^1.11.1", - "phpunit/php-code-coverage": "^9.0", + "phpunit/php-code-coverage": "^9.2", "phpunit/php-file-iterator": "^3.0.4", "phpunit/php-invoker": "^3.1", "phpunit/php-text-template": "^2.0.2", "phpunit/php-timer": "^5.0.1", + "sebastian/cli-parser": "^1.0", "sebastian/code-unit": "^1.0.5", "sebastian/comparator": "^4.0.3", "sebastian/diff": "^4.0.2", @@ -1915,7 +1916,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "9.3-dev" + "dev-master": "9.4-dev" } }, "autoload": { @@ -1946,7 +1947,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.3.2" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.4.0" }, "funding": [ { @@ -1958,7 +1959,7 @@ "type": "github" } ], - "time": "2020-08-07T09:12:30+00:00" + "time": "2020-10-02T03:54:37+00:00" }, { "name": "psalm/plugin-phpunit", @@ -2118,25 +2119,81 @@ }, "time": "2020-03-23T09:12:05+00:00" }, + { + "name": "sebastian/cli-parser", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/cli-parser.git", + "reference": "442e7c7e687e42adc03470c7b668bc4b2402c0b2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/442e7c7e687e42adc03470c7b668bc4b2402c0b2", + "reference": "442e7c7e687e42adc03470c7b668bc4b2402c0b2", + "shasum": "" + }, + "require": { + "php": ">=7.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-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": "Library for parsing CLI options", + "homepage": "https://github.com/sebastianbergmann/cli-parser", + "support": { + "issues": "https://github.com/sebastianbergmann/cli-parser/issues", + "source": "https://github.com/sebastianbergmann/cli-parser/tree/1.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-09-28T06:08:49+00:00" + }, { "name": "sebastian/code-unit", - "version": "1.0.5", + "version": "1.0.7", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/code-unit.git", - "reference": "c1e2df332c905079980b119c4db103117e5e5c90" + "reference": "59236be62b1bb9919e6d7f60b0b832dc05cef9ab" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/c1e2df332c905079980b119c4db103117e5e5c90", - "reference": "c1e2df332c905079980b119c4db103117e5e5c90", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/59236be62b1bb9919e6d7f60b0b832dc05cef9ab", + "reference": "59236be62b1bb9919e6d7f60b0b832dc05cef9ab", "shasum": "" }, "require": { - "php": "^7.3 || ^8.0" + "php": ">=7.3" }, "require-dev": { - "phpunit/phpunit": "^9.0" + "phpunit/phpunit": "^9.3" }, "type": "library", "extra": { @@ -2164,7 +2221,7 @@ "homepage": "https://github.com/sebastianbergmann/code-unit", "support": { "issues": "https://github.com/sebastianbergmann/code-unit/issues", - "source": "https://github.com/sebastianbergmann/code-unit/tree/master" + "source": "https://github.com/sebastianbergmann/code-unit/tree/1.0.7" }, "funding": [ { @@ -2172,27 +2229,27 @@ "type": "github" } ], - "time": "2020-06-26T12:50:45+00:00" + "time": "2020-10-02T14:47:54+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", - "version": "2.0.2", + "version": "2.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", - "reference": "ee51f9bb0c6d8a43337055db3120829fa14da819" + "reference": "ac91f01ccec49fb77bdc6fd1e548bc70f7faa3e5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/ee51f9bb0c6d8a43337055db3120829fa14da819", - "reference": "ee51f9bb0c6d8a43337055db3120829fa14da819", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/ac91f01ccec49fb77bdc6fd1e548bc70f7faa3e5", + "reference": "ac91f01ccec49fb77bdc6fd1e548bc70f7faa3e5", "shasum": "" }, "require": { - "php": "^7.3 || ^8.0" + "php": ">=7.3" }, "require-dev": { - "phpunit/phpunit": "^9.0" + "phpunit/phpunit": "^9.3" }, "type": "library", "extra": { @@ -2219,7 +2276,7 @@ "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", "support": { "issues": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/issues", - "source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/master" + "source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/2.0.3" }, "funding": [ { @@ -2227,29 +2284,29 @@ "type": "github" } ], - "time": "2020-06-26T12:04:00+00:00" + "time": "2020-09-28T05:30:19+00:00" }, { "name": "sebastian/comparator", - "version": "4.0.3", + "version": "4.0.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "dcc580eadfaa4e7f9d2cf9ae1922134ea962e14f" + "reference": "7a8ff306445707539c1a6397372a982a1ec55120" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/dcc580eadfaa4e7f9d2cf9ae1922134ea962e14f", - "reference": "dcc580eadfaa4e7f9d2cf9ae1922134ea962e14f", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/7a8ff306445707539c1a6397372a982a1ec55120", + "reference": "7a8ff306445707539c1a6397372a982a1ec55120", "shasum": "" }, "require": { - "php": "^7.3 || ^8.0", + "php": ">=7.3", "sebastian/diff": "^4.0", "sebastian/exporter": "^4.0" }, "require-dev": { - "phpunit/phpunit": "^9.0" + "phpunit/phpunit": "^9.3" }, "type": "library", "extra": { @@ -2293,7 +2350,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/comparator/issues", - "source": "https://github.com/sebastianbergmann/comparator/tree/master" + "source": "https://github.com/sebastianbergmann/comparator/tree/4.0.5" }, "funding": [ { @@ -2301,28 +2358,28 @@ "type": "github" } ], - "time": "2020-06-26T12:05:46+00:00" + "time": "2020-09-30T06:47:25+00:00" }, { "name": "sebastian/complexity", - "version": "2.0.0", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/complexity.git", - "reference": "33fcd6a26656c6546f70871244ecba4b4dced097" + "reference": "ba8cc2da0c0bfbc813d03b56406734030c7f1eff" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/33fcd6a26656c6546f70871244ecba4b4dced097", - "reference": "33fcd6a26656c6546f70871244ecba4b4dced097", + "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/ba8cc2da0c0bfbc813d03b56406734030c7f1eff", + "reference": "ba8cc2da0c0bfbc813d03b56406734030c7f1eff", "shasum": "" }, "require": { "nikic/php-parser": "^4.7", - "php": "^7.3 || ^8.0" + "php": ">=7.3" }, "require-dev": { - "phpunit/phpunit": "^9.2" + "phpunit/phpunit": "^9.3" }, "type": "library", "extra": { @@ -2350,7 +2407,7 @@ "homepage": "https://github.com/sebastianbergmann/complexity", "support": { "issues": "https://github.com/sebastianbergmann/complexity/issues", - "source": "https://github.com/sebastianbergmann/complexity/tree/2.0.0" + "source": "https://github.com/sebastianbergmann/complexity/tree/2.0.1" }, "funding": [ { @@ -2358,27 +2415,27 @@ "type": "github" } ], - "time": "2020-07-25T14:01:34+00:00" + "time": "2020-09-28T06:05:03+00:00" }, { "name": "sebastian/diff", - "version": "4.0.2", + "version": "4.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "1e90b4cf905a7d06c420b1d2e9d11a4dc8a13113" + "reference": "ffc949a1a2aae270ea064453d7535b82e4c32092" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/1e90b4cf905a7d06c420b1d2e9d11a4dc8a13113", - "reference": "1e90b4cf905a7d06c420b1d2e9d11a4dc8a13113", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/ffc949a1a2aae270ea064453d7535b82e4c32092", + "reference": "ffc949a1a2aae270ea064453d7535b82e4c32092", "shasum": "" }, "require": { - "php": "^7.3 || ^8.0" + "php": ">=7.3" }, "require-dev": { - "phpunit/phpunit": "^9.0", + "phpunit/phpunit": "^9.3", "symfony/process": "^4.2 || ^5" }, "type": "library", @@ -2416,7 +2473,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/diff/issues", - "source": "https://github.com/sebastianbergmann/diff/tree/master" + "source": "https://github.com/sebastianbergmann/diff/tree/4.0.3" }, "funding": [ { @@ -2424,27 +2481,27 @@ "type": "github" } ], - "time": "2020-06-30T04:46:02+00:00" + "time": "2020-09-28T05:32:55+00:00" }, { "name": "sebastian/environment", - "version": "5.1.2", + "version": "5.1.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "0a757cab9d5b7ef49a619f1143e6c9c1bc0fe9d2" + "reference": "388b6ced16caa751030f6a69e588299fa09200ac" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/0a757cab9d5b7ef49a619f1143e6c9c1bc0fe9d2", - "reference": "0a757cab9d5b7ef49a619f1143e6c9c1bc0fe9d2", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/388b6ced16caa751030f6a69e588299fa09200ac", + "reference": "388b6ced16caa751030f6a69e588299fa09200ac", "shasum": "" }, "require": { - "php": "^7.3 || ^8.0" + "php": ">=7.3" }, "require-dev": { - "phpunit/phpunit": "^9.0" + "phpunit/phpunit": "^9.3" }, "suggest": { "ext-posix": "*" @@ -2452,7 +2509,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "5.0-dev" + "dev-master": "5.1-dev" } }, "autoload": { @@ -2479,7 +2536,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/environment/issues", - "source": "https://github.com/sebastianbergmann/environment/tree/master" + "source": "https://github.com/sebastianbergmann/environment/tree/5.1.3" }, "funding": [ { @@ -2487,29 +2544,29 @@ "type": "github" } ], - "time": "2020-06-26T12:07:24+00:00" + "time": "2020-09-28T05:52:38+00:00" }, { "name": "sebastian/exporter", - "version": "4.0.2", + "version": "4.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "571d721db4aec847a0e59690b954af33ebf9f023" + "reference": "d89cc98761b8cb5a1a235a6b703ae50d34080e65" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/571d721db4aec847a0e59690b954af33ebf9f023", - "reference": "571d721db4aec847a0e59690b954af33ebf9f023", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/d89cc98761b8cb5a1a235a6b703ae50d34080e65", + "reference": "d89cc98761b8cb5a1a235a6b703ae50d34080e65", "shasum": "" }, "require": { - "php": "^7.3 || ^8.0", + "php": ">=7.3", "sebastian/recursion-context": "^4.0" }, "require-dev": { "ext-mbstring": "*", - "phpunit/phpunit": "^9.2" + "phpunit/phpunit": "^9.3" }, "type": "library", "extra": { @@ -2556,7 +2613,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/exporter/issues", - "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.2" + "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.3" }, "funding": [ { @@ -2564,24 +2621,24 @@ "type": "github" } ], - "time": "2020-06-26T12:08:55+00:00" + "time": "2020-09-28T05:24:23+00:00" }, { "name": "sebastian/global-state", - "version": "5.0.0", + "version": "5.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "22ae663c951bdc39da96603edc3239ed3a299097" + "reference": "ea779cb749a478b22a2564ac41cd7bda79c78dc7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/22ae663c951bdc39da96603edc3239ed3a299097", - "reference": "22ae663c951bdc39da96603edc3239ed3a299097", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/ea779cb749a478b22a2564ac41cd7bda79c78dc7", + "reference": "ea779cb749a478b22a2564ac41cd7bda79c78dc7", "shasum": "" }, "require": { - "php": "^7.3 || ^8.0", + "php": ">=7.3", "sebastian/object-reflector": "^2.0", "sebastian/recursion-context": "^4.0" }, @@ -2620,7 +2677,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/global-state/issues", - "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.0" + "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.1" }, "funding": [ { @@ -2628,28 +2685,28 @@ "type": "github" } ], - "time": "2020-08-07T04:09:03+00:00" + "time": "2020-09-28T05:54:06+00:00" }, { "name": "sebastian/lines-of-code", - "version": "1.0.0", + "version": "1.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/lines-of-code.git", - "reference": "e02bf626f404b5daec382a7b8a6a4456e49017e5" + "reference": "6514b8f21906b8b46f520d1fbd17a4523fa59a54" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/e02bf626f404b5daec382a7b8a6a4456e49017e5", - "reference": "e02bf626f404b5daec382a7b8a6a4456e49017e5", + "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/6514b8f21906b8b46f520d1fbd17a4523fa59a54", + "reference": "6514b8f21906b8b46f520d1fbd17a4523fa59a54", "shasum": "" }, "require": { "nikic/php-parser": "^4.6", - "php": "^7.3 || ^8.0" + "php": ">=7.3" }, "require-dev": { - "phpunit/phpunit": "^9.2" + "phpunit/phpunit": "^9.3" }, "type": "library", "extra": { @@ -2677,7 +2734,7 @@ "homepage": "https://github.com/sebastianbergmann/lines-of-code", "support": { "issues": "https://github.com/sebastianbergmann/lines-of-code/issues", - "source": "https://github.com/sebastianbergmann/lines-of-code/tree/1.0.0" + "source": "https://github.com/sebastianbergmann/lines-of-code/tree/1.0.1" }, "funding": [ { @@ -2685,29 +2742,29 @@ "type": "github" } ], - "time": "2020-07-22T18:33:42+00:00" + "time": "2020-09-28T06:07:27+00:00" }, { "name": "sebastian/object-enumerator", - "version": "4.0.2", + "version": "4.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/object-enumerator.git", - "reference": "074fed2d0a6d08e1677dd8ce9d32aecb384917b8" + "reference": "f6f5957013d84725427d361507e13513702888a4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/074fed2d0a6d08e1677dd8ce9d32aecb384917b8", - "reference": "074fed2d0a6d08e1677dd8ce9d32aecb384917b8", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/f6f5957013d84725427d361507e13513702888a4", + "reference": "f6f5957013d84725427d361507e13513702888a4", "shasum": "" }, "require": { - "php": "^7.3 || ^8.0", + "php": ">=7.3", "sebastian/object-reflector": "^2.0", "sebastian/recursion-context": "^4.0" }, "require-dev": { - "phpunit/phpunit": "^9.0" + "phpunit/phpunit": "^9.3" }, "type": "library", "extra": { @@ -2734,7 +2791,7 @@ "homepage": "https://github.com/sebastianbergmann/object-enumerator/", "support": { "issues": "https://github.com/sebastianbergmann/object-enumerator/issues", - "source": "https://github.com/sebastianbergmann/object-enumerator/tree/master" + "source": "https://github.com/sebastianbergmann/object-enumerator/tree/4.0.3" }, "funding": [ { @@ -2742,27 +2799,27 @@ "type": "github" } ], - "time": "2020-06-26T12:11:32+00:00" + "time": "2020-09-28T05:55:06+00:00" }, { "name": "sebastian/object-reflector", - "version": "2.0.2", + "version": "2.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/object-reflector.git", - "reference": "127a46f6b057441b201253526f81d5406d6c7840" + "reference": "d9d0ab3b12acb1768bc1e0a89b23c90d2043cbe5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/127a46f6b057441b201253526f81d5406d6c7840", - "reference": "127a46f6b057441b201253526f81d5406d6c7840", + "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/d9d0ab3b12acb1768bc1e0a89b23c90d2043cbe5", + "reference": "d9d0ab3b12acb1768bc1e0a89b23c90d2043cbe5", "shasum": "" }, "require": { - "php": "^7.3 || ^8.0" + "php": ">=7.3" }, "require-dev": { - "phpunit/phpunit": "^9.0" + "phpunit/phpunit": "^9.3" }, "type": "library", "extra": { @@ -2789,7 +2846,7 @@ "homepage": "https://github.com/sebastianbergmann/object-reflector/", "support": { "issues": "https://github.com/sebastianbergmann/object-reflector/issues", - "source": "https://github.com/sebastianbergmann/object-reflector/tree/master" + "source": "https://github.com/sebastianbergmann/object-reflector/tree/2.0.3" }, "funding": [ { @@ -2797,27 +2854,27 @@ "type": "github" } ], - "time": "2020-06-26T12:12:55+00:00" + "time": "2020-09-28T05:56:16+00:00" }, { "name": "sebastian/recursion-context", - "version": "4.0.2", + "version": "4.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "062231bf61d2b9448c4fa5a7643b5e1829c11d63" + "reference": "ed8c9cd355089134bc9cba421b5cfdd58f0eaef7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/062231bf61d2b9448c4fa5a7643b5e1829c11d63", - "reference": "062231bf61d2b9448c4fa5a7643b5e1829c11d63", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/ed8c9cd355089134bc9cba421b5cfdd58f0eaef7", + "reference": "ed8c9cd355089134bc9cba421b5cfdd58f0eaef7", "shasum": "" }, "require": { - "php": "^7.3 || ^8.0" + "php": ">=7.3" }, "require-dev": { - "phpunit/phpunit": "^9.0" + "phpunit/phpunit": "^9.3" }, "type": "library", "extra": { @@ -2852,7 +2909,7 @@ "homepage": "http://www.github.com/sebastianbergmann/recursion-context", "support": { "issues": "https://github.com/sebastianbergmann/recursion-context/issues", - "source": "https://github.com/sebastianbergmann/recursion-context/tree/master" + "source": "https://github.com/sebastianbergmann/recursion-context/tree/4.0.3" }, "funding": [ { @@ -2860,24 +2917,24 @@ "type": "github" } ], - "time": "2020-06-26T12:14:17+00:00" + "time": "2020-09-28T05:17:32+00:00" }, { "name": "sebastian/resource-operations", - "version": "3.0.2", + "version": "3.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/resource-operations.git", - "reference": "0653718a5a629b065e91f774595267f8dc32e213" + "reference": "0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/0653718a5a629b065e91f774595267f8dc32e213", - "reference": "0653718a5a629b065e91f774595267f8dc32e213", + "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8", + "reference": "0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8", "shasum": "" }, "require": { - "php": "^7.3 || ^8.0" + "php": ">=7.3" }, "require-dev": { "phpunit/phpunit": "^9.0" @@ -2907,7 +2964,7 @@ "homepage": "https://www.github.com/sebastianbergmann/resource-operations", "support": { "issues": "https://github.com/sebastianbergmann/resource-operations/issues", - "source": "https://github.com/sebastianbergmann/resource-operations/tree/3.0.2" + "source": "https://github.com/sebastianbergmann/resource-operations/tree/3.0.3" }, "funding": [ { @@ -2915,27 +2972,27 @@ "type": "github" } ], - "time": "2020-06-26T12:16:22+00:00" + "time": "2020-09-28T06:45:17+00:00" }, { "name": "sebastian/type", - "version": "2.2.1", + "version": "2.2.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/type.git", - "reference": "86991e2b33446cd96e648c18bcdb1e95afb2c05a" + "reference": "e494dcaeb89d1458c9ccd8c819745245a1669aea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/86991e2b33446cd96e648c18bcdb1e95afb2c05a", - "reference": "86991e2b33446cd96e648c18bcdb1e95afb2c05a", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/e494dcaeb89d1458c9ccd8c819745245a1669aea", + "reference": "e494dcaeb89d1458c9ccd8c819745245a1669aea", "shasum": "" }, "require": { - "php": "^7.3 || ^8.0" + "php": ">=7.3" }, "require-dev": { - "phpunit/phpunit": "^9.2" + "phpunit/phpunit": "^9.3" }, "type": "library", "extra": { @@ -2963,7 +3020,7 @@ "homepage": "https://github.com/sebastianbergmann/type", "support": { "issues": "https://github.com/sebastianbergmann/type/issues", - "source": "https://github.com/sebastianbergmann/type/tree/2.2.1" + "source": "https://github.com/sebastianbergmann/type/tree/2.2.2" }, "funding": [ { @@ -2971,24 +3028,24 @@ "type": "github" } ], - "time": "2020-07-05T08:31:53+00:00" + "time": "2020-09-28T06:01:38+00:00" }, { "name": "sebastian/version", - "version": "3.0.1", + "version": "3.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/version.git", - "reference": "626586115d0ed31cb71483be55beb759b5af5a3c" + "reference": "c6c1022351a901512170118436c764e473f6de8c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/626586115d0ed31cb71483be55beb759b5af5a3c", - "reference": "626586115d0ed31cb71483be55beb759b5af5a3c", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/c6c1022351a901512170118436c764e473f6de8c", + "reference": "c6c1022351a901512170118436c764e473f6de8c", "shasum": "" }, "require": { - "php": "^7.3 || ^8.0" + "php": ">=7.3" }, "type": "library", "extra": { @@ -3016,7 +3073,7 @@ "homepage": "https://github.com/sebastianbergmann/version", "support": { "issues": "https://github.com/sebastianbergmann/version/issues", - "source": "https://github.com/sebastianbergmann/version/tree/3.0.1" + "source": "https://github.com/sebastianbergmann/version/tree/3.0.2" }, "funding": [ { @@ -3024,7 +3081,7 @@ "type": "github" } ], - "time": "2020-06-26T12:18:43+00:00" + "time": "2020-09-28T06:39:44+00:00" }, { "name": "slevomat/coding-standard", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 6d693d9c924..f79efc83e40 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -12,7 +12,7 @@ Example: phpunit -c mysqlconf.xml --> - - diff --git a/tests/appveyor/mssql.sql2012sp1.sqlsrv.appveyor.xml b/tests/appveyor/mssql.sql2012sp1.sqlsrv.appveyor.xml index 0b060018623..20a0656b4d7 100644 --- a/tests/appveyor/mssql.sql2012sp1.sqlsrv.appveyor.xml +++ b/tests/appveyor/mssql.sql2012sp1.sqlsrv.appveyor.xml @@ -1,6 +1,6 @@ - - diff --git a/tests/appveyor/mssql.sql2017.pdo_sqlsrv.appveyor.xml b/tests/appveyor/mssql.sql2017.pdo_sqlsrv.appveyor.xml index dcf655bee08..4d9a5e8f10e 100644 --- a/tests/appveyor/mssql.sql2017.pdo_sqlsrv.appveyor.xml +++ b/tests/appveyor/mssql.sql2017.pdo_sqlsrv.appveyor.xml @@ -1,6 +1,6 @@ - - diff --git a/tests/appveyor/mssql.sql2017.sqlsrv.appveyor.xml b/tests/appveyor/mssql.sql2017.sqlsrv.appveyor.xml index bf908ed9b5c..956cf6e527d 100644 --- a/tests/appveyor/mssql.sql2017.sqlsrv.appveyor.xml +++ b/tests/appveyor/mssql.sql2017.sqlsrv.appveyor.xml @@ -1,6 +1,6 @@ - - diff --git a/tests/travis/ibm_db2.travis.xml b/tests/travis/ibm_db2.travis.xml index 3089c56c47a..c8b758a711f 100644 --- a/tests/travis/ibm_db2.travis.xml +++ b/tests/travis/ibm_db2.travis.xml @@ -1,6 +1,6 @@ - - diff --git a/tests/travis/mariadb.docker.travis.xml b/tests/travis/mariadb.docker.travis.xml index 67f63b2fde4..6efa94e94eb 100644 --- a/tests/travis/mariadb.docker.travis.xml +++ b/tests/travis/mariadb.docker.travis.xml @@ -1,6 +1,6 @@ - - diff --git a/tests/travis/mariadb.mysqli.docker.travis.xml b/tests/travis/mariadb.mysqli.docker.travis.xml index d93ca5ceda5..9925673195a 100644 --- a/tests/travis/mariadb.mysqli.docker.travis.xml +++ b/tests/travis/mariadb.mysqli.docker.travis.xml @@ -1,6 +1,6 @@ - - diff --git a/tests/travis/mysql.docker.travis.xml b/tests/travis/mysql.docker.travis.xml index 67f63b2fde4..6efa94e94eb 100644 --- a/tests/travis/mysql.docker.travis.xml +++ b/tests/travis/mysql.docker.travis.xml @@ -1,6 +1,6 @@ - - diff --git a/tests/travis/mysqli-tls.docker.travis.xml b/tests/travis/mysqli-tls.docker.travis.xml index f6f653c42bf..568a61ada6c 100644 --- a/tests/travis/mysqli-tls.docker.travis.xml +++ b/tests/travis/mysqli-tls.docker.travis.xml @@ -1,6 +1,6 @@ - - diff --git a/tests/travis/pdo_sqlsrv.travis.xml b/tests/travis/pdo_sqlsrv.travis.xml index 38802c599e9..a6afaabfff0 100644 --- a/tests/travis/pdo_sqlsrv.travis.xml +++ b/tests/travis/pdo_sqlsrv.travis.xml @@ -1,6 +1,6 @@ - - diff --git a/tests/travis/pgsql.travis.xml b/tests/travis/pgsql.travis.xml index 0a1a5c1bebb..b13bc3e1b4c 100644 --- a/tests/travis/pgsql.travis.xml +++ b/tests/travis/pgsql.travis.xml @@ -1,6 +1,6 @@ - - diff --git a/tests/travis/sqlite.travis.xml b/tests/travis/sqlite.travis.xml index ce3c1d0f914..7629953cc15 100644 --- a/tests/travis/sqlite.travis.xml +++ b/tests/travis/sqlite.travis.xml @@ -1,16 +1,12 @@ - - - - ../Doctrine/Tests/DBAL diff --git a/tests/travis/sqlsrv.travis.xml b/tests/travis/sqlsrv.travis.xml index de56350ce9d..c5412cdc2f6 100644 --- a/tests/travis/sqlsrv.travis.xml +++ b/tests/travis/sqlsrv.travis.xml @@ -1,6 +1,6 @@ - - From a4c60655eaa55c687a1675431e3e99274f0f76b4 Mon Sep 17 00:00:00 2001 From: Wojtek Date: Wed, 30 Sep 2020 19:28:11 +0200 Subject: [PATCH 16/56] Fix handling existing SQL Server column comment when other properties change --- .../DBAL/Platforms/SQLServerPlatform.php | 2 +- .../Schema/SQLServerSchemaManagerTest.php | 23 +++++++++++++++++-- .../AbstractSQLServerPlatformTestCase.php | 15 ++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php index c1da7ab8e83..2b45883b3fa 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php @@ -532,7 +532,7 @@ public function getAlterTableSQL(TableDiff $diff) ); } elseif ($hasFromComment && ! $hasComment) { $commentsSql[] = $this->getDropColumnCommentSQL($diff->name, $column->getQuotedName($this)); - } elseif ($hasComment) { + } elseif (! $hasFromComment && $hasComment) { $commentsSql[] = $this->getCreateColumnCommentSQL( $diff->name, $column->getQuotedName($this), diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php index 8b0bd707ee5..045299367b6 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php @@ -178,12 +178,13 @@ public function testColumnComments(): void $table->addColumn('create', 'integer', ['comment' => 'Doctrine 0wnz comments for reserved keyword columns!']); $table->addColumn('commented_type', 'object'); $table->addColumn('commented_type_with_comment', 'array', ['comment' => 'Doctrine array type.']); + $table->addColumn('commented_req_change_column', 'integer', ['comment' => 'Some comment', 'notnull' => true]); $table->setPrimaryKey(['id']); $this->schemaManager->createTable($table); $columns = $this->schemaManager->listTableColumns('sqlsrv_column_comment'); - self::assertCount(12, $columns); + self::assertCount(13, $columns); self::assertNull($columns['id']->getComment()); self::assertNull($columns['comment_null']->getComment()); self::assertNull($columns['comment_false']->getComment()); @@ -199,6 +200,7 @@ public function testColumnComments(): void self::assertEquals('Doctrine 0wnz comments for reserved keyword columns!', $columns['[create]']->getComment()); self::assertNull($columns['commented_type']->getComment()); self::assertEquals('Doctrine array type.', $columns['commented_type_with_comment']->getComment()); + self::assertEquals('Some comment', $columns['commented_req_change_column']->getComment()); $tableDiff = new TableDiff('sqlsrv_column_comment'); $tableDiff->fromTable = $table; @@ -326,13 +328,29 @@ public function testColumnComments(): void new Column('commented_type_with_comment', Type::getType('array'), ['comment' => 'Doctrine array type.']) ); + // Change column requirements without changing comment. + $tableDiff->changedColumns['commented_req_change_column'] = new ColumnDiff( + 'commented_req_change_column', + new Column( + 'commented_req_change_column', + Type::getType('integer'), + ['comment' => 'Some comment', 'notnull' => true] + ), + ['notnull'], + new Column( + 'commented_req_change_column', + Type::getType('integer'), + ['comment' => 'Some comment', 'notnull' => false] + ), + ); + $tableDiff->removedColumns['comment_integer_0'] = new Column('comment_integer_0', Type::getType('integer'), ['comment' => 0]); $this->schemaManager->alterTable($tableDiff); $columns = $this->schemaManager->listTableColumns('sqlsrv_column_comment'); - self::assertCount(23, $columns); + self::assertCount(24, $columns); self::assertEquals('primary', $columns['id']->getComment()); self::assertNull($columns['comment_null']->getComment()); self::assertEquals('false', $columns['comment_false']->getComment()); @@ -356,6 +374,7 @@ public function testColumnComments(): void self::assertEquals('666', $columns['[select]']->getComment()); self::assertNull($columns['added_commented_type']->getComment()); self::assertEquals('666', $columns['added_commented_type_with_comment']->getComment()); + self::assertEquals('Some comment', $columns['commented_req_change_column']->getComment()); } public function testPkOrdering(): void diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php index ddb7df84a00..7a63f3ffccf 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php @@ -1718,4 +1718,19 @@ private function expectCteWithMinAndMaxRowNums( . ') AS doctrine_tbl WHERE doctrine_rownum >= %d AND doctrine_rownum <= %d ORDER BY doctrine_rownum ASC'; self::assertEquals(sprintf($pattern, $expectedSql, $expectedMin, $expectedMax), $sql); } + + public function testAlterTableWithSchemaSameColumnComments(): void + { + $tableDiff = new TableDiff('testschema.mytable'); + $tableDiff->changedColumns['quota'] = new ColumnDiff( + 'quota', + new Column('quota', Type::getType('integer'), ['comment' => 'A comment', 'notnull' => true]), + ['notnull'], + new Column('quota', Type::getType('integer'), ['comment' => 'A comment', 'notnull' => false]) + ); + + $expectedSql = ['ALTER TABLE testschema.mytable ALTER COLUMN quota INT NOT NULL']; + + self::assertEquals($expectedSql, $this->platform->getAlterTableSQL($tableDiff)); + } } From 26fcec6ec827fad6688f0a70c5a63d236ebe4e92 Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Thu, 8 Oct 2020 19:19:35 +0200 Subject: [PATCH 17/56] Fix issue #4282, again --- lib/Doctrine/DBAL/Query/QueryBuilder.php | 9 +++++-- .../Tests/DBAL/Query/QueryBuilderTest.php | 26 +++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/DBAL/Query/QueryBuilder.php b/lib/Doctrine/DBAL/Query/QueryBuilder.php index bb8dce8187e..1d66b9e63c6 100644 --- a/lib/Doctrine/DBAL/Query/QueryBuilder.php +++ b/lib/Doctrine/DBAL/Query/QueryBuilder.php @@ -12,6 +12,7 @@ use function array_key_exists; use function array_keys; use function array_unshift; +use function count; use function func_get_args; use function func_num_args; use function implode; @@ -834,7 +835,9 @@ public function andWhere($where) $where = $this->getQueryPart('where'); if ($where instanceof CompositeExpression && $where->getType() === CompositeExpression::TYPE_AND) { - $where = $where->with(...$args); + if (count($args) > 0) { + $where = $where->with(...$args); + } } else { array_unshift($args, $where); $where = CompositeExpression::and(...$args); @@ -868,7 +871,9 @@ public function orWhere($where) $where = $this->getQueryPart('where'); if ($where instanceof CompositeExpression && $where->getType() === CompositeExpression::TYPE_OR) { - $where = $where->with(...$args); + if (count($args) > 0) { + $where = $where->with(...$args); + } } else { array_unshift($args, $where); $where = CompositeExpression::or(...$args); diff --git a/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php b/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php index 038097c8910..a83362ed588 100644 --- a/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php +++ b/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php @@ -950,6 +950,19 @@ public function testJoinWithNonUniqueAliasThrowsException(): void $qb->getSQL(); } + public function testWhereExpressionAndWhereEmptyString(): void + { + $qb = new QueryBuilder($this->conn); + + $qb->select('id') + ->from('foo') + ->where('a = b'); + + $qb->andWhere(''); + + self::assertSame('SELECT id FROM foo WHERE a = b', $qb->getSQL()); + } + public function testAndWhereEmptyStringStartingWithEmptyExpression(): void { $qb = new QueryBuilder($this->conn); @@ -975,6 +988,19 @@ public function testAndWhereEmptyStringStartingWithNonEmptyExpression(): void self::assertSame('SELECT id FROM foo WHERE (a = b) AND (c = d)', $qb->getSQL()); } + public function testWhereExpressionOrWhereEmptyString(): void + { + $qb = new QueryBuilder($this->conn); + + $qb->select('id') + ->from('foo') + ->orWhere('a = b'); + + $qb->orWhere(''); + + self::assertSame('SELECT id FROM foo WHERE a = b', $qb->getSQL()); + } + public function testOrWhereEmptyStringStartingWithEmptyExpression(): void { $qb = new QueryBuilder($this->conn); From b62626bcb8b0a09ecf9572986d45ef025fc47cd0 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sat, 10 Oct 2020 10:53:06 -0700 Subject: [PATCH 18/56] Improve handling argument types in ReservedWordsCommand --- .../Tools/Console/Command/ReservedWordsCommand.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php index 50e6a59343a..1888efdb619 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php @@ -33,6 +33,7 @@ use function assert; use function count; use function implode; +use function is_array; use function is_string; use function trigger_error; @@ -149,7 +150,14 @@ protected function execute(InputInterface $input, OutputInterface $output) { $conn = $this->getConnection($input); - $keywordLists = (array) $input->getOption('list'); + $keywordLists = $input->getOption('list'); + + if (is_string($keywordLists)) { + $keywordLists = [$keywordLists]; + } elseif (! is_array($keywordLists)) { + $keywordLists = []; + } + if (! $keywordLists) { $keywordLists = [ 'mysql', From 1968ff3c0d00f5037d6611021b0bc7396012b78e Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sat, 10 Oct 2020 10:53:23 -0700 Subject: [PATCH 19/56] Get rid of the naming magic in schema manager tests --- .../Schema/Db2SchemaManagerTest.php | 7 +++++++ .../Schema/DrizzleSchemaManagerTest.php | 7 +++++++ .../Schema/MySqlSchemaManagerTest.php | 6 ++++++ .../Schema/OracleSchemaManagerTest.php | 7 +++++++ .../Schema/PostgreSqlSchemaManagerTest.php | 5 +++++ .../Schema/SQLAnywhereSchemaManagerTest.php | 7 +++++++ .../Schema/SQLServerSchemaManagerTest.php | 6 ++++-- .../SchemaManagerFunctionalTestCase.php | 20 ++++++------------- .../Schema/SqliteSchemaManagerTest.php | 7 +++++++ 9 files changed, 56 insertions(+), 16 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/Db2SchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/Db2SchemaManagerTest.php index 9bc1bd1165e..8bc11a776f8 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/Db2SchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/Db2SchemaManagerTest.php @@ -2,11 +2,18 @@ namespace Doctrine\Tests\DBAL\Functional\Schema; +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\DB2Platform; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\BooleanType; class Db2SchemaManagerTest extends SchemaManagerFunctionalTestCase { + protected function supportsPlatform(AbstractPlatform $platform): bool + { + return $platform instanceof DB2Platform; + } + public function testGetBooleanColumn(): void { $table = new Table('boolean_column_test'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/DrizzleSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/DrizzleSchemaManagerTest.php index 0943124b86b..917e42055ff 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/DrizzleSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/DrizzleSchemaManagerTest.php @@ -2,11 +2,18 @@ namespace Doctrine\Tests\DBAL\Functional\Schema; +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\DrizzlePlatform; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\BinaryType; class DrizzleSchemaManagerTest extends SchemaManagerFunctionalTestCase { + protected function supportsPlatform(AbstractPlatform $platform): bool + { + return $platform instanceof DrizzlePlatform; + } + public function testListTableWithBinary(): void { $tableName = 'test_binary_table'; diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php index 90a78487f19..1da8e4dbfaa 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\DBAL\Functional\Schema; use DateTime; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\MariaDb1027Platform; use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Schema\Comparator; @@ -15,6 +16,11 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase { + protected function supportsPlatform(AbstractPlatform $platform): bool + { + return $platform instanceof MySqlPlatform; + } + protected function setUp(): void { parent::setUp(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php index 570ec8ad63e..d39b7373216 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php @@ -2,6 +2,8 @@ namespace Doctrine\Tests\DBAL\Functional\Schema; +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Schema; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\BinaryType; @@ -15,6 +17,11 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase /** @var bool */ private static $privilegesGranted = false; + protected function supportsPlatform(AbstractPlatform $platform): bool + { + return $platform instanceof OraclePlatform; + } + protected function setUp(): void { parent::setUp(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php index cdf3a51245a..aadf78a8b48 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php @@ -25,6 +25,11 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase /** @var PostgreSqlSchemaManager */ protected $schemaManager; + protected function supportsPlatform(AbstractPlatform $platform): bool + { + return $platform instanceof PostgreSQL94Platform; + } + protected function tearDown(): void { parent::tearDown(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php index dbce7bba895..c502a729c1e 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php @@ -2,12 +2,19 @@ namespace Doctrine\Tests\DBAL\Functional\Schema; +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\SQLAnywherePlatform; use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\View; class SQLAnywhereSchemaManagerTest extends SchemaManagerFunctionalTestCase { + protected function supportsPlatform(AbstractPlatform $platform): bool + { + return $platform instanceof SQLAnywherePlatform; + } + public function testCreateAndListViews(): void { $this->createTestTable('view_test_table'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php index 045299367b6..8d6b0bb56fd 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php @@ -2,6 +2,8 @@ namespace Doctrine\Tests\DBAL\Functional\Schema; +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\SQLServer2012Platform; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ColumnDiff; use Doctrine\DBAL\Schema\Table; @@ -12,9 +14,9 @@ class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase { - protected function getPlatformName(): string + protected function supportsPlatform(AbstractPlatform $platform): bool { - return 'mssql'; + return $platform instanceof SQLServer2012Platform; } public function testDropColumnConstraints(): void diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index e34ef79ec1d..8ae88a87738 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\Events; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Schema\AbstractAsset; use Doctrine\DBAL\Schema\AbstractSchemaManager; @@ -38,11 +39,9 @@ use function array_values; use function count; use function current; -use function end; -use function explode; +use function get_class; use function in_array; use function sprintf; -use function str_replace; use function strcasecmp; use function strlen; use function strtolower; @@ -53,23 +52,16 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase /** @var AbstractSchemaManager */ protected $schemaManager; - protected function getPlatformName(): string - { - $class = static::class; - $e = explode('\\', $class); - $testClass = end($e); - - return strtolower(str_replace('SchemaManagerTest', '', $testClass)); - } + abstract protected function supportsPlatform(AbstractPlatform $platform): bool; protected function setUp(): void { parent::setUp(); - $dbms = $this->getPlatformName(); + $platform = $this->connection->getDatabasePlatform(); - if ($this->connection->getDatabasePlatform()->getName() !== $dbms) { - $this->markTestSkipped(static::class . ' requires the use of ' . $dbms); + if (! $this->supportsPlatform($platform)) { + $this->markTestSkipped(sprintf('Skipping since connected to %s', get_class($platform))); } $this->schemaManager = $this->connection->getSchemaManager(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php index d94a8f8dabe..dc46c35a0f3 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php @@ -4,6 +4,8 @@ use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\Exception; +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Schema; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\BlobType; @@ -14,6 +16,11 @@ class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase { + protected function supportsPlatform(AbstractPlatform $platform): bool + { + return $platform instanceof SqlitePlatform; + } + /** * SQLITE does not support databases. */ From 829ec77f8262c07f8fb1e9ca949cb5c319ed679d Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sat, 10 Oct 2020 10:53:27 -0700 Subject: [PATCH 20/56] Improve prepared statement parameter type annotations --- lib/Doctrine/DBAL/Cache/QueryCacheProfile.php | 9 +- lib/Doctrine/DBAL/Connection.php | 146 +++++++++--------- lib/Doctrine/DBAL/Logging/SQLLogger.php | 8 +- lib/Doctrine/DBAL/Query/QueryBuilder.php | 34 ++-- lib/Doctrine/DBAL/SQLParserUtils.php | 8 +- 5 files changed, 105 insertions(+), 100 deletions(-) diff --git a/lib/Doctrine/DBAL/Cache/QueryCacheProfile.php b/lib/Doctrine/DBAL/Cache/QueryCacheProfile.php index b1270846512..3a57358faad 100644 --- a/lib/Doctrine/DBAL/Cache/QueryCacheProfile.php +++ b/lib/Doctrine/DBAL/Cache/QueryCacheProfile.php @@ -3,6 +3,7 @@ namespace Doctrine\DBAL\Cache; use Doctrine\Common\Cache\Cache; +use Doctrine\DBAL\Types\Type; use function hash; use function serialize; @@ -68,10 +69,10 @@ public function getCacheKey() /** * Generates the real cache key from query, params, types and connection parameters. * - * @param string $sql - * @param mixed[] $params - * @param int[]|string[] $types - * @param mixed[] $connectionParams + * @param string $sql + * @param array|array $params + * @param array|array $types + * @param array $connectionParams * * @return string[] */ diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index 5eb4ae23924..871fba156ea 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -543,11 +543,11 @@ public function setFetchMode($fetchMode) * * @deprecated Use fetchAssociative() * - * @param string $sql The query SQL - * @param mixed[] $params The query parameters - * @param int[]|string[] $types The query parameter types + * @param string $sql SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types * - * @return mixed[]|false False is returned if no rows are found. + * @return array|false False is returned if no rows are found. * * @throws Exception */ @@ -562,11 +562,11 @@ public function fetchAssoc($sql, array $params = [], array $types = []) * * @deprecated Use fetchNumeric() * - * @param string $sql The query SQL - * @param mixed[] $params The query parameters - * @param int[]|string[] $types The query parameter types + * @param string $sql SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types * - * @return mixed[]|false False is returned if no rows are found. + * @return array|false False is returned if no rows are found. */ public function fetchArray($sql, array $params = [], array $types = []) { @@ -579,10 +579,10 @@ public function fetchArray($sql, array $params = [], array $types = []) * * @deprecated Use fetchOne() instead. * - * @param string $sql The query SQL - * @param mixed[] $params The query parameters - * @param int $column The 0-indexed column number to retrieve - * @param int[]|string[] $types The query parameter types + * @param string $sql SQL query + * @param array|array $params Query parameters + * @param int $column 0-indexed column number + * @param array|array $types Parameter types * * @return mixed|false False is returned if no rows are found. * @@ -597,9 +597,9 @@ public function fetchColumn($sql, array $params = [], $column = 0, array $types * Prepares and executes an SQL query and returns the first row of the result * as an associative array. * - * @param string $query The SQL query. - * @param array|array $params The prepared statement params. - * @param array|array $types The query parameter types. + * @param string $query SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types * * @return array|false False is returned if no rows are found. * @@ -624,9 +624,9 @@ public function fetchAssociative(string $query, 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 $query The SQL query to be executed. - * @param array|array $params The prepared statement params. - * @param array|array $types The query parameter types. + * @param string $query SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types * * @return array|false False is returned if no rows are found. * @@ -651,9 +651,9 @@ public function fetchNumeric(string $query, 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 $query The SQL query to be executed. - * @param array|array $params The prepared statement params. - * @param array|array $types The query parameter types. + * @param string $query SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types * * @return mixed|false False is returned if no rows are found. * @@ -729,9 +729,9 @@ private function addIdentifierCondition( * * Table expression and columns are not escaped and are not safe for user-input. * - * @param string $table 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. + * @param string $table Table name + * @param array $identifier Deletion criteria + * @param array|array $types Parameter types * * @return int The number of affected rows. * @@ -797,10 +797,10 @@ public function getTransactionIsolation() * * Table expression and columns are not escaped and are not safe for user-input. * - * @param string $table 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. + * @param string $table Table name + * @param array $data Column-value pairs + * @param array $identifier Update criteria + * @param array|array $types Parameter types * * @return int The number of affected rows. * @@ -833,9 +833,9 @@ public function update($table, array $data, array $identifier, array $types = [] * * Table expression and columns are not escaped and are not safe for user-input. * - * @param string $table 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. + * @param string $table Table name + * @param array $data Column-value pairs + * @param array|array $types Parameter types * * @return int The number of affected rows. * @@ -868,10 +868,10 @@ public function insert($table, array $data, array $types = []) /** * Extract ordered type list from an ordered column list and type map. * - * @param int[]|string[] $columnList - * @param int[]|string[] $types + * @param array $columnList + * @param array|array $types * - * @return int[]|string[] + * @return array|array */ private function extractTypeValues(array $columnList, array $types) { @@ -936,9 +936,9 @@ public function fetchAll($sql, array $params = [], $types = []) /** * Prepares and executes an SQL query and returns the result as an array of numeric arrays. * - * @param string $query The SQL query. - * @param array|array $params The query parameters. - * @param array|array $types The query parameter types. + * @param string $query SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types * * @return array> * @@ -962,9 +962,9 @@ public function fetchAllNumeric(string $query, array $params = [], array $types /** * Prepares and executes an SQL query and returns the result as an array of associative arrays. * - * @param string $query The SQL query. - * @param array|array $params The query parameters. - * @param array|array $types The query parameter types. + * @param string $query SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types * * @return array> * @@ -988,9 +988,9 @@ public function fetchAllAssociative(string $query, array $params = [], array $ty /** * Prepares and executes an SQL query and returns the result as an array of the first column values. * - * @param string $query The SQL query. - * @param array|array $params The query parameters. - * @param array|array $types The query parameter types. + * @param string $query SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types * * @return array * @@ -1014,9 +1014,9 @@ public function fetchFirstColumn(string $query, array $params = [], array $types /** * Prepares and executes an SQL query and returns the result as an iterator over rows represented as numeric arrays. * - * @param string $query The SQL query. - * @param array|array $params The query parameters. - * @param array|array $types The query parameter types. + * @param string $query SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types * * @return Traversable> * @@ -1043,9 +1043,9 @@ public function iterateNumeric(string $query, array $params = [], array $types = * Prepares and executes an SQL query and returns the result as an iterator over rows represented * as associative arrays. * - * @param string $query The SQL query. - * @param array|array $params The query parameters. - * @param array|array $types The query parameter types. + * @param string $query SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types * * @return Traversable> * @@ -1071,9 +1071,9 @@ public function iterateAssociative(string $query, array $params = [], array $typ /** * Prepares and executes an SQL query and returns the result as an iterator over the first column values. * - * @param string $query The SQL query. - * @param array|array $params The query parameters. - * @param array|array $types The query parameter types. + * @param string $query SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types * * @return Traversable * @@ -1124,10 +1124,9 @@ public function prepare($sql) * If the query is parametrized, a prepared statement is used. * If an SQLLogger is configured, the execution is logged. * - * @param string $sql The SQL query to execute. - * @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. + * @param string $sql SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types * * @return ResultStatement The executed statement. * @@ -1181,10 +1180,9 @@ public function executeQuery($sql, array $params = [], $types = [], ?QueryCacheP /** * Executes a caching query. * - * @param string $sql The SQL query to execute. - * @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. + * @param string $sql SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types * * @return ResultStatement * @@ -1301,9 +1299,9 @@ public function query() * * @deprecated Use {@link executeStatement()} instead. * - * @param string $sql The SQL query. - * @param array $params The query parameters. - * @param array $types The parameter types. + * @param string $sql SQL statement + * @param array|array $params Statement parameters + * @param array|array $types Parameter types * * @return int The number of affected rows. * @@ -1326,9 +1324,9 @@ public function executeUpdate($sql, array $params = [], array $types = []) * * This method supports PDO binding types as well as DBAL mapping types. * - * @param string $sql The statement SQL - * @param array $params The query parameters - * @param array $types The parameter types + * @param string $sql SQL statement + * @param array|array $params Statement parameters + * @param array|array $types Parameter types * * @return int The number of affected rows. * @@ -1842,9 +1840,9 @@ public function convertToPHPValue($value, $type) * @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 mixed[] $params The map/list of named/positional parameters. - * @param int[]|string[] $types The parameter types (PDO binding types or DBAL mapping types). + * @param \Doctrine\DBAL\Driver\Statement $stmt Prepared statement + * @param array|array $params Statement parameters + * @param array|array $types Parameter types * * @return void */ @@ -1911,10 +1909,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 mixed[] $params - * @param int[]|string[] $types + * @param array|array $params Query parameters + * @param array|array $types Parameter types * - * @return mixed[] + * @return array|array */ public function resolveParams(array $params, array $types) { @@ -2006,8 +2004,8 @@ public function ping() /** * @internal * - * @param array|array $params - * @param array|array $types + * @param array|array $params + * @param array|array $types * * @throws Exception * diff --git a/lib/Doctrine/DBAL/Logging/SQLLogger.php b/lib/Doctrine/DBAL/Logging/SQLLogger.php index 3cb885affa5..8328a71ba5a 100644 --- a/lib/Doctrine/DBAL/Logging/SQLLogger.php +++ b/lib/Doctrine/DBAL/Logging/SQLLogger.php @@ -2,6 +2,8 @@ namespace Doctrine\DBAL\Logging; +use Doctrine\DBAL\Types\Type; + /** * Interface for SQL loggers. */ @@ -10,9 +12,9 @@ interface SQLLogger /** * Logs a SQL statement somewhere. * - * @param string $sql The SQL to be executed. - * @param mixed[]|null $params The SQL parameters. - * @param array $types The SQL parameter types. + * @param string $sql SQL statement + * @param array|array|null $params Statement parameters + * @param array|array|null $types Parameter types * * @return void */ diff --git a/lib/Doctrine/DBAL/Query/QueryBuilder.php b/lib/Doctrine/DBAL/Query/QueryBuilder.php index 1d66b9e63c6..c0c0ea58451 100644 --- a/lib/Doctrine/DBAL/Query/QueryBuilder.php +++ b/lib/Doctrine/DBAL/Query/QueryBuilder.php @@ -7,6 +7,7 @@ use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Query\Expression\CompositeExpression; use Doctrine\DBAL\Query\Expression\ExpressionBuilder; +use Doctrine\DBAL\Types\Type; use function array_filter; use function array_key_exists; @@ -88,14 +89,14 @@ class QueryBuilder /** * The query parameters. * - * @var mixed[] + * @var array|array */ private $params = []; /** * The parameter type map of this query. * - * @var int[]|string[] + * @var array|array */ private $paramTypes = []; @@ -263,9 +264,9 @@ public function getSQL() * ->setParameter(':user_id', 1); * * - * @param string|int $key The parameter position or name. - * @param mixed $value The parameter value. - * @param string|int|null $type One of the {@link ParameterType} constants. + * @param int|string $key Parameter position or name + * @param mixed $value Parameter value + * @param int|string|Type|null $type One of the {@link ParameterType} constants or DBAL type * * @return $this This QueryBuilder instance. */ @@ -294,8 +295,8 @@ public function setParameter($key, $value, $type = null) * )); * * - * @param mixed[] $params The query parameters to set. - * @param int[]|string[] $types The query parameters types to set. + * @param array|array $params Parameters to set + * @param array|array $types Parameter types * * @return $this This QueryBuilder instance. */ @@ -310,7 +311,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 mixed[] The currently defined query parameters indexed by parameter index or name. + * @return array|array The currently defined query parameters */ public function getParameters() { @@ -332,7 +333,8 @@ public function getParameter($key) /** * Gets all defined query parameter types for the query being constructed indexed by parameter index or name. * - * @return int[]|string[] The currently defined query parameter types indexed by parameter index or name. + * @return array|array The currently defined + * query parameter types */ public function getParameterTypes() { @@ -342,9 +344,9 @@ public function getParameterTypes() /** * Gets a (previously set) query parameter type of the query being constructed. * - * @param mixed $key The key (index or name) of the bound parameter type. + * @param int|string $key The key of the bound parameter type * - * @return mixed The value of the bound parameter type. + * @return int|string|Type|null The value of the bound parameter type */ public function getParameterType($key) { @@ -1291,9 +1293,9 @@ public function __toString() * * @link http://www.zetacomponents.org * - * @param mixed $value - * @param mixed $type - * @param string $placeHolder The name to bind with. The string must start with a colon ':'. + * @param mixed $value + * @param int|string|Type|null $type + * @param string $placeHolder The name to bind with. The string must start with a colon ':'. * * @return string the placeholder name used. */ @@ -1326,8 +1328,8 @@ public function createNamedParameter($value, $type = ParameterType::STRING, $pla * ->orWhere('u.username = ' . $qb->createPositionalParameter('Bar', ParameterType::STRING)) * * - * @param mixed $value - * @param int $type + * @param mixed $value + * @param int|string|Type|null $type * * @return string */ diff --git a/lib/Doctrine/DBAL/SQLParserUtils.php b/lib/Doctrine/DBAL/SQLParserUtils.php index 16ed8a812c1..5b558f01343 100644 --- a/lib/Doctrine/DBAL/SQLParserUtils.php +++ b/lib/Doctrine/DBAL/SQLParserUtils.php @@ -2,6 +2,8 @@ namespace Doctrine\DBAL; +use Doctrine\DBAL\Types\Type; + use function array_fill; use function array_fill_keys; use function array_key_exists; @@ -128,9 +130,9 @@ private static function collectPlaceholders( /** * 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 mixed[] $params The parameters to bind to the query. - * @param array $types The types the previous parameters are in. + * @param string $query SQL query + * @param mixed[] $params Query parameters + * @param array|array $types Parameter types * * @return mixed[] * From 89e1f72dd195938adbed8d740e4487ca9051001e Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sat, 10 Oct 2020 11:57:49 -0700 Subject: [PATCH 21/56] Rename $identifier to $criteria --- lib/Doctrine/DBAL/Connection.php | 34 +++++++++---------- .../PrimaryReadReplicaConnection.php | 8 ++--- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index 871fba156ea..cd5f6e4da7e 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -695,24 +695,24 @@ public function isTransactionActive() } /** - * Adds identifier condition to the query components + * Adds condition based on the criteria to the query components * - * @param mixed[] $identifier Map of key columns to their values + * @param mixed[] $criteria Map of key columns to their values * @param string[] $columns Column names * @param mixed[] $values Column values * @param string[] $conditions Key conditions * * @throws Exception */ - private function addIdentifierCondition( - array $identifier, + private function addCriteriaCondition( + array $criteria, array &$columns, array &$values, array &$conditions ): void { $platform = $this->getDatabasePlatform(); - foreach ($identifier as $columnName => $value) { + foreach ($criteria as $columnName => $value) { if ($value === null) { $conditions[] = $platform->getIsNullExpression($columnName); continue; @@ -729,23 +729,23 @@ private function addIdentifierCondition( * * Table expression and columns are not escaped and are not safe for user-input. * - * @param string $table Table name - * @param array $identifier Deletion criteria - * @param array|array $types Parameter types + * @param string $table Table name + * @param array $criteria Deletion criteria + * @param array|array $types Parameter types * * @return int The number of affected rows. * * @throws Exception */ - public function delete($table, array $identifier, array $types = []) + public function delete($table, array $criteria, array $types = []) { - if (empty($identifier)) { + if (empty($criteria)) { throw InvalidArgumentException::fromEmptyCriteria(); } $columns = $values = $conditions = []; - $this->addIdentifierCondition($identifier, $columns, $values, $conditions); + $this->addCriteriaCondition($criteria, $columns, $values, $conditions); return $this->executeStatement( 'DELETE FROM ' . $table . ' WHERE ' . implode(' AND ', $conditions), @@ -797,16 +797,16 @@ public function getTransactionIsolation() * * Table expression and columns are not escaped and are not safe for user-input. * - * @param string $table Table name - * @param array $data Column-value pairs - * @param array $identifier Update criteria - * @param array|array $types Parameter types + * @param string $table Table name + * @param array $data Column-value pairs + * @param array $criteria Update criteria + * @param array|array $types Parameter types * * @return int The number of affected rows. * * @throws Exception */ - public function update($table, array $data, array $identifier, array $types = []) + public function update($table, array $data, array $criteria, array $types = []) { $columns = $values = $conditions = $set = []; @@ -816,7 +816,7 @@ public function update($table, array $data, array $identifier, array $types = [] $set[] = $columnName . ' = ?'; } - $this->addIdentifierCondition($identifier, $columns, $values, $conditions); + $this->addCriteriaCondition($criteria, $columns, $values, $conditions); if (is_string(key($types))) { $types = $this->extractTypeValues($columns, $types); diff --git a/lib/Doctrine/DBAL/Connections/PrimaryReadReplicaConnection.php b/lib/Doctrine/DBAL/Connections/PrimaryReadReplicaConnection.php index 78cb755d805..81f4accfd22 100644 --- a/lib/Doctrine/DBAL/Connections/PrimaryReadReplicaConnection.php +++ b/lib/Doctrine/DBAL/Connections/PrimaryReadReplicaConnection.php @@ -317,11 +317,11 @@ public function rollBack() /** * {@inheritDoc} */ - public function delete($table, array $identifier, array $types = []) + public function delete($table, array $criteria, array $types = []) { $this->ensureConnectedToPrimary(); - return parent::delete($table, $identifier, $types); + return parent::delete($table, $criteria, $types); } /** @@ -340,11 +340,11 @@ public function close() /** * {@inheritDoc} */ - public function update($table, array $data, array $identifier, array $types = []) + public function update($table, array $data, array $criteria, array $types = []) { $this->ensureConnectedToPrimary(); - return parent::update($table, $data, $identifier, $types); + return parent::update($table, $data, $criteria, $types); } /** From f1a901efbbac5ac6a4749e1fe85634cfe68deb48 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 23 Sep 2020 18:00:36 -0700 Subject: [PATCH 22/56] Add Statement::fetchAllKeyValue() and ::iterateKeyValue() --- .../data-retrieval-and-manipulation.rst | 34 ++++++++ lib/Doctrine/DBAL/Connection.php | 60 ++++++++++++++ lib/Doctrine/DBAL/Exception/NoKeyValue.php | 25 ++++++ lib/Doctrine/DBAL/Statement.php | 51 ++++++++++++ .../DBAL/Functional/Connection/FetchTest.php | 79 +++++++++++++++++++ 5 files changed, 249 insertions(+) create mode 100644 lib/Doctrine/DBAL/Exception/NoKeyValue.php diff --git a/docs/en/reference/data-retrieval-and-manipulation.rst b/docs/en/reference/data-retrieval-and-manipulation.rst index 8a88deb6a64..0efba4c466c 100644 --- a/docs/en/reference/data-retrieval-and-manipulation.rst +++ b/docs/en/reference/data-retrieval-and-manipulation.rst @@ -379,6 +379,25 @@ Execute the query and fetch all results into an array: ) */ +fetchAllKeyValue() +~~~~~~~~~~~~~~~~~~ + +Execute the query and fetch the first two columns into an associative array as keys and values respectively: + +.. code-block:: php + + fetchAllKeyValue('SELECT username, password FROM user'); + + /* + array( + 'jwage' => 'changeme', + ) + */ + +.. note:: + All additional columns will be ignored and are only allowed to be selected by DBAL for its internal purposes. + fetchNumeric() ~~~~~~~~~~~~~~ @@ -425,6 +444,21 @@ Retrieve associative array of the first result row. There are also convenience methods for data manipulation queries: +iterateKeyValue() +~~~~~~~~~~~~~~~~~ + +Execute the query and iterate over the first two columns as keys and values respectively: + +.. code-block:: php + + iterateKeyValue('SELECT username, password FROM user') as $username => $password) { + // ... + } + +.. note:: + All additional columns will be ignored and are only allowed to be selected by DBAL for its internal purposes. + delete() ~~~~~~~~~ diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index cd5f6e4da7e..1d9477431f9 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -15,6 +15,7 @@ use Doctrine\DBAL\Driver\ServerInfoAwareConnection; use Doctrine\DBAL\Exception\ConnectionLost; use Doctrine\DBAL\Exception\InvalidArgumentException; +use Doctrine\DBAL\Exception\NoKeyValue; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Query\Expression\ExpressionBuilder; use Doctrine\DBAL\Query\QueryBuilder; @@ -985,6 +986,33 @@ public function fetchAllAssociative(string $query, array $params = [], array $ty } } + /** + * Prepares and executes an SQL query and returns the result as an associative array with the keys + * mapped to the first column and the values mapped to the second column. + * + * @param string $query The SQL query. + * @param array|array $params The query parameters. + * @param array|array $types The query parameter types. + * + * @return array + * + * @throws Exception + */ + public function fetchAllKeyValue(string $query, array $params = [], array $types = []): array + { + $stmt = $this->executeQuery($query, $params, $types); + + $this->ensureHasKeyValue($stmt); + + $data = []; + + foreach ($stmt->fetchAll(FetchMode::NUMERIC) as [$key, $value]) { + $data[$key] = $value; + } + + return $data; + } + /** * Prepares and executes an SQL query and returns the result as an array of the first column values. * @@ -1068,6 +1096,29 @@ public function iterateAssociative(string $query, array $params = [], array $typ } } + /** + * Prepares and executes an SQL query and returns the result as an iterator with the keys + * mapped to the first column and the values mapped to the second column. + * + * @param string $query The SQL query. + * @param array|array $params The query parameters. + * @param array|array $types The query parameter types. + * + * @return Traversable + * + * @throws Exception + */ + public function iterateKeyValue(string $query, array $params = [], array $types = []): Traversable + { + $stmt = $this->executeQuery($query, $params, $types); + + $this->ensureHasKeyValue($stmt); + + while (($row = $stmt->fetch(FetchMode::NUMERIC)) !== false) { + yield $row[0] => $row[1]; + } + } + /** * Prepares and executes an SQL query and returns the result as an iterator over the first column values. * @@ -2055,4 +2106,13 @@ private function throw(Exception $e): void throw $e; } + + private function ensureHasKeyValue(ResultStatement $stmt): void + { + $columnCount = $stmt->columnCount(); + + if ($columnCount < 2) { + throw NoKeyValue::fromColumnCount($columnCount); + } + } } diff --git a/lib/Doctrine/DBAL/Exception/NoKeyValue.php b/lib/Doctrine/DBAL/Exception/NoKeyValue.php new file mode 100644 index 00000000000..34093704aa1 --- /dev/null +++ b/lib/Doctrine/DBAL/Exception/NoKeyValue.php @@ -0,0 +1,25 @@ + + * + * @throws Exception + */ + public function fetchAllKeyValue(): array + { + $this->ensureHasKeyValue(); + + $data = []; + + foreach ($this->fetchAllNumeric() as [$key, $value]) { + $data[$key] = $value; + } + + return $data; + } + /** * {@inheritdoc} * @@ -441,6 +464,25 @@ public function iterateAssociative(): Traversable } } + /** + * Returns an iterator over the result set with the keys mapped to the first column + * and the values mapped to the second column. + * + * The result must contain at least two columns. + * + * @return Traversable + * + * @throws Exception + */ + public function iterateKeyValue(): Traversable + { + $this->ensureHasKeyValue(); + + foreach ($this->iterateNumeric() as [$key, $value]) { + yield $key => $value; + } + } + /** * {@inheritDoc} * @@ -495,4 +537,13 @@ public function getWrappedStatement() { return $this->stmt; } + + private function ensureHasKeyValue(): void + { + $columnCount = $this->columnCount(); + + if ($columnCount < 2) { + throw NoKeyValue::fromColumnCount($columnCount); + } + } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Connection/FetchTest.php b/tests/Doctrine/Tests/DBAL/Functional/Connection/FetchTest.php index d33fc1708e9..49854b3e121 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Connection/FetchTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Connection/FetchTest.php @@ -2,6 +2,8 @@ namespace Doctrine\Tests\DBAL\Functional\Connection; +use Doctrine\DBAL\Exception\NoKeyValue; +use Doctrine\DBAL\Platforms\SQLServer2012Platform; use Doctrine\Tests\DbalFunctionalTestCase; use Doctrine\Tests\TestUtil; @@ -77,6 +79,53 @@ public function testFetchAllAssociative(): void ], $this->connection->fetchAllAssociative($this->query)); } + public function testFetchAllKeyValue(): void + { + self::assertEquals([ + 'foo' => 1, + 'bar' => 2, + 'baz' => 3, + ], $this->connection->fetchAllKeyValue($this->query)); + } + + public function testStatementFetchAllKeyValue(): void + { + $stmt = $this->connection->prepare($this->query); + $stmt->execute(); + + self::assertEquals([ + 'foo' => 1, + 'bar' => 2, + 'baz' => 3, + ], $stmt->fetchAllKeyValue()); + } + + /** + * This test covers the requirement for the statement result to have at least two columns, + * not exactly two as PDO requires. + */ + public function testFetchAllKeyValueWithLimit(): void + { + $platform = $this->connection->getDatabasePlatform(); + + if ($platform instanceof SQLServer2012Platform) { + self::markTestSkipped('See https://github.com/doctrine/dbal/issues/2374'); + } + + $query = $platform->modifyLimitQuery($this->query, 1, 1); + + self::assertEquals(['bar' => 2], $this->connection->fetchAllKeyValue($query)); + } + + public function testFetchAllKeyValueOneColumn(): void + { + $sql = $this->connection->getDatabasePlatform() + ->getDummySelectSQL(); + + $this->expectException(NoKeyValue::class); + $this->connection->fetchAllKeyValue($sql); + } + public function testFetchFirstColumn(): void { self::assertEquals([ @@ -113,6 +162,36 @@ public function testIterateAssociative(): void ], iterator_to_array($this->connection->iterateAssociative($this->query))); } + public function testIterateKeyValue(): void + { + self::assertEquals([ + 'foo' => 1, + 'bar' => 2, + 'baz' => 3, + ], iterator_to_array($this->connection->iterateKeyValue($this->query))); + } + + public function testStatementKeyValue(): void + { + $stmt = $this->connection->prepare($this->query); + $stmt->execute(); + + self::assertEquals([ + 'foo' => 1, + 'bar' => 2, + 'baz' => 3, + ], iterator_to_array($stmt->iterateKeyValue())); + } + + public function testIterateKeyValueOneColumn(): void + { + $sql = $this->connection->getDatabasePlatform() + ->getDummySelectSQL(); + + $this->expectException(NoKeyValue::class); + iterator_to_array($this->connection->iterateKeyValue($sql)); + } + public function testIterateColumn(): void { self::assertEquals([ From 787a12de949325c3aeca2bc92365b09c4c63c70a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Tue, 13 Oct 2020 13:26:54 +0200 Subject: [PATCH 23/56] Use latest version of the cache action This must have been forgotten in a previous commit I made about this. --- .github/workflows/continuous-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 696fb85d18c..c9d458a61e7 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -25,7 +25,7 @@ jobs: tools: "cs2pr" - name: "Cache dependencies installed with composer" - uses: "actions/cache@v1" + uses: "actions/cache@v2" with: path: "~/.composer/cache" key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}" From 95ef20fa93d6c1b54aecc5ec26859f44921e89b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Tue, 13 Oct 2020 13:28:10 +0200 Subject: [PATCH 24/56] Pin Ubuntu version Using moving aliases has proven troublesome in the past. --- .github/workflows/continuous-integration.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index c9d458a61e7..07abf4152cc 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -6,7 +6,7 @@ on: ["pull_request", "push"] jobs: static-analysis-phpstan: name: "Static Analysis with PHPStan" - runs-on: "ubuntu-latest" + runs-on: "ubuntu-20.04" strategy: matrix: @@ -39,7 +39,7 @@ jobs: static-analysis-psalm: name: "Static Analysis with Psalm" - runs-on: "ubuntu-latest" + runs-on: "ubuntu-20.04" strategy: matrix: @@ -71,7 +71,7 @@ jobs: phpunit-oci8: name: "PHPUnit on OCI8" - runs-on: "ubuntu-latest" + runs-on: "ubuntu-20.04" strategy: matrix: @@ -115,7 +115,7 @@ jobs: phpunit-pdo-oci: name: "PHPUnit on PDO_OCI" - runs-on: "ubuntu-latest" + runs-on: "ubuntu-20.04" strategy: matrix: From 85a3fdcec9333d97d89c473e65c8f2dea2715390 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Wed, 14 Oct 2020 19:23:32 +0200 Subject: [PATCH 25/56] Restrict workflows to protected branches When we push to a branch on origin and make a PR, we see double the normal amount of jobs because of this. --- .github/workflows/coding-standards.yml | 10 +++++++++- .github/workflows/continuous-integration.yml | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index 4e660b208bd..4d42ad000e5 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -1,6 +1,14 @@ name: "Coding Standards" -on: ["pull_request", "push"] +on: + pull_request: + branches: + - "*.x" + - "master" + push: + branches: + - "*.x" + - "master" jobs: coding-standards: diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 07abf4152cc..4b01648afe4 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -1,7 +1,15 @@ name: "Continuous Integration" -on: ["pull_request", "push"] +on: + pull_request: + branches: + - "*.x" + - "master" + push: + branches: + - "*.x" + - "master" jobs: static-analysis-phpstan: From 30218eeef3474bdfd222d688d5811912086c9e97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Wed, 14 Oct 2020 19:25:14 +0200 Subject: [PATCH 26/56] Use cache action v2 I somehow missed another occurrence. --- .github/workflows/continuous-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 4b01648afe4..e51c70279e9 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -150,7 +150,7 @@ jobs: coverage: "pcov" - name: "Cache dependencies installed with composer" - uses: "actions/cache@v1" + uses: "actions/cache@v2" with: path: "~/.composer/cache" key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}" From 9033b958557c2e6909a6c2900d622da654bc002a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Wed, 14 Oct 2020 19:26:18 +0200 Subject: [PATCH 27/56] Extract SA jobs to a separate workflow The end goal is to have a generic workflow that can be contributed back to our .github repository. --- .github/workflows/continuous-integration.yml | 65 ---------------- .github/workflows/static-analysis.yml | 78 ++++++++++++++++++++ 2 files changed, 78 insertions(+), 65 deletions(-) create mode 100644 .github/workflows/static-analysis.yml diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index e51c70279e9..13fc8597b08 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -12,71 +12,6 @@ on: - "master" jobs: - static-analysis-phpstan: - name: "Static Analysis with PHPStan" - runs-on: "ubuntu-20.04" - - strategy: - matrix: - php-version: - - "7.4" - - steps: - - name: "Checkout code" - uses: "actions/checkout@v2" - - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" - with: - coverage: "none" - php-version: "${{ matrix.php-version }}" - tools: "cs2pr" - - - name: "Cache dependencies installed with composer" - uses: "actions/cache@v2" - with: - path: "~/.composer/cache" - key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}" - restore-keys: "php-${{ matrix.php-version }}-composer-locked-" - - - name: "Install dependencies with composer" - run: "composer install --no-interaction --no-progress --no-suggest" - - - name: "Run a static analysis with phpstan/phpstan" - run: "vendor/bin/phpstan analyse --error-format=checkstyle | cs2pr" - - static-analysis-psalm: - name: "Static Analysis with Psalm" - runs-on: "ubuntu-20.04" - - strategy: - matrix: - php-version: - - "7.4" - - steps: - - name: "Checkout code" - uses: "actions/checkout@v2" - - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" - with: - coverage: "none" - php-version: "${{ matrix.php-version }}" - - - name: "Cache dependencies installed with composer" - uses: "actions/cache@v2" - with: - path: "~/.composer/cache" - key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}" - restore-keys: "php-${{ matrix.php-version }}-composer-locked-" - - - name: "Install dependencies with composer" - run: "composer install --no-interaction --no-progress --no-suggest" - - - name: "Run a static analysis with vimeo/psalm" - run: "vendor/bin/psalm --show-info=false --stats --output-format=github --threads=4" - phpunit-oci8: name: "PHPUnit on OCI8" runs-on: "ubuntu-20.04" diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml new file mode 100644 index 00000000000..686eddd6061 --- /dev/null +++ b/.github/workflows/static-analysis.yml @@ -0,0 +1,78 @@ + +name: "Static Analysis" + +on: + pull_request: + branches: + - "*.x" + - "master" + push: + branches: + - "*.x" + - "master" + +jobs: + static-analysis-phpstan: + name: "Static Analysis with PHPStan" + runs-on: "ubuntu-20.04" + + strategy: + matrix: + php-version: + - "7.4" + + steps: + - name: "Checkout code" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{ matrix.php-version }}" + tools: "cs2pr" + + - name: "Cache dependencies installed with composer" + uses: "actions/cache@v2" + with: + path: "~/.composer/cache" + key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}" + restore-keys: "php-${{ matrix.php-version }}-composer-locked-" + + - name: "Install dependencies with composer" + run: "composer install --no-interaction --no-progress --no-suggest" + + - name: "Run a static analysis with phpstan/phpstan" + run: "vendor/bin/phpstan analyse --error-format=checkstyle | cs2pr" + + static-analysis-psalm: + name: "Static Analysis with Psalm" + runs-on: "ubuntu-20.04" + + strategy: + matrix: + php-version: + - "7.4" + + steps: + - name: "Checkout code" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{ matrix.php-version }}" + + - name: "Cache dependencies installed with composer" + uses: "actions/cache@v2" + with: + path: "~/.composer/cache" + key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}" + restore-keys: "php-${{ matrix.php-version }}-composer-locked-" + + - name: "Install dependencies with composer" + run: "composer install --no-interaction --no-progress --no-suggest" + + - name: "Run a static analysis with vimeo/psalm" + run: "vendor/bin/psalm --show-info=false --stats --output-format=github --threads=4" From 78850f4ae4b6b868d685fc3c82989ef27726144b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Wed, 14 Oct 2020 19:27:55 +0200 Subject: [PATCH 28/56] Use official Github Action It is more concise. --- .github/workflows/static-analysis.yml | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 686eddd6061..777c82f0ea8 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -55,24 +55,8 @@ jobs: - "7.4" steps: - - name: "Checkout code" - uses: "actions/checkout@v2" - - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" - with: - coverage: "none" - php-version: "${{ matrix.php-version }}" - - - name: "Cache dependencies installed with composer" - uses: "actions/cache@v2" - with: - path: "~/.composer/cache" - key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}" - restore-keys: "php-${{ matrix.php-version }}-composer-locked-" - - - name: "Install dependencies with composer" - run: "composer install --no-interaction --no-progress --no-suggest" + - name: Checkout code + uses: actions/checkout@v2 - - name: "Run a static analysis with vimeo/psalm" - run: "vendor/bin/psalm --show-info=false --stats --output-format=github --threads=4" + - name: Psalm + uses: docker://vimeo/psalm-github-actions From 6ef95b639635434a877e0e4d89299e60bb479da7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Wed, 14 Oct 2020 19:57:29 +0200 Subject: [PATCH 29/56] Minot CS improvement - use ::class for TestCase::expectException input --- .../DBAL/Platforms/AbstractPlatformTestCase.php | 3 ++- .../DBAL/Platforms/SQLAnywhere16PlatformTest.php | 3 ++- .../DBAL/Sharding/PoolingShardConnectionTest.php | 15 ++++++++------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php index aa51cd1e836..9ef99d6d416 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php @@ -17,6 +17,7 @@ use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DbalTestCase; use Doctrine\Tests\Types\CommentedType; +use InvalidArgumentException; use function get_class; use function implode; @@ -84,7 +85,7 @@ public static function getReturnsForeignKeyReferentialActionSQL(): iterable public function testGetInvalidForeignKeyReferentialActionSQL(): void { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $this->platform->getForeignKeyReferentialActionSQL('unknown'); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere16PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere16PlatformTest.php index e0c4a24a21a..85ae95c4cc8 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere16PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere16PlatformTest.php @@ -5,6 +5,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\SQLAnywhere16Platform; use Doctrine\DBAL\Schema\Index; +use UnexpectedValueException; class SQLAnywhere16PlatformTest extends SQLAnywhere12PlatformTest { @@ -64,7 +65,7 @@ public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL(): void public function testThrowsExceptionOnInvalidWithNullsNotDistinctIndexOptions(): void { - $this->expectException('UnexpectedValueException'); + $this->expectException(UnexpectedValueException::class); $this->platform->getCreateIndexSQL( new Index( diff --git a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php index 1f0abe675f8..f1244541a50 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Sharding\PoolingShardConnection; use Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser; use Doctrine\DBAL\Sharding\ShardingException; +use InvalidArgumentException; use PHPUnit\Framework\TestCase; use stdClass; @@ -50,7 +51,7 @@ public function testConnect(): void public function testNoGlobalServerException(): void { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage("Connection Parameters require 'global' and 'shards' configurations."); DriverManager::getConnection([ @@ -66,7 +67,7 @@ public function testNoGlobalServerException(): void public function testNoShardsServersException(): void { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage("Connection Parameters require 'global' and 'shards' configurations."); DriverManager::getConnection([ @@ -79,7 +80,7 @@ public function testNoShardsServersException(): void public function testNoShardsChoserException(): void { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage("Missing Shard Choser configuration 'shardChoser'"); DriverManager::getConnection([ @@ -95,7 +96,7 @@ public function testNoShardsChoserException(): void public function testShardChoserWrongInstance(): void { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage( "The 'shardChoser' configuration is not a valid instance of Doctrine\DBAL\Sharding\ShardChoser\ShardChoser" ); @@ -114,7 +115,7 @@ public function testShardChoserWrongInstance(): void public function testShardNonNumericId(): void { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Shard Id has to be a non-negative number.'); DriverManager::getConnection([ @@ -130,7 +131,7 @@ public function testShardNonNumericId(): void public function testShardMissingId(): void { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage("Missing 'id' for one configured shard. Please specify a unique shard-id."); DriverManager::getConnection([ @@ -146,7 +147,7 @@ public function testShardMissingId(): void public function testDuplicateShardId(): void { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Shard 1 is duplicated in the configuration.'); DriverManager::getConnection([ From 99f9c7e4179065d742cbf35ed4a3685a20aba642 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Tue, 13 Oct 2020 18:01:36 -0700 Subject: [PATCH 30/56] Add Statement::fetchAllIndexedAssociative() and ::iterateIndexedAssociative() --- .../data-retrieval-and-manipulation.rst | 33 ++++++++++ lib/Doctrine/DBAL/Connection.php | 61 +++++++++++++++++-- lib/Doctrine/DBAL/Statement.php | 35 +++++++++++ .../DBAL/Functional/Connection/FetchTest.php | 44 ++++++++++++- 4 files changed, 166 insertions(+), 7 deletions(-) diff --git a/docs/en/reference/data-retrieval-and-manipulation.rst b/docs/en/reference/data-retrieval-and-manipulation.rst index 0efba4c466c..7e85e3c3a82 100644 --- a/docs/en/reference/data-retrieval-and-manipulation.rst +++ b/docs/en/reference/data-retrieval-and-manipulation.rst @@ -398,6 +398,26 @@ Execute the query and fetch the first two columns into an associative array as k .. note:: All additional columns will be ignored and are only allowed to be selected by DBAL for its internal purposes. +fetchAllAssociativeIndexed() +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Execute the query and fetch the data as an associative array where the key represents the first column and the value is +an associative array of the rest of the columns and their values: + +.. code-block:: php + + fetchAllAssociativeIndexed('SELECT id, username, password FROM user'); + + /* + array( + 1 => array( + 'username' => 'jwage', + 'password' => 'changeme', + ) + ) + */ + fetchNumeric() ~~~~~~~~~~~~~~ @@ -459,6 +479,19 @@ Execute the query and iterate over the first two columns as keys and values resp .. note:: All additional columns will be ignored and are only allowed to be selected by DBAL for its internal purposes. +iterateAssociativeIndexed() +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Execute the query and iterate over the result with the key representing the first column and the value being +an associative array of the rest of the columns and their values: + +.. code-block:: php + + iterateAssociativeIndexed('SELECT id, username, password FROM user') as $id => $data) { + // ... + } + delete() ~~~~~~~~~ diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index 1d9477431f9..2d5d4402bb8 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -25,6 +25,7 @@ use Traversable; use function array_key_exists; +use function array_shift; use function assert; use function func_get_args; use function implode; @@ -990,9 +991,9 @@ public function fetchAllAssociative(string $query, array $params = [], array $ty * Prepares and executes an SQL query and returns the result as an associative array with the keys * mapped to the first column and the values mapped to the second column. * - * @param string $query The SQL query. - * @param array|array $params The query parameters. - * @param array|array $types The query parameter types. + * @param string $query SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types * * @return array * @@ -1013,6 +1014,32 @@ public function fetchAllKeyValue(string $query, array $params = [], array $types return $data; } + /** + * Prepares and executes an SQL query and returns the result as an associative array with the keys mapped + * to the first column and the values being an associative array representing the rest of the columns + * and their values. + * + * @param string $query SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types + * + * @return array> + * + * @throws Exception + */ + public function fetchAllAssociativeIndexed(string $query, array $params = [], array $types = []): array + { + $stmt = $this->executeQuery($query, $params, $types); + + $data = []; + + foreach ($stmt->fetchAll(FetchMode::ASSOCIATIVE) as $row) { + $data[array_shift($row)] = $row; + } + + return $data; + } + /** * Prepares and executes an SQL query and returns the result as an array of the first column values. * @@ -1100,9 +1127,9 @@ public function iterateAssociative(string $query, array $params = [], array $typ * Prepares and executes an SQL query and returns the result as an iterator with the keys * mapped to the first column and the values mapped to the second column. * - * @param string $query The SQL query. - * @param array|array $params The query parameters. - * @param array|array $types The query parameter types. + * @param string $query SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types * * @return Traversable * @@ -1119,6 +1146,28 @@ public function iterateKeyValue(string $query, array $params = [], array $types } } + /** + * Prepares and executes an SQL query and returns the result as an iterator with the keys mapped + * to the first column and the values being an associative array representing the rest of the columns + * and their values. + * + * @param string $query SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types + * + * @return Traversable> + * + * @throws Exception + */ + public function iterateAssociativeIndexed(string $query, array $params = [], array $types = []): Traversable + { + $stmt = $this->executeQuery($query, $params, $types); + + while (($row = $stmt->fetch(FetchMode::ASSOCIATIVE)) !== false) { + yield array_shift($row) => $row; + } + } + /** * Prepares and executes an SQL query and returns the result as an iterator over the first column values. * diff --git a/lib/Doctrine/DBAL/Statement.php b/lib/Doctrine/DBAL/Statement.php index ff27cd13aca..ad5d29b9a5d 100644 --- a/lib/Doctrine/DBAL/Statement.php +++ b/lib/Doctrine/DBAL/Statement.php @@ -13,6 +13,7 @@ use Throwable; use Traversable; +use function array_shift; use function is_array; use function is_string; @@ -398,6 +399,25 @@ public function fetchAllKeyValue(): array return $data; } + /** + * Returns an associative array with the keys mapped to the first column and the values being + * an associative array representing the rest of the columns and their values. + * + * @return array> + * + * @throws Exception + */ + public function fetchAllAssociativeIndexed(): array + { + $data = []; + + foreach ($this->fetchAll(FetchMode::ASSOCIATIVE) as $row) { + $data[array_shift($row)] = $row; + } + + return $data; + } + /** * {@inheritdoc} * @@ -483,6 +503,21 @@ public function iterateKeyValue(): Traversable } } + /** + * Returns an iterator over the result set with the keys mapped to the first column and the values being + * an associative array representing the rest of the columns and their values. + * + * @return Traversable> + * + * @throws Exception + */ + public function iterateAssociativeIndexed(): Traversable + { + while (($row = $this->stmt->fetch(FetchMode::ASSOCIATIVE)) !== false) { + yield array_shift($row) => $row; + } + } + /** * {@inheritDoc} * diff --git a/tests/Doctrine/Tests/DBAL/Functional/Connection/FetchTest.php b/tests/Doctrine/Tests/DBAL/Functional/Connection/FetchTest.php index 49854b3e121..e5f4d2472dd 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Connection/FetchTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Connection/FetchTest.php @@ -126,6 +126,27 @@ public function testFetchAllKeyValueOneColumn(): void $this->connection->fetchAllKeyValue($sql); } + public function testFetchAllAssociativeIndexed(): void + { + self::assertEquals([ + 'foo' => ['b' => 1], + 'bar' => ['b' => 2], + 'baz' => ['b' => 3], + ], $this->connection->fetchAllAssociativeIndexed($this->query)); + } + + public function testStatementFetchAllAssociativeIndexed(): void + { + $stmt = $this->connection->prepare($this->query); + $stmt->execute(); + + self::assertEquals([ + 'foo' => ['b' => 1], + 'bar' => ['b' => 2], + 'baz' => ['b' => 3], + ], $stmt->fetchAllAssociativeIndexed()); + } + public function testFetchFirstColumn(): void { self::assertEquals([ @@ -171,7 +192,7 @@ public function testIterateKeyValue(): void ], iterator_to_array($this->connection->iterateKeyValue($this->query))); } - public function testStatementKeyValue(): void + public function testStatementIterateKeyValue(): void { $stmt = $this->connection->prepare($this->query); $stmt->execute(); @@ -192,6 +213,27 @@ public function testIterateKeyValueOneColumn(): void iterator_to_array($this->connection->iterateKeyValue($sql)); } + public function testIterateAssociativeIndexed(): void + { + self::assertEquals([ + 'foo' => ['b' => 1], + 'bar' => ['b' => 2], + 'baz' => ['b' => 3], + ], iterator_to_array($this->connection->iterateAssociativeIndexed($this->query))); + } + + public function testStatementIterateAssociativeIndexed(): void + { + $stmt = $this->connection->prepare($this->query); + $stmt->execute(); + + self::assertEquals([ + 'foo' => ['b' => 1], + 'bar' => ['b' => 2], + 'baz' => ['b' => 3], + ], iterator_to_array($stmt->iterateAssociativeIndexed())); + } + public function testIterateColumn(): void { self::assertEquals([ From 5bf8e74f4a079688a455d537e12f34db67c32e61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Mon, 28 Sep 2020 14:31:24 +0200 Subject: [PATCH 31/56] Migrate jobs away from Travis to Github Actions It should be faster, and will result in one fewer CI platform to maintain. --- .github/workflows/continuous-integration.yml | 497 +++++++++++++++++- .travis.yml | 191 ------- .../github/ext/install-ibm_db2.sh | 9 +- .../github/phpunit/ibm_db2.xml | 4 +- .../github/phpunit/mysqli-tls.xml | 6 +- .../github/phpunit/mysqli.xml | 6 +- .../{phpunit.oci8.xml => phpunit/oci8.xml} | 4 +- .../github/phpunit/pdo_mysql.xml | 6 +- .../pdo_oci.xml} | 4 +- .../github/phpunit/pdo_pgsql.xml | 5 +- .../github/phpunit/pdo_sqlsrv.xml | 4 +- .../github/phpunit/sqlite.xml | 4 +- .../github/phpunit/sqlsrv.xml | 4 +- tests/travis/docker-run-mysql-or-mariadb.sh | 50 -- tests/travis/install-db2.sh | 23 - tests/travis/install-mssql-pdo_sqlsrv.sh | 7 - tests/travis/install-mssql-sqlsrv.sh | 7 - tests/travis/install-mssql.sh | 19 - tests/travis/install-postgres-10.sh | 13 - tests/travis/install-postgres-11.sh | 12 - tests/travis/install-sqlsrv-dependencies.sh | 10 - tests/travis/mariadb.docker.travis.xml | 29 - tests/travis/mariadb.mysqli.docker.travis.xml | 29 - 23 files changed, 520 insertions(+), 423 deletions(-) delete mode 100644 .travis.yml rename tests/travis/install-db2-ibm_db2.sh => ci/github/ext/install-ibm_db2.sh (67%) mode change 100644 => 100755 rename tests/travis/ibm_db2.travis.xml => ci/github/phpunit/ibm_db2.xml (86%) rename tests/travis/mysqli-tls.docker.travis.xml => ci/github/phpunit/mysqli-tls.xml (87%) rename tests/travis/mysqli.docker.travis.xml => ci/github/phpunit/mysqli.xml (81%) rename ci/github/{phpunit.oci8.xml => phpunit/oci8.xml} (90%) rename tests/travis/mysql.docker.travis.xml => ci/github/phpunit/pdo_mysql.xml (81%) rename ci/github/{phpunit.pdo-oci.xml => phpunit/pdo_oci.xml} (90%) rename tests/travis/pgsql.travis.xml => ci/github/phpunit/pdo_pgsql.xml (81%) rename tests/travis/pdo_sqlsrv.travis.xml => ci/github/phpunit/pdo_sqlsrv.xml (86%) rename tests/travis/sqlite.travis.xml => ci/github/phpunit/sqlite.xml (81%) rename tests/travis/sqlsrv.travis.xml => ci/github/phpunit/sqlsrv.xml (86%) delete mode 100644 tests/travis/docker-run-mysql-or-mariadb.sh delete mode 100644 tests/travis/install-db2.sh delete mode 100644 tests/travis/install-mssql-pdo_sqlsrv.sh delete mode 100644 tests/travis/install-mssql-sqlsrv.sh delete mode 100644 tests/travis/install-mssql.sh delete mode 100644 tests/travis/install-postgres-10.sh delete mode 100644 tests/travis/install-postgres-11.sh delete mode 100644 tests/travis/install-sqlsrv-dependencies.sh delete mode 100644 tests/travis/mariadb.docker.travis.xml delete mode 100644 tests/travis/mariadb.mysqli.docker.travis.xml diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 13fc8597b08..56725b50e3b 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -10,11 +10,66 @@ on: branches: - "*.x" - "master" + schedule: + - cron: "42 3 * * *" jobs: + phpunit-smoke-check: + name: "PHPUnit with SQLite" + runs-on: "ubuntu-20.04" + + strategy: + matrix: + php-version: + - "7.3" + - "7.4" + deps: + - "fixed" + include: + - deps: "low" + php-version: "7.3" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + with: + fetch-depth: 2 + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + php-version: "${{ matrix.php-version }}" + coverage: "pcov" + ini-values: "zend.assertions=1" + + - name: "Cache dependencies installed with composer" + uses: "actions/cache@v2" + with: + path: "~/.composer/cache" + key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}" + restore-keys: "php-${{ matrix.php-version }}-composer-locked-" + + - name: "Install dependencies with composer" + run: "composer install --no-interaction --no-progress --no-suggest" + if: "${{ matrix.deps == 'fixed' }}" + + - name: "Install lowest possible dependencies with composer" + run: "composer update --no-interaction --no-progress --no-suggest --prefer-dist --prefer-lowest" + if: "${{ matrix.deps == 'low' }}" + + - name: "Run PHPUnit" + run: "vendor/bin/phpunit -c ci/github/phpunit/sqlite.xml --coverage-clover=coverage.xml" + + - name: "Upload coverage file" + uses: "actions/upload-artifact@v2" + with: + name: "phpunit-sqlite-${{ matrix.deps }}-${{ matrix.php-version }}.coverage" + path: "coverage.xml" + phpunit-oci8: name: "PHPUnit on OCI8" runs-on: "ubuntu-20.04" + needs: "phpunit-smoke-check" strategy: matrix: @@ -39,6 +94,7 @@ jobs: php-version: "${{ matrix.php-version }}" extensions: "oci8" coverage: "pcov" + ini-values: "zend.assertions=1" - name: "Cache dependencies installed with composer" uses: "actions/cache@v2" @@ -51,14 +107,18 @@ jobs: run: "composer install --no-interaction --no-progress --no-suggest" - name: "Run PHPUnit" - run: "vendor/bin/phpunit -c ci/github/phpunit.oci8.xml --coverage-clover=coverage.xml" + run: "vendor/bin/phpunit -c ci/github/phpunit/oci8.xml --coverage-clover=coverage.xml" - - name: "Upload Code Coverage" - uses: "codecov/codecov-action@v1" + - name: "Upload coverage file" + uses: "actions/upload-artifact@v2" + with: + name: "${{ github.job }}-${{ matrix.php-version }}.coverage" + path: "coverage.xml" phpunit-pdo-oci: name: "PHPUnit on PDO_OCI" runs-on: "ubuntu-20.04" + needs: "phpunit-smoke-check" strategy: matrix: @@ -83,6 +143,362 @@ jobs: php-version: "${{ matrix.php-version }}" extensions: "pdo_oci" coverage: "pcov" + ini-values: "zend.assertions=1" + + - name: "Cache dependencies installed with composer" + uses: "actions/cache@v2" + with: + path: "~/.composer/cache" + key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}" + restore-keys: "php-${{ matrix.php-version }}-composer-locked-" + + - name: "Install dependencies with composer" + run: "composer install --no-interaction --no-progress --no-suggest" + + - name: "Run PHPUnit" + run: "vendor/bin/phpunit -c ci/github/phpunit/pdo_oci.xml --coverage-clover=coverage.xml" + + - name: "Upload coverage file" + uses: "actions/upload-artifact@v2" + with: + name: "${{ github.job }}-${{ matrix.php-version }}.coverage" + path: "coverage.xml" + + phpunit-postgres: + name: "PHPUnit with PostgreSQL" + runs-on: "ubuntu-20.04" + needs: "phpunit-smoke-check" + + strategy: + matrix: + php-version: + - "7.4" + postgres-version: + - "9.2" + - "9.3" + - "9.4" + - "9.5" + - "9.6" + - "10" + - "11" + - "12" + - "13" + + services: + postgres: + image: "postgres:${{ matrix.postgres-version }}" + env: + POSTGRES_PASSWORD: "postgres" + + options: >- + --health-cmd "pg_isready || psql -U postgres -c 'SELECT 1'" + + ports: + - "5432:5432" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + with: + fetch-depth: 2 + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + php-version: "${{ matrix.php-version }}" + coverage: "pcov" + ini-values: "zend.assertions=1" + + - name: "Cache dependencies installed with composer" + uses: "actions/cache@v2" + with: + path: "~/.composer/cache" + key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}" + restore-keys: "php-${{ matrix.php-version }}-composer-locked-" + + - name: "Install dependencies with composer" + run: "composer install --no-interaction --no-progress --no-suggest" + + - name: "Run PHPUnit" + run: "vendor/bin/phpunit -c ci/github/phpunit/pdo_pgsql.xml --coverage-clover=coverage.xml" + + - name: "Upload coverage file" + uses: "actions/upload-artifact@v2" + with: + name: "${{ github.job }}-${{ matrix.postgres-version }}-${{ matrix.php-version }}.coverage" + path: "coverage.xml" + + phpunit-mariadb: + name: "PHPUnit with MariaDB" + runs-on: "ubuntu-20.04" + needs: "phpunit-smoke-check" + + strategy: + matrix: + php-version: + - "7.4" + mariadb-version: + - "10.0" + - "10.1" + - "10.2" + - "10.3" + - "10.4" + - "10.5" + extension: + - "mysqli" + - "pdo_mysql" + + services: + mariadb: + image: "mariadb:${{ matrix.mariadb-version }}" + env: + MYSQL_ALLOW_EMPTY_PASSWORD: yes + MYSQL_DATABASE: "doctrine_tests" + + options: >- + --health-cmd "mysqladmin ping --silent" + + ports: + - "3306:3306" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + with: + fetch-depth: 2 + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + php-version: "${{ matrix.php-version }}" + coverage: "pcov" + ini-values: "zend.assertions=1" + extensions: "${{ matrix.extension }}" + + - name: "Cache dependencies installed with composer" + uses: "actions/cache@v2" + with: + path: "~/.composer/cache" + key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}" + restore-keys: "php-${{ matrix.php-version }}-composer-locked-" + + - name: "Install dependencies with composer" + run: "composer install --no-interaction --no-progress --no-suggest" + + - name: "Run PHPUnit" + run: "vendor/bin/phpunit -c ci/github/phpunit/${{ matrix.extension }}.xml --coverage-clover=coverage.xml" + + - name: "Upload coverage file" + uses: "actions/upload-artifact@v2" + with: + name: "${{ github.job }}-${{ matrix.mariadb-version }}-${{ matrix.extension }}-${{ matrix.php-version }}.coverage" + path: "coverage.xml" + + + phpunit-mysql: + name: "PHPUnit with MySQL" + runs-on: "ubuntu-20.04" + needs: "phpunit-smoke-check" + + strategy: + matrix: + php-version: + - "7.4" + mysql-version: + - "5.7" + - "8.0" + extension: + - "mysqli" + - "pdo_mysql" + config-file-suffix: + - "" + include: + - php-version: "7.3" + mysql-version: "8.0" + extension: "mysqli" + custom-entrypoint: >- + --entrypoint sh mysql:8 -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password" + - php-version: "7.3" + mysql-version: "8.0" + extension: "pdo_mysql" + custom-entrypoint: >- + --entrypoint sh mysql:8 -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password" + - mysql-version: "5.7" + - mysql-version: "8.0" + # https://stackoverflow.com/questions/60902904/how-to-pass-mysql-native-password-to-mysql-service-in-github-actions + custom-entrypoint: >- + --entrypoint sh mysql:8 -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password" + - config-file-suffix: "-tls" + php-version: "7.4" + mysql-version: "8.0" + extension: "mysqli" + + services: + mysql: + image: "mysql:${{ matrix.mysql-version }}" + + options: >- + --health-cmd "mysqladmin ping --silent" + -e MYSQL_ALLOW_EMPTY_PASSWORD=yes + -e MYSQL_DATABASE=doctrine_tests + ${{ matrix.custom-entrypoint }} + + ports: + - "3306:3306" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + with: + fetch-depth: 2 + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + php-version: "${{ matrix.php-version }}" + coverage: "pcov" + ini-values: "zend.assertions=1" + extensions: "${{ matrix.extension }}" + + - name: "Cache dependencies installed with composer" + uses: "actions/cache@v2" + with: + path: "~/.composer/cache" + key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}" + restore-keys: "php-${{ matrix.php-version }}-composer-locked-" + + - name: "Install dependencies with composer" + run: "composer install --no-interaction --no-progress --no-suggest" + + - name: "Copy TLS-related files" + run: 'docker cp "${{ job.services.mysql.id }}:/var/lib/mysql/ca.pem" . && docker cp "${{ job.services.mysql.id }}:/var/lib/mysql/client-cert.pem" . && docker cp "${{ job.services.mysql.id }}:/var/lib/mysql/client-key.pem" .' + if: "${{ endsWith(matrix.config-file-suffix, 'tls') }}" + + - name: "Run PHPUnit" + run: "vendor/bin/phpunit -c ci/github/phpunit/${{ matrix.extension }}${{ matrix.config-file-suffix }}.xml --coverage-clover=coverage.xml" + + - name: "Upload coverage file" + uses: "actions/upload-artifact@v2" + with: + name: "${{ github.job }}-${{ matrix.mysql-version }}-${{ matrix.extension }}-${{ matrix.config-file-suffix }}-${{ matrix.php-version }}.coverage" + path: "coverage.xml" + + phpunit-mssql: + name: "PHPUnit with SQL Server" + runs-on: "ubuntu-20.04" + needs: "phpunit-smoke-check" + + strategy: + matrix: + php-version: + - "7.3" + - "7.4" + extension: + - "sqlsrv" + - "pdo_sqlsrv" + collation: + - "Latin1_General_100_CI_AS" + include: + - collation: "Latin1_General_100_CS_AS" + php-version: "7.4" + extension: "sqlsrv" + - collation: "Latin1_General_100_CS_AS" + php-version: "7.4" + extension: "pdo_sqlsrv" + + services: + mssql: + image: "microsoft/mssql-server-linux:2017-latest" + env: + ACCEPT_EULA: "Y" + SA_PASSWORD: "Doctrine2018" + MSSQL_COLLATION: "${{ matrix.collation }}" + + options: >- + --health-cmd "echo quit | /opt/mssql-tools/bin/sqlcmd -S 127.0.0.1 -l 1 -U sa -P Doctrine2018" + + ports: + - "1433:1433" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + with: + fetch-depth: 2 + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + php-version: "${{ matrix.php-version }}" + coverage: "pcov" + ini-values: "zend.assertions=1" + tools: "pecl" + extensions: "${{ matrix.extension }}-5.7.0preview" + + - name: "Cache dependencies installed with composer" + uses: "actions/cache@v2" + with: + path: "~/.composer/cache" + key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}" + restore-keys: "php-${{ matrix.php-version }}-composer-locked-" + + - name: "Install dependencies with composer" + run: "composer install --no-interaction --no-progress --no-suggest" + + - name: "Run PHPUnit" + run: "vendor/bin/phpunit -c ci/github/phpunit/${{ matrix.extension }}.xml --coverage-clover=coverage.xml" + + - name: "Upload coverage file" + uses: "actions/upload-artifact@v2" + with: + name: "${{ github.job }}-${{ matrix.extension }}-${{ matrix.php-version }}-${{ matrix.collation }}.coverage" + path: "coverage.xml" + + phpunit-ibm-db2: + name: "PHPUnit with IBM DB2" + runs-on: "ubuntu-18.04" + needs: "phpunit-smoke-check" + + strategy: + matrix: + php-version: + - "7.3" + - "7.4" + + services: + ibm_db2: + image: "ibmcom/db2:11.5.0.0" + env: + DB2INST1_PASSWORD: "Doctrine2018" + LICENSE: "accept" + DBNAME: "doctrine" + + options: "--privileged=true" + + ports: + - "50000:50000" + + steps: + - name: "Perform healthcheck from the outside" + run: "docker logs -f ${{ job.services.ibm_db2.id }} | sed '/(*) Setup has completed./ q'" + + - name: "Create temporary tablespace" + run: "docker exec ${{ job.services.ibm_db2.id }} su - db2inst1 -c 'db2 CONNECT TO doctrine && db2 CREATE USER TEMPORARY TABLESPACE doctrine_tbsp PAGESIZE 4 K'" + + - name: "Checkout" + uses: "actions/checkout@v2" + with: + fetch-depth: 2 + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + php-version: "${{ matrix.php-version }}" + coverage: "pcov" + ini-values: "zend.assertions=1,extension=ibm_db2.so, ibm_db2.instance_name=db2inst1" + + - name: "Install ibm_db2 extension" + run: "ci/github/ext/install-ibm_db2.sh ${{ matrix.php-version }}" - name: "Cache dependencies installed with composer" uses: "actions/cache@v2" @@ -95,7 +511,78 @@ jobs: run: "composer install --no-interaction --no-progress --no-suggest" - name: "Run PHPUnit" - run: "vendor/bin/phpunit -c ci/github/phpunit.pdo-oci.xml --coverage-clover=coverage.xml" + run: "vendor/bin/phpunit -c ci/github/phpunit/ibm_db2.xml --coverage-clover=coverage.xml" + + - name: "Upload coverage file" + uses: "actions/upload-artifact@v2" + with: + name: "${{ github.job }}-${{ matrix.php-version }}.coverage" + path: "coverage.xml" + + + development-deps: + name: "PHPUnit with SQLite and development dependencies" + runs-on: "ubuntu-20.04" + + strategy: + matrix: + php-version: + - "7.4" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + php-version: "${{ matrix.php-version }}" + + - name: "Cache dependencies installed with composer" + uses: "actions/cache@v2" + with: + path: "~/.composer/cache" + key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}" + restore-keys: "php-${{ matrix.php-version }}-composer-locked-" + + - name: "Lower minimum stability" + run: "composer config minimum-stability dev" + + - name: "Install development dependencies with composer" + run: "composer update --no-interaction --no-progress --no-suggest --prefer-dist" + + - name: "Run PHPUnit" + run: "vendor/bin/phpunit -c ci/github/phpunit/sqlite.xml" - - name: "Upload Code Coverage" + upload_coverage: + name: "Upload coverage to Codecov" + runs-on: "ubuntu-20.04" + needs: + - "phpunit-smoke-check" + - "phpunit-oci8" + - "phpunit-pdo-oci" + - "phpunit-postgres" + - "phpunit-mariadb" + - "phpunit-mysql" + - "phpunit-mssql" + - "phpunit-ibm-db2" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + with: + fetch-depth: 2 + + - name: "Download coverage files" + uses: "actions/download-artifact@v2" + with: + path: "reports" + + - name: "Display structure of downloaded files" + run: ls -R + working-directory: reports + + - name: "Upload to Codecov" uses: "codecov/codecov-action@v1" + with: + directory: reports diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 4621a9afa96..00000000000 --- a/.travis.yml +++ /dev/null @@ -1,191 +0,0 @@ -language: php -dist: xenial - -cache: - directories: - - vendor - - $HOME/.composer/cache - -before_install: - - phpenv config-rm xdebug.ini || true - - pecl install pcov - -before_script: - - | - if [[ -n "$IMAGE" ]] - then - bash ./tests/travis/docker-run-mysql-or-mariadb.sh - fi - -install: - - travis_retry composer -n install --prefer-dist - -script: - - ./vendor/bin/phpunit --configuration tests/travis/$DB.travis.xml --coverage-clover clover.xml - -after_success: - - bash <(curl -s https://codecov.io/bash) - -jobs: - include: - - - stage: Smoke Testing - php: 7.3 - env: DB=sqlite - - - stage: Test - php: 7.3 - env: DB=mysql.docker IMAGE=mysql:5.7 - - stage: Test - php: 7.3 - env: DB=mysql.docker IMAGE=mysql:8.0 - - stage: Test - php: 7.3 - env: DB=mysqli.docker IMAGE=mysql:5.7 - - stage: Test - php: 7.3 - env: DB=mysqli.docker IMAGE=mysql:8.0 - - stage: Test - php: 7.3 - env: DB=mariadb.docker IMAGE=mariadb:10.0 - - stage: Test - php: 7.3 - env: DB=mariadb.docker IMAGE=mariadb:10.1 - - stage: Test - php: 7.3 - env: DB=mariadb.docker IMAGE=mariadb:10.2 - - stage: Test - php: 7.3 - env: DB=mariadb.docker IMAGE=mariadb:10.3 - - stage: Test - php: 7.3 - env: DB=mariadb.mysqli.docker IMAGE=mariadb:10.0 - - stage: Test - php: 7.3 - env: DB=mariadb.mysqli.docker IMAGE=mariadb:10.1 - - stage: Test - php: 7.3 - env: DB=mariadb.mysqli.docker IMAGE=mariadb:10.2 - - stage: Test - php: 7.3 - env: DB=mariadb.mysqli.docker IMAGE=mariadb:10.3 - - stage: Test - dist: trusty - php: 7.3 - env: DB=pgsql POSTGRESQL_VERSION=9.2 - services: - - postgresql - addons: - postgresql: "9.2" - - stage: Test - dist: trusty - php: 7.3 - env: DB=pgsql POSTGRESQL_VERSION=9.3 - services: - - postgresql - addons: - postgresql: "9.3" - - stage: Test - php: 7.3 - env: DB=pgsql POSTGRESQL_VERSION=9.4 - addons: - postgresql: "9.4" - - stage: Test - php: 7.3 - env: DB=pgsql POSTGRESQL_VERSION=9.5 - addons: - postgresql: "9.5" - - stage: Test - php: 7.3 - env: DB=pgsql POSTGRESQL_VERSION=9.6 - addons: - postgresql: "9.6" - - stage: Test - php: 7.3 - env: DB=pgsql POSTGRESQL_VERSION=10.0 - sudo: required - addons: - postgresql: "10" - before_script: - - bash ./tests/travis/install-postgres-10.sh - - stage: Test - php: 7.3 - env: DB=pgsql POSTGRESQL_VERSION=11.0 - sudo: required - before_script: - - bash ./tests/travis/install-postgres-11.sh - - stage: Test - php: 7.3 - env: DB=sqlsrv - sudo: required - before_script: - - bash ./tests/travis/install-sqlsrv-dependencies.sh - - bash ./tests/travis/install-mssql-sqlsrv.sh - - bash ./tests/travis/install-mssql.sh - - stage: Test - php: 7.3 - env: DB=pdo_sqlsrv - sudo: required - before_script: - - bash ./tests/travis/install-sqlsrv-dependencies.sh - - bash ./tests/travis/install-mssql-pdo_sqlsrv.sh - - bash ./tests/travis/install-mssql.sh - - stage: Test - php: 7.3 - env: DB=ibm_db2 - sudo: required - before_script: - - bash ./tests/travis/install-db2.sh - - bash ./tests/travis/install-db2-ibm_db2.sh - - stage: Test - php: 7.3 - env: DB=sqlite DEPENDENCIES=low - install: - - travis_retry composer update --prefer-dist --prefer-lowest - - stage: Test - php: 7.4 - env: DB=mysql.docker IMAGE=mysql:8.0 - - stage: Test - php: 7.4 - env: DB=mysqli-tls.docker IMAGE=mysql:8.0 TLS=yes - - stage: Test - php: 7.4 - env: DB=mariadb.docker IMAGE=mariadb:10.3 - - stage: Test - php: 7.4 - env: DB=mariadb.mysqli.docker IMAGE=mariadb:10.3 - - stage: Test - php: 7.4 - env: DB=pgsql POSTGRESQL_VERSION=11.0 - sudo: required - before_script: - - bash ./tests/travis/install-postgres-11.sh - - stage: Test - php: 7.4 - env: DB=sqlite - - stage: Test - php: 7.4 - env: DB=sqlsrv MSSQL_COLLATION=Latin1_General_100_CS_AS - sudo: required - before_script: - - bash ./tests/travis/install-sqlsrv-dependencies.sh - - bash ./tests/travis/install-mssql-sqlsrv.sh - - bash ./tests/travis/install-mssql.sh - - stage: Test - php: 7.4 - env: DB=pdo_sqlsrv MSSQL_COLLATION=Latin1_General_100_CS_AS - sudo: required - before_script: - - bash ./tests/travis/install-sqlsrv-dependencies.sh - - bash ./tests/travis/install-mssql-pdo_sqlsrv.sh - - bash ./tests/travis/install-mssql.sh - - stage: Test - if: type = cron - php: 7.2 - env: DB=sqlite DEPENDENCIES=dev - install: - - composer config minimum-stability dev - - travis_retry composer update --prefer-dist - - allow_failures: - - env: DEPENDENCIES=dev diff --git a/tests/travis/install-db2-ibm_db2.sh b/ci/github/ext/install-ibm_db2.sh old mode 100644 new mode 100755 similarity index 67% rename from tests/travis/install-db2-ibm_db2.sh rename to ci/github/ext/install-ibm_db2.sh index b59bb6396fd..fa0abc12df7 --- a/tests/travis/install-db2-ibm_db2.sh +++ b/ci/github/ext/install-ibm_db2.sh @@ -5,8 +5,8 @@ set -ex echo "Installing extension" ( # updating APT packages as per support recommendation - sudo apt -y -q update - sudo apt install ksh + sudo apt-get -y -q update + sudo apt-get install ksh php-pear cd /tmp @@ -21,7 +21,6 @@ echo "Installing extension" cd ibm_db2-* phpize ./configure --with-IBM_DB2=/tmp/dsdriver - make -j `nproc` - make install - echo -e 'extension=ibm_db2.so\nibm_db2.instance_name=db2inst1' > ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/ibm_db2.ini + make -j "$(nproc)" + sudo make install ) diff --git a/tests/travis/ibm_db2.travis.xml b/ci/github/phpunit/ibm_db2.xml similarity index 86% rename from tests/travis/ibm_db2.travis.xml rename to ci/github/phpunit/ibm_db2.xml index c8b758a711f..eabf83d108d 100644 --- a/tests/travis/ibm_db2.travis.xml +++ b/ci/github/phpunit/ibm_db2.xml @@ -17,13 +17,13 @@ - ../Doctrine/Tests/DBAL + ../../../tests - ../../lib/Doctrine + ../../../lib/Doctrine diff --git a/tests/travis/mysqli-tls.docker.travis.xml b/ci/github/phpunit/mysqli-tls.xml similarity index 87% rename from tests/travis/mysqli-tls.docker.travis.xml rename to ci/github/phpunit/mysqli-tls.xml index 568a61ada6c..3a05258a188 100644 --- a/tests/travis/mysqli-tls.docker.travis.xml +++ b/ci/github/phpunit/mysqli-tls.xml @@ -10,7 +10,7 @@ - + @@ -25,13 +25,13 @@ - ../Doctrine/Tests/DBAL + ../../../tests - ../../lib/Doctrine + ../../../lib/Doctrine diff --git a/tests/travis/mysqli.docker.travis.xml b/ci/github/phpunit/mysqli.xml similarity index 81% rename from tests/travis/mysqli.docker.travis.xml rename to ci/github/phpunit/mysqli.xml index 9925673195a..1660b7f4493 100644 --- a/tests/travis/mysqli.docker.travis.xml +++ b/ci/github/phpunit/mysqli.xml @@ -10,20 +10,20 @@ - + - ../Doctrine/Tests/DBAL + ../../../tests - ../../lib/Doctrine + ../../../lib/Doctrine diff --git a/ci/github/phpunit.oci8.xml b/ci/github/phpunit/oci8.xml similarity index 90% rename from ci/github/phpunit.oci8.xml rename to ci/github/phpunit/oci8.xml index bbe76733cac..fef723fec5e 100644 --- a/ci/github/phpunit.oci8.xml +++ b/ci/github/phpunit/oci8.xml @@ -24,13 +24,13 @@ - ../../tests + ../../../tests - ../../lib/Doctrine + ../../../lib/Doctrine diff --git a/tests/travis/mysql.docker.travis.xml b/ci/github/phpunit/pdo_mysql.xml similarity index 81% rename from tests/travis/mysql.docker.travis.xml rename to ci/github/phpunit/pdo_mysql.xml index 6efa94e94eb..99612ab3271 100644 --- a/tests/travis/mysql.docker.travis.xml +++ b/ci/github/phpunit/pdo_mysql.xml @@ -10,20 +10,20 @@ - + - ../Doctrine/Tests/DBAL + ../../../tests - ../../lib/Doctrine + ../../../lib/Doctrine diff --git a/ci/github/phpunit.pdo-oci.xml b/ci/github/phpunit/pdo_oci.xml similarity index 90% rename from ci/github/phpunit.pdo-oci.xml rename to ci/github/phpunit/pdo_oci.xml index d25c124db43..610b56cd72e 100644 --- a/ci/github/phpunit.pdo-oci.xml +++ b/ci/github/phpunit/pdo_oci.xml @@ -24,13 +24,13 @@ - ../../tests + ../../../tests - ../../lib/Doctrine + ../../../lib/Doctrine diff --git a/tests/travis/pgsql.travis.xml b/ci/github/phpunit/pdo_pgsql.xml similarity index 81% rename from tests/travis/pgsql.travis.xml rename to ci/github/phpunit/pdo_pgsql.xml index b13bc3e1b4c..8f6b760781e 100644 --- a/tests/travis/pgsql.travis.xml +++ b/ci/github/phpunit/pdo_pgsql.xml @@ -11,18 +11,19 @@ + - ../Doctrine/Tests/DBAL + ../../../tests - ../../lib/Doctrine + ../../../lib/Doctrine diff --git a/tests/travis/pdo_sqlsrv.travis.xml b/ci/github/phpunit/pdo_sqlsrv.xml similarity index 86% rename from tests/travis/pdo_sqlsrv.travis.xml rename to ci/github/phpunit/pdo_sqlsrv.xml index a6afaabfff0..0f1e1b2edda 100644 --- a/tests/travis/pdo_sqlsrv.travis.xml +++ b/ci/github/phpunit/pdo_sqlsrv.xml @@ -17,13 +17,13 @@ - ../Doctrine/Tests/DBAL + ../../../tests - ../../lib/Doctrine + ../../../lib/Doctrine diff --git a/tests/travis/sqlite.travis.xml b/ci/github/phpunit/sqlite.xml similarity index 81% rename from tests/travis/sqlite.travis.xml rename to ci/github/phpunit/sqlite.xml index 7629953cc15..3e911bd0afc 100644 --- a/tests/travis/sqlite.travis.xml +++ b/ci/github/phpunit/sqlite.xml @@ -9,13 +9,13 @@ > - ../Doctrine/Tests/DBAL + ../../../tests - ../../lib/Doctrine + ../../../lib/Doctrine diff --git a/tests/travis/sqlsrv.travis.xml b/ci/github/phpunit/sqlsrv.xml similarity index 86% rename from tests/travis/sqlsrv.travis.xml rename to ci/github/phpunit/sqlsrv.xml index c5412cdc2f6..02dfcbd4b51 100644 --- a/tests/travis/sqlsrv.travis.xml +++ b/ci/github/phpunit/sqlsrv.xml @@ -17,13 +17,13 @@ - ../Doctrine/Tests/DBAL + ../../../tests - ../../lib/Doctrine + ../../../lib/Doctrine diff --git a/tests/travis/docker-run-mysql-or-mariadb.sh b/tests/travis/docker-run-mysql-or-mariadb.sh deleted file mode 100644 index de0e53b9fcf..00000000000 --- a/tests/travis/docker-run-mysql-or-mariadb.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env bash - -set -ex - -echo "Starting RDBMS…">&2 - -if [[ "$IMAGE" == "mysql:8.0" ]] -then - CMD_OPTIONS="--default-authentication-plugin=mysql_native_password" -else - CMD_OPTIONS="" -fi - -docker run \ - --health-cmd='mysqladmin ping --silent' \ - --detach \ - --env MYSQL_ALLOW_EMPTY_PASSWORD=yes \ - --env MYSQL_DATABASE=doctrine_tests \ - --publish 33306:3306 \ - --name rdbms \ - "$IMAGE" $CMD_OPTIONS - -while true; do - healthStatus=$(docker inspect --format "{{json .State.Health.Status }}" rdbms) - case $healthStatus in - '"starting"') - echo "Waiting for RDBMS to become ready…">&2 - sleep 1 - ;; - '"healthy"') - echo "Container is healthy">&2 - break - ;; - '"unhealthy"') - echo "Container is unhealthy">&2 - exit 1 - ;; - *) - echo "Unexpected health status $healthStatus">&2 - ;; - esac -done - -if [[ "$TLS" == "yes" ]] -then - for file in "ca.pem" "client-cert.pem" "client-key.pem" - do - docker cp "rdbms:/var/lib/mysql/$file" . - done -fi diff --git a/tests/travis/install-db2.sh b/tests/travis/install-db2.sh deleted file mode 100644 index 79c1be98f74..00000000000 --- a/tests/travis/install-db2.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash - -set -ex - -echo Setting up IBM DB2 - -echo "su - db2inst1 -c 'db2 CONNECT TO doctrine && db2 CREATE USER TEMPORARY TABLESPACE doctrine_tbsp PAGESIZE 4 K'" > /tmp/doctrine-init.sh -chmod +x /tmp/doctrine-init.sh - -sudo docker run \ - -d \ - -p 50000:50000 \ - -e DB2INST1_PASSWORD=Doctrine2018 \ - -e LICENSE=accept \ - -e DBNAME=doctrine \ - -v /tmp/doctrine-init.sh:/var/custom/doctrine-init.sh:ro \ - --name db2 \ - --privileged=true \ - ibmcom/db2:11.5.0.0 - -sudo docker logs -f db2 | sed '/(*) Setup has completed./ q' - -echo DB2 started diff --git a/tests/travis/install-mssql-pdo_sqlsrv.sh b/tests/travis/install-mssql-pdo_sqlsrv.sh deleted file mode 100644 index 71e07aee231..00000000000 --- a/tests/travis/install-mssql-pdo_sqlsrv.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -set -ex - -echo "Installing extension" - -pecl install pdo_sqlsrv-5.7.0preview diff --git a/tests/travis/install-mssql-sqlsrv.sh b/tests/travis/install-mssql-sqlsrv.sh deleted file mode 100644 index d44841360dc..00000000000 --- a/tests/travis/install-mssql-sqlsrv.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -set -ex - -echo "Installing extension" - -pecl install sqlsrv-5.7.0preview diff --git a/tests/travis/install-mssql.sh b/tests/travis/install-mssql.sh deleted file mode 100644 index d17058e3455..00000000000 --- a/tests/travis/install-mssql.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash - -set -ex - -echo Setting up Microsoft SQL Server - -sudo docker pull microsoft/mssql-server-linux:2017-latest -sudo docker run \ - -e 'ACCEPT_EULA=Y' \ - -e 'SA_PASSWORD=Doctrine2018' \ - -e "MSSQL_COLLATION=${MSSQL_COLLATION:-Latin1_General_100_CI_AS}" \ - -p 127.0.0.1:1433:1433 \ - --name mssql \ - -d \ - microsoft/mssql-server-linux:2017-latest - -sudo docker exec -i mssql bash <<< 'until echo quit | /opt/mssql-tools/bin/sqlcmd -S 127.0.0.1 -l 1 -U sa -P Doctrine2018 > /dev/null 2>&1 ; do sleep 1; done' - -echo SQL Server started diff --git a/tests/travis/install-postgres-10.sh b/tests/travis/install-postgres-10.sh deleted file mode 100644 index 88041241e6e..00000000000 --- a/tests/travis/install-postgres-10.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash - -set -ex - -echo "Installing Postgres 10" -sudo service postgresql stop -sudo apt-get remove -q 'postgresql-*' -sudo apt-get update -q -sudo apt-get install -q postgresql-10 postgresql-client-10 -sudo cp /etc/postgresql/{9.6,10}/main/pg_hba.conf - -echo "Restarting Postgres 10" -sudo service postgresql restart diff --git a/tests/travis/install-postgres-11.sh b/tests/travis/install-postgres-11.sh deleted file mode 100644 index 2ef1aabc4f0..00000000000 --- a/tests/travis/install-postgres-11.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash - -set -ex - -echo "Preparing Postgres 11" - -sudo service postgresql stop || true - -sudo docker run -d --name postgres11 -p 5432:5432 postgres:11.1 -sudo docker exec -i postgres11 bash <<< 'until pg_isready -U postgres > /dev/null 2>&1 ; do sleep 1; done' - -echo "Postgres 11 ready" diff --git a/tests/travis/install-sqlsrv-dependencies.sh b/tests/travis/install-sqlsrv-dependencies.sh deleted file mode 100644 index ff91bfdfaf0..00000000000 --- a/tests/travis/install-sqlsrv-dependencies.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -set -ex - -echo Installing driver dependencies - -curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - -curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/mssql.list -sudo apt-get update -ACCEPT_EULA=Y sudo apt-get install -qy msodbcsql17 unixodbc unixodbc-dev libssl1.0.0 diff --git a/tests/travis/mariadb.docker.travis.xml b/tests/travis/mariadb.docker.travis.xml deleted file mode 100644 index 6efa94e94eb..00000000000 --- a/tests/travis/mariadb.docker.travis.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - ../Doctrine/Tests/DBAL - - - - - - ../../lib/Doctrine - - - diff --git a/tests/travis/mariadb.mysqli.docker.travis.xml b/tests/travis/mariadb.mysqli.docker.travis.xml deleted file mode 100644 index 9925673195a..00000000000 --- a/tests/travis/mariadb.mysqli.docker.travis.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - ../Doctrine/Tests/DBAL - - - - - - ../../lib/Doctrine - - - From 032b602cd0e864729810215443756a693b522d07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Tue, 13 Oct 2020 10:15:15 +0200 Subject: [PATCH 32/56] Rename vars - from/to instead of 1/2 --- lib/Doctrine/DBAL/Schema/Comparator.php | 88 ++++++++++++------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/lib/Doctrine/DBAL/Schema/Comparator.php b/lib/Doctrine/DBAL/Schema/Comparator.php index 20f5ea7b1a9..7e24b3e8c01 100644 --- a/lib/Doctrine/DBAL/Schema/Comparator.php +++ b/lib/Doctrine/DBAL/Schema/Comparator.php @@ -188,24 +188,24 @@ public function diffSequence(Sequence $sequence1, Sequence $sequence2) } /** - * Returns the difference between the tables $table1 and $table2. + * Returns the difference between the tables $fromTable and $toTable. * * If there are no differences this method returns the boolean false. * * @return TableDiff|false */ - public function diffTable(Table $table1, Table $table2) + public function diffTable(Table $fromTable, Table $toTable) { $changes = 0; - $tableDifferences = new TableDiff($table1->getName()); - $tableDifferences->fromTable = $table1; + $tableDifferences = new TableDiff($fromTable->getName()); + $tableDifferences->fromTable = $fromTable; - $table1Columns = $table1->getColumns(); - $table2Columns = $table2->getColumns(); + $fromTableColumns = $fromTable->getColumns(); + $toTableColumns = $toTable->getColumns(); - /* See if all the columns in table 1 exist in table 2 */ - foreach ($table2Columns as $columnName => $column) { - if ($table1->hasColumn($columnName)) { + /* See if all the columns in "from" table exist in "to" table */ + foreach ($toTableColumns as $columnName => $column) { + if ($fromTable->hasColumn($columnName)) { continue; } @@ -213,23 +213,23 @@ public function diffTable(Table $table1, Table $table2) $changes++; } - /* See if there are any removed columns in table 2 */ - foreach ($table1Columns as $columnName => $column) { - // See if column is removed in table 2. - if (! $table2->hasColumn($columnName)) { + /* See if there are any removed columns in "to" table */ + foreach ($fromTableColumns as $columnName => $column) { + // See if column is removed in "to" table. + if (! $toTable->hasColumn($columnName)) { $tableDifferences->removedColumns[$columnName] = $column; $changes++; continue; } - // See if column has changed properties in table 2. - $changedProperties = $this->diffColumn($column, $table2->getColumn($columnName)); + // See if column has changed properties in "to" table. + $changedProperties = $this->diffColumn($column, $toTable->getColumn($columnName)); if (empty($changedProperties)) { continue; } - $columnDiff = new ColumnDiff($column->getName(), $table2->getColumn($columnName), $changedProperties); + $columnDiff = new ColumnDiff($column->getName(), $toTable->getColumn($columnName), $changedProperties); $columnDiff->fromColumn = $column; $tableDifferences->changedColumns[$column->getName()] = $columnDiff; @@ -238,12 +238,12 @@ public function diffTable(Table $table1, Table $table2) $this->detectColumnRenamings($tableDifferences); - $table1Indexes = $table1->getIndexes(); - $table2Indexes = $table2->getIndexes(); + $fromTableIndexes = $fromTable->getIndexes(); + $toTableIndexes = $toTable->getIndexes(); - /* See if all the indexes in table 1 exist in table 2 */ - foreach ($table2Indexes as $indexName => $index) { - if (($index->isPrimary() && $table1->hasPrimaryKey()) || $table1->hasIndex($indexName)) { + /* See if all the indexes in "from" table exist in "to" table */ + foreach ($toTableIndexes as $indexName => $index) { + if (($index->isPrimary() && $fromTable->hasPrimaryKey()) || $fromTable->hasIndex($indexName)) { continue; } @@ -251,56 +251,56 @@ public function diffTable(Table $table1, Table $table2) $changes++; } - /* See if there are any removed indexes in table 2 */ - foreach ($table1Indexes as $indexName => $index) { - // See if index is removed in table 2. + /* See if there are any removed indexes in "to" table */ + foreach ($fromTableIndexes as $indexName => $index) { + // See if index is removed in "to" table. if ( - ($index->isPrimary() && ! $table2->hasPrimaryKey()) || - ! $index->isPrimary() && ! $table2->hasIndex($indexName) + ($index->isPrimary() && ! $toTable->hasPrimaryKey()) || + ! $index->isPrimary() && ! $toTable->hasIndex($indexName) ) { $tableDifferences->removedIndexes[$indexName] = $index; $changes++; continue; } - // See if index has changed in table 2. - $table2Index = $index->isPrimary() ? $table2->getPrimaryKey() : $table2->getIndex($indexName); - assert($table2Index instanceof Index); + // See if index has changed in "to" table. + $toTableIndex = $index->isPrimary() ? $toTable->getPrimaryKey() : $toTable->getIndex($indexName); + assert($toTableIndex instanceof Index); - if (! $this->diffIndex($index, $table2Index)) { + if (! $this->diffIndex($index, $toTableIndex)) { continue; } - $tableDifferences->changedIndexes[$indexName] = $table2Index; + $tableDifferences->changedIndexes[$indexName] = $toTableIndex; $changes++; } $this->detectIndexRenamings($tableDifferences); - $fromFkeys = $table1->getForeignKeys(); - $toFkeys = $table2->getForeignKeys(); + $fromForeignKeys = $fromTable->getForeignKeys(); + $toForeignKeys = $toTable->getForeignKeys(); - foreach ($fromFkeys as $key1 => $constraint1) { - foreach ($toFkeys as $key2 => $constraint2) { - if ($this->diffForeignKey($constraint1, $constraint2) === false) { - unset($fromFkeys[$key1], $toFkeys[$key2]); + foreach ($fromForeignKeys as $fromKey => $fromConstraint) { + foreach ($toForeignKeys as $toKey => $toConstraint) { + if ($this->diffForeignKey($fromConstraint, $toConstraint) === false) { + unset($fromForeignKeys[$fromKey], $toForeignKeys[$toKey]); } else { - if (strtolower($constraint1->getName()) === strtolower($constraint2->getName())) { - $tableDifferences->changedForeignKeys[] = $constraint2; + if (strtolower($fromConstraint->getName()) === strtolower($toConstraint->getName())) { + $tableDifferences->changedForeignKeys[] = $toConstraint; $changes++; - unset($fromFkeys[$key1], $toFkeys[$key2]); + unset($fromForeignKeys[$fromKey], $toForeignKeys[$toKey]); } } } } - foreach ($fromFkeys as $constraint1) { - $tableDifferences->removedForeignKeys[] = $constraint1; + foreach ($fromForeignKeys as $fromConstraint) { + $tableDifferences->removedForeignKeys[] = $fromConstraint; $changes++; } - foreach ($toFkeys as $constraint2) { - $tableDifferences->addedForeignKeys[] = $constraint2; + foreach ($toForeignKeys as $toConstraint) { + $tableDifferences->addedForeignKeys[] = $toConstraint; $changes++; } From cd8197ce93c77ea0339cd85760220a91f6554d03 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 14 Oct 2020 14:45:06 -0700 Subject: [PATCH 33/56] Use type intersection instead of union types for mock objects --- tests/Doctrine/Tests/DBAL/ConnectionTest.php | 2 +- .../Tests/DBAL/Driver/IBMDB2/DB2ConnectionTest.php | 2 +- .../Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php | 2 +- .../Tests/DBAL/Driver/OCI8/OCI8ConnectionTest.php | 2 +- tests/Doctrine/Tests/DBAL/Driver/PDO/ExceptionTest.php | 3 +-- .../DBAL/Driver/SQLAnywhere/SQLAnywhereConnectionTest.php | 2 +- .../Tests/DBAL/Driver/SQLSrv/SQLSrvConnectionTest.php | 2 +- tests/Doctrine/Tests/DBAL/Portability/StatementTest.php | 6 +++--- tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php | 2 +- tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php | 2 +- tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php | 2 +- .../DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php | 8 ++++---- tests/Doctrine/Tests/DBAL/Types/ArrayTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php | 2 +- tests/Doctrine/Tests/DBAL/Types/BinaryTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/BlobTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/BooleanTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php | 2 +- .../Tests/DBAL/Types/DateTimeImmutableTypeTest.php | 2 +- .../Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/DecimalTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/FloatTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/IntegerTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/JsonTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/ObjectTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/StringTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php | 2 +- .../Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php | 2 +- 33 files changed, 38 insertions(+), 39 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/ConnectionTest.php index 5543a42dec7..feed00275a2 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -51,7 +51,7 @@ protected function setUp(): void } /** - * @return Connection|MockObject + * @return Connection&MockObject */ private function getExecuteStatementMockConnection() { diff --git a/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2ConnectionTest.php index e8b08f745e5..1d7d88ec342 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2ConnectionTest.php @@ -14,7 +14,7 @@ class DB2ConnectionTest extends DbalTestCase /** * The ibm_db2 driver connection mock under test. * - * @var DB2Connection|MockObject + * @var DB2Connection&MockObject */ private $connectionMock; diff --git a/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php index 9611da063cd..c0953ea532b 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php @@ -19,7 +19,7 @@ class MysqliConnectionTest extends DbalFunctionalTestCase /** * The mysqli driver connection mock under test. * - * @var MysqliConnection|MockObject + * @var MysqliConnection&MockObject */ private $connectionMock; diff --git a/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8ConnectionTest.php index 12cd8ef7af4..5185f4abc10 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8ConnectionTest.php @@ -14,7 +14,7 @@ class OCI8ConnectionTest extends DbalTestCase /** * The oci8 driver connection mock under test. * - * @var OCI8Connection|MockObject + * @var OCI8Connection&MockObject */ private $connectionMock; diff --git a/tests/Doctrine/Tests/DBAL/Driver/PDO/ExceptionTest.php b/tests/Doctrine/Tests/DBAL/Driver/PDO/ExceptionTest.php index 4ba493ab2ee..f9323041038 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/PDO/ExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/PDO/ExceptionTest.php @@ -5,7 +5,6 @@ use Doctrine\DBAL\Driver\PDO\Exception; use Doctrine\Tests\DbalTestCase; use PDOException; -use PHPUnit\Framework\MockObject\MockObject; /** * @requires extension pdo @@ -28,7 +27,7 @@ class ExceptionTest extends DbalTestCase /** * The wrapped PDO exception mock. * - * @var PDOException|MockObject + * @var PDOException */ private $wrappedException; diff --git a/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/SQLAnywhereConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/SQLAnywhereConnectionTest.php index b2d1ddef6fc..54cedfce3cd 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/SQLAnywhereConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/SQLAnywhereConnectionTest.php @@ -14,7 +14,7 @@ class SQLAnywhereConnectionTest extends DbalTestCase /** * The sqlanywhere driver connection mock under test. * - * @var SQLAnywhereConnection|MockObject + * @var SQLAnywhereConnection&MockObject */ private $connectionMock; diff --git a/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/SQLSrvConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/SQLSrvConnectionTest.php index 8d424ee21b6..75781443962 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/SQLSrvConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/SQLSrvConnectionTest.php @@ -11,7 +11,7 @@ class SQLSrvConnectionTest extends DbalTestCase /** * The sqlsrv driver connection mock under test. * - * @var SQLSrvConnection|MockObject + * @var SQLSrvConnection&MockObject */ private $connectionMock; diff --git a/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php b/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php index f41124a8334..f83ab92e50d 100644 --- a/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php @@ -15,13 +15,13 @@ class StatementTest extends DbalTestCase { - /** @var Connection|MockObject */ + /** @var Connection&MockObject */ protected $conn; /** @var Statement */ protected $stmt; - /** @var DriverStatement|MockObject */ + /** @var DriverStatement&MockObject */ protected $wrappedStmt; protected function setUp(): void @@ -157,7 +157,7 @@ public function testRowCount(): void } /** - * @return Connection|MockObject + * @return Connection&MockObject */ protected function createConnection() { diff --git a/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php index faa784a6137..36b0551d338 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php @@ -18,7 +18,7 @@ */ final class DB2SchemaManagerTest extends TestCase { - /** @var Connection|MockObject */ + /** @var Connection&MockObject */ private $conn; /** @var DB2SchemaManager */ diff --git a/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php b/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php index 414d779438e..f5100e6c856 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php @@ -46,7 +46,7 @@ public function testSchemaDiffToSaveSql(): void } /** - * @return AbstractPlatform|MockObject + * @return AbstractPlatform&MockObject */ private function createPlatform(bool $unsafe) { diff --git a/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php b/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php index 4c0ada138d0..c1b9ede62cb 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php @@ -11,7 +11,7 @@ class TableDiffTest extends TestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; public function setUp(): void diff --git a/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php b/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php index c4e1aca9e85..26354adef9d 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php @@ -12,7 +12,7 @@ class CreateSchemaSqlCollectorTest extends TestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platformMock; /** @var CreateSchemaSqlCollector */ @@ -134,7 +134,7 @@ public function testResetsQueries(): void } /** - * @return ForeignKeyConstraint|MockObject + * @return ForeignKeyConstraint&MockObject */ private function createForeignKeyConstraintMock() { @@ -144,7 +144,7 @@ private function createForeignKeyConstraintMock() } /** - * @return Sequence|MockObject + * @return Sequence&MockObject */ private function createSequenceMock() { @@ -154,7 +154,7 @@ private function createSequenceMock() } /** - * @return Table|MockObject + * @return Table&MockObject */ private function createTableMock() { diff --git a/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php b/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php index df48f2f14b3..03a960d5034 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php @@ -13,7 +13,7 @@ class ArrayTest extends DbalTestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; /** @var ArrayType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php b/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php index b748cdf19a2..ee111fab030 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php @@ -16,7 +16,7 @@ abstract class BaseDateTypeTestCase extends TestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ protected $platform; /** @var Type */ diff --git a/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php b/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php index 23514f6160b..5adf15b1cfa 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php @@ -17,7 +17,7 @@ class BinaryTest extends DbalTestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ protected $platform; /** @var BinaryType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/BlobTest.php b/tests/Doctrine/Tests/DBAL/Types/BlobTest.php index 23486819798..2c5c6f2f87c 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BlobTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BlobTest.php @@ -15,7 +15,7 @@ class BlobTest extends DbalTestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ protected $platform; /** @var BlobType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php b/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php index 0fe4a2d5a5e..62d70fc0336 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php @@ -10,7 +10,7 @@ class BooleanTest extends DbalTestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; /** @var BooleanType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php index e06e9b02f11..6970096e0de 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php @@ -16,7 +16,7 @@ class DateImmutableTypeTest extends TestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; /** @var DateImmutableType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php b/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php index 6c85de36510..f849afe2938 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php @@ -14,7 +14,7 @@ final class DateIntervalTest extends DbalTestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; /** @var DateIntervalType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php index 4c3a772d344..4ae30947b5f 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php @@ -16,7 +16,7 @@ class DateTimeImmutableTypeTest extends TestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; /** @var DateTimeImmutableType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php index eafaedcb729..2192588a5b7 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php @@ -16,7 +16,7 @@ class DateTimeTzImmutableTypeTest extends TestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; /** @var DateTimeTzImmutableType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php b/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php index bf05598ab32..feacd0a2f0a 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php @@ -10,7 +10,7 @@ class DecimalTest extends DbalTestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; /** @var DecimalType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/FloatTest.php b/tests/Doctrine/Tests/DBAL/Types/FloatTest.php index 44623c28b90..9543b844c0f 100644 --- a/tests/Doctrine/Tests/DBAL/Types/FloatTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/FloatTest.php @@ -10,7 +10,7 @@ class FloatTest extends DbalTestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; /** @var FloatType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php index 3615b687bd9..fd488c862ab 100644 --- a/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php @@ -10,7 +10,7 @@ class GuidTypeTest extends DbalTestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; /** @var GuidType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php b/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php index 7241a9237e1..ae589c8dd78 100644 --- a/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php @@ -10,7 +10,7 @@ class IntegerTest extends DbalTestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; /** @var IntegerType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php b/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php index 4603f3d6206..ac438672426 100644 --- a/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php @@ -16,7 +16,7 @@ class JsonArrayTest extends DbalTestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ protected $platform; /** @var JsonArrayType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/JsonTest.php b/tests/Doctrine/Tests/DBAL/Types/JsonTest.php index 0cf41b7f867..71c444b9a48 100644 --- a/tests/Doctrine/Tests/DBAL/Types/JsonTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/JsonTest.php @@ -17,7 +17,7 @@ class JsonTest extends DbalTestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ protected $platform; /** @var JsonType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php b/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php index df961faa3b9..c7fd42fa799 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php @@ -14,7 +14,7 @@ class ObjectTest extends DbalTestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; /** @var ObjectType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php b/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php index 31ed1a310dd..bc0956a326d 100644 --- a/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php @@ -10,7 +10,7 @@ class SmallIntTest extends DbalTestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; /** @var SmallIntType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/StringTest.php b/tests/Doctrine/Tests/DBAL/Types/StringTest.php index 688a06ba870..4f62fed044a 100644 --- a/tests/Doctrine/Tests/DBAL/Types/StringTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/StringTest.php @@ -10,7 +10,7 @@ class StringTest extends DbalTestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; /** @var StringType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php index c9518fe6dbf..4d664f4966f 100644 --- a/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php @@ -16,7 +16,7 @@ class TimeImmutableTypeTest extends TestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; /** @var TimeImmutableType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php index a8652a6115b..3326e13ac72 100644 --- a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php @@ -14,7 +14,7 @@ class VarDateTimeImmutableTypeTest extends TestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; /** @var VarDateTimeImmutableType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php index 586b36e89cd..5f2f4e50df8 100644 --- a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php @@ -12,7 +12,7 @@ class VarDateTimeTest extends DbalTestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; /** @var VarDateTimeType */ From 7b55dae743d8cd4ad80d3000a1aa8e09d9ea1bcb Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 14 Oct 2020 14:49:33 -0700 Subject: [PATCH 34/56] Fixed ArgumentTypeCoercion issues caused by using strings as class names --- tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php | 3 ++- .../DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php | 2 +- tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/TimeTest.php | 3 ++- tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php | 4 ++-- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php index ef68b5be62f..d4123c79188 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php @@ -20,6 +20,7 @@ use Doctrine\DBAL\Types\Types; use Doctrine\Tests\DbalFunctionalTestCase; use PDO; +use stdClass; use function array_change_key_case; use function array_filter; @@ -734,7 +735,7 @@ public function testFetchAllStyleObject(): void $results = $stmt->fetchAll(FetchMode::STANDARD_OBJECT); self::assertCount(1, $results); - self::assertInstanceOf('stdClass', $results[0]); + self::assertInstanceOf(stdClass::class, $results[0]); self::assertEquals( 1, diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php index 5adf73f7aa0..fc7e00ae3e3 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php @@ -887,7 +887,7 @@ public function testAltersTableColumnCommentIfRequiredByType(): void $tableDiff = $comparator->diffTable($table1, $table2); - $this->assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); + $this->assertNotFalse($tableDiff); $this->assertSame( [ 'ALTER TABLE "foo" ALTER "bar" TYPE TIMESTAMP(0) WITHOUT TIME ZONE', diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php index 72868f328a8..472c64ee201 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php @@ -29,7 +29,7 @@ public function testDateTimeConvertsToPHPValue(): void { // Birthday of jwage and also birthday of Doctrine. Send him a present ;) $date = $this->type->convertToPHPValue('1985-09-01 00:00:00', $this->platform); - self::assertInstanceOf('DateTime', $date); + self::assertInstanceOf(DateTime::class, $date); self::assertEquals('1985-09-01 00:00:00', $date->format('Y-m-d H:i:s')); } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php index f7367f283ec..b02987678c9 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php @@ -29,7 +29,7 @@ public function testDateTimeConvertsToPHPValue(): void { // Birthday of jwage and also birthday of Doctrine. Send him a present ;) $date = $this->type->convertToPHPValue('1985-09-01 00:00:00', $this->platform); - self::assertInstanceOf('DateTime', $date); + self::assertInstanceOf(DateTime::class, $date); self::assertEquals('1985-09-01 00:00:00', $date->format('Y-m-d H:i:s')); } diff --git a/tests/Doctrine/Tests/DBAL/Types/TimeTest.php b/tests/Doctrine/Tests/DBAL/Types/TimeTest.php index 8bec5c2ae37..358fa6e0a38 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 DateTime; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; @@ -16,7 +17,7 @@ protected function setUp(): void public function testTimeConvertsToPHPValue(): void { - self::assertInstanceOf('DateTime', $this->type->convertToPHPValue('5:30:55', $this->platform)); + self::assertInstanceOf(DateTime::class, $this->type->convertToPHPValue('5:30:55', $this->platform)); } public function testDateFieldResetInPHPValue(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php index 5f2f4e50df8..a82e07949ee 100644 --- a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php @@ -42,7 +42,7 @@ public function testDateTimeConvertsToPHPValue(): void { // Birthday of jwage and also birthday of Doctrine. Send him a present ;) $date = $this->type->convertToPHPValue('1985-09-01 00:00:00', $this->platform); - self::assertInstanceOf('DateTime', $date); + self::assertInstanceOf(DateTime::class, $date); self::assertEquals('1985-09-01 00:00:00', $date->format('Y-m-d H:i:s')); self::assertEquals('000000', $date->format('u')); } @@ -56,7 +56,7 @@ public function testInvalidDateTimeFormatConversion(): void public function testConversionWithMicroseconds(): void { $date = $this->type->convertToPHPValue('1985-09-01 00:00:00.123456', $this->platform); - self::assertInstanceOf('DateTime', $date); + self::assertInstanceOf(DateTime::class, $date); self::assertEquals('1985-09-01 00:00:00', $date->format('Y-m-d H:i:s')); self::assertEquals('123456', $date->format('u')); } From 384a1541a94baef9eb37864a8d7c88b673b16e66 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 14 Oct 2020 15:03:25 -0700 Subject: [PATCH 35/56] Instantiate specific type classes instead of using a factory --- tests/Doctrine/Tests/DBAL/Types/ArrayTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/BinaryTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/BlobTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/BooleanTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php | 5 +---- tests/Doctrine/Tests/DBAL/Types/DateTest.php | 4 ++-- .../Tests/DBAL/Types/DateTimeImmutableTypeTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php | 4 ++-- .../Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php | 4 ++-- tests/Doctrine/Tests/DBAL/Types/DecimalTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/FloatTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/IntegerTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/JsonTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/ObjectTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/StringTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/TimeTest.php | 4 ++-- .../Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php | 7 +------ tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php | 7 +------ 24 files changed, 28 insertions(+), 58 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php b/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php index 03a960d5034..ebda9c37c2e 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php @@ -5,7 +5,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ArrayType; use Doctrine\DBAL\Types\ConversionException; -use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; @@ -22,7 +21,7 @@ class ArrayTest extends DbalTestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = Type::getType('array'); + $this->type = new ArrayType(); } public function testArrayConvertsToDatabaseValue(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php b/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php index 5adf15b1cfa..e1b14679c5b 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php @@ -6,7 +6,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\BinaryType; use Doctrine\DBAL\Types\ConversionException; -use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Types; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; @@ -26,7 +25,7 @@ class BinaryTest extends DbalTestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = Type::getType('binary'); + $this->type = new BinaryType(); } public function testReturnsBindingType(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/BlobTest.php b/tests/Doctrine/Tests/DBAL/Types/BlobTest.php index 2c5c6f2f87c..340608fff44 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BlobTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BlobTest.php @@ -4,7 +4,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\BlobType; -use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; @@ -24,7 +23,7 @@ class BlobTest extends DbalTestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = Type::getType('blob'); + $this->type = new BlobType(); } public function testBlobNullConvertsToPHPValue(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php b/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php index 62d70fc0336..7eefeb3f9f9 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php @@ -4,7 +4,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\BooleanType; -use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; @@ -19,7 +18,7 @@ class BooleanTest extends DbalTestCase protected function setUp(): void { $this->platform = $this->getMockForAbstractClass(AbstractPlatform::class); - $this->type = Type::getType('boolean'); + $this->type = new BooleanType(); } public function testBooleanConvertsToDatabaseValue(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php index 6970096e0de..46bbbd3fb39 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php @@ -8,7 +8,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\DateImmutableType; -use Doctrine\DBAL\Types\Type; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -24,8 +23,8 @@ class DateImmutableTypeTest extends TestCase protected function setUp(): void { - $this->type = Type::getType('date_immutable'); $this->platform = $this->createMock(AbstractPlatform::class); + $this->type = new DateImmutableType(); } public function testFactoryCreatesCorrectType(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php b/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php index f849afe2938..ee81bb0e5c7 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php @@ -7,7 +7,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\DateIntervalType; -use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; use stdClass; @@ -23,9 +22,7 @@ final class DateIntervalTest extends DbalTestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = Type::getType('dateinterval'); - - self::assertInstanceOf(DateIntervalType::class, $this->type); + $this->type = new DateIntervalType(); } public function testDateIntervalConvertsToDatabaseValue(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTest.php index 1d97cceaa2c..17183125e1d 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTest.php @@ -4,7 +4,7 @@ use DateTime; use Doctrine\DBAL\Types\ConversionException; -use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\DateType; use function date_default_timezone_set; @@ -12,7 +12,7 @@ class DateTest extends BaseDateTypeTestCase { protected function setUp(): void { - $this->type = Type::getType('date'); + $this->type = new DateType(); parent::setUp(); } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php index 4ae30947b5f..72a3585fe12 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php @@ -8,7 +8,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\DateTimeImmutableType; -use Doctrine\DBAL\Types\Type; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -24,8 +23,8 @@ class DateTimeImmutableTypeTest extends TestCase protected function setUp(): void { - $this->type = Type::getType('datetime_immutable'); $this->platform = $this->getMockBuilder(AbstractPlatform::class)->getMock(); + $this->type = new DateTimeImmutableType(); } public function testFactoryCreatesCorrectType(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php index 472c64ee201..5bf92f811e2 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php @@ -4,13 +4,13 @@ use DateTime; use Doctrine\DBAL\Types\ConversionException; -use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\DateTimeType; class DateTimeTest extends BaseDateTypeTestCase { protected function setUp(): void { - $this->type = Type::getType('datetime'); + $this->type = new DateTimeType(); parent::setUp(); } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php index 2192588a5b7..7992d99b65f 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php @@ -8,7 +8,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\DateTimeTzImmutableType; -use Doctrine\DBAL\Types\Type; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -24,8 +23,8 @@ class DateTimeTzImmutableTypeTest extends TestCase protected function setUp(): void { - $this->type = Type::getType('datetimetz_immutable'); $this->platform = $this->createMock(AbstractPlatform::class); + $this->type = new DateTimeTzImmutableType(); } public function testFactoryCreatesCorrectType(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php index b02987678c9..f7696515f64 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php @@ -4,13 +4,13 @@ use DateTime; use Doctrine\DBAL\Types\ConversionException; -use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\DateTimeTzType; class DateTimeTzTest extends BaseDateTypeTestCase { protected function setUp(): void { - $this->type = Type::getType('datetimetz'); + $this->type = new DateTimeTzType(); parent::setUp(); } diff --git a/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php b/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php index feacd0a2f0a..29f88f6f54a 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php @@ -4,7 +4,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\DecimalType; -use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; @@ -19,7 +18,7 @@ class DecimalTest extends DbalTestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = Type::getType('decimal'); + $this->type = new DecimalType(); } public function testDecimalConvertsToPHPValue(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/FloatTest.php b/tests/Doctrine/Tests/DBAL/Types/FloatTest.php index 9543b844c0f..7316252cade 100644 --- a/tests/Doctrine/Tests/DBAL/Types/FloatTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/FloatTest.php @@ -4,7 +4,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\FloatType; -use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; @@ -19,7 +18,7 @@ class FloatTest extends DbalTestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = Type::getType('float'); + $this->type = new FloatType(); } public function testFloatConvertsToPHPValue(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php index fd488c862ab..2c15c7cbd4b 100644 --- a/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php @@ -4,7 +4,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\GuidType; -use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; @@ -19,7 +18,7 @@ class GuidTypeTest extends DbalTestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = Type::getType('guid'); + $this->type = new GuidType(); } public function testConvertToPHPValue(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php b/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php index ae589c8dd78..c8f9cf952f4 100644 --- a/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php @@ -4,7 +4,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\IntegerType; -use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; @@ -19,7 +18,7 @@ class IntegerTest extends DbalTestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = Type::getType('integer'); + $this->type = new IntegerType(); } public function testIntegerConvertsToPHPValue(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php b/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php index ac438672426..2383543b322 100644 --- a/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php @@ -5,7 +5,6 @@ use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\JsonArrayType; -use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Types; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; @@ -25,7 +24,7 @@ class JsonArrayTest extends DbalTestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = Type::getType('json_array'); + $this->type = new JsonArrayType(); } public function testReturnsBindingType(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/JsonTest.php b/tests/Doctrine/Tests/DBAL/Types/JsonTest.php index 71c444b9a48..158c7bb1a9c 100644 --- a/tests/Doctrine/Tests/DBAL/Types/JsonTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/JsonTest.php @@ -6,7 +6,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\JsonType; -use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Types; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; @@ -26,7 +25,7 @@ class JsonTest extends DbalTestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = Type::getType('json'); + $this->type = new JsonType(); } public function testReturnsBindingType(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php b/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php index c7fd42fa799..227fcef9554 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php @@ -5,7 +5,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\ObjectType; -use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; use stdClass; @@ -23,7 +22,7 @@ class ObjectTest extends DbalTestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = Type::getType('object'); + $this->type = new ObjectType(); } public function testObjectConvertsToDatabaseValue(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php b/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php index bc0956a326d..4c5981f4729 100644 --- a/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php @@ -4,7 +4,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\SmallIntType; -use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; @@ -19,7 +18,7 @@ class SmallIntTest extends DbalTestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = Type::getType('smallint'); + $this->type = new SmallIntType(); } public function testSmallIntConvertsToPHPValue(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/StringTest.php b/tests/Doctrine/Tests/DBAL/Types/StringTest.php index 4f62fed044a..5041e942e75 100644 --- a/tests/Doctrine/Tests/DBAL/Types/StringTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/StringTest.php @@ -4,7 +4,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\StringType; -use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; @@ -19,7 +18,7 @@ class StringTest extends DbalTestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = Type::getType('string'); + $this->type = new StringType(); } public function testReturnsSqlDeclarationFromPlatformVarchar(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php index 4d664f4966f..b2365f54a40 100644 --- a/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php @@ -8,7 +8,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\TimeImmutableType; -use Doctrine\DBAL\Types\Type; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -24,8 +23,8 @@ class TimeImmutableTypeTest extends TestCase protected function setUp(): void { - $this->type = Type::getType('time_immutable'); $this->platform = $this->getMockBuilder(AbstractPlatform::class)->getMock(); + $this->type = new TimeImmutableType(); } public function testFactoryCreatesCorrectType(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/TimeTest.php b/tests/Doctrine/Tests/DBAL/Types/TimeTest.php index 358fa6e0a38..ceb1e9ee7d0 100644 --- a/tests/Doctrine/Tests/DBAL/Types/TimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/TimeTest.php @@ -4,13 +4,13 @@ use DateTime; use Doctrine\DBAL\Types\ConversionException; -use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\TimeType; class TimeTest extends BaseDateTypeTestCase { protected function setUp(): void { - $this->type = Type::getType('time'); + $this->type = new TimeType(); parent::setUp(); } diff --git a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php index 3326e13ac72..442409ac425 100644 --- a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php @@ -7,7 +7,6 @@ use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; -use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\VarDateTimeImmutableType; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -22,12 +21,8 @@ class VarDateTimeImmutableTypeTest extends TestCase protected function setUp(): void { - if (! Type::hasType('vardatetime_immutable')) { - Type::addType('vardatetime_immutable', VarDateTimeImmutableType::class); - } - - $this->type = Type::getType('vardatetime_immutable'); $this->platform = $this->getMockForAbstractClass(AbstractPlatform::class); + $this->type = new VarDateTimeImmutableType(); } public function testReturnsName(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php index a82e07949ee..206c2e094d5 100644 --- a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php @@ -5,7 +5,6 @@ use DateTime; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; -use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\VarDateTimeType; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; @@ -21,11 +20,7 @@ class VarDateTimeTest extends DbalTestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - if (! Type::hasType('vardatetime')) { - Type::addType('vardatetime', VarDateTimeType::class); - } - - $this->type = Type::getType('vardatetime'); + $this->type = new VarDateTimeType(); } public function testDateTimeConvertsToDatabaseValue(): void From df6020aadb26af458be507df00f858bd9bbc347f Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 14 Oct 2020 15:12:57 -0700 Subject: [PATCH 36/56] Fix ArgumentTypeCoercion issues about class-strings --- lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php | 6 +++--- .../DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php | 6 +++--- .../DBAL/Tools/Console/Command/ReservedWordsCommand.php | 7 ++++--- lib/Doctrine/DBAL/Types/Type.php | 8 ++++---- tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php | 3 ++- tests/Doctrine/Tests/TestUtil.php | 3 +++ 6 files changed, 19 insertions(+), 14 deletions(-) diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php index 02cc6526907..483581fedfe 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php @@ -455,9 +455,9 @@ public function free(): void /** * Casts a stdClass object to the given class name mapping its' properties. * - * @param stdClass $sourceObject Object to cast from. - * @param string|object $destinationClass Name of the class or class instance to cast to. - * @param mixed[] $ctorArgs Arguments to use for constructing the destination class instance. + * @param stdClass $sourceObject Object to cast from. + * @param class-string|object $destinationClass Name of the class or class instance to cast to. + * @param mixed[] $ctorArgs Arguments to use for constructing the destination class instance. * * @return object * diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php index 1542276dba2..513e4a508ef 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php @@ -419,9 +419,9 @@ 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 string|object $destinationClass Name of the class or class instance to cast to. - * @param mixed[] $ctorArgs Arguments to use for constructing the destination class instance. + * @param stdClass $sourceObject Object to cast from. + * @param class-string|object $destinationClass Name of the class or class instance to cast to. + * @param mixed[] $ctorArgs Arguments to use for constructing the destination class instance. * * @return object * diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php index 1888efdb619..bd819af0e6a 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php @@ -4,6 +4,7 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Platforms\Keywords\DB2Keywords; +use Doctrine\DBAL\Platforms\Keywords\KeywordList; use Doctrine\DBAL\Platforms\Keywords\MySQL57Keywords; use Doctrine\DBAL\Platforms\Keywords\MySQL80Keywords; use Doctrine\DBAL\Platforms\Keywords\MySQLKeywords; @@ -41,7 +42,7 @@ class ReservedWordsCommand extends Command { - /** @var string[] */ + /** @var array> */ private $keywordListClasses = [ 'mysql' => MySQLKeywords::class, 'mysql57' => MySQL57Keywords::class, @@ -82,8 +83,8 @@ public function __construct(?ConnectionProvider $connectionProvider = null) /** * If you want to add or replace a keywords list use this command. * - * @param string $name - * @param string $class + * @param string $name + * @param class-string $class * * @return void */ diff --git a/lib/Doctrine/DBAL/Types/Type.php b/lib/Doctrine/DBAL/Types/Type.php index 5ff51c4c9bb..f8be9131bcd 100644 --- a/lib/Doctrine/DBAL/Types/Type.php +++ b/lib/Doctrine/DBAL/Types/Type.php @@ -236,8 +236,8 @@ public static function getType($name) /** * Adds a custom type to the type map. * - * @param string $name The name of the type. This should correspond to what getName() returns. - * @param string $className The class name of the custom type. + * @param string $name The name of the type. This should correspond to what getName() returns. + * @param class-string $className The class name of the custom type. * * @return void * @@ -263,8 +263,8 @@ public static function hasType($name) /** * Overrides an already defined type to use a different implementation. * - * @param string $name - * @param string $className + * @param string $name + * @param class-string $className * * @return void * diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php index 078875a4086..c08b33fb898 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php @@ -70,7 +70,8 @@ protected function setUp(): void } /** - * @param int|string $errorCode + * @param int|string $errorCode + * @param class-string $expectedClass * * @dataProvider exceptionConversionProvider */ diff --git a/tests/Doctrine/Tests/TestUtil.php b/tests/Doctrine/Tests/TestUtil.php index f45ee6e232f..3a21df3910e 100644 --- a/tests/Doctrine/Tests/TestUtil.php +++ b/tests/Doctrine/Tests/TestUtil.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests; +use Doctrine\Common\EventSubscriber; use Doctrine\DBAL\Connection; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Platforms\AbstractPlatform; @@ -137,6 +138,8 @@ private static function addDbEventSubscribers(Connection $conn): void } $evm = $conn->getEventManager(); + + /** @psalm-var class-string $subscriberClass */ foreach (explode(',', $GLOBALS['db_event_subscribers']) as $subscriberClass) { $subscriberInstance = new $subscriberClass(); $evm->addEventSubscriber($subscriberInstance); From 759a2982badbe73174382c61493fae17c175926c Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 14 Oct 2020 15:16:22 -0700 Subject: [PATCH 37/56] Fix NullArgument issues --- lib/Doctrine/DBAL/Configuration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/DBAL/Configuration.php b/lib/Doctrine/DBAL/Configuration.php index 6d2497b632d..545b0ffb0b4 100644 --- a/lib/Doctrine/DBAL/Configuration.php +++ b/lib/Doctrine/DBAL/Configuration.php @@ -73,7 +73,7 @@ public function setResultCacheImpl(Cache $cacheImpl) * * @deprecated Use Configuration::setSchemaAssetsFilter() instead * - * @param string $filterExpression + * @param string|null $filterExpression * * @return void */ From 8c1e546448e92370702b5570d7dd7014b7c494e2 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 14 Oct 2020 15:20:35 -0700 Subject: [PATCH 38/56] Fix PossiblyNullArgument issues --- .../DBAL/Cache/ResultCacheStatement.php | 2 +- .../DBAL/Driver/SQLAnywhere/Driver.php | 18 +++++++++--------- .../DBAL/Platforms/SQLServerPlatform.php | 4 ++-- .../DBAL/Schema/PostgreSqlSchemaManager.php | 18 +++++++++++------- .../Platforms/AbstractPlatformTestCase.php | 2 +- 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php index 34381e23b1c..07a6c220611 100644 --- a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php +++ b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php @@ -244,7 +244,7 @@ public function fetchAllNumeric(): array $this->store($data); - return array_map('array_values', $this->data); + return array_map('array_values', $data); } /** diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php index 95b59274e9e..81d88232dca 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php @@ -52,15 +52,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 mixed[] $driverOptions Additional parameters to use for the connection. + * @param string|null $host Host address to connect to. + * @param int|null $port Port to use for the connection (default to SQL Anywhere standard port 2638). + * @param string|null $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|null $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/Platforms/SQLServerPlatform.php b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php index 2b45883b3fa..b41f33bef46 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php @@ -1199,10 +1199,10 @@ public function getAsciiStringTypeDeclarationSQL(array $column): string $length = $column['length'] ?? null; if (! isset($column['fixed'])) { - return sprintf('VARCHAR(%d)', $length); + return sprintf('VARCHAR(%d)', $length ?? 255); } - return sprintf('CHAR(%d)', $length); + return sprintf('CHAR(%d)', $length ?? 255); } /** diff --git a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php index d9fabec1660..20cb5f7277e 100644 --- a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php @@ -150,13 +150,17 @@ protected function _getPortableTableForeignKeyDefinition($tableForeignKey) $onDelete = $match[1]; } - 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]; - } + assert(preg_match( + '/FOREIGN KEY \((.+)\) REFERENCES (.+)\((.+)\)/', + $tableForeignKey['condef'], + $values + ) !== 0); + + // 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]; return new ForeignKeyConstraint( $localColumns, diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php index 9ef99d6d416..943adb99f47 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php @@ -1159,7 +1159,7 @@ public function testGetCommentOnColumnSQL(): void /** * @dataProvider getGeneratesInlineColumnCommentSQL */ - public function testGeneratesInlineColumnCommentSQL(?string $comment, string $expectedSql): void + public function testGeneratesInlineColumnCommentSQL(string $comment, string $expectedSql): void { if (! $this->platform->supportsInlineColumnComments()) { $this->markTestSkipped(sprintf('%s does not support inline column comments.', get_class($this->platform))); From ac75ed5ef13b305e7fc44de7f0fcf2aa2c062027 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 14 Oct 2020 15:38:24 -0700 Subject: [PATCH 39/56] Account for the fact that error_get_last() may return NULL --- lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php | 2 +- lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php | 6 +++--- .../IBMDB2/Exception/CannotCopyStreamToStream.php | 13 +++++++++++-- .../IBMDB2/Exception/CannotCreateTemporaryFile.php | 13 +++++++++++-- .../IBMDB2/Exception/CannotWriteToTemporaryFile.php | 13 +++++++++++-- .../DBAL/Driver/IBMDB2/Exception/PrepareFailed.php | 11 +++++++++-- .../DBAL/Tools/Console/Command/ImportCommand.php | 11 ++++++++--- 7 files changed, 54 insertions(+), 15 deletions(-) diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php index dc2701e344a..4143255e555 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php @@ -93,7 +93,7 @@ public function prepare($sql) $stmt = @db2_prepare($this->conn, $sql); if ($stmt === false) { - throw PrepareFailed::new(error_get_last()['message']); + throw PrepareFailed::new(error_get_last()); } return new Statement($stmt); diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php index 483581fedfe..c758a253d0a 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php @@ -527,7 +527,7 @@ private function createTemporaryFile() $handle = @tmpfile(); if ($handle === false) { - throw CannotCreateTemporaryFile::new(error_get_last()['message']); + throw CannotCreateTemporaryFile::new(error_get_last()); } return $handle; @@ -542,7 +542,7 @@ private function createTemporaryFile() private function copyStreamToStream($source, $target): void { if (@stream_copy_to_stream($source, $target) === false) { - throw CannotCopyStreamToStream::new(error_get_last()['message']); + throw CannotCopyStreamToStream::new(error_get_last()); } } @@ -554,7 +554,7 @@ private function copyStreamToStream($source, $target): void private function writeStringToStream(string $string, $target): void { if (@fwrite($target, $string) === false) { - throw CannotWriteToTemporaryFile::new(error_get_last()['message']); + throw CannotWriteToTemporaryFile::new(error_get_last()); } } } diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotCopyStreamToStream.php b/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotCopyStreamToStream.php index 8223a92d660..61244c1cc61 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotCopyStreamToStream.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotCopyStreamToStream.php @@ -13,8 +13,17 @@ */ final class CannotCopyStreamToStream extends DB2Exception { - public static function new(string $message): self + /** + * @psalm-param array{message: string}|null $error + */ + public static function new(?array $error): self { - return new self('Could not copy source stream to temporary file: ' . $message); + $message = 'Could not copy source stream to temporary file'; + + if ($error !== null) { + $message .= ': ' . $error['message']; + } + + return new self($message); } } diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotCreateTemporaryFile.php b/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotCreateTemporaryFile.php index 48b28dd33d3..d5481ed9e31 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotCreateTemporaryFile.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotCreateTemporaryFile.php @@ -13,8 +13,17 @@ */ final class CannotCreateTemporaryFile extends DB2Exception { - public static function new(string $message): self + /** + * @psalm-param array{message: string}|null $error + */ + public static function new(?array $error): self { - return new self('Could not create temporary file: ' . $message); + $message = 'Could not create temporary file'; + + if ($error !== null) { + $message .= ': ' . $error['message']; + } + + return new self($message); } } diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotWriteToTemporaryFile.php b/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotWriteToTemporaryFile.php index 8acc269a4ad..33d0b86cc4f 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotWriteToTemporaryFile.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotWriteToTemporaryFile.php @@ -13,8 +13,17 @@ */ final class CannotWriteToTemporaryFile extends DB2Exception { - public static function new(string $message): self + /** + * @psalm-param array{message: string}|null $error + */ + public static function new(?array $error): self { - return new self('Could not write string to temporary file: ' . $message); + $message = 'Could not write string to temporary file'; + + if ($error !== null) { + $message .= ': ' . $error['message']; + } + + return new self($message); } } diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/PrepareFailed.php b/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/PrepareFailed.php index f566df8d50d..035fd67f9c2 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/PrepareFailed.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/PrepareFailed.php @@ -13,8 +13,15 @@ */ final class PrepareFailed extends AbstractException { - public static function new(string $message): self + /** + * @psalm-param array{message: string}|null $error + */ + public static function new(?array $error): self { - return new self($message); + if ($error === null) { + return new self('Unknown error'); + } + + return new self($error['message']); } } diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php index 3d53f342968..26456bde0ce 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php @@ -85,9 +85,14 @@ protected function execute(InputInterface $input, OutputInterface $output) $sql = @file_get_contents($filePath); if ($sql === false) { - throw new RuntimeException( - sprintf("Unable to read SQL file '%s': %s", $filePath, error_get_last()['message']) - ); + $message = sprintf("Unable to read SQL file '%s'", $filePath); + $error = error_get_last(); + + if ($error !== null) { + $message .= ': ' . $error['message']; + } + + throw new RuntimeException($message); } if ($conn instanceof PDOConnection) { From 79a5aab29afdb2021072c120b33763ab010932d1 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 14 Oct 2020 17:16:56 -0700 Subject: [PATCH 40/56] Fix PossiblyNullPropertyAssignmentValue issues and remove redundant NULL assignments --- lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php | 2 +- .../DBAL/Event/SchemaColumnDefinitionEventArgs.php | 2 +- lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php | 2 +- .../DBAL/Event/SchemaIndexDefinitionEventArgs.php | 2 +- lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | 4 ++-- lib/Doctrine/DBAL/Platforms/Keywords/KeywordList.php | 2 +- lib/Doctrine/DBAL/Query/QueryBuilder.php | 4 ++-- lib/Doctrine/DBAL/Schema/AbstractAsset.php | 2 +- lib/Doctrine/DBAL/Schema/Column.php | 8 ++++---- lib/Doctrine/DBAL/Schema/Sequence.php | 2 +- lib/Doctrine/DBAL/Schema/Table.php | 2 +- .../DBAL/Schema/Visitor/CreateSchemaSqlCollector.php | 2 +- 12 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php index 4143255e555..bdc52551f52 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php @@ -37,7 +37,7 @@ class DB2Connection implements ConnectionInterface, ServerInfoAwareConnection { /** @var resource */ - private $conn = null; + private $conn; /** * @internal The connection can be only instantiated by its driver. diff --git a/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php index 2be445e38af..7c962a928f4 100644 --- a/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php @@ -12,7 +12,7 @@ class SchemaColumnDefinitionEventArgs extends SchemaEventArgs { /** @var Column|null */ - private $column = null; + private $column; /** * Raw column data as fetched from the database. diff --git a/lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php index 1236de401ab..072e1efb909 100644 --- a/lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php @@ -18,7 +18,7 @@ class SchemaDropTableEventArgs extends SchemaEventArgs private $platform; /** @var string|null */ - private $sql = null; + private $sql; /** * @param string|Table $table diff --git a/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php index ca6bbf81f7e..055a19a7c27 100644 --- a/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php @@ -12,7 +12,7 @@ class SchemaIndexDefinitionEventArgs extends SchemaEventArgs { /** @var Index|null */ - private $index = null; + private $index; /** * Raw index data as fetched from the database. diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index ba551574651..b99a4beb66b 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -132,7 +132,7 @@ abstract class AbstractPlatform public const TRIM_BOTH = TrimMode::BOTH; /** @var string[]|null */ - protected $doctrineTypeMapping = null; + protected $doctrineTypeMapping; /** * Contains a list of all columns that should generate parseable column comments for type-detection @@ -140,7 +140,7 @@ abstract class AbstractPlatform * * @var string[]|null */ - protected $doctrineTypeComments = null; + protected $doctrineTypeComments; /** @var EventManager */ protected $_eventManager; diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/KeywordList.php b/lib/Doctrine/DBAL/Platforms/Keywords/KeywordList.php index 860d9f21099..852a58aba2b 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/KeywordList.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/KeywordList.php @@ -12,7 +12,7 @@ abstract class KeywordList { /** @var string[]|null */ - private $keywords = null; + private $keywords; /** * Checks if the given word is a keyword of this dialect/vendor platform. diff --git a/lib/Doctrine/DBAL/Query/QueryBuilder.php b/lib/Doctrine/DBAL/Query/QueryBuilder.php index c0c0ea58451..492a06951bb 100644 --- a/lib/Doctrine/DBAL/Query/QueryBuilder.php +++ b/lib/Doctrine/DBAL/Query/QueryBuilder.php @@ -119,14 +119,14 @@ class QueryBuilder * * @var int */ - private $firstResult = null; + private $firstResult; /** * The maximum number of results to retrieve or NULL to retrieve all results. * * @var int|null */ - private $maxResults = null; + private $maxResults; /** * The counter of bound parameters used with {@see bindValue). diff --git a/lib/Doctrine/DBAL/Schema/AbstractAsset.php b/lib/Doctrine/DBAL/Schema/AbstractAsset.php index 3424b17c544..02111832e26 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractAsset.php +++ b/lib/Doctrine/DBAL/Schema/AbstractAsset.php @@ -31,7 +31,7 @@ abstract class AbstractAsset * * @var string|null */ - protected $_namespace = null; + protected $_namespace; /** @var bool */ protected $_quoted = false; diff --git a/lib/Doctrine/DBAL/Schema/Column.php b/lib/Doctrine/DBAL/Schema/Column.php index e33f285108b..f63bcc9226b 100644 --- a/lib/Doctrine/DBAL/Schema/Column.php +++ b/lib/Doctrine/DBAL/Schema/Column.php @@ -21,7 +21,7 @@ class Column extends AbstractAsset protected $_type; /** @var int|null */ - protected $_length = null; + protected $_length; /** @var int */ protected $_precision = 10; @@ -39,7 +39,7 @@ class Column extends AbstractAsset protected $_notnull = true; /** @var string|null */ - protected $_default = null; + protected $_default; /** @var bool */ protected $_autoincrement = false; @@ -48,10 +48,10 @@ class Column extends AbstractAsset protected $_platformOptions = []; /** @var string|null */ - protected $_columnDefinition = null; + protected $_columnDefinition; /** @var string|null */ - protected $_comment = null; + protected $_comment; /** @var mixed[] */ protected $_customSchemaOptions = []; diff --git a/lib/Doctrine/DBAL/Schema/Sequence.php b/lib/Doctrine/DBAL/Schema/Sequence.php index 19dec9cd57a..1cba86c086c 100644 --- a/lib/Doctrine/DBAL/Schema/Sequence.php +++ b/lib/Doctrine/DBAL/Schema/Sequence.php @@ -19,7 +19,7 @@ class Sequence extends AbstractAsset protected $initialValue = 1; /** @var int|null */ - protected $cache = null; + protected $cache; /** * @param string $name diff --git a/lib/Doctrine/DBAL/Schema/Table.php b/lib/Doctrine/DBAL/Schema/Table.php index bd0462151a4..740092d3ca1 100644 --- a/lib/Doctrine/DBAL/Schema/Table.php +++ b/lib/Doctrine/DBAL/Schema/Table.php @@ -41,7 +41,7 @@ class Table extends AbstractAsset ]; /** @var SchemaConfig|null */ - protected $_schemaConfig = null; + protected $_schemaConfig; /** * @param string $name diff --git a/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php b/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php index b2fab3ae4af..c08fb6fecd8 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php @@ -24,7 +24,7 @@ class CreateSchemaSqlCollector extends AbstractVisitor private $createFkConstraintQueries = []; /** @var AbstractPlatform */ - private $platform = null; + private $platform; public function __construct(AbstractPlatform $platform) { From e8e0bc408b3817aa4c8915665bae61da154cb114 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 14 Oct 2020 17:48:06 -0700 Subject: [PATCH 41/56] Fix MoreSpecificReturnType issues --- lib/Doctrine/DBAL/DriverManager.php | 3 ++- tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php | 6 +++++- .../Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php | 6 +++++- .../Tests/DBAL/Functional/MasterSlaveConnectionTest.php | 6 +++++- .../DBAL/Functional/PrimaryReadReplicaConnectionTest.php | 6 +++++- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/DBAL/DriverManager.php b/lib/Doctrine/DBAL/DriverManager.php index 5b12e4871bb..17ba8584da2 100644 --- a/lib/Doctrine/DBAL/DriverManager.php +++ b/lib/Doctrine/DBAL/DriverManager.php @@ -113,7 +113,7 @@ private function __construct() * driverClass: * The driver class to use. * - * @param array{wrapperClass?: class-string} $params + * @param array{wrapperClass?: class-string} $params * @param Configuration|null $config The configuration to use. * @param EventManager|null $eventManager The event manager to use. * @@ -195,6 +195,7 @@ public static function getConnection( throw Exception::invalidWrapperClass($params['wrapperClass']); } + /** @var class-string $wrapperClass */ $wrapperClass = $params['wrapperClass']; } diff --git a/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php index 4a7044594f3..bfef87d5de4 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php @@ -84,11 +84,15 @@ private function connect(array $driverOptions): Connection { $params = TestUtil::getConnectionParams(); - return $this->createDriver()->connect( + $connection = $this->createDriver()->connect( $params, $params['user'] ?? '', $params['password'] ?? '', $driverOptions ); + + self::assertInstanceOf(Connection::class, $connection); + + return $connection; } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php index d829a013ea7..f8974ef7b14 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php @@ -48,12 +48,16 @@ private function getConnection(array $driverOptions): Connection $driverOptions = array_merge($params['driverOptions'], $driverOptions); } - return $this->connection->getDriver()->connect( + $connection = $this->connection->getDriver()->connect( $params, $params['user'] ?? '', $params['password'] ?? '', $driverOptions ); + + self::assertInstanceOf(Connection::class, $connection); + + return $connection; } public function testConnectionOptions(): void diff --git a/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php index 13aaea3c6a9..4b842e77654 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php @@ -46,7 +46,11 @@ protected function setUp(): void private function createMasterSlaveConnection(bool $keepSlave = false): MasterSlaveConnection { - return DriverManager::getConnection($this->createMasterSlaveConnectionParams($keepSlave)); + $connection = DriverManager::getConnection($this->createMasterSlaveConnectionParams($keepSlave)); + + self::assertInstanceOf(MasterSlaveConnection::class, $connection); + + return $connection; } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/PrimaryReadReplicaConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/PrimaryReadReplicaConnectionTest.php index 7dd14c355ee..1bbd094e2d3 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/PrimaryReadReplicaConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/PrimaryReadReplicaConnectionTest.php @@ -49,7 +49,11 @@ protected function setUp(): void private function createPrimaryReadReplicaConnection(bool $keepReplica = false): PrimaryReadReplicaConnection { - return DriverManager::getConnection($this->createPrimaryReadReplicaConnectionParams($keepReplica)); + $connection = DriverManager::getConnection($this->createPrimaryReadReplicaConnectionParams($keepReplica)); + + self::assertInstanceOf(PrimaryReadReplicaConnection::class, $connection); + + return $connection; } /** From 5c60ae2b6178ace4ccc3d28b035f1ac580dc3915 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 14 Oct 2020 17:50:58 -0700 Subject: [PATCH 42/56] Fix OCI-Lob assertion --- lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php index d019d74576f..cbb8a851b27 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php @@ -299,8 +299,7 @@ public function bindParam($param, &$variable, $type = ParameterType::STRING, $le if ($type === ParameterType::LARGE_OBJECT) { $lob = oci_new_descriptor($this->_dbh, OCI_D_LOB); - $class = 'OCI-Lob'; - assert($lob instanceof $class); + assert($lob !== false); $lob->writeTemporary($variable, OCI_TEMP_BLOB); From 2dacdf815e47b700713c63e12e79bfdb38530b34 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 14 Oct 2020 18:06:02 -0700 Subject: [PATCH 43/56] Fix PossiblyNullReference issues --- .../DBAL/Platforms/SqlitePlatform.php | 30 ++++++++++--------- .../Schema/OracleSchemaManagerTest.php | 12 ++++++-- .../Schema/PostgreSqlSchemaManagerTest.php | 6 +++- .../SQLAzure/MultiTenantVisitorTest.php | 24 ++++++++++----- 4 files changed, 47 insertions(+), 25 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php index c33970fc142..e42a6bd89ec 100644 --- a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php @@ -719,7 +719,9 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) */ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff) { - if (! $diff->fromTable instanceof Table) { + $fromTable = $diff->fromTable; + + if (! $fromTable instanceof Table) { throw new Exception( 'Sqlite platform requires for alter table the table diff with reference to original table schema' ); @@ -732,7 +734,7 @@ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff) $tableName = $diff->getName($this); } - foreach ($this->getIndexesInAlteredTable($diff) as $index) { + foreach ($this->getIndexesInAlteredTable($diff, $fromTable) as $index) { if ($index->isPrimary()) { continue; } @@ -952,8 +954,8 @@ public function getAlterTableSQL(TableDiff $diff) $newTable = new Table( $table->getQuotedName($this), $columns, - $this->getPrimaryIndexInAlteredTable($diff), - $this->getForeignKeysInAlteredTable($diff), + $this->getPrimaryIndexInAlteredTable($diff, $fromTable), + $this->getForeignKeysInAlteredTable($diff, $fromTable), 0, $table->getOptions() ); @@ -1092,11 +1094,11 @@ private function getSimpleAlterTableSQL(TableDiff $diff) /** * @return string[] */ - private function getColumnNamesInAlteredTable(TableDiff $diff) + private function getColumnNamesInAlteredTable(TableDiff $diff, Table $fromTable) { $columns = []; - foreach ($diff->fromTable->getColumns() as $columnName => $column) { + foreach ($fromTable->getColumns() as $columnName => $column) { $columns[strtolower($columnName)] = $column->getName(); } @@ -1132,10 +1134,10 @@ private function getColumnNamesInAlteredTable(TableDiff $diff) /** * @return Index[] */ - private function getIndexesInAlteredTable(TableDiff $diff) + private function getIndexesInAlteredTable(TableDiff $diff, Table $fromTable) { - $indexes = $diff->fromTable->getIndexes(); - $columnNames = $this->getColumnNamesInAlteredTable($diff); + $indexes = $fromTable->getIndexes(); + $columnNames = $this->getColumnNamesInAlteredTable($diff, $fromTable); foreach ($indexes as $key => $index) { foreach ($diff->renamedIndexes as $oldIndexName => $renamedIndex) { @@ -1200,10 +1202,10 @@ private function getIndexesInAlteredTable(TableDiff $diff) /** * @return ForeignKeyConstraint[] */ - private function getForeignKeysInAlteredTable(TableDiff $diff) + private function getForeignKeysInAlteredTable(TableDiff $diff, Table $fromTable) { - $foreignKeys = $diff->fromTable->getForeignKeys(); - $columnNames = $this->getColumnNamesInAlteredTable($diff); + $foreignKeys = $fromTable->getForeignKeys(); + $columnNames = $this->getColumnNamesInAlteredTable($diff, $fromTable); foreach ($foreignKeys as $key => $constraint) { $changed = false; @@ -1264,11 +1266,11 @@ private function getForeignKeysInAlteredTable(TableDiff $diff) /** * @return Index[] */ - private function getPrimaryIndexInAlteredTable(TableDiff $diff) + private function getPrimaryIndexInAlteredTable(TableDiff $diff, Table $fromTable) { $primaryIndex = []; - foreach ($this->getIndexesInAlteredTable($diff) as $index) { + foreach ($this->getIndexesInAlteredTable($diff, $fromTable) as $index) { if (! $index->isPrimary()) { continue; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php index d39b7373216..4b5846e247f 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php @@ -169,7 +169,11 @@ public function testListTableDetailsWithDifferentIdentifierQuotingRequirements() self::assertTrue($onlinePrimaryTable->hasColumn('"Id"')); self::assertSame('"Id"', $onlinePrimaryTable->getColumn('"Id"')->getQuotedName($platform)); self::assertTrue($onlinePrimaryTable->hasPrimaryKey()); - self::assertSame(['"Id"'], $onlinePrimaryTable->getPrimaryKey()->getQuotedColumns($platform)); + + $primaryKey = $onlinePrimaryTable->getPrimaryKey(); + + self::assertNotNull($primaryKey); + self::assertSame(['"Id"'], $primaryKey->getQuotedColumns($platform)); self::assertTrue($onlinePrimaryTable->hasColumn('select')); self::assertSame('"select"', $onlinePrimaryTable->getColumn('select')->getQuotedName($platform)); @@ -203,7 +207,11 @@ public function testListTableDetailsWithDifferentIdentifierQuotingRequirements() self::assertTrue($onlineForeignTable->hasColumn('id')); self::assertSame('ID', $onlineForeignTable->getColumn('id')->getQuotedName($platform)); self::assertTrue($onlineForeignTable->hasPrimaryKey()); - self::assertSame(['ID'], $onlineForeignTable->getPrimaryKey()->getQuotedColumns($platform)); + + $primaryKey = $onlineForeignTable->getPrimaryKey(); + + self::assertNotNull($primaryKey); + self::assertSame(['ID'], $primaryKey->getQuotedColumns($platform)); self::assertTrue($onlineForeignTable->hasColumn('"Fk"')); self::assertSame('"Fk"', $onlineForeignTable->getColumn('"Fk"')->getQuotedName($platform)); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php index aadf78a8b48..ae97380d257 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php @@ -161,7 +161,11 @@ public function testTableWithSchema(): void $nestedSchemaTable = $this->schemaManager->listTableDetails('nested.schematable'); self::assertTrue($nestedSchemaTable->hasColumn('id')); - self::assertEquals(['id'], $nestedSchemaTable->getPrimaryKey()->getColumns()); + + $primaryKey = $nestedSchemaTable->getPrimaryKey(); + + self::assertNotNull($primaryKey); + self::assertEquals(['id'], $primaryKey->getColumns()); $relatedFks = $nestedSchemaTable->getForeignKeys(); self::assertCount(1, $relatedFks); diff --git a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/MultiTenantVisitorTest.php b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/MultiTenantVisitorTest.php index f12379fafee..560181996e3 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/MultiTenantVisitorTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/MultiTenantVisitorTest.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\DBAL\Sharding\SQLAzure; -use Doctrine\DBAL\Platforms\SQLAzurePlatform; use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Sharding\SQLAzure\Schema\MultiTenantVisitor; use PHPUnit\Framework\TestCase; @@ -11,8 +10,7 @@ class MultiTenantVisitorTest extends TestCase { public function testMultiTenantPrimaryKey(): void { - $platform = new SQLAzurePlatform(); - $visitor = new MultiTenantVisitor(); + $visitor = new MultiTenantVisitor(); $schema = new Schema(); $foo = $schema->createTable('foo'); @@ -20,14 +18,16 @@ public function testMultiTenantPrimaryKey(): void $foo->setPrimaryKey(['id']); $schema->visit($visitor); - self::assertEquals(['id', 'tenant_id'], $foo->getPrimaryKey()->getColumns()); + $primaryKey = $foo->getPrimaryKey(); + + self::assertNotNull($primaryKey); + self::assertEquals(['id', 'tenant_id'], $primaryKey->getColumns()); self::assertTrue($foo->hasColumn('tenant_id')); } public function testMultiTenantNonPrimaryKey(): void { - $platform = new SQLAzurePlatform(); - $visitor = new MultiTenantVisitor(); + $visitor = new MultiTenantVisitor(); $schema = new Schema(); $foo = $schema->createTable('foo'); @@ -36,12 +36,20 @@ public function testMultiTenantNonPrimaryKey(): void $foo->setPrimaryKey(['id']); $foo->addIndex(['created'], 'idx'); - $foo->getPrimaryKey()->addFlag('nonclustered'); + $primaryKey = $foo->getPrimaryKey(); + + self::assertNotNull($primaryKey); + + $primaryKey->addFlag('nonclustered'); $foo->getIndex('idx')->addFlag('clustered'); $schema->visit($visitor); - self::assertEquals(['id'], $foo->getPrimaryKey()->getColumns()); + $primaryKey = $foo->getPrimaryKey(); + + self::assertNotNull($primaryKey); + + self::assertEquals(['id'], $primaryKey->getColumns()); self::assertTrue($foo->hasColumn('tenant_id')); self::assertEquals(['created', 'tenant_id'], $foo->getIndex('idx')->getColumns()); } From d85350286057bf0f008840c01032af2d2035ccb6 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 14 Oct 2020 18:26:48 -0700 Subject: [PATCH 44/56] Fix PossiblyUndefinedVariable issues --- .../DBAL/Platforms/AbstractPlatform.php | 2 +- .../SQLAzureFederationsSynchronizer.php | 2 ++ tests/Doctrine/Tests/DBAL/ConnectionTest.php | 8 ++----- .../Tests/DBAL/Functional/DataAccessTest.php | 22 +++++++++++-------- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index b99a4beb66b..5580ea23dea 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -1742,7 +1742,7 @@ protected function _getCreateTableSQL($name, array $columns, array $options = [] $query .= ')'; - $sql[] = $query; + $sql = [$query]; if (isset($options['foreignKeys'])) { foreach ((array) $options['foreignKeys'] as $definition) { diff --git a/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php b/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php index 7ea9ce1fad3..5fa2aa782eb 100644 --- a/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php +++ b/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php @@ -125,6 +125,8 @@ public function getDropAllSchema() $this->shardManager->selectGlobal(); $globalSql = $this->synchronizer->getDropAllSchema(); + $sql = []; + if ($globalSql) { $sql[] = "-- Work on Root Federation\nUSE FEDERATION ROOT WITH RESET;"; $sql = array_merge($sql, $globalSql); diff --git a/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/ConnectionTest.php index feed00275a2..675881ac207 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -648,22 +648,18 @@ public function testFetchAll(): void public function testConnectionDoesNotMaintainTwoReferencesToExternalPDO(): void { - $params['pdo'] = new stdClass(); - $driverMock = $this->createMock(Driver::class); - $conn = new Connection($params, $driverMock); + $conn = new Connection(['pdo' => new stdClass()], $driverMock); self::assertArrayNotHasKey('pdo', $conn->getParams()); } public function testPassingExternalPDOMeansConnectionIsConnected(): void { - $params['pdo'] = new stdClass(); - $driverMock = $this->createMock(Driver::class); - $conn = new Connection($params, $driverMock); + $conn = new Connection(['pdo' => new stdClass()], $driverMock); self::assertTrue($conn->isConnected(), 'Connection is not connected after passing external PDO'); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php index d4123c79188..83b7b6984c8 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php @@ -27,7 +27,6 @@ use function array_keys; use function count; use function date; -use function implode; use function is_numeric; use function json_encode; use function property_exists; @@ -35,7 +34,6 @@ use function strtotime; use const CASE_LOWER; -use const PHP_EOL; class DataAccessTest extends DbalFunctionalTestCase { @@ -682,14 +680,20 @@ public function testBitComparisonExpressionSupport(): void ]); } - $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 = sprintf( + <<<'SQL' +SELECT test_int, + test_string, + %s AS bit_or, + %s AS bit_and +FROM fetch_table +SQL + , + $platform->getBitOrComparisonExpression('test_int', 2), + $platform->getBitAndComparisonExpression('test_int', 2) + ); - $stmt = $this->connection->executeQuery(implode(PHP_EOL, $sql)); + $stmt = $this->connection->executeQuery($sql); $data = $stmt->fetchAll(FetchMode::ASSOCIATIVE); self::assertCount(4, $data); From 1398eb461a9786a41b8b88379041567334897b8c Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 15 Oct 2020 19:07:41 -0700 Subject: [PATCH 45/56] Fix PossiblyFalseArgument issues --- .../DBAL/Schema/PostgreSqlSchemaManager.php | 6 +- .../Tests/DBAL/Functional/DataAccessTest.php | 6 ++ .../Functional/MasterSlaveConnectionTest.php | 10 +-- .../PrimaryReadReplicaConnectionTest.php | 8 +-- .../Schema/MySqlSchemaManagerTest.php | 32 ++++++---- .../Schema/OracleSchemaManagerTest.php | 15 +++-- .../Schema/PostgreSqlSchemaManagerTest.php | 13 ++-- .../SchemaManagerFunctionalTestCase.php | 20 +++--- .../Schema/SqliteSchemaManagerTest.php | 6 +- .../DBAL/Functional/Ticket/DBAL421Test.php | 4 +- .../AbstractMySQLPlatformTestCase.php | 61 +++++++++++-------- .../Platforms/AbstractPlatformTestCase.php | 10 +-- .../AbstractPostgreSqlPlatformTestCase.php | 18 ++++-- .../DBAL/Platforms/OraclePlatformTest.php | 4 +- .../DBAL/Schema/Platforms/MySQLSchemaTest.php | 8 ++- .../Doctrine/Tests/DBAL/Schema/TableTest.php | 2 +- .../Sharding/SQLAzure/AbstractTestCase.php | 1 + .../Doctrine/Tests/DBAL/Tools/DumperTest.php | 12 ---- 18 files changed, 133 insertions(+), 103 deletions(-) diff --git a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php index 20cb5f7277e..e64a9c81735 100644 --- a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php @@ -60,7 +60,11 @@ public function getSchemaNames() public function getSchemaSearchPaths() { $params = $this->_conn->getParams(); - $schema = explode(',', $this->_conn->fetchColumn('SHOW search_path')); + + $searchPaths = $this->_conn->fetchColumn('SHOW search_path'); + assert($searchPaths !== false); + + $schema = explode(',', $searchPaths); if (isset($params['user'])) { $schema = str_replace('"$user"', $params['user'], $schema); diff --git a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php index 83b7b6984c8..355f8fef368 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php @@ -504,6 +504,8 @@ public function testTrimExpression(string $value, int $position, $char, string $ 'FROM fetch_table'; $row = $this->connection->fetchAssoc($sql); + self::assertNotFalse($row); + $row = array_change_key_case($row, CASE_LOWER); self::assertEquals($expectedResult, $row['trimmed']); @@ -577,6 +579,8 @@ public function testDateArithmetics(): void $sql .= 'FROM fetch_table'; $row = $this->connection->fetchAssoc($sql); + self::assertNotFalse($row); + $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']))); @@ -641,6 +645,8 @@ public function testLocateExpression(): void $sql .= 'FROM fetch_table'; $row = $this->connection->fetchAssoc($sql); + self::assertNotFalse($row); + $row = array_change_key_case($row, CASE_LOWER); self::assertEquals(2, $row['locate1']); diff --git a/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php index 4b842e77654..5e75f6fd29d 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php @@ -11,9 +11,6 @@ use function array_change_key_case; use function sprintf; -use function strlen; -use function strtolower; -use function substr; use const CASE_LOWER; @@ -92,12 +89,9 @@ public function testInheritCharsetFromMaster(): void self::assertFalse($conn->isConnectedToMaster()); - $clientCharset = $conn->fetchColumn('select @@character_set_client as c'); + $clientCharset = $conn->fetchColumn('select @@character_set_client'); - self::assertSame( - $charset, - substr(strtolower($clientCharset), 0, strlen($charset)) - ); + self::assertSame($charset, $clientCharset); } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/PrimaryReadReplicaConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/PrimaryReadReplicaConnectionTest.php index 1bbd094e2d3..e371cf2cfeb 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/PrimaryReadReplicaConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/PrimaryReadReplicaConnectionTest.php @@ -11,9 +11,6 @@ use function array_change_key_case; use function sprintf; -use function strlen; -use function strtolower; -use function substr; use const CASE_LOWER; @@ -97,10 +94,7 @@ public function testInheritCharsetFromPrimary(): void $clientCharset = $conn->fetchColumn('select @@character_set_client as c'); - self::assertSame( - $charset, - substr(strtolower($clientCharset), 0, strlen($charset)) - ); + self::assertSame($charset, $clientCharset); } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php index 1da8e4dbfaa..1ae77de7c8b 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php @@ -45,8 +45,10 @@ public function testSwitchPrimaryKeyColumns(): void $tableNew = clone $tableFetched; $tableNew->setPrimaryKey(['bar_id', 'foo_id']); - $comparator = new Comparator(); - $this->schemaManager->alterTable($comparator->diffTable($tableFetched, $tableNew)); + $diff = (new Comparator())->diffTable($tableFetched, $tableNew); + self::assertNotFalse($diff); + + $this->schemaManager->alterTable($diff); $table = $this->schemaManager->listTableDetails('switch_primary_key_columns'); $primaryKey = $table->getPrimaryKeyColumns(); @@ -73,8 +75,7 @@ public function testDiffTableBug(): void $this->schemaManager->createTable($table); $tableFetched = $this->schemaManager->listTableDetails('diffbug_routing_translations'); - $comparator = new Comparator(); - $diff = $comparator->diffTable($tableFetched, $table); + $diff = (new Comparator())->diffTable($tableFetched, $table); self::assertFalse($diff, 'no changes expected.'); } @@ -135,13 +136,15 @@ public function testAlterTableAddPrimaryKey(): void $this->schemaManager->createTable($table); - $comparator = new Comparator(); - $diffTable = clone $table; + $diffTable = clone $table; $diffTable->dropIndex('idx_id'); $diffTable->setPrimaryKey(['id']); - $this->schemaManager->alterTable($comparator->diffTable($table, $diffTable)); + $diff = (new Comparator())->diffTable($table, $diffTable); + self::assertNotFalse($diff); + + $this->schemaManager->alterTable($diff); $table = $this->schemaManager->listTableDetails('alter_table_add_pk'); @@ -162,9 +165,10 @@ public function testDropPrimaryKeyWithAutoincrementColumn(): void $diffTable->dropPrimaryKey(); - $comparator = new Comparator(); + $diff = (new Comparator())->diffTable($table, $diffTable); + self::assertNotFalse($diff); - $this->schemaManager->alterTable($comparator->diffTable($table, $diffTable)); + $this->schemaManager->alterTable($diff); $table = $this->schemaManager->listTableDetails('drop_primary_key'); @@ -197,9 +201,10 @@ public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes(): vo self::assertNull($onlineTable->getColumn('def_blob_null')->getDefault()); self::assertFalse($onlineTable->getColumn('def_blob_null')->getNotnull()); - $comparator = new Comparator(); + $diff = (new Comparator())->diffTable($table, $onlineTable); + self::assertNotFalse($diff); - $this->schemaManager->alterTable($comparator->diffTable($table, $onlineTable)); + $this->schemaManager->alterTable($diff); $onlineTable = $this->schemaManager->listTableDetails('text_blob_default_value'); @@ -240,9 +245,10 @@ public function testAlterColumnCharset(): void $diffTable = clone $table; $diffTable->getColumn('col_text')->setPlatformOption('charset', 'ascii'); - $comparator = new Comparator(); + $diff = (new Comparator())->diffTable($table, $diffTable); + self::assertNotFalse($diff); - $this->schemaManager->alterTable($comparator->diffTable($table, $diffTable)); + $this->schemaManager->alterTable($diff); $table = $this->schemaManager->listTableDetails($tableName); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php index 4b5846e247f..af0c6b79791 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php @@ -5,6 +5,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Schema; +use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\BinaryType; use Doctrine\DBAL\Types\Types; @@ -76,9 +77,8 @@ public function testListTableWithBinary(): void public function testAlterTableColumnNotNull(): void { - $comparator = new Schema\Comparator(); - $tableName = 'list_table_column_notnull'; - $table = new Schema\Table($tableName); + $tableName = 'list_table_column_notnull'; + $table = new Table($tableName); $table->addColumn('id', 'integer'); $table->addColumn('foo', 'integer'); @@ -97,7 +97,10 @@ public function testAlterTableColumnNotNull(): void $diffTable->changeColumn('foo', ['notnull' => false]); $diffTable->changeColumn('bar', ['length' => 1024]); - $this->schemaManager->alterTable($comparator->diffTable($table, $diffTable)); + $diff = (new Comparator())->diffTable($table, $diffTable); + self::assertNotFalse($diff); + + $this->schemaManager->alterTable($diff); $columns = $this->schemaManager->listTableColumns($tableName); @@ -122,7 +125,7 @@ public function testListDatabases(): void public function testListTableDetailsWithDifferentIdentifierQuotingRequirements(): void { $primaryTableName = '"Primary_Table"'; - $offlinePrimaryTable = new Schema\Table($primaryTableName); + $offlinePrimaryTable = new Table($primaryTableName); $offlinePrimaryTable->addColumn( '"Id"', 'integer', @@ -139,7 +142,7 @@ public function testListTableDetailsWithDifferentIdentifierQuotingRequirements() $offlinePrimaryTable->setPrimaryKey(['"Id"']); $foreignTableName = 'foreign'; - $offlineForeignTable = new Schema\Table($foreignTableName); + $offlineForeignTable = new Table($foreignTableName); $offlineForeignTable->addColumn('id', 'integer', ['autoincrement' => true]); $offlineForeignTable->addColumn('"Fk"', 'integer'); $offlineForeignTable->addIndex(['"Fk"'], '"Fk_index"'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php index ae97380d257..949ee50d51c 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php @@ -99,9 +99,10 @@ public function testAlterTableAutoIncrementAdd(): void $column = $tableTo->addColumn('id', 'integer'); $column->setAutoincrement(true); - $c = new Comparator(); - $diff = $c->diffTable($tableFrom, $tableTo); - $sql = $this->connection->getDatabasePlatform()->getAlterTableSQL($diff); + $diff = (new Comparator())->diffTable($tableFrom, $tableTo); + self::assertNotFalse($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))", @@ -125,9 +126,9 @@ public function testAlterTableAutoIncrementDrop(): void $tableTo = new Table('autoinc_table_drop'); $tableTo->addColumn('id', 'integer'); - $c = new Comparator(); - $diff = $c->diffTable($tableFrom, $tableTo); - self::assertInstanceOf(TableDiff::class, $diff); + $diff = (new Comparator())->diffTable($tableFrom, $tableTo); + self::assertNotFalse($diff); + self::assertEquals( ['ALTER TABLE autoinc_table_drop ALTER id DROP DEFAULT'], $this->connection->getDatabasePlatform()->getAlterTableSQL($diff) diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index 8ae88a87738..a635991e998 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -741,10 +741,10 @@ public function testUpdateSchemaWithForeignKeyRenaming(): void $tableFKNew->addIndex(['rename_fk_id'], 'fk_idx'); $tableFKNew->addForeignKeyConstraint('test_fk_base', ['rename_fk_id'], ['id']); - $c = new Comparator(); - $tableDiff = $c->diffTable($tableFK, $tableFKNew); + $diff = (new Comparator())->diffTable($tableFK, $tableFKNew); + self::assertNotFalse($diff); - $this->schemaManager->alterTable($tableDiff); + $this->schemaManager->alterTable($diff); $table = $this->schemaManager->listTableDetails('test_fk_rename'); $foreignKeys = $table->getForeignKeys(); @@ -781,9 +781,10 @@ public function testRenameIndexUsedInForeignKeyConstraint(): void $foreignTable2 = clone $foreignTable; $foreignTable2->renameIndex('rename_index_fk_idx', 'renamed_index_fk_idx'); - $comparator = new Comparator(); + $diff = (new Comparator())->diffTable($foreignTable, $foreignTable2); + self::assertNotFalse($diff); - $this->schemaManager->alterTable($comparator->diffTable($foreignTable, $foreignTable2)); + $this->schemaManager->alterTable($diff); $foreignTable = $this->schemaManager->listTableDetails('test_rename_index_foreign'); @@ -958,7 +959,7 @@ protected function createTestTable(string $name = 'test_table', array $data = [] */ protected function getTestTable(string $name, array $options = []): Table { - $table = new Table($name, [], [], [], false, $options); + $table = new Table($name, [], [], [], 0, $options); $table->setSchemaConfig($this->schemaManager->createSchemaConfig()); $table->addColumn('id', 'integer', ['notnull' => true]); $table->setPrimaryKey(['id']); @@ -970,7 +971,7 @@ protected function getTestTable(string $name, array $options = []): Table protected function getTestCompositeTable(string $name): Table { - $table = new Table($name, [], [], [], false, []); + $table = new Table($name, [], [], [], 0, []); $table->setSchemaConfig($this->schemaManager->createSchemaConfig()); $table->addColumn('id', 'integer', ['notnull' => true]); $table->addColumn('other_id', 'integer', ['notnull' => true]); @@ -1061,9 +1062,10 @@ public function testColumnDefaultLifecycle(): void $diffTable->changeColumn('column6', ['default' => 666]); $diffTable->changeColumn('column7', ['default' => null]); - $comparator = new Comparator(); + $diff = (new Comparator())->diffTable($table, $diffTable); + self::assertNotFalse($diff); - $this->schemaManager->alterTable($comparator->diffTable($table, $diffTable)); + $this->schemaManager->alterTable($diff); $columns = $this->schemaManager->listTableColumns('col_def_lifecycle'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php index dc46c35a0f3..b7c0c606fa4 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php @@ -7,6 +7,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Schema; +use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\BlobType; use Doctrine\DBAL\Types\Type; @@ -203,10 +204,11 @@ public function testDiffListIntegerAutoincrementTableColumns( $this->schemaManager->dropAndCreateTable($offlineTable); $onlineTable = $this->schemaManager->listTableDetails($tableName); - $comparator = new Schema\Comparator(); - $diff = $comparator->diffTable($offlineTable, $onlineTable); + + $diff = (new Comparator())->diffTable($offlineTable, $onlineTable); if ($expectedComparatorDiff) { + self::assertNotFalse($diff); self::assertEmpty($this->schemaManager->getDatabasePlatform()->getAlterTableSQL($diff)); } else { self::assertFalse($diff); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php index 35e9f0675bc..7bd3dd42333 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php @@ -23,7 +23,9 @@ protected function setUp(): void public function testGuidShouldMatchPattern(): void { - $guid = $this->connection->query($this->getSelectGuidSql())->fetchColumn(); + $guid = $this->connection->query($this->getSelectGuidSql())->fetchColumn(); + self::assertNotFalse($guid); + $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'); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php index 984e19ec719..6f47275a4e8 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php @@ -184,8 +184,8 @@ public function testUniquePrimaryKey(): void $oldTable->addColumn('bar', 'integer'); $oldTable->addColumn('baz', 'string'); - $c = new Comparator(); - $diff = $c->diffTable($oldTable, $keyTable); + $diff = (new Comparator())->diffTable($oldTable, $keyTable); + self::assertNotFalse($diff); $sql = $this->platform->getAlterTableSQL($diff); @@ -384,15 +384,17 @@ public function testAlterTableAddPrimaryKey(): void $table->addColumn('foo', 'integer'); $table->addIndex(['id'], 'idx_id'); - $comparator = new Comparator(); - $diffTable = clone $table; + $diffTable = clone $table; $diffTable->dropIndex('idx_id'); $diffTable->setPrimaryKey(['id']); + $diff = (new Comparator())->diffTable($table, $diffTable); + self::assertNotFalse($diff); + 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($diff) ); } @@ -403,19 +405,21 @@ public function testAlterPrimaryKeyWithAutoincrementColumn(): void $table->addColumn('foo', 'integer'); $table->setPrimaryKey(['id']); - $comparator = new Comparator(); - $diffTable = clone $table; + $diffTable = clone $table; $diffTable->dropPrimaryKey(); $diffTable->setPrimaryKey(['foo']); + $diff = (new Comparator())->diffTable($table, $diffTable); + self::assertNotFalse($diff); + self::assertEquals( [ '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)', ], - $this->platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) + $this->platform->getAlterTableSQL($diff) ); } @@ -427,17 +431,19 @@ public function testDropPrimaryKeyWithAutoincrementColumn(): void $table->addColumn('bar', 'integer'); $table->setPrimaryKey(['id', 'foo']); - $comparator = new Comparator(); - $diffTable = clone $table; + $diffTable = clone $table; $diffTable->dropPrimaryKey(); + $diff = (new Comparator())->diffTable($table, $diffTable); + self::assertNotFalse($diff); + self::assertEquals( [ '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($diff) ); } @@ -449,19 +455,21 @@ public function testDropNonAutoincrementColumnFromCompositePrimaryKeyWithAutoinc $table->addColumn('bar', 'integer'); $table->setPrimaryKey(['id', 'foo']); - $comparator = new Comparator(); - $diffTable = clone $table; + $diffTable = clone $table; $diffTable->dropPrimaryKey(); $diffTable->setPrimaryKey(['id']); + $diff = (new Comparator())->diffTable($table, $diffTable); + self::assertNotFalse($diff); + self::assertSame( [ '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)) + $this->platform->getAlterTableSQL($diff) ); } @@ -473,19 +481,21 @@ public function testAddNonAutoincrementColumnToPrimaryKeyWithAutoincrementColumn $table->addColumn('bar', 'integer'); $table->setPrimaryKey(['id']); - $comparator = new Comparator(); - $diffTable = clone $table; + $diffTable = clone $table; $diffTable->dropPrimaryKey(); $diffTable->setPrimaryKey(['id', 'foo']); + $diff = (new Comparator())->diffTable($table, $diffTable); + self::assertNotFalse($diff); + self::assertSame( [ '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)) + $this->platform->getAlterTableSQL($diff) ); } @@ -499,8 +509,8 @@ public function testAddAutoIncrementPrimaryKey(): void $oldTable = new Table('foo'); $oldTable->addColumn('baz', 'string'); - $c = new Comparator(); - $diff = $c->diffTable($oldTable, $keyTable); + $diff = (new Comparator())->diffTable($oldTable, $keyTable); + self::assertNotFalse($diff); $sql = $this->platform->getAlterTableSQL($diff); @@ -527,20 +537,22 @@ public function testAlterPrimaryKeyWithNewColumn(): void $table->addColumn('col_a', 'integer'); $table->setPrimaryKey(['pkc1']); - $comparator = new Comparator(); - $diffTable = clone $table; + $diffTable = clone $table; $diffTable->addColumn('pkc2', 'integer'); $diffTable->dropPrimaryKey(); $diffTable->setPrimaryKey(['pkc1', 'pkc2']); + $diff = (new Comparator())->diffTable($table, $diffTable); + self::assertNotFalse($diff); + self::assertSame( [ '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)) + $this->platform->getAlterTableSQL($diff) ); } @@ -757,9 +769,10 @@ public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes(): vo $diffTable->changeColumn('def_blob', ['default' => null]); $diffTable->changeColumn('def_blob_null', ['default' => null]); - $comparator = new Comparator(); + $diff = (new Comparator())->diffTable($table, $diffTable); + self::assertNotFalse($diff); - self::assertEmpty($this->platform->getAlterTableSQL($comparator->diffTable($table, $diffTable))); + self::assertEmpty($this->platform->getAlterTableSQL($diff)); } /** diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php index 943adb99f47..658839bd8c1 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php @@ -950,11 +950,12 @@ public function testQuotesAlterTableRenameColumn(): void // quoted -> quoted $toTable->addColumn('`baz`', 'integer', ['comment' => 'Quoted 3']); - $comparator = new Comparator(); + $diff = (new Comparator())->diffTable($fromTable, $toTable); + self::assertNotFalse($diff); self::assertEquals( $this->getQuotedAlterTableRenameColumnSQL(), - $this->platform->getAlterTableSQL($comparator->diffTable($fromTable, $toTable)) + $this->platform->getAlterTableSQL($diff) ); } @@ -987,11 +988,12 @@ public function testQuotesAlterTableChangeColumnLength(): void $toTable->addColumn('table', 'string', ['comment' => 'Reserved keyword 2', 'length' => 255]); $toTable->addColumn('select', 'string', ['comment' => 'Reserved keyword 3', 'length' => 255]); - $comparator = new Comparator(); + $diff = (new Comparator())->diffTable($fromTable, $toTable); + self::assertNotFalse($diff); self::assertEquals( $this->getQuotedAlterTableChangeColumnLengthSQL(), - $this->platform->getAlterTableSQL($comparator->diffTable($fromTable, $toTable)) + $this->platform->getAlterTableSQL($diff) ); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php index fc7e00ae3e3..184dcbb216c 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php @@ -600,10 +600,10 @@ public function testDroppingConstraintsBeforeColumns(): void $oldTable->addColumn('parent_id', 'integer'); $oldTable->addUnnamedForeignKeyConstraint('mytable', ['parent_id'], ['id']); - $comparator = new Comparator(); - $tableDiff = $comparator->diffTable($oldTable, $newTable); + $diff = (new Comparator())->diffTable($oldTable, $newTable); + self::assertNotFalse($diff); - $sql = $this->platform->getAlterTableSQL($tableDiff); + $sql = $this->platform->getAlterTableSQL($diff); $expectedSql = [ 'ALTER TABLE mytable DROP CONSTRAINT FK_6B2BD609727ACA70', @@ -681,7 +681,9 @@ public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType(): vo // VARBINARY -> BINARY // BINARY -> VARBINARY // BLOB -> VARBINARY - self::assertEmpty($this->platform->getAlterTableSQL($comparator->diffTable($table1, $table2))); + $diff = $comparator->diffTable($table1, $table2); + self::assertNotFalse($diff); + self::assertEmpty($this->platform->getAlterTableSQL($diff)); $table2 = new Table('mytable'); $table2->addColumn('column_varbinary', 'binary', ['length' => 42]); @@ -691,7 +693,9 @@ public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType(): vo // VARBINARY -> VARBINARY with changed length // BINARY -> BLOB // BLOB -> BINARY - self::assertEmpty($this->platform->getAlterTableSQL($comparator->diffTable($table1, $table2))); + $diff = $comparator->diffTable($table1, $table2); + self::assertNotFalse($diff); + self::assertEmpty($this->platform->getAlterTableSQL($diff)); $table2 = new Table('mytable'); $table2->addColumn('column_varbinary', 'blob'); @@ -701,7 +705,9 @@ public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType(): vo // VARBINARY -> BLOB // BINARY -> BINARY with changed length // BLOB -> BLOB - self::assertEmpty($this->platform->getAlterTableSQL($comparator->diffTable($table1, $table2))); + $diff = $comparator->diffTable($table1, $table2); + self::assertNotFalse($diff); + self::assertEmpty($this->platform->getAlterTableSQL($diff)); } /** diff --git a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php index 9cd147026b1..11ca8e60f96 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php @@ -582,7 +582,9 @@ public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType(): vo // VARBINARY -> BINARY // BINARY -> VARBINARY - self::assertEmpty($this->platform->getAlterTableSQL($comparator->diffTable($table1, $table2))); + $diff = (new Comparator())->diffTable($table1, $table2); + self::assertNotFalse($diff); + self::assertEmpty($this->platform->getAlterTableSQL($diff)); } public function testUsesSequenceEmulatedIdentityColumns(): void diff --git a/tests/Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php b/tests/Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php index 3802ff27a01..d134a1f2f56 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php @@ -33,7 +33,9 @@ public function testSwitchPrimaryKeyOrder(): void $tableNew->setPrimaryKey(['bar_id', 'foo_id']); $diff = $this->comparator->diffTable($tableOld, $tableNew); - $sql = $this->platform->getAlterTableSQL($diff); + self::assertNotFalse($diff); + + $sql = $this->platform->getAlterTableSQL($diff); self::assertEquals( [ @@ -74,7 +76,9 @@ public function testClobNoAlterTable(): void $tableNew->setPrimaryKey(['id']); $diff = $this->comparator->diffTable($tableOld, $tableNew); - $sql = $this->platform->getAlterTableSQL($diff); + self::assertNotFalse($diff); + + $sql = $this->platform->getAlterTableSQL($diff); self::assertEquals( ['ALTER TABLE test ADD PRIMARY KEY (id)'], diff --git a/tests/Doctrine/Tests/DBAL/Schema/TableTest.php b/tests/Doctrine/Tests/DBAL/Schema/TableTest.php index c596fecfc9c..5b6d897aa80 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/TableTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/TableTest.php @@ -210,7 +210,7 @@ public function testConstraints(): void public function testOptions(): void { - $table = new Table('foo', [], [], [], false, ['foo' => 'bar']); + $table = new Table('foo', [], [], [], 0, ['foo' => 'bar']); self::assertTrue($table->hasOption('foo')); self::assertEquals('bar', $table->getOption('foo')); diff --git a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/AbstractTestCase.php b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/AbstractTestCase.php index 8ad29bfcef6..3ab0991a519 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/AbstractTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/AbstractTestCase.php @@ -41,6 +41,7 @@ protected function setUp(): void $this->conn = DriverManager::getConnection($params); $serverEdition = $this->conn->fetchColumn("SELECT CONVERT(NVARCHAR(128), SERVERPROPERTY('Edition'))"); + self::assertNotFalse($serverEdition); if (strpos($serverEdition, 'SQL Azure') !== 0) { $this->markTestSkipped('SQL Azure only test.'); diff --git a/tests/Doctrine/Tests/DBAL/Tools/DumperTest.php b/tests/Doctrine/Tests/DBAL/Tools/DumperTest.php index 53af4ae420a..5c64ae77834 100644 --- a/tests/Doctrine/Tests/DBAL/Tools/DumperTest.php +++ b/tests/Doctrine/Tests/DBAL/Tools/DumperTest.php @@ -14,10 +14,6 @@ use Doctrine\Tests\DbalTestCase; use stdClass; -use function print_r; -use function strpos; -use function substr; - class DumperTest extends DbalTestCase { public function testExportObject(): void @@ -99,14 +95,6 @@ public function testExportArrayTraversable(): void */ public function testExportParentAttributes(TestAsset\ParentClass $class, array $expected): void { - $print_r_class = print_r($class, true); - $print_r_expected = print_r($expected, true); - - $print_r_class = substr($print_r_class, strpos($print_r_class, '(')); - $print_r_expected = substr($print_r_expected, strpos($print_r_expected, '(')); - - self::assertSame($print_r_class, $print_r_expected); - $var = Dumper::export($class, 3); $var = (array) $var; unset($var['__CLASS__']); From c6585d306730062028714b51ea40e52624390d07 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 15 Oct 2020 19:11:54 -0700 Subject: [PATCH 46/56] Fix PossiblyInvalidArrayAccess issues --- tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php | 1 + .../Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php | 1 + tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php index 355f8fef368..58322e9d90e 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php @@ -360,6 +360,7 @@ public function testFetchArray(): void { $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; $row = $this->connection->fetchArray($sql, [1, 'foo']); + self::assertNotFalse($row); self::assertEquals(1, $row[0]); self::assertEquals('foo', $row[1]); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php index 1ae77de7c8b..0b1e56daebc 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php @@ -463,6 +463,7 @@ public function testColumnDefaultsAreValid(): void $row = $this->connection->fetchAssoc( 'SELECT *, DATEDIFF(CURRENT_TIMESTAMP(), col_datetime) as diff_seconds FROM test_column_defaults_are_valid' ); + self::assertNotFalse($row); self::assertInstanceOf(DateTime::class, DateTime::createFromFormat('Y-m-d H:i:s', $row['col_datetime'])); self::assertNull($row['col_datetime_null']); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php index 77cd108b595..dea9f88d8f6 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php @@ -50,6 +50,7 @@ public function testBooleanConversionSqlLiteral(): void self::assertNotEmpty($id); $row = $this->connection->fetchAssoc('SELECT bool_col FROM dbal630 WHERE id = ?', [$id]); + self::assertNotFalse($row); self::assertFalse($row['bool_col']); } @@ -65,6 +66,7 @@ public function testBooleanConversionBoolParamRealPrepares(): void self::assertNotEmpty($id); $row = $this->connection->fetchAssoc('SELECT bool_col FROM dbal630 WHERE id = ?', [$id]); + self::assertNotFalse($row); self::assertFalse($row['bool_col']); } @@ -84,6 +86,7 @@ public function testBooleanConversionBoolParamEmulatedPrepares(): void self::assertNotEmpty($id); $row = $this->connection->fetchAssoc('SELECT bool_col FROM dbal630 WHERE id = ?', [$id]); + self::assertNotFalse($row); self::assertFalse($row['bool_col']); } @@ -108,6 +111,7 @@ public function testBooleanConversionNullParamEmulatedPrepares( self::assertNotEmpty($id); $row = $this->connection->fetchAssoc('SELECT bool_col FROM dbal630_allow_nulls WHERE id = ?', [$id]); + self::assertNotFalse($row); self::assertSame($databaseConvertedValue, $row['bool_col']); } @@ -136,6 +140,7 @@ public function testBooleanConversionNullParamEmulatedPreparesWithBooleanTypeInB self::assertNotEmpty($id); $row = $this->connection->fetchAssoc('SELECT bool_col FROM dbal630_allow_nulls WHERE id = ?', [$id]); + self::assertNotFalse($row); self::assertSame($databaseConvertedValue, $row['bool_col']); } From 513604f2eed23461fbf2ed06076b11515cee05d4 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 15 Oct 2020 19:14:27 -0700 Subject: [PATCH 47/56] Fix PossiblyInvalidPropertyFetch issues --- .../Tests/DBAL/Schema/ComparatorTest.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php index df2874a535a..9079fbec518 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php @@ -252,8 +252,8 @@ public function testCompareChangeColumnsMultipleNewColumnsRename(): void $tableB->addColumn('new_datecolumn1', 'datetime'); $tableB->addColumn('new_datecolumn2', 'datetime'); - $c = new Comparator(); - $tableDiff = $c->diffTable($tableA, $tableB); + $tableDiff = (new Comparator())->diffTable($tableA, $tableB); + self::assertNotFalse($tableDiff); self::assertCount(1, $tableDiff->renamedColumns); self::assertArrayHasKey('datecolumn1', $tableDiff->renamedColumns); @@ -720,8 +720,8 @@ public function testDetectRenameColumn(): void $tableB = new Table('foo'); $tableB->addColumn('bar', 'integer'); - $c = new Comparator(); - $tableDiff = $c->diffTable($tableA, $tableB); + $tableDiff = (new Comparator())->diffTable($tableA, $tableB); + self::assertNotFalse($tableDiff); self::assertCount(0, $tableDiff->addedColumns); self::assertCount(0, $tableDiff->removedColumns); @@ -743,8 +743,8 @@ public function testDetectRenameColumnAmbiguous(): void $tableB = new Table('foo'); $tableB->addColumn('baz', 'integer'); - $c = new Comparator(); - $tableDiff = $c->diffTable($tableA, $tableB); + $tableDiff = (new Comparator())->diffTable($tableA, $tableB); + self::assertNotFalse($tableDiff); self::assertCount(1, $tableDiff->addedColumns); self::assertArrayHasKey('baz', $tableDiff->addedColumns); @@ -765,8 +765,8 @@ public function testDetectRenameIndex(): void $table2->addIndex(['foo'], 'idx_bar'); - $comparator = new Comparator(); - $tableDiff = $comparator->diffTable($table1, $table2); + $tableDiff = (new Comparator())->diffTable($table1, $table2); + self::assertNotFalse($tableDiff); self::assertCount(0, $tableDiff->addedIndexes); self::assertCount(0, $tableDiff->removedIndexes); @@ -791,8 +791,8 @@ public function testDetectRenameIndexAmbiguous(): void $table2->addIndex(['foo'], 'idx_baz'); - $comparator = new Comparator(); - $tableDiff = $comparator->diffTable($table1, $table2); + $tableDiff = (new Comparator())->diffTable($table1, $table2); + self::assertNotFalse($tableDiff); self::assertCount(1, $tableDiff->addedIndexes); self::assertArrayHasKey('idx_baz', $tableDiff->addedIndexes); From 6c5373f143b3fd20ff126652f79d032e8f432f8f Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 15 Oct 2020 19:20:03 -0700 Subject: [PATCH 48/56] Fix PropertyTypeCoercion issues --- .../DBAL/Functional/Driver/OCI8/ConnectionTest.php | 12 ++++-------- .../DBAL/Functional/Driver/PDO/ConnectionTest.php | 8 ++++---- .../Tests/DBAL/Tools/Console/RunSqlCommandTest.php | 9 +++++---- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/ConnectionTest.php index f4947212ec0..909528eb06e 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/ConnectionTest.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\DBAL\Functional\Driver\OCI8; -use Doctrine\DBAL\Driver\OCI8\Connection; use Doctrine\DBAL\Driver\OCI8\Driver; use Doctrine\DBAL\Schema\Table; use Doctrine\Tests\DbalFunctionalTestCase; @@ -12,18 +11,15 @@ */ class ConnectionTest extends DbalFunctionalTestCase { - /** @var Connection */ - protected $driverConnection; - protected function setUp(): void { parent::setUp(); - if (! $this->connection->getDriver() instanceof Driver) { - $this->markTestSkipped('oci8 only test.'); + if ($this->connection->getDriver() instanceof Driver) { + return; } - $this->driverConnection = $this->connection->getWrappedConnection(); + $this->markTestSkipped('oci8 only test.'); } public function testLastInsertIdAcceptsFqn(): void @@ -42,6 +38,6 @@ public function testLastInsertIdAcceptsFqn(): void $schema = $this->connection->getDatabase(); $sequence = $platform->getIdentitySequenceName($schema . '.DBAL2595', 'id'); - self::assertSame(1, $this->driverConnection->lastInsertId($sequence)); + self::assertSame(1, $this->connection->lastInsertId($sequence)); } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDO/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDO/ConnectionTest.php index c9f748fbce6..143cbf6c687 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDO/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDO/ConnectionTest.php @@ -31,13 +31,13 @@ protected function setUp(): void { parent::setUp(); - $this->driverConnection = $this->connection->getWrappedConnection(); + $driverConnection = $this->connection->getWrappedConnection(); - if ($this->driverConnection instanceof Connection) { - return; + if (! $driverConnection instanceof Connection) { + $this->markTestSkipped('PDO connection only test.'); } - $this->markTestSkipped('PDO connection only test.'); + $this->driverConnection = $driverConnection; } protected function tearDown(): void diff --git a/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php b/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php index 8a99dd366b8..5b7357b30b1 100644 --- a/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php +++ b/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php @@ -24,16 +24,17 @@ class RunSqlCommandTest extends TestCase protected function setUp(): void { - $application = new Application(); - $application->add(new RunSqlCommand()); + $this->command = new RunSqlCommand(); - $this->command = $application->find('dbal:run-sql'); - $this->commandTester = new CommandTester($this->command); + (new Application())->add($this->command); $this->connectionMock = $this->createMock(Connection::class); $helperSet = ConsoleRunner::createHelperSet($this->connectionMock); + $this->command->setHelperSet($helperSet); + + $this->commandTester = new CommandTester($this->command); } public function testMissingSqlArgument(): void From f930db20d2aa4451d3f0bef4e0a5dd33dba38c74 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 15 Oct 2020 19:27:06 -0700 Subject: [PATCH 49/56] Fix PossiblyFalsePropertyAssignmentValue issues --- lib/Doctrine/DBAL/Schema/Schema.php | 2 +- lib/Doctrine/DBAL/Schema/Table.php | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/DBAL/Schema/Schema.php b/lib/Doctrine/DBAL/Schema/Schema.php index 6ea5fd0c8c0..24fc47b599b 100644 --- a/lib/Doctrine/DBAL/Schema/Schema.php +++ b/lib/Doctrine/DBAL/Schema/Schema.php @@ -52,7 +52,7 @@ class Schema extends AbstractAsset protected $_sequences = []; /** @var SchemaConfig */ - protected $_schemaConfig = false; + protected $_schemaConfig; /** * @param Table[] $tables diff --git a/lib/Doctrine/DBAL/Schema/Table.php b/lib/Doctrine/DBAL/Schema/Table.php index 740092d3ca1..d69dc45f189 100644 --- a/lib/Doctrine/DBAL/Schema/Table.php +++ b/lib/Doctrine/DBAL/Schema/Table.php @@ -29,7 +29,7 @@ class Table extends AbstractAsset /** @var Index[] */ protected $_indexes = []; - /** @var string */ + /** @var string|false */ protected $_primaryKeyName = false; /** @var ForeignKeyConstraint[] */ @@ -150,6 +150,10 @@ public function addIndex(array $columnNames, $indexName = null, array $flags = [ */ public function dropPrimaryKey() { + if ($this->_primaryKeyName === false) { + return; + } + $this->dropIndex($this->_primaryKeyName); $this->_primaryKeyName = false; } @@ -717,11 +721,11 @@ public function getColumn($name) */ public function getPrimaryKey() { - if (! $this->hasPrimaryKey()) { - return null; + if ($this->_primaryKeyName !== false) { + return $this->getIndex($this->_primaryKeyName); } - return $this->getIndex($this->_primaryKeyName); + return null; } /** From 7a33a6bf4c9f24b9198484ca795ce6aa9cafbded Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 15 Oct 2020 19:48:56 -0700 Subject: [PATCH 50/56] Fix PossiblyNullPropertyAssignmentValue issues --- lib/Doctrine/DBAL/Schema/TableDiff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/DBAL/Schema/TableDiff.php b/lib/Doctrine/DBAL/Schema/TableDiff.php index dcaeb200a6a..82c912f71b1 100644 --- a/lib/Doctrine/DBAL/Schema/TableDiff.php +++ b/lib/Doctrine/DBAL/Schema/TableDiff.php @@ -10,7 +10,7 @@ class TableDiff { /** @var string */ - public $name = null; + public $name; /** @var string|false */ public $newName = false; From 19a889797a0ac239e77e1adf717c4fe2ba91a18c Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 15 Oct 2020 20:15:29 -0700 Subject: [PATCH 51/56] Fix PossiblyFalseOperand issues --- lib/Doctrine/DBAL/Schema/DB2SchemaManager.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php b/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php index 25f0282c536..fcc196ae519 100644 --- a/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php @@ -7,7 +7,6 @@ use function array_change_key_case; use function assert; -use function is_resource; use function preg_match; use function str_replace; use function strpos; @@ -207,13 +206,12 @@ protected function _getPortableForeignKeyRuleDef($def) protected function _getPortableViewDefinition($view) { $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'])) { - $pos = strpos($view['text'], ' AS '); + + $sql = ''; + $pos = strpos($view['text'], ' AS '); + + if ($pos !== false) { $sql = substr($view['text'], $pos + 4); - } else { - $sql = ''; } return new View($view['name'], $sql); From 8c6ea53361de1fdbb1c44933b65a7d96c69b9abe Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 15 Oct 2020 20:23:36 -0700 Subject: [PATCH 52/56] Fix PossiblyNullArrayOffset issues --- lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index 5580ea23dea..911daa8cb8b 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -1602,8 +1602,10 @@ public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDE } } + $name = $column->getQuotedName($this); + $columnData = array_merge($column->toArray(), [ - 'name' => $column->getQuotedName($this), + 'name' => $name, 'version' => $column->hasPlatformOption('version') ? $column->getPlatformOption('version') : false, 'comment' => $this->getColumnComment($column), ]); @@ -1616,7 +1618,7 @@ public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDE $columnData['primary'] = true; } - $columns[$columnData['name']] = $columnData; + $columns[$name] = $columnData; } if (($createFlags & self::CREATE_FOREIGNKEYS) > 0) { From 7722b516685738121de202450348ee9a6bc617a1 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 14 Oct 2020 18:21:06 -0700 Subject: [PATCH 53/56] Bump Psalm level to 3 --- psalm.xml | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/psalm.xml b/psalm.xml index f67b67c6566..999a5611126 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,7 +1,7 @@ + + + + + + + + + + + + + + +