Codeception

Set up

Install

composer require --dev codeception/codeception mbtbundle/codeception-module

Configure suite

actor: FunctionalTester
modules:
enabled:
- Symfony:
app_path: 'src'
environment: 'test'
- Doctrine2:
depends: Symfony
cleanup: true
- Asserts
- \MbtBundle\Codeception\Module\MbtBundle:
depends:
- Doctrine2
- Symfony

Update Messenger's configuration

framework:
messenger:
# Uncomment this (and the failed transport below) to send failed messages to this transport for later handling.
failure_transport: failed
transports:
# https://symfony.com/doc/current/messenger.html#transport-configuration
async: '%env(MESSENGER_TRANSPORT_DSN)%'
failed: 'doctrine://default?queue_name=failed'
# sync: 'sync://'
routing:
# Route your messages to the transports
'*': async

Prepare database and helpers

php bin/console doctrine:database:create
php bin/console doctrine:schema:create
php bin/console messenger:setup-transports
php vendor/bin/codecept build

Test

Generate workflow

php bin/console make:workflow workflow_name
php bin/consolde cache:clear

Generate subject

php bin/console make:subject workflow_name ClassName

Generate cest

php vendor/bin/codecept generate:cest functional Example

Update cest

<?php
namespace App\Tests;
use App\Tests\FunctionalTester;
class ExampleCest
{
/**
* @param FunctionalTester $I
*/
public function testAnyWorkflow(FunctionalTester $I)
{
$task = $I->haveTask('Example task', 'workflow_name', 'random', 'loop', [], false, [
'max-steps' => 50,
]);
$I->consumeMessages('async');
$bugs = $I->grabBugsFromTask($task);
$I->assertCount(0, $bugs);
}
}

Run cest

php vendor/bin/codecept run functional ExampleCest.php

Demo

Please check out our demo project for integrating MBT Bundle to Codeception in Symfony here