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/FrameworkBundle
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
..
CacheWarmer Make AbstractPhpFileCacheWarmer public 2020-08-26 09:58:02 +02:00
Command [HttpKernel] Add $kernel->getBuildDir() to separate it from the cache directory 2020-08-21 08:43:34 +02:00
Console Merge branch '5.0' 2020-04-13 12:14:44 +02:00
Controller Merge branch '5.1' 2020-08-18 13:41:45 +02:00
DataCollector [FrameworkBundle] Allow to leverage autoconfiguration for DataCollectors with template 2020-08-12 20:58:59 +02:00
DependencyInjection feature #35893 [HttpClient][DI] Add an option to use the MockClient in functional tests (GaryPEGEOT) 2020-08-27 16:44:19 +02:00
EventListener Fix quotes in exception messages 2020-03-16 12:24:17 +01:00
HttpCache [FrameworkBundle] allow enabling the HTTP cache using semantic configuration 2020-06-20 14:01:26 +02:00
Kernel Merge branch '5.1' 2020-06-18 21:55:03 +02:00
Resources feature #35893 [HttpClient][DI] Add an option to use the MockClient in functional tests (GaryPEGEOT) 2020-08-27 16:44:19 +02:00
Routing Revert "feature #30501 [FrameworkBundle][Routing] added Configurators to handle template and redirect controllers (HeahDude)" 2020-04-24 12:08:40 +02:00
Secrets Merge branch '5.0' 2020-05-16 11:12:54 +02:00
Test properly choose the best mailer message logger listener 2020-08-21 11:20:36 +02:00
Tests [HttpClient][DI] Add an option to use the MockClient in functional tests 2020-08-27 16:44:13 +02:00
Translation [HttpKernel] allow cache warmers to add to the list of preloaded classes and files 2020-04-04 11:52:45 +02:00
.gitattributes add missing gitattributes for phpunit-bridge 2020-03-27 17:54:36 +01:00
.gitignore
CHANGELOG.md Add cache.adapter.redis_tag_aware to use RedisCacheAwareAdapter 2020-08-13 10:31:22 +02:00
composer.json Fix Composer constraint 2020-08-23 12:05:10 +02:00
FrameworkBundle.php [FrameworkBundle] allow configuring trusted proxies using semantic configuration 2020-06-22 14:34:19 +02:00
KernelBrowser.php getContainer cannot return null anymore 2020-07-29 00:26:06 +02:00
LICENSE Update year in license files 2020-01-01 12:03:25 +01:00
phpunit.xml.dist Merge branch '2.8' into 3.4 2018-11-11 20:48:54 +01:00
README.md add readme files where missing 2016-03-07 11:36:15 +01:00