Browse Source

Toggle deprecation warnings on error level.

By using the error level to control deprecation warnings, we allow users
to have them enabled in production but go into log files. This is useful
for ensuring all the deprecation warnings have been caught/fixed.
mark_story 8 years ago
parent
commit
876811065d
2 changed files with 5 additions and 9 deletions
  1. 1 1
      src/Core/functions.php
  2. 4 8
      tests/TestCase/Core/FunctionsTest.php

+ 1 - 1
src/Core/functions.php

@@ -260,7 +260,7 @@ if (!function_exists('deprecationWarning')) {
      */
     function deprecationWarning($message, $stackFrame = 2)
     {
-        if (!Configure::read('debug')) {
+        if (!(error_reporting() & E_USER_DEPRECATED)) {
             return;
         }
         $trace = debug_backtrace();

+ 4 - 8
tests/TestCase/Core/FunctionsTest.php

@@ -14,7 +14,6 @@
  */
 namespace Cake\Test\TestCase\Core;
 
-use Cake\Core\Configure;
 use Cake\TestSuite\TestCase;
 
 /**
@@ -50,9 +49,8 @@ class FunctionsTest extends TestCase
      * @expectedException PHPUnit\Framework\Error\Deprecated
      * @expectedExceptionMessage This is going away - [internal], line: ??
      */
-    public function testDeprecationWarningDebugEnabled()
+    public function testDeprecationWarningEnabled()
     {
-        Configure::write('debug', true);
         error_reporting(E_ALL);
         deprecationWarning('This is going away', 1);
     }
@@ -63,9 +61,8 @@ class FunctionsTest extends TestCase
      * @expectedException PHPUnit\Framework\Error\Deprecated
      * @expectedExceptionMessageRegExp /This is going away - (.*?)\/TestCase.php, line\: \d+/
      */
-    public function testDeprecationWarningDebugEnabledDefaultFrame()
+    public function testDeprecationWarningEnabledDefaultFrame()
     {
-        Configure::write('debug', true);
         error_reporting(E_ALL);
         deprecationWarning('This is going away');
     }
@@ -75,10 +72,9 @@ class FunctionsTest extends TestCase
      *
      * @return void
      */
-    public function testDeprecationWarningDebugDisabled()
+    public function testDeprecationWarningLevelDisabled()
     {
-        Configure::write('debug', false);
-        error_reporting(E_ALL);
+        error_reporting(E_ALL ^ E_USER_DEPRECATED);
         $this->assertNull(deprecationWarning('This is going away'));
     }
 }