Browse Source

Added support for cloning `Message`

tags/2.0.7
evpav 8 years ago committed by Klimov Paul
parent
commit
a4bba80244
  1. 1
      CHANGELOG.md
  2. 12
      Message.php
  3. 19
      tests/MessageTest.php

1
CHANGELOG.md

@ -4,6 +4,7 @@ Yii Framework 2 swiftmailer extension Change Log
2.0.7 under development
-----------------------
- Bug #46: Fixed `yii\swiftmailer\Message` does not clones `$swiftMessage` during its own cloning (evpav, klimov-paul)
- Enh #37: `yii\swiftmailer\Logger` now chooses logging level depending on incoming entry format (klimov-paul)
- Enh #40: Added `yii\swiftmailer\Message::setHeaders()` allowing to setup custom headers in batch (klimov-paul)

12
Message.php

@ -46,6 +46,18 @@ class Message extends BaseMessage
/**
* This method is called after the object is created by cloning an existing one.
* It ensures [[swiftMessage]] is also cloned.
* @since 2.0.7
*/
public function __clone()
{
if (is_object($this->_swiftMessage)) {
$this->_swiftMessage = clone $this->_swiftMessage;
}
}
/**
* @return \Swift_Message Swift message instance.
*/
public function getSwiftMessage()

19
tests/MessageTest.php

@ -174,6 +174,25 @@ class MessageTest extends TestCase
}
/**
* @depends testSetGet
*/
public function testClone()
{
$m1 = new Message();
$m1->setFrom('user@example.com');
$m2 = clone $m1;
$m1->setTo(['user1@example.com' => 'user1']);
$m2->setTo(['user2@example.com' => 'user2']);
$this->assertEquals(['user1@example.com' => 'user1'], $m1->getTo());
$this->assertEquals(['user2@example.com' => 'user2'], $m2->getTo());
$messageWithoutSwiftInitialized = new Message();
$m2 = clone $messageWithoutSwiftInitialized; // should be no error during cloning
$this->assertTrue($m2 instanceof Message);
}
/**
* @depends testGetSwiftMessage
*/
public function testSetupHeaderShortcuts()

Loading…
Cancel
Save