Download the PHP package zenstruck/messenger-test without Composer

On this page you can find all versions of the php package zenstruck/messenger-test. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package messenger-test

zenstruck/messenger-test

CI Status Code Coverage

Assertions and helpers for testing your symfony/messenger queues.

This library provides a TestTransport that, by default, intercepts any messages sent to it. You can then inspect and assert against these messages. Sent messages are serialized and unserialized as an added check.

The transport also allows for processing these queued messages.

Installation

  1. Install the library:

  2. If not added automatically by Symfony Flex, add the bundle in config/bundles.php:

  3. Update config/packages/messenger.yaml and override your transport(s) in your test environment with test://:

Transport

You can interact with the test transports in your tests by using the InteractsWithMessenger trait in your KernelTestCase/WebTestCase tests. You can assert the different steps of message processing by asserting on the queue and the different states of message processing like "acknowledged", "rejected" and so on.

Note: If you only need to know if a message has been dispatched you can make assertions on the bus itself.

Queue Assertions

Processing The Queue

NOTE: Calling process() not only processes messages on the queue but any messages created during the handling of messages (all by default or up to $number).

Other Transport Assertions and Helpers

Processing Exceptions

By default, when processing a message that fails, the TestTransport catches the exception and adds to the rejected list. You can change this behaviour:

You can enable exception throwing for your transport(s) by default in the transport dsn:

Unblock Mode

By default, messages sent to the TestTransport are intercepted and added to a queue, waiting to be processed manually. You can change this behaviour so messages are handled as they are sent:

You can disable intercepting messages for your transport(s) by default in the transport dsn:

Testing Serialization

By default, the TestTransport tests that messages can be serialized and deserialized. This behavior can be disabled with the transport dsn:

Multiple Transports

If you have multiple transports you'd like to test, change all their dsn's to test:// in your test environment:

In your tests, pass the name to the transport() method:

Support of DelayStamp

Support of DelayStamp could be enabled per transport, within its dsn:

[!NOTE] Support of delay stamp was added in version 1.8.0.

Usage of a clock

[!WARNING] Support of delay stamp needs an implementation of PSR-20 Clock.

You can, for example use Symfony's clock component:

When using Symfony's clock component, the service will be automatically configured. Otherwise, you need to configure it manually:

Example of code supporting DelayStamp

[!NOTE] This example uses symfony/clock component, but you can use any other implementation of Psr\Clock\ClockInterface.

DelayStamp and unblock mode

"delayed" messages cannot be handled by the unblocking mechanism, $transport->process() must be called after a sleep() has been made.

Enable Retries

By default, the TestTransport does not retry failed messages (your retry settings are ignored). This behavior can be disabled with the transport dsn:

[!NOTE] When using retries along with support_delay_stamp you must mock the time to sleep between retries.

Bus

In addition to transport testing you also can make assertions on the bus. You can test message handling by using the same InteractsWithMessenger trait in your KernelTestCase / WebTestCase tests. This is especially useful when you only need to test if a message has been dispatched by a specific bus but don't need to know how the handling has been made.

It allows you to use your custom transport while asserting your messages are still dispatched properly.

Single bus

Multiple buses

If you use multiple buses you can test that a specific bus has handled its own messages.

In your tests, pass the name to the bus() method:

Troubleshooting

Detached Doctrine Entities

When processing messages in your tests that interact with Doctrine entities you may notice they become detached from the object manager after processing. This is because of DoctrineClearEntityManagerWorkerSubscriber which clears the object managers after a message is processed. Currently, the only way to disable this functionality is to disable the service in your test environment:


All versions of messenger-test with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
symfony/deprecation-contracts Version ^2.2|^3.0
symfony/framework-bundle Version ^5.4.44|^6.0|^7.0
symfony/messenger Version ^5.4|^6.0|^7.0
zenstruck/assert Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package zenstruck/messenger-test contains the following files

Loading the files please wait ....