Browse Source

added deprecated helper

saeid 8 years ago
parent
commit
fbaf969c53
2 changed files with 53 additions and 0 deletions
  1. 14 0
      src/TestSuite/TestCase.php
  2. 39 0
      tests/TestCase/TestSuite/TestCaseTest.php

+ 14 - 0
src/TestSuite/TestCase.php

@@ -88,6 +88,20 @@ abstract class TestCase extends BaseTestCase
     }
 
     /**
+     * Helper method for check deprecation methods
+     *
+     * @param callable $callable callable function that will receive asserts
+     * @return void
+     */
+    public function deprecated($callable)
+    {
+        $errorLevel = error_reporting();
+        error_reporting(E_ALL ^ E_USER_DEPRECATED);
+            $callable();
+        error_reporting($errorLevel);
+    }
+
+    /**
      * Setup the test case, backup the static object values so they can be restored.
      * Specifically backs up the contents of Configure and paths in App if they have
      * not already been backed up.

+ 39 - 0
tests/TestCase/TestSuite/TestCaseTest.php

@@ -176,6 +176,45 @@ class TestCaseTest extends TestCase
     }
 
     /**
+     * testDeprecated
+     *
+     * @return void
+     */
+    public function testDeprecated()
+    {
+        $value = 'custom';
+        $setter = 'setLayout';
+        $getter = 'getLayout';
+        $property = 'layout';
+        $controller = new \Cake\Controller\Controller();
+        $controller->viewBuilder()->{$setter}($value);
+        $this->deprecated(function () use ($value, $getter, $controller, $property) {
+              $this->assertSame($value, $controller->$property);
+              $this->assertSame($value, $controller->viewBuilder()->{$getter}());
+        });
+    }
+
+    /**
+     * testDeprecated
+     *
+     * @expectedException \PHPUnit\Framework\AssertionFailedError
+     * @return void
+     */
+    public function testDeprecatedWithException()
+    {
+        $value = 'custom';
+        $setter = 'setLayout';
+        $getter = 'getLayout';
+        $property = 'layout';
+        $controller = new \Cake\Controller\Controller();
+        $controller->viewBuilder()->{$setter}($value);
+        $this->deprecated(function () use ($value, $getter, $controller, $property) {
+              $this->assertSame($value, $controller->$property);
+              $this->assertSame('Derp', $controller->viewBuilder()->{$getter}());
+        });
+    }
+
+    /**
      * Test that TestCase::setUp() backs up values.
      *
      * @return void