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 ...@@ -49,33 +49,28 @@ class SwiftmailerServiceProviderTest extends \PHPUnit_Framework_TestCase
$test = $this; $test = $this;
/** $app->get('/', function() use ($app) {
* This gets executed before SwiftmailerServiceProvider $app->finish thanks to higher priority
* flushQueue should return 1 if spool has not been flushed
*/
$app->finish(function() use ($app, $test) {
$test->assertEquals(1, $app['swiftmailer.spooltransport']->getSpool()->flushQueue($app['swiftmailer.transport']));
/**
* We add a new message that should be flushed with $app->finish()
*/
$app['mailer']->send(\Swift_Message::newInstance()); $app['mailer']->send(\Swift_Message::newInstance());
}, 1); });
/** /**
* This gets executed after SwiftmailerServiceProvider $app->finish thanks to higher priority * Checks spool is empty before process
* flushQueue should return 0 even having added a message in method above
*/ */
$app->finish(function() use ($app, $test) { $test->assertEquals(0, $app['swiftmailer.spooltransport']->getSpool()->flushQueue($app['swiftmailer.transport']));
$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('/'); $request = Request::create('/');
$app->run($request); $app->handle($request);
/**
* 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());
/**
* Terminates app and checks that spool is empty
*/
$app->terminate($request, new SendMailsResponse('should send e-mails'));
$test->assertEquals(0, $app['swiftmailer.spooltransport']->getSpool()->flushQueue($app['swiftmailer.transport']));
} }
} }
......
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