{"action":"created","issue":{"url":"https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/issues/410","repository_url":"https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects","labels_url":"https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/issues/410/labels{/name}","comments_url":"https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/issues/410/comments","events_url":"https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/issues/410/events","html_url":"https://github.com/sebastianbergmann/phpunit-mock-objects/issues/410","id":298631592,"number":410,"title":"More explicit stubbing of __call()","user":{"login":"sebastianbergmann","id":25218,"avatar_url":"https://avatars1.githubusercontent.com/u/25218?v=4","gravatar_id":"","url":"https://api.github.com/users/sebastianbergmann","html_url":"https://github.com/sebastianbergmann","followers_url":"https://api.github.com/users/sebastianbergmann/followers","following_url":"https://api.github.com/users/sebastianbergmann/following{/other_user}","gists_url":"https://api.github.com/users/sebastianbergmann/gists{/gist_id}","starred_url":"https://api.github.com/users/sebastianbergmann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sebastianbergmann/subscriptions","organizations_url":"https://api.github.com/users/sebastianbergmann/orgs","repos_url":"https://api.github.com/users/sebastianbergmann/repos","events_url":"https://api.github.com/users/sebastianbergmann/events{/privacy}","received_events_url":"https://api.github.com/users/sebastianbergmann/received_events","type":"User","site_admin":false},"labels":[{"id":33758,"url":"https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/labels/feature%20request","name":"feature request","color":"009800","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-02-20T15:16:20Z","updated_at":"2018-04-21T15:42:33Z","closed_at":null,"author_association":"OWNER","body":"Lets assume we have a class `C` with a `__call()` method:\r\n```php\r\n<?php declare(strict_types=1);\r\nclass C\r\n{\r\n    public function __call(string $name, array $arguments)\r\n    {\r\n        switch ($name) {\r\n            case 'm':\r\n                return true;\r\n        }\r\n    }\r\n}\r\n```\r\nOne approach to stubbing the behaviour of `C::m()` is\r\n```php\r\n<?php declare(strict_types=1);\r\nfinal class Test extends PHPUnit\\Framework\\TestCase\r\n{\r\n    public function testOne(): void\r\n    {\r\n        $o = $this->createMock(C::class);\r\n        \r\n        $o->method('__call')->willReturn(false);\r\n\r\n        $this->assertFalse($o->m());\r\n    }\r\n}\r\n```\r\nConfiguring `__call` as shown above can become confusing and tedious when more than one \"virtual\" method needs to be stubbed and configured.\r\n\r\nAnother approach to stubbing the behaviour of `C::m()` is\r\n```php\r\n<?php declare(strict_types=1);\r\nfinal class Test extends PHPUnit\\Framework\\TestCase\r\n{\r\n    public function testTwo(): void\r\n    {\r\n        $o = $this->createPartialMock(C::class, ['m']);\r\n        \r\n        $o->method('m')->willReturn(false);\r\n\r\n        $this->assertFalse($o->m());\r\n    }\r\n}\r\n```\r\nThe above works (at least in this simple case), and is more explict, but we do not want a partial stub here.\r\n\r\nA better approach could be to provide a new method that works just like `createMock()` but takes an array of additional methods as its second parameter."},"comment":{"url":"https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/issues/comments/383306613","html_url":"https://github.com/sebastianbergmann/phpunit-mock-objects/issues/410#issuecomment-383306613","issue_url":"https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/issues/410","id":383306613,"user":{"login":"stale[bot]","id":26384082,"avatar_url":"https://avatars3.githubusercontent.com/in/1724?v=4","gravatar_id":"","url":"https://api.github.com/users/stale%5Bbot%5D","html_url":"https://github.com/apps/stale","followers_url":"https://api.github.com/users/stale%5Bbot%5D/followers","following_url":"https://api.github.com/users/stale%5Bbot%5D/following{/other_user}","gists_url":"https://api.github.com/users/stale%5Bbot%5D/gists{/gist_id}","starred_url":"https://api.github.com/users/stale%5Bbot%5D/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stale%5Bbot%5D/subscriptions","organizations_url":"https://api.github.com/users/stale%5Bbot%5D/orgs","repos_url":"https://api.github.com/users/stale%5Bbot%5D/repos","events_url":"https://api.github.com/users/stale%5Bbot%5D/events{/privacy}","received_events_url":"https://api.github.com/users/stale%5Bbot%5D/received_events","type":"Bot","site_admin":false},"created_at":"2018-04-21T15:42:33Z","updated_at":"2018-04-21T15:42:33Z","author_association":"NONE","body":"This issue has been automatically marked as stale because it has not had activity within the last 60 days. It will be closed after 7 days if no further activity occurs. Thank you for your contributions.\n"}}
{"actor":{"display_login":"stale"}}