Unverified Commit 50927b6b authored by Grégoire Paris's avatar Grégoire Paris

Merge remote-tracking branch 'origin/2.10.x' into 2.11.x

parents c7749236 03f139a6
......@@ -8,9 +8,26 @@ jobs:
static-analysis-psalm:
name: Static Analysis with Psalm
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: "Install PHP"
uses: "shivammathur/setup-php@1.8.1"
with:
coverage: "none"
php-version: "7.4"
- name: "Cache dependencies installed with composer"
uses: "actions/cache@v1.0.3"
with:
path: "~/.composer/cache"
key: "composer-${{ hashFiles('composer.json') }}"
restore-keys: "composer-"
- name: "Install dependencies with composer"
run: "composer update --no-interaction --no-progress --no-suggest"
- name: Psalm
uses: docker://vimeo/psalm-github-actions
run: "vendor/bin/psalm"
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="3.11.2@d470903722cfcbc1cd04744c5491d3e6d13ec3d9">
<file src="lib/Doctrine/DBAL/Driver/Connection.php">
<InvalidParamDefault occurrences="1">
<code>int</code>
</InvalidParamDefault>
</file>
<file src="lib/Doctrine/DBAL/Driver/DriverException.php">
<MissingImmutableAnnotation occurrences="1">
<code>public function getMessage();</code>
</MissingImmutableAnnotation>
</file>
<file src="lib/Doctrine/DBAL/Driver/PDOSqlsrv/Statement.php">
<UndefinedConstant occurrences="1">
<code>PDO::SQLSRV_ENCODING_BINARY</code>
</UndefinedConstant>
</file>
<file src="lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php">
<UndefinedFunction occurrences="14">
<code>sasql_pconnect($dsn)</code>
<code>sasql_connect($dsn)</code>
<code>sasql_set_option($this-&gt;connection, 'verbose_errors', false)</code>
<code>sasql_set_option($this-&gt;connection, 'auto_commit', 'on')</code>
<code>sasql_set_option($this-&gt;connection, 'auto_commit', 'off')</code>
<code>sasql_commit($this-&gt;connection)</code>
<code>sasql_errorcode($this-&gt;connection)</code>
<code>sasql_error($this-&gt;connection)</code>
<code>sasql_real_query($this-&gt;connection, $statement)</code>
<code>sasql_affected_rows($this-&gt;connection)</code>
<code>sasql_insert_id($this-&gt;connection)</code>
<code>sasql_escape_string($this-&gt;connection, $input)</code>
<code>sasql_rollback($this-&gt;connection)</code>
<code>sasql_set_option($this-&gt;connection, 'auto_commit', 'on')</code>
</UndefinedFunction>
</file>
<file src="lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereException.php">
<UndefinedFunction occurrences="8">
<code>sasql_sqlstate($conn)</code>
<code>sasql_sqlstate()</code>
<code>sasql_stmt_errno($stmt)</code>
<code>sasql_stmt_error($stmt)</code>
<code>sasql_errorcode($conn)</code>
<code>sasql_error($conn)</code>
<code>sasql_errorcode()</code>
<code>sasql_error()</code>
</UndefinedFunction>
</file>
<file src="lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php">
<UndefinedConstant occurrences="1">
<code>SASQL_BOTH</code>
</UndefinedConstant>
<UndefinedFunction occurrences="14">
<code>sasql_prepare($conn, $sql)</code>
<code>sasql_stmt_bind_param_ex($this-&gt;stmt, $column - 1, $variable, $type, $variable === null)</code>
<code>sasql_stmt_reset($this-&gt;stmt)</code>
<code>sasql_stmt_field_count($this-&gt;stmt)</code>
<code>sasql_stmt_errno($this-&gt;stmt)</code>
<code>sasql_stmt_error($this-&gt;stmt)</code>
<code>sasql_stmt_execute($this-&gt;stmt)</code>
<code>sasql_stmt_result_metadata($this-&gt;stmt)</code>
<code>sasql_fetch_assoc($this-&gt;result)</code>
<code>sasql_fetch_array($this-&gt;result, SASQL_BOTH)</code>
<code>sasql_fetch_object($this-&gt;result)</code>
<code>sasql_fetch_row($this-&gt;result)</code>
<code>sasql_fetch_object($this-&gt;result)</code>
<code>sasql_stmt_affected_rows($this-&gt;stmt)</code>
</UndefinedFunction>
</file>
<file src="lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php">
<TooFewArguments occurrences="1">
<code>sqlsrv_get_field($this-&gt;stmt, 0)</code>
</TooFewArguments>
</file>
<file src="lib/Doctrine/DBAL/Platforms/AbstractPlatform.php">
<InvalidParamDefault occurrences="1">
<code>int</code>
</InvalidParamDefault>
</file>
<file src="lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php">
<InvalidParamDefault occurrences="1">
<code>string</code>
</InvalidParamDefault>
</file>
<file src="lib/Doctrine/DBAL/Tools/Dumper.php">
<UndefinedClass occurrences="1">
<code>Collection</code>
</UndefinedClass>
</file>
<file src="tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php">
<UndefinedConstant occurrences="5">
<code>PDO::PGSQL_ATTR_DISABLE_PREPARES</code>
<code>PDO::PGSQL_ATTR_DISABLE_PREPARES</code>
<code>PDO::PGSQL_ATTR_DISABLE_PREPARES</code>
<code>PDO::PGSQL_ATTR_DISABLE_PREPARES</code>
<code>PDO::PGSQL_ATTR_DISABLE_PREPARES</code>
</UndefinedConstant>
</file>
<file src="tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php">
<UndefinedDocblockClass occurrences="93">
<code>MySqlPlatform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
</UndefinedDocblockClass>
</file>
<file src="tests/Doctrine/Tests/DBAL/Platforms/MariaDb1027PlatformTest.php">
<UndefinedDocblockClass occurrences="4">
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
</UndefinedDocblockClass>
</file>
<file src="tests/Doctrine/Tests/DBAL/Platforms/MySQL57PlatformTest.php">
<UndefinedDocblockClass occurrences="4">
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
<code>$this-&gt;platform</code>
</UndefinedDocblockClass>
</file>
<file src="tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php">
<UndefinedDocblockClass occurrences="1">
<code>$this-&gt;platform</code>
</UndefinedDocblockClass>
</file>
</files>
......@@ -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": "a0ee337c9500698eeb5d25f1e4a84b69",
"content-hash": "b7f970513c9756e5eaaba3974429c23c",
"packages": [
{
"name": "doctrine/cache",
......@@ -816,16 +816,16 @@
},
{
"name": "nikic/php-parser",
"version": "v4.3.0",
"version": "v4.4.0",
"source": {
"type": "git",
"url": "https://github.com/nikic/PHP-Parser.git",
"reference": "9a9981c347c5c49d6dfe5cf826bb882b824080dc"
"reference": "bd43ec7152eaaab3bd8c6d0aa95ceeb1df8ee120"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/9a9981c347c5c49d6dfe5cf826bb882b824080dc",
"reference": "9a9981c347c5c49d6dfe5cf826bb882b824080dc",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/bd43ec7152eaaab3bd8c6d0aa95ceeb1df8ee120",
"reference": "bd43ec7152eaaab3bd8c6d0aa95ceeb1df8ee120",
"shasum": ""
},
"require": {
......@@ -864,7 +864,7 @@
"parser",
"php"
],
"time": "2019-11-08T13:50:10+00:00"
"time": "2020-04-10T16:34:50+00:00"
},
{
"name": "ocramius/package-versions",
......
......@@ -4,6 +4,9 @@ namespace Doctrine\DBAL\Cache;
use Doctrine\DBAL\DBALException;
/**
* @psalm-immutable
*/
class CacheException extends DBALException
{
/**
......
......@@ -823,7 +823,7 @@ class Connection implements DriverConnection
/**
* {@inheritDoc}
*/
public function quote($input, $type = null)
public function quote($input, $type = ParameterType::STRING)
{
$connection = $this->getWrappedConnection();
......
......@@ -2,6 +2,9 @@
namespace Doctrine\DBAL;
/**
* @psalm-immutable
*/
class ConnectionException extends DBALException
{
/**
......
......@@ -22,6 +22,9 @@ use function preg_replace;
use function spl_object_hash;
use function sprintf;
/**
* @psalm-immutable
*/
class DBALException extends Exception
{
/**
......
......@@ -6,6 +6,8 @@ use Exception;
/**
* Abstract base implementation of the {@link DriverException} interface.
*
* @psalm-immutable
*/
abstract class AbstractDriverException extends Exception implements DriverException
{
......
......@@ -9,6 +9,8 @@ use Throwable;
*
* Driver exceptions provide the SQLSTATE of the driver
* and the driver specific error code at the time the error occurred.
*
* @psalm-immutable
*/
interface DriverException extends Throwable
{
......
......@@ -4,6 +4,9 @@ namespace Doctrine\DBAL\Driver\IBMDB2;
use Exception;
/**
* @psalm-immutable
*/
class DB2Exception extends Exception
{
}
......@@ -6,6 +6,8 @@ use Doctrine\DBAL\Driver\AbstractDriverException;
/**
* Exception thrown in case the mysqli driver errors.
*
* @psalm-immutable
*/
class MysqliException extends AbstractDriverException
{
......
......@@ -4,6 +4,9 @@ namespace Doctrine\DBAL\Driver\OCI8;
use Doctrine\DBAL\Driver\AbstractDriverException;
/**
* @psalm-immutable
*/
class OCI8Exception extends AbstractDriverException
{
/**
......
......@@ -4,6 +4,8 @@ namespace Doctrine\DBAL\Driver;
/**
* Tiny wrapper for PDOException instances to implement the {@link DriverException} interface.
*
* @psalm-immutable
*/
class PDOException extends \PDOException implements DriverException
{
......
......@@ -12,6 +12,8 @@ use function sasql_stmt_error;
/**
* SAP Sybase SQL Anywhere driver exception.
*
* @psalm-immutable
*/
class SQLAnywhereException extends AbstractDriverException
{
......
......@@ -7,6 +7,9 @@ use const SQLSRV_ERR_ERRORS;
use function rtrim;
use function sqlsrv_errors;
/**
* @psalm-immutable
*/
class SQLSrvException extends AbstractDriverException
{
/**
......
......@@ -4,6 +4,8 @@ namespace Doctrine\DBAL\Exception;
/**
* Base class for all connection related errors detected in the driver.
*
* @psalm-immutable
*/
class ConnectionException extends DriverException
{
......
......@@ -4,6 +4,8 @@ namespace Doctrine\DBAL\Exception;
/**
* Base class for all constraint violation related errors detected in the driver.
*
* @psalm-immutable
*/
class ConstraintViolationException extends ServerException
{
......
......@@ -8,6 +8,8 @@ namespace Doctrine\DBAL\Exception;
* A database object is considered any asset that can be created in a database
* such as schemas, tables, views, sequences, triggers, constraints, indexes,
* functions, stored procedures etc.
*
* @psalm-immutable
*/
class DatabaseObjectExistsException extends ServerException
{
......
......@@ -8,6 +8,8 @@ namespace Doctrine\DBAL\Exception;
* A database object is considered any asset that can be created in a database
* such as schemas, tables, views, sequences, triggers, constraints, indexes,
* functions, stored procedures etc.
*
* @psalm-immutable
*/
class DatabaseObjectNotFoundException extends ServerException
{
......
......@@ -4,6 +4,8 @@ namespace Doctrine\DBAL\Exception;
/**
* Exception for a deadlock error of a transaction detected in the driver.
*
* @psalm-immutable
*/
class DeadlockException extends ServerException implements RetryableException
{
......
......@@ -7,6 +7,8 @@ use Exception;
/**
* Base class for all errors detected in the driver.
*
* @psalm-immutable
*/
class DriverException extends DBALException
{
......
......@@ -4,6 +4,8 @@ namespace Doctrine\DBAL\Exception;
/**
* Exception for a foreign key constraint violation detected in the driver.
*
* @psalm-immutable
*/
class ForeignKeyConstraintViolationException extends ConstraintViolationException
{
......
......@@ -6,6 +6,8 @@ use Doctrine\DBAL\DBALException;
/**
* Exception to be thrown when invalid arguments are passed to any DBAL API
*
* @psalm-immutable
*/
class InvalidArgumentException extends DBALException
{
......
......@@ -4,6 +4,8 @@ namespace Doctrine\DBAL\Exception;
/**
* Exception for an invalid specified field name in a statement detected in the driver.
*
* @psalm-immutable
*/
class InvalidFieldNameException extends ServerException
{
......
......@@ -4,6 +4,8 @@ namespace Doctrine\DBAL\Exception;
/**
* Exception for a lock wait timeout error of a transaction detected in the driver.
*
* @psalm-immutable
*/
class LockWaitTimeoutException extends ServerException implements RetryableException
{
......
......@@ -4,6 +4,8 @@ namespace Doctrine\DBAL\Exception;
/**
* Exception for a non-unique/ambiguous specified field name in a statement detected in the driver.
*
* @psalm-immutable
*/
class NonUniqueFieldNameException extends ServerException
{
......
......@@ -4,6 +4,8 @@ namespace Doctrine\DBAL\Exception;
/**
* Exception for a NOT NULL constraint violation detected in the driver.
*
* @psalm-immutable
*/
class NotNullConstraintViolationException extends ConstraintViolationException
{
......
......@@ -4,6 +4,8 @@ namespace Doctrine\DBAL\Exception;
/**
* Exception for a write operation attempt on a read-only database element detected in the driver.
*
* @psalm-immutable
*/
class ReadOnlyException extends ServerException
{
......
......@@ -4,6 +4,8 @@ namespace Doctrine\DBAL\Exception;
/**
* Base class for all server related errors detected in the driver.
*
* @psalm-immutable
*/
class ServerException extends DriverException
{
......
......@@ -4,6 +4,8 @@ namespace Doctrine\DBAL\Exception;
/**
* Exception for a syntax error in a statement detected in the driver.
*
* @psalm-immutable
*/
class SyntaxErrorException extends ServerException
{
......
......@@ -4,6 +4,8 @@ namespace Doctrine\DBAL\Exception;
/**
* Exception for an already existing table referenced in a statement detected in the driver.
*
* @psalm-immutable
*/
class TableExistsException extends DatabaseObjectExistsException
{
......
......@@ -4,6 +4,8 @@ namespace Doctrine\DBAL\Exception;
/**
* Exception for an unknown table referenced in a statement detected in the driver.
*
* @psalm-immutable
*/
class TableNotFoundException extends DatabaseObjectNotFoundException
{
......
......@@ -4,6 +4,8 @@ namespace Doctrine\DBAL\Exception;
/**
* Exception for a unique constraint violation detected in the driver.
*
* @psalm-immutable
*/
class UniqueConstraintViolationException extends ConstraintViolationException
{
......
......@@ -807,6 +807,8 @@ class SqlitePlatform extends AbstractPlatform
/**
* {@inheritDoc}
*
* @param int|null $createFlags
*/
public function getCreateTableSQL(Table $table, $createFlags = null)
{
......
......@@ -5,6 +5,9 @@ namespace Doctrine\DBAL\Query;
use Doctrine\DBAL\DBALException;
use function implode;
/**
* @psalm-immutable
*/
class QueryException extends DBALException
{
/**
......
......@@ -6,6 +6,8 @@ use function sprintf;
/**
* Doctrine\DBAL\ConnectionException
*
* @psalm-immutable
*/
class SQLParserUtilsException extends DBALException
{
......
......@@ -287,6 +287,8 @@ class OracleSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*
* @param string|null $database
*
* Calling this method without an argument or by passing NULL is deprecated.
*/
public function createDatabase($database = null)
......
......@@ -6,6 +6,9 @@ use Doctrine\DBAL\DBALException;
use function implode;
use function sprintf;
/**
* @psalm-immutable
*/
class SchemaException extends DBALException
{
public const TABLE_DOESNT_EXIST = 10;
......
......@@ -8,6 +8,8 @@ use Doctrine\DBAL\DBALException;
* Sharding related Exceptions
*
* @deprecated
*
* @psalm-immutable
*/
class ShardingException extends DBALException
{
......
......@@ -15,6 +15,8 @@ use function substr;
/**
* Conversion Exception is thrown when the database to PHP conversion fails.
*
* @psalm-immutable
*/
class ConversionException extends DBALException
{
......
......@@ -6,7 +6,6 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
errorBaseline="baseline.xml"
>
<projectFiles>
<directory name="lib/Doctrine/DBAL" />
......@@ -16,10 +15,43 @@
</ignoreFiles>
</projectFiles>
<stubs>
<file name="vendor/jetbrains/phpstorm-stubs/PDO/PDO.php" />
<file name="vendor/jetbrains/phpstorm-stubs/ibm_db2/ibm_db2.php" />
<file name="vendor/jetbrains/phpstorm-stubs/mysqli/mysqli.php" />
<file name="vendor/jetbrains/phpstorm-stubs/oci8/oci8.php" />
<file name="vendor/jetbrains/phpstorm-stubs/pgsql/pgsql.php" />
<file name="vendor/jetbrains/phpstorm-stubs/sqlsrv/sqlsrv.php" />
</stubs>
<issueHandlers>
<TooFewArguments>
<errorLevel type="suppress">
<!--
Requires a release of
https://github.com/JetBrains/phpstorm-stubs/pull/727
-->
<file name="lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php"/>
</errorLevel>
</TooFewArguments>
<UndefinedConstant>
<errorLevel type="suppress">
<directory name="lib/Doctrine/DBAL/Driver/SQLAnywhere"/>
<!--
Requires a release of
https://github.com/JetBrains/phpstorm-stubs/pull/732
-->
<file name="tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php" />
</errorLevel>
</UndefinedConstant>
<UndefinedFunction>
<errorLevel type="suppress">
<directory name="lib/Doctrine/DBAL/Driver/SQLAnywhere"/>
</errorLevel>
</UndefinedFunction>
<UndefinedClass>
<errorLevel type="suppress">
<!-- Contains references to optional dependencies -->
<file name="lib/Doctrine/DBAL/Tools/Dumper.php"/>
</errorLevel>
</UndefinedClass>
</issueHandlers>
</psalm>
<?php
namespace Doctrine\Tests\DBAL\Connection;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Logging\SQLLogger;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use PHPUnit\Framework\TestCase;
final class LoggingTest extends TestCase
{
public function testLogExecuteQuery() : void
{
$driverConnection = $this->createStub(DriverConnection::class);
$driverConnection->method('query')
->willReturn($this->createStub(Statement::class));
$this->createConnection($driverConnection, 'SELECT * FROM table')
->executeQuery('SELECT * FROM table');
}
public function testLogExecuteUpdate() : void
{
$this->createConnection(
$this->createStub(DriverConnection::class),
'UPDATE table SET foo = ?'
)
->executeUpdate('UPDATE table SET foo = ?');
}
public function testLogPrepareExecute() : void
{
$driverConnection = $this->createStub(DriverConnection::class);
$driverConnection->method('prepare')
->willReturn($this->createStub(Statement::class));
$this->createConnection($driverConnection, 'UPDATE table SET foo = ?')
->prepare('UPDATE table SET foo = ?')
->execute();
}
private function createConnection(DriverConnection $driverConnection, string $expectedSQL) : Connection
{
$driver = $this->createStub(Driver::class);
$driver->method('connect')
->willReturn($driverConnection);
$driver->method('getDatabasePlatform')
->willReturn($this->createMock(AbstractPlatform::class));
$logger = $this->createMock(SQLLogger::class);
$logger->expects($this->once())
->method('startQuery')
->with($this->equalTo($expectedSQL), $this->equalTo([]));
$logger->expects($this->at(1))
->method('stopQuery');
$connection = new Connection([], $driver);
$connection->getConfiguration()->setSQLLogger($logger);
return $connection;
}
}
<?php
namespace Doctrine\Tests\DBAL\Functional;
use Doctrine\DBAL\Logging\SQLLogger;
use Doctrine\Tests\DbalFunctionalTestCase;
class LoggingTest extends DbalFunctionalTestCase
{
public function testLogExecuteQuery() : void
{
$sql = $this->connection->getDatabasePlatform()->getDummySelectSQL();
$logMock = $this->createMock(SQLLogger::class);
$logMock->expects($this->at(0))
->method('startQuery')
->with($this->equalTo($sql), $this->equalTo([]), $this->equalTo([]));
$logMock->expects($this->at(1))
->method('stopQuery');
$this->connection->getConfiguration()->setSQLLogger($logMock);
$this->connection->executeQuery($sql, []);
}
public function testLogExecuteUpdate() : void
{
$this->markTestSkipped('Test breaks MySQL but works on all other platforms (Unbuffered Queries stuff).');
$sql = $this->connection->getDatabasePlatform()->getDummySelectSQL();
$logMock = $this->createMock(SQLLogger::class);
$logMock->expects($this->at(0))
->method('startQuery')
->with($this->equalTo($sql), $this->equalTo([]), $this->equalTo([]));
$logMock->expects($this->at(1))
->method('stopQuery');
$this->connection->getConfiguration()->setSQLLogger($logMock);
$this->connection->executeUpdate($sql, []);
}
public function testLogPrepareExecute() : void
{
$sql = $this->connection->getDatabasePlatform()->getDummySelectSQL();
$logMock = $this->createMock(SQLLogger::class);
$logMock->expects($this->once())
->method('startQuery')
->with($this->equalTo($sql), $this->equalTo([]));
$logMock->expects($this->at(1))
->method('stopQuery');
$this->connection->getConfiguration()->setSQLLogger($logMock);
$stmt = $this->connection->prepare($sql);
$stmt->execute();
}
}
......@@ -3,6 +3,7 @@
namespace Doctrine\Tests\DBAL\Platforms;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Schema\Index;
......
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