Ignore class name in the exception message

master
Anton Smirnov 2022-11-10 23:12:40 +02:00
parent f604b83754
commit 08e9aa6dd3
2 changed files with 27 additions and 2 deletions

View File

@ -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');
}
}

View File

@ -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));