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

Prophecy not work with virtual private __method #450

Open
BruceGitHub opened this issue Nov 26, 2019 · 0 comments
Open

Prophecy not work with virtual private __method #450

BruceGitHub opened this issue Nov 26, 2019 · 0 comments

Comments

@BruceGitHub
Copy link

BruceGitHub commented Nov 26, 2019

I love prophecy I use this library a lot.
I have seen strange behavior when trying to mock method like this __methodName so I looked in code base and I found that exist a whitelist of reflectable methods. I would mock these methods like __doRequest from soap ext-library for example with __ in the name. If this behavior can be changed, it would be a great thing, if you agree I could make a PR.

Example

class Test {
   void function __test() {
   }
}
$test = $this->prophesize(Test::class);
$test->__test()->shouldBeCalled();

$testReveal = $test->reveal();
$testReveal->__test();

Output

Double\Test\P1:              
   ├ No calls have been made that match:                    
   ├     Double\Test\P1->__test()
   ├   but expected at least one.                           

Class in prophecy that contains a whitelist

class ClassMirror
{
    public static $reflectableMethods = array(
        '__construct',
        '__destruct',
        '__sleep',
        '__wakeup',
        '__toString',
        '__call',
        '__invoke',
    );
...
    private function reflectClassToNode(ReflectionClass $class, Node\ClassNode $node)
    {
      ...
            foreach ($class->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
            if (0 === strpos($method->getName(), '_')
                && !in_array($method->getName(), self::$reflectableMethods)) {
                continue;
            }
      ...
    }
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

No branches or pull requests

1 participant