Skip to content
New issue

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

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

Already on GitHub? # to your account

1.10.0 weird problem with callables? #458

Closed
acasademont opened this issue Dec 20, 2019 · 3 comments · Fixed by #460
Closed

1.10.0 weird problem with callables? #458

acasademont opened this issue Dec 20, 2019 · 3 comments · Fixed by #460

Comments

@acasademont
Copy link

Hi, we just noticed some strange failing tests after upgrading to 1.10.0. We isolated the problem to this test case.

require __DIR__ . '/vendor/autoload.php';

class A {
    public function calc(callable $callable): int
    {
        return 0;
    }
}

$prophet = new \Prophecy\Prophet();

$callable = function() {};
$a = $prophet->prophesize(A::class);
$a->calc($callable)->willReturn(1);

var_dump($a->reveal()->calc($callable));

with 1.9.0, the output is int(1)
with 1.10.0 there's a fatal error

PHP Fatal error:  Uncaught TypeError: Return value of Double\A\P1::calc() must be of the type int, null returned in /Users/albert/Projects/backend-app/vendor/phpspec/prophecy/src/Prophecy/Doubler/Generator/ClassCreator.php(49) : eval()'d code:6
Stack trace:
#0 /Users/albert/Projects/backend-app/test_prophecy.php(18): Double\A\P1->calc(Object(Closure))
#1 {main}
  thrown in /Users/albert/Projects/backend-app/vendor/phpspec/prophecy/src/Prophecy/Doubler/Generator/ClassCreator.php(49) : eval()'d code on line 6

Fatal error: Uncaught TypeError: Return value of Double\A\P1::calc() must be of the type int, null returned in /Users/albert/Projects/backend-app/vendor/phpspec/prophecy/src/Prophecy/Doubler/Generator/ClassCreator.php(49) : eval()'d code:6
Stack trace:
#0 /Users/albert/Projects/backend-app/test_prophecy.php(18): Double\A\P1->calc(Object(Closure))
#1 {main}
  thrown in /Users/albert/Projects/backend-app/vendor/phpspec/prophecy/src/Prophecy/Doubler/Generator/ClassCreator.php(49) : eval()'d code on line 6

we're using PHP 7.3.13.

The problem seems to be related somehow to the callable, it does not happen if the function argument is a scalar or an object. Any ideas? Thx!!

@adriansuter
Copy link

I can confirm that behaviour. See slimphp/Slim#2901 (comment). If we use Argument::is($callable), then this works again.

@ciaranmcnulty
Copy link
Member

I've reproduced and it seems to be caused by this change to how we match arguments exactly:
e9e0970

I suspect we're treating the method as un-stubbed because matching the two callables isn't working

(ping @scroach)

@ciaranmcnulty
Copy link
Member

Hm, #456 tried to fix this but I missed it in the churn because it was closed again

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

Successfully merging a pull request may close this issue.

3 participants