{"action":"closed","issue":{"url":"https://api.github.com/repos/kahlan/kahlan/issues/296","repository_url":"https://api.github.com/repos/kahlan/kahlan","labels_url":"https://api.github.com/repos/kahlan/kahlan/issues/296/labels{/name}","comments_url":"https://api.github.com/repos/kahlan/kahlan/issues/296/comments","events_url":"https://api.github.com/repos/kahlan/kahlan/issues/296/events","html_url":"https://github.com/kahlan/kahlan/issues/296","id":310806503,"number":296,"title":"Kahlan 4.1 does not stub PHP functions properly","user":{"login":"lamp-of-god","id":12278034,"avatar_url":"https://avatars1.githubusercontent.com/u/12278034?v=4","gravatar_id":"","url":"https://api.github.com/users/lamp-of-god","html_url":"https://github.com/lamp-of-god","followers_url":"https://api.github.com/users/lamp-of-god/followers","following_url":"https://api.github.com/users/lamp-of-god/following{/other_user}","gists_url":"https://api.github.com/users/lamp-of-god/gists{/gist_id}","starred_url":"https://api.github.com/users/lamp-of-god/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lamp-of-god/subscriptions","organizations_url":"https://api.github.com/users/lamp-of-god/orgs","repos_url":"https://api.github.com/users/lamp-of-god/repos","events_url":"https://api.github.com/users/lamp-of-god/events{/privacy}","received_events_url":"https://api.github.com/users/lamp-of-god/received_events","type":"User","site_admin":false},"labels":[{"id":52585198,"url":"https://api.github.com/repos/kahlan/kahlan/labels/bug","name":"bug","color":"fc2929","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-04-03T11:58:46Z","updated_at":"2018-04-06T23:49:37Z","closed_at":"2018-04-06T23:49:37Z","author_association":"NONE","body":"Hi. It seems to be bug with kahlan 4.1\r\n\r\nMinimal example:\r\nCode of test file:\r\n\r\n```\r\nuse Demo\\GetContents;\r\n\r\ndescribe('->getContents', function() {\r\n\r\n    it('must return correct values', function() {\r\n        allow('file_get_contents')->toBeCalled()->andReturn(false, 'content');\r\n        expect(GetContents::getContents('asd'))->toBe(false);\r\n        expect(GetContents::getContents('asd'))->toBe('content');\r\n    });\r\n\r\n    it('must return correct values with doubles', function() {\r\n        allow('file_get_contents')->toBeCalled()->andReturn(false, 'content');\r\n        expect(GetContents::getContentsDouble('asd'))->toBe('content');\r\n    });\r\n\r\n});\r\n```\r\n\r\nCode of `GetContents` file:\r\n\r\n```\r\n<?php\r\n\r\nnamespace Demo;\r\n\r\n\r\nclass GetContents\r\n{\r\n    public static function getContents($url)\r\n    {\r\n        return file_get_contents($url);\r\n    }\r\n\r\n    public static function getContentsDouble($url)\r\n    {\r\n        $value1 = file_get_contents($url);\r\n        return file_get_contents($url);\r\n    }\r\n}\r\n```\r\n\r\nIn Kahlan v4.0.6 both of tests are passed. In Kahlan 4.1+ only first test is passed.\r\n\r\nYou can see that in first function `file_get_contents` is called one time, and in second - two times.\r\nHovewer, if you will invoke `GetContents::getContents` multiple times it will return different (correct) values.\r\n\r\nSo the problem seems to be with multiple calls of stubbed function in one method.\r\n\r\nSource to test:\r\n\r\n[kahlan-demo.zip](https://github.com/kahlan/kahlan/files/1871379/kahlan-demo.zip)\r\n"}}
{"actor":{"display_login":"jails"}}