diff --git a/test/PHPMailer/PHPMailerTest.php b/test/PHPMailer/PHPMailerTest.php index ffdcc5eb..43af387a 100644 --- a/test/PHPMailer/PHPMailerTest.php +++ b/test/PHPMailer/PHPMailerTest.php @@ -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. diff --git a/test/POP3/PopBeforeSmtpTest.php b/test/POP3/PopBeforeSmtpTest.php new file mode 100644 index 00000000..e34b6000 --- /dev/null +++ b/test/POP3/PopBeforeSmtpTest.php @@ -0,0 +1,114 @@ + + * @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); + } +} diff --git a/test/TestCase.php b/test/TestCase.php index 00161a1b..6f968bca 100644 --- a/test/TestCase.php +++ b/test/TestCase.php @@ -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"); - } } /**