Permalink
Browse files

Added tests for SMTP and created mocking architecture, to easily mock…

… and load mocked classes
  • Loading branch information...
1 parent b74db21 commit 3a690f4d9edd6b2673c82c63564eb3ca568fd98a CJ Buchmann committed Feb 10, 2012
Showing with 40 additions and 6 deletions.
  1. +1 −0 .gitignore
  2. +2 −2 SendGrid/Smtp.php
  3. +8 −3 SendGrid/Web.php
  4. +1 −1 SendGrid_loader.php
  5. +14 −0 Test/Mock/Mock_loader.php
  6. +14 −0 Test/Mock/SmtpMock.php
  7. 0 Test/Mock/WebMock.php
View
@@ -0,0 +1 @@
+Test/coverage/*
View
@@ -11,7 +11,7 @@ class Smtp extends Api implements MailInterface
//the list of port instances, to be recycled
private $swift_instances = array();
- private $port;
+ protected $port;
public function __construct($username, $password)
{
@@ -59,7 +59,7 @@ private function _getSwiftInstance($port)
* @param Mail $mail - the SendGridMail object
* @return the SwiftMessage object
*/
- private function _mapToSwift(Mail $mail)
+ protected function _mapToSwift(Mail $mail)
{
$message = new \Swift_Message($mail->getSubject());
View
@@ -7,7 +7,12 @@ class Web extends Api implements MailInterface
private $domain = "http://sendgrid.com/";
private $endpoint = "api/mail.send.json";
- public function __construct()
+
+ /**
+ * __construct
+ * Create a new Web instance
+ */
+ public function __construct($username, $password)
{
call_user_func_array("parent::__construct", func_get_args());
}
@@ -18,7 +23,7 @@ public function __construct()
* @param Mail $mail [description]
* @return String - the data query string to be posted
*/
- private function _prepMessageData(Mail $mail)
+ protected function _prepMessageData(Mail $mail)
{
$params =
array(
@@ -46,7 +51,7 @@ private function _prepMessageData(Mail $mail)
* @param String $token - the name of parameter
* @return String - a url part that can be concatenated to a url request
*/
- private function _arrayToUrlPart($array, $token)
+ protected function _arrayToUrlPart($array, $token)
{
$string = "";
View
@@ -4,7 +4,7 @@
function sendGridLoader($string)
{
- if(preg_match("/^SendGrid/", $string))
+ if(preg_match("/SendGrid/", $string))
{
$file = str_replace('\\', '/', "$string.php");
require_once ROOT_DIR . $file;
View
@@ -0,0 +1,14 @@
+<?php
+
+define("MOCK_ROOT", __dir__ . DIRECTORY_SEPARATOR);
+
+function mockLoader($string)
+{
+ if(preg_match("/Mock/", $string))
+ {
+ $file = str_replace('\\', '/', "$string.php");
+ require_once MOCK_ROOT . $file;
+ }
+}
+
+spl_autoload_register("mockLoader");
View
@@ -0,0 +1,14 @@
+<?php
+
+class SmtpMock extends SendGrid\Smtp
+{
+ public function __construct($username, $password)
+ {
+ parent::__construct($username, $password);
+ }
+
+ public function getPort()
+ {
+ return $this->port;
+ }
+}
View
No changes.

0 comments on commit 3a690f4

Please sign in to comment.