File: phpunit_mock_objects.patch

package info (click to toggle)
php-nrk-predis 1.1.10-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,844 kB
  • sloc: php: 31,854; makefile: 16
file content (38 lines) | stat: -rw-r--r-- 2,077 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
diff --git a/src/Framework/MockObject/Generator.php b/src/Framework/MockObject/Generator.php
index 3df3abb..fc76d5d 100644
--- a/src/Framework/MockObject/Generator.php
+++ b/src/Framework/MockObject/Generator.php
@@ -1031,16 +1031,29 @@ protected function getMethodParameters(ReflectionMethod $method, $forCall = fals
             $typeDeclaration = '';
 
             if (!$forCall) {
+                if (PHP_VERSION_ID >= 80000) {
+                    $isArray = $parameter->getType() && $parameter->getType()->getName() === 'array';
+                    $isCallable = $parameter->getType() && $parameter->getType()->getName() === 'callable';
+                } else {
+                    $isArray = $parameter->isArray();
+                    $isCallable = version_compare(PHP_VERSION, '5.4.0', '>=') ? $parameter->isCallable() : false;
+                }
+
                 if ($this->hasType($parameter)) {
-                    $typeDeclaration = (string) $parameter->getType() . ' ';
-                } elseif ($parameter->isArray()) {
+                    $type = $parameter->getType();
+                    $typeDeclaration = (PHP_VERSION_ID >= 70100 ? $type->getName() : (string) $type) . ' ';
+                } elseif ($isArray) {
                     $typeDeclaration = 'array ';
                 } elseif ((defined('HHVM_VERSION') || version_compare(PHP_VERSION, '5.4.0', '>='))
-                          && $parameter->isCallable()) {
+                          && $isCallable) {
                     $typeDeclaration = 'callable ';
                 } else {
                     try {
-                        $class = $parameter->getClass();
+                        if (PHP_VERSION_ID >= 80000) {
+                            $class = $parameter->getType();
+                        } else {
+                            $class = $parameter->getClass();
+                        }
                     } catch (ReflectionException $e) {
                         throw new PHPUnit_Framework_MockObject_RuntimeException(
                             sprintf(