diff --git a/composer.json b/composer.json index 20cebcb153..8d87803379 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "ext-mbstring": "*", "behat/gherkin": "^4.6.2", "codeception/lib-asserts": "2.0.*@dev", - "codeception/stub": "^3.7 | ^4.0", + "codeception/stub": "^4.1", "phpunit/phpunit": "^9.5", "phpunit/php-code-coverage": "^9.2", "phpunit/php-text-template": "^2.0", diff --git a/src/Codeception/Step.php b/src/Codeception/Step.php index eb960d8f28..8d943400dd 100644 --- a/src/Codeception/Step.php +++ b/src/Codeception/Step.php @@ -185,8 +185,24 @@ protected function getClassName(object $argument): string { if ($argument instanceof Closure) { return Closure::class; - } elseif ($argument instanceof MockObject && (property_exists($argument, '__mocked') && $argument->__mocked !== null)) { - return $this->formatClassName($argument->__mocked); + } elseif ($argument instanceof MockObject) { + $parentClass = get_parent_class($argument); + $reflection = new \ReflectionClass($argument); + + if ($parentClass !== false) { + return $this->formatClassName($parentClass); + } + + $interfaces = $reflection->getInterfaceNames(); + foreach ($interfaces as $interface) { + if (str_starts_with($interface, 'PHPUnit\\')) { + continue; + } + if (str_starts_with($interface, 'Codeception\\')) { + continue; + } + return $this->formatClassName($interface); + } } return $this->formatClassName($argument::class); diff --git a/tests/data/DummyOverloadableClass.php b/tests/data/DummyOverloadableClass.php index 04127d0564..cff44a34bf 100644 --- a/tests/data/DummyOverloadableClass.php +++ b/tests/data/DummyOverloadableClass.php @@ -57,15 +57,11 @@ public function exceptionalMethod(): void public function __get($name) { - //seeing as we're not implementing __set here, add check for __mocked - $return = null; - if ($name === '__mocked') { - $return = $this->__mocked ?? null; - } elseif ($this->__isset($name)) { - $return = $this->properties[$name]; + if ($this->__isset($name)) { + return $this->properties[$name]; } - return $return; + return null; } public function __isset($name) diff --git a/tests/unit/Codeception/StepTest.php b/tests/unit/Codeception/StepTest.php index cd7f640544..e2278f84a2 100644 --- a/tests/unit/Codeception/StepTest.php +++ b/tests/unit/Codeception/StepTest.php @@ -43,8 +43,7 @@ public function testGetArguments() $mock = $this->createMock($this::class); $step = $this->getStep(['', [[$mock, 'testGetArguments']]]); - $className = $mock::class; - $this->assertSame('["' . $className . '","testGetArguments"]', $step->getArgumentsAsString()); + $this->assertSame('["StepTest","testGetArguments"]', $step->getArgumentsAsString()); } public function testGetHtml()