function mockUpload($methods = array()) { if (!is_array($methods)) { $methods = (array) $methods; } if (empty($methods)) { $methods = array('handleUploadedFile', 'unlink', '_getMimeType'); } $mockName = $this->currentTestMethod . '_MockUploadBehavior'; Mock::GeneratePartial('UploadBehavior', $mockName, $methods); $this->MockUpload = new $mockName(); $this->MockUpload->setup($this->TestUpload, $this->TestUpload->actsAs['Upload.Upload']); $this->TestUpload->Behaviors->Upload = $this->MockUpload; }
Swift_ClassLoader::load("Swift_Events_SendListener"); Swift_ClassLoader::load("Swift_Events_BeforeCommandListener"); Swift_ClassLoader::load("Swift_Events_CommandListener"); Swift_ClassLoader::load("Swift_Events_ResponseListener"); Swift_ClassLoader::load("Swift_Events_ConnectListener"); Swift_ClassLoader::load("Swift_Events_DisconnectListener"); Swift_ClassLoader::load("Swift_Plugin_AntiFlood"); Swift_ClassLoader::load("Swift_Plugin_BandwidthMonitor"); Swift_ClassLoader::load("Swift_Plugin_Throttler"); Swift_ClassLoader::load("Swift_Plugin_VerboseSending"); Swift_ClassLoader::load("Swift_Plugin_ConnectionRotator"); Swift_ClassLoader::load("Swift_Plugin_Decorator"); Swift_ClassLoader::load("Swift_Message_Headers"); Swift_ClassLoader::load("Swift_CacheFactory"); Swift_ClassLoader::load("Swift_Log_DefaultLog"); Swift_ClassLoader::load("Swift_Message_Encoder"); Swift_ClassLoader::load("Swift_Cache_JointOutputStream"); require_once TestConfiguration::SWIFT_LIBRARY_PATH . "/Swift/Authenticator/@PopB4Smtp.php"; Swift_ClassLoader::load("Swift_Authenticator_PopB4Smtp_Pop3Connection"); require_once dirname(__FILE__) . "/AbstractTestWithSend.php"; require_once dirname(__FILE__) . "/AbstractTestOfCache.php"; require_once dirname(__FILE__) . "/AbstractTestOfAuthenticator.php"; require_once dirname(__FILE__) . "/stubs/MimeExtension.php"; require_once dirname(__FILE__) . "/stubs/DummyConnection.php"; Mock::Generate("DummyConnection", "FullMockConnection"); Mock::Generate("Swift_Connection_Rotator", "MockRotatorConnection"); Mock::Generate("Swift_Message", "MockMessage"); Mock::Generate("Swift_Events_SendListener", "MockSendListener"); Mock::Generate("Swift_Connection_SMTP", "MockSMTPConnection"); Mock::GeneratePartial("Swift_Connection_SMTP", "MockSMTPConnectionAuth", array("read", "write", "isAlive", "start", "stop")); Mock::Generate("Swift_Message_Headers", "MockHeaders");
<?php /** * SwiftMailer Unit Test For the AntiFlood plugin. * @package Swift * @subpackage Tests * @author Chris Corbyn <*****@*****.**> */ Mock::GeneratePartial("Swift_Plugin_AntiFlood", "MockAntiFloodPlugin", array("wait")); /** * SwiftMailer Unit Test For the AntiFlood plugin. * @package Swift * @subpackage Tests * @author Chris Corbyn <*****@*****.**> */ class TestOfAntiFloodPlugin extends AbstractTestWithSend { /** * Tests that the connection is actually dropped when it's told to. */ public function testDisconnectIsInvokedAsManyTimesAsNeeded() { $conn = $this->getWorkingMockConnection(20, null, 5); $conn->expectCallCount("stop", 4); $conn->expectCallCount("start", 5); $swift = new Swift($conn); $swift->attachPlugin(new Swift_Plugin_AntiFlood(5), "antiflood"); for ($i = 0; $i < 20; $i++) { $swift->send(new Swift_Message("foo", "bar"), new Swift_Address("*****@*****.**"), new Swift_Address("*****@*****.**")); } $conn = $this->getWorkingMockConnection(20, null, 15);
<?php /** * Swift Mailer Unit Test for the Swift_Authenticator Interface. * @package Swift * @subpackage Tests * @author Chris Corbyn <*****@*****.**> */ Mock::Generate("Swift_Authenticator", "MockAuthenticator"); Mock::GeneratePartial("Swift_Connection_SMTP", "PartialSmtpConnection", array("read")); /** * Swift Mailer Unit Test for the Swift_Authenticator Interface. * @package Swift * @subpackage Tests * @author Chris Corbyn <*****@*****.**> */ class TestOfAuthenticator extends UnitTestCase { /** * Checks that the interface is actually invoked when needed. */ public function testAuthenticatorIsInvokedIfSMTPUsernameAndPasswordSet() { try { $auth = new MockAuthenticator(); $auth->setReturnValue("getAuthExtensionName", "FOO"); $auth->expectOnce("isAuthenticated", array("foo", "bar", "*")); $smtp = new PartialSmtpConnection(); $smtp->setExtension("AUTH", array("FOO")); $smtp->setUsername("foo"); $smtp->setPassword("bar");
<?php if (!class_exists("PartialSmtpConnection2")) { Mock::GeneratePartial("Swift_Connection_SMTP", "PartialSmtpConnection2", array("read", "write", "start", "stop")); } Mock::GeneratePartial("Swift_Authenticator_PopB4Smtp_Pop3Connection", "MockPop3Connection", array("start", "stop", "read", "write")); class TestOfPopB4SmtpAuthenticator extends UnitTestCase { public function testSmtpConnectionIsClosedBeforeAnythingIsDone() { $pop3conn = new MockPop3Connection(); $pop3conn->setReturnValue("read", "+OK foo"); $auth = new Swift_Authenticator_PopB4Smtp($pop3conn); $conn = new PartialSmtpConnection2(); $conn->attachAuthenticator($auth); $conn->setUsername("foo"); $conn->setPassword("bar"); $conn->setReturnValueAt(0, "read", "220 Hello ESMTP foo"); $conn->setReturnValueAt(3, "read", "220 Hello ESMTP foo"); $conn->setReturnValueAt(2, "read", "221 bye"); $conn->setReturnValue("read", "250 Ok"); $conn->expectMinimumCallCount("write", 2); $conn->expectAt(1, "write", array("QUIT", "*")); $conn->expectAtLeastOnce("stop"); $swift = new Swift($conn, "xxx"); } public function testAuthenticationPassesWithSuccessfulPop3Coversation() { $pop3conn = new MockPop3Connection(); $pop3conn->setReturnValue("read", "+OK xxx"); $pop3conn->expectAt(0, "write", array("USER foo"));
<?php if (!class_exists("FullMockConnection")) { Mock::Generate("DummyConnection", "FullMockConnection"); } if (!class_exists("MockBaseConnection")) { Mock::GeneratePartial("DummyConnection", "MockBaseConnection", array("start", "stop", "read", "write")); } Mock::GeneratePartial("Swift_Message", "Message_RecipientsMocked", array("setTo", "setCc", "setBcc", "setFrom", "setReplyTo")); Mock::GeneratePartial("Swift_Message", "Message_IdMocked", array("generateId")); Mock::GeneratePartial("Swift_Message", "Message_EncodingMocked", array("setEncoding", "getEncoding")); Mock::GeneratePartial("Swift_Log_DefaultLog", "MockLogger", array("add")); class TestOfSwiftCore extends UnitTestCase { public function setUp() { $log = new Swift_Log_DefaultLog(); Swift_LogContainer::setLog($log); } public function testConnectionIsInvokedAtInstantiation() { $conn = new FullMockConnection(); $conn->expectOnce("start"); $swift = new Swift($conn, false, Swift::NO_HANDSHAKE); } public function testConnectionIsNotStartedIfNO_STARTFlagIsSet() { $conn = new FullMockConnection(); $conn->expectNever("start"); $swift = new Swift($conn, null, Swift::NO_START); }
<?php Mock::GeneratePartial("Swift_Connection_Sendmail", "PartialSendmailConnection", array("pipeIn", "pipeOut", "start", "stop")); class TestOfSendmailConnection extends UnitTestCase { public function testRunningIn_bs_ModeWritesAllSMTPCommands() { $sendmail = new PartialSendmailConnection(); $sendmail->setReturnValueAt(0, "pipeOut", "220 xxx Hello"); $sendmail->setReturnValueAt(1, "pipeOut", "250 Blah blah"); $sendmail->setReturnValueAt(2, "pipeOut", "250 Ok"); $sendmail->setReturnValueAt(3, "pipeOut", "250 Ok"); $sendmail->setReturnValueAt(4, "pipeOut", "354 Go ahead"); $sendmail->setReturnValueAt(5, "pipeOut", "250 Ok"); $sendmail->expectAt(0, "pipeIn", array("HELO xxx", "*")); $sendmail->expectAt(1, "pipeIn", array("MAIL FROM: <*****@*****.**>", "*")); $sendmail->expectAt(2, "pipeIn", array("RCPT TO: <*****@*****.**>", "*")); $sendmail->expectAt(3, "pipeIn", array("DATA", "*")); $sendmail->expectAt(4, "pipeIn", array("*", "*")); $sendmail->setFlags("bs"); $swift = new Swift($sendmail, "xxx"); $message = new Swift_Message("subject", "body"); $swift->send($message, new Swift_Address("*****@*****.**"), new Swift_Address("*****@*****.**")); } public function testRunningIn_t_ModeOnlyWritesMessageData() { //Dropped due to issues with Bcc handling and (correct) unreliability with mailers such as Exim // There are arguments online regarding this topic if you Google for 'sendmail "-t option" bcc recipients' // The code still exists in the Sendmail class, but I will not be supporting it's usage. /*$sendmail = new PartialSendmailConnection(); $sendmail->expectOnce("pipeIn");