Skip to content
Permalink
Browse files

Make `connect()` invoke authentication, make tests more explicit, add…

… more tests.
  • Loading branch information...
ndm2
ndm2 committed Jul 17, 2014
1 parent 66b1ba8 commit c2020dabeb131b69445dea7e155fe43b8692bb8e
Showing with 59 additions and 3 deletions.
  1. +1 −0 src/Network/Email/SmtpTransport.php
  2. +58 −3 tests/TestCase/Network/Email/SmtpTransportTest.php
@@ -90,6 +90,7 @@ public function __destruct() {
public function connect() {
if (!$this->connected()) {
$this->_connect();
$this->_auth();
}
}
@@ -82,7 +82,7 @@ public function setUp() {
parent::setUp();
$this->socket = $this->getMock(
'Cake\Network\Socket',
array('read', 'write', 'connect', 'enableCrypto')
array('read', 'write', 'connect', 'disconnect', 'enableCrypto')
);
$this->SmtpTransport = new SmtpTestTransport();
@@ -166,7 +166,6 @@ public function testConnectEhloNoTlsOnRequiredTlsServer() {
$this->socket->expects($this->at(6))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(7))->method('read')->will($this->returnValue("504 5.7.4 Unrecognized authentication type\r\n"));
$this->SmtpTransport->connect();
$this->SmtpTransport->auth();
}
/**
@@ -458,17 +457,68 @@ public function testBufferResponseLines() {
$this->assertEquals($expected, $result);
}
/**
* testExplicitConnectAlreadyConnected method
*
* @return void
*/
public function testExplicitConnectAlreadyConnected() {
$this->socket->expects($this->never())->method('connect');
$this->socket->connected = true;
$this->SmtpTransport->connect();
}
/**
* testConnected method
*
* @return void
*/
public function testConnected() {
$this->socket->connected = true;
$this->assertTrue($this->SmtpTransport->connected());
$this->socket->connected = false;
$this->assertFalse($this->SmtpTransport->connected());
}
/**
* testAutoDisconnect method
*
* @return void
*/
public function testAutoDisconnect() {
$this->socket->expects($this->at(0))->method('write')->with("QUIT\r\n");
$this->socket->expects($this->at(1))->method('disconnect');
$this->socket->connected = true;
unset($this->SmtpTransport);
}
/**
* testExplicitDisconnect method
*
* @return void
*/
public function testExplicitDisconnect() {
$this->socket->expects($this->at(0))->method('write')->with("QUIT\r\n");
$this->socket->expects($this->at(1))->method('disconnect');
$this->socket->connected = true;
$this->SmtpTransport->disconnect();
}
/**
* testExplicitDisconnectNotConnected method
*
* @return void
*/
public function testExplicitDisconnectNotConnected() {
$callback = function($arg) {
$this->assertNotEquals("QUIT\r\n", $arg);
};
$this->socket->expects($this->any())->method('write')->will($this->returnCallback($callback));
$this->socket->expects($this->never())->method('disconnect');
$this->SmtpTransport->disconnect();
}
/**
* testKeepAlive method
*
@@ -482,6 +532,10 @@ public function testKeepAlive() {
$email->to('cake@cakephp.org', 'CakePHP');
$email->expects($this->exactly(2))->method('message')->will($this->returnValue(array('First Line')));
$callback = function($arg) {
$this->assertNotEquals("QUIT\r\n", $arg);
};
$this->socket->expects($this->any())->method('write')->will($this->returnCallback($callback));
$this->socket->expects($this->never())->method('disconnect');
$this->socket->expects($this->at(0))->method('connect')->will($this->returnValue(true));
@@ -561,7 +615,8 @@ public function testSendDefaults() {
$this->socket->expects($this->at(16))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(17))->method('read')->will($this->returnValue("250 OK\r\n"));
$this->socket->expects($this->at(18))->method('disconnect');
$this->socket->expects($this->at(18))->method('write')->with("QUIT\r\n");
$this->socket->expects($this->at(19))->method('disconnect');
$this->SmtpTransport->send($email);
}

0 comments on commit c2020da

Please sign in to comment.
You can’t perform that action at this time.