From f4c43d523606db373a35291dcd843e39b16c44af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Tue, 21 Apr 2020 22:20:45 +0200 Subject: [PATCH 01/33] Document actual types --- lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php | 4 ++++ lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php | 2 ++ lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php | 2 ++ lib/Doctrine/DBAL/Driver/PDOConnection.php | 9 +++++++-- lib/Doctrine/DBAL/Portability/Connection.php | 2 ++ tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php | 2 +- tests/Doctrine/Tests/DBAL/Functional/WriteTest.php | 3 +++ tests/Doctrine/Tests/DbalPerformanceTestListener.php | 2 +- 8 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php index f1b687aaec6..11cad6101ec 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php @@ -200,6 +200,8 @@ public function rollBack() /** * {@inheritdoc} + * + * @return int */ public function errorCode() { @@ -208,6 +210,8 @@ public function errorCode() /** * {@inheritdoc} + * + * @return string */ public function errorInfo() { diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php index 86e846af702..e45e1235843 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php @@ -401,6 +401,8 @@ public function errorCode() /** * {@inheritdoc} + * + * @return string */ public function errorInfo() { diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php index ae1b3599642..490895f4cda 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php @@ -148,6 +148,8 @@ public function exec($statement) /** * {@inheritdoc} + * + * @return int|false */ public function lastInsertId($name = null) { diff --git a/lib/Doctrine/DBAL/Driver/PDOConnection.php b/lib/Doctrine/DBAL/Driver/PDOConnection.php index ffd80d7423c..e3d586edb8d 100644 --- a/lib/Doctrine/DBAL/Driver/PDOConnection.php +++ b/lib/Doctrine/DBAL/Driver/PDOConnection.php @@ -56,12 +56,15 @@ public function getServerVersion() * @param string $prepareString * @param array $driverOptions * - * @return Statement + * @return \PDOStatement */ public function prepare($prepareString, $driverOptions = []) { try { - return parent::prepare($prepareString, $driverOptions); + $statement = parent::prepare($prepareString, $driverOptions); + assert($statement instanceof \PDOStatement); + + return $statement; } catch (\PDOException $exception) { throw new PDOException($exception); } @@ -69,6 +72,8 @@ public function prepare($prepareString, $driverOptions = []) /** * {@inheritdoc} + * + * @return \PDOStatement */ public function query() { diff --git a/lib/Doctrine/DBAL/Portability/Connection.php b/lib/Doctrine/DBAL/Portability/Connection.php index cb1bd2f062b..ce8bfee248c 100644 --- a/lib/Doctrine/DBAL/Portability/Connection.php +++ b/lib/Doctrine/DBAL/Portability/Connection.php @@ -108,6 +108,8 @@ public function executeQuery($query, array $params = [], $types = [], ?QueryCach /** * {@inheritdoc} + * + * @return Statement */ public function prepare($statement) { diff --git a/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php b/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php index 6d03a736e13..eb24e8160c3 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php @@ -21,7 +21,7 @@ */ class ResultCacheTest extends DbalFunctionalTestCase { - /** @var array> */ + /** @var list */ private $expectedResult = [['test_int' => 100, 'test_string' => 'foo'], ['test_int' => 200, 'test_string' => 'bar'], ['test_int' => 300, 'test_string' => 'baz']]; /** @var DebugStack */ diff --git a/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php b/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php index da2e23dc32d..2f8b19e9f97 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php @@ -7,6 +7,7 @@ use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Table; +use Doctrine\DBAL\Statement; use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DbalFunctionalTestCase; use Throwable; @@ -94,6 +95,7 @@ public function testPrepareWithDbalTypes() : void $sql = 'INSERT INTO write_table (test_int, test_string) VALUES (?, ?)'; $stmt = $this->connection->prepare($sql); + self::assertInstanceOf(Statement::class, $stmt); $stmt->bindValue(1, 1, Type::getType('integer')); $stmt->bindValue(2, 'foo', Type::getType('string')); $stmt->execute(); @@ -106,6 +108,7 @@ public function testPrepareWithDbalTypeNames() : void $sql = 'INSERT INTO write_table (test_int, test_string) VALUES (?, ?)'; $stmt = $this->connection->prepare($sql); + self::assertInstanceOf(Statement::class, $stmt); $stmt->bindValue(1, 1, 'integer'); $stmt->bindValue(2, 'foo', 'string'); $stmt->execute(); diff --git a/tests/Doctrine/Tests/DbalPerformanceTestListener.php b/tests/Doctrine/Tests/DbalPerformanceTestListener.php index ba46ca04a68..c9f0027c015 100644 --- a/tests/Doctrine/Tests/DbalPerformanceTestListener.php +++ b/tests/Doctrine/Tests/DbalPerformanceTestListener.php @@ -16,7 +16,7 @@ class DbalPerformanceTestListener implements TestListener { use TestListenerDefaultImplementation; - /** @var string[][] */ + /** @var array> */ private $timings = []; public function endTest(Test $test, float $time) : void From 9a617edbc4fec2d352a8638c3ec4c7d579d737ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Tue, 21 Apr 2020 22:22:50 +0200 Subject: [PATCH 02/33] Install phpunit plugin for Psalm --- composer.json | 1 + composer.lock | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index eb5f95c8eb0..49a7fbb1ec8 100644 --- a/composer.json +++ b/composer.json @@ -43,6 +43,7 @@ "nikic/php-parser": "^4.4", "phpstan/phpstan": "^0.12", "phpunit/phpunit": "^8.4.1", + "psalm/plugin-phpunit": "^0.10.0", "symfony/console": "^2.0.5|^3.0|^4.0|^5.0", "vimeo/psalm": "^3.11" }, diff --git a/composer.lock b/composer.lock index 0073213a8c6..69b35183bb7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6bf4905b268231ccd58bdbe30d4ecf81", + "content-hash": "48526e240461408d90e490246c3b4531", "packages": [ { "name": "doctrine/cache", @@ -1703,6 +1703,57 @@ ], "time": "2019-10-07T12:57:41+00:00" }, + { + "name": "psalm/plugin-phpunit", + "version": "0.10.0", + "source": { + "type": "git", + "url": "https://github.com/psalm/psalm-plugin-phpunit.git", + "reference": "12b3978cea0e9ad3aa3a127a93d3b8a1ce0eb2af" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/psalm/psalm-plugin-phpunit/zipball/12b3978cea0e9ad3aa3a127a93d3b8a1ce0eb2af", + "reference": "12b3978cea0e9ad3aa3a127a93d3b8a1ce0eb2af", + "shasum": "" + }, + "require": { + "composer/semver": "^1.4", + "ext-simplexml": "*", + "ocramius/package-versions": "^1.3", + "php": "^7.1.3", + "phpunit/phpunit": "^7.5 || ^8.0 || ^9.0", + "vimeo/psalm": "^3.6.2 || dev-master" + }, + "require-dev": { + "codeception/codeception": "^4.0.3", + "squizlabs/php_codesniffer": "^3.3.1", + "weirdan/codeception-psalm-module": "^0.4.0" + }, + "type": "psalm-plugin", + "extra": { + "psalm": { + "pluginClass": "Psalm\\PhpUnitPlugin\\Plugin" + } + }, + "autoload": { + "psr-4": { + "Psalm\\PhpUnitPlugin\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Matt Brown", + "email": "github@muglug.com" + } + ], + "description": "Psalm plugin for PHPUnit", + "time": "2020-04-05T22:49:26+00:00" + }, { "name": "psr/container", "version": "1.0.0", @@ -2596,6 +2647,20 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], "time": "2020-03-30T11:41:10+00:00" }, { From 96d5bcc1b462b197683d469dbedc159c94c634d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Tue, 21 Apr 2020 22:28:28 +0200 Subject: [PATCH 03/33] Make return type verified and accurate --- tests/Doctrine/Tests/DBAL/Types/TypeTest.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Types/TypeTest.php b/tests/Doctrine/Tests/DBAL/Types/TypeTest.php index 59440f062c6..8dbca8b57f0 100644 --- a/tests/Doctrine/Tests/DBAL/Types/TypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/TypeTest.php @@ -19,7 +19,7 @@ public function testDefaultTypesAreRegistered(string $name) : void } /** - * @return string[][] + * @return iterable */ public function defaultTypesProvider() : iterable { @@ -28,7 +28,10 @@ public function defaultTypesProvider() : iterable continue; } - yield [$constant->getValue()]; + $constantValue = $constant->getValue(); + self::assertIsString($constantValue); + + yield [$constantValue]; } } } From a8c772d8ab78671aeedde1b8b462d7c2c91f6b34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Wed, 22 Apr 2020 09:21:11 +0200 Subject: [PATCH 04/33] Update phpunit The latest version is easier to understand for static analyzers. --- composer.json | 2 +- composer.lock | 38 +++++++++++++++++--------------------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/composer.json b/composer.json index 49a7fbb1ec8..09263687d3d 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,7 @@ "jetbrains/phpstorm-stubs": "^2019.1", "nikic/php-parser": "^4.4", "phpstan/phpstan": "^0.12", - "phpunit/phpunit": "^8.4.1", + "phpunit/phpunit": "^8.5.5", "psalm/plugin-phpunit": "^0.10.0", "symfony/console": "^2.0.5|^3.0|^4.0|^5.0", "vimeo/psalm": "^3.11" diff --git a/composer.lock b/composer.lock index 69b35183bb7..fbcb548dbf9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "48526e240461408d90e490246c3b4531", + "content-hash": "9157c6d35dd39f5399592fd91126fa07", "packages": [ { "name": "doctrine/cache", @@ -1622,16 +1622,16 @@ }, { "name": "phpunit/phpunit", - "version": "8.4.1", + "version": "8.5.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "366a4a0f2b971fd43b7c351d621e8dd7d7131869" + "reference": "63dda3b212a0025d380a745f91bdb4d8c985adb7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/366a4a0f2b971fd43b7c351d621e8dd7d7131869", - "reference": "366a4a0f2b971fd43b7c351d621e8dd7d7131869", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/63dda3b212a0025d380a745f91bdb4d8c985adb7", + "reference": "63dda3b212a0025d380a745f91bdb4d8c985adb7", "shasum": "" }, "require": { @@ -1675,7 +1675,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "8.4-dev" + "dev-master": "8.5-dev" } }, "autoload": { @@ -1701,7 +1701,17 @@ "testing", "xunit" ], - "time": "2019-10-07T12:57:41+00:00" + "funding": [ + { + "url": "https://phpunit.de/donate.html", + "type": "custom" + }, + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-05-22T13:51:52+00:00" }, { "name": "psalm/plugin-phpunit", @@ -2647,20 +2657,6 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], "time": "2020-03-30T11:41:10+00:00" }, { From befc59af458c5e2d112eb1f70983ed41a1983f6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Wed, 22 Apr 2020 07:43:23 +0200 Subject: [PATCH 05/33] Improve phpdoc --- tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php | 3 +++ tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php | 6 ++++++ .../Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php | 3 ++- .../DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php | 3 +++ tests/Doctrine/Tests/DBAL/StatementTest.php | 7 ++++--- .../Tests/DBAL/Tools/Console/RunSqlCommandTest.php | 3 ++- 6 files changed, 20 insertions(+), 5 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php index 78f6ec5f5a6..3c0a3a1536f 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php @@ -198,6 +198,9 @@ abstract protected function createPlatform() : AbstractPlatform; */ abstract protected function createSchemaManager(Connection $connection) : AbstractSchemaManager; + /** + * @return Connection&MockObject + */ protected function getConnectionMock() : Connection { return $this->getMockBuilder(Connection::class) diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php index e3f6d9b5d0c..74b87deabf0 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php @@ -13,6 +13,12 @@ class SqlitePlatformTest extends AbstractPlatformTestCase { + /** @var SqlitePlatform */ + protected $platform; + + /** + * @return SqlitePlatform + */ public function createPlatform() : AbstractPlatform { return new SqlitePlatform(); diff --git a/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php index 934b3e97bef..f599becad40 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/MySqlSchemaManagerTest.php @@ -10,6 +10,7 @@ use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\MySqlSchemaManager; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use function array_map; @@ -18,7 +19,7 @@ class MySqlSchemaManagerTest extends TestCase /** @var AbstractSchemaManager */ private $manager; - /** @var Connection */ + /** @var Connection&MockObject */ private $conn; protected function setUp() : void diff --git a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php index 78d6afe593c..242c7a0fe52 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/SQLAzureShardManagerTest.php @@ -5,6 +5,7 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Sharding\ShardingException; use Doctrine\DBAL\Sharding\SQLAzure\SQLAzureShardManager; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class SQLAzureShardManagerTest extends TestCase @@ -81,6 +82,8 @@ public function testSelectShard() : void /** * @param mixed[] $params + * + * @return Connection&MockObject */ private function createConnection(array $params) : Connection { diff --git a/tests/Doctrine/Tests/DBAL/StatementTest.php b/tests/Doctrine/Tests/DBAL/StatementTest.php index 1c0794ac4cc..728cc5ab58a 100644 --- a/tests/Doctrine/Tests/DBAL/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/StatementTest.php @@ -14,16 +14,17 @@ use Doctrine\Tests\DbalTestCase; use Exception; use PDOStatement; +use PHPUnit\Framework\MockObject\MockObject; class StatementTest extends DbalTestCase { - /** @var Connection */ + /** @var Connection&MockObject */ private $conn; - /** @var Configuration */ + /** @var Configuration&MockObject */ private $configuration; - /** @var PDOStatement */ + /** @var PDOStatement&MockObject */ private $pdoStatement; protected function setUp() : void diff --git a/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php b/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php index 202748be6d8..b55059ab715 100644 --- a/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php +++ b/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Tools\Console\Command\RunSqlCommand; use Doctrine\DBAL\Tools\Console\ConsoleRunner; use LogicException; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use RuntimeException; use Symfony\Component\Console\Application; @@ -18,7 +19,7 @@ class RunSqlCommandTest extends TestCase /** @var RunSqlCommand */ private $command; - /** @var Connection */ + /** @var Connection&MockObject */ private $connectionMock; protected function setUp() : void From 69cf6c41f4d1238bf385fbb98ec32446ce7fc619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Thu, 23 Apr 2020 00:00:23 +0200 Subject: [PATCH 06/33] Remove uneeded key --- tests/Doctrine/Tests/DBAL/DriverManagerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/DBAL/DriverManagerTest.php b/tests/Doctrine/Tests/DBAL/DriverManagerTest.php index ced3e5d993f..e7550059b4b 100644 --- a/tests/Doctrine/Tests/DBAL/DriverManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/DriverManagerTest.php @@ -341,7 +341,7 @@ public function databaseUrls() : iterable ], ], 'query params from URL are used as extra params' => [ - 'url' => 'mysql://foo:bar@localhost/dbname?charset=UTF-8', + 'mysql://foo:bar@localhost/dbname?charset=UTF-8', ['charset' => 'UTF-8'], ], 'simple URL with fallthrough scheme not defined in map' => [ From 8f7ea5263fda57ddd03591bf9ac77b26e9034b89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Thu, 23 Apr 2020 00:00:39 +0200 Subject: [PATCH 07/33] Use list It is more simple and more accurate --- tests/Doctrine/Tests/DBAL/DriverManagerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/DBAL/DriverManagerTest.php b/tests/Doctrine/Tests/DBAL/DriverManagerTest.php index e7550059b4b..1f3e69c365a 100644 --- a/tests/Doctrine/Tests/DBAL/DriverManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/DriverManagerTest.php @@ -242,7 +242,7 @@ public function testDatabaseUrl($url, $expected) : void } /** - * @return array> + * @return array> */ public function databaseUrls() : iterable { From 99b542a5986ff589cd7636a1d82968892e6c086b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Thu, 23 Apr 2020 00:03:34 +0200 Subject: [PATCH 08/33] Use shortcut --- tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php index 3c0a3a1536f..6cb8fabb785 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php @@ -203,9 +203,7 @@ abstract protected function createSchemaManager(Connection $connection) : Abstra */ protected function getConnectionMock() : Connection { - return $this->getMockBuilder(Connection::class) - ->disableOriginalConstructor() - ->getMock(); + return $this->createMock(Connection::class); } /** From 633f9e36524fc44bcc16b0d98b54bbc17686867f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Thu, 23 Apr 2020 07:36:53 +0200 Subject: [PATCH 09/33] Suppress deliberate error We are testing what happens when providing the wrong type. --- tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php index f73d1c6d1f4..cc77a153a4a 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php @@ -872,6 +872,7 @@ public function testChangedSequence() : void /** * @group DBAL-106 + * @psalm-suppress NullArgument */ public function testDiffDecimalWithNullPrecision() : void { From f2a0ab7fe0ff686c55cda2e8f38d35d68e0bfe64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Thu, 23 Apr 2020 09:10:21 +0200 Subject: [PATCH 10/33] Use TrimMode::UNSPECIFIED over null The method signature does not allow null. --- tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php index e304e797fdf..46d3bd5b1b7 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php @@ -596,7 +596,7 @@ public function testGeneratesSQLSnippets() : void self::assertEquals( "REVERSE(SUBSTR(REVERSE(SUBSTR(column, PATINDEX('%[^' + c + ']%', column))), PATINDEX('%[^' + c + ']%', " . "REVERSE(SUBSTR(column, PATINDEX('%[^' + c + ']%', column))))))", - $this->platform->getTrimExpression('column', null, 'c') + $this->platform->getTrimExpression('column', TrimMode::UNSPECIFIED, 'c') ); self::assertEquals( "REVERSE(SUBSTR(REVERSE(SUBSTR(column, PATINDEX('%[^' + c + ']%', column))), PATINDEX('%[^' + c + ']%', " . From 014ac9c32393a36ac8230c864b6e6f01644150c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Thu, 23 Apr 2020 09:31:33 +0200 Subject: [PATCH 11/33] Pass the right type of argument --- .../Tests/DBAL/Platforms/SQLAnywherePlatformTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php index 46d3bd5b1b7..31a0efcc669 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php @@ -348,14 +348,14 @@ public function testGeneratesPrimaryKeyDeclarationSQL() : void self::assertEquals( 'CONSTRAINT pk PRIMARY KEY CLUSTERED (a, b)', $this->platform->getPrimaryKeyDeclarationSQL( - new Index(null, ['a', 'b'], true, true, ['clustered']), + new Index('', ['a', 'b'], true, true, ['clustered']), 'pk' ) ); self::assertEquals( 'PRIMARY KEY (a, b)', $this->platform->getPrimaryKeyDeclarationSQL( - new Index(null, ['a', 'b'], true, true) + new Index('', ['a', 'b'], true, true) ) ); } @@ -391,12 +391,12 @@ public function testGeneratesUniqueConstraintDeclarationSQL() : void 'CONSTRAINT unique_constraint UNIQUE CLUSTERED (a, b)', $this->platform->getUniqueConstraintDeclarationSQL( 'unique_constraint', - new Index(null, ['a', 'b'], true, false, ['clustered']) + new Index('', ['a', 'b'], true, false, ['clustered']) ) ); self::assertEquals( 'UNIQUE (a, b)', - $this->platform->getUniqueConstraintDeclarationSQL(null, new Index(null, ['a', 'b'], true, false)) + $this->platform->getUniqueConstraintDeclarationSQL('', new Index('', ['a', 'b'], true, false)) ); } From cede6ecc9bb30784292eef25e70793a9fe20bd2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Thu, 23 Apr 2020 09:31:58 +0200 Subject: [PATCH 12/33] Ignore issues when testing with deliberate --- .../Tests/DBAL/Platforms/SQLAnywherePlatformTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php index 31a0efcc669..a1ce2134336 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php @@ -517,6 +517,9 @@ public function testGeneratesDropIndexSQL() : void )); } + /** + * @psalm-suppress InvalidArgument + */ public function testCannotGenerateDropIndexSQLWithInvalidIndexParameter() : void { $this->expectException(InvalidArgumentException::class); @@ -524,6 +527,9 @@ public function testCannotGenerateDropIndexSQLWithInvalidIndexParameter() : void $this->platform->getDropIndexSQL(['index'], 'table'); } + /** + * @psalm-suppress InvalidArgument + */ public function testCannotGenerateDropIndexSQLWithInvalidTableParameter() : void { $this->expectException(InvalidArgumentException::class); From 76fc010904cb9c98a8c21d79efcf7e7c02989a36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Fri, 24 Apr 2020 09:01:13 +0200 Subject: [PATCH 13/33] Make sure to pass in a string Not all RDBMS have a concept of database, apparently (see SQLAnywhere). Those who do not should pass in a string to stay compatible with the signature. --- lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | 4 ++-- .../Tests/DBAL/Platforms/SQLAnywhere12PlatformTest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index 53e097d36eb..bb4a3a569e8 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -2816,8 +2816,8 @@ public function getListTableConstraintsSQL($table) } /** - * @param string $table - * @param string|null $database + * @param string $table + * @param string $database * * @return string * diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere12PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere12PlatformTest.php index e60f6b1c7f1..5e2882a9168 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere12PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywhere12PlatformTest.php @@ -52,7 +52,7 @@ public function testGeneratesSequenceSqlCommands() : void ); self::assertEquals( 'SELECT sequence_name, increment_by, start_with, min_value FROM SYS.SYSSEQUENCE', - $this->platform->getListSequencesSQL(null) + $this->platform->getListSequencesSQL('') ); } From 7c0e1ba4554397622a9346e5dd0e5deac957e25b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Fri, 24 Apr 2020 09:05:46 +0200 Subject: [PATCH 14/33] Document platform --- .../DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php | 4 ++++ .../DBAL/Platforms/AbstractSQLServerPlatformTestCase.php | 4 ++++ .../Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php | 6 ++++++ .../Tests/DBAL/Platforms/PostgreSQL92PlatformTest.php | 8 ++++++++ 4 files changed, 22 insertions(+) diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php index 4da784c3805..d4193766452 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Platforms; +use Doctrine\DBAL\Platforms\PostgreSqlPlatform; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ColumnDiff; use Doctrine\DBAL\Schema\Comparator; @@ -16,6 +17,9 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCase { + /** @var PostgreSqlPlatform */ + protected $platform; + public function getGenerateTableSql() : string { return 'CREATE TABLE test (id SERIAL NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))'; diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php index 40426da5c2b..e7f7c0d71c1 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\DBAL\Platforms; use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Platforms\SQLServerPlatform; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ColumnDiff; use Doctrine\DBAL\Schema\Index; @@ -14,6 +15,9 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCase { + /** @var SQLServerPlatform */ + protected $platform; + public function getGenerateTableSql() : string { return 'CREATE TABLE test (id INT IDENTITY NOT NULL, test NVARCHAR(255), PRIMARY KEY (id))'; diff --git a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php index 4552acb9122..235db34e9e0 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php @@ -22,6 +22,9 @@ class OraclePlatformTest extends AbstractPlatformTestCase { + /** @var OraclePlatform */ + protected $platform; + /** * @return mixed[][] */ @@ -76,6 +79,9 @@ public function testInvalidIdentifiers(string $identifier) : void $platform->assertValidIdentifier($identifier); } + /** + * @return OraclePlatform + */ public function createPlatform() : AbstractPlatform { return new OraclePlatform(); diff --git a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL92PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL92PlatformTest.php index 276c32935b3..04e9d953480 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL92PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSQL92PlatformTest.php @@ -8,6 +8,14 @@ class PostgreSQL92PlatformTest extends AbstractPostgreSqlPlatformTestCase { + /** @var PostgreSQL92Platform */ + protected $platform; + + /** + * {@inheritdoc} + * + * @return PostgreSQL92Platform + */ public function createPlatform() : AbstractPlatform { return new PostgreSQL92Platform(); From dc8d2f3439dfabc74a2b1d0c0d1d7fe80d7d05e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Fri, 24 Apr 2020 20:21:16 +0200 Subject: [PATCH 15/33] Add missing return type declarations --- lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Driver.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Driver.php b/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Driver.php index dbf342814f9..c1b2110eb4b 100644 --- a/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Driver.php +++ b/lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Driver.php @@ -33,6 +33,8 @@ public function createDatabasePlatformForVersion($version) /** * {@inheritdoc} + * + * @return DrizzlePlatform */ public function getDatabasePlatform() { @@ -41,6 +43,8 @@ public function getDatabasePlatform() /** * {@inheritdoc} + * + * @return DrizzleSchemaManager */ public function getSchemaManager(\Doctrine\DBAL\Connection $conn) { From 05fcd8c77fca3ec08705ec141a6d823d7f905e05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Fri, 24 Apr 2020 21:51:10 +0200 Subject: [PATCH 16/33] Document null as a possible type --- lib/Doctrine/DBAL/Connection.php | 6 +++--- lib/Doctrine/DBAL/Logging/SQLLogger.php | 6 +++--- lib/Doctrine/DBAL/SQLParserUtils.php | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index 4a9a8cd959c..9165fce083f 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -1034,9 +1034,9 @@ public function query() * * This method supports PDO binding types as well as DBAL mapping types. * - * @param string $query The SQL query. - * @param mixed[] $params The query parameters. - * @param int[]|string[] $types The parameter types. + * @param string $query The SQL query. + * @param array $params The query parameters. + * @param array $types The parameter types. * * @return int The number of affected rows. * diff --git a/lib/Doctrine/DBAL/Logging/SQLLogger.php b/lib/Doctrine/DBAL/Logging/SQLLogger.php index 2e94611b6a2..3cb885affa5 100644 --- a/lib/Doctrine/DBAL/Logging/SQLLogger.php +++ b/lib/Doctrine/DBAL/Logging/SQLLogger.php @@ -10,9 +10,9 @@ interface SQLLogger /** * Logs a SQL statement somewhere. * - * @param string $sql The SQL to be executed. - * @param mixed[]|null $params The SQL parameters. - * @param int[]|string[]|null $types The SQL parameter types. + * @param string $sql The SQL to be executed. + * @param mixed[]|null $params The SQL parameters. + * @param array $types The SQL parameter types. * * @return void */ diff --git a/lib/Doctrine/DBAL/SQLParserUtils.php b/lib/Doctrine/DBAL/SQLParserUtils.php index 9e3fa0e658f..7bfe71e4d97 100644 --- a/lib/Doctrine/DBAL/SQLParserUtils.php +++ b/lib/Doctrine/DBAL/SQLParserUtils.php @@ -118,9 +118,9 @@ private static function collectPlaceholders(string $statement, string $match, st /** * 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 int[]|string[] $types The types the previous parameters are in. + * @param string $query The SQL query to execute. + * @param mixed[] $params The parameters to bind to the query. + * @param array $types The types the previous parameters are in. * * @return mixed[] * From 464f15018d15342c17e496e13e1aeee5f453ca3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Fri, 24 Apr 2020 22:18:01 +0200 Subject: [PATCH 17/33] Update PHPStorm stubs That alone fixes 6 issues found by Psalm --- composer.lock | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/composer.lock b/composer.lock index fbcb548dbf9..3329a978cae 100644 --- a/composer.lock +++ b/composer.lock @@ -683,25 +683,30 @@ }, { "name": "jetbrains/phpstorm-stubs", - "version": "v2019.1", + "version": "v2019.3", "source": { "type": "git", "url": "https://github.com/JetBrains/phpstorm-stubs.git", - "reference": "9e309771f362e979ecfb429303ad7a402c657234" + "reference": "883b6facd78e01c0743b554af86fa590c2573f40" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/JetBrains/phpstorm-stubs/zipball/9e309771f362e979ecfb429303ad7a402c657234", - "reference": "9e309771f362e979ecfb429303ad7a402c657234", + "url": "https://api.github.com/repos/JetBrains/phpstorm-stubs/zipball/883b6facd78e01c0743b554af86fa590c2573f40", + "reference": "883b6facd78e01c0743b554af86fa590c2573f40", "shasum": "" }, "require-dev": { - "nikic/php-parser": "v4.0.1", + "nikic/php-parser": "^4", "php": "^7.1", "phpdocumentor/reflection-docblock": "^4.3", - "phpunit/phpunit": "7.1.4" + "phpunit/phpunit": "^7" }, "type": "library", + "autoload": { + "files": [ + "PhpStormStubsMap.php" + ] + }, "notification-url": "https://packagist.org/downloads/", "license": [ "Apache-2.0" @@ -718,7 +723,7 @@ "stubs", "type" ], - "time": "2019-03-25T16:59:23+00:00" + "time": "2019-12-05T16:56:26+00:00" }, { "name": "myclabs/deep-copy", From 3a86a6b03984fdacafb9f279683cabba84b7168a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Fri, 24 Apr 2020 22:32:36 +0200 Subject: [PATCH 18/33] Use the appropriate notation for generators --- tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php | 2 +- tests/Doctrine/Tests/DBAL/Driver/StatementIteratorTest.php | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php index 6cb8fabb785..a1be0507d9a 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php @@ -215,7 +215,7 @@ protected function getDatabasePlatformsForVersions() : array } /** - * @return mixed[][] + * @return iterable */ public static function exceptionConversionProvider() : iterable { diff --git a/tests/Doctrine/Tests/DBAL/Driver/StatementIteratorTest.php b/tests/Doctrine/Tests/DBAL/Driver/StatementIteratorTest.php index b3d8abc6b85..e3f1c97eb16 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/StatementIteratorTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/StatementIteratorTest.php @@ -43,6 +43,8 @@ public function testIteratorIterationCallsFetchOncePerStep() : void } /** + * @param class-string $class + * * @dataProvider statementProvider() */ public function testStatementIterationCallsFetchOncePerStep(string $class) : void @@ -80,7 +82,7 @@ private function assertIterationCallsFetchOncePerStep(Traversable $iterator, int } /** - * @return string[][] + * @return iterable}> */ public static function statementProvider() : iterable { From 49bd008e06916fbcf343989ad73a43468c67a005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sat, 25 Apr 2020 09:25:11 +0200 Subject: [PATCH 19/33] Document property --- .../DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php index 0aec5dc14b5..3e4d15cc8a2 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php @@ -7,6 +7,7 @@ use Doctrine\DBAL\Schema; use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\ForeignKeyConstraint; +use Doctrine\DBAL\Schema\PostgreSqlSchemaManager; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Types\BlobType; @@ -20,6 +21,9 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase { + /** @var PostgreSqlSchemaManager */ + protected $schemaManager; + protected function tearDown() : void { parent::tearDown(); From a6af5795b579644662b560458aff772cca751501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sat, 25 Apr 2020 09:25:21 +0200 Subject: [PATCH 20/33] Address deprecation --- .../DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php index 3e4d15cc8a2..956192fe661 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php @@ -32,7 +32,7 @@ protected function tearDown() : void return; } - $this->connection->getConfiguration()->setFilterSchemaAssetsExpression(null); + $this->connection->getConfiguration()->setSchemaAssetsFilter(null); } /** From ca5aceb06c8b2c25bcedd653860eee94b9213457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sat, 25 Apr 2020 11:05:12 +0200 Subject: [PATCH 21/33] Account for columnar expected result This is what is expected with FETCH_COLUMN --- 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 eb24e8160c3..05548da1dbd 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php @@ -195,7 +195,7 @@ public function testFetchAllColumn() : void } /** - * @param array> $expectedResult + * @param array>|list $expectedResult */ private function assertCacheNonCacheSelectSameFetchModeAreEqual(array $expectedResult, int $fetchMode) : void { From 580d139f7f8120e331a25233f1eaa581232d159e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sat, 25 Apr 2020 11:24:03 +0200 Subject: [PATCH 22/33] Fix wrong phpdoc --- tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php b/tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php index 217b27d1f2f..6078fb1ab8c 100644 --- a/tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php +++ b/tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php @@ -21,7 +21,7 @@ class QueryCacheProfileTest extends DbalTestCase /** @var int[] */ private $params = [666]; - /** @var string[] */ + /** @var int[] */ private $types = [ParameterType::INTEGER]; /** @var string[] */ From 682012fcf7e69ba7f599a27d9944c249e3db315a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sat, 25 Apr 2020 12:00:41 +0200 Subject: [PATCH 23/33] Suppress InvalidArgument error This is precisely what we are testing here. --- tests/Doctrine/Tests/DBAL/DriverManagerTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Doctrine/Tests/DBAL/DriverManagerTest.php b/tests/Doctrine/Tests/DBAL/DriverManagerTest.php index 1f3e69c365a..7577d5504b6 100644 --- a/tests/Doctrine/Tests/DBAL/DriverManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/DriverManagerTest.php @@ -107,6 +107,7 @@ public function testCustomWrapper() : void /** * @requires extension pdo_sqlite + * @psalm-suppress InvalidArgument */ public function testInvalidWrapperClass() : void { From fa71f7f0879273a024c88d7c44ef52ba320f2008 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sat, 25 Apr 2020 20:28:24 +0200 Subject: [PATCH 24/33] Use an empty string instead of null See https://github.com/vimeo/psalm/issues/3224 --- .../DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index 665ea42b87e..cc6084f644c 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -60,7 +60,7 @@ protected function getPlatformName() : string $e = explode('\\', $class); $testClass = end($e); - return strtolower(str_replace('SchemaManagerTest', null, $testClass)); + return strtolower(str_replace('SchemaManagerTest', '', $testClass)); } protected function setUp() : void From 7fc2268f2b0725cac59aebc3e640abc4becad6ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sun, 26 Apr 2020 12:04:02 +0200 Subject: [PATCH 25/33] Use level 6 --- psalm.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/psalm.xml b/psalm.xml index 6fe713be249..a6e0a0c0558 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,7 +1,7 @@ Date: Fri, 1 May 2020 09:34:44 +0200 Subject: [PATCH 26/33] Address warning from PHPUnit This hack is temporary and should be removed on 3.0.x --- tests/Doctrine/Tests/DBAL/ConnectionTest.php | 5 ++--- .../DBAL/FutureVersionAwarePlatformDriver.php | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 tests/Doctrine/Tests/DBAL/FutureVersionAwarePlatformDriver.php diff --git a/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/ConnectionTest.php index 8134ee03275..7aa7725b129 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -22,7 +22,6 @@ use Doctrine\DBAL\Logging\EchoSQLLogger; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; -use Doctrine\DBAL\VersionAwarePlatformDriver; use Doctrine\Tests\DbalTestCase; use Exception; use PHPUnit\Framework\MockObject\MockObject; @@ -762,7 +761,7 @@ public function testCallConnectOnce(string $method, array $params) : void */ public function testPlatformDetectionIsTriggerOnlyOnceOnRetrievingPlatform() : void { - $driverMock = $this->createMock([Driver::class, VersionAwarePlatformDriver::class]); + $driverMock = $this->createMock(FutureVersionAwarePlatformDriver::class); $driverConnectionMock = $this->createMock(ServerInfoAwareConnection::class); @@ -883,7 +882,7 @@ public function testThrowsExceptionWhenInValidPlatformSpecified() : void */ public function testRethrowsOriginalExceptionOnDeterminingPlatformWhenConnectingToNonExistentDatabase() : void { - $driverMock = $this->createMock([Driver::class, VersionAwarePlatformDriver::class]); + $driverMock = $this->createMock(FutureVersionAwarePlatformDriver::class); $connection = new Connection(['dbname' => 'foo'], $driverMock); $originalException = new Exception('Original exception'); diff --git a/tests/Doctrine/Tests/DBAL/FutureVersionAwarePlatformDriver.php b/tests/Doctrine/Tests/DBAL/FutureVersionAwarePlatformDriver.php new file mode 100644 index 00000000000..2601fbd9334 --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/FutureVersionAwarePlatformDriver.php @@ -0,0 +1,15 @@ + Date: Fri, 1 May 2020 08:15:36 +0200 Subject: [PATCH 27/33] Describe return type accurately This return type is conditional to $params['wrapperClass']. Luckily, recent versions of Psalm allow documenting it properly. See https://github.com/vimeo/psalm/issues/3277 Note that phpstan is not able to understand this yet, but still attempts to, hence the extra ignore rules. --- composer.json | 2 +- composer.lock | 12 ++++++------ lib/Doctrine/DBAL/DriverManager.php | 10 +++++++--- phpstan.neon.dist | 7 +++++++ 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index 09263687d3d..68b7fe623be 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,7 @@ "phpunit/phpunit": "^8.5.5", "psalm/plugin-phpunit": "^0.10.0", "symfony/console": "^2.0.5|^3.0|^4.0|^5.0", - "vimeo/psalm": "^3.11" + "vimeo/psalm": "^3.11.4" }, "suggest": { "symfony/console": "For helpful console commands such as SQL execution and import of files." diff --git a/composer.lock b/composer.lock index 3329a978cae..37114014b9a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9157c6d35dd39f5399592fd91126fa07", + "content-hash": "0372454a0ee2de4c2051cc13cbb23b72", "packages": [ { "name": "doctrine/cache", @@ -2995,16 +2995,16 @@ }, { "name": "vimeo/psalm", - "version": "3.11.2", + "version": "3.11.4", "source": { "type": "git", "url": "https://github.com/vimeo/psalm.git", - "reference": "d470903722cfcbc1cd04744c5491d3e6d13ec3d9" + "reference": "58e1d8e68e5098bf4fbfdfb420c38d563f882549" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/vimeo/psalm/zipball/d470903722cfcbc1cd04744c5491d3e6d13ec3d9", - "reference": "d470903722cfcbc1cd04744c5491d3e6d13ec3d9", + "url": "https://api.github.com/repos/vimeo/psalm/zipball/58e1d8e68e5098bf4fbfdfb420c38d563f882549", + "reference": "58e1d8e68e5098bf4fbfdfb420c38d563f882549", "shasum": "" }, "require": { @@ -3089,7 +3089,7 @@ "inspection", "php" ], - "time": "2020-04-13T12:47:11+00:00" + "time": "2020-05-11T13:39:25+00:00" }, { "name": "webmozart/assert", diff --git a/lib/Doctrine/DBAL/DriverManager.php b/lib/Doctrine/DBAL/DriverManager.php index 95cb27c29d7..d3ed63a7f39 100644 --- a/lib/Doctrine/DBAL/DriverManager.php +++ b/lib/Doctrine/DBAL/DriverManager.php @@ -115,11 +115,15 @@ private function __construct() * driverClass: * The driver class to use. * - * @param mixed[] $params The parameters. - * @param Configuration|null $config The configuration to use. - * @param EventManager|null $eventManager The event manager to use. + * @param array{wrapperClass?: class-string} $params + * @param Configuration|null $config The configuration to use. + * @param EventManager|null $eventManager The event manager to use. * * @throws DBALException + * + * @phpstan-param mixed[] $params + * @psalm-return ($params is array{wrapperClass:mixed} ? T : Connection) + * @template T of Connection */ public static function getConnection( array $params, diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 70544cbf7ec..40bc84910a1 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -83,3 +83,10 @@ parameters: # Needs Generics - '~Method Doctrine\\DBAL\\Schema\\SchemaDiff::getNewTablesSortedByDependencies\(\) should return array but returns array.~' + + # Caused by phpdoc annotations intended for Psalm + - + message: '~Unable to resolve the template type T in call to method static method Doctrine\\DBAL\\DriverManager::getConnection\(\)~' + paths: + - %currentWorkingDirectory%/lib/Doctrine/DBAL/Id/TableGenerator.php + - %currentWorkingDirectory%/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php From 1a4f23f41dbbaf061212300aee7824184916979a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sun, 3 May 2020 13:59:02 +0200 Subject: [PATCH 28/33] Add contract for createPlatform()'s return type --- .../DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php index d4193766452..10ccac9a046 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Platforms; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\PostgreSqlPlatform; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ColumnDiff; @@ -20,6 +21,11 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa /** @var PostgreSqlPlatform */ protected $platform; + /** + * @return PostgreSqlPlatform + */ + abstract public function createPlatform() : AbstractPlatform; + public function getGenerateTableSql() : string { return 'CREATE TABLE test (id SERIAL NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))'; From 3fa5b3e06b5ab2bea5dd54f4f1f384ff568ef687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Mon, 4 May 2020 22:21:55 +0200 Subject: [PATCH 29/33] Add missing use statement --- tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php index a1be0507d9a..5c8a5dd29ba 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php @@ -28,6 +28,7 @@ use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\VersionAwarePlatformDriver; use Doctrine\Tests\DbalTestCase; +use PHPUnit\Framework\MockObject\MockObject; use ReflectionProperty; use function array_merge; use function get_class; From b0523e0544cfdd5b96346da6efd83a4d95b60a18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Mon, 4 May 2020 22:22:38 +0200 Subject: [PATCH 30/33] Use valid arguments --- .../Tests/DBAL/Functional/Driver/SQLSrv/StatementTest.php | 2 +- .../Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/StatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/StatementTest.php index 4e34f693c0c..29df5aea958 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/SQLSrv/StatementTest.php @@ -27,7 +27,7 @@ protected function setUp() : void public function testFailureToPrepareResultsInException() : void { // use the driver connection directly to avoid having exception wrapped - $stmt = $this->connection->getWrappedConnection()->prepare(null); + $stmt = $this->connection->getWrappedConnection()->prepare(''); // it's impossible to prepare the statement without bound variables for SQL Server, // so the preparation happens before the first execution when variables are already in place diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php index c534833129f..b4008191230 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php @@ -98,7 +98,7 @@ public function testListForeignKeysFromExistingDatabase() : void new Schema\ForeignKeyConstraint( ['log'], 'log', - [null], + [''], 'FK_3', ['onUpdate' => 'SET NULL', 'onDelete' => 'NO ACTION', 'deferrable' => false, 'deferred' => false] ), From b00a2e3aa26f90e04a570392146e5a9c5554f0fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Wed, 27 May 2020 19:12:58 +0200 Subject: [PATCH 31/33] Update psalm --- composer.lock | 153 ++++++++++++++++++++++++++------------------------ 1 file changed, 81 insertions(+), 72 deletions(-) diff --git a/composer.lock b/composer.lock index 37114014b9a..ab624b240e9 100644 --- a/composer.lock +++ b/composer.lock @@ -158,16 +158,16 @@ "packages-dev": [ { "name": "amphp/amp", - "version": "v2.4.2", + "version": "v2.4.4", "source": { "type": "git", "url": "https://github.com/amphp/amp.git", - "reference": "feca077369a47263b22156b3c6389e55f3809f24" + "reference": "1e58d53e4af390efc7813e36cd215bd82cba4b06" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/amphp/amp/zipball/feca077369a47263b22156b3c6389e55f3809f24", - "reference": "feca077369a47263b22156b3c6389e55f3809f24", + "url": "https://api.github.com/repos/amphp/amp/zipball/1e58d53e4af390efc7813e36cd215bd82cba4b06", + "reference": "1e58d53e4af390efc7813e36cd215bd82cba4b06", "shasum": "" }, "require": { @@ -180,7 +180,7 @@ "jetbrains/phpstorm-stubs": "^2019.3", "phpunit/phpunit": "^6.0.9 | ^7", "react/promise": "^2", - "vimeo/psalm": "^3.9@dev" + "vimeo/psalm": "^3.11@dev" }, "type": "library", "extra": { @@ -232,7 +232,7 @@ "non-blocking", "promise" ], - "time": "2020-04-04T15:05:26+00:00" + "time": "2020-04-30T04:54:50+00:00" }, { "name": "amphp/byte-stream", @@ -775,16 +775,16 @@ }, { "name": "netresearch/jsonmapper", - "version": "v2.0.0", + "version": "v2.1.0", "source": { "type": "git", "url": "https://github.com/cweiske/jsonmapper.git", - "reference": "e245890383c3ed38b6d202ee373c23ccfebc0f54" + "reference": "e0f1e33a71587aca81be5cffbb9746510e1fe04e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/cweiske/jsonmapper/zipball/e245890383c3ed38b6d202ee373c23ccfebc0f54", - "reference": "e245890383c3ed38b6d202ee373c23ccfebc0f54", + "url": "https://api.github.com/repos/cweiske/jsonmapper/zipball/e0f1e33a71587aca81be5cffbb9746510e1fe04e", + "reference": "e0f1e33a71587aca81be5cffbb9746510e1fe04e", "shasum": "" }, "require": { @@ -817,7 +817,7 @@ } ], "description": "Map nested JSON structures onto PHP classes", - "time": "2020-03-04T17:23:33+00:00" + "time": "2020-04-16T18:48:43+00:00" }, { "name": "nikic/php-parser", @@ -1074,24 +1074,21 @@ }, { "name": "phpdocumentor/reflection-common", - "version": "2.0.0", + "version": "2.1.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionCommon.git", - "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a" + "reference": "6568f4687e5b41b054365f9ae03fcb1ed5f2069b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/63a995caa1ca9e5590304cd845c15ad6d482a62a", - "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/6568f4687e5b41b054365f9ae03fcb1ed5f2069b", + "reference": "6568f4687e5b41b054365f9ae03fcb1ed5f2069b", "shasum": "" }, "require": { "php": ">=7.1" }, - "require-dev": { - "phpunit/phpunit": "~6" - }, "type": "library", "extra": { "branch-alias": { @@ -1122,44 +1119,42 @@ "reflection", "static analysis" ], - "time": "2018-08-07T13:53:10+00:00" + "time": "2020-04-27T09:25:28+00:00" }, { "name": "phpdocumentor/reflection-docblock", - "version": "4.3.2", + "version": "5.1.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "b83ff7cfcfee7827e1e78b637a5904fe6a96698e" + "reference": "cd72d394ca794d3466a3b2fc09d5a6c1dc86b47e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/b83ff7cfcfee7827e1e78b637a5904fe6a96698e", - "reference": "b83ff7cfcfee7827e1e78b637a5904fe6a96698e", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/cd72d394ca794d3466a3b2fc09d5a6c1dc86b47e", + "reference": "cd72d394ca794d3466a3b2fc09d5a6c1dc86b47e", "shasum": "" }, "require": { - "php": "^7.0", - "phpdocumentor/reflection-common": "^1.0.0 || ^2.0.0", - "phpdocumentor/type-resolver": "~0.4 || ^1.0.0", - "webmozart/assert": "^1.0" + "ext-filter": "^7.1", + "php": "^7.2", + "phpdocumentor/reflection-common": "^2.0", + "phpdocumentor/type-resolver": "^1.0", + "webmozart/assert": "^1" }, "require-dev": { - "doctrine/instantiator": "^1.0.5", - "mockery/mockery": "^1.0", - "phpunit/phpunit": "^6.4" + "doctrine/instantiator": "^1", + "mockery/mockery": "^1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "4.x-dev" + "dev-master": "5.x-dev" } }, "autoload": { "psr-4": { - "phpDocumentor\\Reflection\\": [ - "src/" - ] + "phpDocumentor\\Reflection\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -1170,33 +1165,36 @@ { "name": "Mike van Riel", "email": "me@mikevanriel.com" + }, + { + "name": "Jaap van Otterdijk", + "email": "account@ijaap.nl" } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2019-09-12T14:27:41+00:00" + "time": "2020-02-22T12:28:44+00:00" }, { "name": "phpdocumentor/type-resolver", - "version": "1.0.1", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "2e32a6d48972b2c1976ed5d8967145b6cec4a4a9" + "reference": "7462d5f123dfc080dfdf26897032a6513644fc95" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/2e32a6d48972b2c1976ed5d8967145b6cec4a4a9", - "reference": "2e32a6d48972b2c1976ed5d8967145b6cec4a4a9", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/7462d5f123dfc080dfdf26897032a6513644fc95", + "reference": "7462d5f123dfc080dfdf26897032a6513644fc95", "shasum": "" }, "require": { - "php": "^7.1", + "php": "^7.2", "phpdocumentor/reflection-common": "^2.0" }, "require-dev": { - "ext-tokenizer": "^7.1", - "mockery/mockery": "~1", - "phpunit/phpunit": "^7.0" + "ext-tokenizer": "^7.2", + "mockery/mockery": "~1" }, "type": "library", "extra": { @@ -1220,7 +1218,7 @@ } ], "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", - "time": "2019-08-22T18:11:29+00:00" + "time": "2020-02-18T18:59:58+00:00" }, { "name": "phpspec/prophecy", @@ -1820,16 +1818,16 @@ }, { "name": "psr/log", - "version": "1.1.2", + "version": "1.1.3", "source": { "type": "git", "url": "https://github.com/php-fig/log.git", - "reference": "446d54b4cb6bf489fc9d75f55843658e6f25d801" + "reference": "0f73288fd15629204f9d42b7055f72dacbe811fc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/446d54b4cb6bf489fc9d75f55843658e6f25d801", - "reference": "446d54b4cb6bf489fc9d75f55843658e6f25d801", + "url": "https://api.github.com/repos/php-fig/log/zipball/0f73288fd15629204f9d42b7055f72dacbe811fc", + "reference": "0f73288fd15629204f9d42b7055f72dacbe811fc", "shasum": "" }, "require": { @@ -1863,7 +1861,7 @@ "psr", "psr-3" ], - "time": "2019-11-01T11:05:21+00:00" + "time": "2020-03-23T09:12:05+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -2722,16 +2720,16 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.12.0", + "version": "v1.17.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "550ebaac289296ce228a706d0867afc34687e3f4" + "reference": "e94c8b1bbe2bc77507a1056cdb06451c75b427f9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/550ebaac289296ce228a706d0867afc34687e3f4", - "reference": "550ebaac289296ce228a706d0867afc34687e3f4", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/e94c8b1bbe2bc77507a1056cdb06451c75b427f9", + "reference": "e94c8b1bbe2bc77507a1056cdb06451c75b427f9", "shasum": "" }, "require": { @@ -2743,7 +2741,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.12-dev" + "dev-master": "1.17-dev" } }, "autoload": { @@ -2776,7 +2774,21 @@ "polyfill", "portable" ], - "time": "2019-08-06T08:03:45+00:00" + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-05-12T16:14:59+00:00" }, { "name": "symfony/polyfill-mbstring", @@ -2995,16 +3007,16 @@ }, { "name": "vimeo/psalm", - "version": "3.11.4", + "version": "3.11.5", "source": { "type": "git", "url": "https://github.com/vimeo/psalm.git", - "reference": "58e1d8e68e5098bf4fbfdfb420c38d563f882549" + "reference": "3c60609c218d4d4b3b257728b8089094e5c6c6c2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/vimeo/psalm/zipball/58e1d8e68e5098bf4fbfdfb420c38d563f882549", - "reference": "58e1d8e68e5098bf4fbfdfb420c38d563f882549", + "url": "https://api.github.com/repos/vimeo/psalm/zipball/3c60609c218d4d4b3b257728b8089094e5c6c6c2", + "reference": "3c60609c218d4d4b3b257728b8089094e5c6c6c2", "shasum": "" }, "require": { @@ -3066,8 +3078,7 @@ }, "autoload": { "psr-4": { - "Psalm\\Plugin\\": "src/Psalm/Plugin", - "Psalm\\": "src/Psalm" + "Psalm\\": "src/Psalm/" }, "files": [ "src/functions.php", @@ -3089,35 +3100,33 @@ "inspection", "php" ], - "time": "2020-05-11T13:39:25+00:00" + "time": "2020-05-27T15:12:09+00:00" }, { "name": "webmozart/assert", - "version": "1.5.0", + "version": "1.8.0", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "88e6d84706d09a236046d686bbea96f07b3a34f4" + "reference": "ab2cb0b3b559010b75981b1bdce728da3ee90ad6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/88e6d84706d09a236046d686bbea96f07b3a34f4", - "reference": "88e6d84706d09a236046d686bbea96f07b3a34f4", + "url": "https://api.github.com/repos/webmozart/assert/zipball/ab2cb0b3b559010b75981b1bdce728da3ee90ad6", + "reference": "ab2cb0b3b559010b75981b1bdce728da3ee90ad6", "shasum": "" }, "require": { "php": "^5.3.3 || ^7.0", "symfony/polyfill-ctype": "^1.8" }, + "conflict": { + "vimeo/psalm": "<3.9.1" + }, "require-dev": { "phpunit/phpunit": "^4.8.36 || ^7.5.13" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.3-dev" - } - }, "autoload": { "psr-4": { "Webmozart\\Assert\\": "src/" @@ -3139,7 +3148,7 @@ "check", "validate" ], - "time": "2019-08-24T08:43:50+00:00" + "time": "2020-04-18T12:12:48+00:00" }, { "name": "webmozart/glob", From 9f9629c0fa383533d7055c2da5a9dcac2033af80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Wed, 27 May 2020 19:45:18 +0200 Subject: [PATCH 32/33] Avoid mocking inexistent classes It confuses both Psalm and PHPStan, and involves complicated mocking. --- tests/Doctrine/Tests/DBAL/ConnectionTest.php | 9 ++-- .../SchemaManagerFunctionalTestCase.php | 19 +++++--- .../Platforms/AbstractPlatformTestCase.php | 45 ++++++++++++------- 3 files changed, 46 insertions(+), 27 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/ConnectionTest.php index 7aa7725b129..fc018fcc072 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -144,9 +144,7 @@ public function testGetEventManager() : void public function testConnectDispatchEvent() : void { - $listenerMock = $this->getMockBuilder($this->getMockClass('ConnectDispatchEventListener')) - ->addMethods(['postConnect']) - ->getMock(); + $listenerMock = $this->createMock(ConnectDispatchEventListener::class); $listenerMock->expects($this->once())->method('postConnect'); $eventManager = new EventManager(); @@ -948,3 +946,8 @@ public function testExecuteCacheQueryStripsPlatformFromConnectionParamsBeforeGen $connection->executeCacheQuery($query, [], [], $queryCacheProfile); } } + +interface ConnectDispatchEventListener +{ + public function postConnect() : void; +} diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index cc6084f644c..cf93304fae6 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -369,10 +369,7 @@ public function testListTableColumnsDispatchEvent() : void $this->schemaManager->dropAndCreateTable($table); - $listenerMock = $this->getMockBuilder($this->getMockClass('ListTableColumnsDispatchEventListener')) - ->addMethods(['onSchemaColumnDefinition']) - ->getMock(); - + $listenerMock = $this->createMock(ListTableColumnsDispatchEventListener::class); $listenerMock ->expects($this->exactly(7)) ->method('onSchemaColumnDefinition'); @@ -397,9 +394,7 @@ public function testListTableIndexesDispatchEvent() : void $this->schemaManager->dropAndCreateTable($table); - $listenerMock = $this->getMockBuilder($this->getMockClass('ListTableIndexesDispatchEventListener')) - ->addMethods(['onSchemaIndexDefinition']) - ->getMock(); + $listenerMock = $this->createMock(ListTableIndexesDispatchEventListener::class); $listenerMock ->expects($this->exactly(3)) ->method('onSchemaIndexDefinition'); @@ -1653,3 +1648,13 @@ public function testSchemaDiffForeignKeys() : void } } } + +interface ListTableColumnsDispatchEventListener +{ + public function onSchemaColumnDefinition() : void; +} + +interface ListTableIndexesDispatchEventListener +{ + public function onSchemaIndexDefinition() : void; +} diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php index 6ae57373cc3..f90a8060608 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php @@ -372,9 +372,7 @@ public function testGetCustomColumnDeclarationSql() : void public function testGetCreateTableSqlDispatchEvent() : void { - $listenerMock = $this->getMockBuilder($this->getMockClass('GetCreateTableSqlDispatchEvenListener')) - ->addMethods(['onSchemaCreateTable', 'onSchemaCreateTableColumn']) - ->getMock(); + $listenerMock = $this->createMock(GetCreateTableSqlDispatchEventListener::class); $listenerMock ->expects($this->once()) ->method('onSchemaCreateTable'); @@ -396,9 +394,7 @@ public function testGetCreateTableSqlDispatchEvent() : void public function testGetDropTableSqlDispatchEvent() : void { - $listenerMock = $this->getMockBuilder($this->getMockClass('GetDropTableSqlDispatchEventListener')) - ->addMethods(['onSchemaDropTable']) - ->getMock(); + $listenerMock = $this->createMock(GetDropTableSqlDispatchEventListener::class); $listenerMock ->expects($this->once()) ->method('onSchemaDropTable'); @@ -413,17 +409,7 @@ public function testGetDropTableSqlDispatchEvent() : void public function testGetAlterTableSqlDispatchEvent() : void { - $events = [ - 'onSchemaAlterTable', - 'onSchemaAlterTableAddColumn', - 'onSchemaAlterTableRemoveColumn', - 'onSchemaAlterTableChangeColumn', - 'onSchemaAlterTableRenameColumn', - ]; - - $listenerMock = $this->getMockBuilder($this->getMockClass('GetAlterTableSqlDispatchEvenListener')) - ->addMethods($events) - ->getMock(); + $listenerMock = $this->createMock(GetAlterTableSqlDispatchEventListener::class); $listenerMock ->expects($this->once()) ->method('onSchemaAlterTable'); @@ -1532,3 +1518,28 @@ public function testZeroOffsetWithoutLimitIsIgnored() : void ); } } + +interface GetCreateTableSqlDispatchEventListener +{ + public function onSchemaCreateTable() : void; + + public function onSchemaCreateTableColumn() : void; +} + +interface GetAlterTableSqlDispatchEventListener +{ + public function onSchemaAlterTable() : void; + + public function onSchemaAlterTableAddColumn() : void; + + public function onSchemaAlterTableRemoveColumn() : void; + + public function onSchemaAlterTableChangeColumn() : void; + + public function onSchemaAlterTableRenameColumn() : void; +} + +interface GetDropTableSqlDispatchEventListener +{ + public function onSchemaDropTable() : void; +} From 1bc66b34a92c0f38d30397e5ade8e51c42a7dae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Wed, 27 May 2020 21:47:39 +0200 Subject: [PATCH 33/33] Ignore error about Connection::lastInsertId() The php docs are not very clear about that one. --- phpstan.neon.dist | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 40bc84910a1..88ad9e321d2 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -90,3 +90,8 @@ parameters: paths: - %currentWorkingDirectory%/lib/Doctrine/DBAL/Id/TableGenerator.php - %currentWorkingDirectory%/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php + + - + message: '~Method Doctrine\\DBAL\\Driver\\PDOSqlsrv\\Connection\:\:lastInsertId\(\) should return string but returns string\|false\|null\.~' + paths: + - %currentWorkingDirectory%/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Connection.php