From 8840b115f31f1a1ae9121b9dc9b562cca36af133 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Mon, 21 Aug 2017 21:12:02 -0400 Subject: [PATCH] Add a deprecation warning helper. This will make adding framework deprecation warnings we plan to add in 3.6.x simpler as they will be easier to write. --- src/Core/functions.php | 13 +++++++++++++ tests/TestCase/Core/FunctionsTest.php | 9 +++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Core/functions.php b/src/Core/functions.php index 8cf95d4642e..f739a7485ab 100644 --- a/src/Core/functions.php +++ b/src/Core/functions.php @@ -248,3 +248,16 @@ function env($key, $default = null) } } + +if (!function_exists('deprecationWarning')) { + /** + * Helper method for outputting deprecation warnings + * + * @param string $message The message to output as a deprecation warning. + * @return void + */ + function deprecationWarning($message) + { + trigger_error($message, E_USER_DEPRECATED); + } +} diff --git a/tests/TestCase/Core/FunctionsTest.php b/tests/TestCase/Core/FunctionsTest.php index ccc171a50dd..2f2a71cd93d 100644 --- a/tests/TestCase/Core/FunctionsTest.php +++ b/tests/TestCase/Core/FunctionsTest.php @@ -42,4 +42,13 @@ public function testEnv() $this->assertEquals('0', env('ZERO')); $this->assertEquals('0', env('ZERO', '1')); } + + /** + * @expectedException PHPUnit\Framework\Error\Deprecated + * @expectedExceptionMessage This is going away + */ + public function testDeprecationWarning() + { + deprecationWarning('This is going away'); + } }