mirror of
https://github.com/retailcrm/Fetch.git
synced 2024-11-23 11:36:02 +03:00
Formatting! PSR Compliance
This commit is contained in:
parent
faaff0711d
commit
1725eb2f8b
@ -9,7 +9,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
spl_autoload_register(function($class) {
|
||||
spl_autoload_register(function ($class) {
|
||||
$base = '/src/';
|
||||
|
||||
if (strpos($class, 'Fetch\Test') === 0) {
|
||||
@ -22,4 +22,4 @@ spl_autoload_register(function($class) {
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -160,7 +160,7 @@ class Attachment
|
||||
|
||||
/**
|
||||
* This function returns the object that contains the structure of this attachment.
|
||||
*
|
||||
*
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function getStructure()
|
||||
|
@ -169,7 +169,6 @@ class Message
|
||||
*/
|
||||
public static $charset = 'UTF-8//TRANSLIT';
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
@ -199,6 +198,7 @@ class Message
|
||||
/* First load the message overview information */
|
||||
|
||||
if(!is_object($messageOverview = $this->getOverview()))
|
||||
|
||||
return false;
|
||||
|
||||
$this->subject = $messageOverview->subject;
|
||||
@ -422,7 +422,6 @@ class Message
|
||||
*
|
||||
* @param \stdClass $structure
|
||||
* @param string $partIdentifier
|
||||
* @todoa process attachments.
|
||||
*/
|
||||
protected function processStructure($structure, $partIdentifier = null)
|
||||
{
|
||||
@ -649,9 +648,11 @@ class Message
|
||||
|
||||
if ($enable === true) {
|
||||
$this->status[$flag] = true;
|
||||
|
||||
return imap_setflag_full($this->imapStream, $this->uid, $imapifiedFlag, ST_UID);
|
||||
} else {
|
||||
unset($this->status[$flag]);
|
||||
|
||||
return imap_clearflag_full($this->imapStream, $this->uid, $imapifiedFlag, ST_UID);
|
||||
}
|
||||
}
|
||||
|
@ -150,13 +150,16 @@ class Server
|
||||
/**
|
||||
* This function sets the mailbox to connect to.
|
||||
*
|
||||
* @param string $mailbox
|
||||
* @param string $mailbox
|
||||
* @return bool
|
||||
*/
|
||||
public function setMailBox($mailbox = '')
|
||||
{
|
||||
if(!$this->hasMailBox($mailbox))
|
||||
if (!$this->hasMailBox($mailbox)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$this->mailbox = $mailbox;
|
||||
if (isset($this->imapStream)) {
|
||||
@ -374,20 +377,20 @@ class Server
|
||||
/**
|
||||
* Returns the requested email or false if it is not found.
|
||||
*
|
||||
* @param int $uid
|
||||
* @param int $uid
|
||||
* @return Message|bool
|
||||
*/
|
||||
public function getMessageByUid($uid)
|
||||
{
|
||||
try {
|
||||
$message = new \Fetch\Message($uid, $this);
|
||||
|
||||
return $message;
|
||||
}catch(\Exception $e){
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This function removes all of the messages flagged for deletion from the mailbox.
|
||||
*
|
||||
|
@ -11,7 +11,6 @@
|
||||
|
||||
namespace Fetch\Test;
|
||||
|
||||
|
||||
/**
|
||||
* @package Fetch
|
||||
* @author Robert Hafner <tedivm@tedivm.com>
|
||||
@ -27,6 +26,7 @@ class AttachmentTest extends \PHPUnit_Framework_TestCase
|
||||
$returnAttachments = array();
|
||||
foreach($attachments as $attachment)
|
||||
$returnAttachments[$attachment->getFileName()] = $attachment;
|
||||
|
||||
return $returnAttachments;
|
||||
}
|
||||
|
||||
@ -100,20 +100,16 @@ class AttachmentTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertFileExists($filepath);
|
||||
$this->assertEquals(md5(file_get_contents($filepath)), md5($attachment_RCA->getData()));
|
||||
|
||||
|
||||
$attachments = static::getAttachments('6');
|
||||
$attachment_RCA = $attachments['RCA_Indian_Head_test_pattern.JPG.zip'];
|
||||
$this->assertFalse($attachment_RCA->saveToDirectory('/'), 'Returns false when attempting to save without filesystem permission.');
|
||||
|
||||
|
||||
|
||||
$attachments = static::getAttachments('6');
|
||||
$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.');
|
||||
}
|
||||
|
||||
|
||||
static function tearDownAfterClass()
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
$tmpdir = rtrim(sys_get_temp_dir(), '/') . '/';
|
||||
$filepath = $tmpdir . 'RCA_Indian_Head_test_pattern.JPG.zip';
|
||||
|
@ -12,7 +12,6 @@
|
||||
namespace Fetch\Test;
|
||||
use Fetch\Message;
|
||||
|
||||
|
||||
/**
|
||||
* @package Fetch
|
||||
* @author Robert Hafner <tedivm@tedivm.com>
|
||||
@ -22,6 +21,7 @@ class MessageTest extends \PHPUnit_Framework_TestCase
|
||||
public static function getMessage($id)
|
||||
{
|
||||
$server = ServerTest::getServer();
|
||||
|
||||
return new \Fetch\Message($id, $server);
|
||||
}
|
||||
|
||||
@ -68,7 +68,6 @@ class MessageTest extends \PHPUnit_Framework_TestCase
|
||||
$messageNonHTML = $message->getMessageBody();
|
||||
$this->assertEquals($plaintextTest, md5($messageNonHTML), 'Message returns as plaintext.');
|
||||
|
||||
|
||||
$messageHTML = $message->getMessageBody(true);
|
||||
$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');
|
||||
$this->assertFalse($messageWithoutAttachments->getAttachments(), 'getAttachments returns false when no attachments present.');
|
||||
|
||||
|
||||
$messageWithAttachments = static::getMessage('6');
|
||||
$attachments = $messageWithAttachments->getAttachments();
|
||||
$this->assertCount(2, $attachments);
|
||||
foreach($attachments as $attachment)
|
||||
$this->assertInstanceOf('\Fetch\Attachment', $attachment, 'getAttachments returns Fetch\Attachment objects.');
|
||||
|
||||
|
||||
$attachment = $messageWithAttachments->getAttachments('Test_card.png.zip');
|
||||
$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->assertFalse($message->checkFlag('answered'), 'Message was successfully unanswered.');
|
||||
|
||||
|
||||
$message = static::getMessage('2');
|
||||
$this->assertFalse($message->checkFlag('flagged'), 'Message is not flagged.');
|
||||
|
||||
@ -190,7 +186,6 @@ class MessageTest extends \PHPUnit_Framework_TestCase
|
||||
$server->setMailBox('Sent');
|
||||
$sentFolderNumStart = $server->numMessages();
|
||||
|
||||
|
||||
// Switch to "Flagged" folder in order to test that function properly returns to it
|
||||
$this->assertTrue($server->setMailBox('Flagged Email'));
|
||||
|
||||
@ -246,5 +241,4 @@ class MessageTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -21,18 +21,18 @@ class ServerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider flagsDataProvider
|
||||
* @param string $expected server string with %host% placeholder
|
||||
* @param integer $port to use (needed to test behavior on port 143 and 993 from constructor)
|
||||
* @param array $flags to set/unset ($flag => $value)
|
||||
* @param string $expected server string with %host% placeholder
|
||||
* @param integer $port to use (needed to test behavior on port 143 and 993 from constructor)
|
||||
* @param array $flags to set/unset ($flag => $value)
|
||||
*/
|
||||
public function testFlags($expected, $port, $flags)
|
||||
{
|
||||
$server = new Server(TESTING_SERVER_HOST, $port);
|
||||
|
||||
|
||||
foreach ($flags as $flag => $value) {
|
||||
$server->setFlag($flag, $value);
|
||||
}
|
||||
|
||||
|
||||
$this->assertEquals(str_replace('%host%', TESTING_SERVER_HOST, $expected), $server->getServerString());
|
||||
}
|
||||
|
||||
@ -46,8 +46,9 @@ class ServerTest extends \PHPUnit_Framework_TestCase
|
||||
$server->setFlag('TestFlag', 'false');
|
||||
$this->assertAttributeContains('TestFlag=false', 'flags', $server);
|
||||
}
|
||||
|
||||
public function flagsDataProvider() {
|
||||
|
||||
public function flagsDataProvider()
|
||||
{
|
||||
return array(
|
||||
array('{%host%:143/novalidate-cert}', 143, array()),
|
||||
array('{%host%:143/validate-cert}', 143, array('validate-cert' => true)),
|
||||
@ -67,9 +68,9 @@ class ServerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
/**
|
||||
* @dataProvider connectionDataProvider
|
||||
* @param integer $port to use (needed to test behavior on port 143 and 993 from constructor)
|
||||
* @param array $flags to set/unset ($flag => $value)
|
||||
* @param string $message Assertion message
|
||||
* @param integer $port to use (needed to test behavior on port 143 and 993 from constructor)
|
||||
* @param array $flags to set/unset ($flag => $value)
|
||||
* @param string $message Assertion message
|
||||
*/
|
||||
public function testConnection($port, $flags, $message)
|
||||
{
|
||||
@ -84,7 +85,8 @@ class ServerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertInternalType('resource', $imapSteam, $message);
|
||||
}
|
||||
|
||||
public function connectionDataProvider() {
|
||||
public function connectionDataProvider()
|
||||
{
|
||||
return array(
|
||||
array(143, array(), 'Connects with default settings.'),
|
||||
array(993, array('novalidate-cert' => true), 'Connects over SSL (self signed).'),
|
||||
@ -104,7 +106,7 @@ class ServerTest extends \PHPUnit_Framework_TestCase
|
||||
$messages = $server->getMessages(5);
|
||||
|
||||
$this->assertCount(5, $messages, 'Five messages returned');
|
||||
foreach($messages as $message) {
|
||||
foreach ($messages as $message) {
|
||||
$this->assertInstanceOf('\Fetch\Message', $message, 'Returned values are Messages');
|
||||
}
|
||||
}
|
||||
@ -160,7 +162,6 @@ class ServerTest extends \PHPUnit_Framework_TestCase
|
||||
$server->setOptions('purple');
|
||||
}
|
||||
|
||||
|
||||
public function testSetOptions()
|
||||
{
|
||||
$server = Static::getServer();
|
||||
@ -168,7 +169,6 @@ class ServerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertAttributeEquals(5, 'options', $server);
|
||||
}
|
||||
|
||||
|
||||
public function testExpunge()
|
||||
{
|
||||
$server = Static::getServer();
|
||||
@ -185,10 +185,11 @@ class ServerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertFalse($server->getMessageByUid(12), 'Message successfully expunged');
|
||||
}
|
||||
|
||||
static public function getServer()
|
||||
public static function getServer()
|
||||
{
|
||||
$server = new Server(TESTING_SERVER_HOST, 143);
|
||||
$server->setAuthentication(TEST_USER, TEST_PASSWORD);
|
||||
|
||||
return $server;
|
||||
}
|
||||
}
|
||||
|
@ -17,11 +17,10 @@ define('TEST_PASSWORD', 'applesauce');
|
||||
|
||||
date_default_timezone_set('UTC');
|
||||
|
||||
if(getenv('TRAVIS'))
|
||||
{
|
||||
if (getenv('TRAVIS')) {
|
||||
define('TESTING_ENVIRONMENT', 'TRAVIS');
|
||||
define('TESTING_SERVER_HOST', '127.0.0.1');
|
||||
}else{
|
||||
} else {
|
||||
define('TESTING_ENVIRONMENT', 'VAGRANT');
|
||||
define('TESTING_SERVER_HOST', '172.31.1.2');
|
||||
}
|
||||
@ -35,7 +34,7 @@ if (!file_exists($filename)) {
|
||||
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" . PHP_EOL . PHP_EOL;
|
||||
$filename = __DIR__ .'/../autoload.php';
|
||||
require_once $filename;
|
||||
}else{
|
||||
} else {
|
||||
$loader = require_once $filename;
|
||||
$loader->add('Fetch\\Test', __DIR__);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user