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
f43dd5a5
Commit
f43dd5a5
authored
May 30, 2012
by
Igor Wiedler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix SwiftmailerServiceProviderTest (stub the spool)
parent
1798d08f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
27 deletions
+59
-27
phpunit.xml.dist
phpunit.xml.dist
+1
-1
tests/Silex/Tests/Provider/SpoolStub.php
tests/Silex/Tests/Provider/SpoolStub.php
+45
-0
tests/Silex/Tests/Provider/SwiftmailerServiceProviderTest.php
...s/Silex/Tests/Provider/SwiftmailerServiceProviderTest.php
+9
-26
tests/bootstrap.php
tests/bootstrap.php
+4
-0
No files found.
phpunit.xml.dist
View file @
f43dd5a5
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
processIsolation=
"false"
processIsolation=
"false"
stopOnFailure=
"false"
stopOnFailure=
"false"
syntaxCheck=
"false"
syntaxCheck=
"false"
bootstrap=
"
vendor/autoload
.php"
bootstrap=
"
tests/bootstrap
.php"
>
>
<testsuites>
<testsuites>
<testsuite
name=
"Silex Test Suite"
>
<testsuite
name=
"Silex Test Suite"
>
...
...
tests/Silex/Tests/Provider/SpoolStub.php
0 → 100644
View file @
f43dd5a5
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace
Silex\Tests\Provider
;
class
SpoolStub
implements
\Swift_Spool
{
private
$messages
=
array
();
public
function
getMessages
()
{
return
$this
->
messages
;
}
public
function
start
()
{
}
public
function
stop
()
{
}
public
function
isStarted
()
{
return
count
(
$this
->
messages
)
>
0
;
}
public
function
queueMessage
(
\Swift_Mime_Message
$message
)
{
$this
->
messages
[]
=
$message
;
}
public
function
flushQueue
(
\Swift_Transport
$transport
,
&
$failedRecipients
=
null
)
{
$this
->
messages
=
array
();
}
}
tests/Silex/Tests/Provider/SwiftmailerServiceProviderTest.php
View file @
f43dd5a5
...
@@ -29,6 +29,7 @@ class SwiftmailerServiceProviderTest extends \PHPUnit_Framework_TestCase
...
@@ -29,6 +29,7 @@ class SwiftmailerServiceProviderTest extends \PHPUnit_Framework_TestCase
public
function
testSwiftMailerServiceIsSwiftMailer
()
public
function
testSwiftMailerServiceIsSwiftMailer
()
{
{
$app
=
new
Application
();
$app
=
new
Application
();
$app
->
register
(
new
SwiftmailerServiceProvider
(),
array
(
$app
->
register
(
new
SwiftmailerServiceProvider
(),
array
(
'swiftmailer.class_path'
=>
__DIR__
.
'/../../../../vendor/swiftmailer/swiftmailer/lib/classes'
,
'swiftmailer.class_path'
=>
__DIR__
.
'/../../../../vendor/swiftmailer/swiftmailer/lib/classes'
,
));
));
...
@@ -39,43 +40,25 @@ class SwiftmailerServiceProviderTest extends \PHPUnit_Framework_TestCase
...
@@ -39,43 +40,25 @@ class SwiftmailerServiceProviderTest extends \PHPUnit_Framework_TestCase
public
function
testSwiftMailerSendsMailsOnFinish
()
public
function
testSwiftMailerSendsMailsOnFinish
()
{
{
$app
=
new
Application
();
$app
=
new
Application
();
$app
->
register
(
new
SwiftmailerServiceProvider
(),
array
(
$app
->
register
(
new
SwiftmailerServiceProvider
(),
array
(
'swiftmailer.class_path'
=>
__DIR__
.
'/../../../../vendor/swiftmailer/swiftmailer/lib/classes'
,
'swiftmailer.class_path'
=>
__DIR__
.
'/../../../../vendor/swiftmailer/swiftmailer/lib/classes'
,
));
));
$app
[
'swiftmailer.transport'
]
=
$app
->
share
(
function
()
use
(
$app
)
{
$spool
=
new
SpoolStub
();
return
new
\Swift_Transport_SpoolTransport
(
$app
[
'swiftmailer.transport.eventdispatcher'
],
new
\Swift_MemorySpool
());
$app
[
'swiftmailer.spooltransport'
]
=
new
\Swift_SpoolTransport
(
$spool
);
});
$app
->
get
(
'/'
,
function
()
use
(
$app
)
{
$app
->
get
(
'/'
,
function
()
use
(
$app
)
{
$app
[
'mailer'
]
->
send
(
\Swift_Message
::
newInstance
());
$app
[
'mailer'
]
->
send
(
\Swift_Message
::
newInstance
());
});
});
/**
$this
->
assertCount
(
0
,
$spool
->
getMessages
());
* Checks spool is empty before process
*/
$this
->
assertEquals
(
0
,
$app
[
'swiftmailer.spooltransport'
]
->
getSpool
()
->
flushQueue
(
$app
[
'swiftmailer.transport'
]));
$request
=
Request
::
create
(
'/'
);
$request
=
Request
::
create
(
'/'
);
$app
->
handle
(
$request
);
$response
=
$app
->
handle
(
$request
);
/**
$this
->
assertCount
(
1
,
$spool
->
getMessages
());
* Checks spool has the message that is sent in controller and regenerates it
*/
$this
->
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'
));
$this
->
assertEquals
(
0
,
$app
[
'swiftmailer.spooltransport'
]
->
getSpool
()
->
flushQueue
(
$app
[
'swiftmailer.transport'
]));
}
}
class
SendMailsResponse
extends
Response
$app
->
terminate
(
$request
,
$response
);
{
$this
->
assertCount
(
0
,
$spool
->
getMessages
());
public
function
send
()
{
// do nothing
}
}
}
}
tests/bootstrap.php
0 → 100644
View file @
f43dd5a5
<?php
$loader
=
require
__DIR__
.
'/../vendor/autoload.php'
;
$loader
->
add
(
'Silex\Tests'
,
__DIR__
);
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