private function _createMessageWithByteCount($bytes) { $this->_bytes = $bytes; $msg = $this->_mock('Swift_Mime_Message'); $this->_checking(Expectations::create()->ignoring($msg)->toByteStream(any())->calls(array($this, '_write'))); return $msg; }
public function testRegisterPluginDelegatesToTransport() { $plugin = $this->_createPlugin(); $transport = $this->_createTransport(); $mailer = $this->_createMailer($transport); $this->_checking(Expectations::create()->one($transport)->registerPlugin($plugin)); $mailer->registerPlugin($plugin); }
public function testOverridingTranslationsOnlyAddsNeededFilters() { $factory = $this->_createFactory(); $this->_checking(Expectations::create()->one($factory)->createFilter('a', 'b')->returns($this->_createFilter())->one($factory)->createFilter('x', 'y')->returns($this->_createFilter())->never($factory)); $buffer = $this->_createBuffer($factory); $buffer->setWriteTranslations(array('a' => 'b')); $buffer->setWriteTranslations(array('x' => 'y', 'a' => 'b')); }
public function testSendingMessageRegeneratesId() { $buf = $this->_getBuffer(); $sendmail = $this->_getSendmail($buf); $message = $this->_createMessage(); $this->_checking(Expectations::create()->allowing($message)->getTo()->returns(array('foo@bar' => 'Foobar', 'zip@button' => 'Zippy'))->one($message)->generateId()->ignoring($message)->one($buf)->initialize()->one($buf)->terminate()->one($buf)->setWriteTranslations(array("\r\n" => "\n", "\n." => "\n.."))->one($buf)->setWriteTranslations(array())->ignoring($buf)); $sendmail->setCommand('/usr/sbin/sendmail -t'); $this->assertEqual(2, $sendmail->send($message)); }
public function testReportingFailedBcc() { $message = $this->_createMessage(); $evt = $this->_createSendEvent(); $reporter = $this->_createReporter(); $this->_checking(Expectations::create()->allowing($message)->getTo()->returns(array('*****@*****.**' => 'Foo'))->allowing($message)->getBcc()->returns(array('zip@button' => 'Zip', '*****@*****.**' => 'Test'))->allowing($evt)->getMessage()->returns($message)->allowing($evt)->getFailedRecipients()->returns(array('zip@button'))->one($reporter)->notify($message, '*****@*****.**', Swift_Plugins_Reporter::RESULT_PASS)->one($reporter)->notify($message, 'zip@button', Swift_Plugins_Reporter::RESULT_FAIL)->one($reporter)->notify($message, '*****@*****.**', Swift_Plugins_Reporter::RESULT_PASS)->ignoring($message)->ignoring($evt)); $plugin = new Swift_Plugins_ReporterPlugin($reporter); $plugin->sendPerformed($evt); }
public function testUnbindingStreamPreventsFurtherWrites() { $this->_initializeBuffer(); $is1 = $this->_createMockInputStream(); $is2 = $this->_createMockInputStream(); $this->_checking(Expectations::create()->one($is1)->write('x')->one($is2)->write('x')->one($is1)->write('y')); $this->_buffer->bind($is1); $this->_buffer->bind($is2); $this->_buffer->write('x'); $this->_buffer->unbind($is2); $this->_buffer->write('y'); }
public function testFirstLineCanHaveShorterLength() { $charStream = $this->_mock('Swift_CharacterStream'); $seq = $this->_sequence('byte-sequence'); $string = ''; for ($x = 0; $x < 200; ++$x) { $char = 'a'; $string .= $char; $this->_checking(Expectations::create()->one($charStream)->read(optional())->inSequence($seq)->returns($char)); } $this->_checking(Expectations::create()->atLeast(1)->of($charStream)->read(optional())->inSequence($seq)->returns(false)->one($charStream)->importString($string)->ignoring($charStream)->flushContents()); $encoder = new Swift_Encoder_Rfc2231Encoder($charStream); $encoded = $encoder->encodeString($string, 25, 75); $this->assertEqual(str_repeat('a', 50) . "\r\n" . str_repeat('a', 75) . "\r\n" . str_repeat('a', 75), $encoded, '%s: First line should be 25 bytes shorter than the others.'); }
public function testClonedStreamStillReferencesSameCache() { $cache = $this->_createKeyCache(); $this->_checking(Expectations::create()->one($cache)->setString($this->_nsKey, 'foo', 'a', Swift_KeyCache::MODE_APPEND)->one($cache)->setString($this->_nsKey, 'foo', 'b', Swift_KeyCache::MODE_APPEND)->one($cache)->setString('test', 'bar', 'x', Swift_KeyCache::MODE_APPEND)); $stream = new Swift_KeyCache_SimpleKeyCacheInputStream(); $stream->setKeyCache($cache); $stream->setNsKey($this->_nsKey); $stream->setItemKey('foo'); $stream->write('a'); $stream->write('b'); $newStream = clone $stream; $newStream->setKeyCache($cache); $newStream->setNsKey('test'); $newStream->setItemKey('bar'); $newStream->write('x'); }
public function testUnbindingStreamPreventsFurtherWrites() { $file = $this->_createFileStream($this->_testFile, true); $is1 = $this->_createMockInputStream(); $is2 = $this->_createMockInputStream(); $this->_checking(Expectations::create()->one($is1)->write('x')->one($is2)->write('x')->one($is1)->write('y')); $file->bind($is1); $file->bind($is2); $file->write('x'); $file->unbind($is2); $file->write('y'); }
public function testAddingListenerTwiceDoesNotReceiveEventTwice() { $transport = $this->_stub('Swift_Transport'); $evt = $this->_dispatcher->createTransportChangeEvent($transport); $listener = $this->_mock('Swift_Events_TransportChangeListener'); $this->_dispatcher->bindEventListener($listener); $this->_dispatcher->bindEventListener($listener); $this->_checking(Expectations::create()->one($listener)->transportStarted($evt)->never($listener)->transportStarted($evt)); $this->_dispatcher->dispatchEvent($evt, 'transportStarted'); }
public function testMixinSetterWhichReturnValuesAreNotFluid() { $buf = $this->_getBuffer(); $smtp = $this->_getTransport($buf); $ext1 = $this->_mock('Swift_Transport_EsmtpHandlerMixin'); $ext2 = $this->_mock('Swift_Transport_EsmtpHandler'); $this->_checking(Expectations::create()->allowing($ext1)->getHandledKeyword()->returns('AUTH')->allowing($ext1)->exposeMixinMethods()->returns(array('setUsername', 'setPassword'))->one($ext1)->setUsername('mick')->returns('x')->one($ext1)->setPassword('pass')->returns('x')->allowing($ext2)->getHandledKeyword()->returns('STARTTLS')->ignoring($ext1)->ignoring($ext2)); $this->_finishBuffer($buf); $smtp->setExtensionHandlers(array($ext1, $ext2)); $this->assertEqual('x', $smtp->setUsername('mick')); $this->assertEqual('x', $smtp->setPassword('pass')); }
private function _getFactory($reader) { $factory = $this->_mock('Swift_CharacterReaderFactory'); $this->_checking(Expectations::create()->allowing($factory)->getReaderFor('utf-8')->returns($reader)); return $factory; }
public function testDataCanBeExportedToByteStream() { //See acceptance test for more detail $is = $this->_createInputStream(); $this->_checking(Expectations::create()->atLeast(1)->of($is)->write(any())->ignoring($is)); $kcis = $this->_createKeyCacheInputStream(true); $cache = $this->_createCache($kcis); $cache->setString($this->_key1, 'foo', 'test', Swift_KeyCache::MODE_WRITE); $cache->exportToByteStream($this->_key1, 'foo', $is); }
public function testFirstLineLengthCanBeDifferent() { $input = str_repeat('a', 140); $charStream = $this->_createCharStream(); $seq = $this->_mockery()->sequence('byte-sequence'); $exps = Expectations::create(); $exps->one($charStream)->flushContents(); $exps->one($charStream)->importString($input); $output = ''; for ($i = 0; $i < 140; ++$i) { $exps->one($charStream)->readBytes(optional())->inSequence($seq)->returns(array(ord('a'))); if (53 == $i || 53 + 75 == $i) { $output .= "=\r\n"; } $output .= 'a'; } $exps->one($charStream)->readBytes(optional())->inSequence($seq)->returns(false); $this->_checking($exps); $encoder = new Swift_Encoder_QpEncoder($charStream); $this->assertEqual($output, $encoder->encodeString($input, 22), '%s: First line should start at offset 22 so can only have max length 54'); }
public function testAuthenticationFailureSendRsetAndReturnFalse() { $cram = $this->_getAuthenticator(); $this->_checking(Expectations::create()->one($this->_agent)->executeCommand("AUTH CRAM-MD5\r\n", array(334))->returns('334 ' . base64_encode('<foo@bar>') . "\r\n")->one($this->_agent)->executeCommand(any(), array(235))->throws(new Swift_TransportException(""))->one($this->_agent)->executeCommand("RSET\r\n", array(250))); $this->assertFalse($cram->authenticate($this->_agent, 'jack', 'pass'), '%s: Authentication fails, so RSET should be sent'); }
protected function _createFileStream($path, $data, $stub = true) { $file = $this->_mock('Swift_FileStream'); $pos = $this->_mockery()->states('position')->startsAs('at start'); $this->_checking(Expectations::create()->ignoring($file)->getPath()->returns($path)->ignoring($file)->read(optional())->returns($data)->when($pos->isNot('at end'))->then($pos->is('at end'))->ignoring($file)->read(optional())->returns(false)); if ($stub) { $this->_checking(Expectations::create()->ignoring($file)); } return $file; }
public function testCanonicEncodeByteStreamGeneratesCorrectCrlf_5() { $encoder = $this->_getEncoder('7bit', true); $os = $this->_createOutputByteStream(); $is = $this->_createInputByteStream(); $collection = new Swift_StreamCollector(); $this->_checking(Expectations::create()->allowing($is)->write(any(), optional())->will($collection)->ignoring($is)->one($os)->read(optional())->returns('a')->one($os)->read(optional())->returns("\r\r")->one($os)->read(optional())->returns('b')->allowing($os)->read(optional())->returns(false)->ignoring($os)); $encoder->encodeByteStream($os, $is); $this->assertEqual("a\r\n\r\nb", $collection->content); }
public function testEmbedReturnsValidCid() { $child = $this->_createChild(Swift_Mime_MimeEntity::LEVEL_RELATED, '', false); $this->_checking(Expectations::create()->ignoring($child)->getId()->returns('foo@bar')->ignoring($child)); $message = $this->_createMessage($this->_createHeaderSet(), $this->_createEncoder(), $this->_createCache()); $this->assertEqual('cid:foo@bar', $message->embed($child)); }
private function _createPart($type, $body, $id) { $part = $this->_mock('Swift_Mime_MimeEntity'); $this->_checking(Expectations::create()->ignoring($part)->getContentType()->returns($type)->ignoring($part)->getBody()->returns($body)->ignoring($part)->getId()->returns($id)); return $part; }
private function _createMockAuthenticator($type) { $authenticator = $this->_mock('Swift_Transport_Esmtp_Authenticator'); $this->_checking(Expectations::create()->ignoring($authenticator)->getAuthKeyword()->returns($type)); return $authenticator; }
private function _createSendEvent($message) { $evt = $this->_mock('Swift_Events_SendEvent'); $this->_checking(Expectations::create()->ignoring($evt)->getMessage()->returns($message)); return $evt; }
public function testRegisterPluginDelegatesToLoadedTransports() { $context = new Mockery(); $plugin = $this->_createPlugin($context); $t1 = $context->mock('Swift_Transport'); $t2 = $context->mock('Swift_Transport'); $context->checking(Expectations::create()->one($t1)->registerPlugin($plugin)->one($t2)->registerPlugin($plugin)->ignoring($t1)->ignoring($t2)); $transport = $this->_getTransport(array($t1, $t2)); $transport->registerPlugin($plugin); $context->assertIsSatisfied(); }
private function _getHeaderEncoder($type, $stub = false) { $encoder = $this->_mock('Swift_Mime_HeaderEncoder'); $this->_checking(Expectations::create()->ignoring($encoder)->getName()->returns($type)); if ($stub) { $this->_checking(Expectations::create()->ignoring($encoder)); } return $encoder; }
public function testFluidInterface() { $buf = $this->_getBuffer(); $smtp = $this->_getTransport($buf); $this->_checking(Expectations::create()->one($buf)->setParam('timeout', 30)); $ref = $smtp->setHost('foo')->setPort(25)->setEncryption('tls')->setTimeout(30); $this->assertReference($ref, $smtp); }
public function testFirstLineLengthCanBeDifferent() { $os = $this->_createOutputByteStream(); $is = $this->_createInputByteStream(); $collection = new Swift_StreamCollector(); $this->_checking(Expectations::create()->allowing($is)->write(any(), optional())->will($collection)->ignoring($is)->one($os)->read(optional())->returns('abcdefghijkl')->one($os)->read(optional())->returns('mnopqrstuvwx')->one($os)->read(optional())->returns('yzabc1234567')->one($os)->read(optional())->returns('890ABCDEFGHI')->one($os)->read(optional())->returns('JKLMNOPQRSTU')->one($os)->read(optional())->returns('VWXYZ1234567')->one($os)->read(optional())->returns('abcdefghijkl')->allowing($os)->read(optional())->returns(false)->ignoring($os)); $this->_encoder->encodeByteStream($os, $is, 19); $this->assertEqual("YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXphYmMxMjM0NTY3ODkwQUJDR\r\n" . "EVGR0hJSktMTU5PUFFSU1RVVldYWVoxMjM0NTY3YWJjZGVmZ2hpamts", $collection->content); }
private function _createSendEvent($transport) { $evt = $this->_mock('Swift_Events_SendEvent'); $this->_checking(Expectations::create()->ignoring($evt)->getSource()->returns($transport)->ignoring($evt)->getTransport()->returns($transport)); return $evt; }
protected function _createInputStream($stub = true) { $is = $this->_mock('Swift_InputByteStream'); if ($stub) { $this->_checking(Expectations::create()->ignoring($is)); } return $is; }
/** * @return Swift_Mime_Headers */ private function _createHeaders() { $x = 0; $cache = new Swift_KeyCache_ArrayKeyCache(new Swift_KeyCache_SimpleKeyCacheInputStream()); $factory = new Swift_CharacterReaderFactory_SimpleCharacterReaderFactory(); $contentEncoder = new Swift_Mime_ContentEncoder_Base64ContentEncoder(); $headerEncoder = new Swift_Mime_HeaderEncoder_QpHeaderEncoder(new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8')); $paramEncoder = new Swift_Encoder_Rfc2231Encoder(new Swift_CharacterStream_ArrayCharacterStream($factory, 'utf-8')); $grammar = new Swift_Mime_Grammar(); $headerFactory = new Swift_Mime_SimpleHeaderFactory($headerEncoder, $paramEncoder, $grammar); $headers = $this->_mock('Swift_Mime_HeaderSet'); $this->_checking(Expectations::create()->ignoring($headers)->listAll()->returns(array('From', 'To', 'Date', 'Subject'))->ignoring($headers)->has('From')->returns(True)->ignoring($headers)->getAll('From')->returns(array($headerFactory->createMailboxHeader('From', '*****@*****.**')))->ignoring($headers)->has('To')->returns(True)->ignoring($headers)->getAll('To')->returns(array($headerFactory->createMailboxHeader('To', '*****@*****.**')))->ignoring($headers)->has('Date')->returns(True)->ignoring($headers)->getAll('Date')->returns(array($headerFactory->createTextHeader('Date', 'Fri, 11 Mar 2011 20:56:12 +0000 (GMT)')))->ignoring($headers)->has('Subject')->returns(True)->ignoring($headers)->getAll('Subject')->returns(array($headerFactory->createTextHeader('Subject', 'Foo Bar Text Message')))->ignoring($headers)->addTextHeader('DKIM-Signature', any())->returns(true)->ignoring($headers)->getAll('DKIM-Signature')->returns(array($headerFactory->createTextHeader('DKIM-Signature', 'Foo Bar Text Message')))); return $headers; }
private function _createHeader($name, $body = '') { $header = $this->_mock('Swift_Mime_Header'); $this->_checking(Expectations::create()->ignoring($header)->getFieldName()->returns($name)->ignoring($header)->getFieldBodyModel()->returns($body)); return $header; }
public function testDomainNameIsPlacedInHelo() { //Overridden to include ESMTP /* -- RFC 2821, 4.1.4. The SMTP client MUST, if possible, ensure that the domain parameter to the EHLO command is a valid principal host name (not a CNAME or MX name) for its host. If this is not possible (e.g., when the client's address is dynamically assigned and the client does not have an obvious name), an address literal SHOULD be substituted for the domain name and supplemental information provided that will assist in identifying the client. */ $buf = $this->_getBuffer(); $smtp = $this->_getTransport($buf); $s = $this->_sequence('SMTP-convo'); $this->_checking(Expectations::create()->one($buf)->initialize()->inSequence($s)->one($buf)->readLine(0)->inSequence($s)->returns("220 some.server.tld bleh\r\n")->one($buf)->write(pattern('~^EHLO .+?\\r\\n$~D'))->inSequence($s)->returns(1)->one($buf)->readLine(1)->inSequence($s)->returns('501 WTF' . "\r\n")->one($buf)->write("HELO mydomain.com\r\n")->inSequence($s)->returns(2)->one($buf)->readLine(2)->inSequence($s)->returns('250 ServerName' . "\r\n")); $this->_finishBuffer($buf); $smtp->setLocalDomain('mydomain.com'); $smtp->start(); }