mirror of
https://github.com/retailcrm/Fetch.git
synced 2024-11-25 12:36:01 +03:00
Merge pull request #47 from tedivm/testing_updates
Testing Suite Updates
This commit is contained in:
commit
ec929fb20a
3
.coveralls.yml
Normal file
3
.coveralls.yml
Normal file
@ -0,0 +1,3 @@
|
||||
src_dir: src
|
||||
coverage_clover: build/logs/clover.xml
|
||||
json_path: build/logs/coveralls-upload.json
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,5 +1,4 @@
|
||||
.vagrant
|
||||
|
||||
/.idea
|
||||
/.settings
|
||||
/.buildpath
|
||||
@ -7,3 +6,4 @@
|
||||
/composer.lock
|
||||
/vendor
|
||||
/report
|
||||
/build
|
12
.travis.yml
12
.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
|
||||
script: ./tests/runTests.sh
|
||||
|
||||
after_script:
|
||||
- php vendor/bin/coveralls -v
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- php: hhvm
|
@ -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.
|
||||
|
@ -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) {
|
||||
|
@ -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/"}
|
||||
|
@ -11,16 +11,17 @@
|
||||
syntaxCheck="false"
|
||||
bootstrap="tests/bootstrap.php"
|
||||
>
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="Fetch Test Suite">
|
||||
<directory>./tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory suffix=".php">./src/Fetch/</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
<logging>
|
||||
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false"/>
|
||||
</logging>
|
||||
</phpunit>
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -155,8 +155,11 @@ class Server
|
||||
*/
|
||||
public function setMailBox($mailbox = '')
|
||||
{
|
||||
if(!$this->hasMailBox($mailbox))
|
||||
if (!$this->hasMailBox($mailbox)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$this->mailbox = $mailbox;
|
||||
if (isset($this->imapStream)) {
|
||||
@ -381,13 +384,13 @@ class Server
|
||||
{
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ use Fetch\Server;
|
||||
*/
|
||||
class ServerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
static $num_messages_inbox = 12;
|
||||
|
||||
/**
|
||||
* @dataProvider flagsDataProvider
|
||||
* @param string $expected server string with %host% placeholder
|
||||
@ -47,7 +49,8 @@ class ServerTest extends \PHPUnit_Framework_TestCase
|
||||
$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)),
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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__);
|
||||
}
|
17
tests/runTests.sh
Executable file
17
tests/runTests.sh
Executable file
@ -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
|
Loading…
Reference in New Issue
Block a user