Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manual merge of 2.10.x into 2.11.x #4022

Merged
merged 37 commits into from
May 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
41fb43e
Ignore all violations of the LowercasePHPFunctions sniff in SQLSrvSta…
morozov May 27, 2020
2348831
Merge pull request #4031 from morozov/ignore-sqlsrv-case
morozov May 27, 2020
f4c43d5
Document actual types
greg0ire Apr 21, 2020
9a617ed
Install phpunit plugin for Psalm
greg0ire Apr 21, 2020
96d5bcc
Make return type verified and accurate
greg0ire Apr 21, 2020
a8c772d
Update phpunit
greg0ire Apr 22, 2020
befc59a
Improve phpdoc
greg0ire Apr 22, 2020
69cf6c4
Remove uneeded key
greg0ire Apr 22, 2020
8f7ea52
Use list
greg0ire Apr 22, 2020
99b542a
Use shortcut
greg0ire Apr 22, 2020
633f9e3
Suppress deliberate error
greg0ire Apr 23, 2020
f2a0ab7
Use TrimMode::UNSPECIFIED over null
greg0ire Apr 23, 2020
014ac9c
Pass the right type of argument
greg0ire Apr 23, 2020
cede6ec
Ignore issues when testing with deliberate
greg0ire Apr 23, 2020
76fc010
Make sure to pass in a string
greg0ire Apr 24, 2020
7c0e1ba
Document platform
greg0ire Apr 24, 2020
dc8d2f3
Add missing return type declarations
greg0ire Apr 24, 2020
05fcd8c
Document null as a possible type
greg0ire Apr 24, 2020
464f150
Update PHPStorm stubs
greg0ire Apr 24, 2020
3a86a6b
Use the appropriate notation for generators
greg0ire Apr 24, 2020
49bd008
Document property
greg0ire Apr 25, 2020
a6af579
Address deprecation
greg0ire Apr 25, 2020
ca5aceb
Account for columnar expected result
greg0ire Apr 25, 2020
580d139
Fix wrong phpdoc
greg0ire Apr 25, 2020
682012f
Suppress InvalidArgument error
greg0ire Apr 25, 2020
fa71f7f
Use an empty string instead of null
greg0ire Apr 25, 2020
7fc2268
Use level 6
greg0ire Apr 26, 2020
9d73084
Address warning from PHPUnit
greg0ire May 1, 2020
487b00f
Describe return type accurately
greg0ire May 1, 2020
1a4f23f
Add contract for createPlatform()'s return type
greg0ire May 3, 2020
3fa5b3e
Add missing use statement
greg0ire May 4, 2020
b0523e0
Use valid arguments
greg0ire May 4, 2020
b00a2e3
Update psalm
greg0ire May 27, 2020
9f9629c
Avoid mocking inexistent classes
greg0ire May 27, 2020
1bc66b3
Ignore error about Connection::lastInsertId()
greg0ire May 27, 2020
9f2e25c
Merge pull request #3977 from greg0ire/psalm-6
greg0ire May 27, 2020
ce21834
Merge remote-tracking branch 'origin/2.10.x' into 2.11.x
greg0ire May 27, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@
"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",
"slevomat/coding-standard": "^6.3.6",
"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."
Expand Down
309 changes: 192 additions & 117 deletions composer.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions lib/Doctrine/DBAL/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1265,9 +1265,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<mixed> $params The query parameters.
* @param array<int|string|null> $types The parameter types.
*
* @return int The number of affected rows.
*
Expand Down
4 changes: 4 additions & 0 deletions lib/Doctrine/DBAL/Driver/DrizzlePDOMySql/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public function createDatabasePlatformForVersion($version)

/**
* {@inheritdoc}
*
* @return DrizzlePlatform
*/
public function getDatabasePlatform()
{
Expand All @@ -43,6 +45,8 @@ public function getDatabasePlatform()

/**
* {@inheritdoc}
*
* @return DrizzleSchemaManager
*/
public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
{
Expand Down
4 changes: 4 additions & 0 deletions lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ public function rollBack()
* {@inheritdoc}
*
* @deprecated The error information is available via exceptions.
*
* @return int
*/
public function errorCode()
{
Expand All @@ -212,6 +214,8 @@ public function errorCode()
* {@inheritdoc}
*
* @deprecated The error information is available via exceptions.
*
* @return string
*/
public function errorInfo()
{
Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,8 @@ public function errorCode()
* {@inheritdoc}
*
* @deprecated The error information is available via exceptions.
*
* @return string
*/
public function errorInfo()
{
Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ public function exec($statement)

/**
* {@inheritdoc}
*
* @return int|false
*/
public function lastInsertId($name = null)
{
Expand Down
9 changes: 7 additions & 2 deletions lib/Doctrine/DBAL/Driver/PDOConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,24 @@ public function getServerVersion()
* @param string $prepareString
* @param array<int, int> $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);
}
}

/**
* {@inheritdoc}
*
* @return \PDOStatement
*/
public function query()
{
Expand Down
10 changes: 7 additions & 3 deletions lib/Doctrine/DBAL/DriverManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,15 @@ private function __construct()
* <b>driverClass</b>:
* 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<T>} $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,
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/DBAL/Logging/SQLLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<int|string|null> $types The SQL parameter types.
*
* @return void
*/
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -2816,8 +2816,8 @@ public function getListTableConstraintsSQL($table)
}

/**
* @param string $table
* @param string|null $database
* @param string $table
* @param string $database
*
* @return string
*
Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/DBAL/Portability/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ public function executeQuery($query, array $params = [], $types = [], ?QueryCach

/**
* {@inheritdoc}
*
* @return Statement
*/
public function prepare($statement)
{
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/DBAL/SQLParserUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string|int|null> $types The types the previous parameters are in.
*
* @return mixed[]
*
Expand Down
2 changes: 1 addition & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@

<!-- The SQLSRV_* functions are defined in the upper case by the sqlsrv extension and violate the standard
see https://docs.microsoft.com/en-us/sql/connect/php/constants-microsoft-drivers-for-php-for-sql-server -->
<rule ref="Squiz.PHP.LowercasePHPFunctions.UseStatementUppercase">
<rule ref="Squiz.PHP.LowercasePHPFunctions">
<exclude-pattern>lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php</exclude-pattern>
</rule>
</ruleset>
12 changes: 12 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,15 @@ parameters:

# Needs Generics
- '~Method Doctrine\\DBAL\\Schema\\SchemaDiff::getNewTablesSortedByDependencies\(\) should return array<Doctrine\\DBAL\\Schema\\Table> but returns array<object>.~'

# 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

-
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
2 changes: 1 addition & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<psalm
totallyTyped="false"
errorLevel="7"
errorLevel="6"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/DBAL/Cache/QueryCacheProfileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class QueryCacheProfileTest extends DbalTestCase
/** @var int[] */
private $params = [666];

/** @var string[] */
/** @var int[] */
private $types = [ParameterType::INTEGER];

/** @var string[] */
Expand Down
14 changes: 8 additions & 6 deletions tests/Doctrine/Tests/DBAL/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -145,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();
Expand Down Expand Up @@ -762,7 +759,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);

Expand Down Expand Up @@ -883,7 +880,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');
Expand Down Expand Up @@ -949,3 +946,8 @@ public function testExecuteCacheQueryStripsPlatformFromConnectionParamsBeforeGen
$connection->executeCacheQuery($query, [], [], $queryCacheProfile);
}
}

interface ConnectDispatchEventListener
{
public function postConnect() : void;
}
10 changes: 6 additions & 4 deletions tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -198,11 +199,12 @@ abstract protected function createPlatform() : AbstractPlatform;
*/
abstract protected function createSchemaManager(Connection $connection) : AbstractSchemaManager;

/**
* @return Connection&MockObject
*/
protected function getConnectionMock() : Connection
{
return $this->getMockBuilder(Connection::class)
->disableOriginalConstructor()
->getMock();
return $this->createMock(Connection::class);
}

/**
Expand All @@ -214,7 +216,7 @@ protected function getDatabasePlatformsForVersions() : array
}

/**
* @return mixed[][]
* @return iterable<mixed[]>
*/
public static function exceptionConversionProvider() : iterable
{
Expand Down
4 changes: 3 additions & 1 deletion tests/Doctrine/Tests/DBAL/Driver/StatementIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public function testIteratorIterationCallsFetchOncePerStep() : void
}

/**
* @param class-string<Statement> $class
*
* @dataProvider statementProvider()
*/
public function testStatementIterationCallsFetchOncePerStep(string $class) : void
Expand Down Expand Up @@ -80,7 +82,7 @@ private function assertIterationCallsFetchOncePerStep(Traversable $iterator, int
}

/**
* @return string[][]
* @return iterable<array{0: class-string<Statement>}>
*/
public static function statementProvider() : iterable
{
Expand Down
5 changes: 3 additions & 2 deletions tests/Doctrine/Tests/DBAL/DriverManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public function testCustomWrapper() : void

/**
* @requires extension pdo_sqlite
* @psalm-suppress InvalidArgument
*/
public function testInvalidWrapperClass() : void
{
Expand Down Expand Up @@ -242,7 +243,7 @@ public function testDatabaseUrl($url, $expected) : void
}

/**
* @return array<string, array<int, mixed>>
* @return array<string, list<mixed>>
*/
public function databaseUrls() : iterable
{
Expand Down Expand Up @@ -341,7 +342,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' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
class ResultCacheTest extends DbalFunctionalTestCase
{
/** @var array<int, array<int, int|string>> */
/** @var list<array{test_int: int, test_string: string}> */
private $expectedResult = [['test_int' => 100, 'test_string' => 'foo'], ['test_int' => 200, 'test_string' => 'bar'], ['test_int' => 300, 'test_string' => 'baz']];

/** @var DebugStack */
Expand Down Expand Up @@ -195,7 +195,7 @@ public function testFetchAllColumn() : void
}

/**
* @param array<int, array<int, int|string>> $expectedResult
* @param array<int, array<int, int|string>>|list<int> $expectedResult
*/
private function assertCacheNonCacheSelectSameFetchModeAreEqual(array $expectedResult, int $fetchMode) : void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,6 +21,9 @@

class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
{
/** @var PostgreSqlSchemaManager */
protected $schemaManager;

protected function tearDown() : void
{
parent::tearDown();
Expand All @@ -28,7 +32,7 @@ protected function tearDown() : void
return;
}

$this->connection->getConfiguration()->setFilterSchemaAssetsExpression(null);
$this->connection->getConfiguration()->setSchemaAssetsFilter(null);
}

/**
Expand Down
Loading