Skip to content

Commit

Permalink
Toggle deprecation warnings on error level.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
markstory committed Aug 28, 2017
1 parent b6ce0fe commit 8768110
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Core/functions.php
Expand Up @@ -260,7 +260,7 @@ function env($key, $default = null)
*/
function deprecationWarning($message, $stackFrame = 2)
{
if (!Configure::read('debug')) {
if (!(error_reporting() & E_USER_DEPRECATED)) {
return;
}
$trace = debug_backtrace();
Expand Down
12 changes: 4 additions & 8 deletions tests/TestCase/Core/FunctionsTest.php
Expand Up @@ -14,7 +14,6 @@
*/
namespace Cake\Test\TestCase\Core;

use Cake\Core\Configure;
use Cake\TestSuite\TestCase;

/**
Expand Down Expand Up @@ -50,9 +49,8 @@ public function testEnv()
* @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);
}
Expand All @@ -63,9 +61,8 @@ public function testDeprecationWarningDebugEnabled()
* @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');
}
Expand All @@ -75,10 +72,9 @@ public function testDeprecationWarningDebugEnabledDefaultFrame()
*
* @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'));
}
}

0 comments on commit 8768110

Please sign in to comment.