Add stubs for renamed PHPUnit methods in PHPUnit 9

This commit is contained in:
Ben Thomson 2021-03-01 23:09:16 +08:00
parent 5c757340ae
commit 61df8cf321

View File

@ -1,4 +1,7 @@
<?php
use PHPUnit\Framework\Assert;
class TestCase extends Illuminate\Foundation\Testing\TestCase
{
/**
@ -51,4 +54,38 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
$property->setAccessible(true);
return $property->setValue($object, $value);
}
/**
* Stub for `assertFileNotExists` to allow compatibility with both PHPUnit 8 and 9.
*
* @param string $filename
* @param string $message
* @return void
*/
public static function assertFileNotExists(string $filename, string $message = ''): void
{
if (method_exists(Assert::class, 'assertFileDoesNotExist')) {
Assert::assertFileDoesNotExist($filename, $message);
return;
}
Assert::assertFileNotExists($filename, $message);
}
/**
* Stub for `assertRegExp` to allow compatibility with both PHPUnit 8 and 9.
*
* @param string $filename
* @param string $message
* @return void
*/
public static function assertRegExp(string $pattern, string $string, string $message = ''): void
{
if (method_exists(Assert::class, 'assertMatchesRegularExpression')) {
Assert::assertMatchesRegularExpression($pattern, $string, $message);
return;
}
Assert::assertRegExp($pattern, $string, $message);
}
}