From 2b2848e13edbbf52cb4c443204979251bd3b6061 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 2 Apr 2020 20:32:39 -0700 Subject: [PATCH 01/19] Enabled PHPStan strict rules --- composer.json | 3 +- composer.lock | 70 +++++++++++++++++++++++++++++++++++++++++++++-- phpstan.neon.dist | 3 ++ 3 files changed, 73 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 7d9fcda6cab..1a026121c58 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,8 @@ "require-dev": { "doctrine/coding-standard": "^6.0", "jetbrains/phpstorm-stubs": "^2019.1", - "phpstan/phpstan": "^0.12", + "phpstan/phpstan": "^0.12.18", + "phpstan/phpstan-strict-rules": "^0.12.2", "phpunit/phpunit": "^9.0", "symfony/console": "^2.0.5|^3.0|^4.0|^5.0" }, diff --git a/composer.lock b/composer.lock index 9bcf7a40392..ff58799f837 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "33232ba3c41c9de6f6bc60c784726991", + "content-hash": "194abb042dbd3732c1da46cf05ad7a07", "packages": [ { "name": "doctrine/cache", @@ -876,8 +876,73 @@ "MIT" ], "description": "PHPStan - PHP Static Analysis Tool", + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://www.patreon.com/phpstan", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", + "type": "tidelift" + } + ], "time": "2020-03-22T16:51:47+00:00" }, + { + "name": "phpstan/phpstan-strict-rules", + "version": "0.12.2", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan-strict-rules.git", + "reference": "a670a59aff7cf96f75d21b974860ada10e25b2ee" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan-strict-rules/zipball/a670a59aff7cf96f75d21b974860ada10e25b2ee", + "reference": "a670a59aff7cf96f75d21b974860ada10e25b2ee", + "shasum": "" + }, + "require": { + "php": "~7.1", + "phpstan/phpstan": "^0.12.6" + }, + "require-dev": { + "consistence/coding-standard": "^3.0.1", + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.4", + "ergebnis/composer-normalize": "^2.0.2", + "jakub-onderka/php-parallel-lint": "^1.0", + "phing/phing": "^2.16.0", + "phpstan/phpstan-phpunit": "^0.12", + "phpunit/phpunit": "^7.0", + "slevomat/coding-standard": "^4.5.2" + }, + "type": "phpstan-extension", + "extra": { + "branch-alias": { + "dev-master": "0.12-dev" + }, + "phpstan": { + "includes": [ + "rules.neon" + ] + } + }, + "autoload": { + "psr-4": { + "PHPStan\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Extra strict and opinionated rules for PHPStan", + "time": "2020-01-20T13:08:52+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "8.0.1", @@ -2444,5 +2509,6 @@ "platform-dev": [], "platform-overrides": { "php": "7.3.0" - } + }, + "plugin-api-version": "1.1.0" } diff --git a/phpstan.neon.dist b/phpstan.neon.dist index bd08cc3a8d1..7d561cd2166 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -4,6 +4,7 @@ parameters: - %currentWorkingDirectory%/src autoload_files: - %currentWorkingDirectory%/tests/phpstan-polyfill.php + treatPhpDocTypesAsCertain: false reportUnmatchedIgnoredErrors: false checkMissingIterableValueType: false checkGenericClassInNonGenericObjectType: false @@ -72,3 +73,5 @@ parameters: - message: '~^Cannot cast array\|bool\|string\|null to int\.$~' path: %currentWorkingDirectory%/src/Tools/Console/Command/RunSqlCommand.php +includes: + - vendor/phpstan/phpstan-strict-rules/rules.neon From 4edcd154fde5d6e513043e5b98698a2ebccfe457 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 24 Jan 2020 11:05:13 -0800 Subject: [PATCH 02/19] Reworked type-based and conditions and clarified some types to justify the ones that remain unchanged. --- phpstan.neon.dist | 5 +++++ src/Driver/SQLAnywhere/SQLAnywhereStatement.php | 2 +- src/Platforms/AbstractPlatform.php | 4 ++-- src/Platforms/SQLAnywhere16Platform.php | 2 +- src/Platforms/SqlitePlatform.php | 4 +--- src/Schema/AbstractSchemaManager.php | 4 ---- src/Schema/Table.php | 12 ++++++++---- tests/Functional/Driver/Mysqli/ConnectionTest.php | 8 +++----- 8 files changed, 21 insertions(+), 20 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 7d561cd2166..7025810deae 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -73,5 +73,10 @@ parameters: - message: '~^Cannot cast array\|bool\|string\|null to int\.$~' path: %currentWorkingDirectory%/src/Tools/Console/Command/RunSqlCommand.php + + # https://github.com/phpstan/phpstan/issues/3134 + - + message: '~^Call to static method PHPUnit\\Framework\\Assert::assertSame\(\) with Doctrine\\DBAL\\Types\\Type and Doctrine\\DBAL\\Types\\Type will always evaluate to true\.$~' + path: %currentWorkingDirectory%/tests/Types/TypeRegistryTest.php includes: - vendor/phpstan/phpstan-strict-rules/rules.neon diff --git a/src/Driver/SQLAnywhere/SQLAnywhereStatement.php b/src/Driver/SQLAnywhere/SQLAnywhereStatement.php index 31d4aec7210..59ab35cd087 100644 --- a/src/Driver/SQLAnywhere/SQLAnywhereStatement.php +++ b/src/Driver/SQLAnywhere/SQLAnywhereStatement.php @@ -51,7 +51,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement /** @var int Default fetch mode to use. */ private $defaultFetchMode = FetchMode::MIXED; - /** @var resource The result set resource to fetch. */ + /** @var resource|null The result set resource to fetch. */ private $result; /** @var resource The prepared SQL statement to execute. */ diff --git a/src/Platforms/AbstractPlatform.php b/src/Platforms/AbstractPlatform.php index f805b3d8c52..442dcd1c54a 100644 --- a/src/Platforms/AbstractPlatform.php +++ b/src/Platforms/AbstractPlatform.php @@ -140,7 +140,7 @@ abstract class AbstractPlatform */ protected $doctrineTypeComments = null; - /** @var EventManager */ + /** @var EventManager|null */ protected $_eventManager; /** @@ -167,7 +167,7 @@ public function setEventManager(EventManager $eventManager) /** * Gets the EventManager used by the Platform. * - * @return EventManager + * @return EventManager|null */ public function getEventManager() { diff --git a/src/Platforms/SQLAnywhere16Platform.php b/src/Platforms/SQLAnywhere16Platform.php index e427ac33c64..254f4132647 100644 --- a/src/Platforms/SQLAnywhere16Platform.php +++ b/src/Platforms/SQLAnywhere16Platform.php @@ -373,7 +373,7 @@ public function getCommentOnColumnSQL($tableName, $columnName, $comment) */ public function getConcatExpression() { - return 'STRING(' . implode(', ', (array) func_get_args()) . ')'; + return 'STRING(' . implode(', ', func_get_args()) . ')'; } /** diff --git a/src/Platforms/SqlitePlatform.php b/src/Platforms/SqlitePlatform.php index 3f6e4346e81..52db479bd39 100644 --- a/src/Platforms/SqlitePlatform.php +++ b/src/Platforms/SqlitePlatform.php @@ -3,7 +3,6 @@ namespace Doctrine\DBAL\Platforms; use Doctrine\DBAL\DBALException; -use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\Constraint; use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\Identifier; @@ -958,8 +957,7 @@ private function getSimpleAlterTableSQL(TableDiff $diff) { // Suppress changes on integer type autoincrement columns. foreach ($diff->changedColumns as $oldColumnName => $columnDiff) { - if (! $columnDiff->fromColumn instanceof Column || - ! $columnDiff->column instanceof Column || + if ($columnDiff->fromColumn === null || ! $columnDiff->column->getAutoincrement() || ! $columnDiff->column->getType() instanceof Types\IntegerType ) { diff --git a/src/Schema/AbstractSchemaManager.php b/src/Schema/AbstractSchemaManager.php index 8e4ffa5f966..bcffcce91ba 100644 --- a/src/Schema/AbstractSchemaManager.php +++ b/src/Schema/AbstractSchemaManager.php @@ -18,7 +18,6 @@ use function call_user_func_array; use function count; use function func_get_args; -use function is_array; use function is_callable; use function preg_match; use function str_replace; @@ -594,9 +593,6 @@ public function dropAndCreateView(View $view) public function alterTable(TableDiff $tableDiff) { $queries = $this->_platform->getAlterTableSQL($tableDiff); - if (! is_array($queries) || ! count($queries)) { - return; - } foreach ($queries as $ddlQuery) { $this->_execSql($ddlQuery); diff --git a/src/Schema/Table.php b/src/Schema/Table.php index 842d1fccf67..03743b83642 100644 --- a/src/Schema/Table.php +++ b/src/Schema/Table.php @@ -27,7 +27,7 @@ class Table extends AbstractAsset /** @var Index[] */ protected $_indexes = []; - /** @var string */ + /** @var string|false */ protected $_primaryKeyName = false; /** @var ForeignKeyConstraint[] */ @@ -142,6 +142,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; } @@ -672,11 +676,11 @@ public function getColumn($columnName) */ public function getPrimaryKey() { - if (! $this->hasPrimaryKey()) { - return null; + if ($this->_primaryKeyName !== false) { + return $this->getIndex($this->_primaryKeyName); } - return $this->getIndex($this->_primaryKeyName); + return null; } /** diff --git a/tests/Functional/Driver/Mysqli/ConnectionTest.php b/tests/Functional/Driver/Mysqli/ConnectionTest.php index 3b4abfc073e..9b68a38aa7e 100644 --- a/tests/Functional/Driver/Mysqli/ConnectionTest.php +++ b/tests/Functional/Driver/Mysqli/ConnectionTest.php @@ -31,12 +31,10 @@ protected function tearDown() : void parent::tearDown(); } - public function testDriverOptions() : void + public function testSupportedDriverOptions() : void { - $driverOptions = [MYSQLI_OPT_CONNECT_TIMEOUT => 1]; - - $connection = $this->getConnection($driverOptions); - self::assertInstanceOf(MysqliConnection::class, $connection); + $this->expectNotToPerformAssertions(); + $this->getConnection([MYSQLI_OPT_CONNECT_TIMEOUT => 1]); } public function testUnsupportedDriverOption() : void From 300a8e594840aa786095bf2fcd3ff28aeee52c9c Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 2 Apr 2020 20:42:46 -0700 Subject: [PATCH 03/19] Fixed dynamic calls to static methods --- tests/ConnectionTest.php | 150 +++++++++--------- tests/Driver/AbstractDriverTest.php | 10 +- tests/Driver/AbstractMySQLDriverTest.php | 12 +- .../EasyConnectStringTest.php | 2 +- tests/Driver/AbstractOracleDriverTest.php | 8 +- tests/Driver/AbstractPostgreSQLDriverTest.php | 12 +- tests/Driver/AbstractSQLiteDriverTest.php | 4 +- tests/Driver/Mysqli/MysqliConnectionTest.php | 2 +- tests/Driver/OCI8/OCI8StatementTest.php | 20 +-- tests/Driver/StatementIteratorTest.php | 10 +- tests/Events/MysqlSessionInitTest.php | 4 +- tests/Events/OracleSessionInitTest.php | 8 +- tests/Events/SQLSessionInitTest.php | 4 +- tests/Functional/BlobTest.php | 8 +- tests/Functional/ConnectionTest.php | 27 ++-- tests/Functional/DataAccessTest.php | 16 +- .../Driver/IBMDB2/DB2DriverTest.php | 8 +- .../Driver/IBMDB2/DB2StatementTest.php | 4 +- .../Driver/Mysqli/ConnectionTest.php | 4 +- tests/Functional/Driver/Mysqli/DriverTest.php | 4 +- tests/Functional/Driver/OCI8/DriverTest.php | 8 +- .../Driver/OCI8/OCI8ConnectionTest.php | 4 +- .../Functional/Driver/OCI8/StatementTest.php | 4 +- tests/Functional/Driver/PDOConnectionTest.php | 4 +- .../Functional/Driver/PDOMySql/DriverTest.php | 4 +- .../Driver/PDOOracle/DriverTest.php | 8 +- .../Functional/Driver/PDOPgSql/DriverTest.php | 6 +- .../Driver/PDOPgsqlConnectionTest.php | 4 +- .../Driver/PDOSqlite/DriverTest.php | 4 +- .../Driver/PDOSqlsrv/DriverTest.php | 4 +- .../Driver/SQLAnywhere/ConnectionTest.php | 4 +- .../Driver/SQLAnywhere/DriverTest.php | 4 +- .../Driver/SQLAnywhere/StatementTest.php | 4 +- tests/Functional/Driver/SQLSrv/DriverTest.php | 4 +- tests/Functional/ExceptionTest.php | 10 +- .../Functional/LikeWildcardsEscapingTest.php | 2 +- tests/Functional/LoggingTest.php | 18 +-- .../Functional/MasterSlaveConnectionTest.php | 2 +- tests/Functional/NamedParametersTest.php | 2 +- ...imaryKeyWithNewAutoIncrementColumnTest.php | 10 +- .../Schema/MySqlSchemaManagerTest.php | 4 +- .../Schema/PostgreSqlSchemaManagerTest.php | 2 +- .../SchemaManagerFunctionalTestCase.php | 60 +++---- .../Schema/SqliteSchemaManagerTest.php | 6 +- tests/Functional/StatementTest.php | 8 +- tests/Functional/TableGeneratorTest.php | 2 +- tests/Functional/TemporaryTableTest.php | 4 +- tests/Functional/Ticket/DBAL168Test.php | 2 +- tests/Functional/Ticket/DBAL202Test.php | 2 +- tests/Functional/Ticket/DBAL461Test.php | 2 +- tests/Functional/Ticket/DBAL510Test.php | 2 +- tests/Functional/Ticket/DBAL630Test.php | 2 +- tests/Functional/Ticket/DBAL752Test.php | 2 +- tests/Functional/TransactionTest.php | 4 +- tests/Functional/TypeConversionTest.php | 2 +- tests/Functional/Types/BinaryTest.php | 6 +- tests/Functional/WriteTest.php | 10 +- tests/Logging/LoggerChainTest.php | 2 +- tests/Platforms/AbstractPlatformTestCase.php | 32 ++-- .../AbstractPostgreSQLPlatformTestCase.php | 4 +- .../AbstractSQLServerPlatformTestCase.php | 2 +- tests/Platforms/DB2PlatformTest.php | 2 +- tests/Platforms/MariaDb1027PlatformTest.php | 2 +- tests/Platforms/OraclePlatformTest.php | 2 +- tests/Platforms/SQLAnywhere16PlatformTest.php | 2 +- tests/Platforms/SqlitePlatformTest.php | 4 +- tests/Portability/StatementTest.php | 38 ++--- .../Expression/ExpressionBuilderTest.php | 4 +- tests/Query/QueryBuilderTest.php | 4 +- tests/Schema/ComparatorTest.php | 24 +-- tests/Schema/DB2SchemaManagerTest.php | 20 +-- tests/Schema/ForeignKeyConstraintTest.php | 4 +- tests/Schema/MySqlSchemaManagerTest.php | 2 +- tests/Schema/SchemaDiffTest.php | 66 ++++---- tests/Schema/SchemaTest.php | 36 ++--- tests/Schema/TableDiffTest.php | 4 +- .../Visitor/CreateSchemaSqlCollectorTest.php | 20 +-- .../Visitor/DropSchemaSqlCollectorTest.php | 18 +-- .../Schema/Visitor/SchemaSqlCollectorTest.php | 24 +-- tests/StatementTest.php | 46 +++--- tests/Tools/Console/RunSqlCommandTest.php | 14 +- tests/Types/BinaryTest.php | 2 +- tests/Types/DateImmutableTypeTest.php | 8 +- tests/Types/DateTimeImmutableTypeTest.php | 10 +- tests/Types/DateTimeTzImmutableTypeTest.php | 8 +- tests/Types/GuidTypeTest.php | 4 +- tests/Types/JsonArrayTest.php | 2 +- tests/Types/JsonTest.php | 2 +- tests/Types/StringTest.php | 4 +- tests/Types/TimeImmutableTypeTest.php | 8 +- tests/Types/VarDateTimeImmutableTypeTest.php | 2 +- 91 files changed, 486 insertions(+), 487 deletions(-) diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index 9a35fa4bcde..84156339408 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -56,9 +56,9 @@ private function getExecuteUpdateMockConnection() { $driverMock = $this->createMock(Driver::class); - $driverMock->expects($this->any()) + $driverMock->expects(self::any()) ->method('connect') - ->will($this->returnValue( + ->will(self::returnValue( $this->createMock(DriverConnection::class) )); @@ -146,13 +146,13 @@ public function testConnectDispatchEvent() : void $listenerMock = $this->getMockBuilder($this->getMockClass('ConnectDispatchEventListener')) ->addMethods(['postConnect']) ->getMock(); - $listenerMock->expects($this->once())->method('postConnect'); + $listenerMock->expects(self::once())->method('postConnect'); $eventManager = new EventManager(); $eventManager->addEventListener([Events::postConnect], $listenerMock); $driverMock = $this->createMock(Driver::class); - $driverMock->expects($this->at(0)) + $driverMock->expects(self::at(0)) ->method('connect'); $conn = new Connection([], $driverMock, new Configuration(), $eventManager); @@ -165,13 +165,13 @@ public function testEventManagerPassedToPlatform() : void /** @var AbstractPlatform|MockObject $driver */ $platform = $this->createMock(AbstractPlatform::class); - $platform->expects($this->once()) + $platform->expects(self::once()) ->method('setEventManager') ->with($eventManager); /** @var Driver|MockObject $driver */ $driver = $this->createMock(Driver::class); - $driver->expects($this->any()) + $driver->expects(self::any()) ->method('getDatabasePlatform') ->willReturn($platform); @@ -247,9 +247,9 @@ public function testSetAutoCommit() : void public function testConnectStartsTransactionInNoAutoCommitMode() : void { $driverMock = $this->createMock(Driver::class); - $driverMock->expects($this->any()) + $driverMock->expects(self::any()) ->method('connect') - ->will($this->returnValue( + ->will(self::returnValue( $this->createMock(DriverConnection::class) )); $conn = new Connection([], $driverMock); @@ -269,9 +269,9 @@ public function testConnectStartsTransactionInNoAutoCommitMode() : void public function testCommitStartsTransactionInNoAutoCommitMode() : void { $driverMock = $this->createMock(Driver::class); - $driverMock->expects($this->any()) + $driverMock->expects(self::any()) ->method('connect') - ->will($this->returnValue( + ->will(self::returnValue( $this->createMock(DriverConnection::class) )); $conn = new Connection([], $driverMock); @@ -289,13 +289,13 @@ public function testCommitStartsTransactionInNoAutoCommitMode() : void public function testCommitReturn(bool $expectedResult) : void { $driverConnection = $this->createMock(DriverConnection::class); - $driverConnection->expects($this->once()) + $driverConnection->expects(self::once()) ->method('commit')->willReturn($expectedResult); $driverMock = $this->createMock(Driver::class); - $driverMock->expects($this->any()) + $driverMock->expects(self::any()) ->method('connect') - ->will($this->returnValue($driverConnection)); + ->will(self::returnValue($driverConnection)); $conn = new Connection([], $driverMock); @@ -319,9 +319,9 @@ public function resultProvider() : array public function testRollBackStartsTransactionInNoAutoCommitMode() : void { $driverMock = $this->createMock(Driver::class); - $driverMock->expects($this->any()) + $driverMock->expects(self::any()) ->method('connect') - ->will($this->returnValue( + ->will(self::returnValue( $this->createMock(DriverConnection::class) )); $conn = new Connection([], $driverMock); @@ -339,9 +339,9 @@ public function testRollBackStartsTransactionInNoAutoCommitMode() : void public function testSwitchingAutoCommitModeCommitsAllCurrentTransactions() : void { $driverMock = $this->createMock(Driver::class); - $driverMock->expects($this->any()) + $driverMock->expects(self::any()) ->method('connect') - ->will($this->returnValue( + ->will(self::returnValue( $this->createMock(DriverConnection::class) )); $conn = new Connection([], $driverMock); @@ -364,7 +364,7 @@ public function testEmptyInsert() : void { $conn = $this->getExecuteUpdateMockConnection(); - $conn->expects($this->once()) + $conn->expects(self::once()) ->method('executeUpdate') ->with('INSERT INTO footable () VALUES ()'); @@ -378,7 +378,7 @@ public function testUpdateWithDifferentColumnsInDataAndIdentifiers() : void { $conn = $this->getExecuteUpdateMockConnection(); - $conn->expects($this->once()) + $conn->expects(self::once()) ->method('executeUpdate') ->with( 'UPDATE TestTable SET text = ?, is_edited = ? WHERE id = ? AND name = ?', @@ -422,7 +422,7 @@ public function testUpdateWithSameColumnInDataAndIdentifiers() : void { $conn = $this->getExecuteUpdateMockConnection(); - $conn->expects($this->once()) + $conn->expects(self::once()) ->method('executeUpdate') ->with( 'UPDATE TestTable SET text = ?, is_edited = ? WHERE id = ? AND is_edited = ?', @@ -465,7 +465,7 @@ public function testUpdateWithIsNull() : void { $conn = $this->getExecuteUpdateMockConnection(); - $conn->expects($this->once()) + $conn->expects(self::once()) ->method('executeUpdate') ->with( 'UPDATE TestTable SET text = ?, is_edited = ? WHERE id IS NULL AND name = ?', @@ -507,7 +507,7 @@ public function testDeleteWithIsNull() : void { $conn = $this->getExecuteUpdateMockConnection(); - $conn->expects($this->once()) + $conn->expects(self::once()) ->method('executeUpdate') ->with( 'DELETE FROM TestTable WHERE id IS NULL AND name = ?', @@ -537,18 +537,18 @@ public function testFetchAssoc() : void $driverMock = $this->createMock(Driver::class); - $driverMock->expects($this->any()) + $driverMock->expects(self::any()) ->method('connect') - ->will($this->returnValue( + ->will(self::returnValue( $this->createMock(DriverConnection::class) )); $driverStatementMock = $this->createMock(Statement::class); - $driverStatementMock->expects($this->once()) + $driverStatementMock->expects(self::once()) ->method('fetch') ->with(FetchMode::ASSOCIATIVE) - ->will($this->returnValue($result)); + ->will(self::returnValue($result)); /** @var Connection|MockObject $conn */ $conn = $this->getMockBuilder(Connection::class) @@ -556,10 +556,10 @@ public function testFetchAssoc() : void ->setConstructorArgs([[], $driverMock]) ->getMock(); - $conn->expects($this->once()) + $conn->expects(self::once()) ->method('executeQuery') ->with($statement, $params, $types) - ->will($this->returnValue($driverStatementMock)); + ->will(self::returnValue($driverStatementMock)); self::assertSame($result, $conn->fetchAssoc($statement, $params, $types)); } @@ -573,18 +573,18 @@ public function testFetchArray() : void $driverMock = $this->createMock(Driver::class); - $driverMock->expects($this->any()) + $driverMock->expects(self::any()) ->method('connect') - ->will($this->returnValue( + ->will(self::returnValue( $this->createMock(DriverConnection::class) )); $driverStatementMock = $this->createMock(Statement::class); - $driverStatementMock->expects($this->once()) + $driverStatementMock->expects(self::once()) ->method('fetch') ->with(FetchMode::NUMERIC) - ->will($this->returnValue($result)); + ->will(self::returnValue($result)); /** @var Connection|MockObject $conn */ $conn = $this->getMockBuilder(Connection::class) @@ -592,10 +592,10 @@ public function testFetchArray() : void ->setConstructorArgs([[], $driverMock]) ->getMock(); - $conn->expects($this->once()) + $conn->expects(self::once()) ->method('executeQuery') ->with($statement, $params, $types) - ->will($this->returnValue($driverStatementMock)); + ->will(self::returnValue($driverStatementMock)); self::assertSame($result, $conn->fetchArray($statement, $params, $types)); } @@ -610,18 +610,18 @@ public function testFetchColumn() : void $driverMock = $this->createMock(Driver::class); - $driverMock->expects($this->any()) + $driverMock->expects(self::any()) ->method('connect') - ->will($this->returnValue( + ->will(self::returnValue( $this->createMock(DriverConnection::class) )); $driverStatementMock = $this->createMock(Statement::class); - $driverStatementMock->expects($this->once()) + $driverStatementMock->expects(self::once()) ->method('fetchColumn') ->with($column) - ->will($this->returnValue($result)); + ->will(self::returnValue($result)); /** @var Connection|MockObject $conn */ $conn = $this->getMockBuilder(Connection::class) @@ -629,10 +629,10 @@ public function testFetchColumn() : void ->setConstructorArgs([[], $driverMock]) ->getMock(); - $conn->expects($this->once()) + $conn->expects(self::once()) ->method('executeQuery') ->with($statement, $params, $types) - ->will($this->returnValue($driverStatementMock)); + ->will(self::returnValue($driverStatementMock)); self::assertSame($result, $conn->fetchColumn($statement, $params, $column, $types)); } @@ -646,17 +646,17 @@ public function testFetchAll() : void $driverMock = $this->createMock(Driver::class); - $driverMock->expects($this->any()) + $driverMock->expects(self::any()) ->method('connect') - ->will($this->returnValue( + ->will(self::returnValue( $this->createMock(DriverConnection::class) )); $driverStatementMock = $this->createMock(Statement::class); - $driverStatementMock->expects($this->once()) + $driverStatementMock->expects(self::once()) ->method('fetchAll') - ->will($this->returnValue($result)); + ->will(self::returnValue($result)); /** @var Connection|MockObject $conn */ $conn = $this->getMockBuilder(Connection::class) @@ -664,10 +664,10 @@ public function testFetchAll() : void ->setConstructorArgs([[], $driverMock]) ->getMock(); - $conn->expects($this->once()) + $conn->expects(self::once()) ->method('executeQuery') ->with($statement, $params, $types) - ->will($this->returnValue($driverStatementMock)); + ->will(self::returnValue($driverStatementMock)); self::assertSame($result, $conn->fetchAll($statement, $params, $types)); } @@ -686,7 +686,7 @@ public function testCallConnectOnce() : void { /** @var Driver|MockObject $driver */ $driver = $this->createMock(Driver::class); - $driver->expects($this->once()) + $driver->expects(self::once()) ->method('connect'); $platform = $this->createMock(AbstractPlatform::class); @@ -712,22 +712,22 @@ public function testPlatformDetectionIsTriggerOnlyOnceOnRetrievingPlatform() : v $connection = new Connection([], $driverMock); - $driverMock->expects($this->once()) + $driverMock->expects(self::once()) ->method('connect') - ->will($this->returnValue($driverConnectionMock)); + ->will(self::returnValue($driverConnectionMock)); - $driverConnectionMock->expects($this->once()) + $driverConnectionMock->expects(self::once()) ->method('requiresQueryForServerVersion') - ->will($this->returnValue(false)); + ->will(self::returnValue(false)); - $driverConnectionMock->expects($this->once()) + $driverConnectionMock->expects(self::once()) ->method('getServerVersion') - ->will($this->returnValue('6.6.6')); + ->will(self::returnValue('6.6.6')); - $driverMock->expects($this->once()) + $driverMock->expects(self::once()) ->method('createDatabasePlatformForVersion') ->with('6.6.6') - ->will($this->returnValue($platformMock)); + ->will(self::returnValue($platformMock)); self::assertSame($platformMock, $connection->getDatabasePlatform()); } @@ -737,10 +737,10 @@ public function testConnectionParamsArePassedToTheQueryCacheProfileInExecuteCach $resultCacheDriverMock = $this->createMock(Cache::class); $resultCacheDriverMock - ->expects($this->atLeastOnce()) + ->expects(self::atLeastOnce()) ->method('fetch') ->with('cacheKey') - ->will($this->returnValue(['realKey' => []])); + ->will(self::returnValue(['realKey' => []])); $query = 'SELECT * FROM foo WHERE bar = ?'; $params = [666]; @@ -750,16 +750,16 @@ public function testConnectionParamsArePassedToTheQueryCacheProfileInExecuteCach $queryCacheProfileMock = $this->createMock(QueryCacheProfile::class); $queryCacheProfileMock - ->expects($this->any()) + ->expects(self::any()) ->method('getResultCacheDriver') - ->will($this->returnValue($resultCacheDriverMock)); + ->will(self::returnValue($resultCacheDriverMock)); // This is our main expectation $queryCacheProfileMock - ->expects($this->once()) + ->expects(self::once()) ->method('generateCacheKeys') ->with($query, $params, $types, $this->params) - ->will($this->returnValue(['cacheKey', 'realKey'])); + ->will(self::returnValue(['cacheKey', 'realKey'])); /** @var Driver $driver */ $driver = $this->createMock(Driver::class); @@ -778,28 +778,28 @@ public function testShouldNotPassPlatformInParamsToTheQueryCacheProfileInExecute $resultCacheDriverMock = $this->createMock(Cache::class); $resultCacheDriverMock - ->expects($this->atLeastOnce()) + ->expects(self::atLeastOnce()) ->method('fetch') ->with('cacheKey') - ->will($this->returnValue(['realKey' => []])); + ->will(self::returnValue(['realKey' => []])); /** @var QueryCacheProfile|MockObject $queryCacheProfileMock */ $queryCacheProfileMock = $this->createMock(QueryCacheProfile::class); $queryCacheProfileMock - ->expects($this->any()) + ->expects(self::any()) ->method('getResultCacheDriver') - ->will($this->returnValue($resultCacheDriverMock)); + ->will(self::returnValue($resultCacheDriverMock)); $query = 'SELECT 1'; $connectionParams = $this->params; $queryCacheProfileMock - ->expects($this->once()) + ->expects(self::once()) ->method('generateCacheKeys') ->with($query, [], [], $connectionParams) - ->will($this->returnValue(['cacheKey', 'realKey'])); + ->will(self::returnValue(['cacheKey', 'realKey'])); $connectionParams['platform'] = $this->createMock(AbstractPlatform::class); @@ -837,11 +837,11 @@ public function testRethrowsOriginalExceptionOnDeterminingPlatformWhenConnecting $originalException = new Exception('Original exception'); $fallbackException = new Exception('Fallback exception'); - $driverMock->expects($this->at(0)) + $driverMock->expects(self::at(0)) ->method('connect') ->willThrowException($originalException); - $driverMock->expects($this->at(1)) + $driverMock->expects(self::at(1)) ->method('connect') ->willThrowException($fallbackException); @@ -868,15 +868,15 @@ public function testExecuteCacheQueryStripsPlatformFromConnectionParamsBeforeGen $resultCacheDriver = $this->createMock(Cache::class); $queryCacheProfile - ->expects($this->any()) + ->expects(self::any()) ->method('getResultCacheDriver') - ->will($this->returnValue($resultCacheDriver)); + ->will(self::returnValue($resultCacheDriver)); $resultCacheDriver - ->expects($this->atLeastOnce()) + ->expects(self::atLeastOnce()) ->method('fetch') ->with('cacheKey') - ->will($this->returnValue(['realKey' => []])); + ->will(self::returnValue(['realKey' => []])); $query = 'SELECT 1'; @@ -889,10 +889,10 @@ public function testExecuteCacheQueryStripsPlatformFromConnectionParamsBeforeGen unset($paramsWithoutPlatform['platform']); $queryCacheProfile - ->expects($this->once()) + ->expects(self::once()) ->method('generateCacheKeys') ->with($query, [], [], $paramsWithoutPlatform) - ->will($this->returnValue(['cacheKey', 'realKey'])); + ->will(self::returnValue(['cacheKey', 'realKey'])); $connection = new Connection($params, $driver); diff --git a/tests/Driver/AbstractDriverTest.php b/tests/Driver/AbstractDriverTest.php index 429ffa13bc7..120bc991bf0 100644 --- a/tests/Driver/AbstractDriverTest.php +++ b/tests/Driver/AbstractDriverTest.php @@ -76,7 +76,7 @@ protected function setUp() : void public function testConvertsException($errorCode, ?string $sqlState, ?string $message, string $expectedClass) : void { if (! $this->driver instanceof ExceptionConverterDriver) { - $this->markTestSkipped('This test is only intended for exception converter drivers.'); + self::markTestSkipped('This test is only intended for exception converter drivers.'); } /** @var DriverExceptionInterface|MockObject $driverException */ @@ -102,7 +102,7 @@ public function testConvertsException($errorCode, ?string $sqlState, ?string $me public function testCreatesDatabasePlatformForVersion() : void { if (! $this->driver instanceof VersionAwarePlatformDriver) { - $this->markTestSkipped('This test is only intended for version aware platform drivers.'); + self::markTestSkipped('This test is only intended for version aware platform drivers.'); } $data = $this->getDatabasePlatformsForVersions(); @@ -135,7 +135,7 @@ public function testCreatesDatabasePlatformForVersion() : void public function testThrowsExceptionOnCreatingDatabasePlatformsForInvalidVersion() : void { if (! $this->driver instanceof VersionAwarePlatformDriver) { - $this->markTestSkipped('This test is only intended for version aware platform drivers.'); + self::markTestSkipped('This test is only intended for version aware platform drivers.'); } $this->expectException(DBALException::class); @@ -152,9 +152,9 @@ public function testReturnsDatabaseName() : void $connection = $this->getConnectionMock(); - $connection->expects($this->once()) + $connection->expects(self::once()) ->method('getParams') - ->will($this->returnValue($params)); + ->will(self::returnValue($params)); self::assertSame($params['dbname'], $this->driver->getDatabase($connection)); } diff --git a/tests/Driver/AbstractMySQLDriverTest.php b/tests/Driver/AbstractMySQLDriverTest.php index fa3325f218d..822d06d2380 100644 --- a/tests/Driver/AbstractMySQLDriverTest.php +++ b/tests/Driver/AbstractMySQLDriverTest.php @@ -28,19 +28,19 @@ public function testReturnsDatabaseName() : void $statement = $this->createMock(ResultStatement::class); - $statement->expects($this->once()) + $statement->expects(self::once()) ->method('fetchColumn') - ->will($this->returnValue($database)); + ->will(self::returnValue($database)); $connection = $this->getConnectionMock(); - $connection->expects($this->once()) + $connection->expects(self::once()) ->method('getParams') - ->will($this->returnValue($params)); + ->will(self::returnValue($params)); - $connection->expects($this->once()) + $connection->expects(self::once()) ->method('query') - ->will($this->returnValue($statement)); + ->will(self::returnValue($statement)); self::assertSame($database, $this->driver->getDatabase($connection)); } diff --git a/tests/Driver/AbstractOracleDriver/EasyConnectStringTest.php b/tests/Driver/AbstractOracleDriver/EasyConnectStringTest.php index 0b62f8cef64..46b989448ee 100644 --- a/tests/Driver/AbstractOracleDriver/EasyConnectStringTest.php +++ b/tests/Driver/AbstractOracleDriver/EasyConnectStringTest.php @@ -16,7 +16,7 @@ public function testFromConnectionParameters(array $params, string $expected) : { $string = EasyConnectString::fromConnectionParameters($params); - $this->assertSame($expected, (string) $string); + self::assertSame($expected, (string) $string); } /** diff --git a/tests/Driver/AbstractOracleDriverTest.php b/tests/Driver/AbstractOracleDriverTest.php index 12e270f43ad..53b85b7449e 100644 --- a/tests/Driver/AbstractOracleDriverTest.php +++ b/tests/Driver/AbstractOracleDriverTest.php @@ -22,9 +22,9 @@ public function testReturnsDatabaseName() : void $connection = $this->getConnectionMock(); - $connection->expects($this->once()) + $connection->expects(self::once()) ->method('getParams') - ->will($this->returnValue($params)); + ->will(self::returnValue($params)); self::assertSame($params['user'], $this->driver->getDatabase($connection)); } @@ -41,9 +41,9 @@ public function testReturnsDatabaseNameWithConnectDescriptor() : void $connection = $this->getConnectionMock(); - $connection->expects($this->once()) + $connection->expects(self::once()) ->method('getParams') - ->will($this->returnValue($params)); + ->will(self::returnValue($params)); self::assertSame($params['user'], $this->driver->getDatabase($connection)); } diff --git a/tests/Driver/AbstractPostgreSQLDriverTest.php b/tests/Driver/AbstractPostgreSQLDriverTest.php index a404f291680..f7e18fca116 100644 --- a/tests/Driver/AbstractPostgreSQLDriverTest.php +++ b/tests/Driver/AbstractPostgreSQLDriverTest.php @@ -26,19 +26,19 @@ public function testReturnsDatabaseName() : void $statement = $this->createMock(ResultStatement::class); - $statement->expects($this->once()) + $statement->expects(self::once()) ->method('fetchColumn') - ->will($this->returnValue($database)); + ->will(self::returnValue($database)); $connection = $this->getConnectionMock(); - $connection->expects($this->once()) + $connection->expects(self::once()) ->method('getParams') - ->will($this->returnValue($params)); + ->will(self::returnValue($params)); - $connection->expects($this->once()) + $connection->expects(self::once()) ->method('query') - ->will($this->returnValue($statement)); + ->will(self::returnValue($statement)); self::assertSame($database, $this->driver->getDatabase($connection)); } diff --git a/tests/Driver/AbstractSQLiteDriverTest.php b/tests/Driver/AbstractSQLiteDriverTest.php index 8878fbc4e56..5a57bf5a460 100644 --- a/tests/Driver/AbstractSQLiteDriverTest.php +++ b/tests/Driver/AbstractSQLiteDriverTest.php @@ -23,9 +23,9 @@ public function testReturnsDatabaseName() : void $connection = $this->getConnectionMock(); - $connection->expects($this->once()) + $connection->expects(self::once()) ->method('getParams') - ->will($this->returnValue($params)); + ->will(self::returnValue($params)); self::assertSame($params['path'], $this->driver->getDatabase($connection)); } diff --git a/tests/Driver/Mysqli/MysqliConnectionTest.php b/tests/Driver/Mysqli/MysqliConnectionTest.php index b4de5c9fd36..5275230e543 100644 --- a/tests/Driver/Mysqli/MysqliConnectionTest.php +++ b/tests/Driver/Mysqli/MysqliConnectionTest.php @@ -23,7 +23,7 @@ class MysqliConnectionTest extends FunctionalTestCase protected function setUp() : void { if (! extension_loaded('mysqli')) { - $this->markTestSkipped('mysqli is not installed.'); + self::markTestSkipped('mysqli is not installed.'); } parent::setUp(); diff --git a/tests/Driver/OCI8/OCI8StatementTest.php b/tests/Driver/OCI8/OCI8StatementTest.php index 83a3c0fde34..6a4ff3db823 100644 --- a/tests/Driver/OCI8/OCI8StatementTest.php +++ b/tests/Driver/OCI8/OCI8StatementTest.php @@ -40,23 +40,23 @@ public function testExecute(array $params) : void ->disableOriginalConstructor() ->getMock(); - $statement->expects($this->at(0)) + $statement->expects(self::at(0)) ->method('bindValue') ->with( - $this->equalTo(1), - $this->equalTo($params[0]) + self::equalTo(1), + self::equalTo($params[0]) ); - $statement->expects($this->at(1)) + $statement->expects(self::at(1)) ->method('bindValue') ->with( - $this->equalTo(2), - $this->equalTo($params[1]) + self::equalTo(2), + self::equalTo($params[1]) ); - $statement->expects($this->at(2)) + $statement->expects(self::at(2)) ->method('bindValue') ->with( - $this->equalTo(3), - $this->equalTo($params[2]) + self::equalTo(3), + self::equalTo($params[2]) ); // the return value is irrelevant to the test @@ -70,7 +70,7 @@ public function testExecute(array $params) : void ->onlyMethods(['getExecuteMode']) ->disableOriginalConstructor() ->getMock(); - $conn->expects($this->once()) + $conn->expects(self::once()) ->method('getExecuteMode'); $reflProperty = new ReflectionProperty($statement, '_conn'); diff --git a/tests/Driver/StatementIteratorTest.php b/tests/Driver/StatementIteratorTest.php index 3fd8d1c4e00..45e42e922ed 100644 --- a/tests/Driver/StatementIteratorTest.php +++ b/tests/Driver/StatementIteratorTest.php @@ -25,9 +25,9 @@ public function testGettingIteratorDoesNotCallFetch(string $class) : void { /** @var IteratorAggregate|MockObject $stmt */ $stmt = $this->createPartialMock($class, ['fetch', 'fetchAll', 'fetchColumn']); - $stmt->expects($this->never())->method('fetch'); - $stmt->expects($this->never())->method('fetchAll'); - $stmt->expects($this->never())->method('fetchColumn'); + $stmt->expects(self::never())->method('fetch'); + $stmt->expects(self::never())->method('fetchAll'); + $stmt->expects(self::never())->method('fetchColumn'); $stmt->getIterator(); } @@ -61,7 +61,7 @@ private function configureStatement(MockObject $stmt, int &$calls) : void $values = ['foo', '', 'bar', '0', 'baz', 0, 'qux', null, 'quz', false, 'impossible']; $calls = 0; - $stmt->expects($this->exactly(10)) + $stmt->expects(self::exactly(10)) ->method('fetch') ->willReturnCallback(static function () use ($values, &$calls) { $value = $values[$calls]; @@ -74,7 +74,7 @@ private function configureStatement(MockObject $stmt, int &$calls) : void private function assertIterationCallsFetchOncePerStep(Traversable $iterator, int &$calls) : void { foreach ($iterator as $i => $_) { - $this->assertEquals($i + 1, $calls); + self::assertEquals($i + 1, $calls); } } diff --git a/tests/Events/MysqlSessionInitTest.php b/tests/Events/MysqlSessionInitTest.php index 23a3855ecd4..bc6c2f4237f 100644 --- a/tests/Events/MysqlSessionInitTest.php +++ b/tests/Events/MysqlSessionInitTest.php @@ -13,9 +13,9 @@ class MysqlSessionInitTest extends TestCase public function testPostConnect() : void { $connectionMock = $this->createMock(Connection::class); - $connectionMock->expects($this->once()) + $connectionMock->expects(self::once()) ->method('executeUpdate') - ->with($this->equalTo('SET NAMES foo COLLATE bar')); + ->with(self::equalTo('SET NAMES foo COLLATE bar')); $eventArgs = new ConnectionEventArgs($connectionMock); diff --git a/tests/Events/OracleSessionInitTest.php b/tests/Events/OracleSessionInitTest.php index 66e23a84460..2580329b577 100644 --- a/tests/Events/OracleSessionInitTest.php +++ b/tests/Events/OracleSessionInitTest.php @@ -14,9 +14,9 @@ class OracleSessionInitTest extends TestCase public function testPostConnect() : void { $connectionMock = $this->createMock(Connection::class); - $connectionMock->expects($this->once()) + $connectionMock->expects(self::once()) ->method('executeUpdate') - ->with($this->isType('string')); + ->with(self::isType('string')); $eventArgs = new ConnectionEventArgs($connectionMock); @@ -33,9 +33,9 @@ public function testPostConnectQuotesSessionParameterValues(string $name, string $connectionMock = $this->getMockBuilder(Connection::class) ->disableOriginalConstructor() ->getMock(); - $connectionMock->expects($this->once()) + $connectionMock->expects(self::once()) ->method('executeUpdate') - ->with($this->stringContains(sprintf('%s = %s', $name, $value))); + ->with(self::stringContains(sprintf('%s = %s', $name, $value))); $eventArgs = new ConnectionEventArgs($connectionMock); diff --git a/tests/Events/SQLSessionInitTest.php b/tests/Events/SQLSessionInitTest.php index 910de32f0d2..492d5e3463c 100644 --- a/tests/Events/SQLSessionInitTest.php +++ b/tests/Events/SQLSessionInitTest.php @@ -16,9 +16,9 @@ class SQLSessionInitTest extends TestCase public function testPostConnect() : void { $connectionMock = $this->createMock(Connection::class); - $connectionMock->expects($this->once()) + $connectionMock->expects(self::once()) ->method('exec') - ->with($this->equalTo("SET SEARCH_PATH TO foo, public, TIMEZONE TO 'Europe/Berlin'")); + ->with(self::equalTo("SET SEARCH_PATH TO foo, public, TIMEZONE TO 'Europe/Berlin'")); $eventArgs = new ConnectionEventArgs($connectionMock); diff --git a/tests/Functional/BlobTest.php b/tests/Functional/BlobTest.php index 3b74dddba34..b936b4ebb56 100644 --- a/tests/Functional/BlobTest.php +++ b/tests/Functional/BlobTest.php @@ -25,7 +25,7 @@ protected function setUp() : void if ($this->connection->getDriver() instanceof PDOOracleDriver) { // inserting BLOBs as streams on Oracle requires Oracle-specific SQL syntax which is currently not supported // see http://php.net/manual/en/pdo.lobs.php#example-1035 - $this->markTestSkipped('DBAL doesn\'t support storing LOBs represented as streams using PDO_OCI'); + self::markTestSkipped('DBAL doesn\'t support storing LOBs represented as streams using PDO_OCI'); } $table = new Table('blob_table'); @@ -57,7 +57,7 @@ public function testInsertProcessesStream() : void { // https://github.com/doctrine/dbal/issues/3290 if ($this->connection->getDriver() instanceof OCI8Driver) { - $this->markTestIncomplete('The oci8 driver does not support stream resources as parameters'); + self::markTestIncomplete('The oci8 driver does not support stream resources as parameters'); } $longBlob = str_repeat('x', 4 * 8192); // send 4 chunks @@ -113,7 +113,7 @@ public function testUpdateProcessesStream() : void { // https://github.com/doctrine/dbal/issues/3290 if ($this->connection->getDriver() instanceof OCI8Driver) { - $this->markTestIncomplete('The oci8 driver does not support stream resources as parameters'); + self::markTestIncomplete('The oci8 driver does not support stream resources as parameters'); } $this->connection->insert('blob_table', [ @@ -140,7 +140,7 @@ public function testUpdateProcessesStream() : void public function testBindParamProcessesStream() : void { if ($this->connection->getDriver() instanceof OCI8Driver) { - $this->markTestIncomplete('The oci8 driver does not support stream resources as parameters'); + self::markTestIncomplete('The oci8 driver does not support stream resources as parameters'); } $stmt = $this->connection->prepare("INSERT INTO blob_table(id, clobfield, blobfield) VALUES (1, 'ignored', ?)"); diff --git a/tests/Functional/ConnectionTest.php b/tests/Functional/ConnectionTest.php index da50c11c65a..174dd02b89c 100644 --- a/tests/Functional/ConnectionTest.php +++ b/tests/Functional/ConnectionTest.php @@ -74,7 +74,7 @@ public function testTransactionNestingBehavior() : void self::assertTrue($this->connection->isRollbackOnly()); $this->connection->commit(); // should throw exception - $this->fail('Transaction commit after failed nested transaction should fail.'); + self::fail('Transaction commit after failed nested transaction should fail.'); } catch (ConnectionException $e) { self::assertEquals(1, $this->connection->getTransactionNestingLevel()); $this->connection->rollBack(); @@ -119,7 +119,7 @@ public function testTransactionNestingLevelIsResetOnReconnect() : void public function testTransactionNestingBehaviorWithSavepoints() : void { if (! $this->connection->getDatabasePlatform()->supportsSavepoints()) { - $this->markTestSkipped('This test requires the platform to support savepoints.'); + self::markTestSkipped('This test requires the platform to support savepoints.'); } $this->connection->setNestTransactionsWithSavepoints(true); @@ -144,21 +144,20 @@ public function testTransactionNestingBehaviorWithSavepoints() : void self::assertFalse($this->connection->isRollbackOnly()); try { $this->connection->setNestTransactionsWithSavepoints(false); - $this->fail('Should not be able to disable savepoints in usage for nested transactions inside an open transaction.'); + self::fail('Should not be able to disable savepoints in usage for nested transactions inside an open transaction.'); } catch (ConnectionException $e) { self::assertTrue($this->connection->getNestTransactionsWithSavepoints()); } $this->connection->commit(); // should not throw exception } catch (ConnectionException $e) { - $this->fail('Transaction commit after failed nested transaction should not fail when using savepoints.'); - $this->connection->rollBack(); + self::fail('Transaction commit after failed nested transaction should not fail when using savepoints.'); } } public function testTransactionNestingBehaviorCantBeChangedInActiveTransaction() : void { if (! $this->connection->getDatabasePlatform()->supportsSavepoints()) { - $this->markTestSkipped('This test requires the platform to support savepoints.'); + self::markTestSkipped('This test requires the platform to support savepoints.'); } $this->connection->beginTransaction(); @@ -169,7 +168,7 @@ public function testTransactionNestingBehaviorCantBeChangedInActiveTransaction() public function testSetNestedTransactionsThroughSavepointsNotSupportedThrowsException() : void { if ($this->connection->getDatabasePlatform()->supportsSavepoints()) { - $this->markTestSkipped('This test requires the platform not to support savepoints.'); + self::markTestSkipped('This test requires the platform not to support savepoints.'); } $this->expectException(ConnectionException::class); @@ -181,7 +180,7 @@ public function testSetNestedTransactionsThroughSavepointsNotSupportedThrowsExce public function testCreateSavepointsNotSupportedThrowsException() : void { if ($this->connection->getDatabasePlatform()->supportsSavepoints()) { - $this->markTestSkipped('This test requires the platform not to support savepoints.'); + self::markTestSkipped('This test requires the platform not to support savepoints.'); } $this->expectException(ConnectionException::class); @@ -193,7 +192,7 @@ public function testCreateSavepointsNotSupportedThrowsException() : void public function testReleaseSavepointsNotSupportedThrowsException() : void { if ($this->connection->getDatabasePlatform()->supportsSavepoints()) { - $this->markTestSkipped('This test requires the platform not to support savepoints.'); + self::markTestSkipped('This test requires the platform not to support savepoints.'); } $this->expectException(ConnectionException::class); @@ -205,7 +204,7 @@ public function testReleaseSavepointsNotSupportedThrowsException() : void public function testRollbackSavepointsNotSupportedThrowsException() : void { if ($this->connection->getDatabasePlatform()->supportsSavepoints()) { - $this->markTestSkipped('This test requires the platform not to support savepoints.'); + self::markTestSkipped('This test requires the platform not to support savepoints.'); } $this->expectException(ConnectionException::class); @@ -252,7 +251,7 @@ public function testTransactionalWithException() : void $conn->executeQuery($conn->getDatabasePlatform()->getDummySelectSQL()); throw new RuntimeException('Ooops!'); }); - $this->fail('Expected exception'); + self::fail('Expected exception'); } catch (RuntimeException $expected) { self::assertEquals(0, $this->connection->getTransactionNestingLevel()); } @@ -266,7 +265,7 @@ public function testTransactionalWithThrowable() : void $conn->executeQuery($conn->getDatabasePlatform()->getDummySelectSQL()); throw new Error('Ooops!'); }); - $this->fail('Expected exception'); + self::fail('Expected exception'); } catch (Error $expected) { self::assertEquals(0, $this->connection->getTransactionNestingLevel()); } @@ -314,7 +313,7 @@ public function testPingDoesTriggersConnect() : void public function testConnectWithoutExplicitDatabaseName() : void { if (in_array($this->connection->getDatabasePlatform()->getName(), ['oracle', 'db2'], true)) { - $this->markTestSkipped('Platform does not support connecting without database name.'); + self::markTestSkipped('Platform does not support connecting without database name.'); } $params = $this->connection->getParams(); @@ -337,7 +336,7 @@ public function testConnectWithoutExplicitDatabaseName() : void public function testDeterminesDatabasePlatformWhenConnectingToNonExistentDatabase() : void { if (in_array($this->connection->getDatabasePlatform()->getName(), ['oracle', 'db2'], true)) { - $this->markTestSkipped('Platform does not support connecting without database name.'); + self::markTestSkipped('Platform does not support connecting without database name.'); } $params = $this->connection->getParams(); diff --git a/tests/Functional/DataAccessTest.php b/tests/Functional/DataAccessTest.php index 3dde425e849..aa318020b92 100644 --- a/tests/Functional/DataAccessTest.php +++ b/tests/Functional/DataAccessTest.php @@ -248,7 +248,7 @@ public function testFetchAllWithMissingTypes() : void { if ($this->connection->getDriver() instanceof MySQLiDriver || $this->connection->getDriver() instanceof SQLSrvDriver) { - $this->markTestSkipped('mysqli and sqlsrv actually supports this'); + self::markTestSkipped('mysqli and sqlsrv actually supports this'); } $datetimeString = '2010-01-01 10:10:10'; @@ -319,7 +319,7 @@ public function testFetchAssocWithMissingTypes() : void { if ($this->connection->getDriver() instanceof MySQLiDriver || $this->connection->getDriver() instanceof SQLSrvDriver) { - $this->markTestSkipped('mysqli and sqlsrv actually supports this'); + self::markTestSkipped('mysqli and sqlsrv actually supports this'); } $datetimeString = '2010-01-01 10:10:10'; @@ -364,7 +364,7 @@ public function testFetchArrayWithMissingTypes() : void { if ($this->connection->getDriver() instanceof MySQLiDriver || $this->connection->getDriver() instanceof SQLSrvDriver) { - $this->markTestSkipped('mysqli and sqlsrv actually supports this'); + self::markTestSkipped('mysqli and sqlsrv actually supports this'); } $datetimeString = '2010-01-01 10:10:10'; @@ -411,7 +411,7 @@ public function testFetchColumnWithMissingTypes() : void { if ($this->connection->getDriver() instanceof MySQLiDriver || $this->connection->getDriver() instanceof SQLSrvDriver) { - $this->markTestSkipped('mysqli and sqlsrv actually supports this'); + self::markTestSkipped('mysqli and sqlsrv actually supports this'); } $datetimeString = '2010-01-01 10:10:10'; @@ -620,7 +620,7 @@ public function testSqliteDateArithmeticWithDynamicInterval() : void $platform = $this->connection->getDatabasePlatform(); if (! $platform instanceof SqlitePlatform) { - $this->markTestSkipped('test is for sqlite only'); + self::markTestSkipped('test is for sqlite only'); } $table = new Table('fetch_table_date_math'); @@ -639,7 +639,7 @@ public function testSqliteDateArithmeticWithDynamicInterval() : void $rowCount = $this->connection->fetchColumn($sql, [], 0); - $this->assertEquals(1, $rowCount); + self::assertEquals(1, $rowCount); } public function testLocateExpression() : void @@ -942,11 +942,11 @@ private function beforeFetchClassTest() : void $driver = $this->connection->getDriver(); if ($driver instanceof Oci8Driver) { - $this->markTestSkipped('Not supported by OCI8'); + self::markTestSkipped('Not supported by OCI8'); } if ($driver instanceof MySQLiDriver) { - $this->markTestSkipped('Mysqli driver dont support this feature.'); + self::markTestSkipped('Mysqli driver dont support this feature.'); } if (! $driver instanceof PDOOracleDriver) { diff --git a/tests/Functional/Driver/IBMDB2/DB2DriverTest.php b/tests/Functional/Driver/IBMDB2/DB2DriverTest.php index 61e949e306c..2c1a99cbfb6 100644 --- a/tests/Functional/Driver/IBMDB2/DB2DriverTest.php +++ b/tests/Functional/Driver/IBMDB2/DB2DriverTest.php @@ -12,7 +12,7 @@ class DB2DriverTest extends AbstractDriverTest protected function setUp() : void { if (! extension_loaded('ibm_db2')) { - $this->markTestSkipped('ibm_db2 is not installed.'); + self::markTestSkipped('ibm_db2 is not installed.'); } parent::setUp(); @@ -21,7 +21,7 @@ protected function setUp() : void return; } - $this->markTestSkipped('ibm_db2 only test.'); + self::markTestSkipped('ibm_db2 only test.'); } /** @@ -29,7 +29,7 @@ protected function setUp() : void */ public function testConnectsWithoutDatabaseNameParameter() : void { - $this->markTestSkipped('IBM DB2 does not support connecting without database name.'); + self::markTestSkipped('IBM DB2 does not support connecting without database name.'); } /** @@ -37,7 +37,7 @@ public function testConnectsWithoutDatabaseNameParameter() : void */ public function testReturnsDatabaseNameWithoutDatabaseNameParameter() : void { - $this->markTestSkipped('IBM DB2 does not support connecting without database name.'); + self::markTestSkipped('IBM DB2 does not support connecting without database name.'); } /** diff --git a/tests/Functional/Driver/IBMDB2/DB2StatementTest.php b/tests/Functional/Driver/IBMDB2/DB2StatementTest.php index 8807289e874..3815739d5fc 100644 --- a/tests/Functional/Driver/IBMDB2/DB2StatementTest.php +++ b/tests/Functional/Driver/IBMDB2/DB2StatementTest.php @@ -13,7 +13,7 @@ class DB2StatementTest extends FunctionalTestCase protected function setUp() : void { if (! extension_loaded('ibm_db2')) { - $this->markTestSkipped('ibm_db2 is not installed.'); + self::markTestSkipped('ibm_db2 is not installed.'); } parent::setUp(); @@ -22,7 +22,7 @@ protected function setUp() : void return; } - $this->markTestSkipped('ibm_db2 only test.'); + self::markTestSkipped('ibm_db2 only test.'); } public function testExecutionErrorsAreNotSuppressed() : void diff --git a/tests/Functional/Driver/Mysqli/ConnectionTest.php b/tests/Functional/Driver/Mysqli/ConnectionTest.php index 9b68a38aa7e..a22cde176bb 100644 --- a/tests/Functional/Driver/Mysqli/ConnectionTest.php +++ b/tests/Functional/Driver/Mysqli/ConnectionTest.php @@ -14,7 +14,7 @@ class ConnectionTest extends FunctionalTestCase protected function setUp() : void { if (! extension_loaded('mysqli')) { - $this->markTestSkipped('mysqli is not installed.'); + self::markTestSkipped('mysqli is not installed.'); } parent::setUp(); @@ -23,7 +23,7 @@ protected function setUp() : void return; } - $this->markTestSkipped('MySQLi only test.'); + self::markTestSkipped('MySQLi only test.'); } protected function tearDown() : void diff --git a/tests/Functional/Driver/Mysqli/DriverTest.php b/tests/Functional/Driver/Mysqli/DriverTest.php index 823c3dceedb..7332beef98b 100644 --- a/tests/Functional/Driver/Mysqli/DriverTest.php +++ b/tests/Functional/Driver/Mysqli/DriverTest.php @@ -12,7 +12,7 @@ class DriverTest extends AbstractDriverTest protected function setUp() : void { if (! extension_loaded('mysqli')) { - $this->markTestSkipped('mysqli is not installed.'); + self::markTestSkipped('mysqli is not installed.'); } parent::setUp(); @@ -21,7 +21,7 @@ protected function setUp() : void return; } - $this->markTestSkipped('MySQLi only test.'); + self::markTestSkipped('MySQLi only test.'); } /** diff --git a/tests/Functional/Driver/OCI8/DriverTest.php b/tests/Functional/Driver/OCI8/DriverTest.php index 7ac6e69bc78..11efae0719c 100644 --- a/tests/Functional/Driver/OCI8/DriverTest.php +++ b/tests/Functional/Driver/OCI8/DriverTest.php @@ -12,7 +12,7 @@ class DriverTest extends AbstractDriverTest protected function setUp() : void { if (! extension_loaded('oci8')) { - $this->markTestSkipped('oci8 is not installed.'); + self::markTestSkipped('oci8 is not installed.'); } parent::setUp(); @@ -21,7 +21,7 @@ protected function setUp() : void return; } - $this->markTestSkipped('oci8 only test.'); + self::markTestSkipped('oci8 only test.'); } /** @@ -29,7 +29,7 @@ protected function setUp() : void */ public function testConnectsWithoutDatabaseNameParameter() : void { - $this->markTestSkipped('Oracle does not support connecting without database name.'); + self::markTestSkipped('Oracle does not support connecting without database name.'); } /** @@ -37,7 +37,7 @@ public function testConnectsWithoutDatabaseNameParameter() : void */ public function testReturnsDatabaseNameWithoutDatabaseNameParameter() : void { - $this->markTestSkipped('Oracle does not support connecting without database name.'); + self::markTestSkipped('Oracle does not support connecting without database name.'); } /** diff --git a/tests/Functional/Driver/OCI8/OCI8ConnectionTest.php b/tests/Functional/Driver/OCI8/OCI8ConnectionTest.php index 56c0d41cbb5..16228a1318f 100644 --- a/tests/Functional/Driver/OCI8/OCI8ConnectionTest.php +++ b/tests/Functional/Driver/OCI8/OCI8ConnectionTest.php @@ -16,13 +16,13 @@ class OCI8ConnectionTest extends FunctionalTestCase protected function setUp() : void { if (! extension_loaded('oci8')) { - $this->markTestSkipped('oci8 is not installed.'); + self::markTestSkipped('oci8 is not installed.'); } parent::setUp(); if (! $this->connection->getDriver() instanceof Driver) { - $this->markTestSkipped('oci8 only test.'); + self::markTestSkipped('oci8 only test.'); } $this->driverConnection = $this->connection->getWrappedConnection(); diff --git a/tests/Functional/Driver/OCI8/StatementTest.php b/tests/Functional/Driver/OCI8/StatementTest.php index bb7d04f0382..fe49ce541bf 100644 --- a/tests/Functional/Driver/OCI8/StatementTest.php +++ b/tests/Functional/Driver/OCI8/StatementTest.php @@ -11,7 +11,7 @@ class StatementTest extends FunctionalTestCase protected function setUp() : void { if (! extension_loaded('oci8')) { - $this->markTestSkipped('oci8 is not installed.'); + self::markTestSkipped('oci8 is not installed.'); } parent::setUp(); @@ -20,7 +20,7 @@ protected function setUp() : void return; } - $this->markTestSkipped('oci8 only test.'); + self::markTestSkipped('oci8 only test.'); } /** diff --git a/tests/Functional/Driver/PDOConnectionTest.php b/tests/Functional/Driver/PDOConnectionTest.php index 276cbe10d02..9078535e440 100644 --- a/tests/Functional/Driver/PDOConnectionTest.php +++ b/tests/Functional/Driver/PDOConnectionTest.php @@ -34,7 +34,7 @@ protected function setUp() : void return; } - $this->markTestSkipped('PDO connection only test.'); + self::markTestSkipped('PDO connection only test.'); } protected function tearDown() : void @@ -71,7 +71,7 @@ public function testThrowsWrappedExceptionOnPrepare() : void $driver = $this->connection->getDriver(); if ($driver instanceof PDOSQLSRVDriver) { - $this->markTestSkipped('pdo_sqlsrv does not allow setting PDO::ATTR_EMULATE_PREPARES at connection level.'); + self::markTestSkipped('pdo_sqlsrv does not allow setting PDO::ATTR_EMULATE_PREPARES at connection level.'); } // Some PDO adapters do not check the query server-side diff --git a/tests/Functional/Driver/PDOMySql/DriverTest.php b/tests/Functional/Driver/PDOMySql/DriverTest.php index 35aa1c7d596..d0d458deba3 100644 --- a/tests/Functional/Driver/PDOMySql/DriverTest.php +++ b/tests/Functional/Driver/PDOMySql/DriverTest.php @@ -12,7 +12,7 @@ class DriverTest extends AbstractDriverTest protected function setUp() : void { if (! extension_loaded('pdo_mysql')) { - $this->markTestSkipped('pdo_mysql is not installed.'); + self::markTestSkipped('pdo_mysql is not installed.'); } parent::setUp(); @@ -21,7 +21,7 @@ protected function setUp() : void return; } - $this->markTestSkipped('pdo_mysql only test.'); + self::markTestSkipped('pdo_mysql only test.'); } /** diff --git a/tests/Functional/Driver/PDOOracle/DriverTest.php b/tests/Functional/Driver/PDOOracle/DriverTest.php index 97baf7c00da..90090133a9b 100644 --- a/tests/Functional/Driver/PDOOracle/DriverTest.php +++ b/tests/Functional/Driver/PDOOracle/DriverTest.php @@ -12,7 +12,7 @@ class DriverTest extends AbstractDriverTest protected function setUp() : void { if (! extension_loaded('PDO_OCI')) { - $this->markTestSkipped('PDO_OCI is not installed.'); + self::markTestSkipped('PDO_OCI is not installed.'); } parent::setUp(); @@ -21,7 +21,7 @@ protected function setUp() : void return; } - $this->markTestSkipped('PDO_OCI only test.'); + self::markTestSkipped('PDO_OCI only test.'); } /** @@ -29,7 +29,7 @@ protected function setUp() : void */ public function testConnectsWithoutDatabaseNameParameter() : void { - $this->markTestSkipped('Oracle does not support connecting without database name.'); + self::markTestSkipped('Oracle does not support connecting without database name.'); } /** @@ -37,7 +37,7 @@ public function testConnectsWithoutDatabaseNameParameter() : void */ public function testReturnsDatabaseNameWithoutDatabaseNameParameter() : void { - $this->markTestSkipped('Oracle does not support connecting without database name.'); + self::markTestSkipped('Oracle does not support connecting without database name.'); } /** diff --git a/tests/Functional/Driver/PDOPgSql/DriverTest.php b/tests/Functional/Driver/PDOPgSql/DriverTest.php index 6ff1ab949ef..affbb2aa690 100644 --- a/tests/Functional/Driver/PDOPgSql/DriverTest.php +++ b/tests/Functional/Driver/PDOPgSql/DriverTest.php @@ -17,7 +17,7 @@ class DriverTest extends AbstractDriverTest protected function setUp() : void { if (! extension_loaded('pdo_pgsql')) { - $this->markTestSkipped('pdo_pgsql is not installed.'); + self::markTestSkipped('pdo_pgsql is not installed.'); } parent::setUp(); @@ -26,7 +26,7 @@ protected function setUp() : void return; } - $this->markTestSkipped('pdo_pgsql only test.'); + self::markTestSkipped('pdo_pgsql only test.'); } /** @@ -98,7 +98,7 @@ public function testConnectsWithApplicationNameParameter() : void } } - $this->fail(sprintf('Query result does not contain a record where column "query" equals "%s".', $sql)); + self::fail(sprintf('Query result does not contain a record where column "query" equals "%s".', $sql)); } /** diff --git a/tests/Functional/Driver/PDOPgsqlConnectionTest.php b/tests/Functional/Driver/PDOPgsqlConnectionTest.php index fe4cabc3d7a..2621827bd61 100644 --- a/tests/Functional/Driver/PDOPgsqlConnectionTest.php +++ b/tests/Functional/Driver/PDOPgsqlConnectionTest.php @@ -13,7 +13,7 @@ class PDOPgsqlConnectionTest extends FunctionalTestCase protected function setUp() : void { if (! extension_loaded('pdo_pgsql')) { - $this->markTestSkipped('pdo_pgsql is not loaded.'); + self::markTestSkipped('pdo_pgsql is not loaded.'); } parent::setUp(); @@ -22,7 +22,7 @@ protected function setUp() : void return; } - $this->markTestSkipped('PDOPgsql only test.'); + self::markTestSkipped('PDOPgsql only test.'); } /** diff --git a/tests/Functional/Driver/PDOSqlite/DriverTest.php b/tests/Functional/Driver/PDOSqlite/DriverTest.php index 511288d53ac..f137a551013 100644 --- a/tests/Functional/Driver/PDOSqlite/DriverTest.php +++ b/tests/Functional/Driver/PDOSqlite/DriverTest.php @@ -12,7 +12,7 @@ class DriverTest extends AbstractDriverTest protected function setUp() : void { if (! extension_loaded('pdo_sqlite')) { - $this->markTestSkipped('pdo_sqlite is not installed.'); + self::markTestSkipped('pdo_sqlite is not installed.'); } parent::setUp(); @@ -21,7 +21,7 @@ protected function setUp() : void return; } - $this->markTestSkipped('pdo_sqlite only test.'); + self::markTestSkipped('pdo_sqlite only test.'); } /** diff --git a/tests/Functional/Driver/PDOSqlsrv/DriverTest.php b/tests/Functional/Driver/PDOSqlsrv/DriverTest.php index 0c986faff35..1382a1a9eb2 100644 --- a/tests/Functional/Driver/PDOSqlsrv/DriverTest.php +++ b/tests/Functional/Driver/PDOSqlsrv/DriverTest.php @@ -16,7 +16,7 @@ class DriverTest extends AbstractDriverTest protected function setUp() : void { if (! extension_loaded('pdo_sqlsrv')) { - $this->markTestSkipped('pdo_sqlsrv is not installed.'); + self::markTestSkipped('pdo_sqlsrv is not installed.'); } parent::setUp(); @@ -25,7 +25,7 @@ protected function setUp() : void return; } - $this->markTestSkipped('pdo_sqlsrv only test.'); + self::markTestSkipped('pdo_sqlsrv only test.'); } /** diff --git a/tests/Functional/Driver/SQLAnywhere/ConnectionTest.php b/tests/Functional/Driver/SQLAnywhere/ConnectionTest.php index 0e567fec5e3..663591049f1 100644 --- a/tests/Functional/Driver/SQLAnywhere/ConnectionTest.php +++ b/tests/Functional/Driver/SQLAnywhere/ConnectionTest.php @@ -12,7 +12,7 @@ class ConnectionTest extends FunctionalTestCase protected function setUp() : void { if (! extension_loaded('sqlanywhere')) { - $this->markTestSkipped('sqlanywhere is not installed.'); + self::markTestSkipped('sqlanywhere is not installed.'); } parent::setUp(); @@ -21,7 +21,7 @@ protected function setUp() : void return; } - $this->markTestSkipped('sqlanywhere only test.'); + self::markTestSkipped('sqlanywhere only test.'); } public function testNonPersistentConnection() : void diff --git a/tests/Functional/Driver/SQLAnywhere/DriverTest.php b/tests/Functional/Driver/SQLAnywhere/DriverTest.php index f41f5b89799..014e4d9130b 100644 --- a/tests/Functional/Driver/SQLAnywhere/DriverTest.php +++ b/tests/Functional/Driver/SQLAnywhere/DriverTest.php @@ -13,7 +13,7 @@ class DriverTest extends AbstractDriverTest protected function setUp() : void { if (! extension_loaded('sqlanywhere')) { - $this->markTestSkipped('sqlanywhere is not installed.'); + self::markTestSkipped('sqlanywhere is not installed.'); } parent::setUp(); @@ -22,7 +22,7 @@ protected function setUp() : void return; } - $this->markTestSkipped('sqlanywhere only test.'); + self::markTestSkipped('sqlanywhere only test.'); } public function testReturnsDatabaseNameWithoutDatabaseNameParameter() : void diff --git a/tests/Functional/Driver/SQLAnywhere/StatementTest.php b/tests/Functional/Driver/SQLAnywhere/StatementTest.php index 82cc6125c57..72bdb42aca3 100644 --- a/tests/Functional/Driver/SQLAnywhere/StatementTest.php +++ b/tests/Functional/Driver/SQLAnywhere/StatementTest.php @@ -12,7 +12,7 @@ class StatementTest extends FunctionalTestCase protected function setUp() : void { if (! extension_loaded('sqlanywhere')) { - $this->markTestSkipped('sqlanywhere is not installed.'); + self::markTestSkipped('sqlanywhere is not installed.'); } parent::setUp(); @@ -21,7 +21,7 @@ protected function setUp() : void return; } - $this->markTestSkipped('sqlanywhere only test.'); + self::markTestSkipped('sqlanywhere only test.'); } public function testNonPersistentStatement() : void diff --git a/tests/Functional/Driver/SQLSrv/DriverTest.php b/tests/Functional/Driver/SQLSrv/DriverTest.php index 47da177fb54..cbcdf753beb 100644 --- a/tests/Functional/Driver/SQLSrv/DriverTest.php +++ b/tests/Functional/Driver/SQLSrv/DriverTest.php @@ -12,7 +12,7 @@ class DriverTest extends AbstractDriverTest protected function setUp() : void { if (! extension_loaded('sqlsrv')) { - $this->markTestSkipped('sqlsrv is not installed.'); + self::markTestSkipped('sqlsrv is not installed.'); } parent::setUp(); @@ -21,7 +21,7 @@ protected function setUp() : void return; } - $this->markTestSkipped('sqlsrv only test.'); + self::markTestSkipped('sqlsrv only test.'); } /** diff --git a/tests/Functional/ExceptionTest.php b/tests/Functional/ExceptionTest.php index 0e1a64db22a..18ee129c3a3 100644 --- a/tests/Functional/ExceptionTest.php +++ b/tests/Functional/ExceptionTest.php @@ -37,7 +37,7 @@ protected function setUp() : void return; } - $this->markTestSkipped('Driver does not support special exception handling.'); + self::markTestSkipped('Driver does not support special exception handling.'); } public function testPrimaryConstraintViolationException() : void @@ -296,7 +296,7 @@ public function testSyntaxErrorException() : void public function testConnectionExceptionSqLite() : void { if (! ($this->connection->getDatabasePlatform() instanceof SqlitePlatform)) { - $this->markTestSkipped('Only fails this way on sqlite'); + self::markTestSkipped('Only fails this way on sqlite'); } // mode 0 is considered read-only on Windows @@ -353,11 +353,11 @@ public function testConnectionException(array $params) : void $platform = $this->connection->getDatabasePlatform(); if ($platform instanceof SqlitePlatform) { - $this->markTestSkipped('Only skipped if platform is not sqlite'); + self::markTestSkipped('Only skipped if platform is not sqlite'); } if ($platform instanceof PostgreSQL94Platform && isset($params['password'])) { - $this->markTestSkipped('Does not work on Travis'); + self::markTestSkipped('Does not work on Travis'); } if ($platform instanceof MySqlPlatform && isset($params['user'])) { @@ -365,7 +365,7 @@ public function testConnectionException(array $params) : void assert($wrappedConnection instanceof ServerInfoAwareConnection); if (version_compare($wrappedConnection->getServerVersion(), '8', '>=')) { - $this->markTestIncomplete('PHP currently does not completely support MySQL 8'); + self::markTestIncomplete('PHP currently does not completely support MySQL 8'); } } diff --git a/tests/Functional/LikeWildcardsEscapingTest.php b/tests/Functional/LikeWildcardsEscapingTest.php index e3072b6d95e..9aad98b002d 100644 --- a/tests/Functional/LikeWildcardsEscapingTest.php +++ b/tests/Functional/LikeWildcardsEscapingTest.php @@ -23,6 +23,6 @@ public function testFetchLikeExpressionResult() : void ) ); $stmt->execute(); - $this->assertTrue((bool) $stmt->fetchColumn()); + self::assertTrue((bool) $stmt->fetchColumn()); } } diff --git a/tests/Functional/LoggingTest.php b/tests/Functional/LoggingTest.php index c20ddfde6c3..160d5156bcb 100644 --- a/tests/Functional/LoggingTest.php +++ b/tests/Functional/LoggingTest.php @@ -12,10 +12,10 @@ public function testLogExecuteQuery() : void $sql = $this->connection->getDatabasePlatform()->getDummySelectSQL(); $logMock = $this->createMock(SQLLogger::class); - $logMock->expects($this->at(0)) + $logMock->expects(self::at(0)) ->method('startQuery') - ->with($this->equalTo($sql), $this->equalTo([]), $this->equalTo([])); - $logMock->expects($this->at(1)) + ->with(self::equalTo($sql), self::equalTo([]), self::equalTo([])); + $logMock->expects(self::at(1)) ->method('stopQuery'); $this->connection->getConfiguration()->setSQLLogger($logMock); $this->connection->executeQuery($sql, []); @@ -28,10 +28,10 @@ public function testLogExecuteUpdate() : void $sql = $this->connection->getDatabasePlatform()->getDummySelectSQL(); $logMock = $this->createMock(SQLLogger::class); - $logMock->expects($this->at(0)) + $logMock->expects(self::at(0)) ->method('startQuery') - ->with($this->equalTo($sql), $this->equalTo([]), $this->equalTo([])); - $logMock->expects($this->at(1)) + ->with(self::equalTo($sql), self::equalTo([]), self::equalTo([])); + $logMock->expects(self::at(1)) ->method('stopQuery'); $this->connection->getConfiguration()->setSQLLogger($logMock); $this->connection->executeUpdate($sql, []); @@ -42,10 +42,10 @@ public function testLogPrepareExecute() : void $sql = $this->connection->getDatabasePlatform()->getDummySelectSQL(); $logMock = $this->createMock(SQLLogger::class); - $logMock->expects($this->once()) + $logMock->expects(self::once()) ->method('startQuery') - ->with($this->equalTo($sql), $this->equalTo([])); - $logMock->expects($this->at(1)) + ->with(self::equalTo($sql), self::equalTo([])); + $logMock->expects(self::at(1)) ->method('stopQuery'); $this->connection->getConfiguration()->setSQLLogger($logMock); diff --git a/tests/Functional/MasterSlaveConnectionTest.php b/tests/Functional/MasterSlaveConnectionTest.php index 1cba89d2185..01d7b369884 100644 --- a/tests/Functional/MasterSlaveConnectionTest.php +++ b/tests/Functional/MasterSlaveConnectionTest.php @@ -28,7 +28,7 @@ protected function setUp() : void // This is a MySQL specific test, skip other vendors. if ($platformName !== 'mysql') { - $this->markTestSkipped(sprintf('Test does not work on %s.', $platformName)); + self::markTestSkipped(sprintf('Test does not work on %s.', $platformName)); } try { diff --git a/tests/Functional/NamedParametersTest.php b/tests/Functional/NamedParametersTest.php index f082f0fe749..b88bd16a786 100644 --- a/tests/Functional/NamedParametersTest.php +++ b/tests/Functional/NamedParametersTest.php @@ -199,7 +199,7 @@ protected function setUp() : void 'bar' => 2, ]); } catch (Throwable $e) { - $this->fail($e->getMessage()); + self::fail($e->getMessage()); } } diff --git a/tests/Functional/Platform/NewPrimaryKeyWithNewAutoIncrementColumnTest.php b/tests/Functional/Platform/NewPrimaryKeyWithNewAutoIncrementColumnTest.php index 793d35831f8..1825b183de2 100644 --- a/tests/Functional/Platform/NewPrimaryKeyWithNewAutoIncrementColumnTest.php +++ b/tests/Functional/Platform/NewPrimaryKeyWithNewAutoIncrementColumnTest.php @@ -20,7 +20,7 @@ protected function setUp() : void return; } - $this->markTestSkipped('Restricted to MySQL.'); + self::markTestSkipped('Restricted to MySQL.'); } /** @@ -57,10 +57,10 @@ public function testAlterPrimaryKeyToAutoIncrementColumn() : void $validationSchema = $schemaManager->createSchema(); $validationTable = $validationSchema->getTable($table->getName()); - $this->assertTrue($validationTable->hasColumn('new_id')); - $this->assertTrue($validationTable->getColumn('new_id')->getAutoincrement()); - $this->assertTrue($validationTable->hasPrimaryKey()); - $this->assertSame(['new_id'], $validationTable->getPrimaryKeyColumns()); + self::assertTrue($validationTable->hasColumn('new_id')); + self::assertTrue($validationTable->getColumn('new_id')->getAutoincrement()); + self::assertTrue($validationTable->hasPrimaryKey()); + self::assertSame(['new_id'], $validationTable->getPrimaryKeyColumns()); } private function getPlatform() : AbstractPlatform diff --git a/tests/Functional/Schema/MySqlSchemaManagerTest.php b/tests/Functional/Schema/MySqlSchemaManagerTest.php index 6705d3f13d8..84f42dda77c 100644 --- a/tests/Functional/Schema/MySqlSchemaManagerTest.php +++ b/tests/Functional/Schema/MySqlSchemaManagerTest.php @@ -178,7 +178,7 @@ public function testDropPrimaryKeyWithAutoincrementColumn() : void public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() : void { if ($this->schemaManager->getDatabasePlatform() instanceof MariaDb1027Platform) { - $this->markTestSkipped( + self::markTestSkipped( 'MariaDb102Platform supports default values for BLOB and TEXT columns and will propagate values' ); } @@ -489,7 +489,7 @@ public function testColumnDefaultsAreValid() : void public function testColumnDefaultValuesCurrentTimeAndDate() : void { if (! $this->schemaManager->getDatabasePlatform() instanceof MariaDb1027Platform) { - $this->markTestSkipped('Only relevant for MariaDb102Platform.'); + self::markTestSkipped('Only relevant for MariaDb102Platform.'); } $platform = $this->schemaManager->getDatabasePlatform(); diff --git a/tests/Functional/Schema/PostgreSqlSchemaManagerTest.php b/tests/Functional/Schema/PostgreSqlSchemaManagerTest.php index db3577529d1..c7177397cbe 100644 --- a/tests/Functional/Schema/PostgreSqlSchemaManagerTest.php +++ b/tests/Functional/Schema/PostgreSqlSchemaManagerTest.php @@ -224,7 +224,7 @@ public function testFilterSchemaExpression() : void public function testListForeignKeys() : void { if (! $this->connection->getDatabasePlatform()->supportsForeignKeyConstraints()) { - $this->markTestSkipped('Does not support foreign key constraints.'); + self::markTestSkipped('Does not support foreign key constraints.'); } $fkOptions = ['SET NULL', 'SET DEFAULT', 'NO ACTION','CASCADE', 'RESTRICT']; diff --git a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php index 9bb9663f358..5f61977bebc 100644 --- a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -68,7 +68,7 @@ protected function setUp() : void $dbms = $this->getPlatformName(); if ($this->connection->getDatabasePlatform()->getName() !== $dbms) { - $this->markTestSkipped(static::class . ' requires the use of ' . $dbms); + self::markTestSkipped(static::class . ' requires the use of ' . $dbms); } $this->schemaManager = $this->connection->getSchemaManager(); @@ -95,7 +95,7 @@ protected function tearDown() : void public function testDropsDatabaseWithActiveConnections() : void { if (! $this->schemaManager->getDatabasePlatform()->supportsCreateDropDatabase()) { - $this->markTestSkipped('Cannot drop Database client side with this Driver.'); + self::markTestSkipped('Cannot drop Database client side with this Driver.'); } $this->schemaManager->dropAndCreateDatabase('test_drop_database'); @@ -134,7 +134,7 @@ public function testDropAndCreateSequence() : void $platform = $this->connection->getDatabasePlatform(); if (! $platform->supportsSequences()) { - $this->markTestSkipped( + self::markTestSkipped( sprintf('The "%s" platform does not support sequences.', $platform->getName()) ); } @@ -166,7 +166,7 @@ public function testListSequences() : void $platform = $this->connection->getDatabasePlatform(); if (! $platform->supportsSequences()) { - $this->markTestSkipped( + self::markTestSkipped( sprintf('The "%s" platform does not support sequences.', $platform->getName()) ); } @@ -196,7 +196,7 @@ public function testListSequences() : void public function testListDatabases() : void { if (! $this->schemaManager->getDatabasePlatform()->supportsCreateDropDatabase()) { - $this->markTestSkipped('Cannot drop Database client side with this Driver.'); + self::markTestSkipped('Cannot drop Database client side with this Driver.'); } $this->schemaManager->dropAndCreateDatabase('test_create_database'); @@ -213,7 +213,7 @@ public function testListDatabases() : void public function testListNamespaceNames() : void { if (! $this->schemaManager->getDatabasePlatform()->supportsSchemas()) { - $this->markTestSkipped('Platform does not support schemas.'); + self::markTestSkipped('Platform does not support schemas.'); } // Currently dropping schemas is not supported, so we have to workaround here. @@ -372,7 +372,7 @@ public function testListTableColumnsDispatchEvent() : void ->getMock(); $listenerMock - ->expects($this->exactly(7)) + ->expects(self::exactly(7)) ->method('onSchemaColumnDefinition'); $oldEventManager = $this->schemaManager->getDatabasePlatform()->getEventManager(); @@ -399,7 +399,7 @@ public function testListTableIndexesDispatchEvent() : void ->addMethods(['onSchemaIndexDefinition']) ->getMock(); $listenerMock - ->expects($this->exactly(3)) + ->expects(self::exactly(3)) ->method('onSchemaIndexDefinition'); $oldEventManager = $this->schemaManager->getDatabasePlatform()->getEventManager(); @@ -417,7 +417,7 @@ public function testListTableIndexesDispatchEvent() : void public function testDiffListTableColumns() : void { if ($this->schemaManager->getDatabasePlatform()->getName() === 'oracle') { - $this->markTestSkipped('Does not work with Oracle, since it cannot detect DateTime, Date and Time differenecs (at the moment).'); + self::markTestSkipped('Does not work with Oracle, since it cannot detect DateTime, Date and Time differenecs (at the moment).'); } $offlineTable = $this->createListTableColumns(); @@ -477,7 +477,7 @@ public function testDropAndCreateIndex() : void public function testCreateTableWithForeignKeys() : void { if (! $this->schemaManager->getDatabasePlatform()->supportsForeignKeyConstraints()) { - $this->markTestSkipped('Platform does not support foreign keys.'); + self::markTestSkipped('Platform does not support foreign keys.'); } $tableB = $this->getTestTable('test_foreign'); @@ -505,7 +505,7 @@ public function testCreateTableWithForeignKeys() : void public function testListForeignKeys() : void { if (! $this->connection->getDatabasePlatform()->supportsForeignKeyConstraints()) { - $this->markTestSkipped('Does not support foreign key constraints.'); + self::markTestSkipped('Does not support foreign key constraints.'); } $this->createTestTable('test_create_fk1'); @@ -539,7 +539,7 @@ public function testListForeignKeys() : void protected function getCreateExampleViewSql() : void { - $this->markTestSkipped('No Create Example View SQL was defined for this SchemaManager'); + self::markTestSkipped('No Create Example View SQL was defined for this SchemaManager'); } public function testCreateSchema() : void @@ -553,7 +553,7 @@ public function testCreateSchema() : void public function testAlterTableScenario() : void { if (! $this->schemaManager->getDatabasePlatform()->supportsAlterTable()) { - $this->markTestSkipped('Alter Table is not supported by this platform.'); + self::markTestSkipped('Alter Table is not supported by this platform.'); } $alterTable = $this->createTestTable('alter_table'); @@ -642,7 +642,7 @@ public function testAlterTableScenario() : void public function testTableInNamespace() : void { if (! $this->schemaManager->getDatabasePlatform()->supportsSchemas()) { - $this->markTestSkipped('Schema definition is not supported by this platform.'); + self::markTestSkipped('Schema definition is not supported by this platform.'); } //create schema @@ -666,7 +666,7 @@ public function testTableInNamespace() : void public function testCreateAndListViews() : void { if (! $this->schemaManager->getDatabasePlatform()->supportsViews()) { - $this->markTestSkipped('Views is not supported by this platform.'); + self::markTestSkipped('Views is not supported by this platform.'); } $this->createTestTable('view_test_table'); @@ -684,7 +684,7 @@ public function testCreateAndListViews() : void public function testAutoincrementDetection() : void { if (! $this->schemaManager->getDatabasePlatform()->supportsIdentityColumns()) { - $this->markTestSkipped('This test is only supported on platforms that have autoincrement'); + self::markTestSkipped('This test is only supported on platforms that have autoincrement'); } $table = new Table('test_autoincrement'); @@ -705,7 +705,7 @@ public function testAutoincrementDetection() : void public function testAutoincrementDetectionMulticolumns() : void { if (! $this->schemaManager->getDatabasePlatform()->supportsIdentityColumns()) { - $this->markTestSkipped('This test is only supported on platforms that have autoincrement'); + self::markTestSkipped('This test is only supported on platforms that have autoincrement'); } $table = new Table('test_not_autoincrement'); @@ -727,7 +727,7 @@ public function testAutoincrementDetectionMulticolumns() : void public function testUpdateSchemaWithForeignKeyRenaming() : void { if (! $this->schemaManager->getDatabasePlatform()->supportsForeignKeyConstraints()) { - $this->markTestSkipped('This test is only supported on platforms that have foreign keys.'); + self::markTestSkipped('This test is only supported on platforms that have foreign keys.'); } $table = new Table('test_fk_base'); @@ -772,7 +772,7 @@ public function testUpdateSchemaWithForeignKeyRenaming() : void public function testRenameIndexUsedInForeignKeyConstraint() : void { if (! $this->schemaManager->getDatabasePlatform()->supportsForeignKeyConstraints()) { - $this->markTestSkipped('This test is only supported on platforms that have foreign keys.'); + self::markTestSkipped('This test is only supported on platforms that have foreign keys.'); } $primaryTable = new Table('test_rename_index_primary'); @@ -815,7 +815,7 @@ public function testGetColumnComment() : void if (! $this->connection->getDatabasePlatform()->supportsInlineColumnComments() && ! $this->connection->getDatabasePlatform()->supportsCommentOnStatement() && $this->connection->getDatabasePlatform()->getName() !== 'mssql') { - $this->markTestSkipped('Database does not support column comments.'); + self::markTestSkipped('Database does not support column comments.'); } $table = new Table('column_comment_test'); @@ -859,7 +859,7 @@ public function testAutomaticallyAppendCommentOnMarkedColumns() : void if (! $this->connection->getDatabasePlatform()->supportsInlineColumnComments() && ! $this->connection->getDatabasePlatform()->supportsCommentOnStatement() && $this->connection->getDatabasePlatform()->getName() !== 'mssql') { - $this->markTestSkipped('Database does not support column comments.'); + self::markTestSkipped('Database does not support column comments.'); } $table = new Table('column_comment_test2'); @@ -887,7 +887,7 @@ public function testCommentHintOnDateIntervalTypeColumn() : void if (! $this->connection->getDatabasePlatform()->supportsInlineColumnComments() && ! $this->connection->getDatabasePlatform()->supportsCommentOnStatement() && $this->connection->getDatabasePlatform()->getName() !== 'mssql') { - $this->markTestSkipped('Database does not support column comments.'); + self::markTestSkipped('Database does not support column comments.'); } $table = new Table('column_dateinterval_comment'); @@ -1024,7 +1024,7 @@ protected function assertHasTable(array $tables) : void public function testListForeignKeysComposite() : void { if (! $this->connection->getDatabasePlatform()->supportsForeignKeyConstraints()) { - $this->markTestSkipped('Does not support foreign key constraints.'); + self::markTestSkipped('Does not support foreign key constraints.'); } $this->schemaManager->createTable($this->getTestTable('test_create_fk3')); @@ -1126,7 +1126,7 @@ public function testListTableWithBinary() : void public function testListTableDetailsWithFullQualifiedTableName() : void { if (! $this->schemaManager->getDatabasePlatform()->supportsSchemas()) { - $this->markTestSkipped('Test only works on platforms that support schemas.'); + self::markTestSkipped('Test only works on platforms that support schemas.'); } $defaultSchemaName = $this->schemaManager->getDatabasePlatform()->getDefaultSchemaName(); @@ -1168,7 +1168,7 @@ public function testCommentStringsAreQuoted() : void if (! $this->connection->getDatabasePlatform()->supportsInlineColumnComments() && ! $this->connection->getDatabasePlatform()->supportsCommentOnStatement() && $this->connection->getDatabasePlatform()->getName() !== 'mssql') { - $this->markTestSkipped('Database does not support column comments.'); + self::markTestSkipped('Database does not support column comments.'); } $table = new Table('my_table'); @@ -1184,7 +1184,7 @@ public function testCommentStringsAreQuoted() : void public function testCommentNotDuplicated() : void { if (! $this->connection->getDatabasePlatform()->supportsInlineColumnComments()) { - $this->markTestSkipped('Database does not support column comments.'); + self::markTestSkipped('Database does not support column comments.'); } $options = [ @@ -1216,7 +1216,7 @@ public function testAlterColumnComment( if (! $this->connection->getDatabasePlatform()->supportsInlineColumnComments() && ! $this->connection->getDatabasePlatform()->supportsCommentOnStatement() && $this->connection->getDatabasePlatform()->getName() !== 'mssql') { - $this->markTestSkipped('Database does not support column comments.'); + self::markTestSkipped('Database does not support column comments.'); } $offlineTable = new Table('alter_column_comment_test'); @@ -1281,7 +1281,7 @@ public static function getAlterColumnComment() : iterable public function testDoesNotListIndexesImplicitlyCreatedByForeignKeys() : void { if (! $this->schemaManager->getDatabasePlatform()->supportsForeignKeyConstraints()) { - $this->markTestSkipped('This test is only supported on platforms that have foreign keys.'); + self::markTestSkipped('This test is only supported on platforms that have foreign keys.'); } $primaryTable = new Table('test_list_index_impl_primary'); @@ -1435,7 +1435,7 @@ public function testComparatorShouldReturnAllChangesWhenUsingLegacyJsonArrayType public function testComparatorShouldNotAddCommentToJsonTypeSinceItIsTheDefaultNow() : void { if (! $this->schemaManager->getDatabasePlatform()->hasNativeJsonType()) { - $this->markTestSkipped('This test is only supported on platforms that have native JSON type.'); + self::markTestSkipped('This test is only supported on platforms that have native JSON type.'); } $this->connection->executeQuery('CREATE TABLE json_test (parameters JSON NOT NULL)'); @@ -1571,7 +1571,7 @@ public function testPrimaryKeyAutoIncrement() : void $query->execute(); $lastUsedIdAfterDelete = (int) $query->fetchColumn(); - $this->assertGreaterThan($lastUsedIdBeforeDelete, $lastUsedIdAfterDelete); + self::assertGreaterThan($lastUsedIdBeforeDelete, $lastUsedIdAfterDelete); } public function testGenerateAnIndexWithPartialColumnLength() : void diff --git a/tests/Functional/Schema/SqliteSchemaManagerTest.php b/tests/Functional/Schema/SqliteSchemaManagerTest.php index 74a613f1dd5..8d81eff1637 100644 --- a/tests/Functional/Schema/SqliteSchemaManagerTest.php +++ b/tests/Functional/Schema/SqliteSchemaManagerTest.php @@ -162,12 +162,12 @@ public function testListTableWithBinary() : void public function testNonDefaultPKOrder() : void { if (! extension_loaded('sqlite3')) { - $this->markTestSkipped('This test requires the SQLite3 extension.'); + self::markTestSkipped('This test requires the SQLite3 extension.'); } $version = SQLite3::version(); if (version_compare($version['versionString'], '3.7.16', '<')) { - $this->markTestSkipped('This version of sqlite doesn\'t return the order of the Primary Key.'); + self::markTestSkipped('This version of sqlite doesn\'t return the order of the Primary Key.'); } $this->connection->exec(<<fetchColumn(); // with an empty table, non autoincrement rowid is always 1 - $this->assertEquals(1, $lastUsedIdAfterDelete); + self::assertEquals(1, $lastUsedIdAfterDelete); } } diff --git a/tests/Functional/StatementTest.php b/tests/Functional/StatementTest.php index effebb4e583..ad008b2c5b5 100644 --- a/tests/Functional/StatementTest.php +++ b/tests/Functional/StatementTest.php @@ -27,7 +27,7 @@ protected function setUp() : void public function testStatementIsReusableAfterClosingCursor() : void { if ($this->connection->getDriver() instanceof PDOOracleDriver) { - $this->markTestIncomplete('See https://bugs.php.net/bug.php?id=77181'); + self::markTestIncomplete('See https://bugs.php.net/bug.php?id=77181'); } $this->connection->insert('stmt_test', ['id' => 1]); @@ -52,7 +52,7 @@ public function testStatementIsReusableAfterClosingCursor() : void public function testReuseStatementWithLongerResults() : void { if ($this->connection->getDriver() instanceof PDOOracleDriver) { - $this->markTestIncomplete('PDO_OCI doesn\'t support fetching blobs via PDOStatement::fetchAll()'); + self::markTestIncomplete('PDO_OCI doesn\'t support fetching blobs via PDOStatement::fetchAll()'); } $sm = $this->connection->getSchemaManager(); @@ -91,7 +91,7 @@ public function testFetchLongBlob() : void if ($this->connection->getDriver() instanceof PDOOracleDriver) { // inserting BLOBs as streams on Oracle requires Oracle-specific SQL syntax which is currently not supported // see http://php.net/manual/en/pdo.lobs.php#example-1035 - $this->markTestSkipped('DBAL doesn\'t support storing LOBs represented as streams using PDO_OCI'); + self::markTestSkipped('DBAL doesn\'t support storing LOBs represented as streams using PDO_OCI'); } // make sure memory limit is large enough to not cause false positives, @@ -154,7 +154,7 @@ public function testIncompletelyFetchedStatementDoesNotBlockConnection() : void public function testReuseStatementAfterClosingCursor() : void { if ($this->connection->getDriver() instanceof PDOOracleDriver) { - $this->markTestIncomplete('See https://bugs.php.net/bug.php?id=77181'); + self::markTestIncomplete('See https://bugs.php.net/bug.php?id=77181'); } $this->connection->insert('stmt_test', ['id' => 1]); diff --git a/tests/Functional/TableGeneratorTest.php b/tests/Functional/TableGeneratorTest.php index c7ec0c2dd6e..5c72fee9dcf 100644 --- a/tests/Functional/TableGeneratorTest.php +++ b/tests/Functional/TableGeneratorTest.php @@ -22,7 +22,7 @@ protected function setUp() : void $platform = $this->connection->getDatabasePlatform(); if ($platform->getName() === 'sqlite') { - $this->markTestSkipped('TableGenerator does not work with SQLite'); + self::markTestSkipped('TableGenerator does not work with SQLite'); } try { diff --git a/tests/Functional/TemporaryTableTest.php b/tests/Functional/TemporaryTableTest.php index 38ed2b52554..3764cda0f3a 100644 --- a/tests/Functional/TemporaryTableTest.php +++ b/tests/Functional/TemporaryTableTest.php @@ -38,7 +38,7 @@ public function testDropTemporaryTableNotAutoCommitTransaction() : void { if ($this->connection->getDatabasePlatform()->getName() === 'sqlanywhere' || $this->connection->getDatabasePlatform()->getName() === 'oracle') { - $this->markTestSkipped('Test does not work on Oracle and SQL Anywhere.'); + self::markTestSkipped('Test does not work on Oracle and SQL Anywhere.'); } $platform = $this->connection->getDatabasePlatform(); @@ -73,7 +73,7 @@ public function testCreateTemporaryTableNotAutoCommitTransaction() : void { if ($this->connection->getDatabasePlatform()->getName() === 'sqlanywhere' || $this->connection->getDatabasePlatform()->getName() === 'oracle') { - $this->markTestSkipped('Test does not work on Oracle and SQL Anywhere.'); + self::markTestSkipped('Test does not work on Oracle and SQL Anywhere.'); } $platform = $this->connection->getDatabasePlatform(); diff --git a/tests/Functional/Ticket/DBAL168Test.php b/tests/Functional/Ticket/DBAL168Test.php index fcf80cfdb5e..d6eba032069 100644 --- a/tests/Functional/Ticket/DBAL168Test.php +++ b/tests/Functional/Ticket/DBAL168Test.php @@ -13,7 +13,7 @@ class DBAL168Test extends FunctionalTestCase public function testDomainsTable() : void { if ($this->connection->getDatabasePlatform()->getName() !== 'postgresql') { - $this->markTestSkipped('PostgreSQL only test'); + self::markTestSkipped('PostgreSQL only test'); } $table = new Table('domains'); diff --git a/tests/Functional/Ticket/DBAL202Test.php b/tests/Functional/Ticket/DBAL202Test.php index 8e30060d52f..60eaf29cacb 100644 --- a/tests/Functional/Ticket/DBAL202Test.php +++ b/tests/Functional/Ticket/DBAL202Test.php @@ -15,7 +15,7 @@ protected function setUp() : void parent::setUp(); if ($this->connection->getDatabasePlatform()->getName() !== 'oracle') { - $this->markTestSkipped('OCI8 only test'); + self::markTestSkipped('OCI8 only test'); } if ($this->connection->getSchemaManager()->tablesExist('DBAL202')) { diff --git a/tests/Functional/Ticket/DBAL461Test.php b/tests/Functional/Ticket/DBAL461Test.php index 1a9d018dd23..17e10a367de 100644 --- a/tests/Functional/Ticket/DBAL461Test.php +++ b/tests/Functional/Ticket/DBAL461Test.php @@ -36,6 +36,6 @@ public function testIssue() : void 'comment' => null, ]); - $this->assertInstanceOf(DecimalType::class, $column->getType()); + self::assertInstanceOf(DecimalType::class, $column->getType()); } } diff --git a/tests/Functional/Ticket/DBAL510Test.php b/tests/Functional/Ticket/DBAL510Test.php index 748e8a3bb96..d0d93156013 100644 --- a/tests/Functional/Ticket/DBAL510Test.php +++ b/tests/Functional/Ticket/DBAL510Test.php @@ -19,7 +19,7 @@ protected function setUp() : void return; } - $this->markTestSkipped('PostgreSQL Only test'); + self::markTestSkipped('PostgreSQL Only test'); } public function testSearchPathSchemaChanges() : void diff --git a/tests/Functional/Ticket/DBAL630Test.php b/tests/Functional/Ticket/DBAL630Test.php index 68c6bcf0e51..88a8614dc7d 100644 --- a/tests/Functional/Ticket/DBAL630Test.php +++ b/tests/Functional/Ticket/DBAL630Test.php @@ -23,7 +23,7 @@ protected function setUp() : void $platform = $this->connection->getDatabasePlatform()->getName(); if (! in_array($platform, ['postgresql'])) { - $this->markTestSkipped('Currently restricted to PostgreSQL'); + self::markTestSkipped('Currently restricted to PostgreSQL'); } try { diff --git a/tests/Functional/Ticket/DBAL752Test.php b/tests/Functional/Ticket/DBAL752Test.php index 9a518bfaf91..07858b94f49 100644 --- a/tests/Functional/Ticket/DBAL752Test.php +++ b/tests/Functional/Ticket/DBAL752Test.php @@ -20,7 +20,7 @@ protected function setUp() : void return; } - $this->markTestSkipped('Related to SQLite only'); + self::markTestSkipped('Related to SQLite only'); } public function testUnsignedIntegerDetection() : void diff --git a/tests/Functional/TransactionTest.php b/tests/Functional/TransactionTest.php index 5cce60fb881..0195aaa6fd9 100644 --- a/tests/Functional/TransactionTest.php +++ b/tests/Functional/TransactionTest.php @@ -30,10 +30,10 @@ public function testCommitFalse() : void { $this->connection->query('SET SESSION wait_timeout=1'); - $this->assertTrue($this->connection->beginTransaction()); + self::assertTrue($this->connection->beginTransaction()); sleep(2); // during the sleep mysql will close the connection - $this->assertFalse(@$this->connection->commit()); // we will ignore `MySQL server has gone away` warnings + self::assertFalse(@$this->connection->commit()); // we will ignore `MySQL server has gone away` warnings } } diff --git a/tests/Functional/TypeConversionTest.php b/tests/Functional/TypeConversionTest.php index b1d4084ac5b..84d48b34683 100644 --- a/tests/Functional/TypeConversionTest.php +++ b/tests/Functional/TypeConversionTest.php @@ -122,7 +122,7 @@ public function testIdempotentConversionToString(string $type, $originalValue) : if ($type === 'text' && $this->connection->getDriver() instanceof PDOOracleDriver) { // inserting BLOBs as streams on Oracle requires Oracle-specific SQL syntax which is currently not supported // see http://php.net/manual/en/pdo.lobs.php#example-1035 - $this->markTestSkipped('DBAL doesn\'t support storing LOBs represented as streams using PDO_OCI'); + self::markTestSkipped('DBAL doesn\'t support storing LOBs represented as streams using PDO_OCI'); } $dbValue = $this->processValue($type, $originalValue); diff --git a/tests/Functional/Types/BinaryTest.php b/tests/Functional/Types/BinaryTest.php index 5741112aaec..8491dff877e 100644 --- a/tests/Functional/Types/BinaryTest.php +++ b/tests/Functional/Types/BinaryTest.php @@ -21,7 +21,7 @@ protected function setUp() : void parent::setUp(); if ($this->connection->getDriver() instanceof PDOOracleDriver) { - $this->markTestSkipped('PDO_OCI doesn\'t support binding binary values'); + self::markTestSkipped('PDO_OCI doesn\'t support binding binary values'); } $table = new Table('binary_table'); @@ -53,8 +53,8 @@ public function testInsertAndSelect() : void $this->insert($id1, $value1); $this->insert($id2, $value2); - $this->assertSame($value1, $this->select($id1)); - $this->assertSame($value2, $this->select($id2)); + self::assertSame($value1, $this->select($id1)); + self::assertSame($value2, $this->select($id2)); } private function insert(string $id, string $value) : void diff --git a/tests/Functional/WriteTest.php b/tests/Functional/WriteTest.php index 233c67ec57c..1469e6ecec3 100644 --- a/tests/Functional/WriteTest.php +++ b/tests/Functional/WriteTest.php @@ -146,7 +146,7 @@ public function testUpdate() : void public function testLastInsertId() : void { if (! $this->connection->getDatabasePlatform()->prefersIdentityColumns()) { - $this->markTestSkipped('Test only works on platforms with identity columns.'); + self::markTestSkipped('Test only works on platforms with identity columns.'); } self::assertEquals(1, $this->connection->insert('write_table', ['test_int' => 2, 'test_string' => 'bar'])); @@ -159,7 +159,7 @@ public function testLastInsertId() : void public function testLastInsertIdSequence() : void { if (! $this->connection->getDatabasePlatform()->supportsSequences()) { - $this->markTestSkipped('Test only works on platforms with sequences.'); + self::markTestSkipped('Test only works on platforms with sequences.'); } $sequence = new Sequence('write_table_id_seq'); @@ -185,7 +185,7 @@ public function testLastInsertIdSequence() : void public function testLastInsertIdNoSequenceGiven() : void { if (! $this->connection->getDatabasePlatform()->supportsSequences() || $this->connection->getDatabasePlatform()->supportsIdentityColumns()) { - $this->markTestSkipped("Test only works consistently on platforms that support sequences and don't support identity columns."); + self::markTestSkipped("Test only works consistently on platforms that support sequences and don't support identity columns."); } self::assertFalse($this->lastInsertId()); @@ -260,7 +260,7 @@ public function testEmptyIdentityInsert() : void $platform = $this->connection->getDatabasePlatform(); if (! ($platform->supportsIdentityColumns() || $platform->usesSequenceEmulatedIdentityColumns())) { - $this->markTestSkipped( + self::markTestSkipped( 'Test only works on platforms with identity columns or sequence emulated identity columns.' ); } @@ -350,7 +350,7 @@ private function lastInsertId(?string $name = null) return $this->connection->lastInsertId($name); } catch (DriverException $e) { if ($e->getCode() === 'IM001') { - $this->markTestSkipped($e->getMessage()); + self::markTestSkipped($e->getMessage()); } throw $e; diff --git a/tests/Logging/LoggerChainTest.php b/tests/Logging/LoggerChainTest.php index 07af9f0fe12..567ae77d1f5 100644 --- a/tests/Logging/LoggerChainTest.php +++ b/tests/Logging/LoggerChainTest.php @@ -47,7 +47,7 @@ private function createChain(string $method, ...$args) : LoggerChain private function createLogger(string $method, ...$args) : SQLLogger { $logger = $this->createMock(SQLLogger::class); - $logger->expects($this->once()) + $logger->expects(self::once()) ->method($method) ->with(...$args); diff --git a/tests/Platforms/AbstractPlatformTestCase.php b/tests/Platforms/AbstractPlatformTestCase.php index 76228a2dd53..7984be7f011 100644 --- a/tests/Platforms/AbstractPlatformTestCase.php +++ b/tests/Platforms/AbstractPlatformTestCase.php @@ -39,7 +39,7 @@ protected function setUp() : void public function testQuoteIdentifier() : void { if ($this->platform->getName() === 'mssql') { - $this->markTestSkipped('Not working this way on mssql.'); + self::markTestSkipped('Not working this way on mssql.'); } $c = $this->platform->getIdentifierQuoteCharacter(); @@ -54,7 +54,7 @@ public function testQuoteIdentifier() : void public function testQuoteSingleIdentifier() : void { if ($this->platform->getName() === 'mssql') { - $this->markTestSkipped('Not working this way on mssql.'); + self::markTestSkipped('Not working this way on mssql.'); } $c = $this->platform->getIdentifierQuoteCharacter(); @@ -379,10 +379,10 @@ public function testGetCreateTableSqlDispatchEvent() : void ->addMethods(['onSchemaCreateTable', 'onSchemaCreateTableColumn']) ->getMock(); $listenerMock - ->expects($this->once()) + ->expects(self::once()) ->method('onSchemaCreateTable'); $listenerMock - ->expects($this->exactly(2)) + ->expects(self::exactly(2)) ->method('onSchemaCreateTableColumn'); $eventManager = new EventManager(); @@ -403,7 +403,7 @@ public function testGetDropTableSqlDispatchEvent() : void ->addMethods(['onSchemaDropTable']) ->getMock(); $listenerMock - ->expects($this->once()) + ->expects(self::once()) ->method('onSchemaDropTable'); $eventManager = new EventManager(); @@ -428,19 +428,19 @@ public function testGetAlterTableSqlDispatchEvent() : void ->addMethods($events) ->getMock(); $listenerMock - ->expects($this->once()) + ->expects(self::once()) ->method('onSchemaAlterTable'); $listenerMock - ->expects($this->once()) + ->expects(self::once()) ->method('onSchemaAlterTableAddColumn'); $listenerMock - ->expects($this->once()) + ->expects(self::once()) ->method('onSchemaAlterTableRemoveColumn'); $listenerMock - ->expects($this->once()) + ->expects(self::once()) ->method('onSchemaAlterTableChangeColumn'); $listenerMock - ->expects($this->once()) + ->expects(self::once()) ->method('onSchemaAlterTableRenameColumn'); $eventManager = new EventManager(); @@ -533,7 +533,7 @@ public function testCreateTableColumnTypeComments() : void */ public function getCreateTableColumnCommentsSQL() : array { - $this->markTestSkipped('Platform does not support Column comments.'); + self::markTestSkipped('Platform does not support Column comments.'); } /** @@ -541,7 +541,7 @@ public function getCreateTableColumnCommentsSQL() : array */ public function getAlterTableColumnCommentsSQL() : array { - $this->markTestSkipped('Platform does not support Column comments.'); + self::markTestSkipped('Platform does not support Column comments.'); } /** @@ -549,7 +549,7 @@ public function getAlterTableColumnCommentsSQL() : array */ public function getCreateTableColumnTypeCommentsSQL() : array { - $this->markTestSkipped('Platform does not support Column comments.'); + self::markTestSkipped('Platform does not support Column comments.'); } public function testGetDefaultValueDeclarationSQL() : void @@ -1119,7 +1119,7 @@ protected function getQuotedAlterTableRenameIndexInSchemaSQL() : array public function testQuotesDropForeignKeySQL() : void { if (! $this->platform->supportsForeignKeyConstraints()) { - $this->markTestSkipped( + self::markTestSkipped( sprintf('%s does not support foreign key constraints.', get_class($this->platform)) ); } @@ -1226,7 +1226,7 @@ public function testGetCommentOnColumnSQL() : 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))); + self::markTestSkipped(sprintf('%s does not support inline column comments.', get_class($this->platform))); } self::assertSame($expectedSql, $this->platform->getInlineColumnCommentSQL($comment)); @@ -1291,7 +1291,7 @@ protected function getQuotedStringLiteralQuoteCharacter() : string public function testThrowsExceptionOnGeneratingInlineColumnCommentSQLIfUnsupported() : void { if ($this->platform->supportsInlineColumnComments()) { - $this->markTestSkipped(sprintf('%s supports inline column comments.', get_class($this->platform))); + self::markTestSkipped(sprintf('%s supports inline column comments.', get_class($this->platform))); } $this->expectException(DBALException::class); diff --git a/tests/Platforms/AbstractPostgreSQLPlatformTestCase.php b/tests/Platforms/AbstractPostgreSQLPlatformTestCase.php index 2654ec321a8..4ce6252f183 100644 --- a/tests/Platforms/AbstractPostgreSQLPlatformTestCase.php +++ b/tests/Platforms/AbstractPostgreSQLPlatformTestCase.php @@ -896,8 +896,8 @@ public function testAltersTableColumnCommentIfRequiredByType() : void $tableDiff = $comparator->diffTable($table1, $table2); - $this->assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); - $this->assertSame( + self::assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff); + self::assertSame( [ 'ALTER TABLE "foo" ALTER "bar" TYPE TIMESTAMP(0) WITHOUT TIME ZONE', 'ALTER TABLE "foo" ALTER "bar" DROP DEFAULT', diff --git a/tests/Platforms/AbstractSQLServerPlatformTestCase.php b/tests/Platforms/AbstractSQLServerPlatformTestCase.php index abb6b2b3020..c23df1d6284 100644 --- a/tests/Platforms/AbstractSQLServerPlatformTestCase.php +++ b/tests/Platforms/AbstractSQLServerPlatformTestCase.php @@ -1082,7 +1082,7 @@ protected function getQuotedAlterTableRenameColumnSQL() : array */ protected function getQuotedAlterTableChangeColumnLengthSQL() : array { - $this->markTestIncomplete('Not implemented yet'); + self::markTestIncomplete('Not implemented yet'); } /** diff --git a/tests/Platforms/DB2PlatformTest.php b/tests/Platforms/DB2PlatformTest.php index 2cdf73f2ba0..b82de672c11 100644 --- a/tests/Platforms/DB2PlatformTest.php +++ b/tests/Platforms/DB2PlatformTest.php @@ -502,7 +502,7 @@ protected function getQuotedAlterTableRenameColumnSQL() : array */ protected function getQuotedAlterTableChangeColumnLengthSQL() : array { - $this->markTestIncomplete('Not implemented yet'); + self::markTestIncomplete('Not implemented yet'); } /** diff --git a/tests/Platforms/MariaDb1027PlatformTest.php b/tests/Platforms/MariaDb1027PlatformTest.php index 4303ade85d4..26f3b20f879 100644 --- a/tests/Platforms/MariaDb1027PlatformTest.php +++ b/tests/Platforms/MariaDb1027PlatformTest.php @@ -45,6 +45,6 @@ public function testInitializesJsonTypeMapping() : void */ public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() : void { - $this->markTestSkipped('MariaDB102Platform support propagation of default values for BLOB and TEXT columns'); + self::markTestSkipped('MariaDB102Platform support propagation of default values for BLOB and TEXT columns'); } } diff --git a/tests/Platforms/OraclePlatformTest.php b/tests/Platforms/OraclePlatformTest.php index 2c4ef658a42..458a7763644 100644 --- a/tests/Platforms/OraclePlatformTest.php +++ b/tests/Platforms/OraclePlatformTest.php @@ -632,7 +632,7 @@ protected function getQuotedAlterTableRenameColumnSQL() : array */ protected function getQuotedAlterTableChangeColumnLengthSQL() : array { - $this->markTestIncomplete('Not implemented yet'); + self::markTestIncomplete('Not implemented yet'); } /** diff --git a/tests/Platforms/SQLAnywhere16PlatformTest.php b/tests/Platforms/SQLAnywhere16PlatformTest.php index d842776021f..dc6c8690d0b 100644 --- a/tests/Platforms/SQLAnywhere16PlatformTest.php +++ b/tests/Platforms/SQLAnywhere16PlatformTest.php @@ -1025,7 +1025,7 @@ protected function getQuotedAlterTableRenameColumnSQL() : array */ protected function getQuotedAlterTableChangeColumnLengthSQL() : array { - $this->markTestIncomplete('Not implemented yet'); + self::markTestIncomplete('Not implemented yet'); } /** diff --git a/tests/Platforms/SqlitePlatformTest.php b/tests/Platforms/SqlitePlatformTest.php index fec493251ef..3786926f718 100644 --- a/tests/Platforms/SqlitePlatformTest.php +++ b/tests/Platforms/SqlitePlatformTest.php @@ -595,7 +595,7 @@ protected function getQuotedAlterTableChangeColumnLengthSQL() : array */ public function testAlterTableRenameIndexInSchema() : void { - $this->markTestIncomplete( + self::markTestIncomplete( 'Test currently produces broken SQL due to SQLLitePlatform::getAlterTable being broken ' . 'when used with schemas.' ); @@ -606,7 +606,7 @@ public function testAlterTableRenameIndexInSchema() : void */ public function testQuotesAlterTableRenameIndexInSchema() : void { - $this->markTestIncomplete( + self::markTestIncomplete( 'Test currently produces broken SQL due to SQLLitePlatform::getAlterTable being broken ' . 'when used with schemas.' ); diff --git a/tests/Portability/StatementTest.php b/tests/Portability/StatementTest.php index 36a9e514dc4..087c5d063f6 100644 --- a/tests/Portability/StatementTest.php +++ b/tests/Portability/StatementTest.php @@ -43,10 +43,10 @@ public function testBindParam() : void $type = ParameterType::STRING; $length = 666; - $this->wrappedStmt->expects($this->once()) + $this->wrappedStmt->expects(self::once()) ->method('bindParam') ->with($column, $variable, $type, $length) - ->will($this->returnValue(true)); + ->will(self::returnValue(true)); self::assertTrue($this->stmt->bindParam($column, $variable, $type, $length)); } @@ -57,19 +57,19 @@ public function testBindValue() : void $value = 'myvalue'; $type = ParameterType::STRING; - $this->wrappedStmt->expects($this->once()) + $this->wrappedStmt->expects(self::once()) ->method('bindValue') ->with($param, $value, $type) - ->will($this->returnValue(true)); + ->will(self::returnValue(true)); self::assertTrue($this->stmt->bindValue($param, $value, $type)); } public function testCloseCursor() : void { - $this->wrappedStmt->expects($this->once()) + $this->wrappedStmt->expects(self::once()) ->method('closeCursor') - ->will($this->returnValue(true)); + ->will(self::returnValue(true)); self::assertTrue($this->stmt->closeCursor()); } @@ -78,9 +78,9 @@ public function testColumnCount() : void { $columnCount = 666; - $this->wrappedStmt->expects($this->once()) + $this->wrappedStmt->expects(self::once()) ->method('columnCount') - ->will($this->returnValue($columnCount)); + ->will(self::returnValue($columnCount)); self::assertSame($columnCount, $this->stmt->columnCount()); } @@ -89,9 +89,9 @@ public function testErrorCode() : void { $errorCode = '666'; - $this->wrappedStmt->expects($this->once()) + $this->wrappedStmt->expects(self::once()) ->method('errorCode') - ->will($this->returnValue($errorCode)); + ->will(self::returnValue($errorCode)); self::assertSame($errorCode, $this->stmt->errorCode()); } @@ -100,9 +100,9 @@ public function testErrorInfo() : void { $errorInfo = ['666', 'Evil error.']; - $this->wrappedStmt->expects($this->once()) + $this->wrappedStmt->expects(self::once()) ->method('errorInfo') - ->will($this->returnValue($errorInfo)); + ->will(self::returnValue($errorInfo)); self::assertSame($errorInfo, $this->stmt->errorInfo()); } @@ -114,10 +114,10 @@ public function testExecute() : void 'bar', ]; - $this->wrappedStmt->expects($this->once()) + $this->wrappedStmt->expects(self::once()) ->method('execute') ->with($params) - ->will($this->returnValue(true)); + ->will(self::returnValue(true)); self::assertTrue($this->stmt->execute($params)); } @@ -128,10 +128,10 @@ public function testSetFetchMode() : void $arg1 = 'MyClass'; $arg2 = [1, 2]; - $this->wrappedStmt->expects($this->once()) + $this->wrappedStmt->expects(self::once()) ->method('setFetchMode') ->with($fetchMode, $arg1, $arg2) - ->will($this->returnValue(true)); + ->will(self::returnValue(true)); $re = new ReflectionProperty($this->stmt, 'defaultFetchMode'); $re->setAccessible(true); @@ -143,7 +143,7 @@ public function testSetFetchMode() : void public function testGetIterator() : void { - $this->wrappedStmt->expects($this->exactly(3)) + $this->wrappedStmt->expects(self::exactly(3)) ->method('fetch') ->willReturnOnConsecutiveCalls('foo', 'bar', false); @@ -154,9 +154,9 @@ public function testRowCount() : void { $rowCount = 666; - $this->wrappedStmt->expects($this->once()) + $this->wrappedStmt->expects(self::once()) ->method('rowCount') - ->will($this->returnValue($rowCount)); + ->will(self::returnValue($rowCount)); self::assertSame($rowCount, $this->stmt->rowCount()); } diff --git a/tests/Query/Expression/ExpressionBuilderTest.php b/tests/Query/Expression/ExpressionBuilderTest.php index 38442155ca6..c319dfd7e4b 100644 --- a/tests/Query/Expression/ExpressionBuilderTest.php +++ b/tests/Query/Expression/ExpressionBuilderTest.php @@ -21,9 +21,9 @@ protected function setUp() : void $this->expr = new ExpressionBuilder($conn); - $conn->expects($this->any()) + $conn->expects(self::any()) ->method('getExpressionBuilder') - ->will($this->returnValue($this->expr)); + ->will(self::returnValue($this->expr)); } /** diff --git a/tests/Query/QueryBuilderTest.php b/tests/Query/QueryBuilderTest.php index cbea4e3064a..97da8151136 100644 --- a/tests/Query/QueryBuilderTest.php +++ b/tests/Query/QueryBuilderTest.php @@ -23,9 +23,9 @@ protected function setUp() : void $expressionBuilder = new ExpressionBuilder($this->conn); - $this->conn->expects($this->any()) + $this->conn->expects(self::any()) ->method('getExpressionBuilder') - ->will($this->returnValue($expressionBuilder)); + ->will(self::returnValue($expressionBuilder)); } /** diff --git a/tests/Schema/ComparatorTest.php b/tests/Schema/ComparatorTest.php index 59eb5d4c589..a9329bacf0e 100644 --- a/tests/Schema/ComparatorTest.php +++ b/tests/Schema/ComparatorTest.php @@ -1178,33 +1178,33 @@ public function testComparesNamespaces() : void ->onlyMethods(['getNamespaces', 'hasNamespace']) ->getMock(); - $fromSchema->expects($this->once()) + $fromSchema->expects(self::once()) ->method('getNamespaces') - ->will($this->returnValue(['foo', 'bar'])); + ->will(self::returnValue(['foo', 'bar'])); - $fromSchema->expects($this->at(0)) + $fromSchema->expects(self::at(0)) ->method('hasNamespace') ->with('bar') - ->will($this->returnValue(true)); + ->will(self::returnValue(true)); - $fromSchema->expects($this->at(1)) + $fromSchema->expects(self::at(1)) ->method('hasNamespace') ->with('baz') - ->will($this->returnValue(false)); + ->will(self::returnValue(false)); - $toSchema->expects($this->once()) + $toSchema->expects(self::once()) ->method('getNamespaces') - ->will($this->returnValue(['bar', 'baz'])); + ->will(self::returnValue(['bar', 'baz'])); - $toSchema->expects($this->at(1)) + $toSchema->expects(self::at(1)) ->method('hasNamespace') ->with('foo') - ->will($this->returnValue(false)); + ->will(self::returnValue(false)); - $toSchema->expects($this->at(2)) + $toSchema->expects(self::at(2)) ->method('hasNamespace') ->with('bar') - ->will($this->returnValue(true)); + ->will(self::returnValue(true)); $expected = new SchemaDiff(); $expected->fromSchema = $fromSchema; diff --git a/tests/Schema/DB2SchemaManagerTest.php b/tests/Schema/DB2SchemaManagerTest.php index 93c22128ed7..d7f4afcecbf 100644 --- a/tests/Schema/DB2SchemaManagerTest.php +++ b/tests/Schema/DB2SchemaManagerTest.php @@ -44,7 +44,7 @@ protected function setUp() : void public function testListTableNamesFiltersAssetNamesCorrectly() : void { $this->conn->getConfiguration()->setFilterSchemaAssetsExpression('/^(?!T_)/'); - $this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue([ + $this->conn->expects(self::once())->method('fetchAll')->will(self::returnValue([ ['name' => 'FOO'], ['name' => 'T_FOO'], ['name' => 'BAR'], @@ -67,7 +67,7 @@ public function testAssetFilteringSetsACallable() : void { $filterExpression = '/^(?!T_)/'; $this->conn->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); - $this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue([ + $this->conn->expects(self::once())->method('fetchAll')->will(self::returnValue([ ['name' => 'FOO'], ['name' => 'T_FOO'], ['name' => 'BAR'], @@ -86,7 +86,7 @@ public function testAssetFilteringSetsACallable() : void self::assertIsCallable($callable); // BC check: Test that regexp expression is still preserved & accessible. - $this->assertEquals($filterExpression, $this->conn->getConfiguration()->getFilterSchemaAssetsExpression()); + self::assertEquals($filterExpression, $this->conn->getConfiguration()->getFilterSchemaAssetsExpression()); } public function testListTableNamesFiltersAssetNamesCorrectlyWithCallable() : void @@ -95,8 +95,8 @@ public function testListTableNamesFiltersAssetNamesCorrectlyWithCallable() : voi $this->conn->getConfiguration()->setSchemaAssetsFilter(static function ($assetName) use ($accepted) { return in_array($assetName, $accepted); }); - $this->conn->expects($this->any())->method('quote'); - $this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue([ + $this->conn->expects(self::any())->method('quote'); + $this->conn->expects(self::once())->method('fetchAll')->will(self::returnValue([ ['name' => 'FOO'], ['name' => 'T_FOO'], ['name' => 'BAR'], @@ -111,7 +111,7 @@ public function testListTableNamesFiltersAssetNamesCorrectlyWithCallable() : voi $this->manager->listTableNames() ); - $this->assertNull($this->conn->getConfiguration()->getFilterSchemaAssetsExpression()); + self::assertNull($this->conn->getConfiguration()->getFilterSchemaAssetsExpression()); } public function testSettingNullExpressionWillResetCallable() : void @@ -120,8 +120,8 @@ public function testSettingNullExpressionWillResetCallable() : void $this->conn->getConfiguration()->setSchemaAssetsFilter(static function ($assetName) use ($accepted) { return in_array($assetName, $accepted); }); - $this->conn->expects($this->any())->method('quote'); - $this->conn->expects($this->atLeastOnce())->method('fetchAll')->will($this->returnValue([ + $this->conn->expects(self::any())->method('quote'); + $this->conn->expects($this->atLeastOnce())->method('fetchAll')->will(self::returnValue([ ['name' => 'FOO'], ['name' => 'T_FOO'], ['name' => 'BAR'], @@ -148,7 +148,7 @@ public function testSettingNullExpressionWillResetCallable() : void $this->manager->listTableNames() ); - $this->assertNull($this->conn->getConfiguration()->getSchemaAssetsFilter()); + self::assertNull($this->conn->getConfiguration()->getSchemaAssetsFilter()); } public function testSettingNullAsCallableClearsExpression() : void @@ -156,7 +156,7 @@ public function testSettingNullAsCallableClearsExpression() : void $filterExpression = '/^(?!T_)/'; $this->conn->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); - $this->conn->expects($this->exactly(2))->method('fetchAll')->will($this->returnValue([ + $this->conn->expects(self::exactly(2))->method('fetchAll')->will(self::returnValue([ ['name' => 'FOO'], ['name' => 'T_FOO'], ['name' => 'BAR'], diff --git a/tests/Schema/ForeignKeyConstraintTest.php b/tests/Schema/ForeignKeyConstraintTest.php index 67abc66be92..fb04c1a0ca8 100644 --- a/tests/Schema/ForeignKeyConstraintTest.php +++ b/tests/Schema/ForeignKeyConstraintTest.php @@ -22,9 +22,9 @@ public function testIntersectsIndexColumns(array $indexColumns, bool $expectedRe $index = $this->getMockBuilder(Index::class) ->disableOriginalConstructor() ->getMock(); - $index->expects($this->once()) + $index->expects(self::once()) ->method('getColumns') - ->will($this->returnValue($indexColumns)); + ->will(self::returnValue($indexColumns)); self::assertSame($expectedResult, $foreignKey->intersectsIndexColumns($index)); } diff --git a/tests/Schema/MySqlSchemaManagerTest.php b/tests/Schema/MySqlSchemaManagerTest.php index eb7a7dfa2f7..d405051d5c8 100644 --- a/tests/Schema/MySqlSchemaManagerTest.php +++ b/tests/Schema/MySqlSchemaManagerTest.php @@ -35,7 +35,7 @@ protected function setUp() : void public function testCompositeForeignKeys() : void { - $this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue($this->getFKDefinition())); + $this->conn->expects(self::once())->method('fetchAll')->will(self::returnValue($this->getFKDefinition())); $fkeys = $this->manager->listTableForeignKeys('dummy'); self::assertCount(1, $fkeys, 'Table has to have one foreign key.'); diff --git a/tests/Schema/SchemaDiffTest.php b/tests/Schema/SchemaDiffTest.php index 988b1e5ddeb..b265d986867 100644 --- a/tests/Schema/SchemaDiffTest.php +++ b/tests/Schema/SchemaDiffTest.php @@ -44,60 +44,60 @@ private function createPlatform(bool $unsafe) { /** @var AbstractPlatform|MockObject $platform */ $platform = $this->createMock(AbstractPlatform::class); - $platform->expects($this->exactly(1)) + $platform->expects(self::exactly(1)) ->method('getCreateSchemaSQL') ->with('foo_ns') - ->will($this->returnValue('create_schema')); + ->will(self::returnValue('create_schema')); if ($unsafe) { - $platform->expects($this->exactly(1)) + $platform->expects(self::exactly(1)) ->method('getDropSequenceSql') - ->with($this->isInstanceOf(Sequence::class)) - ->will($this->returnValue('drop_seq')); + ->with(self::isInstanceOf(Sequence::class)) + ->will(self::returnValue('drop_seq')); } - $platform->expects($this->exactly(1)) + $platform->expects(self::exactly(1)) ->method('getAlterSequenceSql') - ->with($this->isInstanceOf(Sequence::class)) - ->will($this->returnValue('alter_seq')); - $platform->expects($this->exactly(1)) + ->with(self::isInstanceOf(Sequence::class)) + ->will(self::returnValue('alter_seq')); + $platform->expects(self::exactly(1)) ->method('getCreateSequenceSql') - ->with($this->isInstanceOf(Sequence::class)) - ->will($this->returnValue('create_seq')); + ->with(self::isInstanceOf(Sequence::class)) + ->will(self::returnValue('create_seq')); if ($unsafe) { - $platform->expects($this->exactly(1)) + $platform->expects(self::exactly(1)) ->method('getDropTableSql') - ->with($this->isInstanceOf(Table::class)) - ->will($this->returnValue('drop_table')); + ->with(self::isInstanceOf(Table::class)) + ->will(self::returnValue('drop_table')); } - $platform->expects($this->exactly(1)) + $platform->expects(self::exactly(1)) ->method('getCreateTableSql') - ->with($this->isInstanceOf(Table::class)) - ->will($this->returnValue(['create_table'])); - $platform->expects($this->exactly(1)) + ->with(self::isInstanceOf(Table::class)) + ->will(self::returnValue(['create_table'])); + $platform->expects(self::exactly(1)) ->method('getCreateForeignKeySQL') - ->with($this->isInstanceOf(ForeignKeyConstraint::class)) - ->will($this->returnValue('create_foreign_key')); - $platform->expects($this->exactly(1)) + ->with(self::isInstanceOf(ForeignKeyConstraint::class)) + ->will(self::returnValue('create_foreign_key')); + $platform->expects(self::exactly(1)) ->method('getAlterTableSql') - ->with($this->isInstanceOf(TableDiff::class)) - ->will($this->returnValue(['alter_table'])); + ->with(self::isInstanceOf(TableDiff::class)) + ->will(self::returnValue(['alter_table'])); if ($unsafe) { - $platform->expects($this->exactly(1)) + $platform->expects(self::exactly(1)) ->method('getDropForeignKeySql') ->with( - $this->isInstanceOf(ForeignKeyConstraint::class), - $this->isInstanceOf(Table::class) + self::isInstanceOf(ForeignKeyConstraint::class), + self::isInstanceOf(Table::class) ) - ->will($this->returnValue('drop_orphan_fk')); + ->will(self::returnValue('drop_orphan_fk')); } - $platform->expects($this->exactly(1)) + $platform->expects(self::exactly(1)) ->method('supportsSchemas') - ->will($this->returnValue(true)); - $platform->expects($this->exactly(1)) + ->will(self::returnValue(true)); + $platform->expects(self::exactly(1)) ->method('supportsSequences') - ->will($this->returnValue(true)); - $platform->expects($this->exactly(2)) + ->will(self::returnValue(true)); + $platform->expects(self::exactly(2)) ->method('supportsForeignKeyConstraints') - ->will($this->returnValue(true)); + ->will(self::returnValue(true)); return $platform; } diff --git a/tests/Schema/SchemaTest.php b/tests/Schema/SchemaTest.php index 28c70b10628..fe3ffaaf22a 100644 --- a/tests/Schema/SchemaTest.php +++ b/tests/Schema/SchemaTest.php @@ -373,30 +373,30 @@ public function testVisitsVisitor() : void $schema->createSequence('moo'); $schema->createSequence('war'); - $visitor->expects($this->once()) + $visitor->expects(self::once()) ->method('acceptSchema') ->with($schema); - $visitor->expects($this->at(1)) + $visitor->expects(self::at(1)) ->method('acceptTable') ->with($schema->getTable('baz')); - $visitor->expects($this->at(2)) + $visitor->expects(self::at(2)) ->method('acceptTable') ->with($schema->getTable('bla.bloo')); - $visitor->expects($this->exactly(2)) + $visitor->expects(self::exactly(2)) ->method('acceptTable'); - $visitor->expects($this->at(3)) + $visitor->expects(self::at(3)) ->method('acceptSequence') ->with($schema->getSequence('moo')); - $visitor->expects($this->at(4)) + $visitor->expects(self::at(4)) ->method('acceptSequence') ->with($schema->getSequence('war')); - $visitor->expects($this->exactly(2)) + $visitor->expects(self::exactly(2)) ->method('acceptSequence'); self::assertNull($schema->visit($visitor)); @@ -419,45 +419,45 @@ public function testVisitsNamespaceVisitor() : void $schema->createSequence('moo'); $schema->createSequence('war'); - $visitor->expects($this->once()) + $visitor->expects(self::once()) ->method('acceptSchema') ->with($schema); - $visitor->expects($this->at(1)) + $visitor->expects(self::at(1)) ->method('acceptNamespace') ->with('foo'); - $visitor->expects($this->at(2)) + $visitor->expects(self::at(2)) ->method('acceptNamespace') ->with('bar'); - $visitor->expects($this->at(3)) + $visitor->expects(self::at(3)) ->method('acceptNamespace') ->with('bla'); - $visitor->expects($this->exactly(3)) + $visitor->expects(self::exactly(3)) ->method('acceptNamespace'); - $visitor->expects($this->at(4)) + $visitor->expects(self::at(4)) ->method('acceptTable') ->with($schema->getTable('baz')); - $visitor->expects($this->at(5)) + $visitor->expects(self::at(5)) ->method('acceptTable') ->with($schema->getTable('bla.bloo')); - $visitor->expects($this->exactly(2)) + $visitor->expects(self::exactly(2)) ->method('acceptTable'); - $visitor->expects($this->at(6)) + $visitor->expects(self::at(6)) ->method('acceptSequence') ->with($schema->getSequence('moo')); - $visitor->expects($this->at(7)) + $visitor->expects(self::at(7)) ->method('acceptSequence') ->with($schema->getSequence('war')); - $visitor->expects($this->exactly(2)) + $visitor->expects(self::exactly(2)) ->method('acceptSequence'); self::assertNull($schema->visit($visitor)); diff --git a/tests/Schema/TableDiffTest.php b/tests/Schema/TableDiffTest.php index a5560c7791e..4922a20233d 100644 --- a/tests/Schema/TableDiffTest.php +++ b/tests/Schema/TableDiffTest.php @@ -41,10 +41,10 @@ public function testPrefersNameFromTableObject() : void $tableDiff = new TableDiff('foo'); $tableDiff->fromTable = $tableMock; - $tableMock->expects($this->once()) + $tableMock->expects(self::once()) ->method('getQuotedName') ->with($this->platform) - ->will($this->returnValue('foo')); + ->will(self::returnValue('foo')); self::assertEquals(new Identifier('foo'), $tableDiff->getName($this->platform)); } diff --git a/tests/Schema/Visitor/CreateSchemaSqlCollectorTest.php b/tests/Schema/Visitor/CreateSchemaSqlCollectorTest.php index f9a09b12671..9a6122a3b18 100644 --- a/tests/Schema/Visitor/CreateSchemaSqlCollectorTest.php +++ b/tests/Schema/Visitor/CreateSchemaSqlCollectorTest.php @@ -50,13 +50,13 @@ protected function setUp() : void public function testAcceptsNamespace() : void { - $this->platformMock->expects($this->at(0)) + $this->platformMock->expects(self::at(0)) ->method('supportsSchemas') - ->will($this->returnValue(false)); + ->will(self::returnValue(false)); - $this->platformMock->expects($this->at(1)) + $this->platformMock->expects(self::at(1)) ->method('supportsSchemas') - ->will($this->returnValue(true)); + ->will(self::returnValue(true)); $this->visitor->acceptNamespace('foo'); @@ -78,13 +78,13 @@ public function testAcceptsTable() : void public function testAcceptsForeignKey() : void { - $this->platformMock->expects($this->at(0)) + $this->platformMock->expects(self::at(0)) ->method('supportsForeignKeyConstraints') - ->will($this->returnValue(false)); + ->will(self::returnValue(false)); - $this->platformMock->expects($this->at(1)) + $this->platformMock->expects(self::at(1)) ->method('supportsForeignKeyConstraints') - ->will($this->returnValue(true)); + ->will(self::returnValue(true)); $table = $this->createTableMock(); $foreignKey = $this->createForeignKeyConstraintMock(); @@ -110,9 +110,9 @@ public function testAcceptsSequences() : void public function testResetsQueries() : void { foreach (['supportsSchemas', 'supportsForeignKeyConstraints'] as $method) { - $this->platformMock->expects($this->any()) + $this->platformMock->expects(self::any()) ->method($method) - ->will($this->returnValue(true)); + ->will(self::returnValue(true)); } $table = $this->createTableMock(); diff --git a/tests/Schema/Visitor/DropSchemaSqlCollectorTest.php b/tests/Schema/Visitor/DropSchemaSqlCollectorTest.php index cab4b00263a..c392e9c1fbf 100644 --- a/tests/Schema/Visitor/DropSchemaSqlCollectorTest.php +++ b/tests/Schema/Visitor/DropSchemaSqlCollectorTest.php @@ -28,14 +28,14 @@ public function testGetQueriesUsesAcceptedForeignKeys() : void $collector = new DropSchemaSqlCollector($platform); - $platform->expects($this->exactly(2)) + $platform->expects(self::exactly(2)) ->method('getDropForeignKeySQL'); - $platform->expects($this->at(0)) + $platform->expects(self::at(0)) ->method('getDropForeignKeySQL') ->with($keyConstraintOne, $tableOne); - $platform->expects($this->at(1)) + $platform->expects(self::at(1)) ->method('getDropForeignKeySQL') ->with($keyConstraintTwo, $tableTwo); @@ -49,17 +49,17 @@ private function getStubKeyConstraint(string $name) : ForeignKeyConstraint { $constraint = $this->createMock(ForeignKeyConstraint::class); - $constraint->expects($this->any()) + $constraint->expects(self::any()) ->method('getName') - ->will($this->returnValue($name)); + ->will(self::returnValue($name)); - $constraint->expects($this->any()) + $constraint->expects(self::any()) ->method('getForeignColumns') - ->will($this->returnValue([])); + ->will(self::returnValue([])); - $constraint->expects($this->any()) + $constraint->expects(self::any()) ->method('getColumns') - ->will($this->returnValue([])); + ->will(self::returnValue([])); return $constraint; } diff --git a/tests/Schema/Visitor/SchemaSqlCollectorTest.php b/tests/Schema/Visitor/SchemaSqlCollectorTest.php index 484a3debe7e..cc56e35c3a0 100644 --- a/tests/Schema/Visitor/SchemaSqlCollectorTest.php +++ b/tests/Schema/Visitor/SchemaSqlCollectorTest.php @@ -13,15 +13,15 @@ public function testCreateSchema() : void $platformMock = $this->getMockBuilder(MySqlPlatform::class) ->onlyMethods(['getCreateTableSql', 'getCreateSequenceSql', 'getCreateForeignKeySql']) ->getMock(); - $platformMock->expects($this->exactly(2)) + $platformMock->expects(self::exactly(2)) ->method('getCreateTableSql') - ->will($this->returnValue(['foo'])); - $platformMock->expects($this->exactly(1)) + ->will(self::returnValue(['foo'])); + $platformMock->expects(self::exactly(1)) ->method('getCreateSequenceSql') - ->will($this->returnValue('bar')); - $platformMock->expects($this->exactly(1)) + ->will(self::returnValue('bar')); + $platformMock->expects(self::exactly(1)) ->method('getCreateForeignKeySql') - ->will($this->returnValue('baz')); + ->will(self::returnValue('baz')); $schema = $this->createFixtureSchema(); @@ -35,15 +35,15 @@ public function testDropSchema() : void $platformMock = $this->getMockBuilder(MySqlPlatform::class) ->onlyMethods(['getDropTableSql', 'getDropSequenceSql', 'getDropForeignKeySql']) ->getMock(); - $platformMock->expects($this->exactly(2)) + $platformMock->expects(self::exactly(2)) ->method('getDropTableSql') - ->will($this->returnValue('tbl')); - $platformMock->expects($this->exactly(1)) + ->will(self::returnValue('tbl')); + $platformMock->expects(self::exactly(1)) ->method('getDropSequenceSql') - ->will($this->returnValue('seq')); - $platformMock->expects($this->exactly(1)) + ->will(self::returnValue('seq')); + $platformMock->expects(self::exactly(1)) ->method('getDropForeignKeySql') - ->will($this->returnValue('fk')); + ->will(self::returnValue('fk')); $schema = $this->createFixtureSchema(); diff --git a/tests/StatementTest.php b/tests/StatementTest.php index c80b3ab17d1..9af45c91d15 100644 --- a/tests/StatementTest.php +++ b/tests/StatementTest.php @@ -40,18 +40,18 @@ protected function setUp() : void $this->conn = $this->getMockBuilder(Connection::class) ->setConstructorArgs([[], $driver]) ->getMock(); - $this->conn->expects($this->atLeastOnce()) + $this->conn->expects(self::atLeastOnce()) ->method('getWrappedConnection') - ->will($this->returnValue($driverConnection)); + ->will(self::returnValue($driverConnection)); $this->configuration = $this->createMock(Configuration::class); - $this->conn->expects($this->any()) + $this->conn->expects(self::any()) ->method('getConfiguration') - ->will($this->returnValue($this->configuration)); + ->will(self::returnValue($this->configuration)); - $this->conn->expects($this->any()) + $this->conn->expects(self::any()) ->method('getDriver') - ->will($this->returnValue($driver)); + ->will(self::returnValue($driver)); } public function testExecuteCallsLoggerStartQueryWithParametersWhenValuesBound() : void @@ -64,13 +64,13 @@ public function testExecuteCallsLoggerStartQueryWithParametersWhenValuesBound() $sql = ''; $logger = $this->createMock(SQLLogger::class); - $logger->expects($this->once()) + $logger->expects(self::once()) ->method('startQuery') - ->with($this->equalTo($sql), $this->equalTo($values), $this->equalTo($types)); + ->with(self::equalTo($sql), self::equalTo($values), self::equalTo($types)); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('getSQLLogger') - ->will($this->returnValue($logger)); + ->will(self::returnValue($logger)); $statement = new Statement($sql, $this->conn); $statement->bindValue($name, $var, $type); @@ -86,13 +86,13 @@ public function testExecuteCallsLoggerStartQueryWithParametersWhenParamsPassedTo $sql = ''; $logger = $this->createMock(SQLLogger::class); - $logger->expects($this->once()) + $logger->expects(self::once()) ->method('startQuery') - ->with($this->equalTo($sql), $this->equalTo($values), $this->equalTo($types)); + ->with(self::equalTo($sql), self::equalTo($values), self::equalTo($types)); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('getSQLLogger') - ->will($this->returnValue($logger)); + ->will(self::returnValue($logger)); $statement = new Statement($sql, $this->conn); $statement->execute($values); @@ -124,24 +124,24 @@ public function testExecuteCallsLoggerStopQueryOnException() : void { $logger = $this->createMock(SQLLogger::class); - $this->configuration->expects($this->once()) + $this->configuration->expects(self::once()) ->method('getSQLLogger') - ->will($this->returnValue($logger)); + ->will(self::returnValue($logger)); // Needed to satisfy construction of DBALException - $this->conn->expects($this->any()) + $this->conn->expects(self::any()) ->method('resolveParams') - ->will($this->returnValue([])); + ->will(self::returnValue([])); - $logger->expects($this->once()) + $logger->expects(self::once()) ->method('startQuery'); - $logger->expects($this->once()) + $logger->expects(self::once()) ->method('stopQuery'); - $this->driverStatement->expects($this->once()) + $this->driverStatement->expects(self::once()) ->method('execute') - ->will($this->throwException(new Exception('Mock test exception'))); + ->will(self::throwException(new Exception('Mock test exception'))); $statement = new Statement('', $this->conn); @@ -154,7 +154,7 @@ public function testPDOCustomClassConstructorArgs() : void { $statement = new Statement('', $this->conn); - $this->driverStatement->expects($this->once()) + $this->driverStatement->expects(self::once()) ->method('fetchAll') ->with(self::equalTo(FetchMode::CUSTOM_OBJECT), self::equalTo('Example'), self::equalTo(['arg1'])); diff --git a/tests/Tools/Console/RunSqlCommandTest.php b/tests/Tools/Console/RunSqlCommandTest.php index 502c537b91c..23796c83ea0 100644 --- a/tests/Tools/Console/RunSqlCommandTest.php +++ b/tests/Tools/Console/RunSqlCommandTest.php @@ -46,7 +46,7 @@ public function testMissingSqlArgument() : void 'command' => $this->command->getName(), 'sql' => null, ]); - $this->fail('Expected a runtime exception when omitting sql argument'); + self::fail('Expected a runtime exception when omitting sql argument'); } catch (RuntimeException $e) { self::assertStringContainsString("Argument 'SQL", $e->getMessage()); } @@ -60,7 +60,7 @@ public function testIncorrectDepthOption() : void 'sql' => 'SELECT 1', '--depth' => 'string', ]); - $this->fail('Expected a logic exception when executing with a stringy depth'); + self::fail('Expected a logic exception when executing with a stringy depth'); } catch (LogicException $e) { self::assertStringContainsString("Option 'depth'", $e->getMessage()); } @@ -74,7 +74,7 @@ public function testSelectStatementsPrintsResult() : void 'command' => $this->command->getName(), 'sql' => 'SELECT 1', ]); - $this->assertSame(0, $exitCode); + self::assertSame(0, $exitCode); self::assertRegExp('@int.*1.*@', $this->commandTester->getDisplay()); self::assertRegExp('@array.*1.*@', $this->commandTester->getDisplay()); @@ -96,20 +96,20 @@ public function testUpdateStatementsPrintsAffectedLines() : void private function expectConnectionExecuteUpdate() : void { $this->connectionMock - ->expects($this->exactly(1)) + ->expects(self::exactly(1)) ->method('executeUpdate'); $this->connectionMock - ->expects($this->exactly(0)) + ->expects(self::exactly(0)) ->method('fetchAll'); } private function expectConnectionFetchAll() : void { $this->connectionMock - ->expects($this->exactly(0)) + ->expects(self::exactly(0)) ->method('executeUpdate'); $this->connectionMock - ->expects($this->exactly(1)) + ->expects(self::exactly(1)) ->method('fetchAll'); } diff --git a/tests/Types/BinaryTest.php b/tests/Types/BinaryTest.php index b516cdb4683..a1dbf2010d4 100644 --- a/tests/Types/BinaryTest.php +++ b/tests/Types/BinaryTest.php @@ -43,7 +43,7 @@ public function testReturnsName() : void public function testReturnsSQLDeclaration() : void { - $this->platform->expects($this->once()) + $this->platform->expects(self::once()) ->method('getBinaryTypeDeclarationSQL') ->willReturn('TEST_BINARY'); diff --git a/tests/Types/DateImmutableTypeTest.php b/tests/Types/DateImmutableTypeTest.php index 6e507d7dc6e..bffc9725c3c 100644 --- a/tests/Types/DateImmutableTypeTest.php +++ b/tests/Types/DateImmutableTypeTest.php @@ -46,10 +46,10 @@ public function testConvertsDateTimeImmutableInstanceToDatabaseValue() : void { $date = $this->createMock(DateTimeImmutable::class); - $this->platform->expects($this->once()) + $this->platform->expects(self::once()) ->method('getDateFormatString') ->willReturn('Y-m-d'); - $date->expects($this->once()) + $date->expects(self::once()) ->method('format') ->with('Y-m-d') ->willReturn('2016-01-01'); @@ -86,7 +86,7 @@ public function testConvertsNullToPHPValue() : void public function testConvertsDateStringToPHPValue() : void { - $this->platform->expects($this->once()) + $this->platform->expects(self::once()) ->method('getDateFormatString') ->willReturn('Y-m-d'); @@ -98,7 +98,7 @@ public function testConvertsDateStringToPHPValue() : void public function testResetTimeFractionsWhenConvertingToPHPValue() : void { - $this->platform->expects($this->any()) + $this->platform->expects(self::any()) ->method('getDateFormatString') ->willReturn('Y-m-d'); diff --git a/tests/Types/DateTimeImmutableTypeTest.php b/tests/Types/DateTimeImmutableTypeTest.php index 638cabdaf19..c34ef77861a 100644 --- a/tests/Types/DateTimeImmutableTypeTest.php +++ b/tests/Types/DateTimeImmutableTypeTest.php @@ -46,10 +46,10 @@ public function testConvertsDateTimeImmutableInstanceToDatabaseValue() : void { $date = $this->getMockBuilder(DateTimeImmutable::class)->getMock(); - $this->platform->expects($this->once()) + $this->platform->expects(self::once()) ->method('getDateTimeFormatString') ->willReturn('Y-m-d H:i:s'); - $date->expects($this->once()) + $date->expects(self::once()) ->method('format') ->with('Y-m-d H:i:s') ->willReturn('2016-01-01 15:58:59'); @@ -86,7 +86,7 @@ public function testConvertsNullToPHPValue() : void public function testConvertsDateTimeStringToPHPValue() : void { - $this->platform->expects($this->once()) + $this->platform->expects(self::once()) ->method('getDateTimeFormatString') ->willReturn('Y-m-d H:i:s'); @@ -101,7 +101,7 @@ public function testConvertsDateTimeStringToPHPValue() : void */ public function testConvertsDateTimeStringWithMicrosecondsToPHPValue() : void { - $this->platform->expects($this->any()) + $this->platform->expects(self::any()) ->method('getDateTimeFormatString') ->willReturn('Y-m-d H:i:s'); @@ -112,7 +112,7 @@ public function testConvertsDateTimeStringWithMicrosecondsToPHPValue() : void public function testThrowsExceptionDuringConversionToPHPValueWithInvalidDateTimeString() : void { - $this->platform->expects($this->atLeastOnce()) + $this->platform->expects(self::atLeastOnce()) ->method('getDateTimeFormatString') ->willReturn('Y-m-d H:i:s'); diff --git a/tests/Types/DateTimeTzImmutableTypeTest.php b/tests/Types/DateTimeTzImmutableTypeTest.php index 8c6ea1996a5..e3443f4171c 100644 --- a/tests/Types/DateTimeTzImmutableTypeTest.php +++ b/tests/Types/DateTimeTzImmutableTypeTest.php @@ -46,10 +46,10 @@ public function testConvertsDateTimeImmutableInstanceToDatabaseValue() : void { $date = $this->createMock(DateTimeImmutable::class); - $this->platform->expects($this->once()) + $this->platform->expects(self::once()) ->method('getDateTimeTzFormatString') ->willReturn('Y-m-d H:i:s T'); - $date->expects($this->once()) + $date->expects(self::once()) ->method('format') ->with('Y-m-d H:i:s T') ->willReturn('2016-01-01 15:58:59 UTC'); @@ -86,7 +86,7 @@ public function testConvertsNullToPHPValue() : void public function testConvertsDateTimeWithTimezoneStringToPHPValue() : void { - $this->platform->expects($this->once()) + $this->platform->expects(self::once()) ->method('getDateTimeTzFormatString') ->willReturn('Y-m-d H:i:s T'); @@ -98,7 +98,7 @@ public function testConvertsDateTimeWithTimezoneStringToPHPValue() : void public function testThrowsExceptionDuringConversionToPHPValueWithInvalidDateTimeWithTimezoneString() : void { - $this->platform->expects($this->atLeastOnce()) + $this->platform->expects(self::atLeastOnce()) ->method('getDateTimeTzFormatString') ->willReturn('Y-m-d H:i:s T'); diff --git a/tests/Types/GuidTypeTest.php b/tests/Types/GuidTypeTest.php index 01fb91e5a18..2a578f951f4 100644 --- a/tests/Types/GuidTypeTest.php +++ b/tests/Types/GuidTypeTest.php @@ -37,9 +37,9 @@ public function testNativeGuidSupport() : void { self::assertTrue($this->type->requiresSQLCommentHint($this->platform)); - $this->platform->expects($this->any()) + $this->platform->expects(self::any()) ->method('hasNativeGuidType') - ->will($this->returnValue(true)); + ->will(self::returnValue(true)); self::assertFalse($this->type->requiresSQLCommentHint($this->platform)); } diff --git a/tests/Types/JsonArrayTest.php b/tests/Types/JsonArrayTest.php index 1a93b7387dc..b773baaa29e 100644 --- a/tests/Types/JsonArrayTest.php +++ b/tests/Types/JsonArrayTest.php @@ -42,7 +42,7 @@ public function testReturnsName() : void public function testReturnsSQLDeclaration() : void { - $this->platform->expects($this->once()) + $this->platform->expects(self::once()) ->method('getJsonTypeDeclarationSQL') ->willReturn('TEST_JSON'); diff --git a/tests/Types/JsonTest.php b/tests/Types/JsonTest.php index 212767d6d6c..66bec19109a 100644 --- a/tests/Types/JsonTest.php +++ b/tests/Types/JsonTest.php @@ -43,7 +43,7 @@ public function testReturnsName() : void public function testReturnsSQLDeclaration() : void { - $this->platform->expects($this->once()) + $this->platform->expects(self::once()) ->method('getJsonTypeDeclarationSQL') ->willReturn('TEST_JSON'); diff --git a/tests/Types/StringTest.php b/tests/Types/StringTest.php index 75c03fc6d46..3c2b51a3760 100644 --- a/tests/Types/StringTest.php +++ b/tests/Types/StringTest.php @@ -24,7 +24,7 @@ protected function setUp() : void public function testReturnsSqlDeclarationFromPlatformVarchar() : void { - $this->platform->expects($this->once()) + $this->platform->expects(self::once()) ->method('getVarcharTypeDeclarationSQL') ->willReturn('TEST_VARCHAR'); @@ -33,7 +33,7 @@ public function testReturnsSqlDeclarationFromPlatformVarchar() : void public function testReturnsDefaultLengthFromPlatformVarchar() : void { - $this->platform->expects($this->once()) + $this->platform->expects(self::once()) ->method('getVarcharDefaultLength') ->willReturn(255); diff --git a/tests/Types/TimeImmutableTypeTest.php b/tests/Types/TimeImmutableTypeTest.php index e2f7586ffaf..730c0feacda 100644 --- a/tests/Types/TimeImmutableTypeTest.php +++ b/tests/Types/TimeImmutableTypeTest.php @@ -46,10 +46,10 @@ public function testConvertsDateTimeImmutableInstanceToDatabaseValue() : void { $date = $this->getMockBuilder(DateTimeImmutable::class)->getMock(); - $this->platform->expects($this->once()) + $this->platform->expects(self::once()) ->method('getTimeFormatString') ->willReturn('H:i:s'); - $date->expects($this->once()) + $date->expects(self::once()) ->method('format') ->with('H:i:s') ->willReturn('15:58:59'); @@ -86,7 +86,7 @@ public function testConvertsNullToPHPValue() : void public function testConvertsTimeStringToPHPValue() : void { - $this->platform->expects($this->once()) + $this->platform->expects(self::once()) ->method('getTimeFormatString') ->willReturn('H:i:s'); @@ -98,7 +98,7 @@ public function testConvertsTimeStringToPHPValue() : void public function testResetDateFractionsWhenConvertingToPHPValue() : void { - $this->platform->expects($this->any()) + $this->platform->expects(self::any()) ->method('getTimeFormatString') ->willReturn('H:i:s'); diff --git a/tests/Types/VarDateTimeImmutableTypeTest.php b/tests/Types/VarDateTimeImmutableTypeTest.php index 0d976b1e167..85c8f18b397 100644 --- a/tests/Types/VarDateTimeImmutableTypeTest.php +++ b/tests/Types/VarDateTimeImmutableTypeTest.php @@ -44,7 +44,7 @@ public function testConvertsDateTimeImmutableInstanceToDatabaseValue() : void { $date = $this->getMockBuilder(DateTimeImmutable::class)->getMock(); - $date->expects($this->once()) + $date->expects(self::once()) ->method('format') ->with('Y-m-d H:i:s') ->willReturn('2016-01-01 15:58:59'); From 8e4946ad0ae40e2561630409f776d58d700fd112 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 2 Apr 2020 22:34:33 -0700 Subject: [PATCH 04/19] Use the original case in method calls --- src/Driver/OCI8/OCI8Statement.php | 2 +- src/Platforms/SqlitePlatform.php | 4 ++-- tests/Functional/ConnectionTest.php | 2 +- .../Schema/SchemaManagerFunctionalTestCase.php | 10 +++++----- tests/Platforms/AbstractPostgreSQLPlatformTestCase.php | 8 ++++---- tests/Platforms/SQLAnywhere16PlatformTest.php | 2 +- tests/Schema/ColumnTest.php | 2 +- tests/Types/StringTest.php | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Driver/OCI8/OCI8Statement.php b/src/Driver/OCI8/OCI8Statement.php index 27bc78cf4df..adc00360c5e 100644 --- a/src/Driver/OCI8/OCI8Statement.php +++ b/src/Driver/OCI8/OCI8Statement.php @@ -291,7 +291,7 @@ public function bindParam($param, &$variable, $type = ParameterType::STRING, $le $class = 'OCI-Lob'; assert($lob instanceof $class); - $lob->writeTemporary($variable, OCI_TEMP_BLOB); + $lob->writetemporary($variable, OCI_TEMP_BLOB); $variable =& $lob; } diff --git a/src/Platforms/SqlitePlatform.php b/src/Platforms/SqlitePlatform.php index 52db479bd39..aef36b7758e 100644 --- a/src/Platforms/SqlitePlatform.php +++ b/src/Platforms/SqlitePlatform.php @@ -227,7 +227,7 @@ public function getBigIntTypeDeclarationSQL(array $field) * * @return string */ - public function getTinyIntTypeDeclarationSql(array $field) + public function getTinyIntTypeDeclarationSQL(array $field) { // SQLite autoincrement is implicit for INTEGER PKs, but not for TINYINT fields. if (! empty($field['autoincrement'])) { @@ -255,7 +255,7 @@ public function getSmallIntTypeDeclarationSQL(array $field) * * @return string */ - public function getMediumIntTypeDeclarationSql(array $field) + public function getMediumIntTypeDeclarationSQL(array $field) { // SQLite autoincrement is implicit for INTEGER PKs, but not for MEDIUMINT fields. if (! empty($field['autoincrement'])) { diff --git a/tests/Functional/ConnectionTest.php b/tests/Functional/ConnectionTest.php index 174dd02b89c..0e06cc1a14b 100644 --- a/tests/Functional/ConnectionTest.php +++ b/tests/Functional/ConnectionTest.php @@ -111,7 +111,7 @@ public function testTransactionNestingLevelIsResetOnReconnect() : void $connection->beginTransaction(); $connection->executeQuery('insert into test_nesting values (33)'); - $connection->rollback(); + $connection->rollBack(); self::assertEquals(0, $connection->fetchColumn('select count(*) from test_nesting')); } diff --git a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php index 5f61977bebc..c3c28c140be 100644 --- a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -281,11 +281,11 @@ public function testListTableColumns() : void self::assertArrayHasKey('id', $columns); self::assertEquals(0, array_search('id', $columnsKeys)); - self::assertEquals('id', strtolower($columns['id']->getname())); - self::assertInstanceOf(IntegerType::class, $columns['id']->gettype()); - self::assertEquals(false, $columns['id']->getunsigned()); - self::assertEquals(true, $columns['id']->getnotnull()); - self::assertEquals(null, $columns['id']->getdefault()); + self::assertEquals('id', strtolower($columns['id']->getName())); + self::assertInstanceOf(IntegerType::class, $columns['id']->getType()); + self::assertEquals(false, $columns['id']->getUnsigned()); + self::assertEquals(true, $columns['id']->getNotnull()); + self::assertEquals(null, $columns['id']->getDefault()); self::assertIsArray($columns['id']->getPlatformOptions()); self::assertArrayHasKey('test', $columns); diff --git a/tests/Platforms/AbstractPostgreSQLPlatformTestCase.php b/tests/Platforms/AbstractPostgreSQLPlatformTestCase.php index 4ce6252f183..7fc3343eab6 100644 --- a/tests/Platforms/AbstractPostgreSQLPlatformTestCase.php +++ b/tests/Platforms/AbstractPostgreSQLPlatformTestCase.php @@ -199,8 +199,8 @@ public function testGenerateTableWithAutoincrementDoesNotSetDefault(string $type { $table = new Table('autoinc_table_notnull'); $column = $table->addColumn('id', $type); - $column->setAutoIncrement(true); - $column->setNotNull(false); + $column->setAutoincrement(true); + $column->setNotnull(false); $sql = $this->platform->getCreateTableSQL($table); @@ -215,8 +215,8 @@ public function testCreateTableWithAutoincrementAndNotNullAddsConstraint(string { $table = new Table('autoinc_table_notnull_enabled'); $column = $table->addColumn('id', $type); - $column->setAutoIncrement(true); - $column->setNotNull(true); + $column->setAutoincrement(true); + $column->setNotnull(true); $sql = $this->platform->getCreateTableSQL($table); diff --git a/tests/Platforms/SQLAnywhere16PlatformTest.php b/tests/Platforms/SQLAnywhere16PlatformTest.php index dc6c8690d0b..39fd4ffbdef 100644 --- a/tests/Platforms/SQLAnywhere16PlatformTest.php +++ b/tests/Platforms/SQLAnywhere16PlatformTest.php @@ -447,7 +447,7 @@ public function testCannotGenerateInvalidForeignKeyMatchClauseSQL() : void { $this->expectException(InvalidArgumentException::class); - $this->platform->getForeignKeyMatchCLauseSQL(3); + $this->platform->getForeignKeyMatchClauseSQL(3); } public function testCannotGenerateForeignKeyConstraintSQLWithEmptyLocalColumns() : void diff --git a/tests/Schema/ColumnTest.php b/tests/Schema/ColumnTest.php index 51da77a5f6d..5668b261cf6 100644 --- a/tests/Schema/ColumnTest.php +++ b/tests/Schema/ColumnTest.php @@ -23,7 +23,7 @@ public function testGet() : void self::assertEquals(5, $column->getPrecision()); self::assertEquals(2, $column->getScale()); self::assertTrue($column->getUnsigned()); - self::assertFalse($column->getNotNull()); + self::assertFalse($column->getNotnull()); self::assertTrue($column->getFixed()); self::assertEquals('baz', $column->getDefault()); diff --git a/tests/Types/StringTest.php b/tests/Types/StringTest.php index 3c2b51a3760..684c99e681f 100644 --- a/tests/Types/StringTest.php +++ b/tests/Types/StringTest.php @@ -28,7 +28,7 @@ public function testReturnsSqlDeclarationFromPlatformVarchar() : void ->method('getVarcharTypeDeclarationSQL') ->willReturn('TEST_VARCHAR'); - self::assertEquals('TEST_VARCHAR', $this->type->getSqlDeclaration([], $this->platform)); + self::assertEquals('TEST_VARCHAR', $this->type->getSQLDeclaration([], $this->platform)); } public function testReturnsDefaultLengthFromPlatformVarchar() : void From f30a9a9a78cb2622645c9511d812e776e2588e3f Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 3 Apr 2020 16:02:48 -0700 Subject: [PATCH 05/19] Reworked usages of the short ternary operator --- src/Cache/ArrayStatement.php | 2 +- src/Cache/ResultCacheStatement.php | 2 +- src/Connections/MasterSlaveConnection.php | 2 +- src/Driver/IBMDB2/DB2Statement.php | 12 +++++++--- src/Driver/Mysqli/MysqliStatement.php | 4 ++-- src/Driver/OCI8/OCI8Statement.php | 20 ++++++++++++---- src/Driver/SQLAnywhere/Driver.php | 22 +++++++++--------- .../SQLAnywhere/SQLAnywhereStatement.php | 2 +- src/Driver/SQLSrv/SQLSrvStatement.php | 22 ++++++++++++++---- src/Platforms/AbstractPlatform.php | 8 +++---- src/Platforms/MySqlPlatform.php | 4 +++- src/Platforms/OraclePlatform.php | 2 +- src/Platforms/SQLAnywhere16Platform.php | 4 ++-- src/Platforms/SQLServer2012Platform.php | 4 +++- src/Portability/Statement.php | 4 ++-- src/Schema/AbstractSchemaManager.php | 2 +- src/Schema/Comparator.php | 6 ++--- src/Schema/Schema.php | 2 +- src/Schema/Sequence.php | 12 ++++++++-- src/Schema/SqliteSchemaManager.php | 23 +++++++++++++------ src/Schema/Table.php | 10 ++++++-- tests/FunctionalTestCase.php | 2 +- 22 files changed, 114 insertions(+), 57 deletions(-) diff --git a/src/Cache/ArrayStatement.php b/src/Cache/ArrayStatement.php index 8975cb98514..386226e60f1 100644 --- a/src/Cache/ArrayStatement.php +++ b/src/Cache/ArrayStatement.php @@ -91,7 +91,7 @@ public function fetch($fetchMode = null, ...$args) } $row = $this->data[$this->num++]; - $fetchMode = $fetchMode ?: $this->defaultFetchMode; + $fetchMode = $fetchMode ?? $this->defaultFetchMode; if ($fetchMode === FetchMode::ASSOCIATIVE) { return $row; diff --git a/src/Cache/ResultCacheStatement.php b/src/Cache/ResultCacheStatement.php index b0de89632bb..e174b90eb7e 100644 --- a/src/Cache/ResultCacheStatement.php +++ b/src/Cache/ResultCacheStatement.php @@ -135,7 +135,7 @@ public function fetch($fetchMode = null, ...$args) if ($row) { $this->data[] = $row; - $fetchMode = $fetchMode ?: $this->defaultFetchMode; + $fetchMode = $fetchMode ?? $this->defaultFetchMode; if ($fetchMode === FetchMode::ASSOCIATIVE) { return $row; diff --git a/src/Connections/MasterSlaveConnection.php b/src/Connections/MasterSlaveConnection.php index d15d7b67700..a2db57655ac 100644 --- a/src/Connections/MasterSlaveConnection.php +++ b/src/Connections/MasterSlaveConnection.php @@ -128,7 +128,7 @@ public function isConnectedToMaster() public function connect($connectionName = null) { $requestedConnectionChange = ($connectionName !== null); - $connectionName = $connectionName ?: 'slave'; + $connectionName = $connectionName ?? 'slave'; if ($connectionName !== 'slave' && $connectionName !== 'master') { throw new InvalidArgumentException('Invalid option to connect(), only master or slave allowed.'); diff --git a/src/Driver/IBMDB2/DB2Statement.php b/src/Driver/IBMDB2/DB2Statement.php index 07fc87c08f3..86bebd17323 100644 --- a/src/Driver/IBMDB2/DB2Statement.php +++ b/src/Driver/IBMDB2/DB2Statement.php @@ -160,7 +160,13 @@ public function closeCursor() */ public function columnCount() { - return db2_num_fields($this->stmt) ?: 0; + $count = db2_num_fields($this->stmt); + + if ($count !== false) { + return $count; + } + + return 0; } /** @@ -261,7 +267,7 @@ public function fetch($fetchMode = null, ...$args) return false; } - $fetchMode = $fetchMode ?: $this->defaultFetchMode; + $fetchMode = $fetchMode ?? $this->defaultFetchMode; switch ($fetchMode) { case FetchMode::COLUMN: return $this->fetchColumn(); @@ -346,7 +352,7 @@ public function fetchColumn($columnIndex = 0) */ public function rowCount() : int { - return @db2_num_rows($this->stmt) ? : 0; + return @db2_num_rows($this->stmt); } /** diff --git a/src/Driver/Mysqli/MysqliStatement.php b/src/Driver/Mysqli/MysqliStatement.php index 9d0bdbe10ba..f16025847a2 100644 --- a/src/Driver/Mysqli/MysqliStatement.php +++ b/src/Driver/Mysqli/MysqliStatement.php @@ -314,7 +314,7 @@ public function fetch($fetchMode = null, ...$args) return false; } - $fetchMode = $fetchMode ?: $this->_defaultFetchMode; + $fetchMode = $fetchMode ?? $this->_defaultFetchMode; if ($fetchMode === FetchMode::COLUMN) { return $this->fetchColumn(); @@ -358,7 +358,7 @@ public function fetch($fetchMode = null, ...$args) */ public function fetchAll($fetchMode = null, ...$args) { - $fetchMode = $fetchMode ?: $this->_defaultFetchMode; + $fetchMode = $fetchMode ?? $this->_defaultFetchMode; $rows = []; diff --git a/src/Driver/OCI8/OCI8Statement.php b/src/Driver/OCI8/OCI8Statement.php index adc00360c5e..33ef1c5e6b9 100644 --- a/src/Driver/OCI8/OCI8Statement.php +++ b/src/Driver/OCI8/OCI8Statement.php @@ -346,7 +346,13 @@ public function closeCursor() */ public function columnCount() { - return oci_num_fields($this->_sth) ?: 0; + $count = oci_num_fields($this->_sth); + + if ($count !== false) { + return $count; + } + + return 0; } /** @@ -432,7 +438,7 @@ public function fetch($fetchMode = null, ...$args) return false; } - $fetchMode = $fetchMode ?: $this->_defaultFetchMode; + $fetchMode = $fetchMode ?? $this->_defaultFetchMode; if ($fetchMode === FetchMode::COLUMN) { return $this->fetchColumn(); @@ -457,7 +463,7 @@ public function fetch($fetchMode = null, ...$args) */ public function fetchAll($fetchMode = null, ...$args) { - $fetchMode = $fetchMode ?: $this->_defaultFetchMode; + $fetchMode = $fetchMode ?? $this->_defaultFetchMode; $result = []; @@ -531,6 +537,12 @@ public function fetchColumn($columnIndex = 0) */ public function rowCount() : int { - return oci_num_rows($this->_sth) ?: 0; + $count = oci_num_rows($this->_sth); + + if ($count !== false) { + return $count; + } + + return 0; } } diff --git a/src/Driver/SQLAnywhere/Driver.php b/src/Driver/SQLAnywhere/Driver.php index 9564dc2981d..ede8b745d09 100644 --- a/src/Driver/SQLAnywhere/Driver.php +++ b/src/Driver/SQLAnywhere/Driver.php @@ -51,22 +51,22 @@ 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|null $username User name to use for connection authentication. + * @param string|null $password Password to use for connection authentication. + * @param mixed[] $driverOptions Additional parameters to use for the connection. * * @return string */ private function buildDsn($host, $port, $server, $dbname, $username = null, $password = null, array $driverOptions = []) { - $host = $host ?: 'localhost'; - $port = $port ?: 2638; + $host = $host ?? 'localhost'; + $port = $port ?? 2638; if (! empty($server)) { $server = ';ServerName=' . $server; diff --git a/src/Driver/SQLAnywhere/SQLAnywhereStatement.php b/src/Driver/SQLAnywhere/SQLAnywhereStatement.php index 59ab35cd087..51d9d287c8d 100644 --- a/src/Driver/SQLAnywhere/SQLAnywhereStatement.php +++ b/src/Driver/SQLAnywhere/SQLAnywhereStatement.php @@ -203,7 +203,7 @@ public function fetch($fetchMode = null, ...$args) return false; } - $fetchMode = $fetchMode ?: $this->defaultFetchMode; + $fetchMode = $fetchMode ?? $this->defaultFetchMode; switch ($fetchMode) { case FetchMode::COLUMN: diff --git a/src/Driver/SQLSrv/SQLSrvStatement.php b/src/Driver/SQLSrv/SQLSrvStatement.php index 4ea0aca2418..bb2d61e579e 100644 --- a/src/Driver/SQLSrv/SQLSrvStatement.php +++ b/src/Driver/SQLSrv/SQLSrvStatement.php @@ -209,7 +209,13 @@ public function columnCount() return 0; } - return sqlsrv_num_fields($this->stmt) ?: 0; + $count = sqlsrv_num_fields($this->stmt); + + if ($count !== false) { + return $count; + } + + return 0; } /** @@ -353,14 +359,14 @@ public function fetch($fetchMode = null, ...$args) return false; } - $fetchMode = $fetchMode ?: $this->defaultFetchMode; + $fetchMode = $fetchMode ?? $this->defaultFetchMode; if ($fetchMode === FetchMode::COLUMN) { return $this->fetchColumn(); } if (isset(self::$fetchMap[$fetchMode])) { - return sqlsrv_fetch_array($this->stmt, self::$fetchMap[$fetchMode]) ?: false; + return sqlsrv_fetch_array($this->stmt, self::$fetchMap[$fetchMode]) ?? false; } if (in_array($fetchMode, [FetchMode::STANDARD_OBJECT, FetchMode::CUSTOM_OBJECT], true)) { @@ -372,7 +378,7 @@ public function fetch($fetchMode = null, ...$args) $ctorArgs = $args[1] ?? []; } - return sqlsrv_fetch_object($this->stmt, $className, $ctorArgs) ?: false; + return sqlsrv_fetch_object($this->stmt, $className, $ctorArgs) ?? false; } throw new SQLSrvException('Fetch mode is not supported!'); @@ -430,6 +436,12 @@ public function rowCount() : int return 0; } - return sqlsrv_rows_affected($this->stmt) ?: 0; + $count = sqlsrv_rows_affected($this->stmt); + + if ($count !== false) { + return $count; + } + + return 0; } } diff --git a/src/Platforms/AbstractPlatform.php b/src/Platforms/AbstractPlatform.php index 442dcd1c54a..6c949b71ee8 100644 --- a/src/Platforms/AbstractPlatform.php +++ b/src/Platforms/AbstractPlatform.php @@ -335,8 +335,8 @@ public function getJsonTypeDeclarationSQL(array $field) } /** - * @param int $length - * @param bool $fixed + * @param int|false $length + * @param bool $fixed * * @return string * @@ -350,8 +350,8 @@ protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) /** * Returns the SQL snippet used to declare a BINARY/VARBINARY column type. * - * @param int $length The length of the column. - * @param bool $fixed Whether the column length is fixed. + * @param int|false $length The length of the column. + * @param bool $fixed Whether the column length is fixed. * * @return string * diff --git a/src/Platforms/MySqlPlatform.php b/src/Platforms/MySqlPlatform.php index a6b51d30004..e2042c967ba 100644 --- a/src/Platforms/MySqlPlatform.php +++ b/src/Platforms/MySqlPlatform.php @@ -233,7 +233,9 @@ protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) */ protected function getBinaryTypeDeclarationSQLSnippet($length, $fixed) { - return $fixed ? 'BINARY(' . ($length ?: 255) . ')' : 'VARBINARY(' . ($length ?: 255) . ')'; + return $fixed + ? 'BINARY(' . ($length > 0 ? $length : 255) . ')' + : 'VARBINARY(' . ($length > 0 ? $length : 255) . ')'; } /** diff --git a/src/Platforms/OraclePlatform.php b/src/Platforms/OraclePlatform.php index a1c477ffafe..41cdac58827 100644 --- a/src/Platforms/OraclePlatform.php +++ b/src/Platforms/OraclePlatform.php @@ -338,7 +338,7 @@ protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) */ protected function getBinaryTypeDeclarationSQLSnippet($length, $fixed) { - return 'RAW(' . ($length ?: $this->getBinaryMaxLength()) . ')'; + return 'RAW(' . ($length > 0 ? $length : $this->getBinaryMaxLength()) . ')'; } /** diff --git a/src/Platforms/SQLAnywhere16Platform.php b/src/Platforms/SQLAnywhere16Platform.php index 254f4132647..f6a2211b508 100644 --- a/src/Platforms/SQLAnywhere16Platform.php +++ b/src/Platforms/SQLAnywhere16Platform.php @@ -1444,8 +1444,8 @@ protected function getAdvancedIndexOptionsSQL(Index $index) protected function getBinaryTypeDeclarationSQLSnippet($length, $fixed) { return $fixed - ? 'BINARY(' . ($length ?: $this->getBinaryDefaultLength()) . ')' - : 'VARBINARY(' . ($length ?: $this->getBinaryDefaultLength()) . ')'; + ? 'BINARY(' . ($length > 0 ? $length : $this->getBinaryDefaultLength()) . ')' + : 'VARBINARY(' . ($length > 0 ? $length : $this->getBinaryDefaultLength()) . ')'; } /** diff --git a/src/Platforms/SQLServer2012Platform.php b/src/Platforms/SQLServer2012Platform.php index 94a8452f033..13a298d73f0 100644 --- a/src/Platforms/SQLServer2012Platform.php +++ b/src/Platforms/SQLServer2012Platform.php @@ -1269,7 +1269,9 @@ protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) */ protected function getBinaryTypeDeclarationSQLSnippet($length, $fixed) { - return $fixed ? 'BINARY(' . ($length ?: 255) . ')' : 'VARBINARY(' . ($length ?: 255) . ')'; + return $fixed + ? 'BINARY(' . ($length > 0 ? $length : 255) . ')' + : 'VARBINARY(' . ($length > 0 ? $length : 255) . ')'; } /** diff --git a/src/Portability/Statement.php b/src/Portability/Statement.php index 38173c286d4..252b0424269 100644 --- a/src/Portability/Statement.php +++ b/src/Portability/Statement.php @@ -131,7 +131,7 @@ public function getIterator() */ public function fetch($fetchMode = null, ...$args) { - $fetchMode = $fetchMode ?: $this->defaultFetchMode; + $fetchMode = $fetchMode ?? $this->defaultFetchMode; $row = $this->stmt->fetch($fetchMode, ...$args); @@ -150,7 +150,7 @@ public function fetch($fetchMode = null, ...$args) */ public function fetchAll($fetchMode = null, ...$args) { - $fetchMode = $fetchMode ?: $this->defaultFetchMode; + $fetchMode = $fetchMode ?? $this->defaultFetchMode; $rows = $this->stmt->fetchAll($fetchMode, ...$args); diff --git a/src/Schema/AbstractSchemaManager.php b/src/Schema/AbstractSchemaManager.php index bcffcce91ba..53ef67e226c 100644 --- a/src/Schema/AbstractSchemaManager.php +++ b/src/Schema/AbstractSchemaManager.php @@ -49,7 +49,7 @@ abstract class AbstractSchemaManager public function __construct(Connection $conn, ?AbstractPlatform $platform = null) { $this->_conn = $conn; - $this->_platform = $platform ?: $this->_conn->getDatabasePlatform(); + $this->_platform = $platform ?? $this->_conn->getDatabasePlatform(); } /** diff --git a/src/Schema/Comparator.php b/src/Schema/Comparator.php index 9ccaa9a1efa..598069cb744 100644 --- a/src/Schema/Comparator.php +++ b/src/Schema/Comparator.php @@ -452,8 +452,8 @@ public function diffColumn(Column $column1, Column $column2) $properties1['type'] instanceof Types\BinaryType ) { // check if value of length is set at all, default value assumed otherwise. - $length1 = $properties1['length'] ?: 255; - $length2 = $properties2['length'] ?: 255; + $length1 = $properties1['length'] ?? 255; + $length2 = $properties2['length'] ?? 255; if ($length1 !== $length2) { $changedProperties[] = 'length'; } @@ -462,7 +462,7 @@ public function diffColumn(Column $column1, Column $column2) $changedProperties[] = 'fixed'; } } elseif ($properties1['type'] instanceof Types\DecimalType) { - if (($properties1['precision'] ?: 10) !== ($properties2['precision'] ?: 10)) { + if (($properties1['precision'] ?? 10) !== ($properties2['precision'] ?? 10)) { $changedProperties[] = 'precision'; } if ($properties1['scale'] !== $properties2['scale']) { diff --git a/src/Schema/Schema.php b/src/Schema/Schema.php index 5d746654a40..5d8f248b1cf 100644 --- a/src/Schema/Schema.php +++ b/src/Schema/Schema.php @@ -68,7 +68,7 @@ public function __construct( $schemaConfig = new SchemaConfig(); } $this->_schemaConfig = $schemaConfig; - $this->_setName($schemaConfig->getName() ?: 'public'); + $this->_setName($schemaConfig->getName() ?? 'public'); foreach ($namespaces as $namespace) { $this->createNamespace($namespace); diff --git a/src/Schema/Sequence.php b/src/Schema/Sequence.php index 88891019bfd..79d6fcb34e3 100644 --- a/src/Schema/Sequence.php +++ b/src/Schema/Sequence.php @@ -65,7 +65,11 @@ public function getCache() */ public function setAllocationSize($allocationSize) { - $this->allocationSize = (int) $allocationSize ?: 1; + if ($allocationSize > 0) { + $this->allocationSize = (int) $allocationSize; + } else { + $this->allocationSize = 1; + } return $this; } @@ -77,7 +81,11 @@ public function setAllocationSize($allocationSize) */ public function setInitialValue($initialValue) { - $this->initialValue = (int) $initialValue ?: 1; + if ($initialValue > 0) { + $this->initialValue = (int) $initialValue; + } else { + $this->initialValue = 1; + } return $this; } diff --git a/src/Schema/SqliteSchemaManager.php b/src/Schema/SqliteSchemaManager.php index 68e1e1f8487..133481af0ae 100644 --- a/src/Schema/SqliteSchemaManager.php +++ b/src/Schema/SqliteSchemaManager.php @@ -119,7 +119,7 @@ public function listTableForeignKeys($table, $database = null) if (! empty($tableForeignKeys)) { $createSql = $this->getCreateTableSQL($table); - if ($createSql !== null && preg_match_all( + if (preg_match_all( '# (?:CONSTRAINT\s+([^\s]+)\s+)? (?:FOREIGN\s+KEY[^\)]+\)\s*)? @@ -272,13 +272,16 @@ protected function _getPortableTableColumnList($table, $database, $tableColumns) } // inspect column collation and comments - $createSql = $this->getCreateTableSQL($table) ?? ''; + $createSql = $this->getCreateTableSQL($table); foreach ($list as $columnName => $column) { $type = $column->getType(); if ($type instanceof StringType || $type instanceof TextType) { - $column->setPlatformOption('collation', $this->parseColumnCollationFromSQL($columnName, $createSql) ?: 'BINARY'); + $column->setPlatformOption( + 'collation', + $this->parseColumnCollationFromSQL($columnName, $createSql) ?? 'BINARY' + ); } $comment = $this->parseColumnCommentFromSQL($columnName, $createSql); @@ -507,9 +510,9 @@ private function parseColumnCommentFromSQL(string $column, string $sql) : ?strin return $comment === '' ? null : $comment; } - private function getCreateTableSQL(string $table) : ?string + private function getCreateTableSQL(string $table) : string { - return $this->_conn->fetchColumn( + $sql = $this->_conn->fetchColumn( <<<'SQL' SELECT sql FROM ( @@ -524,7 +527,13 @@ private function getCreateTableSQL(string $table) : ?string SQL , [$table] - ) ?: null; + ); + + if ($sql !== false) { + return $sql; + } + + return ''; } /** @@ -534,7 +543,7 @@ public function listTableDetails($tableName) : Table { $table = parent::listTableDetails($tableName); - $tableCreateSql = $this->getCreateTableSQL($tableName) ?? ''; + $tableCreateSql = $this->getCreateTableSQL($tableName); $comment = $this->parseTableCommentFromSQL($tableName, $tableCreateSql); diff --git a/src/Schema/Table.php b/src/Schema/Table.php index 03743b83642..b0de96aaf63 100644 --- a/src/Schema/Table.php +++ b/src/Schema/Table.php @@ -104,7 +104,11 @@ protected function _getMaxIdentifierLength() */ public function setPrimaryKey(array $columnNames, $indexName = false) { - $this->_addIndex($this->_createIndex($columnNames, $indexName ?: 'primary', true, true)); + if ($indexName === false) { + $indexName = 'primary'; + } + + $this->_addIndex($this->_createIndex($columnNames, $indexName, true, true)); foreach ($columnNames as $columnName) { $column = $this->getColumn($columnName); @@ -361,7 +365,9 @@ public function dropColumn($columnName) */ public function addForeignKeyConstraint($foreignTable, array $localColumnNames, array $foreignColumnNames, array $options = [], $constraintName = null) { - $constraintName = $constraintName ?: $this->_generateIdentifierName(array_merge((array) $this->getName(), $localColumnNames), 'fk', $this->_getMaxIdentifierLength()); + if ($constraintName === null) { + $constraintName = $this->_generateIdentifierName(array_merge((array) $this->getName(), $localColumnNames), 'fk', $this->_getMaxIdentifierLength()); + } return $this->addNamedForeignKeyConstraint($constraintName, $foreignTable, $localColumnNames, $foreignColumnNames, $options); } diff --git a/tests/FunctionalTestCase.php b/tests/FunctionalTestCase.php index a8d425607e5..15622b6f1e7 100644 --- a/tests/FunctionalTestCase.php +++ b/tests/FunctionalTestCase.php @@ -82,7 +82,7 @@ protected function onNotSuccessfulTest(Throwable $t) : void } return var_export($p, true); - }, $query['params'] ?: []); + }, $query['params'] ?? []); $queries .= $i . ". SQL: '" . $query['sql'] . "' Params: " . implode(', ', $params) . PHP_EOL; $i--; } From 6c4401f45711d47f62f8c35ff05310ac4f8c3a67 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 3 Apr 2020 16:47:08 -0700 Subject: [PATCH 06/19] Reworked all possible usages of the empty() construct and whitelisted the rest --- phpstan.neon.dist | 10 ++++++++++ src/Connection.php | 7 ++++--- src/Driver/AbstractOracleDriver/EasyConnectString.php | 8 ++++---- src/Driver/PDOSqlsrv/Driver.php | 2 +- src/Query/Expression/CompositeExpression.php | 2 +- src/Query/QueryBuilder.php | 9 +++++---- src/Schema/Comparator.php | 2 +- 7 files changed, 26 insertions(+), 14 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 7025810deae..a6108c92579 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -78,5 +78,15 @@ parameters: - message: '~^Call to static method PHPUnit\\Framework\\Assert::assertSame\(\) with Doctrine\\DBAL\\Types\\Type and Doctrine\\DBAL\\Types\\Type will always evaluate to true\.$~' path: %currentWorkingDirectory%/tests/Types/TypeRegistryTest.php + + # https://github.com/phpstan/phpstan-strict-rules/issues/103 + - + message: '~^Construct empty\(\) is not allowed. Use more strict comparison\.~' + paths: + - %currentWorkingDirectory%/src/Driver/*/*Connection.php + - %currentWorkingDirectory%/src/Driver/*/Driver.php + - %currentWorkingDirectory%/src/Driver/AbstractOracleDriver/EasyConnectString.php + - %currentWorkingDirectory%/src/Platforms/*Platform.php + - %currentWorkingDirectory%/src/Schema/*SchemaManager.php includes: - vendor/phpstan/phpstan-strict-rules/rules.neon diff --git a/src/Connection.php b/src/Connection.php index b85e0b65431..5dc99a6d2b1 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -23,6 +23,7 @@ use Throwable; use function array_key_exists; use function assert; +use function count; use function implode; use function is_int; use function is_string; @@ -420,7 +421,7 @@ private function getDatabasePlatformVersion() try { $this->connect(); } catch (Throwable $originalException) { - if (empty($this->params['dbname'])) { + if (! isset($this->params['dbname'])) { throw $originalException; } @@ -647,7 +648,7 @@ private function addIdentifierCondition( */ public function delete($tableExpression, array $identifier, array $types = []) { - if (empty($identifier)) { + if (count($identifier) === 0) { throw InvalidArgumentException::fromEmptyCriteria(); } @@ -753,7 +754,7 @@ public function update($tableExpression, array $data, array $identifier, array $ */ public function insert($tableExpression, array $data, array $types = []) { - if (empty($data)) { + if (count($data) === 0) { return $this->executeUpdate('INSERT INTO ' . $tableExpression . ' () VALUES ()'); } diff --git a/src/Driver/AbstractOracleDriver/EasyConnectString.php b/src/Driver/AbstractOracleDriver/EasyConnectString.php index 01f648b3b85..2499112d9ff 100644 --- a/src/Driver/AbstractOracleDriver/EasyConnectString.php +++ b/src/Driver/AbstractOracleDriver/EasyConnectString.php @@ -45,11 +45,11 @@ public static function fromArray(array $params) : self */ public static function fromConnectionParameters(array $params) : self { - if (! empty($params['connectstring'])) { + if (isset($params['connectstring'])) { return new self($params['connectstring']); } - if (empty($params['host'])) { + if (! isset($params['host'])) { return new self($params['dbname'] ?? ''); } @@ -58,7 +58,7 @@ public static function fromConnectionParameters(array $params) : self if (isset($params['servicename']) || isset($params['dbname'])) { $serviceKey = 'SID'; - if (! empty($params['service'])) { + if (isset($params['service'])) { $serviceKey = 'SERVICE_NAME'; } @@ -67,7 +67,7 @@ public static function fromConnectionParameters(array $params) : self $connectData[$serviceKey] = $serviceName; } - if (! empty($params['instancename'])) { + if (isset($params['instancename'])) { $connectData['INSTANCE_NAME'] = $params['instancename']; } diff --git a/src/Driver/PDOSqlsrv/Driver.php b/src/Driver/PDOSqlsrv/Driver.php index 5fbba4c245f..a9fbfea042f 100644 --- a/src/Driver/PDOSqlsrv/Driver.php +++ b/src/Driver/PDOSqlsrv/Driver.php @@ -55,7 +55,7 @@ private function _constructPdoDsn(array $params, array $connectionOptions) $dsn .= $params['host']; } - if (isset($params['port']) && ! empty($params['port'])) { + if (isset($params['port'])) { $dsn .= ',' . $params['port']; } diff --git a/src/Query/Expression/CompositeExpression.php b/src/Query/Expression/CompositeExpression.php index 21e8d6bf2f5..ba2ffbc28b1 100644 --- a/src/Query/Expression/CompositeExpression.php +++ b/src/Query/Expression/CompositeExpression.php @@ -96,7 +96,7 @@ public function addMultiple(array $parts = []) */ public function add($part) { - if (empty($part)) { + if ($part === null) { return $this; } diff --git a/src/Query/QueryBuilder.php b/src/Query/QueryBuilder.php index 40e52261719..913308a96c5 100644 --- a/src/Query/QueryBuilder.php +++ b/src/Query/QueryBuilder.php @@ -10,6 +10,7 @@ use function array_key_exists; use function array_keys; use function array_unshift; +use function count; use function func_get_args; use function func_num_args; use function implode; @@ -468,7 +469,7 @@ public function select($select = null/*, string ...$selects*/) { $this->type = self::SELECT; - if (empty($select)) { + if ($select === null) { return $this; } @@ -518,7 +519,7 @@ public function addSelect($select = null/*, string ...$selects*/) { $this->type = self::SELECT; - if (empty($select)) { + if ($select === null) { return $this; } @@ -890,7 +891,7 @@ public function orWhere($where) */ public function groupBy($groupBy/*, string ...$groupBys*/) { - if (empty($groupBy)) { + if (is_array($groupBy) && count($groupBy) === 0) { return $this; } @@ -919,7 +920,7 @@ public function groupBy($groupBy/*, string ...$groupBys*/) */ public function addGroupBy($groupBy/*, string ...$groupBys*/) { - if (empty($groupBy)) { + if (is_array($groupBy) && count($groupBy) === 0) { return $this; } diff --git a/src/Schema/Comparator.php b/src/Schema/Comparator.php index 598069cb744..3663e6162e2 100644 --- a/src/Schema/Comparator.php +++ b/src/Schema/Comparator.php @@ -217,7 +217,7 @@ public function diffTable(Table $table1, Table $table2) // See if column has changed properties in table 2. $changedProperties = $this->diffColumn($column, $table2->getColumn($columnName)); - if (empty($changedProperties)) { + if (count($changedProperties) === 0) { continue; } From 7336ae0a4a553b6fdc08fbfe2b311771c8240159 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 2 Apr 2020 23:36:05 -0700 Subject: [PATCH 07/19] Avoid implicit conversion to boolean --- phpstan.neon.dist | 9 ++++ src/Cache/ArrayStatement.php | 2 +- src/Cache/ResultCacheStatement.php | 4 +- src/Configuration.php | 4 +- src/Connection.php | 52 +++++++++---------- src/Connections/MasterSlaveConnection.php | 4 +- src/DBALException.php | 5 +- src/Driver/AbstractMySQLDriver.php | 8 +-- src/Driver/AbstractPostgreSQLDriver.php | 2 +- src/Driver/AbstractSQLAnywhereDriver.php | 4 +- src/Driver/IBMDB2/DB2Connection.php | 2 +- src/Driver/OCI8/OCI8Connection.php | 2 +- src/Driver/OCI8/OCI8Statement.php | 9 ++-- .../SQLAnywhere/SQLAnywhereException.php | 10 ++-- .../SQLAnywhere/SQLAnywhereStatement.php | 3 +- src/Driver/SQLSrv/SQLSrvConnection.php | 2 +- src/Driver/SQLSrv/SQLSrvException.php | 2 +- src/Driver/SQLSrv/SQLSrvStatement.php | 11 ++-- src/DriverManager.php | 4 +- src/Event/Listeners/MysqlSessionInit.php | 9 +++- src/Event/Listeners/OracleSessionInit.php | 2 +- src/Platforms/AbstractPlatform.php | 17 +++--- src/Platforms/DB2Platform.php | 10 ++-- .../Keywords/ReservedKeywordsValidator.php | 3 +- src/Platforms/MySqlPlatform.php | 10 ++-- src/Platforms/OraclePlatform.php | 30 ++++++----- src/Platforms/PostgreSQL94Platform.php | 10 ++-- src/Platforms/SQLAnywhere16Platform.php | 8 +-- src/Platforms/SQLServer2012Platform.php | 24 +++++---- src/Platforms/SqlitePlatform.php | 12 ++--- src/Portability/Connection.php | 2 +- src/Portability/Statement.php | 26 +++++----- src/Query/QueryBuilder.php | 10 ++-- src/SQLParserUtils.php | 6 +-- src/Schema/AbstractAsset.php | 4 +- src/Schema/AbstractSchemaManager.php | 36 ++++--------- src/Schema/ColumnDiff.php | 2 +- src/Schema/Comparator.php | 2 +- src/Schema/DB2SchemaManager.php | 2 +- src/Schema/MySqlSchemaManager.php | 8 ++- src/Schema/OracleSchemaManager.php | 6 +-- src/Schema/PostgreSqlSchemaManager.php | 39 ++++++++++---- src/Schema/SQLServerSchemaManager.php | 2 +- src/Schema/SqliteSchemaManager.php | 4 +- src/Schema/Table.php | 6 +-- src/Statement.php | 9 ++-- .../Console/Command/ReservedWordsCommand.php | 2 +- src/Tools/Console/Command/RunSqlCommand.php | 6 ++- src/Types/DateImmutableType.php | 2 +- src/Types/DateTimeImmutableType.php | 4 +- src/Types/DateTimeType.php | 4 +- src/Types/DateTimeTzImmutableType.php | 2 +- src/Types/DateTimeTzType.php | 2 +- src/Types/DateType.php | 2 +- src/Types/SimpleArrayType.php | 4 +- src/Types/TimeImmutableType.php | 2 +- src/Types/TimeType.php | 2 +- src/Types/VarDateTimeImmutableType.php | 2 +- src/Types/VarDateTimeType.php | 2 +- tests/FunctionalTestCase.php | 2 +- 60 files changed, 252 insertions(+), 224 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index a6108c92579..da93a164f30 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -88,5 +88,14 @@ parameters: - %currentWorkingDirectory%/src/Driver/AbstractOracleDriver/EasyConnectString.php - %currentWorkingDirectory%/src/Platforms/*Platform.php - %currentWorkingDirectory%/src/Schema/*SchemaManager.php + + # In some namespaces, we use array, some elements of which are actually boolean + - + message: '~^Only booleans are allowed in .*, mixed given~' + paths: + - %currentWorkingDirectory%/src/Driver/*/Driver.php + - %currentWorkingDirectory%/src/Platforms/*Platform.php + - %currentWorkingDirectory%/src/Query/QueryBuilder.php + - %currentWorkingDirectory%/src/Schema/*SchemaManager.php includes: - vendor/phpstan/phpstan-strict-rules/rules.neon diff --git a/src/Cache/ArrayStatement.php b/src/Cache/ArrayStatement.php index 386226e60f1..38e337e800a 100644 --- a/src/Cache/ArrayStatement.php +++ b/src/Cache/ArrayStatement.php @@ -32,7 +32,7 @@ class ArrayStatement implements IteratorAggregate, ResultStatement public function __construct(array $data) { $this->data = $data; - if (! count($data)) { + if (count($data) === 0) { return; } diff --git a/src/Cache/ResultCacheStatement.php b/src/Cache/ResultCacheStatement.php index e174b90eb7e..36f01880423 100644 --- a/src/Cache/ResultCacheStatement.php +++ b/src/Cache/ResultCacheStatement.php @@ -82,7 +82,7 @@ public function closeCursor() } $data = $this->resultCache->fetch($this->cacheKey); - if (! $data) { + if ($data === false) { $data = []; } $data[$this->realKey] = $this->data; @@ -132,7 +132,7 @@ public function fetch($fetchMode = null, ...$args) $row = $this->statement->fetch(FetchMode::ASSOCIATIVE); - if ($row) { + if ($row !== false) { $this->data[] = $row; $fetchMode = $fetchMode ?? $this->defaultFetchMode; diff --git a/src/Configuration.php b/src/Configuration.php index 13260cd08bb..442062c2af6 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -72,14 +72,14 @@ public function setResultCacheImpl(Cache $cacheImpl) * * @deprecated Use Configuration::setSchemaAssetsFilter() instead * - * @param string $filterExpression + * @param string|null $filterExpression * * @return void */ public function setFilterSchemaAssetsExpression($filterExpression) { $this->_attributes['filterSchemaAssetsExpression'] = $filterExpression; - if ($filterExpression) { + if ($filterExpression !== null) { $this->_attributes['filterSchemaAssetsExpressionCallable'] = $this->buildSchemaAssetsFilterFromExpression($filterExpression); } else { $this->_attributes['filterSchemaAssetsExpressionCallable'] = null; diff --git a/src/Connection.php b/src/Connection.php index 5dc99a6d2b1..cca1716625f 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -197,11 +197,11 @@ public function __construct( } // Create default config and event manager if none given - if (! $config) { + if ($config === null) { $config = new Configuration(); } - if (! $eventManager) { + if ($eventManager === null) { $eventManager = new EventManager(); } @@ -884,16 +884,16 @@ public function executeQuery(string $query, array $params = [], $types = [], ?Qu $connection = $this->getWrappedConnection(); $logger = $this->_config->getSQLLogger(); - if ($logger) { + if ($logger !== null) { $logger->startQuery($query, $params, $types); } try { - if ($params) { + if (count($params) > 0) { [$query, $params, $types] = SQLParserUtils::expandListParameters($query, $params, $types); $stmt = $connection->prepare($query); - if ($types) { + if (count($types) > 0) { $this->_bindTypedValues($stmt, $params, $types); $stmt->execute(); } else { @@ -908,7 +908,7 @@ public function executeQuery(string $query, array $params = [], $types = [], ?Qu $stmt->setFetchMode($this->defaultFetchMode); - if ($logger) { + if ($logger !== null) { $logger->stopQuery(); } @@ -993,7 +993,7 @@ public function query(string $sql) : ResultStatement $connection = $this->getWrappedConnection(); $logger = $this->_config->getSQLLogger(); - if ($logger) { + if ($logger !== null) { $logger->startQuery($sql); } @@ -1005,7 +1005,7 @@ public function query(string $sql) : ResultStatement $statement->setFetchMode($this->defaultFetchMode); - if ($logger) { + if ($logger !== null) { $logger->stopQuery(); } @@ -1029,17 +1029,17 @@ public function executeUpdate(string $query, array $params = [], array $types = $connection = $this->getWrappedConnection(); $logger = $this->_config->getSQLLogger(); - if ($logger) { + if ($logger !== null) { $logger->startQuery($query, $params, $types); } try { - if ($params) { + if (count($params) > 0) { [$query, $params, $types] = SQLParserUtils::expandListParameters($query, $params, $types); $stmt = $connection->prepare($query); - if ($types) { + if (count($types) > 0) { $this->_bindTypedValues($stmt, $params, $types); $stmt->execute(); } else { @@ -1053,7 +1053,7 @@ public function executeUpdate(string $query, array $params = [], array $types = throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $query, $this->resolveParams($params, $types)); } - if ($logger) { + if ($logger !== null) { $logger->stopQuery(); } @@ -1068,7 +1068,7 @@ public function exec(string $statement) : int $connection = $this->getWrappedConnection(); $logger = $this->_config->getSQLLogger(); - if ($logger) { + if ($logger !== null) { $logger->startQuery($statement); } @@ -1078,7 +1078,7 @@ public function exec(string $statement) : int throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $statement); } - if ($logger) { + if ($logger !== null) { $logger->stopQuery(); } @@ -1217,21 +1217,21 @@ public function beginTransaction() $logger = $this->_config->getSQLLogger(); if ($this->transactionNestingLevel === 1) { - if ($logger) { + if ($logger !== null) { $logger->startQuery('"START TRANSACTION"'); } $connection->beginTransaction(); - if ($logger) { + if ($logger !== null) { $logger->stopQuery(); } } elseif ($this->nestTransactionsWithSavepoints) { - if ($logger) { + if ($logger !== null) { $logger->startQuery('"SAVEPOINT"'); } $this->createSavepoint($this->_getNestedTransactionSavePointName()); - if ($logger) { + if ($logger !== null) { $logger->stopQuery(); } } @@ -1261,21 +1261,21 @@ public function commit() $logger = $this->_config->getSQLLogger(); if ($this->transactionNestingLevel === 1) { - if ($logger) { + if ($logger !== null) { $logger->startQuery('"COMMIT"'); } $result = $connection->commit(); - if ($logger) { + if ($logger !== null) { $logger->stopQuery(); } } elseif ($this->nestTransactionsWithSavepoints) { - if ($logger) { + if ($logger !== null) { $logger->startQuery('"RELEASE SAVEPOINT"'); } $this->releaseSavepoint($this->_getNestedTransactionSavePointName()); - if ($logger) { + if ($logger !== null) { $logger->stopQuery(); } } @@ -1327,13 +1327,13 @@ public function rollBack() $logger = $this->_config->getSQLLogger(); if ($this->transactionNestingLevel === 1) { - if ($logger) { + if ($logger !== null) { $logger->startQuery('"ROLLBACK"'); } $this->transactionNestingLevel = 0; $connection->rollBack(); $this->isRollbackOnly = false; - if ($logger) { + if ($logger !== null) { $logger->stopQuery(); } @@ -1341,12 +1341,12 @@ public function rollBack() $this->beginTransaction(); } } elseif ($this->nestTransactionsWithSavepoints) { - if ($logger) { + if ($logger !== null) { $logger->startQuery('"ROLLBACK TO SAVEPOINT"'); } $this->rollbackSavepoint($this->_getNestedTransactionSavePointName()); --$this->transactionNestingLevel; - if ($logger) { + if ($logger !== null) { $logger->stopQuery(); } } else { diff --git a/src/Connections/MasterSlaveConnection.php b/src/Connections/MasterSlaveConnection.php index a2db57655ac..e163a3f5495 100644 --- a/src/Connections/MasterSlaveConnection.php +++ b/src/Connections/MasterSlaveConnection.php @@ -351,7 +351,7 @@ public function query(string $sql) : ResultStatement assert($this->_conn instanceof DriverConnection); $logger = $this->getConfiguration()->getSQLLogger(); - if ($logger) { + if ($logger !== null) { $logger->startQuery($sql); } @@ -359,7 +359,7 @@ public function query(string $sql) : ResultStatement $statement->setFetchMode($this->defaultFetchMode); - if ($logger) { + if ($logger !== null) { $logger->stopQuery(); } diff --git a/src/DBALException.php b/src/DBALException.php index fe706daffcf..403f5394bb8 100644 --- a/src/DBALException.php +++ b/src/DBALException.php @@ -11,6 +11,7 @@ use Throwable; use function array_map; use function bin2hex; +use function count; use function get_class; use function gettype; use function implode; @@ -103,7 +104,7 @@ public static function invalidPdoInstance() */ public static function driverRequired($url = null) { - if ($url) { + if ($url !== null) { return new self( sprintf( "The options 'driver' or 'driverClass' are mandatory if a connection URL without scheme " . @@ -138,7 +139,7 @@ public static function unknownDriver($unknownDriverName, array $knownDrivers) public static function driverExceptionDuringQuery(Driver $driver, Throwable $driverEx, $sql, array $params = []) { $msg = "An exception occurred while executing '" . $sql . "'"; - if ($params) { + if (count($params) > 0) { $msg .= ' with params ' . self::formatParameters($params); } $msg .= ":\n\n" . $driverEx->getMessage(); diff --git a/src/Driver/AbstractMySQLDriver.php b/src/Driver/AbstractMySQLDriver.php index 0ac3c7484f7..68177207326 100644 --- a/src/Driver/AbstractMySQLDriver.php +++ b/src/Driver/AbstractMySQLDriver.php @@ -140,11 +140,11 @@ public function createDatabasePlatformForVersion($version) */ private function getOracleMysqlVersionNumber(string $versionString) : string { - if (! preg_match( + if (preg_match( '/^(?P\d+)(?:\.(?P\d+)(?:\.(?P\d+))?)?/', $versionString, $versionParts - )) { + ) === 0) { throw DBALException::invalidPlatformVersionSpecified( $versionString, '..' @@ -171,11 +171,11 @@ private function getOracleMysqlVersionNumber(string $versionString) : string */ private function getMariaDbMysqlVersionNumber(string $versionString) : string { - if (! preg_match( + if (preg_match( '/^(?:5\.5\.5-)?(mariadb-)?(?P\d+)\.(?P\d+)\.(?P\d+)/i', $versionString, $versionParts - )) { + ) === 0) { throw DBALException::invalidPlatformVersionSpecified( $versionString, '^(?:5\.5\.5-)?(mariadb-)?..' diff --git a/src/Driver/AbstractPostgreSQLDriver.php b/src/Driver/AbstractPostgreSQLDriver.php index 35b473ea06a..f424e452706 100644 --- a/src/Driver/AbstractPostgreSQLDriver.php +++ b/src/Driver/AbstractPostgreSQLDriver.php @@ -80,7 +80,7 @@ public function convertException($message, DriverException $exception) */ public function createDatabasePlatformForVersion($version) { - if (! preg_match('/^(?P\d+)(?:\.(?P\d+)(?:\.(?P\d+))?)?/', $version, $versionParts)) { + if (preg_match('/^(?P\d+)(?:\.(?P\d+)(?:\.(?P\d+))?)?/', $version, $versionParts) === 0) { throw DBALException::invalidPlatformVersionSpecified( $version, '..' diff --git a/src/Driver/AbstractSQLAnywhereDriver.php b/src/Driver/AbstractSQLAnywhereDriver.php index bc1ef504aef..ffe2f2b1ebb 100644 --- a/src/Driver/AbstractSQLAnywhereDriver.php +++ b/src/Driver/AbstractSQLAnywhereDriver.php @@ -65,11 +65,11 @@ public function convertException($message, DriverException $exception) */ public function createDatabasePlatformForVersion($version) { - if (! preg_match( + if (preg_match( '/^(?P\d+)(?:\.(?P\d+)(?:\.(?P\d+)(?:\.(?P\d+))?)?)?/', $version, $versionParts - )) { + ) === 0) { throw DBALException::invalidPlatformVersionSpecified( $version, '...' diff --git a/src/Driver/IBMDB2/DB2Connection.php b/src/Driver/IBMDB2/DB2Connection.php index 6d8c94764cb..a18fa067d7c 100644 --- a/src/Driver/IBMDB2/DB2Connection.php +++ b/src/Driver/IBMDB2/DB2Connection.php @@ -81,7 +81,7 @@ public function requiresQueryForServerVersion() public function prepare(string $sql) : DriverStatement { $stmt = @db2_prepare($this->conn, $sql); - if (! $stmt) { + if ($stmt === false) { throw new DB2Exception(db2_stmt_errormsg()); } diff --git a/src/Driver/OCI8/OCI8Connection.php b/src/Driver/OCI8/OCI8Connection.php index ce651559eb5..43d6fb45ab5 100644 --- a/src/Driver/OCI8/OCI8Connection.php +++ b/src/Driver/OCI8/OCI8Connection.php @@ -80,7 +80,7 @@ public function getServerVersion() throw OCI8Exception::fromErrorInfo(oci_error($this->dbh)); } - if (! preg_match('/\s+(\d+\.\d+\.\d+\.\d+\.\d+)\s+/', $version, $matches)) { + if (preg_match('/\s+(\d+\.\d+\.\d+\.\d+\.\d+)\s+/', $version, $matches) === 0) { throw new UnexpectedValueException( sprintf( 'Unexpected database version string "%s". Cannot parse an appropriate version number from it. ' . diff --git a/src/Driver/OCI8/OCI8Statement.php b/src/Driver/OCI8/OCI8Statement.php index 33ef1c5e6b9..f8a030395ff 100644 --- a/src/Driver/OCI8/OCI8Statement.php +++ b/src/Driver/OCI8/OCI8Statement.php @@ -191,7 +191,7 @@ private static function findPlaceholderOrOpeningQuote( ) { $token = self::findToken($statement, $tokenOffset, '/[?\'"]/'); - if (! $token) { + if ($token === null) { return false; } @@ -233,7 +233,7 @@ private static function findClosingQuote( '/' . preg_quote($currentLiteralDelimiter, '/') . '/' ); - if (! $token) { + if ($token === null) { return false; } @@ -255,7 +255,7 @@ private static function findClosingQuote( */ private static function findToken($statement, &$offset, $regex) { - if (preg_match($regex, $statement, $matches, PREG_OFFSET_CAPTURE, $offset)) { + if (preg_match($regex, $statement, $matches, PREG_OFFSET_CAPTURE, $offset) === 1) { $offset = $matches[0][1]; return $matches[0][0]; @@ -387,9 +387,8 @@ public function errorInfo() */ public function execute($params = null) { - if ($params) { + if ($params !== null) { $hasZeroIndex = array_key_exists(0, $params); - foreach ($params as $key => $val) { if ($hasZeroIndex && is_int($key)) { $this->bindValue($key + 1, $val); diff --git a/src/Driver/SQLAnywhere/SQLAnywhereException.php b/src/Driver/SQLAnywhere/SQLAnywhereException.php index 0f8bc3e57e6..5f636bb0610 100644 --- a/src/Driver/SQLAnywhere/SQLAnywhereException.php +++ b/src/Driver/SQLAnywhere/SQLAnywhereException.php @@ -27,14 +27,14 @@ class SQLAnywhereException extends AbstractDriverException */ public static function fromSQLAnywhereError($conn = null, $stmt = null) { - $state = $conn ? sasql_sqlstate($conn) : sasql_sqlstate(); - $code = null; + $state = $conn !== null ? sasql_sqlstate($conn) : sasql_sqlstate(); + $code = 0; $message = null; /** * Try retrieving the last error from statement resource if given */ - if ($stmt) { + if ($stmt !== null) { $code = sasql_stmt_errno($stmt); $message = sasql_stmt_error($stmt); } @@ -47,7 +47,7 @@ public static function fromSQLAnywhereError($conn = null, $stmt = null) * it from the connection resource even though it occurred during * a prepared statement. */ - if ($conn && ! $code) { + if ($conn !== null && $code === 0) { $code = sasql_errorcode($conn); $message = sasql_error($conn); } @@ -57,7 +57,7 @@ public static function fromSQLAnywhereError($conn = null, $stmt = null) * or the last error could not be retrieved from the given * connection / statement resource. */ - if (! $conn || ! $code) { + if ($conn === null || $code === 0) { $code = sasql_errorcode(); $message = sasql_error(); } diff --git a/src/Driver/SQLAnywhere/SQLAnywhereStatement.php b/src/Driver/SQLAnywhere/SQLAnywhereStatement.php index 51d9d287c8d..e1dbd770c93 100644 --- a/src/Driver/SQLAnywhere/SQLAnywhereStatement.php +++ b/src/Driver/SQLAnywhere/SQLAnywhereStatement.php @@ -14,7 +14,6 @@ use function array_key_exists; use function count; use function gettype; -use function is_array; use function is_int; use function is_object; use function is_resource; @@ -171,7 +170,7 @@ public function errorInfo() */ public function execute($params = null) { - if (is_array($params)) { + if ($params !== null) { $hasZeroIndex = array_key_exists(0, $params); foreach ($params as $key => $val) { diff --git a/src/Driver/SQLSrv/SQLSrvConnection.php b/src/Driver/SQLSrv/SQLSrvConnection.php index 437ec509e99..d2911254b04 100644 --- a/src/Driver/SQLSrv/SQLSrvConnection.php +++ b/src/Driver/SQLSrv/SQLSrvConnection.php @@ -184,7 +184,7 @@ public function rollBack() public function errorCode() { $errors = sqlsrv_errors(SQLSRV_ERR_ERRORS); - if ($errors) { + if ($errors !== null) { return $errors[0]['code']; } diff --git a/src/Driver/SQLSrv/SQLSrvException.php b/src/Driver/SQLSrv/SQLSrvException.php index 1c1e8c472d7..63463c18b37 100644 --- a/src/Driver/SQLSrv/SQLSrvException.php +++ b/src/Driver/SQLSrv/SQLSrvException.php @@ -34,7 +34,7 @@ public static function fromSqlSrvErrors() $errorCode = $error['code']; } - if (! $message) { + if ($message === '') { $message = 'SQL Server error occurred but no error message was retrieved from driver.'; } diff --git a/src/Driver/SQLSrv/SQLSrvStatement.php b/src/Driver/SQLSrv/SQLSrvStatement.php index bb2d61e579e..6ba0bbd1e53 100644 --- a/src/Driver/SQLSrv/SQLSrvStatement.php +++ b/src/Driver/SQLSrv/SQLSrvStatement.php @@ -224,7 +224,7 @@ public function columnCount() public function errorCode() { $errors = sqlsrv_errors(SQLSRV_ERR_ERRORS); - if ($errors) { + if ($errors !== null) { return $errors[0]['code']; } @@ -244,9 +244,8 @@ public function errorInfo() */ public function execute($params = null) { - if ($params) { + if ($params !== null) { $hasZeroIndex = array_key_exists(0, $params); - foreach ($params as $key => $val) { if ($hasZeroIndex && is_int($key)) { $this->bindValue($key + 1, $val); @@ -256,7 +255,7 @@ public function execute($params = null) } } - if (! $this->stmt) { + if ($this->stmt === null) { $this->stmt = $this->prepare(); } @@ -264,7 +263,7 @@ public function execute($params = null) throw SQLSrvException::fromSqlSrvErrors(); } - if ($this->lastInsertId) { + if ($this->lastInsertId !== null) { sqlsrv_next_result($this->stmt); sqlsrv_fetch($this->stmt); $this->lastInsertId->setId(sqlsrv_get_field($this->stmt, 0)); @@ -313,7 +312,7 @@ private function prepare() $stmt = sqlsrv_prepare($this->conn, $this->sql, $params); - if (! $stmt) { + if ($stmt === false) { throw SQLSrvException::fromSqlSrvErrors(); } diff --git a/src/DriverManager.php b/src/DriverManager.php index 6be382b6f4b..ba05e25ebe4 100644 --- a/src/DriverManager.php +++ b/src/DriverManager.php @@ -124,10 +124,10 @@ public static function getConnection( ?EventManager $eventManager = null ) : Connection { // create default config and event manager, if not set - if (! $config) { + if ($config === null) { $config = new Configuration(); } - if (! $eventManager) { + if ($eventManager === null) { $eventManager = new EventManager(); } diff --git a/src/Event/Listeners/MysqlSessionInit.php b/src/Event/Listeners/MysqlSessionInit.php index 9e722904050..9732b4733be 100644 --- a/src/Event/Listeners/MysqlSessionInit.php +++ b/src/Event/Listeners/MysqlSessionInit.php @@ -44,8 +44,13 @@ public function __construct($charset = 'utf8', $collation = false) */ public function postConnect(ConnectionEventArgs $args) { - $collation = $this->collation ? ' COLLATE ' . $this->collation : ''; - $args->getConnection()->executeUpdate('SET NAMES ' . $this->charset . $collation); + $statement = 'SET NAMES ' . $this->charset; + + if ($this->collation !== false) { + $statement .= ' COLLATE ' . $this->collation; + } + + $args->getConnection()->executeUpdate($statement); } /** diff --git a/src/Event/Listeners/OracleSessionInit.php b/src/Event/Listeners/OracleSessionInit.php index 9e374856078..eef78189354 100644 --- a/src/Event/Listeners/OracleSessionInit.php +++ b/src/Event/Listeners/OracleSessionInit.php @@ -45,7 +45,7 @@ public function __construct(array $oracleSessionVars = []) */ public function postConnect(ConnectionEventArgs $args) { - if (! count($this->_defaultSessionVars)) { + if (count($this->_defaultSessionVars) === 0) { return; } diff --git a/src/Platforms/AbstractPlatform.php b/src/Platforms/AbstractPlatform.php index 6c949b71ee8..3f4eabe9b11 100644 --- a/src/Platforms/AbstractPlatform.php +++ b/src/Platforms/AbstractPlatform.php @@ -814,7 +814,7 @@ public function getTrimExpression($str, $mode = TrimMode::UNSPECIFIED, $char = f $expression .= $char . ' '; } - if ($mode || $char !== false) { + if ($mode !== TrimMode::UNSPECIFIED || $char !== false) { $expression .= 'FROM '; } @@ -2247,19 +2247,18 @@ public function getColumnDeclarationSQL($name, array $field) } else { $default = $this->getDefaultValueDeclarationSQL($field); - $charset = isset($field['charset']) && $field['charset'] ? + $charset = ! empty($field['charset']) ? ' ' . $this->getColumnCharsetDeclarationSQL($field['charset']) : ''; - $collation = isset($field['collation']) && $field['collation'] ? + $collation = ! empty($field['collation']) ? ' ' . $this->getColumnCollationDeclarationSQL($field['collation']) : ''; - $notnull = isset($field['notnull']) && $field['notnull'] ? ' NOT NULL' : ''; + $notnull = ! empty($field['notnull']) ? ' NOT NULL' : ''; - $unique = isset($field['unique']) && $field['unique'] ? + $unique = ! empty($field['unique']) ? ' ' . $this->getUniqueFieldDeclarationSQL() : ''; - $check = isset($field['check']) && $field['check'] ? - ' ' . $field['check'] : ''; + $check = ! empty($field['check']) ? ' ' . $field['check'] : ''; $typeDecl = $field['type']->getSQLDeclaration($field, $this); $columnDef = $typeDecl . $charset . $default . $notnull . $unique . $check . $collation; @@ -2557,7 +2556,7 @@ public function getForeignKeyReferentialActionSQL($action) public function getForeignKeyBaseDeclarationSQL(ForeignKeyConstraint $foreignKey) { $sql = ''; - if (strlen($foreignKey->getName())) { + if (strlen($foreignKey->getName()) > 0) { $sql .= 'CONSTRAINT ' . $foreignKey->getQuotedName($this) . ' '; } $sql .= 'FOREIGN KEY ('; @@ -3560,7 +3559,7 @@ public function rollbackSavePoint($savepoint) final public function getReservedKeywordsList() { // Check for an existing instantiation of the keywords class. - if ($this->_keywords) { + if ($this->_keywords !== null) { return $this->_keywords; } diff --git a/src/Platforms/DB2Platform.php b/src/Platforms/DB2Platform.php index 95d4f3c3749..4c942a40d72 100644 --- a/src/Platforms/DB2Platform.php +++ b/src/Platforms/DB2Platform.php @@ -111,8 +111,8 @@ public function isCommentedDoctrineType(Type $doctrineType) */ protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) { - return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(254)') - : ($length ? 'VARCHAR(' . $length . ')' : 'VARCHAR(255)'); + return $fixed ? ($length > 0 ? 'CHAR(' . $length . ')' : 'CHAR(254)') + : ($length > 0 ? 'VARCHAR(' . $length . ')' : 'VARCHAR(255)'); } /** @@ -664,7 +664,7 @@ private function getAlterColumnClausesSQL(ColumnDiff $columnDiff) $alterClause = 'ALTER COLUMN ' . $columnDiff->column->getQuotedName($this); - if ($column['columnDefinition']) { + if ($column['columnDefinition'] !== null) { return [$alterClause . ' ' . $column['columnDefinition']]; } @@ -687,7 +687,7 @@ private function getAlterColumnClausesSQL(ColumnDiff $columnDiff) if (isset($column['default'])) { $defaultClause = $this->getDefaultValueDeclarationSQL($column); - if ($defaultClause) { + if ($defaultClause !== '') { $clauses[] = $alterClause . ' SET' . $defaultClause; } } else { @@ -753,7 +753,7 @@ public function getDefaultValueDeclarationSQL($field) return ''; } - if (isset($field['version']) && $field['version']) { + if (! empty($field['version'])) { if ((string) $field['type'] !== 'DateTime') { $field['default'] = '1'; } diff --git a/src/Platforms/Keywords/ReservedKeywordsValidator.php b/src/Platforms/Keywords/ReservedKeywordsValidator.php index 68cdf3d15d8..56058ce040a 100644 --- a/src/Platforms/Keywords/ReservedKeywordsValidator.php +++ b/src/Platforms/Keywords/ReservedKeywordsValidator.php @@ -9,6 +9,7 @@ use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Visitor\Visitor; +use function count; use function implode; use function str_replace; @@ -67,7 +68,7 @@ private function isReservedWord($word) */ private function addViolation($asset, $violatedPlatforms) { - if (! $violatedPlatforms) { + if (count($violatedPlatforms) === 0) { return; } diff --git a/src/Platforms/MySqlPlatform.php b/src/Platforms/MySqlPlatform.php index e2042c967ba..a0b0bf03cbe 100644 --- a/src/Platforms/MySqlPlatform.php +++ b/src/Platforms/MySqlPlatform.php @@ -150,7 +150,7 @@ public function getListTableConstraintsSQL($table) */ public function getListTableIndexesSQL($table, $currentDatabase = null) { - if ($currentDatabase) { + if ($currentDatabase !== null) { $currentDatabase = $this->quoteStringLiteral($currentDatabase); $table = $this->quoteStringLiteral($table); @@ -224,8 +224,8 @@ public function getDropViewSQL($name) */ protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) { - return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(255)') - : ($length ? 'VARCHAR(' . $length . ')' : 'VARCHAR(255)'); + return $fixed ? ($length > 0 ? 'CHAR(' . $length . ')' : 'CHAR(255)') + : ($length > 0 ? 'VARCHAR(' . $length . ')' : 'VARCHAR(255)'); } /** @@ -372,7 +372,7 @@ public function getListTableColumnsSQL($table, $database = null) { $table = $this->quoteStringLiteral($table); - if ($database) { + if ($database !== null) { $database = $this->quoteStringLiteral($database); } else { $database = 'DATABASE()'; @@ -394,7 +394,7 @@ public function getListTableMetadataSQL(string $table, ?string $database = null) WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA = %s AND TABLE_NAME = %s SQL , - $database ? $this->quoteStringLiteral($database) : 'DATABASE()', + $database !== null ? $this->quoteStringLiteral($database) : 'DATABASE()', $this->quoteStringLiteral($table) ); } diff --git a/src/Platforms/OraclePlatform.php b/src/Platforms/OraclePlatform.php index 41cdac58827..c3652d5168b 100644 --- a/src/Platforms/OraclePlatform.php +++ b/src/Platforms/OraclePlatform.php @@ -43,7 +43,7 @@ class OraclePlatform extends AbstractPlatform */ public static function assertValidIdentifier($identifier) { - if (! preg_match('(^(([a-zA-Z]{1}[a-zA-Z0-9_$#]{0,})|("[^"]+"))$)', $identifier)) { + if (preg_match('(^(([a-zA-Z]{1}[a-zA-Z0-9_$#]{0,})|("[^"]+"))$)', $identifier) === 0) { throw new DBALException('Invalid Oracle identifier'); } } @@ -329,8 +329,8 @@ protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) */ protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) { - return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(2000)') - : ($length ? 'VARCHAR2(' . $length . ')' : 'VARCHAR2(4000)'); + return $fixed ? ($length > 0 ? 'CHAR(' . $length . ')' : 'CHAR(2000)') + : ($length > 0 ? 'VARCHAR2(' . $length . ')' : 'VARCHAR2(4000)'); } /** @@ -725,13 +725,17 @@ public function getDropForeignKeySQL($foreignKey, $table) */ public function getAdvancedForeignKeyOptionsSQL(ForeignKeyConstraint $foreignKey) { - $referentialAction = null; + $referentialAction = ''; if ($foreignKey->hasOption('onDelete')) { $referentialAction = $this->getForeignKeyReferentialActionSQL($foreignKey->getOption('onDelete')); } - return $referentialAction ? ' ON DELETE ' . $referentialAction : ''; + if ($referentialAction !== '') { + return ' ON DELETE ' . $referentialAction; + } + + return ''; } /** @@ -785,7 +789,7 @@ public function getAlterTableSQL(TableDiff $diff) $fields[] = $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray()); $comment = $this->getColumnComment($column); - if (! $comment) { + if ($comment === null || $comment === '') { continue; } @@ -796,7 +800,7 @@ public function getAlterTableSQL(TableDiff $diff) ); } - if (count($fields)) { + if (count($fields) > 0) { $sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' ADD (' . implode(', ', $fields) . ')'; } @@ -844,7 +848,7 @@ public function getAlterTableSQL(TableDiff $diff) ); } - if (count($fields)) { + if (count($fields) > 0) { $sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' MODIFY (' . implode(', ', $fields) . ')'; } @@ -868,7 +872,7 @@ public function getAlterTableSQL(TableDiff $diff) $fields[] = $column->getQuotedName($this); } - if (count($fields)) { + if (count($fields) > 0) { $sql[] = 'ALTER TABLE ' . $diff->getName($this)->getQuotedName($this) . ' DROP (' . implode(', ', $fields) . ')'; } @@ -913,10 +917,10 @@ public function getColumnDeclarationSQL($name, array $field) $notnull = $field['notnull'] ? ' NOT NULL' : ' NULL'; } - $unique = isset($field['unique']) && $field['unique'] ? + $unique = ! empty($field['unique']) ? ' ' . $this->getUniqueFieldDeclarationSQL() : ''; - $check = isset($field['check']) && $field['check'] ? + $check = ! empty($field['check']) ? ' ' . $field['check'] : ''; $typeDecl = $field['type']->getSQLDeclaration($field, $this); @@ -999,8 +1003,8 @@ protected function doModifyLimitQuery($query, $limit, $offset = null) return $query; } - if (preg_match('/^\s*SELECT/i', $query)) { - if (! preg_match('/\sFROM\s/i', $query)) { + if (preg_match('/^\s*SELECT/i', $query) === 1) { + if (preg_match('/\sFROM\s/i', $query) === 0) { $query .= ' FROM dual'; } diff --git a/src/Platforms/PostgreSQL94Platform.php b/src/Platforms/PostgreSQL94Platform.php index f1de7379b3e..f07e17d8886 100644 --- a/src/Platforms/PostgreSQL94Platform.php +++ b/src/Platforms/PostgreSQL94Platform.php @@ -662,7 +662,7 @@ private function isUnchangedBinaryColumn(ColumnDiff $columnDiff) $fromColumn = $columnDiff->fromColumn instanceof Column ? $columnDiff->fromColumn : null; - if ($fromColumn) { + if ($fromColumn !== null) { $fromColumnType = $fromColumn->getType(); if (! $fromColumnType instanceof BinaryType && ! $fromColumnType instanceof BlobType) { @@ -1047,8 +1047,8 @@ protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) */ protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) { - return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(255)') - : ($length ? 'VARCHAR(' . $length . ')' : 'VARCHAR(255)'); + return $fixed ? ($length > 0 ? 'CHAR(' . $length . ')' : 'CHAR(255)') + : ($length > 0 ? 'VARCHAR(' . $length . ')' : 'VARCHAR(255)'); } /** @@ -1277,7 +1277,7 @@ private function isSerialField(array $field) : bool */ private function typeChangeBreaksDefaultValue(ColumnDiff $columnDiff) : bool { - if (! $columnDiff->fromColumn) { + if ($columnDiff->fromColumn === null) { return $columnDiff->hasChanged('type'); } @@ -1296,7 +1296,7 @@ private function isNumericType(Type $type) : bool private function getOldColumnComment(ColumnDiff $columnDiff) : ?string { - return $columnDiff->fromColumn ? $this->getColumnComment($columnDiff->fromColumn) : null; + return $columnDiff->fromColumn !== null ? $this->getColumnComment($columnDiff->fromColumn) : null; } public function getListTableMetadataSQL(string $table, ?string $schema = null) : string diff --git a/src/Platforms/SQLAnywhere16Platform.php b/src/Platforms/SQLAnywhere16Platform.php index f6a2211b508..44c1491f5d7 100644 --- a/src/Platforms/SQLAnywhere16Platform.php +++ b/src/Platforms/SQLAnywhere16Platform.php @@ -1132,7 +1132,7 @@ public function getTimeTypeDeclarationSQL(array $fieldDeclaration) */ public function getTrimExpression($str, $pos = TrimMode::UNSPECIFIED, $char = false) { - if (! $char) { + if ($char === false) { switch ($pos) { case TrimMode::LEADING: return $this->getLtrimExpression($str); @@ -1389,7 +1389,7 @@ protected function doModifyLimitQuery($query, $limit, $offset) return $query; } - if (! preg_match('/^\s*(SELECT\s+(DISTINCT\s+)?)(.*)/i', $query, $matches)) { + if (preg_match('/^\s*(SELECT\s+(DISTINCT\s+)?)(.*)/i', $query, $matches) === 0) { return $query; } @@ -1543,8 +1543,8 @@ protected function getReservedKeywordsClass() protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) { return $fixed - ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(' . $this->getVarcharDefaultLength() . ')') - : ($length ? 'VARCHAR(' . $length . ')' : 'VARCHAR(' . $this->getVarcharDefaultLength() . ')'); + ? ($length > 0 ? 'CHAR(' . $length . ')' : 'CHAR(' . $this->getVarcharDefaultLength() . ')') + : ($length > 0 ? 'VARCHAR(' . $length . ')' : 'VARCHAR(' . $this->getVarcharDefaultLength() . ')'); } /** diff --git a/src/Platforms/SQLServer2012Platform.php b/src/Platforms/SQLServer2012Platform.php index 13a298d73f0..2b9edfb45b4 100644 --- a/src/Platforms/SQLServer2012Platform.php +++ b/src/Platforms/SQLServer2012Platform.php @@ -316,7 +316,7 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options // @todo does other code breaks because of this? // force primary keys to be not null foreach ($columns as &$column) { - if (isset($column['primary']) && $column['primary']) { + if (! empty($column['primary'])) { $column['notnull'] = true; } @@ -1123,7 +1123,7 @@ public function getModExpression($expression1, $expression2) */ public function getTrimExpression($str, $pos = TrimMode::UNSPECIFIED, $char = false) { - if (! $char) { + if ($char === false) { switch ($pos) { case TrimMode::LEADING: $trimFn = 'LTRIM'; @@ -1261,7 +1261,9 @@ public function getDateTimeTzTypeDeclarationSQL(array $fieldDeclaration) */ protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) { - return $fixed ? ($length ? 'NCHAR(' . $length . ')' : 'CHAR(255)') : ($length ? 'NVARCHAR(' . $length . ')' : 'NVARCHAR(255)'); + return $fixed + ? ($length > 0 ? 'NCHAR(' . $length . ')' : 'CHAR(255)') + : ($length > 0 ? 'NVARCHAR(' . $length . ')' : 'NVARCHAR(255)'); } /** @@ -1352,9 +1354,9 @@ protected function doModifyLimitQuery($query, $limit, $offset = null) } if ($orderByPos === false - || substr_count($query, '(', $orderByPos) - substr_count($query, ')', $orderByPos) + || substr_count($query, '(', $orderByPos) !== substr_count($query, ')', $orderByPos) ) { - if (preg_match('/^SELECT\s+DISTINCT/im', $query)) { + if (preg_match('/^SELECT\s+DISTINCT/im', $query) > 0) { // SQL Server won't let us order by a non-selected column in a DISTINCT query, // so we have to do this madness. This says, order by the first column in the // result. SQL Server's docs say that a nonordered query's result order is non- @@ -1399,10 +1401,10 @@ public function convertBooleans($item) continue; } - $item[$key] = $value ? 1 : 0; + $item[$key] = (int) (bool) $value; } } elseif (is_bool($item) || is_numeric($item)) { - $item = $item ? 1 : 0; + $item = (int) (bool) $item; } return $item; @@ -1611,15 +1613,15 @@ public function getColumnDeclarationSQL($name, array $field) if (isset($field['columnDefinition'])) { $columnDef = $this->getCustomTypeDeclarationSQL($field); } else { - $collation = isset($field['collation']) && $field['collation'] ? + $collation = ! empty($field['collation']) ? ' ' . $this->getColumnCollationDeclarationSQL($field['collation']) : ''; - $notnull = isset($field['notnull']) && $field['notnull'] ? ' NOT NULL' : ''; + $notnull = ! empty($field['notnull']) ? ' NOT NULL' : ''; - $unique = isset($field['unique']) && $field['unique'] ? + $unique = ! empty($field['unique']) ? ' ' . $this->getUniqueFieldDeclarationSQL() : ''; - $check = isset($field['check']) && $field['check'] ? + $check = ! empty($field['check']) ? ' ' . $field['check'] : ''; $typeDecl = $field['type']->getSQLDeclaration($field, $this); diff --git a/src/Platforms/SqlitePlatform.php b/src/Platforms/SqlitePlatform.php index aef36b7758e..d19e9c42696 100644 --- a/src/Platforms/SqlitePlatform.php +++ b/src/Platforms/SqlitePlatform.php @@ -394,8 +394,8 @@ private function getNonAutoincrementPrimaryKeyDefinition(array $columns, array $ */ protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) { - return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(255)') - : ($length ? 'VARCHAR(' . $length . ')' : 'TEXT'); + return $fixed ? ($length > 0 ? 'CHAR(' . $length . ')' : 'CHAR(255)') + : ($length > 0 ? 'VARCHAR(' . $length . ')' : 'TEXT'); } /** @@ -1109,7 +1109,7 @@ private function getIndexesInAlteredTable(TableDiff $diff) foreach ($diff->removedIndexes as $index) { $indexName = strtolower($index->getName()); - if (! strlen($indexName) || ! isset($indexes[$indexName])) { + if (strlen($indexName) === 0 || ! isset($indexes[$indexName])) { continue; } @@ -1118,7 +1118,7 @@ private function getIndexesInAlteredTable(TableDiff $diff) foreach (array_merge($diff->changedIndexes, $diff->addedIndexes, $diff->renamedIndexes) as $index) { $indexName = strtolower($index->getName()); - if (strlen($indexName)) { + if (strlen($indexName) > 0) { $indexes[$indexName] = $index; } else { $indexes[] = $index; @@ -1167,7 +1167,7 @@ private function getForeignKeysInAlteredTable(TableDiff $diff) } $constraintName = strtolower($constraint->getName()); - if (! strlen($constraintName) || ! isset($foreignKeys[$constraintName])) { + if (strlen($constraintName) === 0 || ! isset($foreignKeys[$constraintName])) { continue; } @@ -1176,7 +1176,7 @@ private function getForeignKeysInAlteredTable(TableDiff $diff) foreach (array_merge($diff->changedForeignKeys, $diff->addedForeignKeys) as $constraint) { $constraintName = strtolower($constraint->getName()); - if (strlen($constraintName)) { + if (strlen($constraintName) > 0) { $foreignKeys[$constraintName] = $constraint; } else { $foreignKeys[] = $constraint; diff --git a/src/Portability/Connection.php b/src/Portability/Connection.php index f152b82dc94..623a9482bc7 100644 --- a/src/Portability/Connection.php +++ b/src/Portability/Connection.php @@ -63,7 +63,7 @@ public function connect() $this->portability = $params['portability']; } - if (isset($params['fetch_case']) && $this->portability & self::PORTABILITY_FIX_CASE) { + if (isset($params['fetch_case']) && ($this->portability & self::PORTABILITY_FIX_CASE) !== 0) { if ($this->_conn instanceof PDOConnection) { // make use of c-level support for case handling $this->_conn->getWrappedConnection()->setAttribute(PDO::ATTR_CASE, $params['fetch_case']); diff --git a/src/Portability/Statement.php b/src/Portability/Statement.php index 252b0424269..397f96c5954 100644 --- a/src/Portability/Statement.php +++ b/src/Portability/Statement.php @@ -135,10 +135,10 @@ public function fetch($fetchMode = null, ...$args) $row = $this->stmt->fetch($fetchMode, ...$args); - $iterateRow = $this->portability & (Connection::PORTABILITY_EMPTY_TO_NULL|Connection::PORTABILITY_RTRIM); + $iterateRow = ($this->portability & (Connection::PORTABILITY_EMPTY_TO_NULL|Connection::PORTABILITY_RTRIM)) !== 0; $fixCase = $this->case !== null && ($fetchMode === FetchMode::ASSOCIATIVE || $fetchMode === FetchMode::MIXED) - && ($this->portability & Connection::PORTABILITY_FIX_CASE); + && ($this->portability & Connection::PORTABILITY_FIX_CASE) !== 0; $row = $this->fixRow($row, $iterateRow, $fixCase); @@ -154,10 +154,10 @@ public function fetchAll($fetchMode = null, ...$args) $rows = $this->stmt->fetchAll($fetchMode, ...$args); - $iterateRow = $this->portability & (Connection::PORTABILITY_EMPTY_TO_NULL|Connection::PORTABILITY_RTRIM); + $iterateRow = ($this->portability & (Connection::PORTABILITY_EMPTY_TO_NULL|Connection::PORTABILITY_RTRIM)) !== 0; $fixCase = $this->case !== null && ($fetchMode === FetchMode::ASSOCIATIVE || $fetchMode === FetchMode::MIXED) - && ($this->portability & Connection::PORTABILITY_FIX_CASE); + && ($this->portability & Connection::PORTABILITY_FIX_CASE) !== 0; if (! $iterateRow && ! $fixCase) { return $rows; @@ -184,14 +184,14 @@ public function fetchAll($fetchMode = null, ...$args) /** * @param mixed $row - * @param int $iterateRow + * @param bool $iterateRow * @param bool $fixCase * * @return mixed */ protected function fixRow($row, $iterateRow, $fixCase) { - if (! $row) { + if ($row === false) { return $row; } @@ -201,9 +201,9 @@ protected function fixRow($row, $iterateRow, $fixCase) if ($iterateRow) { foreach ($row as $k => $v) { - if (($this->portability & Connection::PORTABILITY_EMPTY_TO_NULL) && $v === '') { + if (($this->portability & Connection::PORTABILITY_EMPTY_TO_NULL) !== 0 && $v === '') { $row[$k] = null; - } elseif (($this->portability & Connection::PORTABILITY_RTRIM) && is_string($v)) { + } elseif (($this->portability & Connection::PORTABILITY_RTRIM) !== 0 && is_string($v)) { $row[$k] = rtrim($v); } } @@ -219,12 +219,10 @@ public function fetchColumn($columnIndex = 0) { $value = $this->stmt->fetchColumn($columnIndex); - if ($this->portability & (Connection::PORTABILITY_EMPTY_TO_NULL|Connection::PORTABILITY_RTRIM)) { - if (($this->portability & Connection::PORTABILITY_EMPTY_TO_NULL) && $value === '') { - $value = null; - } elseif (($this->portability & Connection::PORTABILITY_RTRIM) && is_string($value)) { - $value = rtrim($value); - } + if (($this->portability & Connection::PORTABILITY_EMPTY_TO_NULL) !== 0 && $value === '') { + $value = null; + } elseif (($this->portability & Connection::PORTABILITY_RTRIM) !== 0 && is_string($value)) { + $value = rtrim($value); } return $value; diff --git a/src/Query/QueryBuilder.php b/src/Query/QueryBuilder.php index 913308a96c5..0f468276cef 100644 --- a/src/Query/QueryBuilder.php +++ b/src/Query/QueryBuilder.php @@ -548,7 +548,7 @@ public function delete($delete = null, $alias = null) { $this->type = self::DELETE; - if (! $delete) { + if ($delete === null) { return $this; } @@ -578,7 +578,7 @@ public function update($update = null, $alias = null) { $this->type = self::UPDATE; - if (! $update) { + if ($update === null) { return $this; } @@ -611,7 +611,7 @@ public function insert($insert = null) { $this->type = self::INSERT; - if (! $insert) { + if ($insert === null) { return $this; } @@ -1053,7 +1053,7 @@ public function orHaving($having) */ public function orderBy($sort, $order = null) { - return $this->add('orderBy', $sort . ' ' . (! $order ? 'ASC' : $order), false); + return $this->add('orderBy', $sort . ' ' . ($order ?? 'ASC'), false); } /** @@ -1066,7 +1066,7 @@ public function orderBy($sort, $order = null) */ public function addOrderBy($sort, $order = null) { - return $this->add('orderBy', $sort . ' ' . (! $order ? 'ASC' : $order), true); + return $this->add('orderBy', $sort . ' ' . ($order ?? 'ASC'), true); } /** diff --git a/src/SQLParserUtils.php b/src/SQLParserUtils.php index 6329a84e20d..60108f99d3f 100644 --- a/src/SQLParserUtils.php +++ b/src/SQLParserUtils.php @@ -155,7 +155,7 @@ public static function expandListParameters($query, $params, $types) $arrayPositions[$name] = false; } - if (( ! $arrayPositions && $isPositional)) { + if ($isPositional && count($arrayPositions) === 0) { return [$query, $params, $types]; } @@ -184,7 +184,7 @@ public static function expandListParameters($query, $params, $types) $types = array_merge( array_slice($types, 0, $needle), - $count ? + $count > 0 ? // array needles are at {@link \Doctrine\DBAL\ParameterType} constants // + {@link Doctrine\DBAL\Connection::ARRAY_PARAM_OFFSET} array_fill(0, $count, $types[$needle] - Connection::ARRAY_PARAM_OFFSET) : @@ -192,7 +192,7 @@ public static function expandListParameters($query, $params, $types) array_slice($types, $needle + 1) ); - $expandStr = $count ? implode(', ', array_fill(0, $count, '?')) : 'NULL'; + $expandStr = $count > 0 ? implode(', ', array_fill(0, $count, '?')) : 'NULL'; $query = substr($query, 0, $needlePos) . $expandStr . substr($query, $needlePos + 1); $paramOffset += ($count - 1); // Grows larger by number of parameters minus the replaced needle. diff --git a/src/Schema/AbstractAsset.php b/src/Schema/AbstractAsset.php index 45af02f5cc9..c23943c5974 100644 --- a/src/Schema/AbstractAsset.php +++ b/src/Schema/AbstractAsset.php @@ -114,7 +114,7 @@ public function getShortestName($defaultNamespaceName) public function getFullQualifiedName($defaultNamespaceName) { $name = $this->getName(); - if (! $this->_namespace) { + if ($this->_namespace === null) { $name = $defaultNamespaceName . '.' . $name; } @@ -162,7 +162,7 @@ protected function trimQuotes($identifier) */ public function getName() { - if ($this->_namespace) { + if ($this->_namespace !== null) { return $this->_namespace . '.' . $this->_name; } diff --git a/src/Schema/AbstractSchemaManager.php b/src/Schema/AbstractSchemaManager.php index 53ef67e226c..ba972c06cef 100644 --- a/src/Schema/AbstractSchemaManager.php +++ b/src/Schema/AbstractSchemaManager.php @@ -155,7 +155,7 @@ public function listSequences($database = null) */ public function listTableColumns($table, $database = null) { - if (! $database) { + if ($database === null) { $database = $this->_conn->getDatabase(); } @@ -226,7 +226,7 @@ public function listTableNames() protected function filterAssetNames($assetNames) { $filter = $this->_conn->getConfiguration()->getSchemaAssetsFilter(); - if (! $filter) { + if ($filter === null) { return $assetNames; } @@ -628,13 +628,7 @@ protected function _getPortableDatabasesList($databases) { $list = []; foreach ($databases as $value) { - $value = $this->_getPortableDatabaseDefinition($value); - - if (! $value) { - continue; - } - - $list[] = $value; + $list[] = $this->_getPortableDatabaseDefinition($value); } return $list; @@ -806,7 +800,7 @@ protected function _getPortableTableColumnList($table, $database, $tableColumns) $column = $this->_getPortableTableColumnDefinition($tableColumn); } - if (! $column) { + if ($column === null) { continue; } @@ -886,7 +880,7 @@ protected function _getPortableTableIndexesList($tableIndexRows, $tableName = nu $index = new Index($data['name'], $data['columns'], $data['unique'], $data['primary'], $data['flags'], $data['options']); } - if (! $index) { + if ($index === null) { continue; } @@ -905,13 +899,7 @@ protected function _getPortableTablesList($tables) { $list = []; foreach ($tables as $value) { - $value = $this->_getPortableTableDefinition($value); - - if (! $value) { - continue; - } - - $list[] = $value; + $list[] = $this->_getPortableTableDefinition($value); } return $list; @@ -936,13 +924,7 @@ protected function _getPortableUsersList($users) { $list = []; foreach ($users as $value) { - $value = $this->_getPortableUserDefinition($value); - - if (! $value) { - continue; - } - - $list[] = $value; + $list[] = $this->_getPortableUserDefinition($value); } return $list; @@ -969,7 +951,7 @@ protected function _getPortableViewsList($views) foreach ($views as $value) { $view = $this->_getPortableViewDefinition($value); - if (! $view) { + if ($view === false) { continue; } @@ -1107,7 +1089,7 @@ public function getSchemaSearchPaths() */ public function extractDoctrineTypeFromComment($comment, $currentType) { - if ($comment !== null && preg_match('(\(DC2Type:(((?!\)).)+)\))', $comment, $match)) { + if ($comment !== null && preg_match('(\(DC2Type:(((?!\)).)+)\))', $comment, $match) === 1) { return $match[1]; } diff --git a/src/Schema/ColumnDiff.php b/src/Schema/ColumnDiff.php index 1589f98d4a9..cc8fb306446 100644 --- a/src/Schema/ColumnDiff.php +++ b/src/Schema/ColumnDiff.php @@ -48,7 +48,7 @@ public function hasChanged($propertyName) */ public function getOldColumnName() { - $quote = $this->fromColumn && $this->fromColumn->isQuoted(); + $quote = $this->fromColumn !== null && $this->fromColumn->isQuoted(); return new Identifier($this->oldColumnName, $quote); } diff --git a/src/Schema/Comparator.php b/src/Schema/Comparator.php index 3663e6162e2..78f33e097ab 100644 --- a/src/Schema/Comparator.php +++ b/src/Schema/Comparator.php @@ -293,7 +293,7 @@ public function diffTable(Table $table1, Table $table2) $changes++; } - return $changes ? $tableDifferences : false; + return $changes > 0 ? $tableDifferences : false; } /** diff --git a/src/Schema/DB2SchemaManager.php b/src/Schema/DB2SchemaManager.php index ae2af864f97..8a1c7a30825 100644 --- a/src/Schema/DB2SchemaManager.php +++ b/src/Schema/DB2SchemaManager.php @@ -51,7 +51,7 @@ protected function _getPortableTableColumnDefinition($tableColumn) if ($tableColumn['default'] !== null && $tableColumn['default'] !== 'NULL') { $default = $tableColumn['default']; - if (preg_match('/^\'(.*)\'$/s', $default, $matches)) { + if (preg_match('/^\'(.*)\'$/s', $default, $matches) === 1) { $default = str_replace("''", "'", $matches[1]); } } diff --git a/src/Schema/MySqlSchemaManager.php b/src/Schema/MySqlSchemaManager.php index 9522faf6a73..3879bd33983 100644 --- a/src/Schema/MySqlSchemaManager.php +++ b/src/Schema/MySqlSchemaManager.php @@ -143,7 +143,11 @@ protected function _getPortableTableColumnDefinition($tableColumn) case 'real': case 'numeric': case 'decimal': - if (preg_match('([A-Za-z]+\(([0-9]+)\,([0-9]+)\))', $tableColumn['type'], $match)) { + if (preg_match( + '([A-Za-z]+\(([0-9]+),([0-9]+)\))', + $tableColumn['type'], + $match + ) === 1) { $precision = $match[1]; $scale = $match[2]; $length = null; @@ -237,7 +241,7 @@ private function getMariaDb1027ColumnDefault(MariaDb1027Platform $platform, ?str return null; } - if (preg_match('/^\'(.*)\'$/', $columnDefault, $matches)) { + if (preg_match('/^\'(.*)\'$/', $columnDefault, $matches) === 1) { return strtr($matches[1], self::MARIADB_ESCAPE_SEQUENCES); } diff --git a/src/Schema/OracleSchemaManager.php b/src/Schema/OracleSchemaManager.php index 9718f932ef5..3f2f28185b5 100644 --- a/src/Schema/OracleSchemaManager.php +++ b/src/Schema/OracleSchemaManager.php @@ -124,7 +124,7 @@ protected function _getPortableTableColumnDefinition($tableColumn) $dbType = strtolower($tableColumn['data_type']); if (strpos($dbType, 'timestamp(') === 0) { - if (strpos($dbType, 'with time zone')) { + if (strpos($dbType, 'with time zone') !== false) { $dbType = 'timestamptz'; } else { $dbType = 'timestamp'; @@ -146,7 +146,7 @@ protected function _getPortableTableColumnDefinition($tableColumn) if ($tableColumn['data_default'] !== null) { // Default values returned from database are represented as literal expressions - if (preg_match('/^\'(.*)\'$/s', $tableColumn['data_default'], $matches)) { + if (preg_match('/^\'(.*)\'$/s', $tableColumn['data_default'], $matches) === 1) { $tableColumn['data_default'] = str_replace("''", "'", $matches[1]); } } @@ -345,7 +345,7 @@ public function dropTable($name) */ private function getQuotedIdentifierName($identifier) { - if (preg_match('/[a-z]/', $identifier)) { + if (preg_match('/[a-z]/', $identifier) === 1) { return $this->_platform->quoteIdentifier($identifier); } diff --git a/src/Schema/PostgreSqlSchemaManager.php b/src/Schema/PostgreSqlSchemaManager.php index 7159b3160ff..25da9f1acba 100644 --- a/src/Schema/PostgreSqlSchemaManager.php +++ b/src/Schema/PostgreSqlSchemaManager.php @@ -138,14 +138,26 @@ protected function _getPortableTableForeignKeyDefinition($tableForeignKey) $foreignColumns = []; $foreignTable = null; - if (preg_match('(ON UPDATE ([a-zA-Z0-9]+( (NULL|ACTION|DEFAULT))?))', $tableForeignKey['condef'], $match)) { + if (preg_match( + '(ON UPDATE ([a-zA-Z0-9]+( (NULL|ACTION|DEFAULT))?))', + $tableForeignKey['condef'], + $match + ) === 1) { $onUpdate = $match[1]; } - if (preg_match('(ON DELETE ([a-zA-Z0-9]+( (NULL|ACTION|DEFAULT))?))', $tableForeignKey['condef'], $match)) { + if (preg_match( + '(ON DELETE ([a-zA-Z0-9]+( (NULL|ACTION|DEFAULT))?))', + $tableForeignKey['condef'], + $match + ) === 1) { $onDelete = $match[1]; } - if (preg_match('/FOREIGN KEY \((.+)\) REFERENCES (.+)\((.+)\)/', $tableForeignKey['condef'], $values)) { + if (preg_match( + '/FOREIGN KEY \((.+)\) REFERENCES (.+)\((.+)\)/', + $tableForeignKey['condef'], + $values + ) === 1) { // 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])); @@ -323,15 +335,15 @@ protected function _getPortableTableColumnDefinition($tableColumn) $matches = []; $autoincrement = false; - if (preg_match("/^nextval\('(.*)'(::.*)?\)$/", $tableColumn['default'], $matches)) { + if (preg_match("/^nextval\('(.*)'(::.*)?\)$/", $tableColumn['default'], $matches) === 1) { $tableColumn['sequence'] = $matches[1]; $tableColumn['default'] = null; $autoincrement = true; } - if (preg_match("/^['(](.*)[')]::/", $tableColumn['default'], $matches)) { + if (preg_match("/^['(](.*)[')]::/", $tableColumn['default'], $matches) === 1) { $tableColumn['default'] = $matches[1]; - } elseif (preg_match('/^NULL::/', $tableColumn['default'])) { + } elseif (preg_match('/^NULL::/', $tableColumn['default']) === 1) { $tableColumn['default'] = null; } @@ -353,7 +365,8 @@ protected function _getPortableTableColumnDefinition($tableColumn) $jsonb = null; $dbType = strtolower($tableColumn['type']); - if (strlen($tableColumn['domain_type']) && ! $this->_platform->hasDoctrineTypeMappingFor($tableColumn['type'])) { + if (strlen($tableColumn['domain_type']) > 0 + && ! $this->_platform->hasDoctrineTypeMappingFor($tableColumn['type'])) { $dbType = strtolower($tableColumn['domain_type']); $tableColumn['complete_type'] = $tableColumn['domain_complete_type']; } @@ -415,7 +428,11 @@ protected function _getPortableTableColumnDefinition($tableColumn) case 'numeric': $tableColumn['default'] = $this->fixVersion94NegativeNumericDefaultValue($tableColumn['default']); - if (preg_match('([A-Za-z]+\(([0-9]+)\,([0-9]+)\))', $tableColumn['complete_type'], $match)) { + if (preg_match( + '([A-Za-z]+\(([0-9]+)\,([0-9]+)\))', + $tableColumn['complete_type'], + $match + ) === 1) { $precision = $match[1]; $scale = $match[2]; $length = null; @@ -431,7 +448,11 @@ protected function _getPortableTableColumnDefinition($tableColumn) break; } - if ($tableColumn['default'] && preg_match("('([^']+)'::)", $tableColumn['default'], $match)) { + if ($tableColumn['default'] !== null && preg_match( + "('([^']+)'::)", + $tableColumn['default'], + $match + ) === 1) { $tableColumn['default'] = $match[1]; } diff --git a/src/Schema/SQLServerSchemaManager.php b/src/Schema/SQLServerSchemaManager.php index 050c4041fc7..c200d4e0ef2 100644 --- a/src/Schema/SQLServerSchemaManager.php +++ b/src/Schema/SQLServerSchemaManager.php @@ -134,7 +134,7 @@ private function parseDefaultExpression(string $value) : ?string return null; } - if (preg_match('/^\'(.*)\'$/s', $value, $matches)) { + if (preg_match('/^\'(.*)\'$/s', $value, $matches) === 1) { $value = str_replace("''", "'", $matches[1]); } diff --git a/src/Schema/SqliteSchemaManager.php b/src/Schema/SqliteSchemaManager.php index 133481af0ae..7f834a83742 100644 --- a/src/Schema/SqliteSchemaManager.php +++ b/src/Schema/SqliteSchemaManager.php @@ -131,7 +131,7 @@ public function listTableForeignKeys($table, $database = null) )?#isx', $createSql, $match - )) { + ) > 0) { $names = array_reverse($match[1]); $deferrable = array_reverse($match[2]); $deferred = array_reverse($match[3]); @@ -334,7 +334,7 @@ protected function _getPortableTableColumnDefinition($tableColumn) if ($default !== null) { // SQLite returns the default value as a literal expression, so we need to parse it - if (preg_match('/^\'(.*)\'$/s', $default, $matches)) { + if (preg_match('/^\'(.*)\'$/s', $default, $matches) === 1) { $default = str_replace("''", "'", $matches[1]); } } diff --git a/src/Schema/Table.php b/src/Schema/Table.php index b0de96aaf63..117d0ddd3d4 100644 --- a/src/Schema/Table.php +++ b/src/Schema/Table.php @@ -271,7 +271,7 @@ public function columnsAreIndexed(array $columnNames) */ private function _createIndex(array $columnNames, $indexName, $isUnique, $isPrimary, array $flags = [], array $options = []) { - if (preg_match('(([^a-zA-Z0-9_]+))', $this->normalizeIdentifier($indexName))) { + if (preg_match('(([^a-zA-Z0-9_]+))', $this->normalizeIdentifier($indexName)) === 1) { throw SchemaException::indexNameInvalid($indexName); } @@ -511,7 +511,7 @@ protected function _addForeignKeyConstraint(ForeignKeyConstraint $constraint) { $constraint->setLocalTable($this); - if (strlen($constraint->getName())) { + if (strlen($constraint->getName()) > 0) { $name = $constraint->getName(); } else { $name = $this->_generateIdentifierName( @@ -714,7 +714,7 @@ public function getPrimaryKeyColumns() */ public function hasPrimaryKey() { - return $this->_primaryKeyName && $this->hasIndex($this->_primaryKeyName); + return $this->_primaryKeyName !== false && $this->hasIndex($this->_primaryKeyName); } /** diff --git a/src/Statement.php b/src/Statement.php index 0ea10de3e58..ab848b3dc42 100644 --- a/src/Statement.php +++ b/src/Statement.php @@ -7,7 +7,6 @@ use Doctrine\DBAL\Types\Type; use IteratorAggregate; use Throwable; -use function is_array; use function is_string; /** @@ -139,19 +138,19 @@ public function bindParam($name, &$var, $type = ParameterType::STRING, $length = */ public function execute($params = null) { - if (is_array($params)) { + if ($params !== null) { $this->params = $params; } $logger = $this->conn->getConfiguration()->getSQLLogger(); - if ($logger) { + if ($logger !== null) { $logger->startQuery($this->sql, $this->params, $this->types); } try { $stmt = $this->stmt->execute($params); } catch (Throwable $ex) { - if ($logger) { + if ($logger !== null) { $logger->stopQuery(); } throw DBALException::driverExceptionDuringQuery( @@ -162,7 +161,7 @@ public function execute($params = null) ); } - if ($logger) { + if ($logger !== null) { $logger->stopQuery(); } $this->params = []; diff --git a/src/Tools/Console/Command/ReservedWordsCommand.php b/src/Tools/Console/Command/ReservedWordsCommand.php index d41117d6e73..ff06f44e944 100644 --- a/src/Tools/Console/Command/ReservedWordsCommand.php +++ b/src/Tools/Console/Command/ReservedWordsCommand.php @@ -108,7 +108,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $conn = $this->getHelper('db')->getConnection(); $keywordLists = (array) $input->getOption('list'); - if (! $keywordLists) { + if (count($keywordLists) === 0) { $keywordLists = array_keys($this->keywordListClasses); } diff --git a/src/Tools/Console/Command/RunSqlCommand.php b/src/Tools/Console/Command/RunSqlCommand.php index 5111a6505db..122fffd2ef2 100644 --- a/src/Tools/Console/Command/RunSqlCommand.php +++ b/src/Tools/Console/Command/RunSqlCommand.php @@ -11,6 +11,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use function assert; +use function is_bool; use function is_numeric; use function is_string; use function stripos; @@ -59,7 +60,10 @@ protected function execute(InputInterface $input, OutputInterface $output) throw new LogicException("Option 'depth' must contains an integer value"); } - if (stripos($sql, 'select') === 0 || $input->getOption('force-fetch')) { + $forceFetch = $input->getOption('force-fetch'); + assert(is_bool($forceFetch)); + + if (stripos($sql, 'select') === 0 || $forceFetch) { $resultSet = $conn->fetchAll($sql); } else { $resultSet = $conn->executeUpdate($sql); diff --git a/src/Types/DateImmutableType.php b/src/Types/DateImmutableType.php index a4c5d266d92..4fbe6a472a1 100644 --- a/src/Types/DateImmutableType.php +++ b/src/Types/DateImmutableType.php @@ -49,7 +49,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) $dateTime = DateTimeImmutable::createFromFormat('!' . $platform->getDateFormatString(), $value); - if (! $dateTime) { + if ($dateTime === false) { throw ConversionException::conversionFailedFormat( $value, $this->getName(), diff --git a/src/Types/DateTimeImmutableType.php b/src/Types/DateTimeImmutableType.php index 51960a8c344..39b3cdf734a 100644 --- a/src/Types/DateTimeImmutableType.php +++ b/src/Types/DateTimeImmutableType.php @@ -50,11 +50,11 @@ public function convertToPHPValue($value, AbstractPlatform $platform) $dateTime = DateTimeImmutable::createFromFormat($platform->getDateTimeFormatString(), $value); - if (! $dateTime) { + if ($dateTime === false) { $dateTime = date_create_immutable($value); } - if (! $dateTime) { + if ($dateTime === false) { throw ConversionException::conversionFailedFormat( $value, $this->getName(), diff --git a/src/Types/DateTimeType.php b/src/Types/DateTimeType.php index 65071a6b188..b69f953153c 100644 --- a/src/Types/DateTimeType.php +++ b/src/Types/DateTimeType.php @@ -55,11 +55,11 @@ public function convertToPHPValue($value, AbstractPlatform $platform) $val = DateTime::createFromFormat($platform->getDateTimeFormatString(), $value); - if (! $val) { + if ($val === false) { $val = date_create($value); } - if (! $val) { + if ($val === false) { throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeFormatString()); } diff --git a/src/Types/DateTimeTzImmutableType.php b/src/Types/DateTimeTzImmutableType.php index b888624796e..6e707e065dc 100644 --- a/src/Types/DateTimeTzImmutableType.php +++ b/src/Types/DateTimeTzImmutableType.php @@ -49,7 +49,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) $dateTime = DateTimeImmutable::createFromFormat($platform->getDateTimeTzFormatString(), $value); - if (! $dateTime) { + if ($dateTime === false) { throw ConversionException::conversionFailedFormat( $value, $this->getName(), diff --git a/src/Types/DateTimeTzType.php b/src/Types/DateTimeTzType.php index 6240da8926c..3adb2ab48cd 100644 --- a/src/Types/DateTimeTzType.php +++ b/src/Types/DateTimeTzType.php @@ -66,7 +66,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) } $val = DateTime::createFromFormat($platform->getDateTimeTzFormatString(), $value); - if (! $val) { + if ($val === false) { throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeTzFormatString()); } diff --git a/src/Types/DateType.php b/src/Types/DateType.php index 15d9362f288..d09317172de 100644 --- a/src/Types/DateType.php +++ b/src/Types/DateType.php @@ -53,7 +53,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) } $val = DateTime::createFromFormat('!' . $platform->getDateFormatString(), $value); - if (! $val) { + if ($val === false) { throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateFormatString()); } diff --git a/src/Types/SimpleArrayType.php b/src/Types/SimpleArrayType.php index 31c22b8e6f6..68cf663c082 100644 --- a/src/Types/SimpleArrayType.php +++ b/src/Types/SimpleArrayType.php @@ -3,8 +3,10 @@ namespace Doctrine\DBAL\Types; use Doctrine\DBAL\Platforms\AbstractPlatform; +use function count; use function explode; use function implode; +use function is_array; use function is_resource; use function stream_get_contents; @@ -28,7 +30,7 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { - if (! $value) { + if (! is_array($value) || count($value) === 0) { return null; } diff --git a/src/Types/TimeImmutableType.php b/src/Types/TimeImmutableType.php index cc437695564..8d2c1517ccb 100644 --- a/src/Types/TimeImmutableType.php +++ b/src/Types/TimeImmutableType.php @@ -49,7 +49,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) $dateTime = DateTimeImmutable::createFromFormat('!' . $platform->getTimeFormatString(), $value); - if (! $dateTime) { + if ($dateTime === false) { throw ConversionException::conversionFailedFormat( $value, $this->getName(), diff --git a/src/Types/TimeType.php b/src/Types/TimeType.php index 1eeb2c01d1f..df65be5b6cd 100644 --- a/src/Types/TimeType.php +++ b/src/Types/TimeType.php @@ -53,7 +53,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) } $val = DateTime::createFromFormat('!' . $platform->getTimeFormatString(), $value); - if (! $val) { + if ($val === false) { throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getTimeFormatString()); } diff --git a/src/Types/VarDateTimeImmutableType.php b/src/Types/VarDateTimeImmutableType.php index 38beb3badf6..3e3d0f081e7 100644 --- a/src/Types/VarDateTimeImmutableType.php +++ b/src/Types/VarDateTimeImmutableType.php @@ -50,7 +50,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) $dateTime = date_create_immutable($value); - if (! $dateTime) { + if ($dateTime === false) { throw ConversionException::conversionFailed($value, $this->getName()); } diff --git a/src/Types/VarDateTimeType.php b/src/Types/VarDateTimeType.php index 1d9dbd3a6c6..1555f4c79d9 100644 --- a/src/Types/VarDateTimeType.php +++ b/src/Types/VarDateTimeType.php @@ -25,7 +25,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) } $val = date_create($value); - if (! $val) { + if ($val === false) { throw ConversionException::conversionFailed($value, $this->getName()); } diff --git a/tests/FunctionalTestCase.php b/tests/FunctionalTestCase.php index 15622b6f1e7..47141c967d7 100644 --- a/tests/FunctionalTestCase.php +++ b/tests/FunctionalTestCase.php @@ -68,7 +68,7 @@ protected function onNotSuccessfulTest(Throwable $t) : void throw $t; } - if (isset($this->sqlLoggerStack->queries) && count($this->sqlLoggerStack->queries)) { + if (count($this->sqlLoggerStack->queries) > 0) { $queries = ''; $i = count($this->sqlLoggerStack->queries); foreach (array_reverse($this->sqlLoggerStack->queries) as $query) { From 182d3d8f07d43d56d7f3c3b9dd3ac2965760e0a6 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 3 Apr 2020 17:20:50 -0700 Subject: [PATCH 08/19] Suppressed variable property access error in statement classes --- phpstan.neon.dist | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index da93a164f30..7cb093cbd21 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -97,5 +97,11 @@ parameters: - %currentWorkingDirectory%/src/Platforms/*Platform.php - %currentWorkingDirectory%/src/Query/QueryBuilder.php - %currentWorkingDirectory%/src/Schema/*SchemaManager.php + + # FetchMode::CUSTOM_OBJECT requires variable property access + - + message: '~^Variable property access on object\.~' + paths: + - %currentWorkingDirectory%/src/Driver/*/*Statement.php includes: - vendor/phpstan/phpstan-strict-rules/rules.neon From 24fc969bff0e64cb7c142a9363cf880041567629 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 3 Apr 2020 17:39:45 -0700 Subject: [PATCH 09/19] Use in_array() in strict mode --- src/DriverManager.php | 2 +- src/Platforms/AbstractPlatform.php | 4 ++-- src/Platforms/MySqlPlatform.php | 2 +- src/Schema/ColumnDiff.php | 2 +- src/Schema/ForeignKeyConstraint.php | 3 +-- src/Schema/PostgreSqlSchemaManager.php | 2 +- src/Schema/SQLServerSchemaManager.php | 6 ++++-- src/Schema/Visitor/Graphviz.php | 2 +- .../NewPrimaryKeyWithNewAutoIncrementColumnTest.php | 4 ++-- tests/Functional/Schema/SchemaManagerFunctionalTestCase.php | 2 +- tests/Functional/Ticket/DBAL630Test.php | 6 ++---- tests/Functional/Ticket/DBAL752Test.php | 6 ++---- tests/Schema/DB2SchemaManagerTest.php | 2 +- 13 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/DriverManager.php b/src/DriverManager.php index ba05e25ebe4..cdd2ea0b7a4 100644 --- a/src/DriverManager.php +++ b/src/DriverManager.php @@ -195,7 +195,7 @@ private static function _checkParams(array $params) : void throw DBALException::unknownDriver($params['driver'], array_keys(self::$_driverMap)); } - if (isset($params['driverClass']) && ! in_array(Driver::class, class_implements($params['driverClass'], true))) { + if (isset($params['driverClass']) && ! in_array(Driver::class, class_implements($params['driverClass']), true)) { throw DBALException::invalidDriverClass($params['driverClass']); } } diff --git a/src/Platforms/AbstractPlatform.php b/src/Platforms/AbstractPlatform.php index 3f4eabe9b11..49f4312006f 100644 --- a/src/Platforms/AbstractPlatform.php +++ b/src/Platforms/AbstractPlatform.php @@ -494,7 +494,7 @@ public function isCommentedDoctrineType(Type $doctrineType) assert(is_array($this->doctrineTypeComments)); - return in_array($doctrineType->getName(), $this->doctrineTypeComments); + return in_array($doctrineType->getName(), $this->doctrineTypeComments, true); } /** @@ -1586,7 +1586,7 @@ public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDE $columnData['length'] = 255; } - if (in_array($column->getName(), $options['primary'])) { + if (in_array($column->getName(), $options['primary'], true)) { $columnData['primary'] = true; } diff --git a/src/Platforms/MySqlPlatform.php b/src/Platforms/MySqlPlatform.php index a0b0bf03cbe..6aae218b2ca 100644 --- a/src/Platforms/MySqlPlatform.php +++ b/src/Platforms/MySqlPlatform.php @@ -765,7 +765,7 @@ private function getPreAlterTableAlterIndexForeignKeySQL(TableDiff $diff) $column = $diff->fromTable->getColumn($columnName); // Check if an autoincrement column was dropped from the primary key. - if (! $column->getAutoincrement() || in_array($columnName, $changedIndex->getColumns())) { + if (! $column->getAutoincrement() || in_array($columnName, $changedIndex->getColumns(), true)) { continue; } diff --git a/src/Schema/ColumnDiff.php b/src/Schema/ColumnDiff.php index cc8fb306446..37a6abb05ea 100644 --- a/src/Schema/ColumnDiff.php +++ b/src/Schema/ColumnDiff.php @@ -40,7 +40,7 @@ public function __construct($oldColumnName, Column $column, array $changedProper */ public function hasChanged($propertyName) { - return in_array($propertyName, $this->changedProperties); + return in_array($propertyName, $this->changedProperties, true); } /** diff --git a/src/Schema/ForeignKeyConstraint.php b/src/Schema/ForeignKeyConstraint.php index 3611b77dccd..172ac33b9f9 100644 --- a/src/Schema/ForeignKeyConstraint.php +++ b/src/Schema/ForeignKeyConstraint.php @@ -5,7 +5,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use function array_keys; use function array_map; -use function in_array; use function strrpos; use function strtolower; use function strtoupper; @@ -360,7 +359,7 @@ private function onEvent($event) if (isset($this->_options[$event])) { $onEvent = strtoupper($this->_options[$event]); - if (! in_array($onEvent, ['NO ACTION', 'RESTRICT'])) { + if ($onEvent !== 'NO ACTION' && $onEvent !== 'RESTRICT') { return $onEvent; } } diff --git a/src/Schema/PostgreSqlSchemaManager.php b/src/Schema/PostgreSqlSchemaManager.php index 25da9f1acba..0a85d156f0e 100644 --- a/src/Schema/PostgreSqlSchemaManager.php +++ b/src/Schema/PostgreSqlSchemaManager.php @@ -94,7 +94,7 @@ public function determineExistingSchemaSearchPaths() $paths = $this->getSchemaSearchPaths(); $this->existingSchemaPaths = array_filter($paths, static function ($v) use ($names) { - return in_array($v, $names); + return in_array($v, $names, true); }); } diff --git a/src/Schema/SQLServerSchemaManager.php b/src/Schema/SQLServerSchemaManager.php index c200d4e0ef2..386feaba753 100644 --- a/src/Schema/SQLServerSchemaManager.php +++ b/src/Schema/SQLServerSchemaManager.php @@ -10,7 +10,6 @@ use Throwable; use function assert; use function count; -use function in_array; use function is_string; use function preg_match; use function sprintf; @@ -104,7 +103,6 @@ protected function _getPortableTableColumnDefinition($tableColumn) $tableColumn['comment'] = $this->removeDoctrineTypeFromComment($tableColumn['comment'], $type); $options = [ - 'length' => $length === 0 || ! in_array($type, ['text', 'string']) ? null : $length, 'unsigned' => false, 'fixed' => (bool) $fixed, 'default' => $default, @@ -115,6 +113,10 @@ protected function _getPortableTableColumnDefinition($tableColumn) 'comment' => $tableColumn['comment'] !== '' ? $tableColumn['comment'] : null, ]; + if ($length !== 0 && ($type === 'text' || $type === 'string')) { + $options['length'] = $length; + } + $column = new Column($tableColumn['name'], Type::getType($type), $options); if (isset($tableColumn['collation']) && $tableColumn['collation'] !== 'NULL') { diff --git a/src/Schema/Visitor/Graphviz.php b/src/Schema/Visitor/Graphviz.php index d5e94cf6ea3..3f283abe542 100644 --- a/src/Schema/Visitor/Graphviz.php +++ b/src/Schema/Visitor/Graphviz.php @@ -84,7 +84,7 @@ private function createTableLabel(Table $table) $primaryKey = $table->getPrimaryKey(); - if ($primaryKey !== null && in_array($column->getName(), $primaryKey->getColumns())) { + if ($primaryKey !== null && in_array($column->getName(), $primaryKey->getColumns(), true)) { $label .= "\xe2\x9c\xb7"; } $label .= ''; diff --git a/tests/Functional/Platform/NewPrimaryKeyWithNewAutoIncrementColumnTest.php b/tests/Functional/Platform/NewPrimaryKeyWithNewAutoIncrementColumnTest.php index 1825b183de2..39cb4bb1d24 100644 --- a/tests/Functional/Platform/NewPrimaryKeyWithNewAutoIncrementColumnTest.php +++ b/tests/Functional/Platform/NewPrimaryKeyWithNewAutoIncrementColumnTest.php @@ -3,9 +3,9 @@ namespace Doctrine\DBAL\Tests\Functional\Platform; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Tests\FunctionalTestCase; -use function in_array; final class NewPrimaryKeyWithNewAutoIncrementColumnTest extends FunctionalTestCase { @@ -16,7 +16,7 @@ protected function setUp() : void { parent::setUp(); - if (in_array($this->getPlatform()->getName(), ['mysql'])) { + if ($this->getPlatform() instanceof MySqlPlatform) { return; } diff --git a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php index c3c28c140be..e184b6dacc7 100644 --- a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -220,7 +220,7 @@ public function testListNamespaceNames() : void $namespaces = $this->schemaManager->listNamespaceNames(); $namespaces = array_map('strtolower', $namespaces); - if (! in_array('test_create_schema', $namespaces)) { + if (! in_array('test_create_schema', $namespaces, true)) { $this->connection->executeUpdate($this->schemaManager->getDatabasePlatform()->getCreateSchemaSQL('test_create_schema')); $namespaces = $this->schemaManager->listNamespaceNames(); diff --git a/tests/Functional/Ticket/DBAL630Test.php b/tests/Functional/Ticket/DBAL630Test.php index 88a8614dc7d..51768df692d 100644 --- a/tests/Functional/Ticket/DBAL630Test.php +++ b/tests/Functional/Ticket/DBAL630Test.php @@ -4,9 +4,9 @@ use Doctrine\DBAL\DBALException; use Doctrine\DBAL\ParameterType; +use Doctrine\DBAL\Platforms\PostgreSQL94Platform; use Doctrine\DBAL\Tests\FunctionalTestCase; use PDO; -use function in_array; /** * @group DBAL-630 @@ -20,9 +20,7 @@ protected function setUp() : void { parent::setUp(); - $platform = $this->connection->getDatabasePlatform()->getName(); - - if (! in_array($platform, ['postgresql'])) { + if (! $this->connection->getDatabasePlatform() instanceof PostgreSQL94Platform) { self::markTestSkipped('Currently restricted to PostgreSQL'); } diff --git a/tests/Functional/Ticket/DBAL752Test.php b/tests/Functional/Ticket/DBAL752Test.php index 07858b94f49..20095e34892 100644 --- a/tests/Functional/Ticket/DBAL752Test.php +++ b/tests/Functional/Ticket/DBAL752Test.php @@ -2,8 +2,8 @@ namespace Doctrine\DBAL\Tests\Functional\Ticket; +use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Tests\FunctionalTestCase; -use function in_array; /** * @group DBAL-752 @@ -14,9 +14,7 @@ protected function setUp() : void { parent::setUp(); - $platform = $this->connection->getDatabasePlatform()->getName(); - - if (in_array($platform, ['sqlite'])) { + if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) { return; } diff --git a/tests/Schema/DB2SchemaManagerTest.php b/tests/Schema/DB2SchemaManagerTest.php index d7f4afcecbf..951340743b0 100644 --- a/tests/Schema/DB2SchemaManagerTest.php +++ b/tests/Schema/DB2SchemaManagerTest.php @@ -93,7 +93,7 @@ public function testListTableNamesFiltersAssetNamesCorrectlyWithCallable() : voi { $accepted = ['T_FOO', 'T_BAR']; $this->conn->getConfiguration()->setSchemaAssetsFilter(static function ($assetName) use ($accepted) { - return in_array($assetName, $accepted); + return in_array($assetName, $accepted, true); }); $this->conn->expects(self::any())->method('quote'); $this->conn->expects(self::once())->method('fetchAll')->will(self::returnValue([ From 8b0ddf6034994a7dc6f096d5cdbc8d528d8d2969 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 3 Apr 2020 17:42:42 -0700 Subject: [PATCH 10/19] Use array_search() in strict mode --- src/Schema/Index.php | 2 +- .../Schema/SchemaManagerFunctionalTestCase.php | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Schema/Index.php b/src/Schema/Index.php index 7a31c7824bf..f573507c09c 100644 --- a/src/Schema/Index.php +++ b/src/Schema/Index.php @@ -164,7 +164,7 @@ public function hasColumnAtPosition($columnName, $pos = 0) $columnName = $this->trimQuotes(strtolower($columnName)); $indexColumns = array_map('strtolower', $this->getUnquotedColumns()); - return array_search($columnName, $indexColumns) === $pos; + return array_search($columnName, $indexColumns, true) === $pos; } /** diff --git a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php index e184b6dacc7..01dfd1f0e2c 100644 --- a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -280,7 +280,7 @@ public function testListTableColumns() : void $columnsKeys = array_keys($columns); self::assertArrayHasKey('id', $columns); - self::assertEquals(0, array_search('id', $columnsKeys)); + self::assertEquals(0, array_search('id', $columnsKeys, true)); self::assertEquals('id', strtolower($columns['id']->getName())); self::assertInstanceOf(IntegerType::class, $columns['id']->getType()); self::assertEquals(false, $columns['id']->getUnsigned()); @@ -289,7 +289,7 @@ public function testListTableColumns() : void self::assertIsArray($columns['id']->getPlatformOptions()); self::assertArrayHasKey('test', $columns); - self::assertEquals(1, array_search('test', $columnsKeys)); + self::assertEquals(1, array_search('test', $columnsKeys, true)); self::assertEquals('test', strtolower($columns['test']->getname())); self::assertInstanceOf(StringType::class, $columns['test']->gettype()); self::assertEquals(255, $columns['test']->getlength()); @@ -299,7 +299,7 @@ public function testListTableColumns() : void self::assertIsArray($columns['test']->getPlatformOptions()); self::assertEquals('foo', strtolower($columns['foo']->getname())); - self::assertEquals(2, array_search('foo', $columnsKeys)); + self::assertEquals(2, array_search('foo', $columnsKeys, true)); self::assertInstanceOf(TextType::class, $columns['foo']->gettype()); self::assertEquals(false, $columns['foo']->getunsigned()); self::assertEquals(false, $columns['foo']->getfixed()); @@ -308,7 +308,7 @@ public function testListTableColumns() : void self::assertIsArray($columns['foo']->getPlatformOptions()); self::assertEquals('bar', strtolower($columns['bar']->getname())); - self::assertEquals(3, array_search('bar', $columnsKeys)); + self::assertEquals(3, array_search('bar', $columnsKeys, true)); self::assertInstanceOf(DecimalType::class, $columns['bar']->gettype()); self::assertEquals(null, $columns['bar']->getlength()); self::assertEquals(10, $columns['bar']->getprecision()); @@ -320,21 +320,21 @@ public function testListTableColumns() : void self::assertIsArray($columns['bar']->getPlatformOptions()); self::assertEquals('baz1', strtolower($columns['baz1']->getname())); - self::assertEquals(4, array_search('baz1', $columnsKeys)); + self::assertEquals(4, array_search('baz1', $columnsKeys, true)); self::assertInstanceOf(DateTimeType::class, $columns['baz1']->gettype()); self::assertEquals(true, $columns['baz1']->getnotnull()); self::assertEquals(null, $columns['baz1']->getdefault()); self::assertIsArray($columns['baz1']->getPlatformOptions()); self::assertEquals('baz2', strtolower($columns['baz2']->getname())); - self::assertEquals(5, array_search('baz2', $columnsKeys)); + self::assertEquals(5, array_search('baz2', $columnsKeys, true)); self::assertContains($columns['baz2']->gettype()->getName(), ['time', 'date', 'datetime']); self::assertEquals(true, $columns['baz2']->getnotnull()); self::assertEquals(null, $columns['baz2']->getdefault()); self::assertIsArray($columns['baz2']->getPlatformOptions()); self::assertEquals('baz3', strtolower($columns['baz3']->getname())); - self::assertEquals(6, array_search('baz3', $columnsKeys)); + self::assertEquals(6, array_search('baz3', $columnsKeys, true)); self::assertContains($columns['baz3']->gettype()->getName(), ['time', 'date', 'datetime']); self::assertEquals(true, $columns['baz3']->getnotnull()); self::assertEquals(null, $columns['baz3']->getdefault()); From e17fcab81fbb363986025ac0c10fd4296bb8966a Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 3 Apr 2020 17:54:34 -0700 Subject: [PATCH 11/19] Anonymous function should have native return typehint --- src/DBALException.php | 2 +- src/Driver/Mysqli/MysqliConnection.php | 4 +++- src/Driver/SQLAnywhere/Driver.php | 2 +- src/Platforms/PostgreSQL94Platform.php | 2 +- src/Schema/AbstractAsset.php | 2 +- src/Schema/PostgreSqlSchemaManager.php | 2 +- src/Schema/Table.php | 2 +- tests/Functional/ConnectionTest.php | 2 +- tests/Functional/DataAccessTest.php | 2 +- tests/Functional/StatementTest.php | 2 +- tests/Functional/WriteTest.php | 2 +- tests/FunctionalTestCase.php | 2 +- tests/Schema/DB2SchemaManagerTest.php | 2 +- 13 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/DBALException.php b/src/DBALException.php index 403f5394bb8..c0e59ee0b2d 100644 --- a/src/DBALException.php +++ b/src/DBALException.php @@ -180,7 +180,7 @@ private static function wrapException(Driver $driver, Throwable $driverEx, strin */ private static function formatParameters(array $params) { - return '[' . implode(', ', array_map(static function ($param) { + return '[' . implode(', ', array_map(static function ($param) : string { if (is_resource($param)) { return (string) $param; } diff --git a/src/Driver/Mysqli/MysqliConnection.php b/src/Driver/Mysqli/MysqliConnection.php index f2b27c00630..f9bb38e24ba 100644 --- a/src/Driver/Mysqli/MysqliConnection.php +++ b/src/Driver/Mysqli/MysqliConnection.php @@ -63,8 +63,10 @@ public function __construct(array $params, $username, $password, array $driverOp $this->setSecureConnection($params); $this->setDriverOptions($driverOptions); - set_error_handler(static function () { + set_error_handler(static function () : bool { + return true; }); + try { if (! $this->conn->real_connect($host, $username, $password, $dbname, $port, $socket, $flags)) { throw new MysqliException($this->conn->connect_error, $this->conn->sqlstate ?? 'HY000', $this->conn->connect_errno); diff --git a/src/Driver/SQLAnywhere/Driver.php b/src/Driver/SQLAnywhere/Driver.php index ede8b745d09..a2d7c34ee36 100644 --- a/src/Driver/SQLAnywhere/Driver.php +++ b/src/Driver/SQLAnywhere/Driver.php @@ -79,7 +79,7 @@ private function buildDsn($host, $port, $server, $dbname, $username = null, $pas ';PWD=' . $password . ';' . implode( ';', - array_map(static function ($key, $value) { + array_map(static function ($key, $value) : string { return $key . '=' . $value; }, array_keys($driverOptions), $driverOptions) ); diff --git a/src/Platforms/PostgreSQL94Platform.php b/src/Platforms/PostgreSQL94Platform.php index f07e17d8886..e57802fec03 100644 --- a/src/Platforms/PostgreSQL94Platform.php +++ b/src/Platforms/PostgreSQL94Platform.php @@ -905,7 +905,7 @@ public function convertBooleansToDatabaseValue($item) return $this->doConvertBooleans( $item, - static function ($boolean) { + static function ($boolean) : ?int { return $boolean === null ? null : (int) $boolean; } ); diff --git a/src/Schema/AbstractAsset.php b/src/Schema/AbstractAsset.php index c23943c5974..d2f4cd8e6d0 100644 --- a/src/Schema/AbstractAsset.php +++ b/src/Schema/AbstractAsset.php @@ -201,7 +201,7 @@ public function getQuotedName(AbstractPlatform $platform) */ protected function _generateIdentifierName($columnNames, $prefix = '', $maxSize = 30) { - $hash = implode('', array_map(static function ($column) { + $hash = implode('', array_map(static function ($column) : string { return dechex(crc32($column)); }, $columnNames)); diff --git a/src/Schema/PostgreSqlSchemaManager.php b/src/Schema/PostgreSqlSchemaManager.php index 0a85d156f0e..d3e9c528725 100644 --- a/src/Schema/PostgreSqlSchemaManager.php +++ b/src/Schema/PostgreSqlSchemaManager.php @@ -93,7 +93,7 @@ public function determineExistingSchemaSearchPaths() $names = $this->getSchemaNames(); $paths = $this->getSchemaSearchPaths(); - $this->existingSchemaPaths = array_filter($paths, static function ($v) use ($names) { + $this->existingSchemaPaths = array_filter($paths, static function ($v) use ($names) : bool { return in_array($v, $names, true); }); } diff --git a/src/Schema/Table.php b/src/Schema/Table.php index 117d0ddd3d4..6014bbfd00d 100644 --- a/src/Schema/Table.php +++ b/src/Schema/Table.php @@ -637,7 +637,7 @@ private function getForeignKeyColumns() */ private function filterColumns(array $columnNames) { - return array_filter($this->_columns, static function ($columnName) use ($columnNames) { + return array_filter($this->_columns, static function ($columnName) use ($columnNames) : bool { return in_array($columnName, $columnNames, true); }, ARRAY_FILTER_USE_KEY); } diff --git a/tests/Functional/ConnectionTest.php b/tests/Functional/ConnectionTest.php index 0e06cc1a14b..a7d6d37ccc8 100644 --- a/tests/Functional/ConnectionTest.php +++ b/tests/Functional/ConnectionTest.php @@ -283,7 +283,7 @@ public function testTransactional() : void public function testTransactionalReturnValue() : void { - $res = $this->connection->transactional(static function () { + $res = $this->connection->transactional(static function () : int { return 42; }); diff --git a/tests/Functional/DataAccessTest.php b/tests/Functional/DataAccessTest.php index aa318020b92..6bbd52cfab2 100644 --- a/tests/Functional/DataAccessTest.php +++ b/tests/Functional/DataAccessTest.php @@ -737,7 +737,7 @@ public function testSetDefaultFetchMode() : void $stmt->setFetchMode(FetchMode::NUMERIC); $row = array_keys($stmt->fetch()); - self::assertCount(0, array_filter($row, static function ($v) { + self::assertCount(0, array_filter($row, static function ($v) : bool { return ! is_numeric($v); }), 'should be no non-numerical elements in the result.'); } diff --git a/tests/Functional/StatementTest.php b/tests/Functional/StatementTest.php index ad008b2c5b5..61925a3a7b7 100644 --- a/tests/Functional/StatementTest.php +++ b/tests/Functional/StatementTest.php @@ -303,7 +303,7 @@ static function (Statement $stmt) { false, ], 'fetch-all' => [ - static function (Statement $stmt) { + static function (Statement $stmt) : array { return $stmt->fetchAll(); }, [], diff --git a/tests/Functional/WriteTest.php b/tests/Functional/WriteTest.php index 1469e6ecec3..a48b4a7ff65 100644 --- a/tests/Functional/WriteTest.php +++ b/tests/Functional/WriteTest.php @@ -169,7 +169,7 @@ public function testLastInsertIdSequence() : void } $sequences = $this->connection->getSchemaManager()->listSequences(); - self::assertCount(1, array_filter($sequences, static function ($sequence) { + self::assertCount(1, array_filter($sequences, static function ($sequence) : bool { return strtolower($sequence->getName()) === 'write_table_id_seq'; })); diff --git a/tests/FunctionalTestCase.php b/tests/FunctionalTestCase.php index 47141c967d7..60b3a069415 100644 --- a/tests/FunctionalTestCase.php +++ b/tests/FunctionalTestCase.php @@ -72,7 +72,7 @@ protected function onNotSuccessfulTest(Throwable $t) : void $queries = ''; $i = count($this->sqlLoggerStack->queries); foreach (array_reverse($this->sqlLoggerStack->queries) as $query) { - $params = array_map(static function ($p) { + $params = array_map(static function ($p) : string { if (is_object($p)) { return get_class($p); } diff --git a/tests/Schema/DB2SchemaManagerTest.php b/tests/Schema/DB2SchemaManagerTest.php index 951340743b0..b0158b98564 100644 --- a/tests/Schema/DB2SchemaManagerTest.php +++ b/tests/Schema/DB2SchemaManagerTest.php @@ -92,7 +92,7 @@ public function testAssetFilteringSetsACallable() : void public function testListTableNamesFiltersAssetNamesCorrectlyWithCallable() : void { $accepted = ['T_FOO', 'T_BAR']; - $this->conn->getConfiguration()->setSchemaAssetsFilter(static function ($assetName) use ($accepted) { + $this->conn->getConfiguration()->setSchemaAssetsFilter(static function ($assetName) use ($accepted) : bool { return in_array($assetName, $accepted, true); }); $this->conn->expects(self::any())->method('quote'); From 2b3b7182f833f2bdcfd3bf993700c59bf8cd0b9c Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 3 Apr 2020 18:01:06 -0700 Subject: [PATCH 12/19] Foreach overwrites $variable with its value variable. --- src/Platforms/SqlitePlatform.php | 4 ++-- src/Query/Expression/CompositeExpression.php | 6 +----- .../SchemaManagerFunctionalTestCase.php | 20 +++++++++---------- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/Platforms/SqlitePlatform.php b/src/Platforms/SqlitePlatform.php index d19e9c42696..30d8a7d4ab1 100644 --- a/src/Platforms/SqlitePlatform.php +++ b/src/Platforms/SqlitePlatform.php @@ -325,8 +325,8 @@ protected function _getCreateTableSQL($name, array $columns, array $options = [] $queryFields = $this->getColumnDeclarationListSQL($columns); if (isset($options['uniqueConstraints']) && ! empty($options['uniqueConstraints'])) { - foreach ($options['uniqueConstraints'] as $name => $definition) { - $queryFields .= ', ' . $this->getUniqueConstraintDeclarationSQL($name, $definition); + foreach ($options['uniqueConstraints'] as $constraintName => $definition) { + $queryFields .= ', ' . $this->getUniqueConstraintDeclarationSQL($constraintName, $definition); } } diff --git a/src/Query/Expression/CompositeExpression.php b/src/Query/Expression/CompositeExpression.php index ba2ffbc28b1..34b71faead2 100644 --- a/src/Query/Expression/CompositeExpression.php +++ b/src/Query/Expression/CompositeExpression.php @@ -119,11 +119,7 @@ public function with($part, ...$parts) : self { $that = clone $this; - $that->parts[] = $part; - - foreach ($parts as $part) { - $that->parts[] = $part; - } + $that->parts = array_merge($that->parts, [$part], $parts); return $that; } diff --git a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php index 01dfd1f0e2c..13134f2aefb 100644 --- a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -171,26 +171,24 @@ public function testListSequences() : void ); } - $sequence = new Sequence('list_sequences_test_seq', 20, 10); - $this->schemaManager->createSequence($sequence); + $this->schemaManager->createSequence( + new Sequence('list_sequences_test_seq', 20, 10) + ); $sequences = $this->schemaManager->listSequences(); self::assertIsArray($sequences, 'listSequences() should return an array.'); - $foundSequence = null; foreach ($sequences as $sequence) { - self::assertInstanceOf(Sequence::class, $sequence, 'Array elements of listSequences() should be Sequence instances.'); - if (strtolower($sequence->getName()) !== 'list_sequences_test_seq') { - continue; - } + if (strtolower($sequence->getName()) === 'list_sequences_test_seq') { + self::assertSame(20, $sequence->getAllocationSize()); + self::assertSame(10, $sequence->getInitialValue()); - $foundSequence = $sequence; + return; + } } - self::assertNotNull($foundSequence, "Sequence with name 'list_sequences_test_seq' was not found."); - self::assertSame(20, $foundSequence->getAllocationSize(), 'Allocation Size is expected to be 20.'); - self::assertSame(10, $foundSequence->getInitialValue(), 'Initial Value is expected to be 10.'); + self::fail('Sequence was not found.'); } public function testListDatabases() : void From e67657828fc7ebf7974133bdbdfde549b143323c Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 3 Apr 2020 18:04:35 -0700 Subject: [PATCH 13/19] Use base64_decode() in strict mode --- tests/Functional/StatementTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Functional/StatementTest.php b/tests/Functional/StatementTest.php index 61925a3a7b7..59813218b59 100644 --- a/tests/Functional/StatementTest.php +++ b/tests/Functional/StatementTest.php @@ -118,7 +118,7 @@ public function testFetchLongBlob() : void Za4tXHUiPyB8Vm781oaT+3fN6Y/eUFDfPkcNWetNxb+tlxEZsPqPdZMOzS4rxwJ8CDC+ABj1+Tu0 d+N0hqezcjblboJ3Bj8ARJilHX4FAAA= EOF - ); + , true); $this->connection->insert('stmt_long_blob', ['contents' => $contents], [ParameterType::LARGE_OBJECT]); From 20c5931c5e508280e9e3d7d6aca571777b857bed Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 3 Apr 2020 18:15:38 -0700 Subject: [PATCH 14/19] Variable method call on an object --- phpstan.neon.dist | 7 +++++++ tests/ConnectionTest.php | 40 +++++++++++++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 7cb093cbd21..ca7a4e8ed3c 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -103,5 +103,12 @@ parameters: message: '~^Variable property access on object\.~' paths: - %currentWorkingDirectory%/src/Driver/*/*Statement.php + + # Some APIs use variable method calls internally + - + message: '~^Variable method call on .*~' + paths: + - %currentWorkingDirectory%/src/Schema/AbstractSchemaManager.php + - %currentWorkingDirectory%/src/Schema/Column.php includes: - vendor/phpstan/phpstan-strict-rules/rules.neon diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index 84156339408..ef14ea66ff8 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -183,7 +183,7 @@ public function testEventManagerPassedToPlatform() : void * @requires extension pdo_sqlite * @dataProvider getQueryMethods */ - public function testDriverExceptionIsWrapped(string $method) : void + public function testDriverExceptionIsWrapped(callable $callback) : void { $this->expectException(DBALException::class); $this->expectExceptionMessage("An exception occurred while executing 'MUUHAAAAHAAAA':\n\nSQLSTATE[HY000]: General error: 1 near \"MUUHAAAAHAAAA\""); @@ -193,20 +193,42 @@ public function testDriverExceptionIsWrapped(string $method) : void 'memory' => true, ]); - $connection->$method('MUUHAAAAHAAAA'); + $callback($connection, 'MUUHAAAAHAAAA'); } /** - * @return array> + * @return iterable> */ public static function getQueryMethods() : iterable { - return [ - ['exec'], - ['query'], - ['executeQuery'], - ['executeUpdate'], - ['prepare'], + yield 'exec' => [ + static function (Connection $connection, string $statement) : void { + $connection->exec($statement); + }, + ]; + + yield 'query' => [ + static function (Connection $connection, string $statement) : void { + $connection->query($statement); + }, + ]; + + yield 'executeQuery' => [ + static function (Connection $connection, string $statement) : void { + $connection->executeQuery($statement); + }, + ]; + + yield 'executeUpdate' => [ + static function (Connection $connection, string $statement) : void { + $connection->executeUpdate($statement); + }, + ]; + + yield 'prepare' => [ + static function (Connection $connection, string $statement) : void { + $connection->prepare($statement); + }, ]; } From 7acf85c5a78dd17e95e2b2edb4f9286e0306f449 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 3 Apr 2020 18:19:22 -0700 Subject: [PATCH 15/19] Reworked implicit array creation --- src/Platforms/AbstractPlatform.php | 2 +- tests/Functional/DataAccessTest.php | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/Platforms/AbstractPlatform.php b/src/Platforms/AbstractPlatform.php index 49f4312006f..3da275ece4a 100644 --- a/src/Platforms/AbstractPlatform.php +++ b/src/Platforms/AbstractPlatform.php @@ -1714,7 +1714,7 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options } $query .= ')'; - $sql[] = $query; + $sql = [$query]; if (isset($options['foreignKeys'])) { foreach ((array) $options['foreignKeys'] as $definition) { diff --git a/tests/Functional/DataAccessTest.php b/tests/Functional/DataAccessTest.php index 6bbd52cfab2..2706f3b3176 100644 --- a/tests/Functional/DataAccessTest.php +++ b/tests/Functional/DataAccessTest.php @@ -20,13 +20,11 @@ use Doctrine\DBAL\Types\Types; use PDO; use const CASE_LOWER; -use const PHP_EOL; use function array_change_key_case; use function array_filter; 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; @@ -701,14 +699,12 @@ 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 = 'SELECT test_int, test_string' + . ', ' . $platform->getBitOrComparisonExpression('test_int', 2) . ' AS bit_or' + . ', ' . $platform->getBitAndComparisonExpression('test_int', 2) . ' AS bit_and' + . ' FROM fetch_table'; - $stmt = $this->connection->executeQuery(implode(PHP_EOL, $sql)); + $stmt = $this->connection->executeQuery($sql); $data = $stmt->fetchAll(FetchMode::ASSOCIATIVE); self::assertCount(4, $data); From d45fd7ad5c712ff7237d80218ed423e4fd2c59df Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 3 Apr 2020 18:29:56 -0700 Subject: [PATCH 16/19] Fixed return values types to match the parent method types --- tests/Platforms/OraclePlatformTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/Platforms/OraclePlatformTest.php b/tests/Platforms/OraclePlatformTest.php index 458a7763644..02c19eaf81c 100644 --- a/tests/Platforms/OraclePlatformTest.php +++ b/tests/Platforms/OraclePlatformTest.php @@ -87,7 +87,7 @@ public function getGenerateTableSql() : string } /** - * @return mixed[] + * {@inheritDoc} */ public function getGenerateTableWithMultiColumnUniqueIndexSql() : array { @@ -405,7 +405,7 @@ public function getBitOrComparisonExpressionSql(string $value1, string $value2) } /** - * @return mixed[] + * {@inheritDoc} */ protected function getQuotedColumnInPrimaryKeySQL() : array { @@ -413,7 +413,7 @@ protected function getQuotedColumnInPrimaryKeySQL() : array } /** - * @return mixed[] + * {@inheritDoc} */ protected function getQuotedColumnInIndexSQL() : array { @@ -424,7 +424,7 @@ protected function getQuotedColumnInIndexSQL() : array } /** - * @return mixed[] + * {@inheritDoc} */ protected function getQuotedNameInIndexSQL() : array { @@ -435,7 +435,7 @@ protected function getQuotedNameInIndexSQL() : array } /** - * @return mixed[] + * {@inheritDoc} */ protected function getQuotedColumnInForeignKeySQL() : array { From 0a57e8ed826ca03ae03abaf69378853020ef5ecc Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 3 Apr 2020 18:31:28 -0700 Subject: [PATCH 17/19] Removed redundant casting to string --- tests/Query/Expression/ExpressionBuilderTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Query/Expression/ExpressionBuilderTest.php b/tests/Query/Expression/ExpressionBuilderTest.php index c319dfd7e4b..91b6e61ab29 100644 --- a/tests/Query/Expression/ExpressionBuilderTest.php +++ b/tests/Query/Expression/ExpressionBuilderTest.php @@ -179,7 +179,7 @@ public function testComparison(string $leftExpr, string $operator, string $right { $part = $this->expr->comparison($leftExpr, $operator, $rightExpr); - self::assertEquals($expected, (string) $part); + self::assertEquals($expected, $part); } /** From 559c6bae428ed23674b53660ec4203705c27a7a1 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 3 Apr 2020 18:40:45 -0700 Subject: [PATCH 18/19] Only numeric types are allowed in +/- --- phpstan.neon.dist | 6 ++++++ src/Schema/DB2SchemaManager.php | 11 +++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index ca7a4e8ed3c..867cc3bdc29 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -110,5 +110,11 @@ parameters: paths: - %currentWorkingDirectory%/src/Schema/AbstractSchemaManager.php - %currentWorkingDirectory%/src/Schema/Column.php + + # https://github.com/phpstan/phpstan/issues/3146 + - + message: '~^Only numeric types are allowed in -, int<1, max>\|false given on the left side\.~' + paths: + - %currentWorkingDirectory%/src/Platforms/SQLServer2012Platform.php includes: - vendor/phpstan/phpstan-strict-rules/rules.neon diff --git a/src/Schema/DB2SchemaManager.php b/src/Schema/DB2SchemaManager.php index 8a1c7a30825..7045d275fd5 100644 --- a/src/Schema/DB2SchemaManager.php +++ b/src/Schema/DB2SchemaManager.php @@ -6,7 +6,6 @@ use Doctrine\DBAL\Types\Type; use const CASE_LOWER; use function array_change_key_case; -use function is_resource; use function preg_match; use function str_replace; use function strpos; @@ -201,11 +200,11 @@ 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 = substr($view['text'], $pos+4); + + $position = strpos($view['text'], ' AS '); + + if ($position !== false) { + $sql = substr($view['text'], $position + 4); } else { $sql = ''; } From b8066db4b41f5aef0d90e062716a0c9fcc77addc Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Mon, 6 Apr 2020 11:13:38 -0700 Subject: [PATCH 19/19] Declared Driver\Statement::bind(Parameter|Value) $name argument as string|ing --- src/Driver/IBMDB2/DB2Statement.php | 4 +++ .../SQLAnywhere/SQLAnywhereStatement.php | 3 ++ src/Driver/Statement.php | 28 +++++++++---------- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/Driver/IBMDB2/DB2Statement.php b/src/Driver/IBMDB2/DB2Statement.php index 86bebd17323..6c8c5cb3b7e 100644 --- a/src/Driver/IBMDB2/DB2Statement.php +++ b/src/Driver/IBMDB2/DB2Statement.php @@ -18,6 +18,7 @@ use const DB2_PARAM_FILE; use const DB2_PARAM_IN; use function array_change_key_case; +use function assert; use function count; use function db2_bind_param; use function db2_execute; @@ -34,6 +35,7 @@ use function fclose; use function fwrite; use function gettype; +use function is_int; use function is_object; use function is_resource; use function is_string; @@ -97,6 +99,8 @@ public function bindValue($param, $value, $type = ParameterType::STRING) */ public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null) { + assert(is_int($column)); + switch ($type) { case ParameterType::INTEGER: $this->bind($column, $variable, DB2_PARAM_IN, DB2_LONG); diff --git a/src/Driver/SQLAnywhere/SQLAnywhereStatement.php b/src/Driver/SQLAnywhere/SQLAnywhereStatement.php index e1dbd770c93..0667617426a 100644 --- a/src/Driver/SQLAnywhere/SQLAnywhereStatement.php +++ b/src/Driver/SQLAnywhere/SQLAnywhereStatement.php @@ -12,6 +12,7 @@ use stdClass; use const SASQL_BOTH; use function array_key_exists; +use function assert; use function count; use function gettype; use function is_int; @@ -88,6 +89,8 @@ public function __construct($conn, $sql) */ public function bindParam($column, &$variable, $type = ParameterType::STRING, $length = null) { + assert(is_int($column)); + switch ($type) { case ParameterType::INTEGER: case ParameterType::BOOLEAN: diff --git a/src/Driver/Statement.php b/src/Driver/Statement.php index fd3c0bd0bf6..01d84e5d3c2 100644 --- a/src/Driver/Statement.php +++ b/src/Driver/Statement.php @@ -19,12 +19,12 @@ interface Statement extends ResultStatement * As mentioned above, the named parameters are not natively supported by the mysqli driver, use executeQuery(), * fetchAll(), fetchArray(), fetchColumn(), fetchAssoc() methods to have the named parameter emulated by doctrine. * - * @param mixed $param Parameter identifier. For a prepared statement using named placeholders, - * this will be a parameter name of the form :name. For a prepared statement - * using question mark placeholders, this will be the 1-indexed position of the parameter. - * @param mixed $value The value to bind to the parameter. - * @param int $type Explicit data type for the parameter using the {@link \Doctrine\DBAL\ParameterType} - * constants. + * @param string|int $param Parameter identifier. For a prepared statement using named placeholders, + * this will be a parameter name of the form :name. For a prepared statement + * using question mark placeholders, this will be the 1-indexed position of the parameter. + * @param mixed $value The value to bind to the parameter. + * @param int $type Explicit data type for the parameter using the {@link \Doctrine\DBAL\ParameterType} + * constants. * * @return bool TRUE on success or FALSE on failure. */ @@ -44,14 +44,14 @@ public function bindValue($param, $value, $type = ParameterType::STRING); * of stored procedures that return data as output parameters, and some also as input/output * parameters that both send in data and are updated to receive it. * - * @param mixed $column Parameter identifier. For a prepared statement using named placeholders, - * this will be a parameter name of the form :name. For a prepared statement using - * question mark placeholders, this will be the 1-indexed position of the parameter. - * @param mixed $variable Name of the PHP variable to bind to the SQL statement parameter. - * @param int $type Explicit data type for the parameter using the {@link \Doctrine\DBAL\ParameterType} - * constants. - * @param int|null $length You must specify maxlength when using an OUT bind - * so that PHP allocates enough memory to hold the returned value. + * @param string|int $column Parameter identifier. For a prepared statement using named placeholders, + * this will be a parameter name of the form :name. For a prepared statement using + * question mark placeholders, this will be the 1-indexed position of the parameter. + * @param mixed $variable Name of the PHP variable to bind to the SQL statement parameter. + * @param int $type Explicit data type for the parameter using the {@link \Doctrine\DBAL\ParameterType} + * constants. + * @param int|null $length You must specify maxlength when using an OUT bind + * so that PHP allocates enough memory to hold the returned value. * * @return bool TRUE on success or FALSE on failure. */