Skip to content

removal of Throwables through _sendRequest from get(), post(), patch(), put(), delete, head(), & options()#14193

Closed
travisfont wants to merge 8 commits intocakephp:masterfrom
travisfont:enhancement/integration_test_trait_exception_removal
Closed

removal of Throwables through _sendRequest from get(), post(), patch(), put(), delete, head(), & options()#14193
travisfont wants to merge 8 commits intocakephp:masterfrom
travisfont:enhancement/integration_test_trait_exception_removal

Conversation

@travisfont
Copy link
Copy Markdown

IntegrationTestTrait removed all throwables from send request methods:

  • get()
  • post()
  • patch()
  • put()
  • delet()
  • head()
  • options()

See discussion/issue at:
#14143

Comment thread src/TestSuite/IntegrationTestTrait.php Outdated
* @param string|array $url The URL to request.
*
* @return void
* @throws \PHPUnit\Framework\Error\Error|\Throwable
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arent those true if you disable error handler middleware?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like if any business logic or in the controller throws exceptions, and we disable the error catching then this would still be true, right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are still not answered here. I still think those should be kept as those can through exceptions if error handler middleware is disabled.

Comment thread src/TestSuite/IntegrationTestTrait.php Outdated
@othercorey
Copy link
Copy Markdown
Contributor

@tfont are you going to follow up on this?

@othercorey othercorey added this to the 4.0.5 milestone Mar 10, 2020
@travisfont
Copy link
Copy Markdown
Author

@tfont are you going to follow up on this?

@othercorey Yes, I can update this.

@markstory markstory modified the milestones: 4.0.5, 4.0.6 Mar 29, 2020
@markstory markstory modified the milestones: 4.0.6, 4.0.7 Apr 19, 2020
@travisfont
Copy link
Copy Markdown
Author

@othercorey @markstory
feel free to review and leave feedback!

* If that class does not exist, the built-in renderer will be used.
*
* @param \Throwable $exception Exception to handle.
* @param \Throwable|\LogicException|\Cake\Database\Exception|\PHPUnit\Framework\Error\Error $exception Exception to handle.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't \LogicException|\Cake\Database\Exception|\PHPUnit\Framework\Error\Error all extending Throwable?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Is it more ideal to remove them all and use the inheritable Throwable instead?

Copy link
Copy Markdown
Member

@dereuromark dereuromark Apr 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the point in outlining them all here, if they are subclasses of it.
Also, why removing the typehint?

}

// Simulate the global exception handler being invoked.
if ($this->_exception instanceof Throwable) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isnt this a behavior change?
They all are instance of this class afaik. Before only in the last catch block this was invoked, now in every case, right?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, previously it was:

try {
   // ...
   $this->_response = $response;
   } catch (PhpUnitError $e) {
      throw $e;
   } catch (DatabaseException $e) {
      throw $e;
   } catch (LogicException $e) {
      throw $e;
   } catch (Throwable $e) {
      $this->_exception = $e;
      // Simulate the global exception handler being invoked.
      $this->_handleError($e);
}

I've updated all throwables to be added to the exception property and then passed to the handleError() to handle the exception. Thoughts?

Comment on lines +501 to +502
} catch (\PHPUnit\Framework\Error\Error $e) {
$this->_exception = $e;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least PHPUnit exceptions should be rethrown. Normal applications shouldn't use PHPUnit classes.

However it could be widened to \PHPUnit\Framework\Exception class or \PHPUnit\Exception interface.

All PHPUnit asserts should immediately abort test, but not rendered with ExceptionRenderer. Otherwise it makes testing hard.

@dereuromark
Copy link
Copy Markdown
Member

Can you explain again please what the reason for this is?
The original issue was about removing some docblock lines, which given that they shouldn't occur in normal testing, made sense

@throws \PHPUnit\Exception

etc
But the scope of the changes now here go way beyond, and in a way that is not acceptable as is.

It would be good to have the main goal again in front of us, to be able to find a solution.

@markstory
Copy link
Copy Markdown
Member

Closing in favour of #14549 which achieves a similar result with a simpler approach.

@markstory markstory closed this May 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants