Unverified Commit 4509f271 authored by Sergei Morozov's avatar Sergei Morozov

Merge branch '2.11.x' into 3.0.x

parents 2bd48393 f7e8b5f1
...@@ -75,6 +75,16 @@ parameters: ...@@ -75,6 +75,16 @@ parameters:
message: '~^Cannot cast array<string>\|bool\|string\|null to int\.$~' message: '~^Cannot cast array<string>\|bool\|string\|null to int\.$~'
path: %currentWorkingDirectory%/src/Tools/Console/Command/RunSqlCommand.php path: %currentWorkingDirectory%/src/Tools/Console/Command/RunSqlCommand.php
# Requires a release of https://github.com/JetBrains/phpstorm-stubs/pull/553
-
message: '~^Call to function assert\(\) with true will always evaluate to true\.$~'
path: %currentWorkingDirectory%/src/Driver/PDOConnection.php
# Requires a release of https://github.com/JetBrains/phpstorm-stubs/pull/553
-
message: '~^Strict comparison using !== between int and false will always evaluate to true\.$~'
path: %currentWorkingDirectory%/src/Driver/PDOConnection.php
# Requires a release of https://github.com/JetBrains/phpstorm-stubs/pull/732 # Requires a release of https://github.com/JetBrains/phpstorm-stubs/pull/732
- -
message: '~^Access to undefined constant PDO::PGSQL_ATTR_DISABLE_PREPARES\.$~' message: '~^Access to undefined constant PDO::PGSQL_ATTR_DISABLE_PREPARES\.$~'
...@@ -135,5 +145,9 @@ parameters: ...@@ -135,5 +145,9 @@ parameters:
paths: paths:
- %currentWorkingDirectory%/src/Driver/PDOSqlsrv/Connection.php - %currentWorkingDirectory%/src/Driver/PDOSqlsrv/Connection.php
-
message: '~Return type \(Doctrine\\DBAL\\Portability\\Statement\) of method Doctrine\\DBAL\\Portability\\Connection::prepare\(\) should be compatible with return type \(Doctrine\\DBAL\\Statement\) of method Doctrine\\DBAL\\Connection::prepare\(\)~'
paths:
- %currentWorkingDirectory%/src/Portability/Connection.php
includes: includes:
- vendor/phpstan/phpstan-strict-rules/rules.neon - vendor/phpstan/phpstan-strict-rules/rules.neon
<?xml version="1.0"?> <?xml version="1.0"?>
<psalm <psalm
totallyTyped="false" totallyTyped="false"
errorLevel="6" errorLevel="5"
resolveFromConfigFile="true" resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config" xmlns="https://getpsalm.org/schema/config"
...@@ -32,6 +32,23 @@ ...@@ -32,6 +32,23 @@
<file name="src/Driver/OCI8/OCI8Statement.php"/> <file name="src/Driver/OCI8/OCI8Statement.php"/>
</errorLevel> </errorLevel>
</ConflictingReferenceConstraint> </ConflictingReferenceConstraint>
<FalsableReturnStatement>
<errorLevel type="suppress">
<!--
Fixing these issues requires an API change
-->
<file name="src/Driver/PDOSqlsrv/Connection.php"/>
<file name="src/Driver/SQLSrv/SQLSrvConnection.php"/>
</errorLevel>
</FalsableReturnStatement>
<NullableReturnStatement>
<errorLevel type="suppress">
<!--
Fixing this issue requires an API change
-->
<file name="src/Driver/AbstractSQLiteDriver.php"/>
</errorLevel>
</NullableReturnStatement>
<TooFewArguments> <TooFewArguments>
<errorLevel type="suppress"> <errorLevel type="suppress">
<!-- <!--
......
...@@ -92,11 +92,7 @@ class CachingResult implements Result ...@@ -92,11 +92,7 @@ class CachingResult implements Result
*/ */
public function fetchAllNumeric(): array public function fetchAllNumeric(): array
{ {
$this->store( return array_map('array_values', $this->result->fetchAllAssociative());
$this->result->fetchAllAssociative()
);
return array_map('array_values', $this->data);
} }
/** /**
...@@ -104,11 +100,11 @@ class CachingResult implements Result ...@@ -104,11 +100,11 @@ class CachingResult implements Result
*/ */
public function fetchAllAssociative(): array public function fetchAllAssociative(): array
{ {
$this->store( $data = $this->result->fetchAllAssociative();
$this->result->fetchAllAssociative()
); $this->store($data);
return $this->data; return $data;
} }
/** /**
......
...@@ -71,13 +71,6 @@ class Connection implements DriverConnection ...@@ -71,13 +71,6 @@ class Connection implements DriverConnection
/** @var ExpressionBuilder */ /** @var ExpressionBuilder */
protected $_expr; protected $_expr;
/**
* Whether or not a connection has been established.
*
* @var bool
*/
private $isConnected = false;
/** /**
* The current auto-commit mode of this connection. * The current auto-commit mode of this connection.
* *
...@@ -284,7 +277,7 @@ class Connection implements DriverConnection ...@@ -284,7 +277,7 @@ class Connection implements DriverConnection
*/ */
public function connect() public function connect()
{ {
if ($this->isConnected) { if ($this->_conn !== null) {
return false; return false;
} }
...@@ -294,8 +287,6 @@ class Connection implements DriverConnection ...@@ -294,8 +287,6 @@ class Connection implements DriverConnection
throw DBALException::driverException($this->_driver, $e); throw DBALException::driverException($this->_driver, $e);
} }
$this->isConnected = true;
$this->transactionNestingLevel = 0; $this->transactionNestingLevel = 0;
if ($this->autoCommit === false) { if ($this->autoCommit === false) {
...@@ -453,7 +444,7 @@ class Connection implements DriverConnection ...@@ -453,7 +444,7 @@ class Connection implements DriverConnection
$this->autoCommit = $autoCommit; $this->autoCommit = $autoCommit;
// Commit all currently active transactions if any when switching auto-commit mode. // Commit all currently active transactions if any when switching auto-commit mode.
if ($this->isConnected !== true || $this->transactionNestingLevel === 0) { if ($this->_conn === null || $this->transactionNestingLevel === 0) {
return; return;
} }
...@@ -530,7 +521,7 @@ class Connection implements DriverConnection ...@@ -530,7 +521,7 @@ class Connection implements DriverConnection
*/ */
public function isConnected() public function isConnected()
{ {
return $this->isConnected; return $this->_conn !== null;
} }
/** /**
...@@ -612,8 +603,6 @@ class Connection implements DriverConnection ...@@ -612,8 +603,6 @@ class Connection implements DriverConnection
public function close() public function close()
{ {
$this->_conn = null; $this->_conn = null;
$this->isConnected = false;
} }
/** /**
...@@ -904,6 +893,8 @@ class Connection implements DriverConnection ...@@ -904,6 +893,8 @@ class Connection implements DriverConnection
* *
* @param string $sql The SQL statement to prepare. * @param string $sql The SQL statement to prepare.
* *
* @return Statement
*
* @throws DBALException * @throws DBALException
*/ */
public function prepare(string $sql): DriverStatement public function prepare(string $sql): DriverStatement
...@@ -1435,6 +1426,8 @@ class Connection implements DriverConnection ...@@ -1435,6 +1426,8 @@ class Connection implements DriverConnection
{ {
$this->connect(); $this->connect();
assert($this->_conn !== null);
return $this->_conn; return $this->_conn;
} }
......
...@@ -55,6 +55,8 @@ class DB2Statement implements Statement ...@@ -55,6 +55,8 @@ class DB2Statement implements Statement
*/ */
public function bindValue($param, $value, $type = ParameterType::STRING) public function bindValue($param, $value, $type = ParameterType::STRING)
{ {
assert(is_int($param));
return $this->bindParam($param, $value, $type); return $this->bindParam($param, $value, $type);
} }
......
...@@ -40,7 +40,11 @@ class PDOConnection implements ServerInfoAwareConnection ...@@ -40,7 +40,11 @@ class PDOConnection implements ServerInfoAwareConnection
public function exec(string $statement): int public function exec(string $statement): int
{ {
try { try {
return $this->connection->exec($statement); $result = $this->connection->exec($statement);
assert($result !== false);
return $result;
} catch (\PDOException $exception) { } catch (\PDOException $exception) {
throw new PDOException($exception); throw new PDOException($exception);
} }
......
...@@ -101,6 +101,9 @@ class Connection extends BaseConnection ...@@ -101,6 +101,9 @@ class Connection extends BaseConnection
); );
} }
/**
* @return Statement
*/
public function prepare(string $sql): DriverStatement public function prepare(string $sql): DriverStatement
{ {
return new Statement(parent::prepare($sql), $this->converter); return new Statement(parent::prepare($sql), $this->converter);
......
...@@ -397,7 +397,7 @@ class QueryBuilder ...@@ -397,7 +397,7 @@ class QueryBuilder
* Gets the maximum number of results the query object was set to retrieve (the "limit"). * Gets the maximum number of results the query object was set to retrieve (the "limit").
* Returns NULL if all results will be returned. * Returns NULL if all results will be returned.
* *
* @return int The maximum number of results. * @return int|null The maximum number of results.
*/ */
public function getMaxResults() public function getMaxResults()
{ {
......
...@@ -632,7 +632,10 @@ class ConnectionTest extends TestCase ...@@ -632,7 +632,10 @@ class ConnectionTest extends TestCase
{ {
$driver = $this->createMock(Driver::class); $driver = $this->createMock(Driver::class);
$driver->expects(self::once()) $driver->expects(self::once())
->method('connect'); ->method('connect')
->willReturn(
$this->createMock(Driver\Connection::class)
);
$platform = $this->createMock(AbstractPlatform::class); $platform = $this->createMock(AbstractPlatform::class);
......
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
namespace Doctrine\DBAL\Tests\Functional\Driver\PDOSqlsrv; namespace Doctrine\DBAL\Tests\Functional\Driver\PDOSqlsrv;
use Doctrine\DBAL\Driver as DriverInterface; use Doctrine\DBAL\Driver as DriverInterface;
use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Driver\PDOConnection; use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\Driver\PDOSqlsrv\Driver; use Doctrine\DBAL\Driver\PDOSqlsrv\Driver;
use Doctrine\DBAL\Tests\Functional\Driver\AbstractDriverTest; use Doctrine\DBAL\Tests\Functional\Driver\AbstractDriverTest;
...@@ -44,7 +43,7 @@ class DriverTest extends AbstractDriverTest ...@@ -44,7 +43,7 @@ class DriverTest extends AbstractDriverTest
/** /**
* @param int[]|string[] $driverOptions * @param int[]|string[] $driverOptions
*/ */
protected function getConnection(array $driverOptions): Connection private function getConnection(array $driverOptions): PDOConnection
{ {
return $this->connection->getDriver()->connect( return $this->connection->getDriver()->connect(
array_merge( array_merge(
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Doctrine\DBAL\Tests\Functional\Ticket; namespace Doctrine\DBAL\Tests\Functional\Ticket;
use Doctrine\DBAL\DBALException; use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\PostgreSQL94Platform; use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
use Doctrine\DBAL\Tests\FunctionalTestCase; use Doctrine\DBAL\Tests\FunctionalTestCase;
...@@ -36,7 +37,7 @@ class DBAL630Test extends FunctionalTestCase ...@@ -36,7 +37,7 @@ class DBAL630Test extends FunctionalTestCase
protected function tearDown(): void protected function tearDown(): void
{ {
if ($this->running) { if ($this->running) {
$this->connection->getWrappedConnection() $this->getWrappedConnection()
->getWrappedConnection() ->getWrappedConnection()
->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); ->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
} }
...@@ -72,7 +73,7 @@ class DBAL630Test extends FunctionalTestCase ...@@ -72,7 +73,7 @@ class DBAL630Test extends FunctionalTestCase
public function testBooleanConversionBoolParamEmulatedPrepares(): void public function testBooleanConversionBoolParamEmulatedPrepares(): void
{ {
$this->connection->getWrappedConnection() $this->getWrappedConnection()
->getWrappedConnection() ->getWrappedConnection()
->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); ->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
...@@ -98,7 +99,7 @@ class DBAL630Test extends FunctionalTestCase ...@@ -98,7 +99,7 @@ class DBAL630Test extends FunctionalTestCase
?bool $statementValue, ?bool $statementValue,
?bool $databaseConvertedValue ?bool $databaseConvertedValue
): void { ): void {
$this->connection->getWrappedConnection() $this->getWrappedConnection()
->getWrappedConnection() ->getWrappedConnection()
->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); ->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
...@@ -124,7 +125,7 @@ class DBAL630Test extends FunctionalTestCase ...@@ -124,7 +125,7 @@ class DBAL630Test extends FunctionalTestCase
?bool $statementValue, ?bool $statementValue,
bool $databaseConvertedValue bool $databaseConvertedValue
): void { ): void {
$this->connection->getWrappedConnection() $this->getWrappedConnection()
->getWrappedConnection() ->getWrappedConnection()
->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); ->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
...@@ -176,4 +177,12 @@ class DBAL630Test extends FunctionalTestCase ...@@ -176,4 +177,12 @@ class DBAL630Test extends FunctionalTestCase
[null, null], [null, null],
]; ];
} }
private function getWrappedConnection(): PDOConnection
{
$connection = $this->connection->getWrappedConnection();
self::assertInstanceOf(PDOConnection::class, $connection);
return $connection;
}
} }
...@@ -153,7 +153,7 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase ...@@ -153,7 +153,7 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
return 'CREATE UNIQUE INDEX index_name ON test (test, test2)'; return 'CREATE UNIQUE INDEX index_name ON test (test, test2)';
} }
public function getGenerateForeignKeySql(): string protected function getGenerateForeignKeySql(): string
{ {
return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)'; return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)';
} }
......
...@@ -246,7 +246,7 @@ abstract class AbstractPlatformTestCase extends TestCase ...@@ -246,7 +246,7 @@ abstract class AbstractPlatformTestCase extends TestCase
self::assertEquals($sql, $this->getGenerateForeignKeySql()); self::assertEquals($sql, $this->getGenerateForeignKeySql());
} }
abstract public function getGenerateForeignKeySql(): string; abstract protected function getGenerateForeignKeySql(): string;
public function testGeneratesConstraintCreationSql(): void public function testGeneratesConstraintCreationSql(): void
{ {
......
...@@ -64,7 +64,7 @@ abstract class AbstractPostgreSQLPlatformTestCase extends AbstractPlatformTestCa ...@@ -64,7 +64,7 @@ abstract class AbstractPostgreSQLPlatformTestCase extends AbstractPlatformTestCa
return 'CREATE INDEX my_idx ON mytable (user_name, last_login)'; return 'CREATE INDEX my_idx ON mytable (user_name, last_login)';
} }
public function getGenerateForeignKeySql(): string protected function getGenerateForeignKeySql(): string
{ {
return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id) NOT DEFERRABLE INITIALLY IMMEDIATE'; return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id) NOT DEFERRABLE INITIALLY IMMEDIATE';
} }
......
...@@ -181,7 +181,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas ...@@ -181,7 +181,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
return 'CREATE UNIQUE INDEX index_name ON test (test, test2) WHERE test IS NOT NULL AND test2 IS NOT NULL'; return 'CREATE UNIQUE INDEX index_name ON test (test, test2) WHERE test IS NOT NULL AND test2 IS NOT NULL';
} }
public function getGenerateForeignKeySql(): string protected function getGenerateForeignKeySql(): string
{ {
return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)'; return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)';
} }
......
...@@ -42,7 +42,7 @@ class DB2PlatformTest extends AbstractPlatformTestCase ...@@ -42,7 +42,7 @@ class DB2PlatformTest extends AbstractPlatformTestCase
]; ];
} }
public function getGenerateForeignKeySql(): string protected function getGenerateForeignKeySql(): string
{ {
return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)'; return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)';
} }
......
...@@ -235,7 +235,7 @@ class OraclePlatformTest extends AbstractPlatformTestCase ...@@ -235,7 +235,7 @@ class OraclePlatformTest extends AbstractPlatformTestCase
return 'CREATE UNIQUE INDEX index_name ON test (test, test2)'; return 'CREATE UNIQUE INDEX index_name ON test (test, test2)';
} }
public function getGenerateForeignKeySql(): string protected function getGenerateForeignKeySql(): string
{ {
return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)'; return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)';
} }
......
...@@ -286,9 +286,9 @@ class SqlitePlatformTest extends AbstractPlatformTestCase ...@@ -286,9 +286,9 @@ class SqlitePlatformTest extends AbstractPlatformTestCase
parent::testGeneratesConstraintCreationSql(); parent::testGeneratesConstraintCreationSql();
} }
public function getGenerateForeignKeySql(): string protected function getGenerateForeignKeySql(): string
{ {
return null; return '';
} }
public function testModifyLimitQuery(): void public function testModifyLimitQuery(): void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment