lamoda / codeception-kafka

Codeception Kafka module

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Codeception Kafka Extension

THIS MODULE IS NOT PRODUCTION READY

This extension supports working with Apache Kafka.

Installation

  1. Install library

    composer require lamoda/codeception-kafka
  2. Create message serializer for your data transfer object

namespace Tests\KafkaModule;

use App\EventBus\DtoInterface;
use Lamoda\Codeception\Extension\MessageSerializer\MessageSerializerInterface;

class AcmeMessageSerializer implements MessageSerializerInterface
{
    public function serialize($dto): string
    {
        if (!$dto instanceif DtoInterface) {
            throw new \RuntimeException('This value must be an ' . DtoInterface::class);
        }

        $message = json_encode($dto->toArray());

        if (!is_string($message)) {
            throw new \RuntimeException(json_last_error(), json_last_error_msg());
        }

        return $message;
    }
}

The default message serializer is Lamoda\Codeception\Extension\MessageSerializer\ArrayMessageSerializer.

  1. Include to suite and configure
    modules:
        enabled:
            - \Lamoda\Codeception\Extension\KafkaModule
                 serializer: 'Tests\KafkaModule\AcmeMessageSerializer'
                 config:
                     metadata.broker.list: '192.168.99.100:9092'
                     group.id: 'group_for_tests'
                 topic_config:
                     offset.store.sync.interval.ms: '0'
                     auto.commit.interval.ms: '500'
                     auto.offset.reset: 'smallest'   

Development

PHP Coding Standards Fixer

make php-cs-check
make php-cs-fix

Tests

Unit

make test-unit

About

Codeception Kafka module

License:MIT License


Languages

Language:PHP 97.0%Language:Makefile 3.0%