summaryrefslogtreecommitdiff
path: root/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Transport/StreamBuffer
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Transport/StreamBuffer')
-rw-r--r--vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Transport/StreamBuffer/AbstractStreamBufferAcceptanceTest.php131
-rw-r--r--vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Transport/StreamBuffer/BasicSocketAcceptanceTest.php33
-rw-r--r--vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Transport/StreamBuffer/ProcessAcceptanceTest.php26
-rw-r--r--vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Transport/StreamBuffer/SocketTimeoutTest.php67
-rw-r--r--vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Transport/StreamBuffer/SslSocketAcceptanceTest.php40
-rw-r--r--vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Transport/StreamBuffer/TlsSocketAcceptanceTest.php39
6 files changed, 336 insertions, 0 deletions
diff --git a/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Transport/StreamBuffer/AbstractStreamBufferAcceptanceTest.php b/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Transport/StreamBuffer/AbstractStreamBufferAcceptanceTest.php
new file mode 100644
index 0000000..21abc13
--- /dev/null
+++ b/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Transport/StreamBuffer/AbstractStreamBufferAcceptanceTest.php
@@ -0,0 +1,131 @@
+<?php
+
+abstract class Swift_Transport_StreamBuffer_AbstractStreamBufferAcceptanceTest extends \PHPUnit_Framework_TestCase
+{
+ protected $_buffer;
+
+ abstract protected function _initializeBuffer();
+
+ protected function setUp()
+ {
+ if (true == getenv('TRAVIS')) {
+ $this->markTestSkipped(
+ 'Will fail on travis-ci if not skipped due to travis blocking '.
+ 'socket mailing tcp connections.'
+ );
+ }
+
+ $this->_buffer = new Swift_Transport_StreamBuffer(
+ $this->getMockBuilder('Swift_ReplacementFilterFactory')->getMock()
+ );
+ }
+
+ public function testReadLine()
+ {
+ $this->_initializeBuffer();
+
+ $line = $this->_buffer->readLine(0);
+ $this->assertRegExp('/^[0-9]{3}.*?\r\n$/D', $line);
+ $seq = $this->_buffer->write("QUIT\r\n");
+ $this->assertTrue((bool) $seq);
+ $line = $this->_buffer->readLine($seq);
+ $this->assertRegExp('/^[0-9]{3}.*?\r\n$/D', $line);
+ $this->_buffer->terminate();
+ }
+
+ public function testWrite()
+ {
+ $this->_initializeBuffer();
+
+ $line = $this->_buffer->readLine(0);
+ $this->assertRegExp('/^[0-9]{3}.*?\r\n$/D', $line);
+
+ $seq = $this->_buffer->write("HELO foo\r\n");
+ $this->assertTrue((bool) $seq);
+ $line = $this->_buffer->readLine($seq);
+ $this->assertRegExp('/^[0-9]{3}.*?\r\n$/D', $line);
+
+ $seq = $this->_buffer->write("QUIT\r\n");
+ $this->assertTrue((bool) $seq);
+ $line = $this->_buffer->readLine($seq);
+ $this->assertRegExp('/^[0-9]{3}.*?\r\n$/D', $line);
+ $this->_buffer->terminate();
+ }
+
+ public function testBindingOtherStreamsMirrorsWriteOperations()
+ {
+ $this->_initializeBuffer();
+
+ $is1 = $this->_createMockInputStream();
+ $is2 = $this->_createMockInputStream();
+
+ $is1->expects($this->at(0))
+ ->method('write')
+ ->with('x');
+ $is1->expects($this->at(1))
+ ->method('write')
+ ->with('y');
+ $is2->expects($this->at(0))
+ ->method('write')
+ ->with('x');
+ $is2->expects($this->at(1))
+ ->method('write')
+ ->with('y');
+
+ $this->_buffer->bind($is1);
+ $this->_buffer->bind($is2);
+
+ $this->_buffer->write('x');
+ $this->_buffer->write('y');
+ }
+
+ public function testBindingOtherStreamsMirrorsFlushOperations()
+ {
+ $this->_initializeBuffer();
+
+ $is1 = $this->_createMockInputStream();
+ $is2 = $this->_createMockInputStream();
+
+ $is1->expects($this->once())
+ ->method('flushBuffers');
+ $is2->expects($this->once())
+ ->method('flushBuffers');
+
+ $this->_buffer->bind($is1);
+ $this->_buffer->bind($is2);
+
+ $this->_buffer->flushBuffers();
+ }
+
+ public function testUnbindingStreamPreventsFurtherWrites()
+ {
+ $this->_initializeBuffer();
+
+ $is1 = $this->_createMockInputStream();
+ $is2 = $this->_createMockInputStream();
+
+ $is1->expects($this->at(0))
+ ->method('write')
+ ->with('x');
+ $is1->expects($this->at(1))
+ ->method('write')
+ ->with('y');
+ $is2->expects($this->once())
+ ->method('write')
+ ->with('x');
+
+ $this->_buffer->bind($is1);
+ $this->_buffer->bind($is2);
+
+ $this->_buffer->write('x');
+
+ $this->_buffer->unbind($is2);
+
+ $this->_buffer->write('y');
+ }
+
+ private function _createMockInputStream()
+ {
+ return $this->getMockBuilder('Swift_InputByteStream')->getMock();
+ }
+}
diff --git a/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Transport/StreamBuffer/BasicSocketAcceptanceTest.php b/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Transport/StreamBuffer/BasicSocketAcceptanceTest.php
new file mode 100644
index 0000000..4c3c7d3
--- /dev/null
+++ b/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Transport/StreamBuffer/BasicSocketAcceptanceTest.php
@@ -0,0 +1,33 @@
+<?php
+
+require_once __DIR__.'/AbstractStreamBufferAcceptanceTest.php';
+
+class Swift_Transport_StreamBuffer_BasicSocketAcceptanceTest extends Swift_Transport_StreamBuffer_AbstractStreamBufferAcceptanceTest
+{
+ protected function setUp()
+ {
+ if (!defined('SWIFT_SMTP_HOST')) {
+ $this->markTestSkipped(
+ 'Cannot run test without an SMTP host to connect to (define '.
+ 'SWIFT_SMTP_HOST in tests/acceptance.conf.php if you wish to run this test)'
+ );
+ }
+ parent::setUp();
+ }
+
+ protected function _initializeBuffer()
+ {
+ $parts = explode(':', SWIFT_SMTP_HOST);
+ $host = $parts[0];
+ $port = isset($parts[1]) ? $parts[1] : 25;
+
+ $this->_buffer->initialize(array(
+ 'type' => Swift_Transport_IoBuffer::TYPE_SOCKET,
+ 'host' => $host,
+ 'port' => $port,
+ 'protocol' => 'tcp',
+ 'blocking' => 1,
+ 'timeout' => 15,
+ ));
+ }
+}
diff --git a/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Transport/StreamBuffer/ProcessAcceptanceTest.php b/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Transport/StreamBuffer/ProcessAcceptanceTest.php
new file mode 100644
index 0000000..a37439d
--- /dev/null
+++ b/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Transport/StreamBuffer/ProcessAcceptanceTest.php
@@ -0,0 +1,26 @@
+<?php
+
+require_once __DIR__.'/AbstractStreamBufferAcceptanceTest.php';
+
+class Swift_Transport_StreamBuffer_ProcessAcceptanceTest extends Swift_Transport_StreamBuffer_AbstractStreamBufferAcceptanceTest
+{
+ protected function setUp()
+ {
+ if (!defined('SWIFT_SENDMAIL_PATH')) {
+ $this->markTestSkipped(
+ 'Cannot run test without a path to sendmail (define '.
+ 'SWIFT_SENDMAIL_PATH in tests/acceptance.conf.php if you wish to run this test)'
+ );
+ }
+
+ parent::setUp();
+ }
+
+ protected function _initializeBuffer()
+ {
+ $this->_buffer->initialize(array(
+ 'type' => Swift_Transport_IoBuffer::TYPE_PROCESS,
+ 'command' => SWIFT_SENDMAIL_PATH.' -bs',
+ ));
+ }
+}
diff --git a/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Transport/StreamBuffer/SocketTimeoutTest.php b/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Transport/StreamBuffer/SocketTimeoutTest.php
new file mode 100644
index 0000000..59362b0
--- /dev/null
+++ b/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Transport/StreamBuffer/SocketTimeoutTest.php
@@ -0,0 +1,67 @@
+<?php
+
+class Swift_Transport_StreamBuffer_SocketTimeoutTest extends \PHPUnit_Framework_TestCase
+{
+ protected $_buffer;
+
+ protected $_randomHighPort;
+
+ protected $_server;
+
+ protected function setUp()
+ {
+ if (!defined('SWIFT_SMTP_HOST')) {
+ $this->markTestSkipped(
+ 'Cannot run test without an SMTP host to connect to (define '.
+ 'SWIFT_SMTP_HOST in tests/acceptance.conf.php if you wish to run this test)'
+ );
+ }
+
+ $serverStarted = false;
+ for ($i = 0; $i < 5; ++$i) {
+ $this->_randomHighPort = rand(50000, 65000);
+ $this->_server = stream_socket_server('tcp://127.0.0.1:'.$this->_randomHighPort);
+ if ($this->_server) {
+ $serverStarted = true;
+ }
+ }
+
+ $this->_buffer = new Swift_Transport_StreamBuffer(
+ $this->getMockBuilder('Swift_ReplacementFilterFactory')->getMock()
+ );
+ }
+
+ protected function _initializeBuffer()
+ {
+ $host = '127.0.0.1';
+ $port = $this->_randomHighPort;
+
+ $this->_buffer->initialize(array(
+ 'type' => Swift_Transport_IoBuffer::TYPE_SOCKET,
+ 'host' => $host,
+ 'port' => $port,
+ 'protocol' => 'tcp',
+ 'blocking' => 1,
+ 'timeout' => 1,
+ ));
+ }
+
+ public function testTimeoutException()
+ {
+ $this->_initializeBuffer();
+ $e = null;
+ try {
+ $line = $this->_buffer->readLine(0);
+ } catch (Exception $e) {
+ }
+ $this->assertInstanceOf('Swift_IoException', $e, 'IO Exception Not Thrown On Connection Timeout');
+ $this->assertRegExp('/Connection to .* Timed Out/', $e->getMessage());
+ }
+
+ protected function tearDown()
+ {
+ if ($this->_server) {
+ stream_socket_shutdown($this->_server, STREAM_SHUT_RDWR);
+ }
+ }
+}
diff --git a/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Transport/StreamBuffer/SslSocketAcceptanceTest.php b/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Transport/StreamBuffer/SslSocketAcceptanceTest.php
new file mode 100644
index 0000000..32e0fe8
--- /dev/null
+++ b/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Transport/StreamBuffer/SslSocketAcceptanceTest.php
@@ -0,0 +1,40 @@
+<?php
+
+require_once __DIR__.'/AbstractStreamBufferAcceptanceTest.php';
+
+class Swift_Transport_StreamBuffer_SslSocketAcceptanceTest extends Swift_Transport_StreamBuffer_AbstractStreamBufferAcceptanceTest
+{
+ protected function setUp()
+ {
+ $streams = stream_get_transports();
+ if (!in_array('ssl', $streams)) {
+ $this->markTestSkipped(
+ 'SSL is not configured for your system. It is not possible to run this test'
+ );
+ }
+ if (!defined('SWIFT_SSL_HOST')) {
+ $this->markTestSkipped(
+ 'Cannot run test without an SSL enabled SMTP host to connect to (define '.
+ 'SWIFT_SSL_HOST in tests/acceptance.conf.php if you wish to run this test)'
+ );
+ }
+
+ parent::setUp();
+ }
+
+ protected function _initializeBuffer()
+ {
+ $parts = explode(':', SWIFT_SSL_HOST);
+ $host = $parts[0];
+ $port = isset($parts[1]) ? $parts[1] : 25;
+
+ $this->_buffer->initialize(array(
+ 'type' => Swift_Transport_IoBuffer::TYPE_SOCKET,
+ 'host' => $host,
+ 'port' => $port,
+ 'protocol' => 'ssl',
+ 'blocking' => 1,
+ 'timeout' => 15,
+ ));
+ }
+}
diff --git a/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Transport/StreamBuffer/TlsSocketAcceptanceTest.php b/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Transport/StreamBuffer/TlsSocketAcceptanceTest.php
new file mode 100644
index 0000000..1053a87
--- /dev/null
+++ b/vendor/swiftmailer/swiftmailer/tests/acceptance/Swift/Transport/StreamBuffer/TlsSocketAcceptanceTest.php
@@ -0,0 +1,39 @@
+<?php
+
+require_once __DIR__.'/AbstractStreamBufferAcceptanceTest.php';
+
+class Swift_Transport_StreamBuffer_TlsSocketAcceptanceTest extends Swift_Transport_StreamBuffer_AbstractStreamBufferAcceptanceTest
+{
+ protected function setUp()
+ {
+ $streams = stream_get_transports();
+ if (!in_array('tls', $streams)) {
+ $this->markTestSkipped(
+ 'TLS is not configured for your system. It is not possible to run this test'
+ );
+ }
+ if (!defined('SWIFT_TLS_HOST')) {
+ $this->markTestSkipped(
+ 'Cannot run test without a TLS enabled SMTP host to connect to (define '.
+ 'SWIFT_TLS_HOST in tests/acceptance.conf.php if you wish to run this test)'
+ );
+ }
+ parent::setUp();
+ }
+
+ protected function _initializeBuffer()
+ {
+ $parts = explode(':', SWIFT_TLS_HOST);
+ $host = $parts[0];
+ $port = isset($parts[1]) ? $parts[1] : 25;
+
+ $this->_buffer->initialize(array(
+ 'type' => Swift_Transport_IoBuffer::TYPE_SOCKET,
+ 'host' => $host,
+ 'port' => $port,
+ 'protocol' => 'tls',
+ 'blocking' => 1,
+ 'timeout' => 15,
+ ));
+ }
+}