{"action":"created","issue":{"url":"https://api.github.com/repos/phpspec/prophecy/issues/250","repository_url":"https://api.github.com/repos/phpspec/prophecy","labels_url":"https://api.github.com/repos/phpspec/prophecy/issues/250/labels{/name}","comments_url":"https://api.github.com/repos/phpspec/prophecy/issues/250/comments","events_url":"https://api.github.com/repos/phpspec/prophecy/issues/250/events","html_url":"https://github.com/phpspec/prophecy/issues/250","id":129595942,"number":250,"title":"Spies and PHP7 return typehinting","user":{"login":"Sam-Burns","id":6594039,"avatar_url":"https://avatars.githubusercontent.com/u/6594039?v=3","gravatar_id":"","url":"https://api.github.com/users/Sam-Burns","html_url":"https://github.com/Sam-Burns","followers_url":"https://api.github.com/users/Sam-Burns/followers","following_url":"https://api.github.com/users/Sam-Burns/following{/other_user}","gists_url":"https://api.github.com/users/Sam-Burns/gists{/gist_id}","starred_url":"https://api.github.com/users/Sam-Burns/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Sam-Burns/subscriptions","organizations_url":"https://api.github.com/users/Sam-Burns/orgs","repos_url":"https://api.github.com/users/Sam-Burns/repos","events_url":"https://api.github.com/users/Sam-Burns/events{/privacy}","received_events_url":"https://api.github.com/users/Sam-Burns/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/phpspec/prophecy/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2016-01-28T22:03:31Z","updated_at":"2016-02-28T13:10:24Z","closed_at":null,"body":"Spies don't work with PHP return typehinting.\r\n\r\nExample in repo at https://github.com/Sam-Burns/prophecy-bug-demo for now; code cut-and-paste below for prosperity.\r\n\r\nReproducible step: Clone the repo, run Composer, and run PHPSpec.\r\nExpected result: Spec passes.\r\nActual result:\r\n```\r\n✘ Fatal error happened while executing the following\r\n    it calls something on its dependency\r\n    Uncaught TypeError: Return value of Double\\DependencyWithReturnTypehinting\\P1::getAnInt() must be of the type integer, null returned in\r\n```\r\n\r\nThe basic problem seems to be that spies don't return anything, so you can't make a spy of a class which uses return typehinting.  Perhaps a solution might be to catch ```\\Throwable```, ```\\Error``` or something when calling methods on spies, but I don't really know because I've never read the Prophecy codebase.\r\n\r\nThe code in the temporary repo demonstrating the bug is (was) as follows:\r\n\r\n```php\r\n<?php\r\nclass SubjectUnderTest\r\n{\r\n    public function getAnIntFromThisThing(DependencyWithReturnTypehinting $dependencyWithReturnTypehinting)\r\n    {\r\n        $int = $dependencyWithReturnTypehinting->getAnInt();\r\n    }\r\n}\r\n```\r\n\r\n```php\r\n<?php\r\nclass DependencyWithReturnTypehinting\r\n{\r\n    public function getAnInt(): int\r\n    {\r\n        return 42;\r\n    }\r\n}\r\n```\r\n\r\n```php\r\n<?php\r\nnamespace spec;\r\nuse PhpSpec\\ObjectBehavior;\r\nclass SubjectUnderTestSpec extends ObjectBehavior\r\n{\r\n    function it_calls_something_on_its_dependency(\\DependencyWithReturnTypehinting $dependencyWithReturnTypehinting)\r\n    {\r\n        $this->getAnIntFromThisThing($dependencyWithReturnTypehinting);\r\n        $dependencyWithReturnTypehinting->getAnInt()->shouldHaveBeenCalled();\r\n    }\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/phpspec/prophecy/issues/comments/189867119","html_url":"https://github.com/phpspec/prophecy/issues/250#issuecomment-189867119","issue_url":"https://api.github.com/repos/phpspec/prophecy/issues/250","id":189867119,"user":{"login":"everzet","id":30813,"avatar_url":"https://avatars.githubusercontent.com/u/30813?v=3","gravatar_id":"","url":"https://api.github.com/users/everzet","html_url":"https://github.com/everzet","followers_url":"https://api.github.com/users/everzet/followers","following_url":"https://api.github.com/users/everzet/following{/other_user}","gists_url":"https://api.github.com/users/everzet/gists{/gist_id}","starred_url":"https://api.github.com/users/everzet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/everzet/subscriptions","organizations_url":"https://api.github.com/users/everzet/orgs","repos_url":"https://api.github.com/users/everzet/repos","events_url":"https://api.github.com/users/everzet/events{/privacy}","received_events_url":"https://api.github.com/users/everzet/received_events","type":"User","site_admin":false},"created_at":"2016-02-28T13:10:24Z","updated_at":"2016-02-28T13:10:24Z","body":"After investigation, I don't see a bug anymore. It seems to me that Prophecy behaves like it logically should. Further explanation in PR:\r\nhttps://github.com/phpspec/prophecy/pull/261#issuecomment-189866771"}}