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:
message: '~^Cannot cast array<string>\|bool\|string\|null to int\.$~'
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
-
message: '~^Access to undefined constant PDO::PGSQL_ATTR_DISABLE_PREPARES\.$~'
......@@ -135,5 +145,9 @@ parameters:
paths:
- %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:
- vendor/phpstan/phpstan-strict-rules/rules.neon
<?xml version="1.0"?>
<psalm
totallyTyped="false"
errorLevel="6"
errorLevel="5"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
......@@ -32,6 +32,23 @@
<file name="src/Driver/OCI8/OCI8Statement.php"/>
</errorLevel>
</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>
<errorLevel type="suppress">
<!--
......
......@@ -92,11 +92,7 @@ class CachingResult implements Result
*/
public function fetchAllNumeric(): array
{
$this->store(
$this->result->fetchAllAssociative()
);
return array_map('array_values', $this->data);
return array_map('array_values', $this->result->fetchAllAssociative());
}
/**
......@@ -104,11 +100,11 @@ class CachingResult implements Result
*/
public function fetchAllAssociative(): array
{
$this->store(
$this->result->fetchAllAssociative()
);
$data = $this->result->fetchAllAssociative();
$this->store($data);
return $this->data;
return $data;
}
/**
......
......@@ -71,13 +71,6 @@ class Connection implements DriverConnection
/** @var ExpressionBuilder */
protected $_expr;
/**
* Whether or not a connection has been established.
*
* @var bool
*/
private $isConnected = false;
/**
* The current auto-commit mode of this connection.
*
......@@ -284,7 +277,7 @@ class Connection implements DriverConnection
*/
public function connect()
{
if ($this->isConnected) {
if ($this->_conn !== null) {
return false;
}
......@@ -294,8 +287,6 @@ class Connection implements DriverConnection
throw DBALException::driverException($this->_driver, $e);
}
$this->isConnected = true;
$this->transactionNestingLevel = 0;
if ($this->autoCommit === false) {
......@@ -453,7 +444,7 @@ class Connection implements DriverConnection
$this->autoCommit = $autoCommit;
// 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;
}
......@@ -530,7 +521,7 @@ class Connection implements DriverConnection
*/
public function isConnected()
{
return $this->isConnected;
return $this->_conn !== null;
}
/**
......@@ -612,8 +603,6 @@ class Connection implements DriverConnection
public function close()
{
$this->_conn = null;
$this->isConnected = false;
}
/**
......@@ -904,6 +893,8 @@ class Connection implements DriverConnection
*
* @param string $sql The SQL statement to prepare.
*
* @return Statement
*
* @throws DBALException
*/
public function prepare(string $sql): DriverStatement
......@@ -1435,6 +1426,8 @@ class Connection implements DriverConnection
{
$this->connect();
assert($this->_conn !== null);
return $this->_conn;
}
......
......@@ -55,6 +55,8 @@ class DB2Statement implements Statement
*/
public function bindValue($param, $value, $type = ParameterType::STRING)
{
assert(is_int($param));
return $this->bindParam($param, $value, $type);
}
......
......@@ -40,7 +40,11 @@ class PDOConnection implements ServerInfoAwareConnection
public function exec(string $statement): int
{
try {
return $this->connection->exec($statement);
$result = $this->connection->exec($statement);
assert($result !== false);
return $result;
} catch (\PDOException $exception) {
throw new PDOException($exception);
}
......
......@@ -101,6 +101,9 @@ class Connection extends BaseConnection
);
}
/**
* @return Statement
*/
public function prepare(string $sql): DriverStatement
{
return new Statement(parent::prepare($sql), $this->converter);
......
......@@ -397,7 +397,7 @@ class QueryBuilder
* Gets the maximum number of results the query object was set to retrieve (the "limit").
* 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()
{
......
......@@ -632,7 +632,10 @@ class ConnectionTest extends TestCase
{
$driver = $this->createMock(Driver::class);
$driver->expects(self::once())
->method('connect');
->method('connect')
->willReturn(
$this->createMock(Driver\Connection::class)
);
$platform = $this->createMock(AbstractPlatform::class);
......
......@@ -3,7 +3,6 @@
namespace Doctrine\DBAL\Tests\Functional\Driver\PDOSqlsrv;
use Doctrine\DBAL\Driver as DriverInterface;
use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\Driver\PDOSqlsrv\Driver;
use Doctrine\DBAL\Tests\Functional\Driver\AbstractDriverTest;
......@@ -44,7 +43,7 @@ class DriverTest extends AbstractDriverTest
/**
* @param int[]|string[] $driverOptions
*/
protected function getConnection(array $driverOptions): Connection
private function getConnection(array $driverOptions): PDOConnection
{
return $this->connection->getDriver()->connect(
array_merge(
......
......@@ -3,6 +3,7 @@
namespace Doctrine\DBAL\Tests\Functional\Ticket;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
use Doctrine\DBAL\Tests\FunctionalTestCase;
......@@ -36,7 +37,7 @@ class DBAL630Test extends FunctionalTestCase
protected function tearDown(): void
{
if ($this->running) {
$this->connection->getWrappedConnection()
$this->getWrappedConnection()
->getWrappedConnection()
->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
}
......@@ -72,7 +73,7 @@ class DBAL630Test extends FunctionalTestCase
public function testBooleanConversionBoolParamEmulatedPrepares(): void
{
$this->connection->getWrappedConnection()
$this->getWrappedConnection()
->getWrappedConnection()
->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
......@@ -98,7 +99,7 @@ class DBAL630Test extends FunctionalTestCase
?bool $statementValue,
?bool $databaseConvertedValue
): void {
$this->connection->getWrappedConnection()
$this->getWrappedConnection()
->getWrappedConnection()
->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
......@@ -124,7 +125,7 @@ class DBAL630Test extends FunctionalTestCase
?bool $statementValue,
bool $databaseConvertedValue
): void {
$this->connection->getWrappedConnection()
$this->getWrappedConnection()
->getWrappedConnection()
->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
......@@ -176,4 +177,12 @@ class DBAL630Test extends FunctionalTestCase
[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
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)';
}
......
......@@ -246,7 +246,7 @@ abstract class AbstractPlatformTestCase extends TestCase
self::assertEquals($sql, $this->getGenerateForeignKeySql());
}
abstract public function getGenerateForeignKeySql(): string;
abstract protected function getGenerateForeignKeySql(): string;
public function testGeneratesConstraintCreationSql(): void
{
......
......@@ -64,7 +64,7 @@ abstract class AbstractPostgreSQLPlatformTestCase extends AbstractPlatformTestCa
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';
}
......
......@@ -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';
}
public function getGenerateForeignKeySql(): string
protected function getGenerateForeignKeySql(): string
{
return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)';
}
......
......@@ -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)';
}
......
......@@ -235,7 +235,7 @@ class OraclePlatformTest extends AbstractPlatformTestCase
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)';
}
......
......@@ -286,9 +286,9 @@ class SqlitePlatformTest extends AbstractPlatformTestCase
parent::testGeneratesConstraintCreationSql();
}
public function getGenerateForeignKeySql(): string
protected function getGenerateForeignKeySql(): string
{
return null;
return '';
}
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