diff --git a/.coveralls.yml b/.coveralls.yml
new file mode 100644
index 0000000..cbd906c
--- /dev/null
+++ b/.coveralls.yml
@@ -0,0 +1,3 @@
+src_dir: src
+coverage_clover: build/logs/clover.xml
+json_path: build/logs/coveralls-upload.json
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 56f700e..75ec387 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,4 @@
.vagrant
-
/.idea
/.settings
/.buildpath
@@ -7,3 +6,4 @@
/composer.lock
/vendor
/report
+/build
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
index 9e11a95..77d571d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,10 +4,18 @@ php:
- 5.3
- 5.4
- 5.5
+ - hhvm
before_script:
- - composer install --dev
+ - composer self-update && composer install --dev
- vendor/tedivm/dovecottesting/SetupEnvironment.sh
-script: phpunit --verbose --coverage-text
\ No newline at end of file
+script: ./tests/runTests.sh
+
+after_script:
+ - php vendor/bin/coveralls -v
+
+matrix:
+ allow_failures:
+ - php: hhvm
\ No newline at end of file
diff --git a/README.md b/README.md
index f397044..836a9d0 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,7 @@
[![Latest Stable Version](https://poser.pugx.org/tedivm/fetch/v/stable.png)](https://packagist.org/packages/tedivm/fetch)
[![Total Downloads](https://poser.pugx.org/tedivm/fetch/downloads.png)](https://packagist.org/packages/tedivm/fetch)
+[![Coverage Status](https://coveralls.io/repos/tedivm/Fetch/badge.png?branch=master)](https://coveralls.io/r/tedivm/Fetch?branch=master)
Fetch is a library for reading email and attachments, primarily using the POP
and IMAP protocols.
diff --git a/autoload.php b/autoload.php
index 7cbce55..97c6b00 100644
--- a/autoload.php
+++ b/autoload.php
@@ -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;
}
-});
\ No newline at end of file
+});
diff --git a/composer.json b/composer.json
index e9f85a0..fad0f80 100644
--- a/composer.json
+++ b/composer.json
@@ -15,7 +15,11 @@
"php": ">=5.3.0"
},
"require-dev": {
- "tedivm/dovecottesting": "1.2.1"
+ "tedivm/dovecottesting": "1.2.2",
+ "phpunit/phpunit": "4.0.*",
+ "fabpot/php-cs-fixer": "0.4.0",
+ "satooshi/php-coveralls": "dev-master"
+
},
"autoload": {
"psr-0": {"Fetch": "src/"}
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 5eec1bf..26aa323 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -11,16 +11,17 @@
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
>
-
./tests
-
./src/Fetch/
+
+
+
diff --git a/src/Fetch/Attachment.php b/src/Fetch/Attachment.php
index 3e6c8c3..96f7082 100644
--- a/src/Fetch/Attachment.php
+++ b/src/Fetch/Attachment.php
@@ -160,7 +160,7 @@ class Attachment
/**
* This function returns the object that contains the structure of this attachment.
- *
+ *
* @return \stdClass
*/
public function getStructure()
diff --git a/src/Fetch/Message.php b/src/Fetch/Message.php
index 3755869..3644c91 100644
--- a/src/Fetch/Message.php
+++ b/src/Fetch/Message.php
@@ -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);
}
}
diff --git a/src/Fetch/Server.php b/src/Fetch/Server.php
index 34a7bf6..17f572a 100644
--- a/src/Fetch/Server.php
+++ b/src/Fetch/Server.php
@@ -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.
*
diff --git a/tests/Fetch/Test/AttachmentTest.php b/tests/Fetch/Test/AttachmentTest.php
index fda5f68..ffec66b 100644
--- a/tests/Fetch/Test/AttachmentTest.php
+++ b/tests/Fetch/Test/AttachmentTest.php
@@ -11,7 +11,6 @@
namespace Fetch\Test;
-
/**
* @package Fetch
* @author Robert Hafner
@@ -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';
diff --git a/tests/Fetch/Test/MessageTest.php b/tests/Fetch/Test/MessageTest.php
index 0547414..de9ce25 100644
--- a/tests/Fetch/Test/MessageTest.php
+++ b/tests/Fetch/Test/MessageTest.php
@@ -12,7 +12,6 @@
namespace Fetch\Test;
use Fetch\Message;
-
/**
* @package Fetch
* @author Robert Hafner
@@ -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
}
-
}
diff --git a/tests/Fetch/Test/ServerTest.php b/tests/Fetch/Test/ServerTest.php
index a4fb072..0d854ad 100644
--- a/tests/Fetch/Test/ServerTest.php
+++ b/tests/Fetch/Test/ServerTest.php
@@ -19,20 +19,22 @@ use Fetch\Server;
*/
class ServerTest extends \PHPUnit_Framework_TestCase
{
+ static $num_messages_inbox = 12;
+
/**
* @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 +48,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 +70,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 +87,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).'),
@@ -95,7 +99,7 @@ class ServerTest extends \PHPUnit_Framework_TestCase
{
$server = Static::getServer();
$numMessages = $server->numMessages();
- $this->assertEquals(11, $numMessages);
+ $this->assertEquals(self::$num_messages_inbox, $numMessages);
}
public function testGetMessages()
@@ -104,7 +108,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 +164,6 @@ class ServerTest extends \PHPUnit_Framework_TestCase
$server->setOptions('purple');
}
-
public function testSetOptions()
{
$server = Static::getServer();
@@ -168,7 +171,6 @@ class ServerTest extends \PHPUnit_Framework_TestCase
$this->assertAttributeEquals(5, 'options', $server);
}
-
public function testExpunge()
{
$server = Static::getServer();
@@ -185,10 +187,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;
}
}
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 7597f3a..3548183 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -17,16 +17,12 @@ 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');
- echo 'Initializing Environment using Vagrant' . PHP_EOL;
- passthru('/bin/bash ' . __DIR__ . '/../vendor/tedivm/dovecottesting/SetupEnvironment.sh');
- echo 'Environment Initialized' . PHP_EOL . PHP_EOL . PHP_EOL;
}
$filename = __DIR__ .'/../vendor/autoload.php';
@@ -38,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__);
-}
\ No newline at end of file
+}
diff --git a/tests/runTests.sh b/tests/runTests.sh
new file mode 100755
index 0000000..d4dc032
--- /dev/null
+++ b/tests/runTests.sh
@@ -0,0 +1,17 @@
+#/usr/bin/env/sh
+set -e
+
+if [ ! -n "$TRAVIS" ]; then
+ ./vendor/tedivm/dovecottesting/SetupEnvironment.sh
+ sleep 5
+fi
+
+echo 'Running unit tests.'
+phpunit --verbose --coverage-clover build/logs/clover.xml
+
+echo ''
+echo ''
+echo ''
+echo 'Testing for Coding Styling Compliance.'
+echo 'All code should follow PSR standards.'
+./vendor/fabpot/php-cs-fixer/php-cs-fixer fix ./ --level="all" -vv --dry-run
\ No newline at end of file