This module allows you to write functional tests for gRPC services using Codeception. It provides tools for sending gRPC requests and asserting responses, which helps ensure your gRPC services behave as expected.
- Send gRPC requests using any gRPC service client.
- Validate responses using familiar Codeception assertions.
- Supports fixtures and integration with your DI container (e.g. Symfony).
composer require --dev mercer_morning/codeception-grpc-module
Add the module to your suite configuration file (e.g., tests/functional.suite.yml
):
modules:
enabled:
- Codeception\Module\Grpc
Here’s an example of how to use the module in a test:
<?php
use App\Grpc\CalendarService;
use App\Tests\Fixtures\CalendarFixture;
use Codeception\Example;
use YourNamespace\Proto\GetEmployeesWithWorkingDaysInRangeRequest;
use YourNamespace\Proto\GetEmployeesWithWorkingDaysInRangeResponse;
$request = new GetEmployeesWithWorkingDaysInRangeRequest();
$request->setBranchUuid('d43040e0-96ea-4d9f-9fc9-020ee933536b');
/** @var GetEmployeesWithWorkingDaysInRangeResponse $res */
$res = $I->doGrpcRequest(
$I->grabService(CalendarService::class),
'GetEmployeesWithWorkingDaysInRange',
$request
);
$uuids = [];
foreach ($res->getUuids() as $uuid) {
$uuids[] = $uuid;
}
$I->assertEquals([
"dbf4de2e-c342-4c52-b95d-ecd8f7a492f1",
"dbf4de2e-c342-4c52-b95d-ecd8f7a492f2"
], $uuids);
Sends a gRPC request to the specified service using the given method and request object. Returns the response object.