Skip to content

Commit 71c43bc

Browse files
committed
Unit tests 3.
1 parent 58a78a6 commit 71c43bc

File tree

4 files changed

+56
-39
lines changed

4 files changed

+56
-39
lines changed

src/config.php.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ $config = [
2323
'port' => 25,
2424
'username' => 'username',
2525
'password' => 'ChangeMeSeymourChangeMe',
26-
'security' => 'ssl'
26+
'security' => null
2727
],
2828
],
2929
'twitter' => [

src/services/BaseEmailService.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@ abstract class BaseEmailService
4040
*/
4141
public function __construct(array $config, array $recipients)
4242
{
43-
if(!defined('UNIT_TEST')) {
44-
if (!isset($config['email']['smtp'])) {
45-
throw new Exception("SMTP Server not properly set up.");
46-
}
43+
if (!isset($config['email']['smtp'])) {
44+
throw new Exception("SMTP Server not properly set up.");
45+
}
4746

4847
$transport = Swift_SmtpTransport::newInstance(
4948
$config['email']['smtp']['host'],
@@ -55,9 +54,7 @@ public function __construct(array $config, array $recipients)
5554
->setUsername($config['email']['smtp']['username'])
5655
->setPassword($config['email']['smtp']['password'])
5756
;
58-
} else {
59-
$transport = Swift_SmtpTransport::newInstance();
60-
}
57+
6158

6259
$this->mailer = Swift_Mailer::newInstance($transport);
6360
$this->message = Swift_Message::newInstance();

tests/controllers/TalksControllerTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ public function setUp()
1919
$this->config = [
2020
'email' => [
2121
'from' => '[email protected]',
22+
'smtp' => [
23+
'host' => 'localhost',
24+
'port' => 25,
25+
'username' => 'username',
26+
'password' => 'ChangeMeSeymourChangeMe',
27+
'security' => null
28+
],
2229
],
2330
'website_url' => 'http://example.com',
2431
];

tests/inc/TalkCommentEmailServiceTest.php

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,38 @@
22

33
namespace JoindinTest\Inc;
44

5-
use \TalkModel;
5+
use TalkModel;
66

7-
require_once __DIR__ . '/../../src/services/TalkCommentEmailService.php';
7+
require_once __DIR__.'/../../src/services/TalkCommentEmailService.php';
88

99
class TalkCommentEmailServiceTest extends \PHPUnit_Framework_Testcase
1010
{
1111

12+
protected $config = [
13+
'email' => [
14+
"from" => "[email protected]",
15+
'smtp' => [
16+
'host' => 'localhost',
17+
'port' => 25,
18+
'username' => 'username',
19+
'password' => 'ChangeMeSeymourChangeMe',
20+
'security' => null,
21+
],
22+
],
23+
];
24+
1225
/**
1326
* Check that we can create the service
1427
*
1528
* @test
1629
*/
1730
public function createService()
1831
{
19-
$config = array("email" => array("from" => "[email protected]"));
20-
$recipients = array("[email protected]");
21-
$talk = new TalkModel(array("talk_title" => "sample talk"));
22-
$comment = array("comments" => array(array("comment" => "test comment", "rating" => 3)));
32+
$recipients = ["[email protected]"];
33+
$talk = new TalkModel(["talk_title" => "sample talk"]);
34+
$comment = ["comments" => [["comment" => "test comment", "rating" => 3]]];
2335

24-
$service = new \TalkCommentEmailService($config, $recipients, $talk, $comment);
36+
$service = new \TalkCommentEmailService($this->config, $recipients, $talk, $comment);
2537
$this->assertInstanceOf('TalkCommentEmailService', $service);
2638
}
2739

@@ -32,13 +44,14 @@ public function createService()
3244
*/
3345
public function createServiceWithEmailRedirect()
3446
{
35-
$config = array("email" => array("from" => "[email protected]", "forward_all_to" => "[email protected]"));
36-
$recipients = array("[email protected]");
37-
$talk = new TalkModel(array("talk_title" => "sample talk"));
38-
$comment = array("comments" => array(array("comment" => "test comment", "rating" => 3)));
47+
$config = $this->config;
48+
$config["email"]["forward_all_to"] = "[email protected]";
49+
$recipients = ["[email protected]"];
50+
$talk = new TalkModel(["talk_title" => "sample talk"]);
51+
$comment = ["comments" => [["comment" => "test comment", "rating" => 3]]];
3952

4053
$service = new \TalkCommentEmailService($config, $recipients, $talk, $comment);
41-
$this->assertEquals($service->getRecipients(), array("[email protected]"));
54+
$this->assertEquals(["[email protected]"], $service->getRecipients());
4255
}
4356

4457
/**
@@ -48,18 +61,17 @@ public function createServiceWithEmailRedirect()
4861
*/
4962
public function templateReplacements()
5063
{
51-
$config = array("email" => array("from" => "[email protected]"));
52-
$recipients = array("[email protected]");
53-
$talk = new TalkModel(array("talk_title" => "sample talk"));
54-
$comment = array("comments" => array(array("comment" => "test comment", "rating" => 3)));
64+
$recipients = ["[email protected]"];
65+
$talk = new TalkModel(["talk_title" => "sample talk"]);
66+
$comment = ["comments" => [["comment" => "test comment", "rating" => 3]]];
5567

56-
$service = new \TalkCommentEmailService($config, $recipients, $talk, $comment);
57-
$service->templatePath = __DIR__ . '/../../src/views/emails/';
68+
$service = new \TalkCommentEmailService($this->config, $recipients, $talk, $comment);
69+
$service->templatePath = __DIR__.'/../../src/views/emails/';
5870

59-
$template = "testTemplate.md";
60-
$replacements = array("cat" => "Camel", "mat" => "magic carpet");
61-
$message = $service->parseEmail($template, $replacements);
62-
$expected = "The Camel sat on the magic carpet
71+
$template = "testTemplate.md";
72+
$replacements = ["cat" => "Camel", "mat" => "magic carpet"];
73+
$message = $service->parseEmail($template, $replacements);
74+
$expected = "The Camel sat on the magic carpet
6375
6476
6577
----
@@ -77,17 +89,18 @@ public function templateReplacements()
7789
*/
7890
public function markdownTransform()
7991
{
80-
$markdown = "A *sunny* day";
81-
82-
$config = array("email" => array("from" => "[email protected]"));
83-
$recipients = array("[email protected]");
84-
$talk = new TalkModel(array("talk_title" => "sample talk"));
85-
$comment = array("comments" => array(array("comment" => "test comment", "rating" => 3)));
92+
$markdown = "A *sunny* day";
93+
$recipients = ["[email protected]"];
94+
$talk = new TalkModel(["talk_title" => "sample talk"]);
95+
$comment = ["comments" => [["comment" => "test comment", "rating" => 3]]];
8696

87-
$service = new \TalkCommentEmailService($config, $recipients, $talk, $comment);
97+
$service = new \TalkCommentEmailService($this->config, $recipients, $talk, $comment);
8898

8999
$html = $service->markdownToHtml($markdown);
90-
$this->assertEquals($html, "<p>A <em>sunny</em> day</p>
91-
");
100+
$this->assertEquals(
101+
$html,
102+
"<p>A <em>sunny</em> day</p>
103+
"
104+
);
92105
}
93106
}

0 commit comments

Comments
 (0)