<?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;
final class PopBeforeSmtpTest extends TestCase
{
protected $pids = [];
public static function set_up_before_class()
{
if (defined('PHPMAILER_INCLUDE_DIR') === false) {
define('PHPMAILER_INCLUDE_DIR', dirname(__DIR__));
}
}
protected function set_up()
{
if (DIRECTORY_SEPARATOR === '\\') {
$this->markTestSkipped('This test needs a non-Windows OS to run');
}
}
protected function tear_down()
{
foreach ($this->pids as $pid) {
$p = escapeshellarg($pid);
shell_exec("ps $p && kill -TERM $p");
}
}
public function testPopBeforeSmtpGood()
{
$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);
self::assertTrue(
POP3::popBeforeSmtp('localhost', 1100, 10, 'user', 'test'),
'POP before SMTP failed'
);
@shell_exec('kill -TERM ' . escapeshellarg($pid));
sleep(2);
}
public function testPopBeforeSmtpBad()
{
$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);
self::assertFalse(
POP3::popBeforeSmtp('localhost', 1101, 10, 'user', 'xxx'),
'POP before SMTP should have failed'
);
@shell_exec('kill -TERM ' . escapeshellarg($pid));
sleep(2);
}
}