lundi 30 mars 2015

Disable Symfony2 SwiftMailer spooling for unit tests

I need to completely disable the SwiftMailer spooling functionality for some of my unit tests.


I have methods that implement application-specific functionality on top of SwiftMailer and I have unit tests for them.


Unfortunately, it appears that SwiftMailer's listener that sends mail spooled to memory at the end of a request is not run during unit testing.


This means that messages spooled to memory are lost. If I spool to a file then I have to manually run the console/swiftmailer:spool:send command. Yes. I know that I could run that command from within my test, but that really doesn't seem very clean and is subject to failure if the syntax of the send command is ever changed.


I have tried removing the swiftmailer.spool configuration from config.yml and specifying it only in config_dev.yml and config_prod.yml, leaving it out of config_test.yml. This has had no effect.


In fact, I have been utterly unable to get rid of the default spool configuration.


I have been using the console config:debug swiftmailer --env=[whetever] to test after each change and the spool configuration is always there with type:memory unless I explicitly set the type to file.


Suggestions? Many thanks.


Aucun commentaire:

Enregistrer un commentaire