Importing Routes from a Controller

This is how you import routes from a specific controller (only works if you used annotations):

This is very useful if you have multiple controllers in single bundle but you can’t import the whole Controller directory at once because some routes have to be treated in a special way, e.g. you want a different prefix for every controller.

For reference, this is the original documentation of that feature.

PHPUnit: contains vs. stringContains

Note to myself: If I ever see that error again when running PHPUnit tests

please remember that $this->contains() is not the same as $this->stringContains(). The first one is a constraint for arrays, the second one is for strings.

SonataNotificationBundle does not consume messages

Today I was playing around with SonataNotificationBundle. I simply followed the installation instructions, but I encountered some problems.

First problem: You have to manually add SonataEasyExtendsBundle as a dependency. For some reason it is not automatically added by Composer. I guess they’ve just forgot it in the composer.json, so maybe this problem is already fixed by the time you read this.

After the bundle was working I’ve implemented a new component to dispatch some messages. Everything was working fine, I could even see the message in the database (used Doctrine for the message queue). To complete that test scenario I implemented a consumer for my message type and registered it as a tagged service. I started the consumer job as described in the documentation …

… but nothing happend!

Second problem: The messages did not process. Some debugging in the code showed me that it only fetched messages with type default from the database. This was strange, because the console told me that my message consumer is registered and there was no default type at all. I did some research on this problem and found a very useful post of someone having the exact same problem. There was as a working configuration in the thread so a gave it a try – and it worked! The trick was to configure at least one queue. Your configuration should look similar to this:

The catchall is just a name for the queue, it can be anything. It’s more important to make it the default queue, which is done with default: true.