Unverified Commit 8ef1b6c2 authored by Grégoire Paris's avatar Grégoire Paris

Merge branch '3.0.x'

parents a7aa9760 9d22f7bc
......@@ -45,9 +45,10 @@
"phpstan/phpstan-phpunit": "^0.12",
"phpstan/phpstan-strict-rules": "^0.12.2",
"phpunit/phpunit": "^9.1.1",
"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."
......
This diff is collapsed.
......@@ -113,7 +113,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">
<exclude-pattern>src/Driver/SQLSrv/SQLSrvStatement.php</exclude-pattern>
<rule ref="Squiz.PHP.LowercasePHPFunctions">
<exclude-pattern>lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php</exclude-pattern>
</rule>
</ruleset>
......@@ -109,6 +109,19 @@ parameters:
-
message: '~^Call to an undefined method Doctrine\\DBAL\\Driver::createDatabasePlatformForVersion\(\)\.$~'
path: %currentWorkingDirectory%/tests/Driver/AbstractDriverTest.php
# 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%/src/Id/TableGenerator.php
- %currentWorkingDirectory%/src/Schema/SqliteSchemaManager.php
-
message: '~Method Doctrine\\DBAL\\Driver\\PDOSqlsrv\\Connection\:\:lastInsertId\(\) should return string but returns string\|false\|null\.~'
paths:
- %currentWorkingDirectory%/src/Driver/PDOSqlsrv/Connection.php
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
......
<?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"
......
......@@ -118,11 +118,15 @@ final class DriverManager
* <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,
......
......@@ -100,9 +100,9 @@ class SQLParserUtils
/**
* 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[]
*
......
......@@ -112,9 +112,7 @@ class ConnectionTest extends TestCase
public function testConnectDispatchEvent() : void
{
$listenerMock = $this->getMockBuilder($this->getMockClass('ConnectDispatchEventListener'))
->addMethods(['postConnect'])
->getMock();
$listenerMock = $this->createMock(ConnectDispatchEventListener::class);
$listenerMock->expects(self::once())->method('postConnect');
$eventManager = new EventManager();
......@@ -839,3 +837,8 @@ class ConnectionTest extends TestCase
$connection->executeCacheQuery($query, [], [], $queryCacheProfile);
}
}
interface ConnectDispatchEventListener
{
public function postConnect() : void;
}
......@@ -185,9 +185,7 @@ abstract class AbstractDriverTest extends TestCase
*/
protected function getConnectionMock() : Connection
{
return $this->getMockBuilder(Connection::class)
->disableOriginalConstructor()
->getMock();
return $this->createMock(Connection::class);
}
/**
......@@ -199,7 +197,7 @@ abstract class AbstractDriverTest extends TestCase
}
/**
* @return mixed[][]
* @return iterable<mixed[]>
*/
public static function exceptionConversionProvider() : iterable
{
......
......@@ -69,6 +69,7 @@ class DriverManagerTest extends TestCase
/**
* @requires extension pdo_sqlite
* @psalm-suppress InvalidArgument
*/
public function testInvalidWrapperClass() : void
{
......@@ -158,7 +159,7 @@ class DriverManagerTest extends TestCase
}
/**
* @return array<string, mixed>
* @return array<string, list<mixed>>
*/
public function databaseUrls() : iterable
{
......@@ -257,7 +258,7 @@ class DriverManagerTest extends TestCase
],
],
'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' => [
......
......@@ -21,7 +21,7 @@ use const CASE_LOWER;
*/
class ResultCacheTest extends FunctionalTestCase
{
/** @var array<int, array<string, 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 */
......@@ -195,7 +195,7 @@ class ResultCacheTest extends FunctionalTestCase
}
/**
* @param array<int, mixed> $expectedResult
* @param array<int, array<int, int|string>>|list<int> $expectedResult
*/
private function assertCacheNonCacheSelectSameFetchModeAreEqual(array $expectedResult, callable $fetchMode) : void
{
......
......@@ -353,10 +353,7 @@ abstract class SchemaManagerFunctionalTestCase extends FunctionalTestCase
$this->schemaManager->dropAndCreateTable($table);
$listenerMock = $this->getMockBuilder($this->getMockClass('ListTableColumnsDispatchEventListener'))
->addMethods(['onSchemaColumnDefinition'])
->getMock();
$listenerMock = $this->createMock(ListTableColumnsDispatchEventListener::class);
$listenerMock
->expects(self::exactly(7))
->method('onSchemaColumnDefinition');
......@@ -382,9 +379,7 @@ abstract class SchemaManagerFunctionalTestCase extends FunctionalTestCase
$this->schemaManager->dropAndCreateTable($table);
$listenerMock = $this->getMockBuilder($this->getMockClass('ListTableIndexesDispatchEventListener'))
->addMethods(['onSchemaIndexDefinition'])
->getMock();
$listenerMock = $this->createMock(ListTableIndexesDispatchEventListener::class);
$listenerMock
->expects(self::exactly(3))
->method('onSchemaIndexDefinition');
......@@ -1327,3 +1322,13 @@ abstract class SchemaManagerFunctionalTestCase extends FunctionalTestCase
}
}
}
interface ListTableColumnsDispatchEventListener
{
public function onSchemaColumnDefinition() : void;
}
interface ListTableIndexesDispatchEventListener
{
public function onSchemaIndexDefinition() : void;
}
......@@ -385,9 +385,7 @@ abstract class AbstractPlatformTestCase extends TestCase
public function testGetCreateTableSqlDispatchEvent() : void
{
$listenerMock = $this->getMockBuilder($this->getMockClass('GetCreateTableSqlDispatchEvenListener'))
->addMethods(['onSchemaCreateTable', 'onSchemaCreateTableColumn'])
->getMock();
$listenerMock = $this->createMock(GetCreateTableSqlDispatchEventListener::class);
$listenerMock
->expects(self::once())
->method('onSchemaCreateTable');
......@@ -409,9 +407,7 @@ abstract class AbstractPlatformTestCase extends TestCase
public function testGetDropTableSqlDispatchEvent() : void
{
$listenerMock = $this->getMockBuilder($this->getMockClass('GetDropTableSqlDispatchEventListener'))
->addMethods(['onSchemaDropTable'])
->getMock();
$listenerMock = $this->createMock(GetDropTableSqlDispatchEventListener::class);
$listenerMock
->expects(self::once())
->method('onSchemaDropTable');
......@@ -426,17 +422,7 @@ abstract class AbstractPlatformTestCase extends TestCase
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(self::once())
->method('onSchemaAlterTable');
......@@ -1622,3 +1608,28 @@ abstract class AbstractPlatformTestCase extends TestCase
);
}
}
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;
}
......@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace Doctrine\DBAL\Tests\Platforms;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\PostgreSQL100Platform;
use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\ColumnDiff;
......@@ -19,9 +21,12 @@ use function sprintf;
abstract class AbstractPostgreSQLPlatformTestCase extends AbstractPlatformTestCase
{
/** @var PostgreSQL94Platform */
/** @var PostgreSQL94Platform|PostgreSQL100Platform */
protected $platform;
/** @return PostgreSQL94Platform|PostgreSQL100Platform */
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))';
......
......@@ -19,6 +19,9 @@ use function assert;
abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCase
{
/** @var SQLServer2012Platform */
protected $platform;
public function getGenerateTableSql() : string
{
return 'CREATE TABLE test (id INT IDENTITY NOT NULL, test NVARCHAR(255), PRIMARY KEY (id))';
......
......@@ -26,6 +26,9 @@ use function uniqid;
class OraclePlatformTest extends AbstractPlatformTestCase
{
/** @var OraclePlatform */
protected $platform;
/**
* @return mixed[][]
*/
......@@ -78,6 +81,9 @@ class OraclePlatformTest extends AbstractPlatformTestCase
OraclePlatform::assertValidIdentifier($identifier);
}
/**
* @return OraclePlatform
*/
public function createPlatform() : AbstractPlatform
{
return new OraclePlatform();
......
......@@ -345,14 +345,14 @@ class SQLAnywhere16PlatformTest extends AbstractPlatformTestCase
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)
)
);
}
......
......@@ -16,6 +16,12 @@ use function assert;
class SqlitePlatformTest extends AbstractPlatformTestCase
{
/** @var SqlitePlatform */
protected $platform;
/**
* @return SqlitePlatform
*/
public function createPlatform() : AbstractPlatform
{
return new SqlitePlatform();
......
......@@ -875,6 +875,7 @@ class ComparatorTest extends TestCase
/**
* @group DBAL-106
* @psalm-suppress NullArgument
*/
public function testDiffDecimalWithNullPrecision() : void
{
......
......@@ -20,7 +20,7 @@ class MySqlSchemaManagerTest extends TestCase
/** @var AbstractSchemaManager */
private $manager;
/** @var Connection|MockObject */
/** @var Connection&MockObject */
private $conn;
protected function setUp() : void
......
......@@ -19,13 +19,13 @@ use PHPUnit\Framework\TestCase;
class StatementTest extends TestCase
{
/** @var Connection|MockObject */
/** @var Connection&MockObject */
private $conn;
/** @var Configuration|MockObject */
/** @var Configuration&MockObject */
private $configuration;
/** @var DriverStatement|MockObject */
/** @var DriverStatement&MockObject */
private $driverStatement;
protected function setUp() : void
......
......@@ -21,7 +21,7 @@ class RunSqlCommandTest extends TestCase
/** @var RunSqlCommand */
private $command;
/** @var Connection|MockObject */
/** @var Connection&MockObject */
private $connectionMock;
protected function setUp() : void
......
......@@ -19,7 +19,7 @@ class TypeTest extends TestCase
}
/**
* @return string[][]
* @return iterable<string[]>
*/
public function defaultTypesProvider() : iterable
{
......@@ -28,7 +28,10 @@ class TypeTest extends TestCase
continue;
}
yield [$constant->getValue()];
$constantValue = $constant->getValue();
self::assertIsString($constantValue);
yield [$constantValue];
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment