Skip to content
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

Merged
merged 68 commits into from
Aug 15, 2019

Conversation

abbadon1334
Copy link
Collaborator

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 removed all "generalized" try catch, any Error or Exception not strictly related to the flow must be throw upper to the App->catchException.
  • add some throw to methods.
  • simplify methods when i see some old syntax.
  • i try to commit on every change to have comments on the work in progress.
  • PHPUnit on my PC pass all tests
  • Manual testing to be sure all works correctly

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.

@codecov
Copy link

codecov bot commented Aug 2, 2019

Codecov Report

Merging #790 into develop will increase coverage by 0.49%.
The diff coverage is 85.71%.

Impacted file tree graph

@@              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
Impacted Files Coverage Δ Complexity Δ
src/Form.php 72.6% <ø> (-3.43%) 66 <0> (-2)
src/jQuery.php 71.42% <ø> (ø) 3 <0> (ø) ⬇️
src/View.php 88.75% <100%> (+3.24%) 138 <6> (-4) ⬇️
src/App.php 80% <62.5%> (+8.4%) 117 <3> (ø) ⬇️
src/TableColumn/Status.php 82.85% <0%> (+2.85%) 12% <0%> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ac79ff6...1324961. Read the comment docs.

@codecov
Copy link

codecov bot commented Aug 2, 2019

Codecov Report

Merging #790 into develop will increase coverage by 5.25%.
The diff coverage is 82.5%.

Impacted file tree graph

@@              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
Impacted Files Coverage Δ Complexity Δ
src/jQuery.php 71.42% <ø> (ø) 3 <0> (ø) ⬇️
src/Form.php 74.65% <ø> (-3.43%) 66 <0> (-2)
src/View.php 90% <100%> (+4.49%) 138 <6> (-4) ⬇️
src/jsSSE.php 94.82% <75%> (+18.04%) 23 <0> (ø) ⬇️
src/App.php 82.81% <79.68%> (+11.22%) 131 <11> (+14) ⬆️
src/Menu.php 94.73% <0%> (-5.27%) 25% <0%> (ø)
src/TableColumn/Multiformat.php 91.89% <0%> (-2.71%) 12% <0%> (ø)
src/Wizard.php 84.28% <0%> (-1.43%) 23% <0%> (ø)
src/Table.php 84.61% <0%> (ø) 110% <0%> (ø) ⬇️
... and 21 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 56e6843...480301d. Read the comment docs.

@abbadon1334 abbadon1334 requested review from romaninsh, ibelar, DarkSide666 and gowrav-vishwakarma and removed request for romaninsh August 2, 2019 17:15
src/App.php Outdated
// catch Exit Exception and return
if ($exception instanceof ExitApplicationException) {
return true;
}
Copy link
Member

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.

@abbadon1334
Copy link
Collaborator Author

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) {
Copy link
Collaborator Author

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;
Copy link
Collaborator Author

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 {
Copy link
Collaborator Author

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;
Copy link
Collaborator Author

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();
Copy link
Collaborator Author

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();
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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/')) {
Copy link
Collaborator Author

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

@abbadon1334 abbadon1334 added the hangout agenda 🔈 Will discuss on next hangout label Aug 15, 2019
@romaninsh romaninsh changed the title Remove calls to exit functions Remove calls to exit functions and cleanups Aug 15, 2019
@romaninsh romaninsh merged commit 04739e7 into atk4:develop Aug 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hangout agenda 🔈 Will discuss on next hangout
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants