Skip to content

Commit

Permalink
Run tests on PHP 8.1 with different database drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed Oct 15, 2021
1 parent a4eacec commit 840caef
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 20 deletions.
20 changes: 9 additions & 11 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:
matrix:
php-version:
- "7.4"
- "8.0"
- "8.1"

services:
oracle:
Expand Down Expand Up @@ -139,7 +139,7 @@ jobs:
matrix:
php-version:
- "7.4"
- "8.0"
- "8.1"

services:
oracle:
Expand Down Expand Up @@ -188,7 +188,7 @@ jobs:
- "13"
- "14"
include:
- php-version: "8.0"
- php-version: "8.1"
postgres-version: "14"

services:
Expand Down Expand Up @@ -245,10 +245,10 @@ jobs:
- "mysqli"
- "pdo_mysql"
include:
- php-version: "8.0"
- php-version: "8.1"
mariadb-version: "10.5"
extension: "mysqli"
- php-version: "8.0"
- php-version: "8.1"
mariadb-version: "10.5"
extension: "pdo_mysql"

Expand Down Expand Up @@ -291,7 +291,6 @@ jobs:
name: "${{ github.job }}-${{ matrix.mariadb-version }}-${{ matrix.extension }}-${{ matrix.php-version }}.coverage"
path: "coverage.xml"


phpunit-mysql:
name: "PHPUnit with MySQL"
runs-on: "ubuntu-20.04"
Expand Down Expand Up @@ -329,12 +328,12 @@ jobs:
php-version: "7.4"
mysql-version: "8.0"
extension: "mysqli"
- php-version: "8.0"
- php-version: "8.1"
mysql-version: "8.0"
extension: "mysqli"
custom-entrypoint: >-
--entrypoint sh mysql:8 -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password"
- php-version: "8.0"
- php-version: "8.1"
mysql-version: "8.0"
extension: "pdo_mysql"
custom-entrypoint: >-
Expand Down Expand Up @@ -393,7 +392,7 @@ jobs:
php-version:
- "7.3"
- "7.4"
- "8.0"
- "8.1"
extension:
- "sqlsrv"
- "pdo_sqlsrv"
Expand Down Expand Up @@ -434,7 +433,7 @@ jobs:
coverage: "pcov"
ini-values: "zend.assertions=1"
tools: "pecl"
extensions: "${{ matrix.extension }}-5.9.0preview1"
extensions: "${{ matrix.extension }}-5.10.0beta1"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"
Expand Down Expand Up @@ -506,7 +505,6 @@ jobs:
name: "${{ github.job }}-${{ matrix.php-version }}.coverage"
path: "coverage.xml"


development-deps:
name: "PHPUnit with SQLite and development dependencies"
runs-on: "ubuntu-20.04"
Expand Down
5 changes: 3 additions & 2 deletions lib/Doctrine/DBAL/Driver/AbstractException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Doctrine\Deprecations\Deprecation;
use Exception as BaseException;
use Throwable;

/**
* Base implementation of the {@link Exception} interface.
Expand Down Expand Up @@ -35,9 +36,9 @@ abstract class AbstractException extends BaseException implements DriverExceptio
* @param string|null $sqlState The SQLSTATE the driver is in at the time the error occurred, if any.
* @param int|string|null $errorCode The driver specific error code if any.
*/
public function __construct($message, $sqlState = null, $errorCode = null)
public function __construct($message, $sqlState = null, $errorCode = null, ?Throwable $previous = null)
{
parent::__construct($message);
parent::__construct($message, 0, $previous);

$this->errorCode = $errorCode;
$this->sqlState = $sqlState;
Expand Down
10 changes: 10 additions & 0 deletions lib/Doctrine/DBAL/Driver/Mysqli/Exception/ConnectionError.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use Doctrine\DBAL\Driver\Mysqli\MysqliException;
use mysqli;
use mysqli_sql_exception;
use ReflectionProperty;

/**
* @internal
Expand All @@ -18,4 +20,12 @@ public static function new(mysqli $connection): self
{
return new self($connection->error, $connection->sqlstate, $connection->errno);
}

public static function upcast(mysqli_sql_exception $exception): self
{
$p = new ReflectionProperty(mysqli_sql_exception::class, 'sqlstate');
$p->setAccessible(true);

return new self($exception->getMessage(), $p->getValue($exception), $exception->getCode(), $exception);
}
}
10 changes: 10 additions & 0 deletions lib/Doctrine/DBAL/Driver/Mysqli/Exception/ConnectionFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use Doctrine\DBAL\Driver\Mysqli\MysqliException;
use mysqli;
use mysqli_sql_exception;
use ReflectionProperty;

/**
* @internal
Expand All @@ -18,4 +20,12 @@ public static function new(mysqli $connection): self
{
return new self($connection->connect_error, 'HY000', $connection->connect_errno);
}

public static function upcast(mysqli_sql_exception $exception): self
{
$p = new ReflectionProperty(mysqli_sql_exception::class, 'sqlstate');
$p->setAccessible(true);

return new self($exception->getMessage(), $p->getValue($exception), $exception->getCode(), $exception);
}
}
10 changes: 10 additions & 0 deletions lib/Doctrine/DBAL/Driver/Mysqli/Exception/StatementError.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
namespace Doctrine\DBAL\Driver\Mysqli\Exception;

use Doctrine\DBAL\Driver\Mysqli\MysqliException;
use mysqli_sql_exception;
use mysqli_stmt;
use ReflectionProperty;

/**
* @internal
Expand All @@ -18,4 +20,12 @@ public static function new(mysqli_stmt $statement): self
{
return new self($statement->error, $statement->sqlstate, $statement->errno);
}

public static function upcast(mysqli_sql_exception $exception): self
{
$p = new ReflectionProperty(mysqli_sql_exception::class, 'sqlstate');
$p->setAccessible(true);

return new self($exception->getMessage(), $p->getValue($exception), $exception->getCode(), $exception);
}
}
29 changes: 25 additions & 4 deletions lib/Doctrine/DBAL/Driver/Mysqli/MysqliConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Doctrine\DBAL\ParameterType;
use Doctrine\Deprecations\Deprecation;
use mysqli;
use mysqli_sql_exception;

use function assert;
use function floor;
Expand Down Expand Up @@ -77,7 +78,13 @@ public function __construct(array $params, $username, $password, array $driverOp
$this->setSecureConnection($params);
$this->setDriverOptions($driverOptions);

if (! @$this->conn->real_connect($params['host'], $username, $password, $dbname, $port, $socket, $flags)) {
try {
$success = @$this->conn->real_connect($params['host'], $username, $password, $dbname, $port, $socket, $flags);
} catch (mysqli_sql_exception $e) {
throw ConnectionFailed::upcast($e);
}

if (! $success) {
throw ConnectionFailed::new($this->conn);
}

Expand Down Expand Up @@ -170,7 +177,13 @@ public function quote($value, $type = ParameterType::STRING)
*/
public function exec($sql)
{
if ($this->conn->query($sql) === false) {
try {
$result = $this->conn->query($sql);
} catch (mysqli_sql_exception $e) {
throw ConnectionError::upcast($e);
}

if ($result === false) {
throw ConnectionError::new($this->conn);
}

Expand Down Expand Up @@ -200,15 +213,23 @@ public function beginTransaction()
*/
public function commit()
{
return $this->conn->commit();
try {
return $this->conn->commit();
} catch (mysqli_sql_exception $e) {
return false;
}
}

/**
* {@inheritdoc}non-PHPdoc)
*/
public function rollBack()
{
return $this->conn->rollback();
try {
return $this->conn->rollback();
} catch (mysqli_sql_exception $e) {
return false;
}
}

/**
Expand Down
15 changes: 13 additions & 2 deletions lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Doctrine\DBAL\ParameterType;
use IteratorAggregate;
use mysqli;
use mysqli_sql_exception;
use mysqli_stmt;
use PDO;
use ReturnTypeWillChange;
Expand Down Expand Up @@ -94,7 +95,11 @@ public function __construct(mysqli $conn, $prepareString)
{
$this->_conn = $conn;

$stmt = $conn->prepare($prepareString);
try {
$stmt = $conn->prepare($prepareString);
} catch (mysqli_sql_exception $e) {
throw ConnectionError::upcast($e);
}

if ($stmt === false) {
throw ConnectionError::new($this->_conn);
Expand Down Expand Up @@ -161,7 +166,13 @@ public function execute($params = null)
}
}

if (! $this->_stmt->execute()) {
try {
$result = $this->_stmt->execute();
} catch (mysqli_sql_exception $e) {
throw StatementError::upcast($e);
}

if (! $result) {
throw StatementError::new($this->_stmt);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected function setUp(): void

public function testConnectionLost(): void
{
$this->connection->query('SET SESSION wait_timeout=1');
$this->connection->executeStatement('SET SESSION wait_timeout=1');

sleep(2);

Expand Down

0 comments on commit 840caef

Please sign in to comment.