{"action":"created","issue":{"url":"https://api.github.com/repos/Codeception/Codeception/issues/2626","labels_url":"https://api.github.com/repos/Codeception/Codeception/issues/2626/labels{/name}","comments_url":"https://api.github.com/repos/Codeception/Codeception/issues/2626/comments","events_url":"https://api.github.com/repos/Codeception/Codeception/issues/2626/events","html_url":"https://github.com/Codeception/Codeception/issues/2626","id":121632482,"number":2626,"title":"Codeception execution ends early since an exit is called within the code","user":{"login":"fc","id":20962,"avatar_url":"https://avatars.githubusercontent.com/u/20962?v=3","gravatar_id":"","url":"https://api.github.com/users/fc","html_url":"https://github.com/fc","followers_url":"https://api.github.com/users/fc/followers","following_url":"https://api.github.com/users/fc/following{/other_user}","gists_url":"https://api.github.com/users/fc/gists{/gist_id}","starred_url":"https://api.github.com/users/fc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fc/subscriptions","organizations_url":"https://api.github.com/users/fc/orgs","repos_url":"https://api.github.com/users/fc/repos","events_url":"https://api.github.com/users/fc/events{/privacy}","received_events_url":"https://api.github.com/users/fc/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-11T03:54:18Z","updated_at":"2015-12-14T22:02:55Z","closed_at":"2015-12-14T22:02:55Z","body":"I am using the ZF1 module although others may be affected.  I'm 100% new to any kind of code testing tools so forgive me if I've overlooked anything.\r\n\r\nI run codeception from the command line (not doing blackbox testing or running headless, etc).\r\n\r\ncodeception will run code and then suddenly stop at a line like this:\r\n```\r\n* I someaction {...}\r\n```\r\n\r\nOkay... so I had to poke around in the code until finding that the code runs runs an 'exit' after sending JSON to the browser.\r\n\r\nMy workaround (hack) is as follows.  Modify the Codeception/Lib/Connector/ZF1.php\r\n```\r\n--- a/vendor/codeception/codeception/src/Codeception/Lib/Connector/ZF1.php\r\n+++ b/vendor/codeception/codeception/src/Codeception/Lib/Connector/ZF1.php\r\n@@ -70,9 +70,11 @@ public function doRequest($request)\r\n             $this->bootstrap->run();\r\n             $_GET = $_POST = [];\r\n         } catch (\\Exception $e) {\r\n-            ob_end_clean();\r\n             $_GET = $_POST = [];\r\n-            throw $e;\r\n+            if ($e->getMessage()!='SAFE_EXIT') {\r\n+                ob_end_clean();\r\n+                throw $e;\r\n+            }\r\n         }\r\n         ob_end_clean();\r\n```\r\nthen replacing the exit with this:\r\n```\r\n-        exit;\r\n+               if ( Zend_Session::$_unitTestEnabled ) {\r\n+                       throw new Exception('SAFE_EXIT');\r\n+               } else {\r\n+                       exit;\r\n+               }\r\n```\r\n\r\nSomething feels totally wrong about trying to fix it in this way... so either there is a better way to do it, or perhaps there is an existing method within codeception that does this?\r\nAnd, certainly, the Json helper in ZF1 not exiting would also be a fix but that would require code changes that I don't want to make at this time.\r\n\r\nWhat do you think?"},"comment":{"url":"https://api.github.com/repos/Codeception/Codeception/issues/comments/164573917","html_url":"https://github.com/Codeception/Codeception/issues/2626#issuecomment-164573917","issue_url":"https://api.github.com/repos/Codeception/Codeception/issues/2626","id":164573917,"user":{"login":"Naktibalda","id":395992,"avatar_url":"https://avatars.githubusercontent.com/u/395992?v=3","gravatar_id":"","url":"https://api.github.com/users/Naktibalda","html_url":"https://github.com/Naktibalda","followers_url":"https://api.github.com/users/Naktibalda/followers","following_url":"https://api.github.com/users/Naktibalda/following{/other_user}","gists_url":"https://api.github.com/users/Naktibalda/gists{/gist_id}","starred_url":"https://api.github.com/users/Naktibalda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Naktibalda/subscriptions","organizations_url":"https://api.github.com/users/Naktibalda/orgs","repos_url":"https://api.github.com/users/Naktibalda/repos","events_url":"https://api.github.com/users/Naktibalda/events{/privacy}","received_events_url":"https://api.github.com/users/Naktibalda/received_events","type":"User","site_admin":false},"created_at":"2015-12-14T22:02:55Z","updated_at":"2015-12-14T22:02:55Z","body":"[Using `exit` makes your code untestable](http://phpmd.org/rules/design.html).\r\n\r\nMultiple alternatives are given in this StackOverflow thread: http://stackoverflow.com/questions/1347794/how-do-you-use-phpunit-to-test-a-function-if-that-function-is-supposed-to-kill-ph\r\n\r\nParticularly interesting is the one which suggests that `exit` can be overloaded.\r\nLink to current repository of PHP extension: https://github.com/krakjoe/uopz#overload-example\r\n\r\nCodeception can't overload `exit`."}}