{"action":"created","issue":{"url":"https://api.github.com/repos/phpspec/phpspec/issues/702","labels_url":"https://api.github.com/repos/phpspec/phpspec/issues/702/labels{/name}","comments_url":"https://api.github.com/repos/phpspec/phpspec/issues/702/comments","events_url":"https://api.github.com/repos/phpspec/phpspec/issues/702/events","html_url":"https://github.com/phpspec/phpspec/pull/702","id":75252852,"number":702,"title":"Fixed exception thrown by ArrayKeyValueMatcher","user":{"login":"gquemener","id":668604,"avatar_url":"https://avatars.githubusercontent.com/u/668604?v=3","gravatar_id":"","url":"https://api.github.com/users/gquemener","html_url":"https://github.com/gquemener","followers_url":"https://api.github.com/users/gquemener/followers","following_url":"https://api.github.com/users/gquemener/following{/other_user}","gists_url":"https://api.github.com/users/gquemener/gists{/gist_id}","starred_url":"https://api.github.com/users/gquemener/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gquemener/subscriptions","organizations_url":"https://api.github.com/users/gquemener/orgs","repos_url":"https://api.github.com/users/gquemener/repos","events_url":"https://api.github.com/users/gquemener/events{/privacy}","received_events_url":"https://api.github.com/users/gquemener/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/phpspec/phpspec/labels/bug","name":"bug","color":"e10c02"}],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/phpspec/phpspec/milestones/11","html_url":"https://github.com/phpspec/phpspec/milestones/2.2.1","labels_url":"https://api.github.com/repos/phpspec/phpspec/milestones/11/labels","id":1125528,"number":11,"title":"2.2.1","description":null,"creator":{"login":"ciaranmcnulty","id":237866,"avatar_url":"https://avatars.githubusercontent.com/u/237866?v=3","gravatar_id":"","url":"https://api.github.com/users/ciaranmcnulty","html_url":"https://github.com/ciaranmcnulty","followers_url":"https://api.github.com/users/ciaranmcnulty/followers","following_url":"https://api.github.com/users/ciaranmcnulty/following{/other_user}","gists_url":"https://api.github.com/users/ciaranmcnulty/gists{/gist_id}","starred_url":"https://api.github.com/users/ciaranmcnulty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ciaranmcnulty/subscriptions","organizations_url":"https://api.github.com/users/ciaranmcnulty/orgs","repos_url":"https://api.github.com/users/ciaranmcnulty/repos","events_url":"https://api.github.com/users/ciaranmcnulty/events{/privacy}","received_events_url":"https://api.github.com/users/ciaranmcnulty/received_events","type":"User","site_admin":false},"open_issues":0,"closed_issues":1,"state":"open","created_at":"2015-05-22T11:31:19Z","updated_at":"2015-05-22T22:11:49Z","due_on":null,"closed_at":null},"comments":10,"created_at":"2015-05-11T15:06:25Z","updated_at":"2015-05-23T07:55:58Z","closed_at":"2015-05-22T22:11:49Z","pull_request":{"url":"https://api.github.com/repos/phpspec/phpspec/pulls/702","html_url":"https://github.com/phpspec/phpspec/pull/702","diff_url":"https://github.com/phpspec/phpspec/pull/702.diff","patch_url":"https://github.com/phpspec/phpspec/pull/702.patch"},"body":"I see several problems with the current implementation of the ArrayKeyValueMatcher:\r\n\r\n- `$this->method()->shouldHaveKeyWithValue('foo', 'bar')` will throw exception telling that no matcher was found for \"haveKeyWithValue\", even if the matcher is registered. This is because the matcher is only used when the method returns an array or an ArrayObject. This is not convenient at all, as I expect my method body to be empty (and thus return `null`) when I'm writing my spec. PhpSpec should tell me that expecting result was an array or instance or ArrayObject and that he received something else.\r\n- When my method returns an array that doesn't contain the expected key, PhpSpec will raise a notice error: `Undefined index on line 79`. BTW, this error was no captured earlier because of the use of `shouldThrow()` without argument. It indeed throws an exception but not the good one! \r\n\r\nThis PR covers these lacks.\r\n\r\nAnother concern of mine is what to expect when I do `$this->method()->shouldNotHaveKeyWithValue('abc', 123)` and `$this->method()` returns `[]`? Should it fail because the method didn't return an array with the expected key? Was the key expected at all (as we are asserting the content of the key, I'd say yes, we expect the value of the key not to be `123`, but we at least expect the key to exist, don't you think?)?"},"comment":{"url":"https://api.github.com/repos/phpspec/phpspec/issues/comments/104862019","html_url":"https://github.com/phpspec/phpspec/pull/702#issuecomment-104862019","issue_url":"https://api.github.com/repos/phpspec/phpspec/issues/702","id":104862019,"user":{"login":"ciaranmcnulty","id":237866,"avatar_url":"https://avatars.githubusercontent.com/u/237866?v=3","gravatar_id":"","url":"https://api.github.com/users/ciaranmcnulty","html_url":"https://github.com/ciaranmcnulty","followers_url":"https://api.github.com/users/ciaranmcnulty/followers","following_url":"https://api.github.com/users/ciaranmcnulty/following{/other_user}","gists_url":"https://api.github.com/users/ciaranmcnulty/gists{/gist_id}","starred_url":"https://api.github.com/users/ciaranmcnulty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ciaranmcnulty/subscriptions","organizations_url":"https://api.github.com/users/ciaranmcnulty/orgs","repos_url":"https://api.github.com/users/ciaranmcnulty/repos","events_url":"https://api.github.com/users/ciaranmcnulty/events{/privacy}","received_events_url":"https://api.github.com/users/ciaranmcnulty/received_events","type":"User","site_admin":false},"created_at":"2015-05-23T07:55:58Z","updated_at":"2015-05-23T07:55:58Z","body":"Thanks for spotting and fixing this, @gquemener.\r\n\r\nI'll make a 2.2.1 release soon for this fix."}}