This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Bundle
Fabien Potencier fe4d92806b feature #35893 [HttpClient][DI] Add an option to use the MockClient in functional tests (GaryPEGEOT)
This PR was squashed before being merged into the 5.2-dev branch.

Discussion
----------

[HttpClient][DI] Add an option to use the MockClient in functional tests

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        | TODO

Let's say you want to mock HTTP responses in your test or dev environment:

First, you create an invokable class responsible of generating the response:
```php
namespace App\Tests;

use Symfony\Contracts\HttpClient\ResponseInterface;

class MyAwesomeCallback
{
    public function __invoke(string $method, string $url, array $options = []): ResponseInterface
    {
        // load a fixture file or generate dynamic data
    }
}
```

Then configure it:
```yaml

# config/services_test.yaml
services:
   # ...
   App\Tests\MyAwesomeCallback: ~

# config/packages/test/framework.yaml
framework:
    http_client:
        mock_response_factory: App\Tests\MyAwesomeCallback
```

The HttpClient will now be using MockHttpClient in your functional test:
```php
$client = static::createClient();

// No live HTTP connection made
$client->request('GET', '/path-with-http-call');
```

Commits
-------

b53739c79d [HttpClient][DI] Add an option to use the MockClient in functional tests
2020-08-27 16:44:19 +02:00
..
DebugBundle [HttpKernel] Add $kernel->getBuildDir() to separate it from the cache directory 2020-08-21 08:43:34 +02:00
FrameworkBundle feature #35893 [HttpClient][DI] Add an option to use the MockClient in functional tests (GaryPEGEOT) 2020-08-27 16:44:19 +02:00
SecurityBundle Lazily load the user during the check passport event 2020-08-27 16:28:46 +02:00
TwigBundle Fix PHPUnit 8.5 deprecations. 2020-07-23 11:37:51 +02:00
WebProfilerBundle feature #37889 Toolbar toggler accessibility (Chi-teck) 2020-08-21 08:53:22 +02:00
FullStack.php [FrameworkBundle] changed some default configs from canBeEnabled to canBeDisabled 2017-01-07 14:17:04 -08:00