Browse Source

Merge pull request #9921 from cakephp/3.next-email

Clean up Email API and combined setter getter methods.
Mark Story 9 years ago
parent
commit
3249ea61c9
3 changed files with 792 additions and 118 deletions
  1. 784 111
      src/Mailer/Email.php
  2. 4 3
      src/Mailer/Mailer.php
  3. 4 4
      tests/TestCase/Mailer/MailerTest.php

File diff suppressed because it is too large
+ 784 - 111
src/Mailer/Email.php


+ 4 - 3
src/Mailer/Mailer.php

@@ -33,8 +33,8 @@ use Cake\Mailer\Exception\MissingActionException;
  *     public function resetPassword($user)
  *     {
  *         $this
- *             ->subject('Reset Password')
- *             ->to($user->email)
+ *             ->setSubject('Reset Password')
+ *             ->setTo($user->email)
  *             ->set(['token' => $user->token]);
  *     }
  * }
@@ -173,6 +173,7 @@ abstract class Mailer implements EventListenerInterface
     /**
      * Sets layout to use.
      *
+     * @deprecated 3.4.0 Use setLayout() which sets the layout on the email class instead.
      * @param string $layout Name of the layout to use.
      * @return self object.
      */
@@ -216,7 +217,7 @@ abstract class Mailer implements EventListenerInterface
      */
     public function set($key, $value = null)
     {
-        $this->_email->viewVars(is_string($key) ? [$key => $value] : $key);
+        $this->_email->setViewVars(is_string($key) ? [$key => $value] : $key);
 
         return $this;
     }

+ 4 - 4
tests/TestCase/Mailer/MailerTest.php

@@ -84,16 +84,16 @@ class MailerTest extends TestCase
 
     public function testSet()
     {
-        $email = $this->getMockForEmail('viewVars');
+        $email = $this->getMockForEmail('setViewVars');
         $email->expects($this->once())
-            ->method('viewVars')
+            ->method('setViewVars')
             ->with(['key' => 'value']);
         $result = (new TestMailer($email))->set('key', 'value');
         $this->assertInstanceOf('TestApp\Mailer\TestMailer', $result);
 
-        $email = $this->getMockForEmail('viewVars');
+        $email = $this->getMockForEmail('setViewVars');
         $email->expects($this->once())
-            ->method('viewVars')
+            ->method('setViewVars')
             ->with(['key' => 'value']);
         $result = (new TestMailer($email))->set(['key' => 'value']);
         $this->assertInstanceOf('TestApp\Mailer\TestMailer', $result);