Browse Source

Split enableAutoRender($flag)
into enableAutoRender() and disableAutoRender().

Deprecated properties test added.

Robert Pustułka 8 years ago
parent
commit
cbf88f98e8
2 changed files with 66 additions and 8 deletions
  1. 21 6
      src/Controller/Controller.php
  2. 45 2
      tests/TestCase/Controller/ControllerTest.php

+ 21 - 6
src/Controller/Controller.php

@@ -383,8 +383,7 @@ class Controller implements EventListenerInterface, EventDispatcherInterface
     {
         $deprecated = [
             'name' => 'setName',
-            'plugin' => 'setPlugin',
-            'autoRender' => 'enableAutoRender',
+            'plugin' => 'setPlugin'
         ];
         if (isset($deprecated[$name])) {
             $method = $deprecated[$name];
@@ -392,6 +391,11 @@ class Controller implements EventListenerInterface, EventDispatcherInterface
 
             return;
         }
+        if ($name === 'autoRender') {
+            $value ? $this->enableAutoRender() : $this->disableAutoRender();
+
+            return;
+        }
         $deprecated = [
             'layout' => 'setLayout',
             'view' => 'setTemplate',
@@ -469,14 +473,25 @@ class Controller implements EventListenerInterface, EventDispatcherInterface
     }
 
     /**
-     * Enable or disbale automatic action rendering.
+     * Enable automatic action rendering.
      *
-     * @param bool $autoRender Flag.
      * @return $this
      */
-    public function enableAutoRender($autoRender = true)
+    public function enableAutoRender()
     {
-        $this->autoRender = $autoRender;
+        $this->autoRender = true;
+
+        return $this;
+    }
+
+    /**
+     * Disbale automatic action rendering.
+     *
+     * @return $this
+     */
+    public function disableAutoRender()
+    {
+        $this->autoRender = false;
 
         return $this;
     }

+ 45 - 2
tests/TestCase/Controller/ControllerTest.php

@@ -1164,7 +1164,7 @@ class ControllerTest extends TestCase
         $controller = new PostsController();
         $this->assertTrue($controller->isAutoRenderEnabled());
 
-        $this->assertSame($controller, $controller->enableAutoRender(false));
+        $this->assertSame($controller, $controller->disableAutoRender());
         $this->assertFalse($controller->isAutoRenderEnabled());
 
         $this->assertSame($controller, $controller->enableAutoRender());
@@ -1172,7 +1172,50 @@ class ControllerTest extends TestCase
     }
 
     /**
-     * Tests deprecated view propertiyes work
+     * Tests deprecated controller properties work
+     *
+     * @param $property Deprecated property name
+     * @param $getter Getter name
+     * @param $setter Setter name
+     * @param mixed $value Value to be set
+     * @return void
+     * @dataProvider deprecatedControllerPropertyProvider
+     */
+    public function testDeprecatedControllerProperty($property, $getter, $setter, $value)
+    {
+        $controller = new AnotherTestController();
+        $message = false;
+
+        set_error_handler(function ($errno, $errstr) use (&$message) {
+            $message = ($errno === E_USER_DEPRECATED ? $errstr : false);
+        });
+
+        try {
+            $controller->$property = $value;
+//
+            $this->assertSame($value, $controller->$property);
+            $this->assertSame($value, $controller->{$getter}());
+        } finally {
+            restore_error_handler();
+        }
+    }
+
+    /**
+     * Data provider for testing deprecated view properties
+     *
+     * @return array
+     */
+    public function deprecatedControllerPropertyProvider()
+    {
+        return [
+            ['name', 'getName', 'setName', 'Foo'],
+            ['plugin', 'getPlugin', 'setPlugin', 'Foo'],
+            ['autoRender', 'isAutoRenderEnabled', 'enableAutoRender/disableAutoRender', false],
+        ];
+    }
+
+    /**
+     * Tests deprecated view properties work
      *
      * @group deprecated
      * @param $property Deprecated property name