Skip to content

Commit 8768110

Browse files
committed
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.
1 parent b6ce0fe commit 8768110

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

src/Core/functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ function env($key, $default = null)
260260
*/
261261
function deprecationWarning($message, $stackFrame = 2)
262262
{
263-
if (!Configure::read('debug')) {
263+
if (!(error_reporting() & E_USER_DEPRECATED)) {
264264
return;
265265
}
266266
$trace = debug_backtrace();

tests/TestCase/Core/FunctionsTest.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
*/
1515
namespace Cake\Test\TestCase\Core;
1616

17-
use Cake\Core\Configure;
1817
use Cake\TestSuite\TestCase;
1918

2019
/**
@@ -50,9 +49,8 @@ public function testEnv()
5049
* @expectedException PHPUnit\Framework\Error\Deprecated
5150
* @expectedExceptionMessage This is going away - [internal], line: ??
5251
*/
53-
public function testDeprecationWarningDebugEnabled()
52+
public function testDeprecationWarningEnabled()
5453
{
55-
Configure::write('debug', true);
5654
error_reporting(E_ALL);
5755
deprecationWarning('This is going away', 1);
5856
}
@@ -63,9 +61,8 @@ public function testDeprecationWarningDebugEnabled()
6361
* @expectedException PHPUnit\Framework\Error\Deprecated
6462
* @expectedExceptionMessageRegExp /This is going away - (.*?)\/TestCase.php, line\: \d+/
6563
*/
66-
public function testDeprecationWarningDebugEnabledDefaultFrame()
64+
public function testDeprecationWarningEnabledDefaultFrame()
6765
{
68-
Configure::write('debug', true);
6966
error_reporting(E_ALL);
7067
deprecationWarning('This is going away');
7168
}
@@ -75,10 +72,9 @@ public function testDeprecationWarningDebugEnabledDefaultFrame()
7572
*
7673
* @return void
7774
*/
78-
public function testDeprecationWarningDebugDisabled()
75+
public function testDeprecationWarningLevelDisabled()
7976
{
80-
Configure::write('debug', false);
81-
error_reporting(E_ALL);
77+
error_reporting(E_ALL ^ E_USER_DEPRECATED);
8278
$this->assertNull(deprecationWarning('This is going away'));
8379
}
8480
}

0 commit comments

Comments
 (0)