Skip to content
Permalink
Browse files

Fixing more namespaces

  • Loading branch information...
lorenzo committed Aug 30, 2014
1 parent 2f3b863 commit 0b5672b1b836c3ead499394a4fade36dc7db616a
@@ -16,6 +16,7 @@
use Cake\Network\Error;
use Cake\Network\Socket;
use Cake\Network\Exception\SocketException;
/**
* Send mail using SMTP protocol
@@ -151,7 +152,7 @@ public function getLastResponse() {
*
* @param \Cake\Network\Email\Email $email Cake Email
* @return array
* @throws \Cake\Network\Error\SocketException
* @throws \Cake\Network\Exception\SocketException
*/
public function send(Email $email) {
$this->_cakeEmail = $email;
@@ -196,12 +197,12 @@ protected function _bufferResponseLines(array $responseLines) {
* Connect to SMTP Server
*
* @return void
* @throws \Cake\Network\Error\SocketException
* @throws \Cake\Network\Exception\SocketException
*/
protected function _connect() {
$this->_generateSocket();
if (!$this->_socket->connect()) {
throw new Error\SocketException('Unable to connect to SMTP server.');
throw new SocketException('Unable to connect to SMTP server.');
}
$this->_smtpSend(null, '220');
@@ -222,14 +223,14 @@ protected function _connect() {
$this->_socket->enableCrypto('tls');
$this->_smtpSend("EHLO {$host}", '250');
}
} catch (Error\SocketException $e) {
} catch (SocketException $e) {
if ($config['tls']) {
throw new Error\SocketException('SMTP server did not accept the connection or trying to connect to non TLS SMTP server using TLS.');
throw new SocketException('SMTP server did not accept the connection or trying to connect to non TLS SMTP server using TLS.');
}
try {
$this->_smtpSend("HELO {$host}", '250');
} catch (Error\SocketException $e2) {
throw new Error\SocketException('SMTP server did not accept the connection.');
} catch (SocketException $e2) {
throw new SocketException('SMTP server did not accept the connection.');
}
}
}
@@ -238,26 +239,26 @@ protected function _connect() {
* Send authentication
*
* @return void
* @throws \Cake\Network\Error\SocketException
* @throws \Cake\Network\Exception\SocketException
*/
protected function _auth() {
if (isset($this->_config['username']) && isset($this->_config['password'])) {
$replyCode = $this->_smtpSend('AUTH LOGIN', '334|500|502|504');
if ($replyCode == '334') {
try {
$this->_smtpSend(base64_encode($this->_config['username']), '334');
} catch (Error\SocketException $e) {
throw new Error\SocketException('SMTP server did not accept the username.');
} catch (SocketException $e) {
throw new SocketException('SMTP server did not accept the username.');
}
try {
$this->_smtpSend(base64_encode($this->_config['password']), '235');
} catch (Error\SocketException $e) {
throw new Error\SocketException('SMTP server did not accept the password.');
} catch (SocketException $e) {
throw new SocketException('SMTP server did not accept the password.');
}
} elseif ($replyCode == '504') {
throw new Error\SocketException('SMTP authentication method not allowed, check if SMTP server requires TLS.');
throw new SocketException('SMTP authentication method not allowed, check if SMTP server requires TLS.');
} else {
throw new Error\SocketException('AUTH command not recognized or not implemented, SMTP server may not require authentication.');
throw new SocketException('AUTH command not recognized or not implemented, SMTP server may not require authentication.');
}
}
}
@@ -338,7 +339,7 @@ protected function _prepareMessage() {
* Send emails
*
* @return void
* @throws \Cake\Network\Error\SocketException
* @throws \Cake\Network\Exception\SocketException
*/
protected function _sendRcpt() {
$from = $this->_prepareFromAddress();
@@ -354,7 +355,7 @@ protected function _sendRcpt() {
* Send Data
*
* @return void
* @throws \Cake\Network\Error\SocketException
* @throws \Cake\Network\Exception\SocketException
*/
protected function _sendData() {
$this->_smtpSend('DATA', '354');
@@ -370,7 +371,7 @@ protected function _sendData() {
* Disconnect
*
* @return void
* @throws \Cake\Network\Error\SocketException
* @throws \Cake\Network\Exception\SocketException
*/
protected function _disconnect() {
$this->_smtpSend('QUIT', false);
@@ -381,7 +382,7 @@ protected function _disconnect() {
* Helper method to generate socket
*
* @return void
* @throws \Cake\Network\Error\SocketException
* @throws \Cake\Network\Exception\SocketException
*/
protected function _generateSocket() {
$this->_socket = new Socket($this->_config);
@@ -393,7 +394,7 @@ protected function _generateSocket() {
* @param string $data data to be sent to SMTP server
* @param string|bool $checkCode code to check for in server response, false to skip
* @return void
* @throws \Cake\Network\Error\SocketException
* @throws \Cake\Network\Exception\SocketException
*/
protected function _smtpSend($data, $checkCode = '250') {
$this->_lastResponse = array();
@@ -411,7 +412,7 @@ protected function _smtpSend($data, $checkCode = '250') {
$response .= $this->_socket->read();
}
if (substr($response, -2) !== "\r\n") {
throw new Error\SocketException('SMTP timeout.');
throw new SocketException('SMTP timeout.');
}
$responseLines = explode("\r\n", rtrim($response, "\r\n"));
$response = end($responseLines);
@@ -424,7 +425,7 @@ protected function _smtpSend($data, $checkCode = '250') {
}
return $code[1];
}
throw new Error\SocketException(sprintf('SMTP Error: %s', $response));
throw new SocketException(sprintf('SMTP Error: %s', $response));
}
}
@@ -22,6 +22,8 @@
use Cake\Error\ErrorHandler;
use Cake\Error\ExceptionRenderer;
use Cake\Log\Log;
use Cake\Network\Exception\ForbiddenException;
use Cake\Network\Exception\NotFoundException;
use Cake\Network\Request;
use Cake\Network\Response;
use Cake\Routing\Router;
@@ -220,7 +222,7 @@ public function testHandleErrorLoggingTrace() {
* @return void
*/
public function testHandleException() {
$error = new Error\NotFoundException('Kaboom!');
$error = new NotFoundException('Kaboom!');
$errorHandler = new TestErrorHandler();
$errorHandler->handleException($error);
@@ -237,12 +239,12 @@ public function testHandleExceptionLog() {
'log' => true,
]);
$error = new Error\NotFoundException('Kaboom!');
$error = new NotFoundException('Kaboom!');
$this->_logger->expects($this->once())
->method('write')
->with('error', $this->logicalAnd(
$this->stringContains('[Cake\Error\NotFoundException] Kaboom!'),
$this->stringContains('[Cake\NEtwork\Exception\NotFoundException] Kaboom!'),
$this->stringContains('ErrorHandlerTest->testHandleExceptionLog')
));
@@ -256,19 +258,19 @@ public function testHandleExceptionLog() {
* @return void
*/
public function testHandleExceptionLogSkipping() {
$notFound = new Error\NotFoundException('Kaboom!');
$forbidden = new Error\ForbiddenException('Fooled you!');
$notFound = new NotFoundException('Kaboom!');
$forbidden = new ForbiddenException('Fooled you!');
$this->_logger->expects($this->once())
->method('write')
->with(
'error',
$this->stringContains('[Cake\Error\ForbiddenException] Fooled you!')
$this->stringContains('[Cake\Network\Exception\ForbiddenException] Fooled you!')
);
$errorHandler = new TestErrorHandler([
'log' => true,
'skipLog' => ['Cake\Error\NotFoundException'],
'skipLog' => ['Cake\Network\Exception\NotFoundException'],
]);
$errorHandler->handleException($notFound);
@@ -289,7 +291,7 @@ public function testLoadPluginHandler() {
'exceptionRenderer' => 'TestPlugin.TestPluginExceptionRenderer',
]);
$error = new Error\NotFoundException('Kaboom!');
$error = new NotFoundException('Kaboom!');
$errorHandler->handleException($error);
$result = $errorHandler->response;
@@ -29,9 +29,10 @@
use Cake\Error;
use Cake\Error\ExceptionRenderer;
use Cake\Event\Event;
use Cake\Network\Error\SocketException;
use Cake\Network\Exception\InternalErrorException;
use Cake\Network\Exception\MethodNotAllowedException;
use Cake\Network\Exception\NotFoundException;
use Cake\Network\Exception\SocketException;
use Cake\Network\Request;
use Cake\ORM\Error\MissingBehaviorException;
use Cake\Routing\Router;

0 comments on commit 0b5672b

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