Skip to content

Commit

Permalink
feature #22890 [HttpKernel] Add ability to configure catching excepti…
Browse files Browse the repository at this point in the history
…ons for Client (kbond)

This PR was merged into the 3.4 branch.

Discussion
----------

[HttpKernel] Add ability to configure catching exceptions for Client

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | todo

Debugging exceptions in functional tests is difficult as you need to look at the logs to see which exception was thrown. Disabling catching of exceptions in the client would allow the exception to bubble up to phpunit  and make it easier to see what exception was thrown.

Commits
-------

4812e60 add ability to configure catching exceptions
  • Loading branch information
ogizanagi committed Sep 26, 2017
2 parents 07f7973 + 4812e60 commit ec8edee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Symfony/Component/HttpKernel/CHANGELOG.md
Expand Up @@ -11,6 +11,7 @@ CHANGELOG
* added `AddCacheClearerPass`
* added `AddCacheWarmerPass`
* deprecated `EnvParametersResource`
* added `Symfony\Component\HttpKernel\Client::catchExceptions()`

3.3.0
-----
Expand Down
13 changes: 12 additions & 1 deletion src/Symfony/Component/HttpKernel/Client.php
Expand Up @@ -31,6 +31,7 @@
class Client extends BaseClient
{
protected $kernel;
private $catchExceptions = true;

/**
* Constructor.
Expand All @@ -49,6 +50,16 @@ public function __construct(HttpKernelInterface $kernel, array $server = array()
parent::__construct($server, $history, $cookieJar);
}

/**
* Sets whether to catch exceptions when the kernel is handling a request.
*
* @param bool $catchExceptions Whether to catch exceptions
*/
public function catchExceptions($catchExceptions)
{
$this->catchExceptions = $catchExceptions;
}

/**
* Makes a request.
*
Expand All @@ -58,7 +69,7 @@ public function __construct(HttpKernelInterface $kernel, array $server = array()
*/
protected function doRequest($request)
{
$response = $this->kernel->handle($request);
$response = $this->kernel->handle($request, HttpKernelInterface::MASTER_REQUEST, $this->catchExceptions);

if ($this->kernel instanceof TerminableInterface) {
$this->kernel->terminate($request, $response);
Expand Down

0 comments on commit ec8edee

Please sign in to comment.