|
12 | 12 | use const DIRECTORY_SEPARATOR; |
13 | 13 | use const PHP_EOL; |
14 | 14 | use const PHP_MAJOR_VERSION; |
| 15 | +use const PHP_VERSION; |
15 | 16 | use const PREG_OFFSET_CAPTURE; |
16 | 17 | use const WSDL_CACHE_NONE; |
17 | 18 | use function array_diff_assoc; |
|
43 | 44 | use function strtolower; |
44 | 45 | use function substr; |
45 | 46 | use function trait_exists; |
| 47 | +use function version_compare; |
46 | 48 | use Doctrine\Instantiator\Exception\ExceptionInterface as InstantiatorException; |
47 | 49 | use Doctrine\Instantiator\Instantiator; |
48 | 50 | use Exception; |
@@ -113,20 +115,9 @@ public function __clone() |
113 | 115 | EOT; |
114 | 116 |
|
115 | 117 | /** |
116 | | - * @var array |
| 118 | + * @var array<non-empty-string, true> |
117 | 119 | */ |
118 | | - private const BLACKLISTED_METHOD_NAMES = [ |
119 | | - '__CLASS__' => true, |
120 | | - '__DIR__' => true, |
121 | | - '__FILE__' => true, |
122 | | - '__FUNCTION__' => true, |
123 | | - '__LINE__' => true, |
124 | | - '__METHOD__' => true, |
125 | | - '__NAMESPACE__' => true, |
126 | | - '__TRAIT__' => true, |
127 | | - '__clone' => true, |
128 | | - '__halt_compiler' => true, |
129 | | - ]; |
| 120 | + private static $excludedMethodNames = []; |
130 | 121 |
|
131 | 122 | /** |
132 | 123 | * @var array |
@@ -1112,12 +1103,32 @@ private function generateMockClassDeclaration(array $mockClassName, bool $isInte |
1112 | 1103 |
|
1113 | 1104 | private function canMockMethod(ReflectionMethod $method): bool |
1114 | 1105 | { |
1115 | | - return !($this->isConstructor($method) || $method->isFinal() || $method->isPrivate() || $this->isMethodNameBlacklisted($method->getName())); |
| 1106 | + return !($this->isConstructor($method) || $method->isFinal() || $method->isPrivate() || $this->isMethodNameExcluded($method->getName())); |
1116 | 1107 | } |
1117 | 1108 |
|
1118 | | - private function isMethodNameBlacklisted(string $name): bool |
| 1109 | + private function isMethodNameExcluded(string $name): bool |
1119 | 1110 | { |
1120 | | - return isset(self::BLACKLISTED_METHOD_NAMES[$name]); |
| 1111 | + if (self::$excludedMethodNames === []) { |
| 1112 | + self::$excludedMethodNames = [ |
| 1113 | + '__CLASS__' => true, |
| 1114 | + '__DIR__' => true, |
| 1115 | + '__FILE__' => true, |
| 1116 | + '__FUNCTION__' => true, |
| 1117 | + '__LINE__' => true, |
| 1118 | + '__METHOD__' => true, |
| 1119 | + '__NAMESPACE__' => true, |
| 1120 | + '__TRAIT__' => true, |
| 1121 | + '__clone' => true, |
| 1122 | + '__halt_compiler' => true, |
| 1123 | + ]; |
| 1124 | + |
| 1125 | + if (version_compare(PHP_VERSION, '8.5', '>=')) { |
| 1126 | + self::$excludedMethodNames['__sleep'] = true; |
| 1127 | + self::$excludedMethodNames['__wakeup'] = true; |
| 1128 | + } |
| 1129 | + } |
| 1130 | + |
| 1131 | + return isset(self::$excludedMethodNames[$name]); |
1121 | 1132 | } |
1122 | 1133 |
|
1123 | 1134 | private function getTemplate(string $template): Text_Template |
|
0 commit comments