1<?php 2/** 3 * Created by PhpStorm. 4 * User: msowers 5 * Date: 3/31/15 6 * Time: 10:57 AM 7 */ 8 9use Tx\Mailer\SMTP; 10use Tx\Mailer\Message; 11use ERB\Testing\Tools\TestHelper; 12 13/** 14 * Class SMTPTest 15 * @package Tests 16 * 17 * This test set requires the use of an open SMTP server mock. Currently, I'm using FakeSMTPServer 18 * 19 */ 20class SMTPTest extends TestCase { 21 22 /** 23 * @var SMTP 24 */ 25 protected $smtp; 26 27 /** 28 * @var TestHelper 29 */ 30 protected $testHelper; 31 32 public function setup() 33 { 34 $this->smtp = new SMTP(); 35 $this->testHelper = new TestHelper(); 36 37 } 38 39 public function testSetServer() 40 { 41 $result = $this->smtp->setServer("localhost", "25", null); 42 $this->assertEquals('localhost', $this->testHelper->getPropertyValue($this->smtp, 'host')); 43 $this->assertEquals('25', $this->testHelper->getPropertyValue($this->smtp, 'port')); 44 $this->assertSame($this->smtp, $result); 45 } 46 47 public function testSetAuth() 48 { 49 $result = $this->smtp->setAuth('none', 'none'); 50 51 $this->assertEquals('none', $this->testHelper->getPropertyValue($this->smtp, 'username')); 52 $this->assertEquals('none', $this->testHelper->getPropertyValue($this->smtp, 'password')); 53 $this->assertSame($this->smtp, $result); 54 } 55 56 public function testMessage() 57 { 58 $this->smtp->setServer("localhost", "25", null) 59 ->setAuth('none', 'none'); 60 61 $message = new Message(); 62 $message->setFrom('You', 'nobody@nowhere.no') 63 ->setTo('Them', 'them@nowhere.no') 64 ->setSubject('This is a test') 65 ->setBody('This is a test part two'); 66 67 $status = $this->smtp->send($message); 68 $this->assertTrue($status); 69 } 70 71 72 /** 73 * @expectedException \Tx\Mailer\Exceptions\SMTPException 74 */ 75 public function testConnectSMTPException() 76 { 77 $this->smtp->setServer("localhost", "99999", null) 78 ->setAuth('none', 'none'); 79 $message = new Message(); 80 $message->setFrom('You', 'nobody@nowhere.no') 81 ->setTo('Them', 'them@nowhere.no') 82 ->setSubject('This is a test') 83 ->setBody('This is a test part two'); 84 85 $this->smtp->send($message); 86 87 } 88 89 90} 91