For the complete documentation index, see llms.txt. This page is also available as Markdown.

Testing

Testing Ecotone messaging in Tempest applications

Messaging behavior — including asynchronous, delayed and failing flows — is testable in-process with Ecotone Lite, without booting Tempest, a database or a broker. Tests run in milliseconds. Every pattern on this page runs in the live demo application test suite.

Test Mode and the Production Cache

The Tempest application skeleton sets ENVIRONMENT=testing in phpunit.xml — keep it. Ecotone reads the environment from APP_ENV or Tempest's ENVIRONMENT variable, and outside of prod/production it uses per-configuration caching, so your test runs never reuse the application's production cache.

To use MessagingTestSupport against a booted Tempest application, enable test mode in ecotone.config.php:

return new EcotoneConfig(
    test: true,
);

Flow Testing without Tempest

EcotoneLite::bootstrapFlowTesting runs your real handlers with in-memory infrastructure. Tempest services your handlers inject (like Mailer) are provided as stubs:

$mailer = new class implements Mailer {
    public array $subjects = [];

    public function send(Email $email): void
    {
        $this->subjects[] = $email instanceof GenericEmail ? (string) $email->subject : '';
    }
};

$ecotone = EcotoneLite::bootstrapFlowTesting(
    classesToResolve: [OrderConfirmationWorkflow::class, EnrichingStub::class],
    containerOrAvailableServices: [
        new OrderConfirmationWorkflow(),
        new EnrichingStub(),
        Mailer::class => $mailer,
    ],
    enableAsynchronousProcessing: [
        SimpleMessageChannelBuilder::createQueueChannel('notifications', delayable: true),
    ],
);

Pipeline steps are substitutable the same way services are: the production enricher looks account details up in the database, so the flow test registers a stub step instead — a plain class with the same input and output channels returning canned headers. You swap one step of the flow, not the flow itself.

Testing Delayed Messages with Time Travel

There is no need to sleep through real delays — release the channel's awaiting messages as if time had passed:

Testing the Failure Path

Retries, dead-letter parking and failure isolation are ordinary flow tests. Configure the error handling the same shape as production, with an in-memory parking channel:

Each releaseAwaitingMessagesAndRunConsumer call releases the next scheduled retry. "The queue retried, parked the message, and did not block the others" becomes an assertion instead of something you can only observe on staging infrastructure.

Integration Tests that Boot Tempest

When a test boots a real Tempest kernel, clear Ecotone's static state before the kernel boots — discovery may compile the messaging system during boot, and clearing afterwards leaves a container without its registered gateways:

Last updated

Was this helpful?