otezvikentiy/codeception-symfony-http-client-mock

Codeception Module for Mocking HttpClient in Symfony

Maintainers

👁 OtezVikentiy

Package info

github.com/OtezVikentiy/codeception-symfony-http-client-mock

pkg:composer/otezvikentiy/codeception-symfony-http-client-mock

Statistics

Installs: 14

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.3.0 2025-08-13 11:10 UTC

Requires

Requires (Dev)

None

Suggests

Provides

None

Conflicts

None

Replaces

None

MIT 7e2efc310b1209c849a29173021e7bd20ca015a6

symfonymockcodeceptiontestshttp-client

This package is auto-updated.

Last update: 2026-06-13 12:49:47 UTC


README

Mock module for Symfony + Codeception + HttpClient

Installation

composer require otezvikentiy/codeception-symfony-http-client-mock --dev

Configuration

  1. Add to your Functional.suite.yaml
modules:
 enabled:
 - OtezVikentiy\CodeceptionHttpMock\HttpMockModule
 config:
 OtezVikentiy\CodeceptionHttpMock\HttpMockModule:
 http_client_service_name: 'http_client'
  1. 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']
  1. 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);
 }