diff --git a/src/Prophecy/Doubler/Generator/ClassCodeGenerator.php b/src/Prophecy/Doubler/Generator/ClassCodeGenerator.php index 2d30a3f2e..ddc6985cd 100644 --- a/src/Prophecy/Doubler/Generator/ClassCodeGenerator.php +++ b/src/Prophecy/Doubler/Generator/ClassCodeGenerator.php @@ -110,7 +110,14 @@ private function generateArguments(array $arguments): array $php .= '$'.$argument->getName(); if ($argument->isOptional() && !$argument->isVariadic()) { - $php .= ' = '.var_export($argument->getDefault(), true); + $default = var_export($argument->getDefault(), true); + + // This is necessary for PHP 8.1, as enum cases are exported without a leading slash in this version + if ($argument->getDefault() instanceof \UnitEnum && 0 !== strpos($default, '\\')) { + $default = '\\'.$default; + } + + $php .= ' = '.$default; } return $php;