From cd8197ce93c77ea0339cd85760220a91f6554d03 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 14 Oct 2020 14:45:06 -0700 Subject: [PATCH 01/21] Use type intersection instead of union types for mock objects --- tests/Doctrine/Tests/DBAL/ConnectionTest.php | 2 +- .../Tests/DBAL/Driver/IBMDB2/DB2ConnectionTest.php | 2 +- .../Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php | 2 +- .../Tests/DBAL/Driver/OCI8/OCI8ConnectionTest.php | 2 +- tests/Doctrine/Tests/DBAL/Driver/PDO/ExceptionTest.php | 3 +-- .../DBAL/Driver/SQLAnywhere/SQLAnywhereConnectionTest.php | 2 +- .../Tests/DBAL/Driver/SQLSrv/SQLSrvConnectionTest.php | 2 +- tests/Doctrine/Tests/DBAL/Portability/StatementTest.php | 6 +++--- tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php | 2 +- tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php | 2 +- tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php | 2 +- .../DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php | 8 ++++---- tests/Doctrine/Tests/DBAL/Types/ArrayTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php | 2 +- tests/Doctrine/Tests/DBAL/Types/BinaryTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/BlobTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/BooleanTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php | 2 +- .../Tests/DBAL/Types/DateTimeImmutableTypeTest.php | 2 +- .../Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/DecimalTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/FloatTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/IntegerTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/JsonTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/ObjectTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/StringTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php | 2 +- .../Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php | 2 +- 33 files changed, 38 insertions(+), 39 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/ConnectionTest.php index 5543a42dec7..feed00275a2 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -51,7 +51,7 @@ protected function setUp(): void } /** - * @return Connection|MockObject + * @return Connection&MockObject */ private function getExecuteStatementMockConnection() { diff --git a/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2ConnectionTest.php index e8b08f745e5..1d7d88ec342 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2ConnectionTest.php @@ -14,7 +14,7 @@ class DB2ConnectionTest extends DbalTestCase /** * The ibm_db2 driver connection mock under test. * - * @var DB2Connection|MockObject + * @var DB2Connection&MockObject */ private $connectionMock; diff --git a/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php index 9611da063cd..c0953ea532b 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/Mysqli/MysqliConnectionTest.php @@ -19,7 +19,7 @@ class MysqliConnectionTest extends DbalFunctionalTestCase /** * The mysqli driver connection mock under test. * - * @var MysqliConnection|MockObject + * @var MysqliConnection&MockObject */ private $connectionMock; diff --git a/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8ConnectionTest.php index 12cd8ef7af4..5185f4abc10 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/OCI8/OCI8ConnectionTest.php @@ -14,7 +14,7 @@ class OCI8ConnectionTest extends DbalTestCase /** * The oci8 driver connection mock under test. * - * @var OCI8Connection|MockObject + * @var OCI8Connection&MockObject */ private $connectionMock; diff --git a/tests/Doctrine/Tests/DBAL/Driver/PDO/ExceptionTest.php b/tests/Doctrine/Tests/DBAL/Driver/PDO/ExceptionTest.php index 4ba493ab2ee..f9323041038 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/PDO/ExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/PDO/ExceptionTest.php @@ -5,7 +5,6 @@ use Doctrine\DBAL\Driver\PDO\Exception; use Doctrine\Tests\DbalTestCase; use PDOException; -use PHPUnit\Framework\MockObject\MockObject; /** * @requires extension pdo @@ -28,7 +27,7 @@ class ExceptionTest extends DbalTestCase /** * The wrapped PDO exception mock. * - * @var PDOException|MockObject + * @var PDOException */ private $wrappedException; diff --git a/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/SQLAnywhereConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/SQLAnywhereConnectionTest.php index b2d1ddef6fc..54cedfce3cd 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/SQLAnywhereConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/SQLAnywhere/SQLAnywhereConnectionTest.php @@ -14,7 +14,7 @@ class SQLAnywhereConnectionTest extends DbalTestCase /** * The sqlanywhere driver connection mock under test. * - * @var SQLAnywhereConnection|MockObject + * @var SQLAnywhereConnection&MockObject */ private $connectionMock; diff --git a/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/SQLSrvConnectionTest.php b/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/SQLSrvConnectionTest.php index 8d424ee21b6..75781443962 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/SQLSrvConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/SQLSrv/SQLSrvConnectionTest.php @@ -11,7 +11,7 @@ class SQLSrvConnectionTest extends DbalTestCase /** * The sqlsrv driver connection mock under test. * - * @var SQLSrvConnection|MockObject + * @var SQLSrvConnection&MockObject */ private $connectionMock; diff --git a/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php b/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php index f41124a8334..f83ab92e50d 100644 --- a/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Portability/StatementTest.php @@ -15,13 +15,13 @@ class StatementTest extends DbalTestCase { - /** @var Connection|MockObject */ + /** @var Connection&MockObject */ protected $conn; /** @var Statement */ protected $stmt; - /** @var DriverStatement|MockObject */ + /** @var DriverStatement&MockObject */ protected $wrappedStmt; protected function setUp(): void @@ -157,7 +157,7 @@ public function testRowCount(): void } /** - * @return Connection|MockObject + * @return Connection&MockObject */ protected function createConnection() { diff --git a/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php index faa784a6137..36b0551d338 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/DB2SchemaManagerTest.php @@ -18,7 +18,7 @@ */ final class DB2SchemaManagerTest extends TestCase { - /** @var Connection|MockObject */ + /** @var Connection&MockObject */ private $conn; /** @var DB2SchemaManager */ diff --git a/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php b/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php index 414d779438e..f5100e6c856 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php @@ -46,7 +46,7 @@ public function testSchemaDiffToSaveSql(): void } /** - * @return AbstractPlatform|MockObject + * @return AbstractPlatform&MockObject */ private function createPlatform(bool $unsafe) { diff --git a/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php b/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php index 4c0ada138d0..c1b9ede62cb 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php @@ -11,7 +11,7 @@ class TableDiffTest extends TestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; public function setUp(): void diff --git a/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php b/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php index c4e1aca9e85..26354adef9d 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php @@ -12,7 +12,7 @@ class CreateSchemaSqlCollectorTest extends TestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platformMock; /** @var CreateSchemaSqlCollector */ @@ -134,7 +134,7 @@ public function testResetsQueries(): void } /** - * @return ForeignKeyConstraint|MockObject + * @return ForeignKeyConstraint&MockObject */ private function createForeignKeyConstraintMock() { @@ -144,7 +144,7 @@ private function createForeignKeyConstraintMock() } /** - * @return Sequence|MockObject + * @return Sequence&MockObject */ private function createSequenceMock() { @@ -154,7 +154,7 @@ private function createSequenceMock() } /** - * @return Table|MockObject + * @return Table&MockObject */ private function createTableMock() { diff --git a/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php b/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php index df48f2f14b3..03a960d5034 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php @@ -13,7 +13,7 @@ class ArrayTest extends DbalTestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; /** @var ArrayType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php b/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php index b748cdf19a2..ee111fab030 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Types/BaseDateTypeTestCase.php @@ -16,7 +16,7 @@ abstract class BaseDateTypeTestCase extends TestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ protected $platform; /** @var Type */ diff --git a/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php b/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php index 23514f6160b..5adf15b1cfa 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php @@ -17,7 +17,7 @@ class BinaryTest extends DbalTestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ protected $platform; /** @var BinaryType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/BlobTest.php b/tests/Doctrine/Tests/DBAL/Types/BlobTest.php index 23486819798..2c5c6f2f87c 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BlobTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BlobTest.php @@ -15,7 +15,7 @@ class BlobTest extends DbalTestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ protected $platform; /** @var BlobType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php b/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php index 0fe4a2d5a5e..62d70fc0336 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php @@ -10,7 +10,7 @@ class BooleanTest extends DbalTestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; /** @var BooleanType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php index e06e9b02f11..6970096e0de 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php @@ -16,7 +16,7 @@ class DateImmutableTypeTest extends TestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; /** @var DateImmutableType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php b/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php index 6c85de36510..f849afe2938 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php @@ -14,7 +14,7 @@ final class DateIntervalTest extends DbalTestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; /** @var DateIntervalType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php index 4c3a772d344..4ae30947b5f 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php @@ -16,7 +16,7 @@ class DateTimeImmutableTypeTest extends TestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; /** @var DateTimeImmutableType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php index eafaedcb729..2192588a5b7 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php @@ -16,7 +16,7 @@ class DateTimeTzImmutableTypeTest extends TestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; /** @var DateTimeTzImmutableType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php b/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php index bf05598ab32..feacd0a2f0a 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php @@ -10,7 +10,7 @@ class DecimalTest extends DbalTestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; /** @var DecimalType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/FloatTest.php b/tests/Doctrine/Tests/DBAL/Types/FloatTest.php index 44623c28b90..9543b844c0f 100644 --- a/tests/Doctrine/Tests/DBAL/Types/FloatTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/FloatTest.php @@ -10,7 +10,7 @@ class FloatTest extends DbalTestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; /** @var FloatType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php index 3615b687bd9..fd488c862ab 100644 --- a/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php @@ -10,7 +10,7 @@ class GuidTypeTest extends DbalTestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; /** @var GuidType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php b/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php index 7241a9237e1..ae589c8dd78 100644 --- a/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php @@ -10,7 +10,7 @@ class IntegerTest extends DbalTestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; /** @var IntegerType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php b/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php index 4603f3d6206..ac438672426 100644 --- a/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php @@ -16,7 +16,7 @@ class JsonArrayTest extends DbalTestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ protected $platform; /** @var JsonArrayType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/JsonTest.php b/tests/Doctrine/Tests/DBAL/Types/JsonTest.php index 0cf41b7f867..71c444b9a48 100644 --- a/tests/Doctrine/Tests/DBAL/Types/JsonTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/JsonTest.php @@ -17,7 +17,7 @@ class JsonTest extends DbalTestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ protected $platform; /** @var JsonType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php b/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php index df961faa3b9..c7fd42fa799 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php @@ -14,7 +14,7 @@ class ObjectTest extends DbalTestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; /** @var ObjectType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php b/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php index 31ed1a310dd..bc0956a326d 100644 --- a/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php @@ -10,7 +10,7 @@ class SmallIntTest extends DbalTestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; /** @var SmallIntType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/StringTest.php b/tests/Doctrine/Tests/DBAL/Types/StringTest.php index 688a06ba870..4f62fed044a 100644 --- a/tests/Doctrine/Tests/DBAL/Types/StringTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/StringTest.php @@ -10,7 +10,7 @@ class StringTest extends DbalTestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; /** @var StringType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php index c9518fe6dbf..4d664f4966f 100644 --- a/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php @@ -16,7 +16,7 @@ class TimeImmutableTypeTest extends TestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; /** @var TimeImmutableType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php index a8652a6115b..3326e13ac72 100644 --- a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php @@ -14,7 +14,7 @@ class VarDateTimeImmutableTypeTest extends TestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; /** @var VarDateTimeImmutableType */ diff --git a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php index 586b36e89cd..5f2f4e50df8 100644 --- a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php @@ -12,7 +12,7 @@ class VarDateTimeTest extends DbalTestCase { - /** @var AbstractPlatform|MockObject */ + /** @var AbstractPlatform&MockObject */ private $platform; /** @var VarDateTimeType */ From 7b55dae743d8cd4ad80d3000a1aa8e09d9ea1bcb Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 14 Oct 2020 14:49:33 -0700 Subject: [PATCH 02/21] Fixed ArgumentTypeCoercion issues caused by using strings as class names --- tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php | 3 ++- .../DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php | 2 +- tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php | 2 +- tests/Doctrine/Tests/DBAL/Types/TimeTest.php | 3 ++- tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php | 4 ++-- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php index ef68b5be62f..d4123c79188 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php @@ -20,6 +20,7 @@ use Doctrine\DBAL\Types\Types; use Doctrine\Tests\DbalFunctionalTestCase; use PDO; +use stdClass; use function array_change_key_case; use function array_filter; @@ -734,7 +735,7 @@ public function testFetchAllStyleObject(): void $results = $stmt->fetchAll(FetchMode::STANDARD_OBJECT); self::assertCount(1, $results); - self::assertInstanceOf('stdClass', $results[0]); + self::assertInstanceOf(stdClass::class, $results[0]); self::assertEquals( 1, diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php index 5adf73f7aa0..fc7e00ae3e3 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php @@ -887,7 +887,7 @@ public function testAltersTableColumnCommentIfRequiredByType(): void $tableDiff = $comparator->diffTable($table1, $table2); - $this->assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); + $this->assertNotFalse($tableDiff); $this->assertSame( [ 'ALTER TABLE "foo" ALTER "bar" TYPE TIMESTAMP(0) WITHOUT TIME ZONE', diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php index 72868f328a8..472c64ee201 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php @@ -29,7 +29,7 @@ public function testDateTimeConvertsToPHPValue(): void { // Birthday of jwage and also birthday of Doctrine. Send him a present ;) $date = $this->type->convertToPHPValue('1985-09-01 00:00:00', $this->platform); - self::assertInstanceOf('DateTime', $date); + self::assertInstanceOf(DateTime::class, $date); self::assertEquals('1985-09-01 00:00:00', $date->format('Y-m-d H:i:s')); } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php index f7367f283ec..b02987678c9 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php @@ -29,7 +29,7 @@ public function testDateTimeConvertsToPHPValue(): void { // Birthday of jwage and also birthday of Doctrine. Send him a present ;) $date = $this->type->convertToPHPValue('1985-09-01 00:00:00', $this->platform); - self::assertInstanceOf('DateTime', $date); + self::assertInstanceOf(DateTime::class, $date); self::assertEquals('1985-09-01 00:00:00', $date->format('Y-m-d H:i:s')); } diff --git a/tests/Doctrine/Tests/DBAL/Types/TimeTest.php b/tests/Doctrine/Tests/DBAL/Types/TimeTest.php index 8bec5c2ae37..358fa6e0a38 100644 --- a/tests/Doctrine/Tests/DBAL/Types/TimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/TimeTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\DBAL\Types; +use DateTime; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\Type; @@ -16,7 +17,7 @@ protected function setUp(): void public function testTimeConvertsToPHPValue(): void { - self::assertInstanceOf('DateTime', $this->type->convertToPHPValue('5:30:55', $this->platform)); + self::assertInstanceOf(DateTime::class, $this->type->convertToPHPValue('5:30:55', $this->platform)); } public function testDateFieldResetInPHPValue(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php index 5f2f4e50df8..a82e07949ee 100644 --- a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php @@ -42,7 +42,7 @@ public function testDateTimeConvertsToPHPValue(): void { // Birthday of jwage and also birthday of Doctrine. Send him a present ;) $date = $this->type->convertToPHPValue('1985-09-01 00:00:00', $this->platform); - self::assertInstanceOf('DateTime', $date); + self::assertInstanceOf(DateTime::class, $date); self::assertEquals('1985-09-01 00:00:00', $date->format('Y-m-d H:i:s')); self::assertEquals('000000', $date->format('u')); } @@ -56,7 +56,7 @@ public function testInvalidDateTimeFormatConversion(): void public function testConversionWithMicroseconds(): void { $date = $this->type->convertToPHPValue('1985-09-01 00:00:00.123456', $this->platform); - self::assertInstanceOf('DateTime', $date); + self::assertInstanceOf(DateTime::class, $date); self::assertEquals('1985-09-01 00:00:00', $date->format('Y-m-d H:i:s')); self::assertEquals('123456', $date->format('u')); } From 384a1541a94baef9eb37864a8d7c88b673b16e66 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 14 Oct 2020 15:03:25 -0700 Subject: [PATCH 03/21] Instantiate specific type classes instead of using a factory --- tests/Doctrine/Tests/DBAL/Types/ArrayTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/BinaryTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/BlobTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/BooleanTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php | 5 +---- tests/Doctrine/Tests/DBAL/Types/DateTest.php | 4 ++-- .../Tests/DBAL/Types/DateTimeImmutableTypeTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php | 4 ++-- .../Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php | 4 ++-- tests/Doctrine/Tests/DBAL/Types/DecimalTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/FloatTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/IntegerTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/JsonTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/ObjectTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/StringTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php | 3 +-- tests/Doctrine/Tests/DBAL/Types/TimeTest.php | 4 ++-- .../Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php | 7 +------ tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php | 7 +------ 24 files changed, 28 insertions(+), 58 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php b/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php index 03a960d5034..ebda9c37c2e 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ArrayTest.php @@ -5,7 +5,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ArrayType; use Doctrine\DBAL\Types\ConversionException; -use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; @@ -22,7 +21,7 @@ class ArrayTest extends DbalTestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = Type::getType('array'); + $this->type = new ArrayType(); } public function testArrayConvertsToDatabaseValue(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php b/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php index 5adf15b1cfa..e1b14679c5b 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BinaryTest.php @@ -6,7 +6,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\BinaryType; use Doctrine\DBAL\Types\ConversionException; -use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Types; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; @@ -26,7 +25,7 @@ class BinaryTest extends DbalTestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = Type::getType('binary'); + $this->type = new BinaryType(); } public function testReturnsBindingType(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/BlobTest.php b/tests/Doctrine/Tests/DBAL/Types/BlobTest.php index 2c5c6f2f87c..340608fff44 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BlobTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BlobTest.php @@ -4,7 +4,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\BlobType; -use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; @@ -24,7 +23,7 @@ class BlobTest extends DbalTestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = Type::getType('blob'); + $this->type = new BlobType(); } public function testBlobNullConvertsToPHPValue(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php b/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php index 62d70fc0336..7eefeb3f9f9 100644 --- a/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/BooleanTest.php @@ -4,7 +4,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\BooleanType; -use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; @@ -19,7 +18,7 @@ class BooleanTest extends DbalTestCase protected function setUp(): void { $this->platform = $this->getMockForAbstractClass(AbstractPlatform::class); - $this->type = Type::getType('boolean'); + $this->type = new BooleanType(); } public function testBooleanConvertsToDatabaseValue(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php index 6970096e0de..46bbbd3fb39 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateImmutableTypeTest.php @@ -8,7 +8,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\DateImmutableType; -use Doctrine\DBAL\Types\Type; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -24,8 +23,8 @@ class DateImmutableTypeTest extends TestCase protected function setUp(): void { - $this->type = Type::getType('date_immutable'); $this->platform = $this->createMock(AbstractPlatform::class); + $this->type = new DateImmutableType(); } public function testFactoryCreatesCorrectType(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php b/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php index f849afe2938..ee81bb0e5c7 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateIntervalTest.php @@ -7,7 +7,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\DateIntervalType; -use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; use stdClass; @@ -23,9 +22,7 @@ final class DateIntervalTest extends DbalTestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = Type::getType('dateinterval'); - - self::assertInstanceOf(DateIntervalType::class, $this->type); + $this->type = new DateIntervalType(); } public function testDateIntervalConvertsToDatabaseValue(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTest.php index 1d97cceaa2c..17183125e1d 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTest.php @@ -4,7 +4,7 @@ use DateTime; use Doctrine\DBAL\Types\ConversionException; -use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\DateType; use function date_default_timezone_set; @@ -12,7 +12,7 @@ class DateTest extends BaseDateTypeTestCase { protected function setUp(): void { - $this->type = Type::getType('date'); + $this->type = new DateType(); parent::setUp(); } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php index 4ae30947b5f..72a3585fe12 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeImmutableTypeTest.php @@ -8,7 +8,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\DateTimeImmutableType; -use Doctrine\DBAL\Types\Type; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -24,8 +23,8 @@ class DateTimeImmutableTypeTest extends TestCase protected function setUp(): void { - $this->type = Type::getType('datetime_immutable'); $this->platform = $this->getMockBuilder(AbstractPlatform::class)->getMock(); + $this->type = new DateTimeImmutableType(); } public function testFactoryCreatesCorrectType(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php index 472c64ee201..5bf92f811e2 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTest.php @@ -4,13 +4,13 @@ use DateTime; use Doctrine\DBAL\Types\ConversionException; -use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\DateTimeType; class DateTimeTest extends BaseDateTypeTestCase { protected function setUp(): void { - $this->type = Type::getType('datetime'); + $this->type = new DateTimeType(); parent::setUp(); } diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php index 2192588a5b7..7992d99b65f 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzImmutableTypeTest.php @@ -8,7 +8,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\DateTimeTzImmutableType; -use Doctrine\DBAL\Types\Type; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -24,8 +23,8 @@ class DateTimeTzImmutableTypeTest extends TestCase protected function setUp(): void { - $this->type = Type::getType('datetimetz_immutable'); $this->platform = $this->createMock(AbstractPlatform::class); + $this->type = new DateTimeTzImmutableType(); } public function testFactoryCreatesCorrectType(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php index b02987678c9..f7696515f64 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DateTimeTzTest.php @@ -4,13 +4,13 @@ use DateTime; use Doctrine\DBAL\Types\ConversionException; -use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\DateTimeTzType; class DateTimeTzTest extends BaseDateTypeTestCase { protected function setUp(): void { - $this->type = Type::getType('datetimetz'); + $this->type = new DateTimeTzType(); parent::setUp(); } diff --git a/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php b/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php index feacd0a2f0a..29f88f6f54a 100644 --- a/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/DecimalTest.php @@ -4,7 +4,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\DecimalType; -use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; @@ -19,7 +18,7 @@ class DecimalTest extends DbalTestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = Type::getType('decimal'); + $this->type = new DecimalType(); } public function testDecimalConvertsToPHPValue(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/FloatTest.php b/tests/Doctrine/Tests/DBAL/Types/FloatTest.php index 9543b844c0f..7316252cade 100644 --- a/tests/Doctrine/Tests/DBAL/Types/FloatTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/FloatTest.php @@ -4,7 +4,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\FloatType; -use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; @@ -19,7 +18,7 @@ class FloatTest extends DbalTestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = Type::getType('float'); + $this->type = new FloatType(); } public function testFloatConvertsToPHPValue(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php index fd488c862ab..2c15c7cbd4b 100644 --- a/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/GuidTypeTest.php @@ -4,7 +4,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\GuidType; -use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; @@ -19,7 +18,7 @@ class GuidTypeTest extends DbalTestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = Type::getType('guid'); + $this->type = new GuidType(); } public function testConvertToPHPValue(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php b/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php index ae589c8dd78..c8f9cf952f4 100644 --- a/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/IntegerTest.php @@ -4,7 +4,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\IntegerType; -use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; @@ -19,7 +18,7 @@ class IntegerTest extends DbalTestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = Type::getType('integer'); + $this->type = new IntegerType(); } public function testIntegerConvertsToPHPValue(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php b/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php index ac438672426..2383543b322 100644 --- a/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php @@ -5,7 +5,6 @@ use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\JsonArrayType; -use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Types; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; @@ -25,7 +24,7 @@ class JsonArrayTest extends DbalTestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = Type::getType('json_array'); + $this->type = new JsonArrayType(); } public function testReturnsBindingType(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/JsonTest.php b/tests/Doctrine/Tests/DBAL/Types/JsonTest.php index 71c444b9a48..158c7bb1a9c 100644 --- a/tests/Doctrine/Tests/DBAL/Types/JsonTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/JsonTest.php @@ -6,7 +6,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\JsonType; -use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Types; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; @@ -26,7 +25,7 @@ class JsonTest extends DbalTestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = Type::getType('json'); + $this->type = new JsonType(); } public function testReturnsBindingType(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php b/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php index c7fd42fa799..227fcef9554 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php @@ -5,7 +5,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\ObjectType; -use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; use stdClass; @@ -23,7 +22,7 @@ class ObjectTest extends DbalTestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = Type::getType('object'); + $this->type = new ObjectType(); } public function testObjectConvertsToDatabaseValue(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php b/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php index bc0956a326d..4c5981f4729 100644 --- a/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/SmallIntTest.php @@ -4,7 +4,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\SmallIntType; -use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; @@ -19,7 +18,7 @@ class SmallIntTest extends DbalTestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = Type::getType('smallint'); + $this->type = new SmallIntType(); } public function testSmallIntConvertsToPHPValue(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/StringTest.php b/tests/Doctrine/Tests/DBAL/Types/StringTest.php index 4f62fed044a..5041e942e75 100644 --- a/tests/Doctrine/Tests/DBAL/Types/StringTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/StringTest.php @@ -4,7 +4,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\StringType; -use Doctrine\DBAL\Types\Type; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; @@ -19,7 +18,7 @@ class StringTest extends DbalTestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = Type::getType('string'); + $this->type = new StringType(); } public function testReturnsSqlDeclarationFromPlatformVarchar(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php index 4d664f4966f..b2365f54a40 100644 --- a/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/TimeImmutableTypeTest.php @@ -8,7 +8,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\TimeImmutableType; -use Doctrine\DBAL\Types\Type; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -24,8 +23,8 @@ class TimeImmutableTypeTest extends TestCase protected function setUp(): void { - $this->type = Type::getType('time_immutable'); $this->platform = $this->getMockBuilder(AbstractPlatform::class)->getMock(); + $this->type = new TimeImmutableType(); } public function testFactoryCreatesCorrectType(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/TimeTest.php b/tests/Doctrine/Tests/DBAL/Types/TimeTest.php index 358fa6e0a38..ceb1e9ee7d0 100644 --- a/tests/Doctrine/Tests/DBAL/Types/TimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/TimeTest.php @@ -4,13 +4,13 @@ use DateTime; use Doctrine\DBAL\Types\ConversionException; -use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\TimeType; class TimeTest extends BaseDateTypeTestCase { protected function setUp(): void { - $this->type = Type::getType('time'); + $this->type = new TimeType(); parent::setUp(); } diff --git a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php index 3326e13ac72..442409ac425 100644 --- a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeImmutableTypeTest.php @@ -7,7 +7,6 @@ use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; -use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\VarDateTimeImmutableType; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -22,12 +21,8 @@ class VarDateTimeImmutableTypeTest extends TestCase protected function setUp(): void { - if (! Type::hasType('vardatetime_immutable')) { - Type::addType('vardatetime_immutable', VarDateTimeImmutableType::class); - } - - $this->type = Type::getType('vardatetime_immutable'); $this->platform = $this->getMockForAbstractClass(AbstractPlatform::class); + $this->type = new VarDateTimeImmutableType(); } public function testReturnsName(): void diff --git a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php index a82e07949ee..206c2e094d5 100644 --- a/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/VarDateTimeTest.php @@ -5,7 +5,6 @@ use DateTime; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\ConversionException; -use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\VarDateTimeType; use Doctrine\Tests\DbalTestCase; use PHPUnit\Framework\MockObject\MockObject; @@ -21,11 +20,7 @@ class VarDateTimeTest extends DbalTestCase protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - if (! Type::hasType('vardatetime')) { - Type::addType('vardatetime', VarDateTimeType::class); - } - - $this->type = Type::getType('vardatetime'); + $this->type = new VarDateTimeType(); } public function testDateTimeConvertsToDatabaseValue(): void From df6020aadb26af458be507df00f858bd9bbc347f Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 14 Oct 2020 15:12:57 -0700 Subject: [PATCH 04/21] Fix ArgumentTypeCoercion issues about class-strings --- lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php | 6 +++--- .../DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php | 6 +++--- .../DBAL/Tools/Console/Command/ReservedWordsCommand.php | 7 ++++--- lib/Doctrine/DBAL/Types/Type.php | 8 ++++---- tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php | 3 ++- tests/Doctrine/Tests/TestUtil.php | 3 +++ 6 files changed, 19 insertions(+), 14 deletions(-) diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php index 02cc6526907..483581fedfe 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php @@ -455,9 +455,9 @@ public function free(): void /** * Casts a stdClass object to the given class name mapping its' properties. * - * @param stdClass $sourceObject Object to cast from. - * @param string|object $destinationClass Name of the class or class instance to cast to. - * @param mixed[] $ctorArgs Arguments to use for constructing the destination class instance. + * @param stdClass $sourceObject Object to cast from. + * @param class-string|object $destinationClass Name of the class or class instance to cast to. + * @param mixed[] $ctorArgs Arguments to use for constructing the destination class instance. * * @return object * diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php index 1542276dba2..513e4a508ef 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php @@ -419,9 +419,9 @@ public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) /** * Casts a stdClass object to the given class name mapping its' properties. * - * @param stdClass $sourceObject Object to cast from. - * @param string|object $destinationClass Name of the class or class instance to cast to. - * @param mixed[] $ctorArgs Arguments to use for constructing the destination class instance. + * @param stdClass $sourceObject Object to cast from. + * @param class-string|object $destinationClass Name of the class or class instance to cast to. + * @param mixed[] $ctorArgs Arguments to use for constructing the destination class instance. * * @return object * diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php index 1888efdb619..bd819af0e6a 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php @@ -4,6 +4,7 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Platforms\Keywords\DB2Keywords; +use Doctrine\DBAL\Platforms\Keywords\KeywordList; use Doctrine\DBAL\Platforms\Keywords\MySQL57Keywords; use Doctrine\DBAL\Platforms\Keywords\MySQL80Keywords; use Doctrine\DBAL\Platforms\Keywords\MySQLKeywords; @@ -41,7 +42,7 @@ class ReservedWordsCommand extends Command { - /** @var string[] */ + /** @var array> */ private $keywordListClasses = [ 'mysql' => MySQLKeywords::class, 'mysql57' => MySQL57Keywords::class, @@ -82,8 +83,8 @@ public function __construct(?ConnectionProvider $connectionProvider = null) /** * If you want to add or replace a keywords list use this command. * - * @param string $name - * @param string $class + * @param string $name + * @param class-string $class * * @return void */ diff --git a/lib/Doctrine/DBAL/Types/Type.php b/lib/Doctrine/DBAL/Types/Type.php index 5ff51c4c9bb..f8be9131bcd 100644 --- a/lib/Doctrine/DBAL/Types/Type.php +++ b/lib/Doctrine/DBAL/Types/Type.php @@ -236,8 +236,8 @@ public static function getType($name) /** * Adds a custom type to the type map. * - * @param string $name The name of the type. This should correspond to what getName() returns. - * @param string $className The class name of the custom type. + * @param string $name The name of the type. This should correspond to what getName() returns. + * @param class-string $className The class name of the custom type. * * @return void * @@ -263,8 +263,8 @@ public static function hasType($name) /** * Overrides an already defined type to use a different implementation. * - * @param string $name - * @param string $className + * @param string $name + * @param class-string $className * * @return void * diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php index 078875a4086..c08b33fb898 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php @@ -70,7 +70,8 @@ protected function setUp(): void } /** - * @param int|string $errorCode + * @param int|string $errorCode + * @param class-string $expectedClass * * @dataProvider exceptionConversionProvider */ diff --git a/tests/Doctrine/Tests/TestUtil.php b/tests/Doctrine/Tests/TestUtil.php index f45ee6e232f..3a21df3910e 100644 --- a/tests/Doctrine/Tests/TestUtil.php +++ b/tests/Doctrine/Tests/TestUtil.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests; +use Doctrine\Common\EventSubscriber; use Doctrine\DBAL\Connection; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Platforms\AbstractPlatform; @@ -137,6 +138,8 @@ private static function addDbEventSubscribers(Connection $conn): void } $evm = $conn->getEventManager(); + + /** @psalm-var class-string $subscriberClass */ foreach (explode(',', $GLOBALS['db_event_subscribers']) as $subscriberClass) { $subscriberInstance = new $subscriberClass(); $evm->addEventSubscriber($subscriberInstance); From 759a2982badbe73174382c61493fae17c175926c Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 14 Oct 2020 15:16:22 -0700 Subject: [PATCH 05/21] Fix NullArgument issues --- lib/Doctrine/DBAL/Configuration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/DBAL/Configuration.php b/lib/Doctrine/DBAL/Configuration.php index 6d2497b632d..545b0ffb0b4 100644 --- a/lib/Doctrine/DBAL/Configuration.php +++ b/lib/Doctrine/DBAL/Configuration.php @@ -73,7 +73,7 @@ public function setResultCacheImpl(Cache $cacheImpl) * * @deprecated Use Configuration::setSchemaAssetsFilter() instead * - * @param string $filterExpression + * @param string|null $filterExpression * * @return void */ From 8c1e546448e92370702b5570d7dd7014b7c494e2 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 14 Oct 2020 15:20:35 -0700 Subject: [PATCH 06/21] Fix PossiblyNullArgument issues --- .../DBAL/Cache/ResultCacheStatement.php | 2 +- .../DBAL/Driver/SQLAnywhere/Driver.php | 18 +++++++++--------- .../DBAL/Platforms/SQLServerPlatform.php | 4 ++-- .../DBAL/Schema/PostgreSqlSchemaManager.php | 18 +++++++++++------- .../Platforms/AbstractPlatformTestCase.php | 2 +- 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php index 34381e23b1c..07a6c220611 100644 --- a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php +++ b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php @@ -244,7 +244,7 @@ public function fetchAllNumeric(): array $this->store($data); - return array_map('array_values', $this->data); + return array_map('array_values', $data); } /** diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php index 95b59274e9e..81d88232dca 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php @@ -52,15 +52,15 @@ public function getName() /** * Build the connection string for given connection parameters and driver options. * - * @param string $host Host address to connect to. - * @param int $port Port to use for the connection (default to SQL Anywhere standard port 2638). - * @param string $server Database server name on the host to connect to. - * SQL Anywhere allows multiple database server instances on the same host, - * therefore specifying the server instance name to use is mandatory. - * @param string $dbname Name of the database on the server instance to connect to. - * @param string $username User name to use for connection authentication. - * @param string $password Password to use for connection authentication. - * @param mixed[] $driverOptions Additional parameters to use for the connection. + * @param string|null $host Host address to connect to. + * @param int|null $port Port to use for the connection (default to SQL Anywhere standard port 2638). + * @param string|null $server Database server name on the host to connect to. + * SQL Anywhere allows multiple database server instances on the same host, + * therefore specifying the server instance name to use is mandatory. + * @param string|null $dbname Name of the database on the server instance to connect to. + * @param string $username User name to use for connection authentication. + * @param string $password Password to use for connection authentication. + * @param mixed[] $driverOptions Additional parameters to use for the connection. * * @return string */ diff --git a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php index 2b45883b3fa..b41f33bef46 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php @@ -1199,10 +1199,10 @@ public function getAsciiStringTypeDeclarationSQL(array $column): string $length = $column['length'] ?? null; if (! isset($column['fixed'])) { - return sprintf('VARCHAR(%d)', $length); + return sprintf('VARCHAR(%d)', $length ?? 255); } - return sprintf('CHAR(%d)', $length); + return sprintf('CHAR(%d)', $length ?? 255); } /** diff --git a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php index d9fabec1660..20cb5f7277e 100644 --- a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php @@ -150,13 +150,17 @@ protected function _getPortableTableForeignKeyDefinition($tableForeignKey) $onDelete = $match[1]; } - if (preg_match('/FOREIGN KEY \((.+)\) REFERENCES (.+)\((.+)\)/', $tableForeignKey['condef'], $values)) { - // PostgreSQL returns identifiers that are keywords with quotes, we need them later, don't get - // the idea to trim them here. - $localColumns = array_map('trim', explode(',', $values[1])); - $foreignColumns = array_map('trim', explode(',', $values[3])); - $foreignTable = $values[2]; - } + assert(preg_match( + '/FOREIGN KEY \((.+)\) REFERENCES (.+)\((.+)\)/', + $tableForeignKey['condef'], + $values + ) !== 0); + + // PostgreSQL returns identifiers that are keywords with quotes, we need them later, don't get + // the idea to trim them here. + $localColumns = array_map('trim', explode(',', $values[1])); + $foreignColumns = array_map('trim', explode(',', $values[3])); + $foreignTable = $values[2]; return new ForeignKeyConstraint( $localColumns, diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php index 9ef99d6d416..943adb99f47 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php @@ -1159,7 +1159,7 @@ public function testGetCommentOnColumnSQL(): void /** * @dataProvider getGeneratesInlineColumnCommentSQL */ - public function testGeneratesInlineColumnCommentSQL(?string $comment, string $expectedSql): void + public function testGeneratesInlineColumnCommentSQL(string $comment, string $expectedSql): void { if (! $this->platform->supportsInlineColumnComments()) { $this->markTestSkipped(sprintf('%s does not support inline column comments.', get_class($this->platform))); From ac75ed5ef13b305e7fc44de7f0fcf2aa2c062027 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 14 Oct 2020 15:38:24 -0700 Subject: [PATCH 07/21] Account for the fact that error_get_last() may return NULL --- lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php | 2 +- lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php | 6 +++--- .../IBMDB2/Exception/CannotCopyStreamToStream.php | 13 +++++++++++-- .../IBMDB2/Exception/CannotCreateTemporaryFile.php | 13 +++++++++++-- .../IBMDB2/Exception/CannotWriteToTemporaryFile.php | 13 +++++++++++-- .../DBAL/Driver/IBMDB2/Exception/PrepareFailed.php | 11 +++++++++-- .../DBAL/Tools/Console/Command/ImportCommand.php | 11 ++++++++--- 7 files changed, 54 insertions(+), 15 deletions(-) diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php index dc2701e344a..4143255e555 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php @@ -93,7 +93,7 @@ public function prepare($sql) $stmt = @db2_prepare($this->conn, $sql); if ($stmt === false) { - throw PrepareFailed::new(error_get_last()['message']); + throw PrepareFailed::new(error_get_last()); } return new Statement($stmt); diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php index 483581fedfe..c758a253d0a 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php @@ -527,7 +527,7 @@ private function createTemporaryFile() $handle = @tmpfile(); if ($handle === false) { - throw CannotCreateTemporaryFile::new(error_get_last()['message']); + throw CannotCreateTemporaryFile::new(error_get_last()); } return $handle; @@ -542,7 +542,7 @@ private function createTemporaryFile() private function copyStreamToStream($source, $target): void { if (@stream_copy_to_stream($source, $target) === false) { - throw CannotCopyStreamToStream::new(error_get_last()['message']); + throw CannotCopyStreamToStream::new(error_get_last()); } } @@ -554,7 +554,7 @@ private function copyStreamToStream($source, $target): void private function writeStringToStream(string $string, $target): void { if (@fwrite($target, $string) === false) { - throw CannotWriteToTemporaryFile::new(error_get_last()['message']); + throw CannotWriteToTemporaryFile::new(error_get_last()); } } } diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotCopyStreamToStream.php b/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotCopyStreamToStream.php index 8223a92d660..61244c1cc61 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotCopyStreamToStream.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotCopyStreamToStream.php @@ -13,8 +13,17 @@ */ final class CannotCopyStreamToStream extends DB2Exception { - public static function new(string $message): self + /** + * @psalm-param array{message: string}|null $error + */ + public static function new(?array $error): self { - return new self('Could not copy source stream to temporary file: ' . $message); + $message = 'Could not copy source stream to temporary file'; + + if ($error !== null) { + $message .= ': ' . $error['message']; + } + + return new self($message); } } diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotCreateTemporaryFile.php b/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotCreateTemporaryFile.php index 48b28dd33d3..d5481ed9e31 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotCreateTemporaryFile.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotCreateTemporaryFile.php @@ -13,8 +13,17 @@ */ final class CannotCreateTemporaryFile extends DB2Exception { - public static function new(string $message): self + /** + * @psalm-param array{message: string}|null $error + */ + public static function new(?array $error): self { - return new self('Could not create temporary file: ' . $message); + $message = 'Could not create temporary file'; + + if ($error !== null) { + $message .= ': ' . $error['message']; + } + + return new self($message); } } diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotWriteToTemporaryFile.php b/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotWriteToTemporaryFile.php index 8acc269a4ad..33d0b86cc4f 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotWriteToTemporaryFile.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/CannotWriteToTemporaryFile.php @@ -13,8 +13,17 @@ */ final class CannotWriteToTemporaryFile extends DB2Exception { - public static function new(string $message): self + /** + * @psalm-param array{message: string}|null $error + */ + public static function new(?array $error): self { - return new self('Could not write string to temporary file: ' . $message); + $message = 'Could not write string to temporary file'; + + if ($error !== null) { + $message .= ': ' . $error['message']; + } + + return new self($message); } } diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/PrepareFailed.php b/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/PrepareFailed.php index f566df8d50d..035fd67f9c2 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/PrepareFailed.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/Exception/PrepareFailed.php @@ -13,8 +13,15 @@ */ final class PrepareFailed extends AbstractException { - public static function new(string $message): self + /** + * @psalm-param array{message: string}|null $error + */ + public static function new(?array $error): self { - return new self($message); + if ($error === null) { + return new self('Unknown error'); + } + + return new self($error['message']); } } diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php index 3d53f342968..26456bde0ce 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php @@ -85,9 +85,14 @@ protected function execute(InputInterface $input, OutputInterface $output) $sql = @file_get_contents($filePath); if ($sql === false) { - throw new RuntimeException( - sprintf("Unable to read SQL file '%s': %s", $filePath, error_get_last()['message']) - ); + $message = sprintf("Unable to read SQL file '%s'", $filePath); + $error = error_get_last(); + + if ($error !== null) { + $message .= ': ' . $error['message']; + } + + throw new RuntimeException($message); } if ($conn instanceof PDOConnection) { From 79a5aab29afdb2021072c120b33763ab010932d1 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 14 Oct 2020 17:16:56 -0700 Subject: [PATCH 08/21] Fix PossiblyNullPropertyAssignmentValue issues and remove redundant NULL assignments --- lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php | 2 +- .../DBAL/Event/SchemaColumnDefinitionEventArgs.php | 2 +- lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php | 2 +- .../DBAL/Event/SchemaIndexDefinitionEventArgs.php | 2 +- lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | 4 ++-- lib/Doctrine/DBAL/Platforms/Keywords/KeywordList.php | 2 +- lib/Doctrine/DBAL/Query/QueryBuilder.php | 4 ++-- lib/Doctrine/DBAL/Schema/AbstractAsset.php | 2 +- lib/Doctrine/DBAL/Schema/Column.php | 8 ++++---- lib/Doctrine/DBAL/Schema/Sequence.php | 2 +- lib/Doctrine/DBAL/Schema/Table.php | 2 +- .../DBAL/Schema/Visitor/CreateSchemaSqlCollector.php | 2 +- 12 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php index 4143255e555..bdc52551f52 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php @@ -37,7 +37,7 @@ class DB2Connection implements ConnectionInterface, ServerInfoAwareConnection { /** @var resource */ - private $conn = null; + private $conn; /** * @internal The connection can be only instantiated by its driver. diff --git a/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php index 2be445e38af..7c962a928f4 100644 --- a/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php @@ -12,7 +12,7 @@ class SchemaColumnDefinitionEventArgs extends SchemaEventArgs { /** @var Column|null */ - private $column = null; + private $column; /** * Raw column data as fetched from the database. diff --git a/lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php index 1236de401ab..072e1efb909 100644 --- a/lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaDropTableEventArgs.php @@ -18,7 +18,7 @@ class SchemaDropTableEventArgs extends SchemaEventArgs private $platform; /** @var string|null */ - private $sql = null; + private $sql; /** * @param string|Table $table diff --git a/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php index ca6bbf81f7e..055a19a7c27 100644 --- a/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaIndexDefinitionEventArgs.php @@ -12,7 +12,7 @@ class SchemaIndexDefinitionEventArgs extends SchemaEventArgs { /** @var Index|null */ - private $index = null; + private $index; /** * Raw index data as fetched from the database. diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index ba551574651..b99a4beb66b 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -132,7 +132,7 @@ abstract class AbstractPlatform public const TRIM_BOTH = TrimMode::BOTH; /** @var string[]|null */ - protected $doctrineTypeMapping = null; + protected $doctrineTypeMapping; /** * Contains a list of all columns that should generate parseable column comments for type-detection @@ -140,7 +140,7 @@ abstract class AbstractPlatform * * @var string[]|null */ - protected $doctrineTypeComments = null; + protected $doctrineTypeComments; /** @var EventManager */ protected $_eventManager; diff --git a/lib/Doctrine/DBAL/Platforms/Keywords/KeywordList.php b/lib/Doctrine/DBAL/Platforms/Keywords/KeywordList.php index 860d9f21099..852a58aba2b 100644 --- a/lib/Doctrine/DBAL/Platforms/Keywords/KeywordList.php +++ b/lib/Doctrine/DBAL/Platforms/Keywords/KeywordList.php @@ -12,7 +12,7 @@ abstract class KeywordList { /** @var string[]|null */ - private $keywords = null; + private $keywords; /** * Checks if the given word is a keyword of this dialect/vendor platform. diff --git a/lib/Doctrine/DBAL/Query/QueryBuilder.php b/lib/Doctrine/DBAL/Query/QueryBuilder.php index c0c0ea58451..492a06951bb 100644 --- a/lib/Doctrine/DBAL/Query/QueryBuilder.php +++ b/lib/Doctrine/DBAL/Query/QueryBuilder.php @@ -119,14 +119,14 @@ class QueryBuilder * * @var int */ - private $firstResult = null; + private $firstResult; /** * The maximum number of results to retrieve or NULL to retrieve all results. * * @var int|null */ - private $maxResults = null; + private $maxResults; /** * The counter of bound parameters used with {@see bindValue). diff --git a/lib/Doctrine/DBAL/Schema/AbstractAsset.php b/lib/Doctrine/DBAL/Schema/AbstractAsset.php index 3424b17c544..02111832e26 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractAsset.php +++ b/lib/Doctrine/DBAL/Schema/AbstractAsset.php @@ -31,7 +31,7 @@ abstract class AbstractAsset * * @var string|null */ - protected $_namespace = null; + protected $_namespace; /** @var bool */ protected $_quoted = false; diff --git a/lib/Doctrine/DBAL/Schema/Column.php b/lib/Doctrine/DBAL/Schema/Column.php index e33f285108b..f63bcc9226b 100644 --- a/lib/Doctrine/DBAL/Schema/Column.php +++ b/lib/Doctrine/DBAL/Schema/Column.php @@ -21,7 +21,7 @@ class Column extends AbstractAsset protected $_type; /** @var int|null */ - protected $_length = null; + protected $_length; /** @var int */ protected $_precision = 10; @@ -39,7 +39,7 @@ class Column extends AbstractAsset protected $_notnull = true; /** @var string|null */ - protected $_default = null; + protected $_default; /** @var bool */ protected $_autoincrement = false; @@ -48,10 +48,10 @@ class Column extends AbstractAsset protected $_platformOptions = []; /** @var string|null */ - protected $_columnDefinition = null; + protected $_columnDefinition; /** @var string|null */ - protected $_comment = null; + protected $_comment; /** @var mixed[] */ protected $_customSchemaOptions = []; diff --git a/lib/Doctrine/DBAL/Schema/Sequence.php b/lib/Doctrine/DBAL/Schema/Sequence.php index 19dec9cd57a..1cba86c086c 100644 --- a/lib/Doctrine/DBAL/Schema/Sequence.php +++ b/lib/Doctrine/DBAL/Schema/Sequence.php @@ -19,7 +19,7 @@ class Sequence extends AbstractAsset protected $initialValue = 1; /** @var int|null */ - protected $cache = null; + protected $cache; /** * @param string $name diff --git a/lib/Doctrine/DBAL/Schema/Table.php b/lib/Doctrine/DBAL/Schema/Table.php index bd0462151a4..740092d3ca1 100644 --- a/lib/Doctrine/DBAL/Schema/Table.php +++ b/lib/Doctrine/DBAL/Schema/Table.php @@ -41,7 +41,7 @@ class Table extends AbstractAsset ]; /** @var SchemaConfig|null */ - protected $_schemaConfig = null; + protected $_schemaConfig; /** * @param string $name diff --git a/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php b/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php index b2fab3ae4af..c08fb6fecd8 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php @@ -24,7 +24,7 @@ class CreateSchemaSqlCollector extends AbstractVisitor private $createFkConstraintQueries = []; /** @var AbstractPlatform */ - private $platform = null; + private $platform; public function __construct(AbstractPlatform $platform) { From e8e0bc408b3817aa4c8915665bae61da154cb114 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 14 Oct 2020 17:48:06 -0700 Subject: [PATCH 09/21] Fix MoreSpecificReturnType issues --- lib/Doctrine/DBAL/DriverManager.php | 3 ++- tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php | 6 +++++- .../Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php | 6 +++++- .../Tests/DBAL/Functional/MasterSlaveConnectionTest.php | 6 +++++- .../DBAL/Functional/PrimaryReadReplicaConnectionTest.php | 6 +++++- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/DBAL/DriverManager.php b/lib/Doctrine/DBAL/DriverManager.php index 5b12e4871bb..17ba8584da2 100644 --- a/lib/Doctrine/DBAL/DriverManager.php +++ b/lib/Doctrine/DBAL/DriverManager.php @@ -113,7 +113,7 @@ private function __construct() * driverClass: * The driver class to use. * - * @param array{wrapperClass?: class-string} $params + * @param array{wrapperClass?: class-string} $params * @param Configuration|null $config The configuration to use. * @param EventManager|null $eventManager The event manager to use. * @@ -195,6 +195,7 @@ public static function getConnection( throw Exception::invalidWrapperClass($params['wrapperClass']); } + /** @var class-string $wrapperClass */ $wrapperClass = $params['wrapperClass']; } diff --git a/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php index 4a7044594f3..bfef87d5de4 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php @@ -84,11 +84,15 @@ private function connect(array $driverOptions): Connection { $params = TestUtil::getConnectionParams(); - return $this->createDriver()->connect( + $connection = $this->createDriver()->connect( $params, $params['user'] ?? '', $params['password'] ?? '', $driverOptions ); + + self::assertInstanceOf(Connection::class, $connection); + + return $connection; } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php index d829a013ea7..f8974ef7b14 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlsrv/DriverTest.php @@ -48,12 +48,16 @@ private function getConnection(array $driverOptions): Connection $driverOptions = array_merge($params['driverOptions'], $driverOptions); } - return $this->connection->getDriver()->connect( + $connection = $this->connection->getDriver()->connect( $params, $params['user'] ?? '', $params['password'] ?? '', $driverOptions ); + + self::assertInstanceOf(Connection::class, $connection); + + return $connection; } public function testConnectionOptions(): void diff --git a/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php index 13aaea3c6a9..4b842e77654 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php @@ -46,7 +46,11 @@ protected function setUp(): void private function createMasterSlaveConnection(bool $keepSlave = false): MasterSlaveConnection { - return DriverManager::getConnection($this->createMasterSlaveConnectionParams($keepSlave)); + $connection = DriverManager::getConnection($this->createMasterSlaveConnectionParams($keepSlave)); + + self::assertInstanceOf(MasterSlaveConnection::class, $connection); + + return $connection; } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/PrimaryReadReplicaConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/PrimaryReadReplicaConnectionTest.php index 7dd14c355ee..1bbd094e2d3 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/PrimaryReadReplicaConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/PrimaryReadReplicaConnectionTest.php @@ -49,7 +49,11 @@ protected function setUp(): void private function createPrimaryReadReplicaConnection(bool $keepReplica = false): PrimaryReadReplicaConnection { - return DriverManager::getConnection($this->createPrimaryReadReplicaConnectionParams($keepReplica)); + $connection = DriverManager::getConnection($this->createPrimaryReadReplicaConnectionParams($keepReplica)); + + self::assertInstanceOf(PrimaryReadReplicaConnection::class, $connection); + + return $connection; } /** From 5c60ae2b6178ace4ccc3d28b035f1ac580dc3915 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 14 Oct 2020 17:50:58 -0700 Subject: [PATCH 10/21] Fix OCI-Lob assertion --- lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php index d019d74576f..cbb8a851b27 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php @@ -299,8 +299,7 @@ public function bindParam($param, &$variable, $type = ParameterType::STRING, $le if ($type === ParameterType::LARGE_OBJECT) { $lob = oci_new_descriptor($this->_dbh, OCI_D_LOB); - $class = 'OCI-Lob'; - assert($lob instanceof $class); + assert($lob !== false); $lob->writeTemporary($variable, OCI_TEMP_BLOB); From 2dacdf815e47b700713c63e12e79bfdb38530b34 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 14 Oct 2020 18:06:02 -0700 Subject: [PATCH 11/21] Fix PossiblyNullReference issues --- .../DBAL/Platforms/SqlitePlatform.php | 30 ++++++++++--------- .../Schema/OracleSchemaManagerTest.php | 12 ++++++-- .../Schema/PostgreSqlSchemaManagerTest.php | 6 +++- .../SQLAzure/MultiTenantVisitorTest.php | 24 ++++++++++----- 4 files changed, 47 insertions(+), 25 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php index c33970fc142..e42a6bd89ec 100644 --- a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php @@ -719,7 +719,9 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) */ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff) { - if (! $diff->fromTable instanceof Table) { + $fromTable = $diff->fromTable; + + if (! $fromTable instanceof Table) { throw new Exception( 'Sqlite platform requires for alter table the table diff with reference to original table schema' ); @@ -732,7 +734,7 @@ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff) $tableName = $diff->getName($this); } - foreach ($this->getIndexesInAlteredTable($diff) as $index) { + foreach ($this->getIndexesInAlteredTable($diff, $fromTable) as $index) { if ($index->isPrimary()) { continue; } @@ -952,8 +954,8 @@ public function getAlterTableSQL(TableDiff $diff) $newTable = new Table( $table->getQuotedName($this), $columns, - $this->getPrimaryIndexInAlteredTable($diff), - $this->getForeignKeysInAlteredTable($diff), + $this->getPrimaryIndexInAlteredTable($diff, $fromTable), + $this->getForeignKeysInAlteredTable($diff, $fromTable), 0, $table->getOptions() ); @@ -1092,11 +1094,11 @@ private function getSimpleAlterTableSQL(TableDiff $diff) /** * @return string[] */ - private function getColumnNamesInAlteredTable(TableDiff $diff) + private function getColumnNamesInAlteredTable(TableDiff $diff, Table $fromTable) { $columns = []; - foreach ($diff->fromTable->getColumns() as $columnName => $column) { + foreach ($fromTable->getColumns() as $columnName => $column) { $columns[strtolower($columnName)] = $column->getName(); } @@ -1132,10 +1134,10 @@ private function getColumnNamesInAlteredTable(TableDiff $diff) /** * @return Index[] */ - private function getIndexesInAlteredTable(TableDiff $diff) + private function getIndexesInAlteredTable(TableDiff $diff, Table $fromTable) { - $indexes = $diff->fromTable->getIndexes(); - $columnNames = $this->getColumnNamesInAlteredTable($diff); + $indexes = $fromTable->getIndexes(); + $columnNames = $this->getColumnNamesInAlteredTable($diff, $fromTable); foreach ($indexes as $key => $index) { foreach ($diff->renamedIndexes as $oldIndexName => $renamedIndex) { @@ -1200,10 +1202,10 @@ private function getIndexesInAlteredTable(TableDiff $diff) /** * @return ForeignKeyConstraint[] */ - private function getForeignKeysInAlteredTable(TableDiff $diff) + private function getForeignKeysInAlteredTable(TableDiff $diff, Table $fromTable) { - $foreignKeys = $diff->fromTable->getForeignKeys(); - $columnNames = $this->getColumnNamesInAlteredTable($diff); + $foreignKeys = $fromTable->getForeignKeys(); + $columnNames = $this->getColumnNamesInAlteredTable($diff, $fromTable); foreach ($foreignKeys as $key => $constraint) { $changed = false; @@ -1264,11 +1266,11 @@ private function getForeignKeysInAlteredTable(TableDiff $diff) /** * @return Index[] */ - private function getPrimaryIndexInAlteredTable(TableDiff $diff) + private function getPrimaryIndexInAlteredTable(TableDiff $diff, Table $fromTable) { $primaryIndex = []; - foreach ($this->getIndexesInAlteredTable($diff) as $index) { + foreach ($this->getIndexesInAlteredTable($diff, $fromTable) as $index) { if (! $index->isPrimary()) { continue; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php index d39b7373216..4b5846e247f 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php @@ -169,7 +169,11 @@ public function testListTableDetailsWithDifferentIdentifierQuotingRequirements() self::assertTrue($onlinePrimaryTable->hasColumn('"Id"')); self::assertSame('"Id"', $onlinePrimaryTable->getColumn('"Id"')->getQuotedName($platform)); self::assertTrue($onlinePrimaryTable->hasPrimaryKey()); - self::assertSame(['"Id"'], $onlinePrimaryTable->getPrimaryKey()->getQuotedColumns($platform)); + + $primaryKey = $onlinePrimaryTable->getPrimaryKey(); + + self::assertNotNull($primaryKey); + self::assertSame(['"Id"'], $primaryKey->getQuotedColumns($platform)); self::assertTrue($onlinePrimaryTable->hasColumn('select')); self::assertSame('"select"', $onlinePrimaryTable->getColumn('select')->getQuotedName($platform)); @@ -203,7 +207,11 @@ public function testListTableDetailsWithDifferentIdentifierQuotingRequirements() self::assertTrue($onlineForeignTable->hasColumn('id')); self::assertSame('ID', $onlineForeignTable->getColumn('id')->getQuotedName($platform)); self::assertTrue($onlineForeignTable->hasPrimaryKey()); - self::assertSame(['ID'], $onlineForeignTable->getPrimaryKey()->getQuotedColumns($platform)); + + $primaryKey = $onlineForeignTable->getPrimaryKey(); + + self::assertNotNull($primaryKey); + self::assertSame(['ID'], $primaryKey->getQuotedColumns($platform)); self::assertTrue($onlineForeignTable->hasColumn('"Fk"')); self::assertSame('"Fk"', $onlineForeignTable->getColumn('"Fk"')->getQuotedName($platform)); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php index aadf78a8b48..ae97380d257 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php @@ -161,7 +161,11 @@ public function testTableWithSchema(): void $nestedSchemaTable = $this->schemaManager->listTableDetails('nested.schematable'); self::assertTrue($nestedSchemaTable->hasColumn('id')); - self::assertEquals(['id'], $nestedSchemaTable->getPrimaryKey()->getColumns()); + + $primaryKey = $nestedSchemaTable->getPrimaryKey(); + + self::assertNotNull($primaryKey); + self::assertEquals(['id'], $primaryKey->getColumns()); $relatedFks = $nestedSchemaTable->getForeignKeys(); self::assertCount(1, $relatedFks); diff --git a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/MultiTenantVisitorTest.php b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/MultiTenantVisitorTest.php index f12379fafee..560181996e3 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/MultiTenantVisitorTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/MultiTenantVisitorTest.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\DBAL\Sharding\SQLAzure; -use Doctrine\DBAL\Platforms\SQLAzurePlatform; use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Sharding\SQLAzure\Schema\MultiTenantVisitor; use PHPUnit\Framework\TestCase; @@ -11,8 +10,7 @@ class MultiTenantVisitorTest extends TestCase { public function testMultiTenantPrimaryKey(): void { - $platform = new SQLAzurePlatform(); - $visitor = new MultiTenantVisitor(); + $visitor = new MultiTenantVisitor(); $schema = new Schema(); $foo = $schema->createTable('foo'); @@ -20,14 +18,16 @@ public function testMultiTenantPrimaryKey(): void $foo->setPrimaryKey(['id']); $schema->visit($visitor); - self::assertEquals(['id', 'tenant_id'], $foo->getPrimaryKey()->getColumns()); + $primaryKey = $foo->getPrimaryKey(); + + self::assertNotNull($primaryKey); + self::assertEquals(['id', 'tenant_id'], $primaryKey->getColumns()); self::assertTrue($foo->hasColumn('tenant_id')); } public function testMultiTenantNonPrimaryKey(): void { - $platform = new SQLAzurePlatform(); - $visitor = new MultiTenantVisitor(); + $visitor = new MultiTenantVisitor(); $schema = new Schema(); $foo = $schema->createTable('foo'); @@ -36,12 +36,20 @@ public function testMultiTenantNonPrimaryKey(): void $foo->setPrimaryKey(['id']); $foo->addIndex(['created'], 'idx'); - $foo->getPrimaryKey()->addFlag('nonclustered'); + $primaryKey = $foo->getPrimaryKey(); + + self::assertNotNull($primaryKey); + + $primaryKey->addFlag('nonclustered'); $foo->getIndex('idx')->addFlag('clustered'); $schema->visit($visitor); - self::assertEquals(['id'], $foo->getPrimaryKey()->getColumns()); + $primaryKey = $foo->getPrimaryKey(); + + self::assertNotNull($primaryKey); + + self::assertEquals(['id'], $primaryKey->getColumns()); self::assertTrue($foo->hasColumn('tenant_id')); self::assertEquals(['created', 'tenant_id'], $foo->getIndex('idx')->getColumns()); } From d85350286057bf0f008840c01032af2d2035ccb6 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 14 Oct 2020 18:26:48 -0700 Subject: [PATCH 12/21] Fix PossiblyUndefinedVariable issues --- .../DBAL/Platforms/AbstractPlatform.php | 2 +- .../SQLAzureFederationsSynchronizer.php | 2 ++ tests/Doctrine/Tests/DBAL/ConnectionTest.php | 8 ++----- .../Tests/DBAL/Functional/DataAccessTest.php | 22 +++++++++++-------- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index b99a4beb66b..5580ea23dea 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -1742,7 +1742,7 @@ protected function _getCreateTableSQL($name, array $columns, array $options = [] $query .= ')'; - $sql[] = $query; + $sql = [$query]; if (isset($options['foreignKeys'])) { foreach ((array) $options['foreignKeys'] as $definition) { diff --git a/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php b/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php index 7ea9ce1fad3..5fa2aa782eb 100644 --- a/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php +++ b/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php @@ -125,6 +125,8 @@ public function getDropAllSchema() $this->shardManager->selectGlobal(); $globalSql = $this->synchronizer->getDropAllSchema(); + $sql = []; + if ($globalSql) { $sql[] = "-- Work on Root Federation\nUSE FEDERATION ROOT WITH RESET;"; $sql = array_merge($sql, $globalSql); diff --git a/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/ConnectionTest.php index feed00275a2..675881ac207 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -648,22 +648,18 @@ public function testFetchAll(): void public function testConnectionDoesNotMaintainTwoReferencesToExternalPDO(): void { - $params['pdo'] = new stdClass(); - $driverMock = $this->createMock(Driver::class); - $conn = new Connection($params, $driverMock); + $conn = new Connection(['pdo' => new stdClass()], $driverMock); self::assertArrayNotHasKey('pdo', $conn->getParams()); } public function testPassingExternalPDOMeansConnectionIsConnected(): void { - $params['pdo'] = new stdClass(); - $driverMock = $this->createMock(Driver::class); - $conn = new Connection($params, $driverMock); + $conn = new Connection(['pdo' => new stdClass()], $driverMock); self::assertTrue($conn->isConnected(), 'Connection is not connected after passing external PDO'); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php index d4123c79188..83b7b6984c8 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php @@ -27,7 +27,6 @@ use function array_keys; use function count; use function date; -use function implode; use function is_numeric; use function json_encode; use function property_exists; @@ -35,7 +34,6 @@ use function strtotime; use const CASE_LOWER; -use const PHP_EOL; class DataAccessTest extends DbalFunctionalTestCase { @@ -682,14 +680,20 @@ public function testBitComparisonExpressionSupport(): void ]); } - $sql[] = 'SELECT '; - $sql[] = 'test_int, '; - $sql[] = 'test_string, '; - $sql[] = $platform->getBitOrComparisonExpression('test_int', 2) . ' AS bit_or, '; - $sql[] = $platform->getBitAndComparisonExpression('test_int', 2) . ' AS bit_and '; - $sql[] = 'FROM fetch_table'; + $sql = sprintf( + <<<'SQL' +SELECT test_int, + test_string, + %s AS bit_or, + %s AS bit_and +FROM fetch_table +SQL + , + $platform->getBitOrComparisonExpression('test_int', 2), + $platform->getBitAndComparisonExpression('test_int', 2) + ); - $stmt = $this->connection->executeQuery(implode(PHP_EOL, $sql)); + $stmt = $this->connection->executeQuery($sql); $data = $stmt->fetchAll(FetchMode::ASSOCIATIVE); self::assertCount(4, $data); From 1398eb461a9786a41b8b88379041567334897b8c Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 15 Oct 2020 19:07:41 -0700 Subject: [PATCH 13/21] Fix PossiblyFalseArgument issues --- .../DBAL/Schema/PostgreSqlSchemaManager.php | 6 +- .../Tests/DBAL/Functional/DataAccessTest.php | 6 ++ .../Functional/MasterSlaveConnectionTest.php | 10 +-- .../PrimaryReadReplicaConnectionTest.php | 8 +-- .../Schema/MySqlSchemaManagerTest.php | 32 ++++++---- .../Schema/OracleSchemaManagerTest.php | 15 +++-- .../Schema/PostgreSqlSchemaManagerTest.php | 13 ++-- .../SchemaManagerFunctionalTestCase.php | 20 +++--- .../Schema/SqliteSchemaManagerTest.php | 6 +- .../DBAL/Functional/Ticket/DBAL421Test.php | 4 +- .../AbstractMySQLPlatformTestCase.php | 61 +++++++++++-------- .../Platforms/AbstractPlatformTestCase.php | 10 +-- .../AbstractPostgreSqlPlatformTestCase.php | 18 ++++-- .../DBAL/Platforms/OraclePlatformTest.php | 4 +- .../DBAL/Schema/Platforms/MySQLSchemaTest.php | 8 ++- .../Doctrine/Tests/DBAL/Schema/TableTest.php | 2 +- .../Sharding/SQLAzure/AbstractTestCase.php | 1 + .../Doctrine/Tests/DBAL/Tools/DumperTest.php | 12 ---- 18 files changed, 133 insertions(+), 103 deletions(-) diff --git a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php index 20cb5f7277e..e64a9c81735 100644 --- a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php @@ -60,7 +60,11 @@ public function getSchemaNames() public function getSchemaSearchPaths() { $params = $this->_conn->getParams(); - $schema = explode(',', $this->_conn->fetchColumn('SHOW search_path')); + + $searchPaths = $this->_conn->fetchColumn('SHOW search_path'); + assert($searchPaths !== false); + + $schema = explode(',', $searchPaths); if (isset($params['user'])) { $schema = str_replace('"$user"', $params['user'], $schema); diff --git a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php index 83b7b6984c8..355f8fef368 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php @@ -504,6 +504,8 @@ public function testTrimExpression(string $value, int $position, $char, string $ 'FROM fetch_table'; $row = $this->connection->fetchAssoc($sql); + self::assertNotFalse($row); + $row = array_change_key_case($row, CASE_LOWER); self::assertEquals($expectedResult, $row['trimmed']); @@ -577,6 +579,8 @@ public function testDateArithmetics(): void $sql .= 'FROM fetch_table'; $row = $this->connection->fetchAssoc($sql); + self::assertNotFalse($row); + $row = array_change_key_case($row, CASE_LOWER); self::assertEquals('2010-01-01 10:10:11', date('Y-m-d H:i:s', strtotime($row['add_seconds']))); @@ -641,6 +645,8 @@ public function testLocateExpression(): void $sql .= 'FROM fetch_table'; $row = $this->connection->fetchAssoc($sql); + self::assertNotFalse($row); + $row = array_change_key_case($row, CASE_LOWER); self::assertEquals(2, $row['locate1']); diff --git a/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php index 4b842e77654..5e75f6fd29d 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php @@ -11,9 +11,6 @@ use function array_change_key_case; use function sprintf; -use function strlen; -use function strtolower; -use function substr; use const CASE_LOWER; @@ -92,12 +89,9 @@ public function testInheritCharsetFromMaster(): void self::assertFalse($conn->isConnectedToMaster()); - $clientCharset = $conn->fetchColumn('select @@character_set_client as c'); + $clientCharset = $conn->fetchColumn('select @@character_set_client'); - self::assertSame( - $charset, - substr(strtolower($clientCharset), 0, strlen($charset)) - ); + self::assertSame($charset, $clientCharset); } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/PrimaryReadReplicaConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/PrimaryReadReplicaConnectionTest.php index 1bbd094e2d3..e371cf2cfeb 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/PrimaryReadReplicaConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/PrimaryReadReplicaConnectionTest.php @@ -11,9 +11,6 @@ use function array_change_key_case; use function sprintf; -use function strlen; -use function strtolower; -use function substr; use const CASE_LOWER; @@ -97,10 +94,7 @@ public function testInheritCharsetFromPrimary(): void $clientCharset = $conn->fetchColumn('select @@character_set_client as c'); - self::assertSame( - $charset, - substr(strtolower($clientCharset), 0, strlen($charset)) - ); + self::assertSame($charset, $clientCharset); } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php index 1da8e4dbfaa..1ae77de7c8b 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php @@ -45,8 +45,10 @@ public function testSwitchPrimaryKeyColumns(): void $tableNew = clone $tableFetched; $tableNew->setPrimaryKey(['bar_id', 'foo_id']); - $comparator = new Comparator(); - $this->schemaManager->alterTable($comparator->diffTable($tableFetched, $tableNew)); + $diff = (new Comparator())->diffTable($tableFetched, $tableNew); + self::assertNotFalse($diff); + + $this->schemaManager->alterTable($diff); $table = $this->schemaManager->listTableDetails('switch_primary_key_columns'); $primaryKey = $table->getPrimaryKeyColumns(); @@ -73,8 +75,7 @@ public function testDiffTableBug(): void $this->schemaManager->createTable($table); $tableFetched = $this->schemaManager->listTableDetails('diffbug_routing_translations'); - $comparator = new Comparator(); - $diff = $comparator->diffTable($tableFetched, $table); + $diff = (new Comparator())->diffTable($tableFetched, $table); self::assertFalse($diff, 'no changes expected.'); } @@ -135,13 +136,15 @@ public function testAlterTableAddPrimaryKey(): void $this->schemaManager->createTable($table); - $comparator = new Comparator(); - $diffTable = clone $table; + $diffTable = clone $table; $diffTable->dropIndex('idx_id'); $diffTable->setPrimaryKey(['id']); - $this->schemaManager->alterTable($comparator->diffTable($table, $diffTable)); + $diff = (new Comparator())->diffTable($table, $diffTable); + self::assertNotFalse($diff); + + $this->schemaManager->alterTable($diff); $table = $this->schemaManager->listTableDetails('alter_table_add_pk'); @@ -162,9 +165,10 @@ public function testDropPrimaryKeyWithAutoincrementColumn(): void $diffTable->dropPrimaryKey(); - $comparator = new Comparator(); + $diff = (new Comparator())->diffTable($table, $diffTable); + self::assertNotFalse($diff); - $this->schemaManager->alterTable($comparator->diffTable($table, $diffTable)); + $this->schemaManager->alterTable($diff); $table = $this->schemaManager->listTableDetails('drop_primary_key'); @@ -197,9 +201,10 @@ public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes(): vo self::assertNull($onlineTable->getColumn('def_blob_null')->getDefault()); self::assertFalse($onlineTable->getColumn('def_blob_null')->getNotnull()); - $comparator = new Comparator(); + $diff = (new Comparator())->diffTable($table, $onlineTable); + self::assertNotFalse($diff); - $this->schemaManager->alterTable($comparator->diffTable($table, $onlineTable)); + $this->schemaManager->alterTable($diff); $onlineTable = $this->schemaManager->listTableDetails('text_blob_default_value'); @@ -240,9 +245,10 @@ public function testAlterColumnCharset(): void $diffTable = clone $table; $diffTable->getColumn('col_text')->setPlatformOption('charset', 'ascii'); - $comparator = new Comparator(); + $diff = (new Comparator())->diffTable($table, $diffTable); + self::assertNotFalse($diff); - $this->schemaManager->alterTable($comparator->diffTable($table, $diffTable)); + $this->schemaManager->alterTable($diff); $table = $this->schemaManager->listTableDetails($tableName); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php index 4b5846e247f..af0c6b79791 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php @@ -5,6 +5,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Schema; +use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\BinaryType; use Doctrine\DBAL\Types\Types; @@ -76,9 +77,8 @@ public function testListTableWithBinary(): void public function testAlterTableColumnNotNull(): void { - $comparator = new Schema\Comparator(); - $tableName = 'list_table_column_notnull'; - $table = new Schema\Table($tableName); + $tableName = 'list_table_column_notnull'; + $table = new Table($tableName); $table->addColumn('id', 'integer'); $table->addColumn('foo', 'integer'); @@ -97,7 +97,10 @@ public function testAlterTableColumnNotNull(): void $diffTable->changeColumn('foo', ['notnull' => false]); $diffTable->changeColumn('bar', ['length' => 1024]); - $this->schemaManager->alterTable($comparator->diffTable($table, $diffTable)); + $diff = (new Comparator())->diffTable($table, $diffTable); + self::assertNotFalse($diff); + + $this->schemaManager->alterTable($diff); $columns = $this->schemaManager->listTableColumns($tableName); @@ -122,7 +125,7 @@ public function testListDatabases(): void public function testListTableDetailsWithDifferentIdentifierQuotingRequirements(): void { $primaryTableName = '"Primary_Table"'; - $offlinePrimaryTable = new Schema\Table($primaryTableName); + $offlinePrimaryTable = new Table($primaryTableName); $offlinePrimaryTable->addColumn( '"Id"', 'integer', @@ -139,7 +142,7 @@ public function testListTableDetailsWithDifferentIdentifierQuotingRequirements() $offlinePrimaryTable->setPrimaryKey(['"Id"']); $foreignTableName = 'foreign'; - $offlineForeignTable = new Schema\Table($foreignTableName); + $offlineForeignTable = new Table($foreignTableName); $offlineForeignTable->addColumn('id', 'integer', ['autoincrement' => true]); $offlineForeignTable->addColumn('"Fk"', 'integer'); $offlineForeignTable->addIndex(['"Fk"'], '"Fk_index"'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php index ae97380d257..949ee50d51c 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php @@ -99,9 +99,10 @@ public function testAlterTableAutoIncrementAdd(): void $column = $tableTo->addColumn('id', 'integer'); $column->setAutoincrement(true); - $c = new Comparator(); - $diff = $c->diffTable($tableFrom, $tableTo); - $sql = $this->connection->getDatabasePlatform()->getAlterTableSQL($diff); + $diff = (new Comparator())->diffTable($tableFrom, $tableTo); + self::assertNotFalse($diff); + + $sql = $this->connection->getDatabasePlatform()->getAlterTableSQL($diff); self::assertEquals([ 'CREATE SEQUENCE autoinc_table_add_id_seq', "SELECT setval('autoinc_table_add_id_seq', (SELECT MAX(id) FROM autoinc_table_add))", @@ -125,9 +126,9 @@ public function testAlterTableAutoIncrementDrop(): void $tableTo = new Table('autoinc_table_drop'); $tableTo->addColumn('id', 'integer'); - $c = new Comparator(); - $diff = $c->diffTable($tableFrom, $tableTo); - self::assertInstanceOf(TableDiff::class, $diff); + $diff = (new Comparator())->diffTable($tableFrom, $tableTo); + self::assertNotFalse($diff); + self::assertEquals( ['ALTER TABLE autoinc_table_drop ALTER id DROP DEFAULT'], $this->connection->getDatabasePlatform()->getAlterTableSQL($diff) diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index 8ae88a87738..a635991e998 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -741,10 +741,10 @@ public function testUpdateSchemaWithForeignKeyRenaming(): void $tableFKNew->addIndex(['rename_fk_id'], 'fk_idx'); $tableFKNew->addForeignKeyConstraint('test_fk_base', ['rename_fk_id'], ['id']); - $c = new Comparator(); - $tableDiff = $c->diffTable($tableFK, $tableFKNew); + $diff = (new Comparator())->diffTable($tableFK, $tableFKNew); + self::assertNotFalse($diff); - $this->schemaManager->alterTable($tableDiff); + $this->schemaManager->alterTable($diff); $table = $this->schemaManager->listTableDetails('test_fk_rename'); $foreignKeys = $table->getForeignKeys(); @@ -781,9 +781,10 @@ public function testRenameIndexUsedInForeignKeyConstraint(): void $foreignTable2 = clone $foreignTable; $foreignTable2->renameIndex('rename_index_fk_idx', 'renamed_index_fk_idx'); - $comparator = new Comparator(); + $diff = (new Comparator())->diffTable($foreignTable, $foreignTable2); + self::assertNotFalse($diff); - $this->schemaManager->alterTable($comparator->diffTable($foreignTable, $foreignTable2)); + $this->schemaManager->alterTable($diff); $foreignTable = $this->schemaManager->listTableDetails('test_rename_index_foreign'); @@ -958,7 +959,7 @@ protected function createTestTable(string $name = 'test_table', array $data = [] */ protected function getTestTable(string $name, array $options = []): Table { - $table = new Table($name, [], [], [], false, $options); + $table = new Table($name, [], [], [], 0, $options); $table->setSchemaConfig($this->schemaManager->createSchemaConfig()); $table->addColumn('id', 'integer', ['notnull' => true]); $table->setPrimaryKey(['id']); @@ -970,7 +971,7 @@ protected function getTestTable(string $name, array $options = []): Table protected function getTestCompositeTable(string $name): Table { - $table = new Table($name, [], [], [], false, []); + $table = new Table($name, [], [], [], 0, []); $table->setSchemaConfig($this->schemaManager->createSchemaConfig()); $table->addColumn('id', 'integer', ['notnull' => true]); $table->addColumn('other_id', 'integer', ['notnull' => true]); @@ -1061,9 +1062,10 @@ public function testColumnDefaultLifecycle(): void $diffTable->changeColumn('column6', ['default' => 666]); $diffTable->changeColumn('column7', ['default' => null]); - $comparator = new Comparator(); + $diff = (new Comparator())->diffTable($table, $diffTable); + self::assertNotFalse($diff); - $this->schemaManager->alterTable($comparator->diffTable($table, $diffTable)); + $this->schemaManager->alterTable($diff); $columns = $this->schemaManager->listTableColumns('col_def_lifecycle'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php index dc46c35a0f3..b7c0c606fa4 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php @@ -7,6 +7,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Schema; +use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\BlobType; use Doctrine\DBAL\Types\Type; @@ -203,10 +204,11 @@ public function testDiffListIntegerAutoincrementTableColumns( $this->schemaManager->dropAndCreateTable($offlineTable); $onlineTable = $this->schemaManager->listTableDetails($tableName); - $comparator = new Schema\Comparator(); - $diff = $comparator->diffTable($offlineTable, $onlineTable); + + $diff = (new Comparator())->diffTable($offlineTable, $onlineTable); if ($expectedComparatorDiff) { + self::assertNotFalse($diff); self::assertEmpty($this->schemaManager->getDatabasePlatform()->getAlterTableSQL($diff)); } else { self::assertFalse($diff); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php index 35e9f0675bc..7bd3dd42333 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php @@ -23,7 +23,9 @@ protected function setUp(): void public function testGuidShouldMatchPattern(): void { - $guid = $this->connection->query($this->getSelectGuidSql())->fetchColumn(); + $guid = $this->connection->query($this->getSelectGuidSql())->fetchColumn(); + self::assertNotFalse($guid); + $pattern = '/[0-9A-F]{8}\-[0-9A-F]{4}\-[0-9A-F]{4}\-[8-9A-B][0-9A-F]{3}\-[0-9A-F]{12}/i'; self::assertEquals(1, preg_match($pattern, $guid), 'GUID does not match pattern'); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php index 984e19ec719..6f47275a4e8 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php @@ -184,8 +184,8 @@ public function testUniquePrimaryKey(): void $oldTable->addColumn('bar', 'integer'); $oldTable->addColumn('baz', 'string'); - $c = new Comparator(); - $diff = $c->diffTable($oldTable, $keyTable); + $diff = (new Comparator())->diffTable($oldTable, $keyTable); + self::assertNotFalse($diff); $sql = $this->platform->getAlterTableSQL($diff); @@ -384,15 +384,17 @@ public function testAlterTableAddPrimaryKey(): void $table->addColumn('foo', 'integer'); $table->addIndex(['id'], 'idx_id'); - $comparator = new Comparator(); - $diffTable = clone $table; + $diffTable = clone $table; $diffTable->dropIndex('idx_id'); $diffTable->setPrimaryKey(['id']); + $diff = (new Comparator())->diffTable($table, $diffTable); + self::assertNotFalse($diff); + self::assertEquals( ['DROP INDEX idx_id ON alter_table_add_pk', 'ALTER TABLE alter_table_add_pk ADD PRIMARY KEY (id)'], - $this->platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) + $this->platform->getAlterTableSQL($diff) ); } @@ -403,19 +405,21 @@ public function testAlterPrimaryKeyWithAutoincrementColumn(): void $table->addColumn('foo', 'integer'); $table->setPrimaryKey(['id']); - $comparator = new Comparator(); - $diffTable = clone $table; + $diffTable = clone $table; $diffTable->dropPrimaryKey(); $diffTable->setPrimaryKey(['foo']); + $diff = (new Comparator())->diffTable($table, $diffTable); + self::assertNotFalse($diff); + self::assertEquals( [ 'ALTER TABLE alter_primary_key MODIFY id INT NOT NULL', 'ALTER TABLE alter_primary_key DROP PRIMARY KEY', 'ALTER TABLE alter_primary_key ADD PRIMARY KEY (foo)', ], - $this->platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) + $this->platform->getAlterTableSQL($diff) ); } @@ -427,17 +431,19 @@ public function testDropPrimaryKeyWithAutoincrementColumn(): void $table->addColumn('bar', 'integer'); $table->setPrimaryKey(['id', 'foo']); - $comparator = new Comparator(); - $diffTable = clone $table; + $diffTable = clone $table; $diffTable->dropPrimaryKey(); + $diff = (new Comparator())->diffTable($table, $diffTable); + self::assertNotFalse($diff); + self::assertEquals( [ 'ALTER TABLE drop_primary_key MODIFY id INT NOT NULL', 'ALTER TABLE drop_primary_key DROP PRIMARY KEY', ], - $this->platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) + $this->platform->getAlterTableSQL($diff) ); } @@ -449,19 +455,21 @@ public function testDropNonAutoincrementColumnFromCompositePrimaryKeyWithAutoinc $table->addColumn('bar', 'integer'); $table->setPrimaryKey(['id', 'foo']); - $comparator = new Comparator(); - $diffTable = clone $table; + $diffTable = clone $table; $diffTable->dropPrimaryKey(); $diffTable->setPrimaryKey(['id']); + $diff = (new Comparator())->diffTable($table, $diffTable); + self::assertNotFalse($diff); + self::assertSame( [ 'ALTER TABLE tbl MODIFY id INT NOT NULL', 'ALTER TABLE tbl DROP PRIMARY KEY', 'ALTER TABLE tbl ADD PRIMARY KEY (id)', ], - $this->platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) + $this->platform->getAlterTableSQL($diff) ); } @@ -473,19 +481,21 @@ public function testAddNonAutoincrementColumnToPrimaryKeyWithAutoincrementColumn $table->addColumn('bar', 'integer'); $table->setPrimaryKey(['id']); - $comparator = new Comparator(); - $diffTable = clone $table; + $diffTable = clone $table; $diffTable->dropPrimaryKey(); $diffTable->setPrimaryKey(['id', 'foo']); + $diff = (new Comparator())->diffTable($table, $diffTable); + self::assertNotFalse($diff); + self::assertSame( [ 'ALTER TABLE tbl MODIFY id INT NOT NULL', 'ALTER TABLE tbl DROP PRIMARY KEY', 'ALTER TABLE tbl ADD PRIMARY KEY (id, foo)', ], - $this->platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) + $this->platform->getAlterTableSQL($diff) ); } @@ -499,8 +509,8 @@ public function testAddAutoIncrementPrimaryKey(): void $oldTable = new Table('foo'); $oldTable->addColumn('baz', 'string'); - $c = new Comparator(); - $diff = $c->diffTable($oldTable, $keyTable); + $diff = (new Comparator())->diffTable($oldTable, $keyTable); + self::assertNotFalse($diff); $sql = $this->platform->getAlterTableSQL($diff); @@ -527,20 +537,22 @@ public function testAlterPrimaryKeyWithNewColumn(): void $table->addColumn('col_a', 'integer'); $table->setPrimaryKey(['pkc1']); - $comparator = new Comparator(); - $diffTable = clone $table; + $diffTable = clone $table; $diffTable->addColumn('pkc2', 'integer'); $diffTable->dropPrimaryKey(); $diffTable->setPrimaryKey(['pkc1', 'pkc2']); + $diff = (new Comparator())->diffTable($table, $diffTable); + self::assertNotFalse($diff); + self::assertSame( [ 'ALTER TABLE yolo DROP PRIMARY KEY', 'ALTER TABLE yolo ADD pkc2 INT NOT NULL', 'ALTER TABLE yolo ADD PRIMARY KEY (pkc1, pkc2)', ], - $this->platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) + $this->platform->getAlterTableSQL($diff) ); } @@ -757,9 +769,10 @@ public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes(): vo $diffTable->changeColumn('def_blob', ['default' => null]); $diffTable->changeColumn('def_blob_null', ['default' => null]); - $comparator = new Comparator(); + $diff = (new Comparator())->diffTable($table, $diffTable); + self::assertNotFalse($diff); - self::assertEmpty($this->platform->getAlterTableSQL($comparator->diffTable($table, $diffTable))); + self::assertEmpty($this->platform->getAlterTableSQL($diff)); } /** diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php index 943adb99f47..658839bd8c1 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php @@ -950,11 +950,12 @@ public function testQuotesAlterTableRenameColumn(): void // quoted -> quoted $toTable->addColumn('`baz`', 'integer', ['comment' => 'Quoted 3']); - $comparator = new Comparator(); + $diff = (new Comparator())->diffTable($fromTable, $toTable); + self::assertNotFalse($diff); self::assertEquals( $this->getQuotedAlterTableRenameColumnSQL(), - $this->platform->getAlterTableSQL($comparator->diffTable($fromTable, $toTable)) + $this->platform->getAlterTableSQL($diff) ); } @@ -987,11 +988,12 @@ public function testQuotesAlterTableChangeColumnLength(): void $toTable->addColumn('table', 'string', ['comment' => 'Reserved keyword 2', 'length' => 255]); $toTable->addColumn('select', 'string', ['comment' => 'Reserved keyword 3', 'length' => 255]); - $comparator = new Comparator(); + $diff = (new Comparator())->diffTable($fromTable, $toTable); + self::assertNotFalse($diff); self::assertEquals( $this->getQuotedAlterTableChangeColumnLengthSQL(), - $this->platform->getAlterTableSQL($comparator->diffTable($fromTable, $toTable)) + $this->platform->getAlterTableSQL($diff) ); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php index fc7e00ae3e3..184dcbb216c 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php @@ -600,10 +600,10 @@ public function testDroppingConstraintsBeforeColumns(): void $oldTable->addColumn('parent_id', 'integer'); $oldTable->addUnnamedForeignKeyConstraint('mytable', ['parent_id'], ['id']); - $comparator = new Comparator(); - $tableDiff = $comparator->diffTable($oldTable, $newTable); + $diff = (new Comparator())->diffTable($oldTable, $newTable); + self::assertNotFalse($diff); - $sql = $this->platform->getAlterTableSQL($tableDiff); + $sql = $this->platform->getAlterTableSQL($diff); $expectedSql = [ 'ALTER TABLE mytable DROP CONSTRAINT FK_6B2BD609727ACA70', @@ -681,7 +681,9 @@ public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType(): vo // VARBINARY -> BINARY // BINARY -> VARBINARY // BLOB -> VARBINARY - self::assertEmpty($this->platform->getAlterTableSQL($comparator->diffTable($table1, $table2))); + $diff = $comparator->diffTable($table1, $table2); + self::assertNotFalse($diff); + self::assertEmpty($this->platform->getAlterTableSQL($diff)); $table2 = new Table('mytable'); $table2->addColumn('column_varbinary', 'binary', ['length' => 42]); @@ -691,7 +693,9 @@ public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType(): vo // VARBINARY -> VARBINARY with changed length // BINARY -> BLOB // BLOB -> BINARY - self::assertEmpty($this->platform->getAlterTableSQL($comparator->diffTable($table1, $table2))); + $diff = $comparator->diffTable($table1, $table2); + self::assertNotFalse($diff); + self::assertEmpty($this->platform->getAlterTableSQL($diff)); $table2 = new Table('mytable'); $table2->addColumn('column_varbinary', 'blob'); @@ -701,7 +705,9 @@ public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType(): vo // VARBINARY -> BLOB // BINARY -> BINARY with changed length // BLOB -> BLOB - self::assertEmpty($this->platform->getAlterTableSQL($comparator->diffTable($table1, $table2))); + $diff = $comparator->diffTable($table1, $table2); + self::assertNotFalse($diff); + self::assertEmpty($this->platform->getAlterTableSQL($diff)); } /** diff --git a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php index 9cd147026b1..11ca8e60f96 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php @@ -582,7 +582,9 @@ public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType(): vo // VARBINARY -> BINARY // BINARY -> VARBINARY - self::assertEmpty($this->platform->getAlterTableSQL($comparator->diffTable($table1, $table2))); + $diff = (new Comparator())->diffTable($table1, $table2); + self::assertNotFalse($diff); + self::assertEmpty($this->platform->getAlterTableSQL($diff)); } public function testUsesSequenceEmulatedIdentityColumns(): void diff --git a/tests/Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php b/tests/Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php index 3802ff27a01..d134a1f2f56 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Platforms/MySQLSchemaTest.php @@ -33,7 +33,9 @@ public function testSwitchPrimaryKeyOrder(): void $tableNew->setPrimaryKey(['bar_id', 'foo_id']); $diff = $this->comparator->diffTable($tableOld, $tableNew); - $sql = $this->platform->getAlterTableSQL($diff); + self::assertNotFalse($diff); + + $sql = $this->platform->getAlterTableSQL($diff); self::assertEquals( [ @@ -74,7 +76,9 @@ public function testClobNoAlterTable(): void $tableNew->setPrimaryKey(['id']); $diff = $this->comparator->diffTable($tableOld, $tableNew); - $sql = $this->platform->getAlterTableSQL($diff); + self::assertNotFalse($diff); + + $sql = $this->platform->getAlterTableSQL($diff); self::assertEquals( ['ALTER TABLE test ADD PRIMARY KEY (id)'], diff --git a/tests/Doctrine/Tests/DBAL/Schema/TableTest.php b/tests/Doctrine/Tests/DBAL/Schema/TableTest.php index c596fecfc9c..5b6d897aa80 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/TableTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/TableTest.php @@ -210,7 +210,7 @@ public function testConstraints(): void public function testOptions(): void { - $table = new Table('foo', [], [], [], false, ['foo' => 'bar']); + $table = new Table('foo', [], [], [], 0, ['foo' => 'bar']); self::assertTrue($table->hasOption('foo')); self::assertEquals('bar', $table->getOption('foo')); diff --git a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/AbstractTestCase.php b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/AbstractTestCase.php index 8ad29bfcef6..3ab0991a519 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/AbstractTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/SQLAzure/AbstractTestCase.php @@ -41,6 +41,7 @@ protected function setUp(): void $this->conn = DriverManager::getConnection($params); $serverEdition = $this->conn->fetchColumn("SELECT CONVERT(NVARCHAR(128), SERVERPROPERTY('Edition'))"); + self::assertNotFalse($serverEdition); if (strpos($serverEdition, 'SQL Azure') !== 0) { $this->markTestSkipped('SQL Azure only test.'); diff --git a/tests/Doctrine/Tests/DBAL/Tools/DumperTest.php b/tests/Doctrine/Tests/DBAL/Tools/DumperTest.php index 53af4ae420a..5c64ae77834 100644 --- a/tests/Doctrine/Tests/DBAL/Tools/DumperTest.php +++ b/tests/Doctrine/Tests/DBAL/Tools/DumperTest.php @@ -14,10 +14,6 @@ use Doctrine\Tests\DbalTestCase; use stdClass; -use function print_r; -use function strpos; -use function substr; - class DumperTest extends DbalTestCase { public function testExportObject(): void @@ -99,14 +95,6 @@ public function testExportArrayTraversable(): void */ public function testExportParentAttributes(TestAsset\ParentClass $class, array $expected): void { - $print_r_class = print_r($class, true); - $print_r_expected = print_r($expected, true); - - $print_r_class = substr($print_r_class, strpos($print_r_class, '(')); - $print_r_expected = substr($print_r_expected, strpos($print_r_expected, '(')); - - self::assertSame($print_r_class, $print_r_expected); - $var = Dumper::export($class, 3); $var = (array) $var; unset($var['__CLASS__']); From c6585d306730062028714b51ea40e52624390d07 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 15 Oct 2020 19:11:54 -0700 Subject: [PATCH 14/21] Fix PossiblyInvalidArrayAccess issues --- tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php | 1 + .../Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php | 1 + tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php index 355f8fef368..58322e9d90e 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php @@ -360,6 +360,7 @@ public function testFetchArray(): void { $sql = 'SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?'; $row = $this->connection->fetchArray($sql, [1, 'foo']); + self::assertNotFalse($row); self::assertEquals(1, $row[0]); self::assertEquals('foo', $row[1]); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php index 1ae77de7c8b..0b1e56daebc 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php @@ -463,6 +463,7 @@ public function testColumnDefaultsAreValid(): void $row = $this->connection->fetchAssoc( 'SELECT *, DATEDIFF(CURRENT_TIMESTAMP(), col_datetime) as diff_seconds FROM test_column_defaults_are_valid' ); + self::assertNotFalse($row); self::assertInstanceOf(DateTime::class, DateTime::createFromFormat('Y-m-d H:i:s', $row['col_datetime'])); self::assertNull($row['col_datetime_null']); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php index 77cd108b595..dea9f88d8f6 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php @@ -50,6 +50,7 @@ public function testBooleanConversionSqlLiteral(): void self::assertNotEmpty($id); $row = $this->connection->fetchAssoc('SELECT bool_col FROM dbal630 WHERE id = ?', [$id]); + self::assertNotFalse($row); self::assertFalse($row['bool_col']); } @@ -65,6 +66,7 @@ public function testBooleanConversionBoolParamRealPrepares(): void self::assertNotEmpty($id); $row = $this->connection->fetchAssoc('SELECT bool_col FROM dbal630 WHERE id = ?', [$id]); + self::assertNotFalse($row); self::assertFalse($row['bool_col']); } @@ -84,6 +86,7 @@ public function testBooleanConversionBoolParamEmulatedPrepares(): void self::assertNotEmpty($id); $row = $this->connection->fetchAssoc('SELECT bool_col FROM dbal630 WHERE id = ?', [$id]); + self::assertNotFalse($row); self::assertFalse($row['bool_col']); } @@ -108,6 +111,7 @@ public function testBooleanConversionNullParamEmulatedPrepares( self::assertNotEmpty($id); $row = $this->connection->fetchAssoc('SELECT bool_col FROM dbal630_allow_nulls WHERE id = ?', [$id]); + self::assertNotFalse($row); self::assertSame($databaseConvertedValue, $row['bool_col']); } @@ -136,6 +140,7 @@ public function testBooleanConversionNullParamEmulatedPreparesWithBooleanTypeInB self::assertNotEmpty($id); $row = $this->connection->fetchAssoc('SELECT bool_col FROM dbal630_allow_nulls WHERE id = ?', [$id]); + self::assertNotFalse($row); self::assertSame($databaseConvertedValue, $row['bool_col']); } From 513604f2eed23461fbf2ed06076b11515cee05d4 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 15 Oct 2020 19:14:27 -0700 Subject: [PATCH 15/21] Fix PossiblyInvalidPropertyFetch issues --- .../Tests/DBAL/Schema/ComparatorTest.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php index df2874a535a..9079fbec518 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php @@ -252,8 +252,8 @@ public function testCompareChangeColumnsMultipleNewColumnsRename(): void $tableB->addColumn('new_datecolumn1', 'datetime'); $tableB->addColumn('new_datecolumn2', 'datetime'); - $c = new Comparator(); - $tableDiff = $c->diffTable($tableA, $tableB); + $tableDiff = (new Comparator())->diffTable($tableA, $tableB); + self::assertNotFalse($tableDiff); self::assertCount(1, $tableDiff->renamedColumns); self::assertArrayHasKey('datecolumn1', $tableDiff->renamedColumns); @@ -720,8 +720,8 @@ public function testDetectRenameColumn(): void $tableB = new Table('foo'); $tableB->addColumn('bar', 'integer'); - $c = new Comparator(); - $tableDiff = $c->diffTable($tableA, $tableB); + $tableDiff = (new Comparator())->diffTable($tableA, $tableB); + self::assertNotFalse($tableDiff); self::assertCount(0, $tableDiff->addedColumns); self::assertCount(0, $tableDiff->removedColumns); @@ -743,8 +743,8 @@ public function testDetectRenameColumnAmbiguous(): void $tableB = new Table('foo'); $tableB->addColumn('baz', 'integer'); - $c = new Comparator(); - $tableDiff = $c->diffTable($tableA, $tableB); + $tableDiff = (new Comparator())->diffTable($tableA, $tableB); + self::assertNotFalse($tableDiff); self::assertCount(1, $tableDiff->addedColumns); self::assertArrayHasKey('baz', $tableDiff->addedColumns); @@ -765,8 +765,8 @@ public function testDetectRenameIndex(): void $table2->addIndex(['foo'], 'idx_bar'); - $comparator = new Comparator(); - $tableDiff = $comparator->diffTable($table1, $table2); + $tableDiff = (new Comparator())->diffTable($table1, $table2); + self::assertNotFalse($tableDiff); self::assertCount(0, $tableDiff->addedIndexes); self::assertCount(0, $tableDiff->removedIndexes); @@ -791,8 +791,8 @@ public function testDetectRenameIndexAmbiguous(): void $table2->addIndex(['foo'], 'idx_baz'); - $comparator = new Comparator(); - $tableDiff = $comparator->diffTable($table1, $table2); + $tableDiff = (new Comparator())->diffTable($table1, $table2); + self::assertNotFalse($tableDiff); self::assertCount(1, $tableDiff->addedIndexes); self::assertArrayHasKey('idx_baz', $tableDiff->addedIndexes); From 6c5373f143b3fd20ff126652f79d032e8f432f8f Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 15 Oct 2020 19:20:03 -0700 Subject: [PATCH 16/21] Fix PropertyTypeCoercion issues --- .../DBAL/Functional/Driver/OCI8/ConnectionTest.php | 12 ++++-------- .../DBAL/Functional/Driver/PDO/ConnectionTest.php | 8 ++++---- .../Tests/DBAL/Tools/Console/RunSqlCommandTest.php | 9 +++++---- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/ConnectionTest.php index f4947212ec0..909528eb06e 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/ConnectionTest.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\DBAL\Functional\Driver\OCI8; -use Doctrine\DBAL\Driver\OCI8\Connection; use Doctrine\DBAL\Driver\OCI8\Driver; use Doctrine\DBAL\Schema\Table; use Doctrine\Tests\DbalFunctionalTestCase; @@ -12,18 +11,15 @@ */ class ConnectionTest extends DbalFunctionalTestCase { - /** @var Connection */ - protected $driverConnection; - protected function setUp(): void { parent::setUp(); - if (! $this->connection->getDriver() instanceof Driver) { - $this->markTestSkipped('oci8 only test.'); + if ($this->connection->getDriver() instanceof Driver) { + return; } - $this->driverConnection = $this->connection->getWrappedConnection(); + $this->markTestSkipped('oci8 only test.'); } public function testLastInsertIdAcceptsFqn(): void @@ -42,6 +38,6 @@ public function testLastInsertIdAcceptsFqn(): void $schema = $this->connection->getDatabase(); $sequence = $platform->getIdentitySequenceName($schema . '.DBAL2595', 'id'); - self::assertSame(1, $this->driverConnection->lastInsertId($sequence)); + self::assertSame(1, $this->connection->lastInsertId($sequence)); } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDO/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDO/ConnectionTest.php index c9f748fbce6..143cbf6c687 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDO/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDO/ConnectionTest.php @@ -31,13 +31,13 @@ protected function setUp(): void { parent::setUp(); - $this->driverConnection = $this->connection->getWrappedConnection(); + $driverConnection = $this->connection->getWrappedConnection(); - if ($this->driverConnection instanceof Connection) { - return; + if (! $driverConnection instanceof Connection) { + $this->markTestSkipped('PDO connection only test.'); } - $this->markTestSkipped('PDO connection only test.'); + $this->driverConnection = $driverConnection; } protected function tearDown(): void diff --git a/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php b/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php index 8a99dd366b8..5b7357b30b1 100644 --- a/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php +++ b/tests/Doctrine/Tests/DBAL/Tools/Console/RunSqlCommandTest.php @@ -24,16 +24,17 @@ class RunSqlCommandTest extends TestCase protected function setUp(): void { - $application = new Application(); - $application->add(new RunSqlCommand()); + $this->command = new RunSqlCommand(); - $this->command = $application->find('dbal:run-sql'); - $this->commandTester = new CommandTester($this->command); + (new Application())->add($this->command); $this->connectionMock = $this->createMock(Connection::class); $helperSet = ConsoleRunner::createHelperSet($this->connectionMock); + $this->command->setHelperSet($helperSet); + + $this->commandTester = new CommandTester($this->command); } public function testMissingSqlArgument(): void From f930db20d2aa4451d3f0bef4e0a5dd33dba38c74 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 15 Oct 2020 19:27:06 -0700 Subject: [PATCH 17/21] Fix PossiblyFalsePropertyAssignmentValue issues --- lib/Doctrine/DBAL/Schema/Schema.php | 2 +- lib/Doctrine/DBAL/Schema/Table.php | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/DBAL/Schema/Schema.php b/lib/Doctrine/DBAL/Schema/Schema.php index 6ea5fd0c8c0..24fc47b599b 100644 --- a/lib/Doctrine/DBAL/Schema/Schema.php +++ b/lib/Doctrine/DBAL/Schema/Schema.php @@ -52,7 +52,7 @@ class Schema extends AbstractAsset protected $_sequences = []; /** @var SchemaConfig */ - protected $_schemaConfig = false; + protected $_schemaConfig; /** * @param Table[] $tables diff --git a/lib/Doctrine/DBAL/Schema/Table.php b/lib/Doctrine/DBAL/Schema/Table.php index 740092d3ca1..d69dc45f189 100644 --- a/lib/Doctrine/DBAL/Schema/Table.php +++ b/lib/Doctrine/DBAL/Schema/Table.php @@ -29,7 +29,7 @@ class Table extends AbstractAsset /** @var Index[] */ protected $_indexes = []; - /** @var string */ + /** @var string|false */ protected $_primaryKeyName = false; /** @var ForeignKeyConstraint[] */ @@ -150,6 +150,10 @@ public function addIndex(array $columnNames, $indexName = null, array $flags = [ */ public function dropPrimaryKey() { + if ($this->_primaryKeyName === false) { + return; + } + $this->dropIndex($this->_primaryKeyName); $this->_primaryKeyName = false; } @@ -717,11 +721,11 @@ public function getColumn($name) */ public function getPrimaryKey() { - if (! $this->hasPrimaryKey()) { - return null; + if ($this->_primaryKeyName !== false) { + return $this->getIndex($this->_primaryKeyName); } - return $this->getIndex($this->_primaryKeyName); + return null; } /** From 7a33a6bf4c9f24b9198484ca795ce6aa9cafbded Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 15 Oct 2020 19:48:56 -0700 Subject: [PATCH 18/21] Fix PossiblyNullPropertyAssignmentValue issues --- lib/Doctrine/DBAL/Schema/TableDiff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/DBAL/Schema/TableDiff.php b/lib/Doctrine/DBAL/Schema/TableDiff.php index dcaeb200a6a..82c912f71b1 100644 --- a/lib/Doctrine/DBAL/Schema/TableDiff.php +++ b/lib/Doctrine/DBAL/Schema/TableDiff.php @@ -10,7 +10,7 @@ class TableDiff { /** @var string */ - public $name = null; + public $name; /** @var string|false */ public $newName = false; From 19a889797a0ac239e77e1adf717c4fe2ba91a18c Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 15 Oct 2020 20:15:29 -0700 Subject: [PATCH 19/21] Fix PossiblyFalseOperand issues --- lib/Doctrine/DBAL/Schema/DB2SchemaManager.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php b/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php index 25f0282c536..fcc196ae519 100644 --- a/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php @@ -7,7 +7,6 @@ use function array_change_key_case; use function assert; -use function is_resource; use function preg_match; use function str_replace; use function strpos; @@ -207,13 +206,12 @@ protected function _getPortableForeignKeyRuleDef($def) protected function _getPortableViewDefinition($view) { $view = array_change_key_case($view, CASE_LOWER); - // sadly this still segfaults on PDO_IBM, see http://pecl.php.net/bugs/bug.php?id=17199 - //$view['text'] = (is_resource($view['text']) ? stream_get_contents($view['text']) : $view['text']); - if (! is_resource($view['text'])) { - $pos = strpos($view['text'], ' AS '); + + $sql = ''; + $pos = strpos($view['text'], ' AS '); + + if ($pos !== false) { $sql = substr($view['text'], $pos + 4); - } else { - $sql = ''; } return new View($view['name'], $sql); From 8c6ea53361de1fdbb1c44933b65a7d96c69b9abe Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 15 Oct 2020 20:23:36 -0700 Subject: [PATCH 20/21] Fix PossiblyNullArrayOffset issues --- lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index 5580ea23dea..911daa8cb8b 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -1602,8 +1602,10 @@ public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDE } } + $name = $column->getQuotedName($this); + $columnData = array_merge($column->toArray(), [ - 'name' => $column->getQuotedName($this), + 'name' => $name, 'version' => $column->hasPlatformOption('version') ? $column->getPlatformOption('version') : false, 'comment' => $this->getColumnComment($column), ]); @@ -1616,7 +1618,7 @@ public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDE $columnData['primary'] = true; } - $columns[$columnData['name']] = $columnData; + $columns[$name] = $columnData; } if (($createFlags & self::CREATE_FOREIGNKEYS) > 0) { From 7722b516685738121de202450348ee9a6bc617a1 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 14 Oct 2020 18:21:06 -0700 Subject: [PATCH 21/21] Bump Psalm level to 3 --- psalm.xml | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/psalm.xml b/psalm.xml index f67b67c6566..999a5611126 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,7 +1,7 @@ + + + + + + + + + + + + + + +