Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'feature/7263'
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Mar 25, 2015
194 parents a003056 + 027b839 + 376c43c + 9b17060 + 26177b0 + 2beabf9 + de855cb + 82571c3 + d3c79d6 + 956daea + f581f22 + 10ab90e + 31569f7 + 9256cad + 155b787 + 6a14e0a + e84c12e + 94de9c5 + 4b83eb4 + 1483e66 + b428d8b + dc72787 + bca6f24 + 1cda83c + 835b631 + d3605c7 + 7a32de0 + 7a6cebf + 662a059 + 5e1c4bb + de6ba8b + 19c92ef + f5abdbd + a4b3fcc + e0d3e79 + eb7f4fc + f5f296f + c1bc89d + 2cfde08 + 5ed923d + 7bfa121 + 0b38f0b + 1914ec7 + 47650bd + b7f9c80 + d490dab + 0b235a6 + ea8420a + 806e429 + 14b8e16 + 2c9f881 + 1591173 + 3288109 + 6149722 + fb18be8 + 2f56d24 + 256686b + 3cc679d + da18011 + 93ac388 + 57ef4a3 + 2f2851a + 2ec1dbc + 9a48955 + b6b50b9 + a16c105 + a634561 + 779d017 + e998d74 + e0c0b66 + 677bd85 + bd0abb6 + 7e23a9b + 76e9a65 + 9666e65 + 0fb7a6e + b476244 + a566cb1 + 84a7972 + f6501d5 + 74b0454 + ea99bf1 + e2703e7 + 90db7ae + b2f5380 + d6ee2dd + 2dae9df + 15a2e1f + 00d7ef1 + 88e29ab + 04f5596 + d4b9187 + 83cb40e + e80536c + 8344c40 + 314ef07 + f8fe680 + 7d99158 + 5a453b7 + 16b512c + e13bb78 + f8c8e84 + 0e833f2 + 463bd0b + e23f919 + c0f3fe1 + 9af4d23 + fbdafd9 + 46c341e + 1fcdf03 + 9e5c38e + 41f8caa + f236745 + ab9047d + c7b4a3f + 5cbe79f + dc8268a + cbafbe9 + d2c6567 + 0cc6fdf + 09daef8 + df6fc46 + ba228cf + 67d18da + 48a0084 + c78da38 + 76f6205 + 02baf86 + 907dad9 + 56854a7 + 51b08b5 + 86f37cb + 5ecd1ed + a4cca36 + cfc46bf + a576736 + 0650b43 + 6fc76b3 + 2dcfeeb + 80461fa + db66f77 + 66790e4 + ceefa98 + fc0f947 + 6a060b9 + de10d09 + 9ac9f8e + dc02847 + ee05131 + fb9ea71 + cb2e3cf + 08f2b17 + efc498e + 71822ef + 818d7d9 + 5c72f46 + 2b5dcae + 32dbda5 + d550f51 + 3aa0ee9 + 4ea71ee + 730f592 + c6516da + 76770c7 + 167fdbf + 1510cfa + e52ef9a + c1754e3 + 30e7e8b + c208a5e + c258e8b + 95bc2ba + 62058ff + 5129baa + e212b9b + 760714d + 844e2ae + 69ad6c7 + d68e5a1 + 9fededc + 1fe76d7 + 9cfe1eb + de84a61 + ee1b45a + 8dd678f + fd733d8 + a0f84c8 + c1d4cb7 + eb5e6bf + d361dcc + 94d4789 + 722be83 + 6a7c055 + e15a875 commit dd5bd4a
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 62 deletions.
2 changes: 1 addition & 1 deletion src/Storage/Mbox.php
Expand Up @@ -231,7 +231,7 @@ protected function isMboxFile($file, $fileIsString = true)

$result = false;

$line = fgets($file);
$line = fgets($file) ?: '';
if (strpos($line, 'From ') === 0) {
$result = true;
}
Expand Down
7 changes: 5 additions & 2 deletions src/Transport/Factory.php
Expand Up @@ -19,7 +19,9 @@ abstract class Factory
*/
protected static $classMap = array(
'file' => 'Zend\Mail\Transport\File',
'null' => 'Zend\Mail\Transport\Null',
'inmemory' => 'Zend\Mail\Transport\InMemory',
'memory' => 'Zend\Mail\Transport\InMemory',
'null' => 'Zend\Mail\Transport\InMemory',
'sendmail' => 'Zend\Mail\Transport\Sendmail',
'smtp' => 'Zend\Mail\Transport\Smtp',
);
Expand Down Expand Up @@ -64,7 +66,8 @@ public static function create($spec = array())

if (! $transport instanceof TransportInterface) {
throw new Exception\DomainException(sprintf(
'%s expects the "type" attribute to resolve to a valid Zend\Mail\Transport\TransportInterface instance; received "%s"',
'%s expects the "type" attribute to resolve to a valid'
. ' Zend\Mail\Transport\TransportInterface instance; received "%s"',
__METHOD__,
$type
));
Expand Down
47 changes: 47 additions & 0 deletions src/Transport/InMemory.php
@@ -0,0 +1,47 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Mail\Transport;

use Zend\Mail\Message;

/**
* InMemory transport
*
* This transport will just store the message in memory. It is helpful
* when unit testing, or to prevent sending email when in development or
* testing.
*/
class InMemory implements TransportInterface
{
/**
* @var Message
*/
protected $lastMessage;

/**
* Takes the last message and saves it for testing.
*
* @param Message $message
*/
public function send(Message $message)
{
$this->lastMessage = $message;
}

/**
* Get the last message sent.
*
* @return Message
*/
public function getLastMessage()
{
return $this->lastMessage;
}
}
45 changes: 17 additions & 28 deletions src/Transport/Null.php
Expand Up @@ -9,38 +9,27 @@

namespace Zend\Mail\Transport;

use Zend\Mail\Message;

/**
* File transport
* Stub class for backwards compatibility.
*
* Since PHP 7 adds "null" as a reserved keyword, we can no longer have a class
* named that and retain PHP 7 compatibility. The original class has been
* renamed to "InMemory", and this class is now an extension of it. It raises an
* E_USER_DEPRECATED to warn users to migrate.
*
* The null transport will just store the message in memory. It is helpful
* when unit testing.
* @deprecated
*/
class Null implements TransportInterface
class Null extends InMemory
{
/**
* @var Message
*/
protected $lastMessage;

/**
* Takes the last message and Saves it for testing
*
* @param Message $message
*/
public function send(Message $message)
{
$this->lastMessage = $message;
}

/**
* Get the last message sent
*
* @return Message
*/
public function getLastMessage()
public function __construct()
{
return $this->lastMessage;
trigger_error(
sprintf(
'The class %s has been deprecated; please use %s\\InMemory',
__CLASS__,
__NAMESPACE__
),
E_USER_DEPRECATED
);
}
}
26 changes: 20 additions & 6 deletions test/Transport/FactoryTest.php
Expand Up @@ -47,21 +47,32 @@ public function testDefaultTypeIsSendmail()
*/
public function testCanCreateClassUsingTypeKey($type)
{
set_error_handler(function ($code, $message) {
// skip deprecation notices
return;
}, E_USER_DEPRECATED);
$transport = Factory::create(array(
'type' => $type,
));
restore_error_handler();

$this->assertInstanceOf($type, $transport);
}

public function typeProvider()
{
return array(
$types = array(
array('Zend\Mail\Transport\File'),
array('Zend\Mail\Transport\Null'),
array('Zend\Mail\Transport\InMemory'),
array('Zend\Mail\Transport\Sendmail'),
array('Zend\Mail\Transport\Smtp'),
);

if (version_compare(PHP_VERSION, '7.0', '<')) {
$types[] = array('Zend\Mail\Transport\Null');
}

return $types;
}

/**
Expand All @@ -82,12 +93,15 @@ public function typeAliasProvider()
{
return array(
array('file', 'Zend\Mail\Transport\File'),
array('null', 'Zend\Mail\Transport\Null'),
array('null', 'Zend\Mail\Transport\InMemory'),
array('memory', 'Zend\Mail\Transport\InMemory'),
array('inmemory', 'Zend\Mail\Transport\InMemory'),
array('InMemory', 'Zend\Mail\Transport\InMemory'),
array('sendmail', 'Zend\Mail\Transport\Sendmail'),
array('smtp', 'Zend\Mail\Transport\Smtp'),
array('File', 'Zend\Mail\Transport\File'),
array('Null', 'Zend\Mail\Transport\Null'),
array('NULL', 'Zend\Mail\Transport\Null'),
array('Null', 'Zend\Mail\Transport\InMemory'),
array('NULL', 'Zend\Mail\Transport\InMemory'),
array('Sendmail', 'Zend\Mail\Transport\Sendmail'),
array('SendMail', 'Zend\Mail\Transport\Sendmail'),
array('Smtp', 'Zend\Mail\Transport\Smtp'),
Expand All @@ -106,7 +120,7 @@ public function testCanUseTraversableAsSpec()

$transport = Factory::create($spec);

$this->assertInstanceOf('Zend\Mail\Transport\Null', $transport);
$this->assertInstanceOf('Zend\Mail\Transport\InMemory', $transport);
}

/**
Expand Down
48 changes: 48 additions & 0 deletions test/Transport/InMemoryTest.php
@@ -0,0 +1,48 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Mail\Transport;

use Zend\Mail\Message;
use Zend\Mail\Transport\InMemory;

/**
* @group Zend_Mail
*/
class InMemoryTest extends \PHPUnit_Framework_TestCase
{
public function getMessage()
{
$message = new Message();
$message->addTo('zf-devteam@zend.com', 'ZF DevTeam')
->addCc('matthew@zend.com')
->addBcc('zf-crteam@lists.zend.com', 'CR-Team, ZF Project')
->addFrom(array(
'zf-devteam@zend.com',
'Matthew' => 'matthew@zend.com',
))
->setSender('ralph.schindler@zend.com', 'Ralph Schindler')
->setSubject('Testing Zend\Mail\Transport\Sendmail')
->setBody('This is only a test.');
$message->getHeaders()->addHeaders(array(
'X-Foo-Bar' => 'Matthew',
));
return $message;
}

public function testReceivesMailArtifacts()
{
$message = $this->getMessage();
$transport = new InMemory();

$transport->send($message);

$this->assertSame($message, $transport->getLastMessage());
}
}
33 changes: 8 additions & 25 deletions test/Transport/NullTest.php
Expand Up @@ -9,40 +9,23 @@

namespace ZendTest\Mail\Transport;

use Zend\Mail\Message;
use Zend\Mail\Transport\Null;
use Zend\Mail\Transport\Null as NullTransport;

/**
* @group Zend_Mail
*/
class NullTest extends \PHPUnit_Framework_TestCase
{
public function getMessage()
public function setUp()
{
$message = new Message();
$message->addTo('zf-devteam@zend.com', 'ZF DevTeam')
->addCc('matthew@zend.com')
->addBcc('zf-crteam@lists.zend.com', 'CR-Team, ZF Project')
->addFrom(array(
'zf-devteam@zend.com',
'Matthew' => 'matthew@zend.com',
))
->setSender('ralph.schindler@zend.com', 'Ralph Schindler')
->setSubject('Testing Zend\Mail\Transport\Sendmail')
->setBody('This is only a test.');
$message->getHeaders()->addHeaders(array(
'X-Foo-Bar' => 'Matthew',
));
return $message;
if (version_compare(PHP_VERSION, '7.0', '>=')) {
$this->markTestSkipped('Cannot test Null transport under PHP 7; reserved keyword');
}
}

public function testReceivesMailArtifacts()
public function testRaisesNoticeOnInstantiation()
{
$message = $this->getMessage();
$transport = new Null();

$transport->send($message);

$this->assertSame($message, $transport->getLastMessage());
$this->setExpectedException('PHPUnit_Framework_Error_Deprecated');
new NullTransport();
}
}

0 comments on commit dd5bd4a

Please sign in to comment.