diff --git a/ci/github/phpunit/oci8-21.xml b/ci/github/phpunit/oci8-21.xml index d8e1d99fbf7..f333e9d30a8 100644 --- a/ci/github/phpunit/oci8-21.xml +++ b/ci/github/phpunit/oci8-21.xml @@ -6,7 +6,6 @@ beStrictAboutTodoAnnotatedTests="true" failOnRisky="true" failOnWarning="true" - convertDeprecationsToExceptions="true" > @@ -31,9 +30,9 @@ - + - ../../../src + ../../../src - + diff --git a/ci/github/phpunit/pdo_oci-21.xml b/ci/github/phpunit/pdo_oci-21.xml index ef1e272e5e0..7a9fb1ee900 100644 --- a/ci/github/phpunit/pdo_oci-21.xml +++ b/ci/github/phpunit/pdo_oci-21.xml @@ -6,7 +6,6 @@ beStrictAboutTodoAnnotatedTests="true" failOnRisky="true" failOnWarning="true" - convertDeprecationsToExceptions="true" > @@ -31,9 +30,9 @@ - + - ../../../src + ../../../src - + diff --git a/composer.json b/composer.json index 5dd9dce1c89..98fd0413afe 100644 --- a/composer.json +++ b/composer.json @@ -43,7 +43,7 @@ "phpstan/phpstan": "1.10.56", "phpstan/phpstan-phpunit": "1.3.15", "phpstan/phpstan-strict-rules": "^1.5", - "phpunit/phpunit": "10.4.2", + "phpunit/phpunit": "10.5.9", "psalm/plugin-phpunit": "0.18.4", "slevomat/coding-standard": "8.13.1", "squizlabs/php_codesniffer": "3.8.1", diff --git a/tests/Functional/Driver/OCI8/ResultTest.php b/tests/Functional/Driver/OCI8/ResultTest.php index 1e4fedc966e..a5f935ea35b 100644 --- a/tests/Functional/Driver/OCI8/ResultTest.php +++ b/tests/Functional/Driver/OCI8/ResultTest.php @@ -9,11 +9,12 @@ use Doctrine\DBAL\Tests\TestUtil; use Generator; +use function func_get_args; use function ini_get; +use function restore_error_handler; +use function set_error_handler; use function sprintf; - -use const E_ALL; -use const E_WARNING; +use function str_contains; /** @requires extension oci8 */ class ResultTest extends FunctionalTestCase @@ -56,9 +57,6 @@ public function testTruncatedFetch( bool $invalidateDataMidFetch, ): void { if ($invalidateDataMidFetch) { - // prevent the PHPUnit error handler from handling the warnings that oci_*() functions may trigger - $this->iniSet('error_reporting', (string) (E_ALL & ~E_WARNING)); - $this->expectException(DriverException::class); $this->expectExceptionCode(4068); } @@ -88,22 +86,37 @@ public function testTruncatedFetch( // Invalidate the original dataset by changing the pipelined function // after the initial prefetch that caches locally the first X results $this->createOrReplacePipelinedFunction($expectedTotalRowCount + 10); + + $previous = null; + $previous = set_error_handler(static function (int $errno, string $errstr) use (&$previous): bool { + if (str_contains($errstr, 'ORA-04061')) { + return true; + } + + return $previous !== null && $previous(...func_get_args()); + }); } - while ($result->fetchOne()) { - // Attempt to access all remaining rows from the original fetch - // The rows locally cached from the default prefetch will first be used - // but when the result attempts to get the remaining 10 rows beyond - // the first prefetch, nothing will be returned - // - // PHP oci8 oci_fetch_array will issue a PHP E_WARNING when the 2nd prefetch occurs - // oci_fetch_array(): ORA-04068: existing state of packages has been discarded - // ORA-04061: existing state of function "ROOT.TEST_ORACLE_FETCH_FAILURE" has been invalidated - // ORA-04065: not executed, altered or dropped function "ROOT.TEST_ORACLE_FETCH_FAILURE" - // - // If there was no issue, this should have returned rows totalling 10 - // higher than the oci8 default prefetch - continue; + try { + while ($result->fetchOne()) { + // Attempt to access all remaining rows from the original fetch + // The rows locally cached from the default prefetch will first be used + // but when the result attempts to get the remaining 10 rows beyond + // the first prefetch, nothing will be returned + // + // PHP oci8 oci_fetch_array will issue a PHP E_WARNING when the 2nd prefetch occurs + // oci_fetch_array(): ORA-04068: existing state of packages has been discarded + // ORA-04061: existing state of function "ROOT.TEST_ORACLE_FETCH_FAILURE" has been invalidated + // ORA-04065: not executed, altered or dropped function "ROOT.TEST_ORACLE_FETCH_FAILURE" + // + // If there was no issue, this should have returned rows totalling 10 + // higher than the oci8 default prefetch + continue; + } + } finally { + if ($invalidateDataMidFetch) { + restore_error_handler(); + } } self::assertEquals( diff --git a/tests/Functional/ExceptionTest.php b/tests/Functional/ExceptionTest.php index c152d261a7b..e7a8e7cdc51 100644 --- a/tests/Functional/ExceptionTest.php +++ b/tests/Functional/ExceptionTest.php @@ -18,13 +18,15 @@ use function exec; use function extension_loaded; use function file_exists; +use function func_get_args; use function posix_geteuid; +use function restore_error_handler; +use function set_error_handler; use function sprintf; use function sys_get_temp_dir; use function touch; use function unlink; -use const E_ALL; use const E_WARNING; use const PHP_OS_FAMILY; @@ -82,11 +84,23 @@ public function testInvalidFieldNameException(): void $table->addColumn('id', Types::INTEGER, []); $this->dropAndCreateTable($table); + $this->expectException(Exception\InvalidFieldNameException::class); + // prevent the PHPUnit error handler from handling the warning that db2_bind_param() may trigger - $this->iniSet('error_reporting', (string) (E_ALL & ~E_WARNING)); + $previous = null; + $previous = set_error_handler(static function (int $errno) use (&$previous): bool { + if (($errno & ~E_WARNING) === 0) { + return true; + } - $this->expectException(Exception\InvalidFieldNameException::class); - $this->connection->insert('bad_columnname_table', ['name' => 5]); + return $previous !== null && $previous(...func_get_args()); + }); + + try { + $this->connection->insert('bad_columnname_table', ['name' => 5]); + } finally { + restore_error_handler(); + } } public function testNonUniqueFieldNameException(): void diff --git a/tests/Functional/TransactionTest.php b/tests/Functional/TransactionTest.php index 99d963ca9f1..570aa6d7a6a 100644 --- a/tests/Functional/TransactionTest.php +++ b/tests/Functional/TransactionTest.php @@ -10,9 +10,11 @@ use Doctrine\DBAL\Platforms\AbstractMySQLPlatform; use Doctrine\DBAL\Tests\FunctionalTestCase; +use function func_get_args; +use function restore_error_handler; +use function set_error_handler; use function sleep; -use const E_ALL; use const E_WARNING; use const PHP_VERSION_ID; @@ -53,10 +55,21 @@ private function expectConnectionLoss(callable $scenario): void // during the sleep MySQL will close the connection sleep(2); + $this->expectException(ConnectionLost::class); + // prevent the PHPUnit error handler from handling the "MySQL server has gone away" warning - $this->iniSet('error_reporting', (string) (E_ALL & ~E_WARNING)); + $previous = null; + $previous = set_error_handler(static function (int $errno) use (&$previous): bool { + if (($errno & ~E_WARNING) === 0) { + return true; + } - $this->expectException(ConnectionLost::class); - $scenario($this->connection); + return $previous !== null && $previous(...func_get_args()); + }); + try { + $scenario($this->connection); + } finally { + restore_error_handler(); + } } }