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

Tests improvements (#1162)

* Move tests to proper namespace; enforce signatures

* Travis stages, check coding-standard before tests

* Test against PHP 7.2

* CS Fix

* Remove php-cs-fixer on test builds

* Travis: remove phpdocumentor/phpdocumentor from builds

* Allow PHPUnit 5
This commit is contained in:
Filippo Tessarotto 2017-09-14 18:47:12 +02:00 committed by Marcus Bointon
parent dc54e2b93c
commit 992392437c
5 changed files with 56 additions and 40 deletions

View File

@ -1,16 +1,5 @@
language: php language: php
matrix:
include:
- php: 7.1
env: CODE_COVERAGE=1
- php: 7.0
- php: 5.6
- php: 5.5
env: CS_CHECK=1
- php: hhvm
dist: trusty
cache: cache:
directories: directories:
- $HOME/.composer - $HOME/.composer
@ -20,6 +9,8 @@ before_install:
- sudo apt-get install -y -qq postfix - sudo apt-get install -y -qq postfix
install: install:
- REMOVE_PACKAGE="friendsofphp/php-cs-fixer"; if [ "$CS_CHECK" = 1 ]; then REMOVE_PACKAGE="phpunit/phpunit"; fi; composer remove --no-update --no-scripts --dev $REMOVE_PACKAGE
- composer remove --no-update --no-scripts --dev phpdocumentor/phpdocumentor
- composer install - composer install
- if [ "$CODE_COVERAGE" != 1 ]; then phpenv config-rm xdebug.ini || true; fi - if [ "$CODE_COVERAGE" != 1 ]; then phpenv config-rm xdebug.ini || true; fi
@ -39,10 +30,31 @@ before_script:
echo 'sendmail_path = "/usr/sbin/sendmail -t -i "' > $(php --ini|grep -m 1 "ini files in:"|cut -d ":" -f 2)/sendmail.ini echo 'sendmail_path = "/usr/sbin/sendmail -t -i "' > $(php --ini|grep -m 1 "ini files in:"|cut -d ":" -f 2)/sendmail.ini
fi fi
script: script: ./vendor/bin/phpunit --configuration ./travis.phpunit.xml.dist
- ./vendor/bin/phpunit --configuration ./travis.phpunit.xml.dist
- if [ "$CS_CHECK" = 1 ]; then ./vendor/bin/php-cs-fixer --diff --dry-run --verbose fix; fi
after_script: after_script:
- if [ "$CODE_COVERAGE" = 1 ]; then wget https://scrutinizer-ci.com/ocular.phar; fi - if [ "$CODE_COVERAGE" = 1 ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
- if [ "$CODE_COVERAGE" = 1 ]; then php ocular.phar code-coverage:upload --format=php-clover ../build/logs/clover.xml; fi - if [ "$CODE_COVERAGE" = 1 ]; then php ocular.phar code-coverage:upload --format=php-clover ../build/logs/clover.xml; fi
stages:
- coding-standard
- test
jobs:
include:
- stage: coding-standard
before_install:
before_script:
script: ./vendor/bin/php-cs-fixer --diff --dry-run --verbose fix
after_script:
php: 5.5
env: CS_CHECK=1
- stage: test
php: 5.5
- php: 5.6
- php: 7.0
- php: 7.1
env: CODE_COVERAGE=1
- php: 7.2
- php: hhvm
dist: trusty

View File

@ -26,7 +26,7 @@
"require-dev": { "require-dev": {
"friendsofphp/php-cs-fixer": "^2.2", "friendsofphp/php-cs-fixer": "^2.2",
"phpdocumentor/phpdocumentor": "2.*", "phpdocumentor/phpdocumentor": "2.*",
"phpunit/phpunit": "4.*", "phpunit/phpunit": "^4.8 || ^5.7",
"zendframework/zend-serializer": "2.7.*", "zendframework/zend-serializer": "2.7.*",
"doctrine/annotations": "1.2.*", "doctrine/annotations": "1.2.*",
"zendframework/zend-eventmanager": "3.0.*", "zendframework/zend-eventmanager": "3.0.*",

View File

@ -11,31 +11,27 @@
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/ */
namespace PHPMailer\PHPMailer; namespace PHPMailer\Test;
use PHPMailer\PHPMailer\PHPMailer;
use PHPUnit\Framework\TestCase;
/** /**
* Check language files for missing or excess translations. * Check language files for missing or excess translations.
*/ */
class PHPMailerLangTest extends \PHPUnit_Framework_TestCase final class PHPMailerLangTest extends TestCase
{ {
/** /**
* Holds a PHPMailer instance. * Holds a PHPMailer instance.
* *
* @var PHPMailer * @var PHPMailer
*/ */
public $Mail; private $Mail;
/**
* Default include path.
*
* @var string
*/
public $INCLUDE_DIR = '../';
/** /**
* Run before each test is started. * Run before each test is started.
*/ */
public function setUp() protected function setUp()
{ {
$this->Mail = new PHPMailer(); $this->Mail = new PHPMailer();
} }

View File

@ -10,47 +10,50 @@
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/ */
namespace PHPMailer\PHPMailer; namespace PHPMailer\Test;
use PHPMailer\PHPMailer\PHPMailer;
use PHPUnit\Framework\TestCase;
/** /**
* PHPMailer - PHP email transport unit test class. * PHPMailer - PHP email transport unit test class.
*/ */
class PHPMailerTest extends \PHPUnit_Framework_TestCase final class PHPMailerTest extends TestCase
{ {
/** /**
* Holds the PHPMailer instance. * Holds the PHPMailer instance.
* *
* @var PHPMailer * @var PHPMailer
*/ */
public $Mail; private $Mail;
/** /**
* Holds the SMTP mail host. * Holds the SMTP mail host.
* *
* @var string * @var string
*/ */
public $Host = ''; private $Host = '';
/** /**
* Holds the change log. * Holds the change log.
* *
* @var string[] * @var string[]
*/ */
public $ChangeLog = []; private $ChangeLog = [];
/** /**
* Holds the note log. * Holds the note log.
* *
* @var string[] * @var string[]
*/ */
public $NoteLog = []; private $NoteLog = [];
/** /**
* Default include path. * Default include path.
* *
* @var string * @var string
*/ */
public $INCLUDE_DIR = '..'; private $INCLUDE_DIR = '..';
/** /**
* PIDs of any processes we need to kill. * PIDs of any processes we need to kill.
@ -62,7 +65,7 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
/** /**
* Run before each test is started. * Run before each test is started.
*/ */
public function setUp() protected function setUp()
{ {
$this->INCLUDE_DIR = dirname(__DIR__); //Default to the dir above the test dir, i.e. the project home dir $this->INCLUDE_DIR = dirname(__DIR__); //Default to the dir above the test dir, i.e. the project home dir
if (file_exists($this->INCLUDE_DIR . '/test/testbootstrap.php')) { if (file_exists($this->INCLUDE_DIR . '/test/testbootstrap.php')) {
@ -117,7 +120,7 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
/** /**
* Run after each test is completed. * Run after each test is completed.
*/ */
public function tearDown() protected function tearDown()
{ {
// Clean global variables // Clean global variables
$this->Mail = null; $this->Mail = null;
@ -133,7 +136,7 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
/** /**
* Build the body of the message in the appropriate format. * Build the body of the message in the appropriate format.
*/ */
public function buildBody() private function buildBody()
{ {
$this->checkChanges(); $this->checkChanges();
@ -210,7 +213,7 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
/** /**
* Check which default settings have been changed for the report. * Check which default settings have been changed for the report.
*/ */
public function checkChanges() private function checkChanges()
{ {
if (3 != $this->Mail->Priority) { if (3 != $this->Mail->Priority) {
$this->addChange('Priority', $this->Mail->Priority); $this->addChange('Priority', $this->Mail->Priority);
@ -247,7 +250,7 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
* @param string $sName * @param string $sName
* @param string $sNewValue * @param string $sNewValue
*/ */
public function addChange($sName, $sNewValue) private function addChange($sName, $sNewValue)
{ {
$this->ChangeLog[] = [$sName, $sNewValue]; $this->ChangeLog[] = [$sName, $sNewValue];
} }
@ -257,7 +260,7 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
* *
* @param string $sValue * @param string $sValue
*/ */
public function addNote($sValue) private function addNote($sValue)
{ {
$this->NoteLog[] = $sValue; $this->NoteLog[] = $sValue;
} }
@ -271,7 +274,7 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
* *
* @return bool * @return bool
*/ */
public function setAddress($sAddress, $sName = '', $sType = 'to') private function setAddress($sAddress, $sName = '', $sType = 'to')
{ {
switch ($sType) { switch ($sType) {
case 'to': case 'to':

View File

@ -26,6 +26,11 @@
<group>pop3</group> <group>pop3</group>
</exclude> </exclude>
</groups> </groups>
<filter>
<whitelist>
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<logging> <logging>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="true"/> <log type="coverage-text" target="php://stdout" showUncoveredFiles="true"/>
<log type="coverage-clover" target="build/logs/clover.xml"/> <log type="coverage-clover" target="build/logs/clover.xml"/>