-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove calls to exit functions and cleanups #790
Remove calls to exit functions and cleanups #790
Conversation
just to give no error and be happy.
Codecov Report
@@ Coverage Diff @@
## develop #790 +/- ##
=============================================
+ Coverage 71.17% 71.66% +0.49%
+ Complexity 2246 2240 -6
=============================================
Files 119 119
Lines 5328 5311 -17
=============================================
+ Hits 3792 3806 +14
+ Misses 1536 1505 -31
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## develop #790 +/- ##
=============================================
+ Coverage 71.26% 76.51% +5.25%
- Complexity 2242 2250 +8
=============================================
Files 119 119
Lines 5325 5336 +11
=============================================
+ Hits 3795 4083 +288
+ Misses 1530 1253 -277
Continue to review full report at Codecov.
|
src/App.php
Outdated
// catch Exit Exception and return | ||
if ($exception instanceof ExitApplicationException) { | ||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clever approach to avoid error.
But it's different to what we dicsussed and i think this can cause problem if you run app with "catch_exception = false".
Also i think it will create some insanity if used with logger (which normally log all unhandled exceptions)
Best to implement the property App::call_exit = true , which can be modified to "false" if exception is required.
Need to be App to stop execution.
just try to solve issue on travis for Callbacks TEST
they are caught in set_exception_handler or custom catch
add a TODO about checking this because multiple sent, may be the cause is the underlying developer code
use the built in server i use in local testing
i try to added to request/response check for demos and coverage, the new actions from demos/actions.php Local it works perfectly, on travis if i call the url POST for confirm in download popup action or the url POST for submit the form in edit popup for record 1, i get an error of record not found, which is wrong because i call first the action to importFromFileSystem which will populate the database. I don't understand what is wrong on travis. Probably i will divide this PR in smaller PR |
'catch_exceptions' => isset($_GET['APP_CATCH_EXCEPTIONS']) && $_GET['APP_CATCH_EXCEPTIONS'] == 0 ? false : true, | ||
]); | ||
|
||
if ($app->call_exit !== true) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be tested for both exits ( call_exit=true and call_exit=false)
$l->initLayout('Centered'); | ||
// just replace layout to avoid any extended App->_construct problems | ||
// it will maintain everything as in the original app StickyGet, logger, Events | ||
$this->html = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in place of creating a new app for exception, why not destroy the render tree making $app->html = null
and reuse the actual app, all $defaults will be respected.
echo $output; | ||
if ($this->isJsonRequest()) { | ||
$this->outputResponseJSON($output); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any response from atk4 is text/html, i made 2 function to respond with JSON or HTML headers
i have also made a outputResponse with custom headers for any special needs (SEE?)
} | ||
echo $this->html->template->render(); | ||
} catch (ExitApplicationException $e) { | ||
$is_exit_exception = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrap all App->run i a try catch that catch only exit application exception and call exit app if raised
@@ -595,7 +595,7 @@ public function ajaxSubmit() | |||
ob_start(); | |||
$this->loadPOST(); | |||
$response = $this->hook('submit'); | |||
$output = ob_get_contents(); | |||
$output = ob_get_clean(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i raise exception to the upper level to be caught by the global exception handler
} else { | ||
$l->add(new self(['ui' => 'message', get_class($exception).': '.$exception->getMessage(), 'error'])); | ||
} | ||
$this->renderAll(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raise exception to upper level
we already have exception handler that format correctly the exception, if an exception happen here will broke the normal flow of the whole application.
*/ | ||
public function stickyGet($name, $newValue = null) | ||
public function stickyGet($name, $newValue = null) : ?string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just simplify this
use Psr\Http\Message\ResponseInterface; | ||
use Symfony\Component\Process\Process; | ||
|
||
abstract class BuiltInWebServerAbstract extends TestCase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add alternative base Test class to test real GET POST request using built in server
@@ -1,7 +1,7 @@ | |||
#!/bin/bash | |||
|
|||
echo "Setting up coverage logging"; | |||
mkdir coverage | |||
mkdir -p coverage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add -p to mkdir to avoid errors on call to mkdir
-p, --parents no error if existing, make parent directories as needed
|
||
public static function setUpBeforeClass() | ||
{ | ||
if (!file_exists(getcwd().'/coverage/')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to get coverage on tests run with built in server i use the same idea that we already use with selenium, include file coverage.php and collect .cov files
i removed calls to php exit function, that create many problem and not allow to include the atk in a any other framework that use PSR-7 with request -> response flow.
what i have done :
I had only one problem in : https://github.com/abbadon1334/ui/blob/18ce128a68ad1785f0d33e09f584bc1d77992de8/src/Form.php#L592
Where in Form.php we return "Direct output" as an error, and i normalized it to Exception.