Giter Site home page Giter Site logo

Comments (7)

herndlm avatar herndlm commented on June 3, 2024 2

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

image

from php-mock-phpunit.

gaglioffo avatar gaglioffo commented on June 3, 2024

I have the same issue:

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

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

from php-mock-phpunit.

herndlm avatar herndlm commented on June 3, 2024

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()
        );
    }

from php-mock-phpunit.

michalbundyra avatar michalbundyra commented on June 3, 2024

@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

from php-mock-phpunit.

herndlm avatar herndlm commented on June 3, 2024

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

from php-mock-phpunit.

MekkiLakhdher avatar MekkiLakhdher commented on June 3, 2024

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());

from php-mock-phpunit.

michalbundyra avatar michalbundyra commented on June 3, 2024

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

from php-mock-phpunit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.