Tests: move POP before SMTP tests to separate file (#2382)

* Tests/reorganize: move POP before SMTP tests to own file

This also removed the `$pids` property and handling from the PHPMailer base `TestCase` and moves this to the POP test class.

As this test now does not actually need an instantiated PHPMailer object, this class extends the `Yoast\PHPUnitPolyfills\TestCases\TestCase` instead of the `PHPMailer\Test\TestCase`.

* PopBeforeSmtpTest: move `@group` tags

... to the class level and remove them from the individual test functions.

* PopBeforeSmtpTest: various test tweaks

Minor test tweaks:
* Add `@covers` tag at class level.
* Inline comment punctuation.
* Minor code readability tweaks.

Co-authored-by: jrfnl <jrfnl@users.noreply.github.com>
This commit is contained in:
Juliette 2021-06-24 15:22:24 +02:00 committed by GitHub
parent d2780d4125
commit 8317ed0bb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 114 additions and 67 deletions

View File

@ -16,7 +16,6 @@ namespace PHPMailer\Test\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\OAuth;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\POP3;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\Test\TestCase;
@ -1857,60 +1856,6 @@ EOT;
);
}
/**
* Use a fake POP3 server to test POP-before-SMTP auth with a known-good login.
*
* @group pop3
*/
public function testPopBeforeSmtpGood()
{
//Start a fake POP server
$pid = shell_exec(
'/usr/bin/nohup ' .
\PHPMAILER_INCLUDE_DIR .
'/test/runfakepopserver.sh 1100 >/dev/null 2>/dev/null & printf "%u" $!'
);
$this->pids[] = $pid;
sleep(1);
//Test a known-good login
self::assertTrue(
POP3::popBeforeSmtp('localhost', 1100, 10, 'user', 'test'),
'POP before SMTP failed'
);
//Kill the fake server, don't care if it fails
@shell_exec('kill -TERM ' . escapeshellarg($pid));
sleep(2);
}
/**
* Use a fake POP3 server to test POP-before-SMTP auth
* with a known-bad login.
*
* @group pop3
*/
public function testPopBeforeSmtpBad()
{
//Start a fake POP server on a different port
//so we don't inadvertently connect to the previous instance
$pid = shell_exec(
'/usr/bin/nohup ' .
\PHPMAILER_INCLUDE_DIR .
'/test/runfakepopserver.sh 1101 >/dev/null 2>/dev/null & printf "%u" $!'
);
$this->pids[] = $pid;
sleep(2);
//Test a known-bad login
self::assertFalse(
POP3::popBeforeSmtp('localhost', 1101, 10, 'user', 'xxx'),
'POP before SMTP should have failed'
);
//Kill the fake server, don't care if it fails
@shell_exec('kill -TERM ' . escapeshellarg($pid));
sleep(2);
}
/**
* Test SMTP host connections.
* This test can take a long time, so run it last.

View File

@ -0,0 +1,114 @@
<?php
/**
* PHPMailer - PHP email transport unit tests.
* PHP version 5.5.
*
* @author Marcus Bointon <phpmailer@synchromedia.co.uk>
* @author Andy Prevost
* @copyright 2012 - 2020 Marcus Bointon
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
namespace PHPMailer\Test\POP3;
use PHPMailer\PHPMailer\POP3;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;
/**
* Test Pop before Smtp functionality.
*
* @group pop3
*
* @covers PHPMailer\PHPMailer\POP3
*/
final class PopBeforeSmtpTest extends TestCase
{
/**
* PIDs of any processes we need to kill.
*
* @var array
*/
protected $pids = [];
/**
* Run before each test class.
*/
public static function set_up_before_class()
{
if (defined('PHPMAILER_INCLUDE_DIR') === false) {
/*
* Set up default include path.
* Default to the dir above the test dir, i.e. the project home dir.
*/
define('PHPMAILER_INCLUDE_DIR', dirname(__DIR__));
}
}
/**
* Run after each test is completed.
*/
protected function tear_down()
{
foreach ($this->pids as $pid) {
$p = escapeshellarg($pid);
shell_exec("ps $p && kill -TERM $p");
}
}
/**
* Use a fake POP3 server to test POP-before-SMTP auth with a known-good login.
*/
public function testPopBeforeSmtpGood()
{
// Start a fake POP server.
$pid = shell_exec(
'/usr/bin/nohup ' .
\PHPMAILER_INCLUDE_DIR .
'/test/runfakepopserver.sh 1100 >/dev/null 2>/dev/null & printf "%u" $!'
);
$this->pids[] = $pid;
sleep(1);
// Test a known-good login.
self::assertTrue(
POP3::popBeforeSmtp('localhost', 1100, 10, 'user', 'test'),
'POP before SMTP failed'
);
// Kill the fake server, don't care if it fails.
@shell_exec('kill -TERM ' . escapeshellarg($pid));
sleep(2);
}
/**
* Use a fake POP3 server to test POP-before-SMTP auth
* with a known-bad login.
*/
public function testPopBeforeSmtpBad()
{
// Start a fake POP server on a different port,
// so we don't inadvertently connect to the previous instance.
$pid = shell_exec(
'/usr/bin/nohup ' .
\PHPMAILER_INCLUDE_DIR .
'/test/runfakepopserver.sh 1101 >/dev/null 2>/dev/null & printf "%u" $!'
);
$this->pids[] = $pid;
sleep(2);
// Test a known-bad login.
self::assertFalse(
POP3::popBeforeSmtp('localhost', 1101, 10, 'user', 'xxx'),
'POP before SMTP should have failed'
);
// Kill the fake server, don't care if it fails.
@shell_exec('kill -TERM ' . escapeshellarg($pid));
sleep(2);
}
}

View File

@ -50,13 +50,6 @@ abstract class TestCase extends PolyfillTestCase
*/
private $NoteLog = [];
/**
* PIDs of any processes we need to kill.
*
* @var array
*/
protected $pids = [];
/**
* Run before each test class.
*/
@ -143,11 +136,6 @@ abstract class TestCase extends PolyfillTestCase
$this->Mail = null;
$this->ChangeLog = [];
$this->NoteLog = [];
foreach ($this->pids as $pid) {
$p = escapeshellarg($pid);
shell_exec("ps $p && kill -TERM $p");
}
}
/**