You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 20, 2023. It is now read-only.
Good evening. Tried run project on PHP 7.2 and unit tests failed with strange behavior PHP Fatal error: Declaration of Mock_TestId_baa7a0d1::generate(): \TestId must be compatible with \BaseId::generate(): \Id in /var/www/html/vendor/phpunit/phpunit-mock-objects/src/Generator.php(603) : eval()'d code on line 1
Class example:
declare(strict_types=1);
abstract class Id
{
protected $uid;
/**
* Id constructor.
* @param UuidInterface $uid
*/
public function __construct(UuidInterface $uid)
{
$this->uid = $uid;
}
abstract public static function generate();
}
class BaseId extends Id
{
/**
* @return Id
*/
public static function generate(): parent
{
return new static(Uuid::uuid1());
}
}
class TestId extends BaseId
{
}
Class generated from private function evalClass in Generator.php
class Mock_TestId_3b9eb4f3 extends TestId implements PHPUnit\Framework\MockObject\MockObject
{
private $__phpunit_invocationMocker;
private $__phpunit_originalObject;
private $__phpunit_configurable = ['generate', 'fromstring', 'frombytes', 'fromint', 'tostring', '__tostring', 'isequalas', 'getuid'];
public function __clone()
{
$this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
}
public static function generate(): parent
{
throw new \PHPUnit\Framework\MockObject\BadMethodCallException('Static method "generate" cannot be invoked on mock object');
}
public static function fromString(string $Id): Id
{
throw new \PHPUnit\Framework\MockObject\BadMethodCallException('Static method "fromString" cannot be invoked on mock object');
}
public static function fromBytes(string $Id): Id
{
throw new \PHPUnit\Framework\MockObject\BadMethodCallException('Static method "fromBytes" cannot be invoked on mock object');
}
public static function fromInt(int $id): Id
{
throw new \PHPUnit\Framework\MockObject\BadMethodCallException('Static method "fromInt" cannot be invoked on mock object');
}
public function toString(): string
{
$arguments = [];
$count = func_num_args();
if ($count > 0) {
$_arguments = func_get_args();
for ($i = 0; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Id', 'toString', $arguments, 'string', $this, false
)
);
return $result;
}
public function __toString(): string
{
$arguments = [];
$count = func_num_args();
if ($count > 0) {
$_arguments = func_get_args();
for ($i = 0; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Id', '__toString', $arguments, 'string', $this, false
)
);
return $result;
}
public function isEqualAs(Id $other): bool
{
$arguments = [$other];
$count = func_num_args();
if ($count > 1) {
$_arguments = func_get_args();
for ($i = 1; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Id', 'isEqualAs', $arguments, 'bool', $this, false
)
);
return $result;
}
public function getUid(): Ramsey\Uuid\UuidInterface
{
$arguments = [];
$count = func_num_args();
if ($count > 0) {
$_arguments = func_get_args();
for ($i = 0; $i < $count; $i++) {
$arguments[] = $_arguments[$i];
}
}
$result = $this->__phpunit_getInvocationMocker()->invoke(
new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
'Id', 'getUid', $arguments, 'Ramsey\Uuid\UuidInterface', $this, false
)
);
return $result;
}
public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
{
return $this->__phpunit_getInvocationMocker()->expects($matcher);
}
public function method()
{
$any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
$expects = $this->expects($any);
return call_user_func_array([$expects, 'method'], func_get_args());
}
public function __phpunit_setOriginalObject($originalObject)
{
$this->__phpunit_originalObject = $originalObject;
}
public function __phpunit_getInvocationMocker()
{
if ($this->__phpunit_invocationMocker === null) {
$this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable);
}
return $this->__phpunit_invocationMocker;
}
public function __phpunit_hasMatchers()
{
return $this->__phpunit_getInvocationMocker()->hasMatchers();
}
public function __phpunit_verify($unsetInvocationMocker = true)
{
$this->__phpunit_getInvocationMocker()->verify();
if ($unsetInvocationMocker) {
$this->__phpunit_invocationMocker = null;
}
}
}
The text was updated successfully, but these errors were encountered:
sebastianbergmann
changed the title
PHP 7.2 PHP Fatal errorparent return type declaration is not handled correctly
Feb 15, 2018
sebastianbergmann
changed the title
parent return type declaration is not handled correctly
parent return type declaration is not handled correctly
Feb 15, 2018
Good evening. Tried run project on PHP 7.2 and unit tests failed with strange behavior
PHP Fatal error: Declaration of Mock_TestId_baa7a0d1::generate(): \TestId must be compatible with \BaseId::generate(): \Id in /var/www/html/vendor/phpunit/phpunit-mock-objects/src/Generator.php(603) : eval()'d code on line 1
Class example:
Class generated from private function evalClass in Generator.php
The text was updated successfully, but these errors were encountered: