{"action":"created","issue":{"url":"https://api.github.com/repos/crysalead/kahlan/issues/76","labels_url":"https://api.github.com/repos/crysalead/kahlan/issues/76/labels{/name}","comments_url":"https://api.github.com/repos/crysalead/kahlan/issues/76/comments","events_url":"https://api.github.com/repos/crysalead/kahlan/issues/76/events","html_url":"https://github.com/crysalead/kahlan/issues/76","id":104272256,"number":76,"title":"Stubs don't seem to get cleared (conflicting tests)","user":{"login":"gavD","id":205245,"avatar_url":"https://avatars.githubusercontent.com/u/205245?v=3","gravatar_id":"","url":"https://api.github.com/users/gavD","html_url":"https://github.com/gavD","followers_url":"https://api.github.com/users/gavD/followers","following_url":"https://api.github.com/users/gavD/following{/other_user}","gists_url":"https://api.github.com/users/gavD/gists{/gist_id}","starred_url":"https://api.github.com/users/gavD/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gavD/subscriptions","organizations_url":"https://api.github.com/users/gavD/orgs","repos_url":"https://api.github.com/users/gavD/repos","events_url":"https://api.github.com/users/gavD/events{/privacy}","received_events_url":"https://api.github.com/users/gavD/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-09-01T13:56:02Z","updated_at":"2015-09-01T14:29:18Z","closed_at":null,"body":"Hello\r\n\r\nI have two tests in my project that conflict (reduced down to the simplest case that causes the bug):\r\n\r\n**PingerSpec.php**\r\n\r\n```php\r\n<?php\r\nuse kahlan\\plugin\\Stub;\r\n\r\ndescribe(\"Pinger\", function() {\r\n        beforeEach(function() {\r\n            $this->describer = Stub::create(['class' => 'denzel\\services\\aws\\InstanceDescriber']);\r\n        });\r\n\r\n        it(\"...\", function() {\r\n            expect(1)->toBe(1);\r\n        });\r\n});\r\n?>\r\n```\r\n\r\n**InstanceDescriberSpec.php**\r\n\r\n```php\r\n<?php\r\nuse denzel\\services\\aws\\InstanceDescriber;\r\nuse kahlan\\plugin\\Stub;\r\n\r\ndescribe(\"InstanceDescriber\", function() {\r\n    beforeEach(function() {\r\n        $this->client = Stub::create(['class' => 'Aws\\Ec2\\Ec2Client']);\r\n        $this->sut = new InstanceDescriber($this->client);\r\n    });\r\n\r\n    describe('getInstance()', function() {\r\n        it(\"returns an instance\", function() {\r\n            expect(1)->toBe(1);\r\n        });\r\n    });\r\n});\r\n?>\r\n```\r\n\r\nIf I run either test in isolation using `fdescribe`, each test works fine. If I run them together, though, I get:\r\n\r\n```\r\n.E                                                                               100%\r\n\r\nPinger\r\n  ping()\r\n    ✘ it ...\r\n      an uncaught exception has been thrown in `/tmp/kahlan/denzel/services/aws/InstanceDescriber.php` line 21\r\n\r\n      message:`kahlan\\PhpErrorException` Code(0) with message \"`E_RECOVERABLE_ERROR` Argument 1 passed to denzel\\\\services\\\\aws\\\\InstanceDescriber::__construct() must be an instance of Aws\\\\Ec2\\\\Ec2Client, none given, called in /opt/denzel/libraries/crysalead/kahlan/src/plugin/Stub.php on line 196 and defined\"\r\n\r\n        [NA] - /tmp/kahlan/opt/denzel/denzel/services/aws/InstanceDescriber.php, line  to 21\r\n        denzel\\services\\aws\\InstanceDescriber::__construct() - /opt/denzel/libraries/crysalead/kahlan/src/plugin/Stub.php, line 196\r\n        kahlan\\plugin\\Stub::create() - /opt/denzel/spec/services/aws/PingerSpec.php, line 7\r\n        kahlan\\Suite::runCallbacks() - /opt/denzel/libraries/crysalead/kahlan/src/Spec.php, line 88\r\n        kahlan\\Spec::_specStart() - /opt/denzel/libraries/crysalead/kahlan/src/Spec.php, line 67\r\n        kahlan\\Spec::process() - /opt/denzel/libraries/crysalead/kahlan/src/Suite.php, line 304\r\n        kahlan\\Suite::process() - /opt/denzel/libraries/crysalead/kahlan/src/Suite.php, line 304\r\n        kahlan\\Suite::process() - /opt/denzel/libraries/crysalead/kahlan/src/Suite.php, line 304\r\n        kahlan\\Suite::process() - /opt/denzel/libraries/crysalead/kahlan/src/Suite.php, line 417\r\n        kahlan\\Suite::run() - /opt/denzel/libraries/crysalead/kahlan/src/cli/Kahlan.php, line 540\r\n        filter\\Filter::on() - /opt/denzel/libraries/crysalead/kahlan/src/cli/Kahlan.php, line 541\r\n        kahlan\\cli\\Kahlan::_run() - /opt/denzel/libraries/crysalead/kahlan/src/cli/Kahlan.php, line 361\r\n        filter\\Filter::on() - /opt/denzel/libraries/crysalead/kahlan/src/cli/Kahlan.php, line 369\r\n        kahlan\\cli\\Kahlan::run() - /opt/denzel/libraries/crysalead/kahlan/bin/kahlan, line 44\r\n\r\nExecuted 1 of 2 FAIL (EXCEPTION: 1) in 0.103 seconds\r\n```\r\n\r\nThis suggests to me that the mock on `InstanceDescriber` in `PingerSpec` causes problems when it comes to `InstanceDescriberSpec`.\r\n\r\nAm I approaching this incorrectly?\r\n\r\nMy classes (simplified for reference):\r\n\r\n```php\r\n<?php\r\nnamespace denzel\\services\\aws;\r\n\r\nuse Aws\\Ec2\\Ec2Client;\r\n\r\nclass InstanceDescriber {\r\n\r\n    protected $_client;\r\n\r\n    public function __construct(Ec2Client $client) {\r\n        $this->_client = $client;\r\n    }\r\n\r\n    public function getInstance($id) {\r\n        $results = $this->_client->describeInstances(['InstanceIds' => [$id]]);\r\n        return $results['Reservations'][0]['Instances'][0];\r\n    }\r\n}\r\n?>\r\n```\r\n\r\n```php\r\n<?php\r\nnamespace denzel\\services\\aws;\r\n\r\nclass Pinger {\r\n    protected $_describer;\r\n\r\n    public function __construct(InstanceDescriber $describer) {\r\n        $this->_describer = $describer;\r\n    }\r\n    public function ping($instanceId) {\r\n        return false; // TODO\r\n    }\r\n}\r\n?>\r\n```\r\n\r\nI'd appreciate any suggestions! :-)\r\n"},"comment":{"url":"https://api.github.com/repos/crysalead/kahlan/issues/comments/136740362","html_url":"https://github.com/crysalead/kahlan/issues/76#issuecomment-136740362","issue_url":"https://api.github.com/repos/crysalead/kahlan/issues/76","id":136740362,"user":{"login":"gavD","id":205245,"avatar_url":"https://avatars.githubusercontent.com/u/205245?v=3","gravatar_id":"","url":"https://api.github.com/users/gavD","html_url":"https://github.com/gavD","followers_url":"https://api.github.com/users/gavD/followers","following_url":"https://api.github.com/users/gavD/following{/other_user}","gists_url":"https://api.github.com/users/gavD/gists{/gist_id}","starred_url":"https://api.github.com/users/gavD/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gavD/subscriptions","organizations_url":"https://api.github.com/users/gavD/orgs","repos_url":"https://api.github.com/users/gavD/repos","events_url":"https://api.github.com/users/gavD/events{/privacy}","received_events_url":"https://api.github.com/users/gavD/received_events","type":"User","site_admin":false},"created_at":"2015-09-01T14:29:18Z","updated_at":"2015-09-01T14:29:18Z","body":"aha! Thanks @jails that makes perfect sense, thank you :-1: "}}