Ignore class name in the exception message
parent
f604b83754
commit
08e9aa6dd3
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Arokettu\Random\Tests;
|
||||
|
||||
trait AssertRegexCompat
|
||||
{
|
||||
public static function assertRegex(string $pattern, string $string, string $message = ''): void
|
||||
{
|
||||
if (\method_exists(static::class, 'assertMatchesRegularExpression')) {
|
||||
self::assertMatchesRegularExpression($pattern, $string, $message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (\method_exists(static::class, 'assertRegExp')) {
|
||||
self::assertRegExp($pattern, $string, $message);
|
||||
return;
|
||||
}
|
||||
|
||||
throw new \LogicException('Class should have either assertMatchesRegularExpression or assertRegExp');
|
||||
}
|
||||
}
|
|
@ -16,6 +16,8 @@ use Throwable;
|
|||
|
||||
class DynamicPropertiesTest extends TestCase
|
||||
{
|
||||
use AssertRegexCompat;
|
||||
|
||||
public function testRandomizer(): void
|
||||
{
|
||||
try {
|
||||
|
@ -63,8 +65,8 @@ class DynamicPropertiesTest extends TestCase
|
|||
$engine = new Secure();
|
||||
$engine->test = 123;
|
||||
} catch (Throwable $e) {
|
||||
self::assertEquals(
|
||||
'Cannot create dynamic property Random\Engine\Secure::$test',
|
||||
self::assertRegex(
|
||||
'/^Cannot create dynamic property (?<classname>.*)::\\$test$/',
|
||||
$e->getMessage()
|
||||
);
|
||||
self::assertEquals(Error::class, \get_class($e));
|
||||
|
|
Loading…
Reference in New Issue