0
0
mirror of https://github.com/PHPMailer/PHPMailer.git synced 2024-09-20 01:52:15 +02:00

Add config for scrutinizer

This commit is contained in:
Synchro 2013-12-16 14:28:57 +01:00
parent 38fc062458
commit 379b700e77
12 changed files with 200 additions and 290 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ docs/phpdoc/
test/message.txt
test/testbootstrap.php
.idea
build/

126
.scrutinizer.yml Normal file
View File

@ -0,0 +1,126 @@
before_commands:
- "composer install --prefer-source"
tools:
# Code Coverage
external_code_coverage:
enabled: true
timeout: 300
filter:
excluded_paths:
- 'docs/*'
- 'examples/*'
- 'extras/*'
- 'test/*'
- 'vendor/*'
php_code_coverage:
enabled: false
test_command: phpunit
filter:
excluded_paths:
- 'docs/*'
- 'examples/*'
- 'extras/*'
- 'test/*'
- 'vendor/*'
# Code Sniffer
php_code_sniffer:
enabled: true
command: phpcs
config:
standard: PSR2
filter:
excluded_paths:
- 'docs/*'
- 'examples/*'
- 'extras/*'
- 'test/*'
- 'vendor/*'
# Copy/Paste Detector
php_cpd:
enabled: true
command: phpcpd
excluded_dirs:
- docs
- examples
- extras
- test
- vendor
# PHP CS Fixer (http://http://cs.sensiolabs.org/).
php_cs_fixer:
enabled: true
command: php-cs-fixer
config:
level: psr2
filter:
excluded_paths:
- 'docs/*'
- 'examples/*'
- 'extras/*'
- 'test/*'
- 'vendor/*'
# Analyzes the size and structure of a PHP project.
php_loc:
enabled: true
command: phploc
excluded_dirs:
- docs
- examples
- extras
- test
- vendor
# PHP Mess Detector (http://phpmd.org).
php_mess_detector:
enabled: true
command: phpmd
config:
rulesets:
- codesize
- unusedcode
- naming
- design
filter:
excluded_paths:
- 'docs/*'
- 'examples/*'
- 'extras/*'
- 'test/*'
- 'vendor/*'
# Analyzes the size and structure of a PHP project.
php_pdepend:
enabled: true
command: pdepend
excluded_dirs:
- docs
- examples
- extras
- test
- vendor
# Runs Scrutinizer's PHP Analyzer Tool
php_analyzer:
enabled: true
filter:
excluded_paths:
- 'docs/*'
- 'examples/*'
- 'extras/*'
- 'test/*'
- 'vendor/*'
# Security Advisory Checker
sensiolabs_security_checker: true

View File

@ -9,6 +9,7 @@ before_install:
before_script:
- sudo service postfix stop
- smtp-sink -d "%d.%H.%M.%S" localhost:2500 1000 &
- mkdir -p build/logs
- cd test
- cp testbootstrap-dist.php testbootstrap.php
- chmod +x fakesendmail.sh
@ -16,5 +17,10 @@ before_script:
- sudo cp fakesendmail.sh /var/qmail/bin/sendmail
- sudo cp fakesendmail.sh /usr/sbin/sendmail
- echo 'sendmail_path = "/usr/sbin/sendmail -t -i "' | sudo tee "/home/travis/.phpenv/versions/`php -i|grep "PHP Version"|head -n 1|grep -o -P '\d+\.\d+\.\d+.*'`/etc/conf.d/sendmail.ini"
- pwd
- ls -al
script:
- phpunit phpmailerTest
- phpunit --configuration ../travis.phpunit.xml.dist
after_script:
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover ../build/logs/clover.xml

View File

@ -38,7 +38,10 @@ if (version_compare(PHP_VERSION, '5.1.2', '>=')) {
spl_autoload_register('PHPMailerAutoload');
}
} else {
//Fall back to traditional autoload for old PHP versions
/**
* Fall back to traditional autoload for old PHP versions
* @param string $classname The name of the class to load
*/
function __autoload($classname)
{
PHPMailerAutoload($classname);

View File

@ -1,6 +1,8 @@
# PHPMailer - A full-featured email creation and transfer class for PHP
Build status: [![Build Status](https://travis-ci.org/Synchro/PHPMailer.png)](https://travis-ci.org/Synchro/PHPMailer)
[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/Synchro/PHPMailer/badges/quality-score.png?s=320d104c5f7ae0bdb10abd98ea04e0cb107fe905)](https://scrutinizer-ci.com/g/Synchro/PHPMailer/)
[![Code Coverage](https://scrutinizer-ci.com/g/Synchro/PHPMailer/badges/coverage.png?s=4a55049051633406197503e4f66cc8eeb224c9a4)](https://scrutinizer-ci.com/g/Synchro/PHPMailer/)
## Class Features

View File

@ -396,11 +396,7 @@ class PHPMailer
* The function that handles the result of the send email action.
* It is called out by send() for each email sent.
*
* Value can be:
* - 'function_name' for function names
* - 'Class::Method' for static method calls
* - array($object, 'Method') for calling methods on $object
* See http://php.net/is_callable manual page for more details.
* Value can be any php callable: http://www.php.net/is_callable
*
* Parameters:
* bool $result result of the send action
@ -410,7 +406,6 @@ class PHPMailer
* string $subject the subject
* string $body the email body
* string $from email address of sender
*
* @type string
*/
public $action_function = '';

View File

@ -1,5 +1,5 @@
#!/bin/sh
# Regenerate PHPMailer documentation
# Run from within the docs folder
rm -rf phpdocs/*
phpdoc --directory .. --target ./phpdoc --ignore test/,examples/,extras/,test_script/ --sourcecode --force --title PHPMailer
rm -rf phpdoc/*
phpdoc --directory .. --target ./phpdoc --ignore test/,examples/,extras/,test_script/ --sourcecode --force --title PHPMailer --template="clean"

View File

@ -21,4 +21,4 @@ $PHPMAILER_LANG['recipients_failed'] = 'SMTP Feil: Følgende mottagere feilet
$PHPMAILER_LANG['signing'] = 'Signeringsfeil: ';
$PHPMAILER_LANG['smtp_connect_failed'] = 'SMTP Connect() feilet.';
$PHPMAILER_LANG['smtp_error'] = 'SMTP-serverfeil: ';
$PHPMAILER_LANG['variable_set'] = 'Kan ikke sette eller resette variabelen: ';
$PHPMAILER_LANG['variable_set'] = 'Kan ikke sette eller resette variabelen: ';

5
test/bootstrap.php Normal file
View File

@ -0,0 +1,5 @@
<?php
require_once 'vendor/autoload.php';
spl_autoload_register(function ($class) {
require_once strtr($class, '\\_', '//').'.php';
});

View File

@ -1,18 +1,20 @@
<?php
/**
* PHPMailer - language file tests
* Before running these tests you need to install PHPUnit 3.3 or later through pear, like this:
* pear install "channel://pear.phpunit.de/PHPUnit"
* Then run the tests like this:
* phpunit phpmailerLangTest
* Requires PHPUnit 3.3 or later.
*
* PHP version 5.0.0
*
* @package PHPMailer
* @author Andy Prevost
* @author Marcus Bointon
* @author Marcus Bointon <phpmailer@synchromedia.co.uk>
* @copyright 2004 - 2009 Andy Prevost
* @copyright 2010 Marcus Bointon
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
require 'PHPUnit/Autoload.php';
require_once 'PHPUnit/Autoload.php';
require_once '../PHPMailerAutoload.php';
/**
* PHPMailer - PHP email transport unit test class
@ -21,33 +23,12 @@ require 'PHPUnit/Autoload.php';
class PHPMailerLangTest extends PHPUnit_Framework_TestCase
{
/**
* Holds the default phpmailer instance.
* Holds a phpmailer instance.
* @private
* @var PHPMailer
*/
public $Mail;
/**
* Holds the SMTP mail host.
* @public
* @var string
*/
public $Host = "";
/**
* Holds the change log.
* @private
* @var string[]
*/
public $ChangeLog = array();
/**
* Holds the note log.
* @private
* @var string[]
*/
public $NoteLog = array();
/**
* @var string Default include path
*/
@ -58,231 +39,13 @@ class PHPMailerLangTest extends PHPUnit_Framework_TestCase
*/
public function setUp()
{
if (file_exists('./testbootstrap.php')) {
include './testbootstrap.php'; //Overrides go in here
}
require_once $this->INCLUDE_DIR . 'class.phpmailer.php';
$this->Mail = new PHPMailer;
$this->Mail->Priority = 3;
$this->Mail->Encoding = "8bit";
$this->Mail->CharSet = "iso-8859-1";
if (array_key_exists('mail_from', $_REQUEST)) {
$this->Mail->From = $_REQUEST['mail_from'];
} else {
$this->Mail->From = 'unit_test@phpmailer.example.com';
}
$this->Mail->FromName = "Unit Tester";
$this->Mail->Sender = "";
$this->Mail->Subject = "Unit Test";
$this->Mail->Body = "";
$this->Mail->AltBody = "";
$this->Mail->WordWrap = 0;
if (array_key_exists('mail_host', $_REQUEST)) {
$this->Mail->Host = $_REQUEST['mail_host'];
} else {
$this->Mail->Host = 'mail.example.com';
}
if (array_key_exists('mail_port', $_REQUEST)) {
$this->Mail->Port = $_REQUEST['mail_port'];
} else {
$this->Mail->Port = 25;
}
$this->Mail->Helo = "localhost.localdomain";
$this->Mail->SMTPAuth = false;
$this->Mail->Username = "";
$this->Mail->Password = "";
$this->Mail->PluginDir = $this->INCLUDE_DIR;
$this->Mail->addReplyTo("no_reply@phpmailer.example.com", "Reply Guy");
$this->Mail->Sender = "unit_test@phpmailer.example.com";
if (strlen($this->Mail->Host) > 0) {
$this->Mail->Mailer = "smtp";
} else {
$this->Mail->Mailer = "mail";
$this->Mail->Sender = "unit_test@phpmailer.example.com";
}
if (array_key_exists('mail_to', $_REQUEST)) {
$this->setAddress($_REQUEST['mail_to'], 'Test User', 'to');
}
if (array_key_exists('mail_cc', $_REQUEST) and strlen($_REQUEST['mail_cc']) > 0) {
$this->setAddress($_REQUEST['mail_cc'], 'Carbon User', 'cc');
}
}
/**
* Run after each test is completed.
*/
public function tearDown()
{
// Clean global variables
$this->Mail = null;
$this->ChangeLog = array();
$this->NoteLog = array();
}
/**
* Build the body of the message in the appropriate format.
* @private
* @returns void
*/
public function buildBody()
{
$this->CheckChanges();
// Determine line endings for message
if ($this->Mail->ContentType == "text/html" || strlen($this->Mail->AltBody) > 0) {
$eol = "<br/>";
$bullet = "<li>";
$bullet_start = "<ul>";
$bullet_end = "</ul>";
} else {
$eol = "\n";
$bullet = " - ";
$bullet_start = "";
$bullet_end = "";
}
$ReportBody = "";
$ReportBody .= "---------------------" . $eol;
$ReportBody .= "Unit Test Information" . $eol;
$ReportBody .= "---------------------" . $eol;
$ReportBody .= "phpmailer version: " . $this->Mail->Version . $eol;
$ReportBody .= "Content Type: " . $this->Mail->ContentType . $eol;
if (strlen($this->Mail->Host) > 0) {
$ReportBody .= "Host: " . $this->Mail->Host . $eol;
}
// If attachments then create an attachment list
$attachments = $this->Mail->getAttachments();
if (count($attachments) > 0) {
$ReportBody .= "Attachments:" . $eol;
$ReportBody .= $bullet_start;
foreach ($attachments as $attachment) {
$ReportBody .= $bullet . "Name: " . $attachment[1] . ", ";
$ReportBody .= "Encoding: " . $attachment[3] . ", ";
$ReportBody .= "Type: " . $attachment[4] . $eol;
}
$ReportBody .= $bullet_end . $eol;
}
// If there are changes then list them
if (count($this->ChangeLog) > 0) {
$ReportBody .= "Changes" . $eol;
$ReportBody .= "-------" . $eol;
$ReportBody .= $bullet_start;
for ($i = 0; $i < count($this->ChangeLog); $i++) {
$ReportBody .= $bullet . $this->ChangeLog[$i][0] . " was changed to [" .
$this->ChangeLog[$i][1] . "]" . $eol;
}
$ReportBody .= $bullet_end . $eol . $eol;
}
// If there are notes then list them
if (count($this->NoteLog) > 0) {
$ReportBody .= "Notes" . $eol;
$ReportBody .= "-----" . $eol;
$ReportBody .= $bullet_start;
for ($i = 0; $i < count($this->NoteLog); $i++) {
$ReportBody .= $bullet . $this->NoteLog[$i] . $eol;
}
$ReportBody .= $bullet_end;
}
// Re-attach the original body
$this->Mail->Body .= $eol . $eol . $ReportBody;
}
/**
* Check which default settings have been changed for the report.
* @private
* @returns void
*/
public function checkChanges()
{
if ($this->Mail->Priority != 3) {
$this->addChange("Priority", $this->Mail->Priority);
}
if ($this->Mail->Encoding != "8bit") {
$this->addChange("Encoding", $this->Mail->Encoding);
}
if ($this->Mail->CharSet != "iso-8859-1") {
$this->addChange("CharSet", $this->Mail->CharSet);
}
if ($this->Mail->Sender != "") {
$this->addChange("Sender", $this->Mail->Sender);
}
if ($this->Mail->WordWrap != 0) {
$this->addChange("WordWrap", $this->Mail->WordWrap);
}
if ($this->Mail->Mailer != "mail") {
$this->addChange("Mailer", $this->Mail->Mailer);
}
if ($this->Mail->Port != 25) {
$this->addChange("Port", $this->Mail->Port);
}
if ($this->Mail->Helo != "localhost.localdomain") {
$this->addChange("Helo", $this->Mail->Helo);
}
if ($this->Mail->SMTPAuth) {
$this->addChange("SMTPAuth", "true");
}
}
/**
* Add a changelog entry.
* @access private
* @param string $sName
* @param string $sNewValue
* @return void
*/
public function addChange($sName, $sNewValue)
{
$this->ChangeLog[] = array($sName, $sNewValue);
}
/**
* Adds a simple note to the message.
* @public
* @param string $sValue
* @return void
*/
public function addNote($sValue)
{
$this->NoteLog[] = $sValue;
}
/**
* Adds all of the addresses
* @access public
* @param string $sAddress
* @param string $sName
* @param string $sType
* @return boolean
*/
public function setAddress($sAddress, $sName = '', $sType = 'to')
{
switch ($sType) {
case 'to':
return $this->Mail->addAddress($sAddress, $sName);
case 'cc':
return $this->Mail->addCC($sAddress, $sName);
case "bcc":
return $this->Mail->addBCC($sAddress, $sName);
}
return false;
}
/**
* Test language files for missing and excess translations
* All languages are compared with English
* @group languages
*/
public function testTranslations()
{
@ -312,29 +75,3 @@ class PHPMailerLangTest extends PHPUnit_Framework_TestCase
$this->assertEmpty($err, $err);
}
}
/**
* This is a sample form for setting appropriate test values through a browser
* These values can also be set using a file called testbootstrap.php (not in svn) in the same folder as this script
* which is probably more useful if you run these tests a lot
* <html>
* <body>
* <h3>phpmailer Unit Test</h3>
* By entering a SMTP hostname it will automatically perform tests with SMTP.
*
* <form name="phpmailer_unit" action=__FILE__ method="get">
* <input type="hidden" name="submitted" value="1"/>
* From Address: <input type="text" size="50" name="mail_from" value="<?php echo get("mail_from"); ?>"/>
* <br/>
* To Address: <input type="text" size="50" name="mail_to" value="<?php echo get("mail_to"); ?>"/>
* <br/>
* Cc Address: <input type="text" size="50" name="mail_cc" value="<?php echo get("mail_cc"); ?>"/>
* <br/>
* SMTP Hostname: <input type="text" size="50" name="mail_host" value="<?php echo get("mail_host"); ?>"/>
* <p/>
* <input type="submit" value="Run Test"/>
*
* </form>
* </body>
* </html>
*/

View File

@ -1,10 +1,7 @@
<?php
/**
* PHPMailer - PHP email transport unit tests
* Requires PHPUnit 3.3 or later. Install like this:
* pear install "channel://pear.phpunit.de/PHPUnit"
* Then run the tests like this:
* phpunit phpmailerTest
* Requires PHPUnit 3.3 or later.
*
* PHP version 5.0.0
*
@ -12,11 +9,12 @@
* @author Andy Prevost
* @author Marcus Bointon <phpmailer@synchromedia.co.uk>
* @copyright 2004 - 2009 Andy Prevost
* @copyright 2010 Marcus Bointon
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
require 'PHPUnit/Autoload.php';
require '../PHPMailerAutoload.php';
require_once 'PHPUnit/Autoload.php';
require_once '../PHPMailerAutoload.php';
/**
* PHPMailer - PHP email transport unit test class
@ -990,6 +988,8 @@ EOT;
$this->Mail->Subject = $subject . ': qmail';
$this->Mail->IsQmail();
$this->assertTrue($this->Mail->Send(), $this->Mail->ErrorInfo);
} else {
$this->markTestSkipped('Qmail is not installed');
}
}

35
travis.phpunit.xml.dist Normal file
View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
verbose="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
colors="false"
forceCoversAnnotation="false"
strict="false"
processIsolation="false">
<testsuites>
<testsuite name="PHPMailer Tests">
<directory>./test/</directory>
</testsuite>
</testsuites>
<filter>
<blacklist>
<directory suffix=".php">./extras</directory>
</blacklist>
</filter>
<groups>
<exclude>
<group>languages</group>
</exclude>
</groups>
<logging>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="true"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false"/>
</logging>
</phpunit>