Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.10.x' into 2.11.x
Browse files Browse the repository at this point in the history
  • Loading branch information
greg0ire committed May 27, 2020
2 parents 256cefa + 9f2e25c commit ce21834
Show file tree
Hide file tree
Showing 42 changed files with 400 additions and 194 deletions.
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

0 comments on commit ce21834

Please sign in to comment.