Skip to content

Commit

Permalink
Tests improvements (PHPMailer#1162)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Slamdunk authored and Synchro committed Sep 14, 2017
1 parent dc54e2b commit 9923924
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 40 deletions.
40 changes: 26 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
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:
directories:
- $HOME/.composer
Expand All @@ -20,6 +9,8 @@ before_install:
- sudo apt-get install -y -qq postfix

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
- if [ "$CODE_COVERAGE" != 1 ]; then phpenv config-rm xdebug.ini || true; fi

Expand All @@ -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
fi
script:
- ./vendor/bin/phpunit --configuration ./travis.phpunit.xml.dist
- if [ "$CS_CHECK" = 1 ]; then ./vendor/bin/php-cs-fixer --diff --dry-run --verbose fix; fi
script: ./vendor/bin/phpunit --configuration ./travis.phpunit.xml.dist

after_script:
- 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

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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.2",
"phpdocumentor/phpdocumentor": "2.*",
"phpunit/phpunit": "4.*",
"phpunit/phpunit": "^4.8 || ^5.7",
"zendframework/zend-serializer": "2.7.*",
"doctrine/annotations": "1.2.*",
"zendframework/zend-eventmanager": "3.0.*",
Expand Down
18 changes: 7 additions & 11 deletions test/PHPMailerLangTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,27 @@
* @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.
*/
class PHPMailerLangTest extends \PHPUnit_Framework_TestCase
final class PHPMailerLangTest extends TestCase
{
/**
* Holds a PHPMailer instance.
*
* @var PHPMailer
*/
public $Mail;

/**
* Default include path.
*
* @var string
*/
public $INCLUDE_DIR = '../';
private $Mail;

/**
* Run before each test is started.
*/
public function setUp()
protected function setUp()
{
$this->Mail = new PHPMailer();
}
Expand Down
31 changes: 17 additions & 14 deletions test/PHPMailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,50 @@
* @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.
*/
class PHPMailerTest extends \PHPUnit_Framework_TestCase
final class PHPMailerTest extends TestCase
{
/**
* Holds the PHPMailer instance.
*
* @var PHPMailer
*/
public $Mail;
private $Mail;

/**
* Holds the SMTP mail host.
*
* @var string
*/
public $Host = '';
private $Host = '';

/**
* Holds the change log.
*
* @var string[]
*/
public $ChangeLog = [];
private $ChangeLog = [];

/**
* Holds the note log.
*
* @var string[]
*/
public $NoteLog = [];
private $NoteLog = [];

/**
* Default include path.
*
* @var string
*/
public $INCLUDE_DIR = '..';
private $INCLUDE_DIR = '..';

/**
* PIDs of any processes we need to kill.
Expand All @@ -62,7 +65,7 @@ class PHPMailerTest extends \PHPUnit_Framework_TestCase
/**
* 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
if (file_exists($this->INCLUDE_DIR . '/test/testbootstrap.php')) {
Expand Down Expand Up @@ -117,7 +120,7 @@ public function setUp()
/**
* Run after each test is completed.
*/
public function tearDown()
protected function tearDown()
{
// Clean global variables
$this->Mail = null;
Expand All @@ -133,7 +136,7 @@ public function tearDown()
/**
* Build the body of the message in the appropriate format.
*/
public function buildBody()
private function buildBody()
{
$this->checkChanges();

Expand Down Expand Up @@ -210,7 +213,7 @@ public function buildBody()
/**
* Check which default settings have been changed for the report.
*/
public function checkChanges()
private function checkChanges()
{
if (3 != $this->Mail->Priority) {
$this->addChange('Priority', $this->Mail->Priority);
Expand Down Expand Up @@ -247,7 +250,7 @@ public function checkChanges()
* @param string $sName
* @param string $sNewValue
*/
public function addChange($sName, $sNewValue)
private function addChange($sName, $sNewValue)
{
$this->ChangeLog[] = [$sName, $sNewValue];
}
Expand All @@ -257,7 +260,7 @@ public function addChange($sName, $sNewValue)
*
* @param string $sValue
*/
public function addNote($sValue)
private function addNote($sValue)
{
$this->NoteLog[] = $sValue;
}
Expand All @@ -271,7 +274,7 @@ public function addNote($sValue)
*
* @return bool
*/
public function setAddress($sAddress, $sName = '', $sType = 'to')
private function setAddress($sAddress, $sName = '', $sType = 'to')
{
switch ($sType) {
case 'to':
Expand Down
5 changes: 5 additions & 0 deletions travis.phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
<group>pop3</group>
</exclude>
</groups>
<filter>
<whitelist>
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="true"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
Expand Down

0 comments on commit 9923924

Please sign in to comment.