Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible with PHPUnit >= 10.3 #61

Closed
mac89 opened this issue Aug 4, 2023 · 7 comments · Fixed by #63
Closed

Incompatible with PHPUnit >= 10.3 #61

mac89 opened this issue Aug 4, 2023 · 7 comments · Fixed by #63
Milestone

Comments

@mac89
Copy link

mac89 commented Aug 4, 2023

Caused by making the $properties property read only: sebastianbergmann/phpunit@eb2d761

@gaglioffo
Copy link

I have the same issue:

Error: Cannot modify readonly property PHPUnit\Framework\MockObject\Invocation::$parameters

...\php-mock\php-mock-phpunit\classes\DefaultArgumentRemoverReturnTypes100.php:76

@herndlm
Copy link

herndlm commented Aug 11, 2023

I was looking into this a bit and found out the following so far

Since the whole modification of default params in Invocation is already a hack (Invocation is internal, private parameters are modified via closure binding) we could use reflection to only access returnType and then "cleanly" create a new instance of Invocation maybe?

E.g. I tried the following (only in the one place that broke a test for us!) and it seems to work

private function removeDefaultArguments(Invocation $invocation, string $class)
    {
        $parameters = $invocation->parameters();
        MockFunctionGenerator::removeDefaultArguments($parameters);

        $returnTypePropertyReflection = new \ReflectionProperty(Invocation::class, 'returnType');
        $returnTypePropertyReflection->setAccessible(true);

        $invocation = new Invocation(   
            $invocation->className(),
            $invocation->methodName(),
            $parameters,
            $returnTypePropertyReflection->getValue($invocation),
            $invocation->object()
        );
    }

@michalbundyra
Copy link
Member

@herndlm I was looking into it as well, and I have no solution yet. I am worried we might not have one, or we would need to came up with something else. Yes, this library hacks PHPUnits, and it's already so complex to support all PHPUnit versions.

Thanks for investigation, I'll try to dig a bit more once I have a bit more time. Thanks again

@herndlm
Copy link

herndlm commented Aug 11, 2023

oh, right, and in my proposed fix I missed that the passed $invocation is not overwritten / returned, so It's not doing anything 🤦‍♂️

additionally (missed in the previous points):

  • Invocation is final, so changing it's behaviour via child class is not possible
  • Invocation doesn't have a useful interface and is used directly, so using a decorator to change it's behaviour is also not possible

@MekkiLakhdher
Copy link

I am facing the same issue :

Error: Cannot modify readonly property PHPUnit\Framework\MockObject\Invocation::$parameters
...\php-mock\php-mock-phpunit\classes\DefaultArgumentRemoverReturnTypes100.php:76

The solution that worked for me is simply using \PHPUnit\Framework\MockObject\Invocation::parameters method which is the getter of the readonly $parameters variable.

Here are the necessary changes :

/php-mock/php-mock-phpunit/classes/DefaultArgumentRemoverReturnTypes100.php:41
- MockFunctionGenerator::removeDefaultArguments($invocation->parameters);
+ MockFunctionGenerator::removeDefaultArguments($invocation->parameters());

And

/php-mock/php-mock-phpunit/classes/DefaultArgumentRemoverReturnTypes100.php:76
- MockFunctionGenerator::removeDefaultArguments($this->parameters);
+ MockFunctionGenerator::removeDefaultArguments($this->parameters());

@michalbundyra
Copy link
Member

michalbundyra commented Aug 28, 2023

@MekkiLakhdher it does not seem to be working - see: #62 (commit: 1dfcf66)

janwehner pushed a commit to Securepoint/token-bucket that referenced this issue Oct 2, 2023
ceithir added a commit to ceithir/sakkaku that referenced this issue Oct 27, 2023
php-mock/php-mock-phpunit#61
Triggers a ton of deprecation warning; update as soon as possible
@michalbundyra michalbundyra added this to the 2.8.0 milestone Oct 30, 2023
michalbundyra pushed a commit that referenced this issue Oct 30, 2023
@herndlm
Copy link

herndlm commented Oct 30, 2023

nice, thx @marcoscoelho. I can finally merge this one :D

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants