Skip to content

Commit

Permalink
More work on handling anonymous class names
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Aug 6, 2024
1 parent f6fc1c8 commit 3af87db
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Framework/Constraint/Constraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
use function is_object;
use function sprintf;
use function str_replace;
use function strpos;
use function strtolower;
use function substr;
use Countable;
use PHPUnit\Framework\ExpectationFailedException;
use PHPUnit\Framework\SelfDescribing;
Expand Down Expand Up @@ -243,7 +245,10 @@ protected function valueToTypeStringFragment(mixed $value): string
$reflector = new ReflectionObject($value);

if ($reflector->isAnonymous()) {
return 'an instance of anonymous class created at ' . str_replace('class@anonymous', '', $reflector->getName()) . ' ';
$name = str_replace('class@anonymous', '', $reflector->getName());
$name = substr($name, 0, strpos($name, '$'));

return 'an instance of anonymous class created at ' . $name . ' ';
}

return 'an instance of class ' . $reflector->getName() . ' ';
Expand Down

0 comments on commit 3af87db

Please sign in to comment.