{"action":"created","issue":{"url":"https://api.github.com/repos/atoum/atoum/issues/678","repository_url":"https://api.github.com/repos/atoum/atoum","labels_url":"https://api.github.com/repos/atoum/atoum/issues/678/labels{/name}","comments_url":"https://api.github.com/repos/atoum/atoum/issues/678/comments","events_url":"https://api.github.com/repos/atoum/atoum/issues/678/events","html_url":"https://github.com/atoum/atoum/pull/678","id":196704311,"number":678,"title":"Now, each mock instance may be unique, even if they are not identical.","user":{"login":"mageekguy","id":457534,"avatar_url":"https://avatars.githubusercontent.com/u/457534?v=3","gravatar_id":"","url":"https://api.github.com/users/mageekguy","html_url":"https://github.com/mageekguy","followers_url":"https://api.github.com/users/mageekguy/followers","following_url":"https://api.github.com/users/mageekguy/following{/other_user}","gists_url":"https://api.github.com/users/mageekguy/gists{/gist_id}","starred_url":"https://api.github.com/users/mageekguy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mageekguy/subscriptions","organizations_url":"https://api.github.com/users/mageekguy/orgs","repos_url":"https://api.github.com/users/mageekguy/repos","events_url":"https://api.github.com/users/mageekguy/events{/privacy}","received_events_url":"https://api.github.com/users/mageekguy/received_events","type":"User","site_admin":false},"labels":[{"id":7571511,"url":"https://api.github.com/repos/atoum/atoum/labels/bug","name":"bug","color":"e10c02","default":true},{"id":153784904,"url":"https://api.github.com/repos/atoum/atoum/labels/enhancement","name":"enhancement","color":"fbca04","default":true}],"state":"open","locked":false,"assignee":{"login":"Hywan","id":946104,"avatar_url":"https://avatars.githubusercontent.com/u/946104?v=3","gravatar_id":"","url":"https://api.github.com/users/Hywan","html_url":"https://github.com/Hywan","followers_url":"https://api.github.com/users/Hywan/followers","following_url":"https://api.github.com/users/Hywan/following{/other_user}","gists_url":"https://api.github.com/users/Hywan/gists{/gist_id}","starred_url":"https://api.github.com/users/Hywan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Hywan/subscriptions","organizations_url":"https://api.github.com/users/Hywan/orgs","repos_url":"https://api.github.com/users/Hywan/repos","events_url":"https://api.github.com/users/Hywan/events{/privacy}","received_events_url":"https://api.github.com/users/Hywan/received_events","type":"User","site_admin":false},"assignees":[{"login":"Hywan","id":946104,"avatar_url":"https://avatars.githubusercontent.com/u/946104?v=3","gravatar_id":"","url":"https://api.github.com/users/Hywan","html_url":"https://github.com/Hywan","followers_url":"https://api.github.com/users/Hywan/followers","following_url":"https://api.github.com/users/Hywan/following{/other_user}","gists_url":"https://api.github.com/users/Hywan/gists{/gist_id}","starred_url":"https://api.github.com/users/Hywan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Hywan/subscriptions","organizations_url":"https://api.github.com/users/Hywan/orgs","repos_url":"https://api.github.com/users/Hywan/repos","events_url":"https://api.github.com/users/Hywan/events{/privacy}","received_events_url":"https://api.github.com/users/Hywan/received_events","type":"User","site_admin":false}],"milestone":null,"comments":3,"created_at":"2016-12-20T15:40:54Z","updated_at":"2016-12-21T07:48:47Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/atoum/atoum/pulls/678","html_url":"https://github.com/atoum/atoum/pull/678","diff_url":"https://github.com/atoum/atoum/pull/678.diff","patch_url":"https://github.com/atoum/atoum/pull/678.patch"},"body":"Hi folks,\r\n\r\nThat made a very loooooong time, and i'm very happy to contribute once again to `atoum`.  \r\nMaybe you can see this PR as a gift for Xmas, with all my love ;), because you do an awesome job.  \r\nHowever, now that I have say that, i can say that this PR may be seems weird at first look, but… i have very good reasons to do it.  \r\nSo, this is a test:\r\n\r\n```\r\n$this\r\n\t->given(\r\n\t\t$output = new mockOfOutput,\r\n\r\n\t\t$outputOfBlock1 = new mockOfOutput,\r\n\t\t$block1 = new mockOfBlock,\r\n\t\t$this->calling($block1)->blockArgumentsAre = function($output, $recipient) use ($outputOfBlock1) {\r\n\t\t\t$recipient->outputIs($outputOfBlock1);\r\n\t\t},\r\n\r\n\t\t$outputOfBlock2 = new mockOfOutput,\r\n\t\t$outputOfBlock2->id = uniqid(),\r\n\t\t$block2 = new mockOfBlock,\r\n\t\t$this->calling($block2)->blockArgumentsAre = function($output, $recipient) use ($outputOfBlock2) {\r\n\t\t\t$recipient->outputIs($outputOfBlock2);\r\n\t\t}\r\n\t)\r\n\t->if(\r\n\t\t$this->newTestedInstance($output)\r\n\t)\r\n\t->then\r\n\t\t->object($this->testedInstance->blockCollectionIs(new block\\collection($block1, $block2)))\r\n\t\t\t->isEqualTo($this->newTestedInstance($outputOfBlock2))\r\n\t\t->mock($block1)\r\n\t\t\t->receive('blockArgumentsAre')\r\n\t\t\t\t->withArguments($output)\r\n\t\t\t\t\t->once\r\n\t\t->mock($block2)\r\n\t\t\t->receive('blockArgumentsAre')\r\n\t\t\t\t->withArguments($outputOfBlock1)\r\n\t\t\t\t\t->once\r\n;\r\n```\r\n\r\nThis test is perfectly valid at first look, but… there is a trap!  \r\nIn this context, `$output` is strictly equal to `$outputOfBlock2`, so to be clear, `$output == $outputOfBlock2`.  \r\nSo, `$this->newTestedInstance($output) == $this->newTestedInstance($outputOfBlock2)`, and assertion `->isEqualTo($this->newTestedInstance($outputOfBlock2))` is true.  \r\nSo, if i'm using `$output` instead of `$outputOfBlock2` if in the tested code, the test will be… GREEN, and not RED, whereas there is a bug in the tested code!  \r\nAnd in this context, it's not possible to use `->withIdenticalArguments` to check that the return value was built with the right instance of `output` class.   \r\nThe only trick is to add `$outputOfBlock2->id = uniqid();` after `$outputOfBlock2` instantiation to be able to differentiate it from `$output`.  \r\nAnd it's exactly that this PR do, but automatically.  \r\nHowever, this change can introduce BC breaks in some tests, and we don't like BC breaks.  \r\nSo, this ID is added in mock instances only if `mock\\generator::eachInstanceIsUnique()` was called somewhere during test setup.  \r\nHappy code review!"},"comment":{"url":"https://api.github.com/repos/atoum/atoum/issues/comments/268458184","html_url":"https://github.com/atoum/atoum/pull/678#issuecomment-268458184","issue_url":"https://api.github.com/repos/atoum/atoum/issues/678","id":268458184,"user":{"login":"mageekguy","id":457534,"avatar_url":"https://avatars.githubusercontent.com/u/457534?v=3","gravatar_id":"","url":"https://api.github.com/users/mageekguy","html_url":"https://github.com/mageekguy","followers_url":"https://api.github.com/users/mageekguy/followers","following_url":"https://api.github.com/users/mageekguy/following{/other_user}","gists_url":"https://api.github.com/users/mageekguy/gists{/gist_id}","starred_url":"https://api.github.com/users/mageekguy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mageekguy/subscriptions","organizations_url":"https://api.github.com/users/mageekguy/orgs","repos_url":"https://api.github.com/users/mageekguy/repos","events_url":"https://api.github.com/users/mageekguy/events{/privacy}","received_events_url":"https://api.github.com/users/mageekguy/received_events","type":"User","site_admin":false},"created_at":"2016-12-21T07:48:47Z","updated_at":"2016-12-21T07:48:47Z","body":"From my point of view, its -1 for 3.0, because this PR does not introduce any BC break.  \r\nThe behaviour is different only if the user call `mock\\generator::eachInstanceIsUnique()` (and somewhere, it's a bug…).  "}}
{"actor":{"display_login":"mageekguy"}}