Skip to content

Commit 6278319

Browse files
committed
Add fix in ServerTest for PHP 8.4 + PHPUnit 9 issue.
1 parent de099b8 commit 6278319

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@
3939
},
4040
"type": "library",
4141
"require-dev": {
42-
"phpunit/phpunit": "^9"
42+
"phpunit/phpunit": "^9.0 | ^10.0"
4343
}
4444
}

tests/Unit/ServerTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,27 @@ class ServerTest extends TestCase
2323
const MOCK_HTTP_METHOD = 'MOCK';
2424
const MOCK_PATH = '/mock/path';
2525

26+
public static function setUpBeforeClass(): void
27+
{
28+
$phpUnitVersion = \PHPUnit\Runner\Version::id();
29+
30+
/* PHP 8.4.0 and PHPUnit 9 triggers a Deprecation Warning, which PHPUnit
31+
* promotes to an Exception, which causes tests to fail.This is fixed in
32+
* PHPUnit v10. As a workaround for v9, instead of loading the real
33+
* interface, a fixed interface is loaded on the fly.
34+
*/
35+
if (
36+
version_compare(PHP_VERSION, '8.4.0', '>=')
37+
&& version_compare($phpUnitVersion, '9.0.0', '>=')
38+
&& version_compare($phpUnitVersion, '10.0.0', '<')
39+
) {
40+
$file = __DIR__ . '/../../vendor/league/flysystem/src/FilesystemInterface.php';
41+
$contents = file_get_contents($file);
42+
$contents = str_replace(['<?php','Handler $handler = null'], ['','?Handler $handler = null'], $contents);
43+
eval($contents);
44+
}
45+
}
46+
2647
/////////////////////////////////// TESTS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
2748

2849
/**

0 commit comments

Comments
 (0)