Browse Source

Fix get methods not being proxied correctly.

Add method checking to make __call() better emulate the new
un-deprecated method proxies.

Refs #10721
Mark Story 8 years ago
parent
commit
145282f2c7
2 changed files with 22 additions and 1 deletions
  1. 4 1
      src/Mailer/Mailer.php
  2. 18 0
      tests/TestCase/Mailer/MailerTest.php

+ 4 - 1
src/Mailer/Mailer.php

@@ -249,7 +249,10 @@ abstract class Mailer implements EventListenerInterface
      */
     public function __call($method, $args)
     {
-        $this->_email->$method(...$args);
+        $result = $this->_email->$method(...$args);
+        if (strpos($method, 'get') === 0) {
+            return $result;
+        }
 
         return $this;
     }

+ 18 - 0
tests/TestCase/Mailer/MailerTest.php

@@ -53,6 +53,7 @@ class MailerTest extends TestCase
         $result = (new TestMailer())->layout('foo');
         $this->assertInstanceOf('TestApp\Mailer\TestMailer', $result);
         $this->assertEquals('foo', $result->viewBuilder()->layout());
+        $this->assertEquals('foo', $result->getLayout());
     }
 
     public function testProxies()
@@ -83,6 +84,23 @@ class MailerTest extends TestCase
         $this->assertInstanceOf('TestApp\Mailer\TestMailer', $result);
     }
 
+    /**
+     * Test that get/set methods can be proxied.
+     *
+     * @return void
+     */
+    public function testGetSetProxies()
+    {
+        $mailer = new TestMailer();
+        $result = $mailer->setLayout('custom')
+            ->setTo('test@example.com')
+            ->setCc('cc@example.com');
+        $this->assertSame($result, $mailer);
+
+        $this->assertSame(['test@example.com' => 'test@example.com'], $result->getTo());
+        $this->assertSame(['cc@example.com' => 'cc@example.com'], $result->getCc());
+    }
+
     public function testSet()
     {
         $email = $this->getMockForEmail('setViewVars');