Skip to content

Commit

Permalink
#2255 - Adapt unit test for PHP8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeckerson committed Dec 11, 2021
1 parent 0efa65c commit f45391b
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions tests/Extension/NewInstanceOperatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ final class NewInstanceOperatorTest extends TestCase
public Operator $test;

protected array $autoloadMap = [
'Fixture\ThrowException' => ZEPHIRPATH.'/tests/fixtures/throw-exception.php',
'Fixture\EmptyClass' => ZEPHIRPATH.'/tests/fixtures/class-empty.php',
'Fixture\ThrowException' => 'tests/fixtures/throw-exception.php',
'Fixture\EmptyClass' => 'tests/fixtures/class-empty.php',
];

protected function setUp(): void
Expand All @@ -38,15 +38,29 @@ protected function tearDown(): void

public function autoload(string $className): void
{
if (isset($this->autoloadMap[$className])) {
include $this->autoloadMap[$className];
if (version_compare(PHP_VERSION, '8.1.0', '>=')) {
try {
if (isset($this->autoloadMap[$className])) {
include $this->autoloadMap[$className];
}
} catch (\Throwable $exception) {
// Ignore, as since PHP8.1 all exceptions are thrown during file include.
}
} else {
if (isset($this->autoloadMap[$className])) {
include $this->autoloadMap[$className];
}
}
}

public function testException(): void
{
$this->expectException(\Exception::class);
$this->test->testNewInstanceOperator('Fixture\ThrowException');
if (version_compare(PHP_VERSION, '8.1.0', '<')) {
$this->expectException(\Exception::class);
$this->test->testNewInstanceOperator('Fixture\ThrowException');
} else {
$this->markTestSkipped('spl_autoload_register() now can only register with valid class inside included file.');
}
}

public function testNewInstance(): void
Expand Down

0 comments on commit f45391b

Please sign in to comment.