Skip to content

Commit

Permalink
PHPUnit 10.5.9 (#6266)
Browse files Browse the repository at this point in the history
This PR upgrades PHPUnit to 10.5.9.

~~Apparently, the build is broken by a couple of warnings that PHPUnit
collected. I've pushed a commit that makes them visible. We should
investigate those warnings.~~

Warnings have been addressed.
  • Loading branch information
derrabus committed Jan 25, 2024
1 parent d98a279 commit d2aed19
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 37 deletions.
7 changes: 3 additions & 4 deletions ci/github/phpunit/oci8-21.xml
Expand Up @@ -6,7 +6,6 @@
beStrictAboutTodoAnnotatedTests="true"
failOnRisky="true"
failOnWarning="true"
convertDeprecationsToExceptions="true"
>
<php>
<ini name="error_reporting" value="-1" />
Expand All @@ -31,9 +30,9 @@
</testsuite>
</testsuites>

<coverage>
<source>
<include>
<directory suffix=".php">../../../src</directory>
<directory>../../../src</directory>
</include>
</coverage>
</source>
</phpunit>
7 changes: 3 additions & 4 deletions ci/github/phpunit/pdo_oci-21.xml
Expand Up @@ -6,7 +6,6 @@
beStrictAboutTodoAnnotatedTests="true"
failOnRisky="true"
failOnWarning="true"
convertDeprecationsToExceptions="true"
>
<php>
<ini name="error_reporting" value="-1" />
Expand All @@ -31,9 +30,9 @@
</testsuite>
</testsuites>

<coverage>
<source>
<include>
<directory suffix=".php">../../../src</directory>
<directory>../../../src</directory>
</include>
</coverage>
</source>
</phpunit>
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -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",
Expand Down
53 changes: 33 additions & 20 deletions tests/Functional/Driver/OCI8/ResultTest.php
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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(
Expand Down
22 changes: 18 additions & 4 deletions tests/Functional/ExceptionTest.php
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
21 changes: 17 additions & 4 deletions tests/Functional/TransactionTest.php
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
}
}

0 comments on commit d2aed19

Please sign in to comment.