Formatting! PSR Compliance

This commit is contained in:
Robert Hafner 2014-04-16 00:35:51 -07:00
parent faaff0711d
commit 1725eb2f8b
8 changed files with 36 additions and 42 deletions

View File

@ -169,7 +169,6 @@ class Message
*/ */
public static $charset = 'UTF-8//TRANSLIT'; public static $charset = 'UTF-8//TRANSLIT';
/** /**
* This constructor takes in the uid for the message and the Imap class representing the mailbox the * This constructor takes in the uid for the message and the Imap class representing the mailbox the
* message should be opened from. This constructor should generally not be called directly, but rather retrieved * message should be opened from. This constructor should generally not be called directly, but rather retrieved
@ -199,6 +198,7 @@ class Message
/* First load the message overview information */ /* First load the message overview information */
if(!is_object($messageOverview = $this->getOverview())) if(!is_object($messageOverview = $this->getOverview()))
return false; return false;
$this->subject = $messageOverview->subject; $this->subject = $messageOverview->subject;
@ -422,7 +422,6 @@ class Message
* *
* @param \stdClass $structure * @param \stdClass $structure
* @param string $partIdentifier * @param string $partIdentifier
* @todoa process attachments.
*/ */
protected function processStructure($structure, $partIdentifier = null) protected function processStructure($structure, $partIdentifier = null)
{ {
@ -649,9 +648,11 @@ class Message
if ($enable === true) { if ($enable === true) {
$this->status[$flag] = true; $this->status[$flag] = true;
return imap_setflag_full($this->imapStream, $this->uid, $imapifiedFlag, ST_UID); return imap_setflag_full($this->imapStream, $this->uid, $imapifiedFlag, ST_UID);
} else { } else {
unset($this->status[$flag]); unset($this->status[$flag]);
return imap_clearflag_full($this->imapStream, $this->uid, $imapifiedFlag, ST_UID); return imap_clearflag_full($this->imapStream, $this->uid, $imapifiedFlag, ST_UID);
} }
} }

View File

@ -155,8 +155,11 @@ class Server
*/ */
public function setMailBox($mailbox = '') public function setMailBox($mailbox = '')
{ {
if(!$this->hasMailBox($mailbox)) if (!$this->hasMailBox($mailbox)) {
return false; return false;
}
$this->mailbox = $mailbox; $this->mailbox = $mailbox;
if (isset($this->imapStream)) { if (isset($this->imapStream)) {
@ -381,13 +384,13 @@ class Server
{ {
try { try {
$message = new \Fetch\Message($uid, $this); $message = new \Fetch\Message($uid, $this);
return $message; return $message;
} catch (\Exception $e) { } catch (\Exception $e) {
return false; return false;
} }
} }
/** /**
* This function removes all of the messages flagged for deletion from the mailbox. * This function removes all of the messages flagged for deletion from the mailbox.
* *

View File

@ -11,7 +11,6 @@
namespace Fetch\Test; namespace Fetch\Test;
/** /**
* @package Fetch * @package Fetch
* @author Robert Hafner <tedivm@tedivm.com> * @author Robert Hafner <tedivm@tedivm.com>
@ -27,6 +26,7 @@ class AttachmentTest extends \PHPUnit_Framework_TestCase
$returnAttachments = array(); $returnAttachments = array();
foreach($attachments as $attachment) foreach($attachments as $attachment)
$returnAttachments[$attachment->getFileName()] = $attachment; $returnAttachments[$attachment->getFileName()] = $attachment;
return $returnAttachments; return $returnAttachments;
} }
@ -100,20 +100,16 @@ class AttachmentTest extends \PHPUnit_Framework_TestCase
$this->assertFileExists($filepath); $this->assertFileExists($filepath);
$this->assertEquals(md5(file_get_contents($filepath)), md5($attachment_RCA->getData())); $this->assertEquals(md5(file_get_contents($filepath)), md5($attachment_RCA->getData()));
$attachments = static::getAttachments('6'); $attachments = static::getAttachments('6');
$attachment_RCA = $attachments['RCA_Indian_Head_test_pattern.JPG.zip']; $attachment_RCA = $attachments['RCA_Indian_Head_test_pattern.JPG.zip'];
$this->assertFalse($attachment_RCA->saveToDirectory('/'), 'Returns false when attempting to save without filesystem permission.'); $this->assertFalse($attachment_RCA->saveToDirectory('/'), 'Returns false when attempting to save without filesystem permission.');
$attachments = static::getAttachments('6'); $attachments = static::getAttachments('6');
$attachment_RCA = $attachments['RCA_Indian_Head_test_pattern.JPG.zip']; $attachment_RCA = $attachments['RCA_Indian_Head_test_pattern.JPG.zip'];
$this->assertFalse($attachment_RCA->saveToDirectory($filepath), 'Returns false when attempting to save over a file.'); $this->assertFalse($attachment_RCA->saveToDirectory($filepath), 'Returns false when attempting to save over a file.');
} }
public static function tearDownAfterClass()
static function tearDownAfterClass()
{ {
$tmpdir = rtrim(sys_get_temp_dir(), '/') . '/'; $tmpdir = rtrim(sys_get_temp_dir(), '/') . '/';
$filepath = $tmpdir . 'RCA_Indian_Head_test_pattern.JPG.zip'; $filepath = $tmpdir . 'RCA_Indian_Head_test_pattern.JPG.zip';

View File

@ -12,7 +12,6 @@
namespace Fetch\Test; namespace Fetch\Test;
use Fetch\Message; use Fetch\Message;
/** /**
* @package Fetch * @package Fetch
* @author Robert Hafner <tedivm@tedivm.com> * @author Robert Hafner <tedivm@tedivm.com>
@ -22,6 +21,7 @@ class MessageTest extends \PHPUnit_Framework_TestCase
public static function getMessage($id) public static function getMessage($id)
{ {
$server = ServerTest::getServer(); $server = ServerTest::getServer();
return new \Fetch\Message($id, $server); return new \Fetch\Message($id, $server);
} }
@ -68,7 +68,6 @@ class MessageTest extends \PHPUnit_Framework_TestCase
$messageNonHTML = $message->getMessageBody(); $messageNonHTML = $message->getMessageBody();
$this->assertEquals($plaintextTest, md5($messageNonHTML), 'Message returns as plaintext.'); $this->assertEquals($plaintextTest, md5($messageNonHTML), 'Message returns as plaintext.');
$messageHTML = $message->getMessageBody(true); $messageHTML = $message->getMessageBody(true);
$this->assertEquals($convertedHtmlTest, md5($messageHTML), 'Message converts from plaintext to HTML when requested.'); $this->assertEquals($convertedHtmlTest, md5($messageHTML), 'Message converts from plaintext to HTML when requested.');
@ -130,14 +129,12 @@ class MessageTest extends \PHPUnit_Framework_TestCase
$messageWithoutAttachments = static::getMessage('3'); $messageWithoutAttachments = static::getMessage('3');
$this->assertFalse($messageWithoutAttachments->getAttachments(), 'getAttachments returns false when no attachments present.'); $this->assertFalse($messageWithoutAttachments->getAttachments(), 'getAttachments returns false when no attachments present.');
$messageWithAttachments = static::getMessage('6'); $messageWithAttachments = static::getMessage('6');
$attachments = $messageWithAttachments->getAttachments(); $attachments = $messageWithAttachments->getAttachments();
$this->assertCount(2, $attachments); $this->assertCount(2, $attachments);
foreach($attachments as $attachment) foreach($attachments as $attachment)
$this->assertInstanceOf('\Fetch\Attachment', $attachment, 'getAttachments returns Fetch\Attachment objects.'); $this->assertInstanceOf('\Fetch\Attachment', $attachment, 'getAttachments returns Fetch\Attachment objects.');
$attachment = $messageWithAttachments->getAttachments('Test_card.png.zip'); $attachment = $messageWithAttachments->getAttachments('Test_card.png.zip');
$this->assertInstanceOf('\Fetch\Attachment', $attachment, 'getAttachment returns specified Fetch\Attachment object.'); $this->assertInstanceOf('\Fetch\Attachment', $attachment, 'getAttachment returns specified Fetch\Attachment object.');
} }
@ -160,7 +157,6 @@ class MessageTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($message->setFlag('answered', false), 'setFlag returned true.'); $this->assertTrue($message->setFlag('answered', false), 'setFlag returned true.');
$this->assertFalse($message->checkFlag('answered'), 'Message was successfully unanswered.'); $this->assertFalse($message->checkFlag('answered'), 'Message was successfully unanswered.');
$message = static::getMessage('2'); $message = static::getMessage('2');
$this->assertFalse($message->checkFlag('flagged'), 'Message is not flagged.'); $this->assertFalse($message->checkFlag('flagged'), 'Message is not flagged.');
@ -190,7 +186,6 @@ class MessageTest extends \PHPUnit_Framework_TestCase
$server->setMailBox('Sent'); $server->setMailBox('Sent');
$sentFolderNumStart = $server->numMessages(); $sentFolderNumStart = $server->numMessages();
// Switch to "Flagged" folder in order to test that function properly returns to it // Switch to "Flagged" folder in order to test that function properly returns to it
$this->assertTrue($server->setMailBox('Flagged Email')); $this->assertTrue($server->setMailBox('Flagged Email'));
@ -246,5 +241,4 @@ class MessageTest extends \PHPUnit_Framework_TestCase
} }
} }

View File

@ -47,7 +47,8 @@ class ServerTest extends \PHPUnit_Framework_TestCase
$this->assertAttributeContains('TestFlag=false', 'flags', $server); $this->assertAttributeContains('TestFlag=false', 'flags', $server);
} }
public function flagsDataProvider() { public function flagsDataProvider()
{
return array( return array(
array('{%host%:143/novalidate-cert}', 143, array()), array('{%host%:143/novalidate-cert}', 143, array()),
array('{%host%:143/validate-cert}', 143, array('validate-cert' => true)), array('{%host%:143/validate-cert}', 143, array('validate-cert' => true)),
@ -84,7 +85,8 @@ class ServerTest extends \PHPUnit_Framework_TestCase
$this->assertInternalType('resource', $imapSteam, $message); $this->assertInternalType('resource', $imapSteam, $message);
} }
public function connectionDataProvider() { public function connectionDataProvider()
{
return array( return array(
array(143, array(), 'Connects with default settings.'), array(143, array(), 'Connects with default settings.'),
array(993, array('novalidate-cert' => true), 'Connects over SSL (self signed).'), array(993, array('novalidate-cert' => true), 'Connects over SSL (self signed).'),
@ -160,7 +162,6 @@ class ServerTest extends \PHPUnit_Framework_TestCase
$server->setOptions('purple'); $server->setOptions('purple');
} }
public function testSetOptions() public function testSetOptions()
{ {
$server = Static::getServer(); $server = Static::getServer();
@ -168,7 +169,6 @@ class ServerTest extends \PHPUnit_Framework_TestCase
$this->assertAttributeEquals(5, 'options', $server); $this->assertAttributeEquals(5, 'options', $server);
} }
public function testExpunge() public function testExpunge()
{ {
$server = Static::getServer(); $server = Static::getServer();
@ -185,10 +185,11 @@ class ServerTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($server->getMessageByUid(12), 'Message successfully expunged'); $this->assertFalse($server->getMessageByUid(12), 'Message successfully expunged');
} }
static public function getServer() public static function getServer()
{ {
$server = new Server(TESTING_SERVER_HOST, 143); $server = new Server(TESTING_SERVER_HOST, 143);
$server->setAuthentication(TEST_USER, TEST_PASSWORD); $server->setAuthentication(TEST_USER, TEST_PASSWORD);
return $server; return $server;
} }
} }

View File

@ -17,8 +17,7 @@ define('TEST_PASSWORD', 'applesauce');
date_default_timezone_set('UTC'); date_default_timezone_set('UTC');
if(getenv('TRAVIS')) if (getenv('TRAVIS')) {
{
define('TESTING_ENVIRONMENT', 'TRAVIS'); define('TESTING_ENVIRONMENT', 'TRAVIS');
define('TESTING_SERVER_HOST', '127.0.0.1'); define('TESTING_SERVER_HOST', '127.0.0.1');
} else { } else {