Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
34ddab52
Commit
34ddab52
authored
May 25, 2012
by
Ricard Clau
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add a test for swiftmailerServiceProvider app->finish event
parent
5d599be3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
0 deletions
+53
-0
tests/Silex/Tests/Provider/SwiftmailerServiceProviderTest.php
...s/Silex/Tests/Provider/SwiftmailerServiceProviderTest.php
+53
-0
No files found.
tests/Silex/Tests/Provider/SwiftmailerServiceProviderTest.php
View file @
34ddab52
...
@@ -14,6 +14,9 @@ namespace Silex\Tests\Provider;
...
@@ -14,6 +14,9 @@ namespace Silex\Tests\Provider;
use
Silex\Application
;
use
Silex\Application
;
use
Silex\Provider\SwiftmailerServiceProvider
;
use
Silex\Provider\SwiftmailerServiceProvider
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Response
;
class
SwiftmailerServiceProviderTest
extends
\PHPUnit_Framework_TestCase
class
SwiftmailerServiceProviderTest
extends
\PHPUnit_Framework_TestCase
{
{
public
function
setUp
()
public
function
setUp
()
...
@@ -32,4 +35,54 @@ class SwiftmailerServiceProviderTest extends \PHPUnit_Framework_TestCase
...
@@ -32,4 +35,54 @@ class SwiftmailerServiceProviderTest extends \PHPUnit_Framework_TestCase
$this
->
assertInstanceOf
(
'Swift_Mailer'
,
$app
[
'mailer'
]);
$this
->
assertInstanceOf
(
'Swift_Mailer'
,
$app
[
'mailer'
]);
}
}
public
function
testSwiftMailerSendsMailsOnFinish
()
{
$app
=
new
Application
();
$app
->
register
(
new
SwiftmailerServiceProvider
(),
array
(
'swiftmailer.class_path'
=>
__DIR__
.
'/../../../../vendor/swiftmailer/swiftmailer/lib/classes'
,
));
$app
[
'swiftmailer.transport'
]
=
$app
->
share
(
function
()
use
(
$app
)
{
return
new
\Swift_Transport_SpoolTransport
(
$app
[
'swiftmailer.transport.eventdispatcher'
],
new
\Swift_MemorySpool
());
});
$test
=
$this
;
/**
* 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
());
},
1
);
/**
* This gets executed after SwiftmailerServiceProvider $app->finish thanks to higher priority
* 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'
]));
},
-
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
);
}
}
class
SendMailsResponse
extends
Response
{
public
function
send
()
{
// do nothing
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment