otezvikentiy / codeception-symfony-http-client-mock
Codeception Module for Mocking HttpClient in Symfony
1.0.0
2025-04-25 21:16 UTC
Requires
- php: ^8.1
- codeception/codeception: ^5.0
- symfony/http-client: ^6.3|^7.0
Suggests
- codeception/module-symfony: For Symfony module
- symfony/framework-bundle: For Symfony integration
README
Mock module for Symfony + Codeception + HttpClient
Installation
composer require otezvikentiy/codeception-symfony-http-client-mock --dev
Configuration
- Add to your Functional.suite.yaml
modules: enabled: - OtezVikentiy\CodeceptionHttpMock\HttpMockModule config: OtezVikentiy\CodeceptionHttpMock\HttpMockModule: http_client_service_name: 'http_client'
- Configure your Symfony services.yaml as follows
when@test: services: _defaults: public: true # turn off project factory # replace this path with the path to your factory App\Infrastructure\HttpClient\HttpClientFactory: class: stdClass # replace the client with mock http_client: class: OtezVikentiy\CodeceptionHttpMock\HttpClient\HttpClientMock factory: ['OtezVikentiy\CodeceptionHttpMock\HttpClient\HttpClientMock', 'getInstance']
- Usage in tests
final public function someTest(FunctionalTester $I): void { $I->expectHttpRequest('DELETE', '/example/v1/orders') ->withBody(json_encode([ 'id' => '01f5cfeb-007e-11e5-82bf-9c8e99f9e058', ])) ->respondWith(status: 200, body: json_encode([ 'Result' => 'Ok', ], JSON_UNESCAPED_UNICODE)); $I->sendPost('/api/v3', '{"field": "value"}'; $I->seeResponseCodeIs(200); }