<commit_before><?php
require_once 'PHPUnit/Framework.php';
require_once 'lib/Smtp.php';
require_once 'lib/Message.php';

use Mail\Message;
use Mail\Protocol\Smtp;
use Mail\Protocol\Smtp_Exception;

class SmtpTest extends PHPUnit_Framework_TestCase
{
	protected $_connection;

	public function setUp()
	{
		$config = array(
		  'host'	 => TESTS_MAIL_SMTP_HOST,
		  'port'	 => TESTS_MAIL_SMTP_SUBMISSION_PORT,
		  'ssl_mode' => 'tls'
		);

		$this->_connection = new Smtp($config);
		if ($this->_connection->isConnected() === false) {
			$this->_connection->connect();
		}
	}

	public function tearDown()
	{
		if ($this->_connection->isConnected() === true) {
			$this->_connection->close();
		}
	}

	public function testSmtpTCPConnection()
	{
		$config = array(
		  'host' => TESTS_MAIL_SMTP_HOST,
		  'port' => TESTS_MAIL_SMTP_PORT,
		);

		$this->_connection = new Smtp($config);
		$this->assertFalse(
		  $this->_connection->isConnected()
		);
		$this->_connection->connect();
		$this->assertTrue(
		  $this->_connection->isConnected()
		);
		$this->assertTrue(
		  $this->_connection->noop()
		);
		$this->_connection->close();
	}

	public function testSmtpTLSConnection()
	{
		$config = array(
		  'host'	 => TESTS_MAIL_SMTP_HOST,
		  'port'	 => TESTS_MAIL_SMTP_SUBMISSION_PORT,
		  'ssl_mode' => 'tls'
		);

		$this->_connection = new Smtp($config);
		$this->assertFalse(
		  $this->_connection->isConnected()
		);
		$this->_connection->connect();
		$this->assertTrue(
		  $this->_connection->isConnected()
		);
		$this->assertTrue(
		  $this->_connection->noop()
		);
		$this->_connection->close();
	}

	public function testSmtpSSLConnection()
	{
		$config = array(
		  'host'	 => TESTS_MAIL_SMTP_HOST,
		  'port'	 => TESTS_MAIL_SMTP_SSL_PORT,
		  'ssl_mode' => 'ssl'
		);

		$this->_connection = new Smtp($config);
		$this->assertFalse(
		  $this->_connection->isConnected()
		);
		$this->_connection->connect();
		$this->assertTrue(
		  $this->_connection->isConnected()
		);
		$this->assertTrue(
		  $this->_connection->noop()
		);
		$this->_connection->close();
	}

	public function testSmtpHeloCommand()
	{
		$this->assertTrue(
		  $this->_connection->helo(TESTS_MAIL_SMTP_HOST)
		);
	}

	public function testSmtpEhloCommand()
	{
		$this->assertType(
		  'array', $this->_connection->ehlo(TESTS_MAIL_SMTP_HOST)
		);
	}

	public function testSmtpAuthPlain()
	{
		$this->_connection->helo(TESTS_MAIL_SMTP_HOST);
		$this->assertTrue(
		  $this->_connection->authenticate(
		    TESTS_MAIL_SMTP_USER, TESTS_MAIL_SMTP_PASSWORD, 'plain'
		));
	}

	public function testSmtpAuthLogin()
	{
		$this->_connection->helo(TESTS_MAIL_SMTP_HOST);
		$this->assertTrue(
		  $this->_connection->authenticate(
		    TESTS_MAIL_SMTP_USER, TESTS_MAIL_SMTP_PASSWORD, 'login'
		));
	}

	public function testSmtpAutoPlainFail()
	{
		$this->_connection->helo(TESTS_MAIL_SMTP_HOST); try {
			$this->_connection->authenticate('wrong', 'wrong', 'plain');
		}
		catch (Smtp_Exception $e) {
			return;<commit_msg>Fixed typo.<commit_after><?php
require_once 'PHPUnit/Framework.php';
require_once 'lib/Smtp.php';
require_once 'lib/Message.php';

use Mail\Message;
use Mail\Protocol\Smtp;
use Mail\Protocol\Smtp_Exception;

class SmtpTest extends PHPUnit_Framework_TestCase
{
	protected $_connection;

	public function setUp()
	{
		$config = array(
		  'host'	 => TESTS_MAIL_SMTP_HOST,
		  'port'	 => TESTS_MAIL_SMTP_SUBMISSION_PORT,
		  'ssl_mode' => 'tls'
		);

		$this->_connection = new Smtp($config);
		if ($this->_connection->isConnected() === false) {
			$this->_connection->connect();
		}
	}

	public function tearDown()
	{
		if ($this->_connection->isConnected() === true) {
			$this->_connection->close();
		}
	}

	public function testSmtpTCPConnection()
	{
		$config = array(
		  'host' => TESTS_MAIL_SMTP_HOST,
		  'port' => TESTS_MAIL_SMTP_PORT,
		);

		$this->_connection = new Smtp($config);
		$this->assertFalse(
		  $this->_connection->isConnected()
		);
		$this->_connection->connect();
		$this->assertTrue(
		  $this->_connection->isConnected()
		);
		$this->assertTrue(
		  $this->_connection->noop()
		);
		$this->_connection->close();
	}

	public function testSmtpTLSConnection()
	{
		$config = array(
		  'host'	 => TESTS_MAIL_SMTP_HOST,
		  'port'	 => TESTS_MAIL_SMTP_SUBMISSION_PORT,
		  'ssl_mode' => 'tls'
		);

		$this->_connection = new Smtp($config);
		$this->assertFalse(
		  $this->_connection->isConnected()
		);
		$this->_connection->connect();
		$this->assertTrue(
		  $this->_connection->isConnected()
		);
		$this->assertTrue(
		  $this->_connection->noop()
		);
		$this->_connection->close();
	}

	public function testSmtpSSLConnection()
	{
		$config = array(
		  'host'	 => TESTS_MAIL_SMTP_HOST,
		  'port'	 => TESTS_MAIL_SMTP_SSL_PORT,
		  'ssl_mode' => 'ssl'
		);

		$this->_connection = new Smtp($config);
		$this->assertFalse(
		  $this->_connection->isConnected()
		);
		$this->_connection->connect();
		$this->assertTrue(
		  $this->_connection->isConnected()
		);
		$this->assertTrue(
		  $this->_connection->noop()
		);
		$this->_connection->close();
	}

	public function testSmtpHeloCommand()
	{
		$this->assertTrue(
		  $this->_connection->helo(TESTS_MAIL_SMTP_HOST)
		);
	}

	public function testSmtpEhloCommand()
	{
		$this->assertType(
		  'array', $this->_connection->ehlo(TESTS_MAIL_SMTP_HOST)
		);
	}

	public function testSmtpAuthPlain()
	{
		$this->_connection->helo(TESTS_MAIL_SMTP_HOST);
		$this->assertTrue(
		  $this->_connection->authenticate(
		    TESTS_MAIL_SMTP_USER, TESTS_MAIL_SMTP_PASSWORD, 'plain'
		));
	}

	public function testSmtpAuthLogin()
	{
		$this->_connection->helo(TESTS_MAIL_SMTP_HOST);
		$this->assertTrue(
		  $this->_connection->authenticate(
		    TESTS_MAIL_SMTP_USER, TESTS_MAIL_SMTP_PASSWORD, 'login'
		));
	}

	public function testSmtpAuthPlainFail()
	{
		$this->_connection->helo(TESTS_MAIL_SMTP_HOST); try {
			$this->_connection->authenticate('wrong', 'wrong', 'plain');
		}
		catch (Smtp_Exception $e) {
			return;
{'fraction_non_alphanumeric': 0.1669451871657754, 'fraction_numerical': 0.0, 'mean_word_length': 4.2088772845953, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 167, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4396489', 'n_tokens_mistral': 2445, 'n_tokens_neox': 2219, 'n_words': 298}