Skip to content

Commit

Permalink
Show debug log only when tests fail (PHPMailer#1161)
Browse files Browse the repository at this point in the history
  • Loading branch information
Slamdunk authored and Synchro committed Sep 14, 2017
1 parent 18a34ad commit dc54e2b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ before_script:
fi
script:
- ./vendor/bin/phpunit --configuration ./travis.phpunit.xml.dist --bootstrap ./vendor/autoload.php
- ./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:
Expand Down
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,10 @@
"PHPMailer\\PHPMailer\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"PHPMailer\\Test\\": "test/"
}
},
"license": "LGPL-2.1"
}
39 changes: 39 additions & 0 deletions test/DebugLogTestListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* PHPMailer - language file tests.
*
* PHP version 5.5.
*
* @author Marcus Bointon <phpmailer@synchromedia.co.uk>
* @author Andy Prevost
* @copyright 2010 - 2017 Marcus Bointon
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/

namespace PHPMailer\Test;

class DebugLogTestListener extends \PHPUnit_Framework_BaseTestListener
{
private static $debugLog = '';

public function addError(\PHPUnit_Framework_Test $test, \Exception $e, $time)
{
echo self::$debugLog;
}

public function addFailure(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_AssertionFailedError $e, $time)
{
echo self::$debugLog;
}

public function startTest(\PHPUnit_Framework_Test $test)
{
self::$debugLog = '';
}

public static function debugLog($str)
{
self::$debugLog .= $str . PHP_EOL;
}
}
1 change: 1 addition & 0 deletions test/PHPMailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function setUp()
}
$this->Mail = new PHPMailer();
$this->Mail->SMTPDebug = 3; //Full debug output
$this->Mail->Debugoutput = ['PHPMailer\Test\DebugLogTestListener', 'debugLog'];
$this->Mail->Priority = 3;
$this->Mail->Encoding = '8bit';
$this->Mail->CharSet = 'iso-8859-1';
Expand Down
6 changes: 5 additions & 1 deletion travis.phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
bootstrap="vendor/autoload.php"
verbose="false"
stopOnError="false"
stopOnFailure="false"
Expand All @@ -8,14 +9,17 @@
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
colors="false"
colors="true"
forceCoversAnnotation="false"
processIsolation="false">
<testsuites>
<testsuite name="PHPMailer Tests">
<directory>./test/</directory>
</testsuite>
</testsuites>
<listeners>
<listener class="PHPMailer\Test\DebugLogTestListener" />
</listeners>
<groups>
<exclude>
<group>languages</group>
Expand Down

0 comments on commit dc54e2b

Please sign in to comment.