Commit f1edad0c authored by Ricard Clau's avatar Ricard Clau

following @igorw approach

parent a238971e
......@@ -49,33 +49,28 @@ class SwiftmailerServiceProviderTest extends \PHPUnit_Framework_TestCase
$test = $this;
$app->get('/', function() use ($app) {
$app['mailer']->send(\Swift_Message::newInstance());
});
/**
* This gets executed before SwiftmailerServiceProvider $app->finish thanks to higher priority
* flushQueue should return 1 if spool has not been flushed
* Checks spool is empty before process
*/
$app->finish(function() use ($app, $test) {
$test->assertEquals(1, $app['swiftmailer.spooltransport']->getSpool()->flushQueue($app['swiftmailer.transport']));
$test->assertEquals(0, $app['swiftmailer.spooltransport']->getSpool()->flushQueue($app['swiftmailer.transport']));
$request = Request::create('/');
$app->handle($request);
/**
* We add a new message that should be flushed with $app->finish()
* Checks spool has the message that is sent in controller and regenerates it
*/
$test->assertEquals(1, $app['swiftmailer.spooltransport']->getSpool()->flushQueue($app['swiftmailer.transport']));
$app['mailer']->send(\Swift_Message::newInstance());
}, 1);
/**
* This gets executed after SwiftmailerServiceProvider $app->finish thanks to higher priority
* flushQueue should return 0 even having added a message in method above
* Terminates app and checks that spool is empty
*/
$app->finish(function() use ($app, $test) {
$app->terminate($request, new SendMailsResponse('should send e-mails'));
$test->assertEquals(0, $app['swiftmailer.spooltransport']->getSpool()->flushQueue($app['swiftmailer.transport']));
}, -1);
$app->get('/', function() use ($app) {
$app['mailer']->send(\Swift_Message::newInstance());
return new SendMailsResponse('should send e-mails');
});
$request = Request::create('/');
$app->run($request);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment