{"action":"created","issue":{"url":"https://api.github.com/repos/sebastianbergmann/phpunit/issues/1601","labels_url":"https://api.github.com/repos/sebastianbergmann/phpunit/issues/1601/labels{/name}","comments_url":"https://api.github.com/repos/sebastianbergmann/phpunit/issues/1601/comments","events_url":"https://api.github.com/repos/sebastianbergmann/phpunit/issues/1601/events","html_url":"https://github.com/sebastianbergmann/phpunit/issues/1601","id":56683990,"number":1601,"title":"mock ->with($this->callback(callback)) - callback is called once more than expected","user":{"login":"simonbrahan","id":5075397,"avatar_url":"https://avatars.githubusercontent.com/u/5075397?v=3","gravatar_id":"","url":"https://api.github.com/users/simonbrahan","html_url":"https://github.com/simonbrahan","followers_url":"https://api.github.com/users/simonbrahan/followers","following_url":"https://api.github.com/users/simonbrahan/following{/other_user}","gists_url":"https://api.github.com/users/simonbrahan/gists{/gist_id}","starred_url":"https://api.github.com/users/simonbrahan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simonbrahan/subscriptions","organizations_url":"https://api.github.com/users/simonbrahan/orgs","repos_url":"https://api.github.com/users/simonbrahan/repos","events_url":"https://api.github.com/users/simonbrahan/events{/privacy}","received_events_url":"https://api.github.com/users/simonbrahan/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-02-05T15:24:48Z","updated_at":"2015-02-05T21:38:45Z","closed_at":null,"body":"    <?php\r\n    \r\n    class MockedThing\r\n    {\r\n        public function doMockedThing($arg)\r\n        {\r\n            return $arg;\r\n        }\r\n    }\r\n    \r\n    class Thing\r\n    {\r\n        protected $mocked_thing;\r\n    \r\n        public function __construct($mocked_thing)\r\n        {\r\n            $this->mocked_thing = $mocked_thing;\r\n        }\r\n    \r\n        public function doThing($arg)\r\n        {\r\n            $this->mocked_thing->doMockedThing($arg);\r\n        }\r\n    }\r\n    \r\n    class ThingTest extends PHPUnit_Framework_TestCase\r\n    {\r\n        public function testThingHappens()\r\n        {\r\n            $mock = $this->getMockBuilder('MockedThing')\r\n                         ->disableOriginalConstructor()\r\n                         ->getMock();\r\n    \r\n            $validate_param = function ($params) {\r\n                var_dump($params);\r\n                return true;\r\n            };\r\n    \r\n            $mock->expects($this->exactly(2))\r\n                 ->method('doMockedThing')\r\n                 ->with($this->callback($validate_param));\r\n    \r\n            $thing = new Thing($mock);\r\n    \r\n            $thing->doThing('thing 1');\r\n            $thing->doThing('thing 2');\r\n        }\r\n    }\r\n\r\nIn this code the $validate_param is called three times where I would expect it to be called twice. Output as follows:\r\n\r\n    PHPUnit 4.4.5 by Sebastian Bergmann.\r\n\r\n    .string(7) \"thing 1\"\r\n    string(7) \"thing 2\"\r\n    string(7) \"thing 2\"\r\n\r\n\r\n    Time: 16 ms, Memory: 4.00Mb\r\n\r\n    OK (1 test, 1 assertion)\r\n\r\nRun against PHP 5.3.3."},"comment":{"url":"https://api.github.com/repos/sebastianbergmann/phpunit/issues/comments/73134204","html_url":"https://github.com/sebastianbergmann/phpunit/issues/1601#issuecomment-73134204","issue_url":"https://api.github.com/repos/sebastianbergmann/phpunit/issues/1601","id":73134204,"user":{"login":"simonbrahan","id":5075397,"avatar_url":"https://avatars.githubusercontent.com/u/5075397?v=3","gravatar_id":"","url":"https://api.github.com/users/simonbrahan","html_url":"https://github.com/simonbrahan","followers_url":"https://api.github.com/users/simonbrahan/followers","following_url":"https://api.github.com/users/simonbrahan/following{/other_user}","gists_url":"https://api.github.com/users/simonbrahan/gists{/gist_id}","starred_url":"https://api.github.com/users/simonbrahan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simonbrahan/subscriptions","organizations_url":"https://api.github.com/users/simonbrahan/orgs","repos_url":"https://api.github.com/users/simonbrahan/repos","events_url":"https://api.github.com/users/simonbrahan/events{/privacy}","received_events_url":"https://api.github.com/users/simonbrahan/received_events","type":"User","site_admin":false},"created_at":"2015-02-05T21:38:45Z","updated_at":"2015-02-05T21:38:45Z","body":"That fix will only allow one verification to occur. Running my code against that branch produces the following:\r\n\r\n    PHPUnit 4.4.5 by Sebastian Bergmann.\r\n    \r\n    .string(7) \"thing 1\"\r\n    \r\n    \r\n    Time: 15 ms, Memory: 3.00Mb\r\n    \r\n    OK (1 test, 1 assertion)\r\n\r\nI would expect an output similar to:\r\n\r\n    PHPUnit 4.4.5 by Sebastian Bergmann.\r\n    \r\n    .string(7) \"thing 1\"\r\n    string(7) \"thing 2\"\r\n    \r\n    \r\n    Time: 16 ms, Memory: 4.00Mb\r\n\r\nOK (1 test, 1 assertion)"}}