PHPackages                             drupsys/codeception-use-cases-module - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. drupsys/codeception-use-cases-module

ActiveLibrary[Testing &amp; Quality](/categories/testing)

drupsys/codeception-use-cases-module
====================================

Codeception module to support use case based tests

2.0.7(2y ago)01.1kMITPHPPHP ^7.4|^8.0

Since Jan 14Pushed 2y ago1 watchersCompare

[ Source](https://github.com/drupsys/codeception-use-cases-module)[ Packagist](https://packagist.org/packages/drupsys/codeception-use-cases-module)[ RSS](/packages/drupsys-codeception-use-cases-module/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (8)Versions (39)Used By (0)

CODECEPTION USE CASES MODULE
============================

[](#codeception-use-cases-module)

> A codeception module for use case based tests, this module aims to promote writing of real unit tests as described in the "TDD, Where Did It All Go Wrong" talk by Ian Cooper.

Relevant references:

- [TDD, Where Did It All Go Wrong](https://www.youtube.com/watch?v=EZ05e7EMOLM&ab_channel=DevTernityConference)
- [How to write use case tests](?)

Setup
-----

[](#setup)

Assuming you have `tests/usecase.suite.yaml` file, enable this module like this

```
actor: UseCaseTester
modules:
    enabled:
        - \Helper\UseCase
        - \MVF\Codeception\UseCases\Module:
            providers:
                mysql: App\Providers\UseCases\EloquentProvider
                redis: App\Providers\UseCases\RedisProvider
        - Asserts
```

Specifically note `\MVF\Codeception\UseCases\Module` added to the list of modules. This module has required config to function properly, the list of `providers` must be defined.

### MySql Provider

[](#mysql-provider)

This is an object that must implement `MVF\Codeception\UseCases\Contracts\MySqlInterface` and it should look something like this.

```
namespace App\Providers\UseCases;

use Illuminate\Database\Connection;
use MVF\Codeception\UseCases\Contracts\MySqlInterface;

class EloquentProvider implements MySqlInterface
{
    public function __construct() {}

    public function getMySql(): Connection
    {
        return ...; // return writable eloquent connection, this connection should be privileged, able to write, read, delete and truncate tables.
    }
}
```

### Redis Provider

[](#redis-provider)

This is an object that must implement `MVF\Codeception\UseCases\Contracts\RedisInterface` and it should look something like this.

```
namespace App\Providers\UseCases;

use MVF\Codeception\UseCases\Contracts\RedisInterface;
use Redis;

class RedisProvider implements RedisInterface
{
    public function __construct() {}

    public function getRedis(): Redis
    {
        return ...; // return redis object
    }
}
```

### Services

[](#services)

Your docker compose file should have the following services

```
  -test-mysql:
    container_name: -test-mysql
    networks: [mvf_shared]
    image: mysql:5.7.26
    environment:
      MYSQL_ROOT_PASSWORD: 12345
      MYSQL_DATABASE: ...
      MYSQL_USER: ...
      MYSQL_PASSWORD: ...
    healthcheck:
      test: mysqladmin -uroot -p12345 ping -h localhost
      interval: 2s
      timeout: 20s
      retries: 10
    volumes:
      - mysql-test:/var/lib/mysql:cached
    command: --server-id=1 --log-bin=test.log

  -binlog-parser:
    build:
      context: build/binlog-parser
    container_name: -binlog-parser
    networks: [mvf_shared]
    restart: always

  -redis:
    container_name: -redis
    networks: [mvf_shared]
    image: redis:6-alpine

  networks:
    mvf_shared:
      external: true
```

#### &lt;app&gt;-test-mysql

[](#app-test-mysql)

MySql service should have `MYSQL_ROOT_PASSWORD` set to `12345`, have command with the following flags `--server-id=1 --log-bin=test.log`, if you already define some command just append these flags to your existing command, and should use `[mvf_shared]` network.

#### &lt;app&gt;-binlog-parser

[](#app-binlog-parser)

Maxwell service should use `[mvf_shared]` network as well and it should be built in `build/binlog-parser` folder. this folder should have `Dockerfile` and `config.properties` files.

The content of your `Dockerfile` is below, check `maxwell` and `alpine` versions to see if there is a newer version available.

```
FROM openjdk:18-ea-11-jdk-alpine3.15

RUN apk add --no-cache --update bash shadow
RUN /usr/sbin/groupadd -g 1000 www
RUN /usr/sbin/useradd -s /bin/sh -g 1000 -u 1000 www

ENV MAXWELL_VERSION=1.35.5

COPY --from=zendesk/maxwell:v1.35.5 /app /app

WORKDIR /app

RUN chown 1000:1000 /app && echo "$MAXWELL_VERSION" > /REVISION

USER 1000

COPY config.properties ./config.properties

CMD [ "/bin/bash", "-c", "bin/maxwell", "--config=/app/config.properties" ]
```

The content of your `config.properties` is below.

```
log_level=info

# mysql source config
host=-test-mysql
user=root
password=12345

# redis target config
producer=redis
redis_key=maxwell
redis_type=xadd
redis_host=-redis
redis_port=6379
```

Most of this config should be self-explanatory the only thing to elaborate is `redis_key` this is where maxwell will store all the bin log data, by default this key is set to `maxwell` but if you are already using this key in your application then you need to change the value of it.

If you change your `redis_key` value to `testing` then you must also provide additional config in your test suite. Assuming you have `tests/usecase.suite.yaml` then new `redis_key` must also be defined there like this.

```
actor: UseCaseTester
modules:
    enabled:
        - \MVF\Codeception\UseCases\Module:
            providers: ...
            redis_key: testing #
