Closed i-am-nikola closed 2 years ago
@kenjis i have same issues, could you help me check it please? thank you so much!
It seems the code does return nothing.
try {
$data = [123];
exit();
} catch(Exception $e) {
$data = [456];
exit();
}
Can you show the minimul code to reproduce your problem?
@kenjis
try {
$this->response('Success')
} catch(Exception $e) {
$this->response('Failed');
}
My response
function response($message) {
// mycode
exit();
}
It return both $this->response('Success')
and $this->response('Failed')
, I want return only $this->response('Success')
See https://github.com/kenjis/ci-phpunit-test/blob/3.x/docs/HowToWriteTests.md#codeigniter-rest-server
In your case:
try {
echo 'Success';
exit();
} catch(CIPHPUnitTestExitException $e) {
throw $e;
} catch(Exception $e) {
echo 'Failed';
exit();
}
@kenjis Good worked, My problem is solved. Thank you so much!!!
ci-phpunit-test has functionality that makes all exit() and die() in your code throw CIPHPUnitTestExitException
When I use "try cache" in my code, both response and exception are returned. ex: try { $data = [123]; exit(); } catch(Exception $e) { $data = [456]; exit(); } => return "[123][456]" in my test case. I don't want this, My Expected result is return "[123]" Thanks!!!