Skip to content

Commit

Permalink
Merge pull request #14925 from cakephp/deprecation-disable
Browse files Browse the repository at this point in the history
Add support for ignoring deprecations by path
  • Loading branch information
dereuromark committed Aug 28, 2020
2 parents fc3e741 + 42e48bf commit e194b11
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/Core/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,24 @@ function deprecationWarning(string $message, int $stackFrame = 1): void
$frame = $trace[$stackFrame];
$frame += ['file' => '[internal]', 'line' => '??'];

$relative = str_replace(DIRECTORY_SEPARATOR, '/', substr($frame['file'], strlen(ROOT) + 1));
$patterns = (array)Configure::read('Error.ignoredDeprecationPaths');
foreach ($patterns as $pattern) {
$pattern = str_replace(DIRECTORY_SEPARATOR, '/', $pattern);
if (fnmatch($pattern, $relative)) {
return;
}
}

$message = sprintf(
'%s - %s, line: %s' . "\n" .
' You can disable deprecation warnings by setting `Error.errorLevel` to' .
' `E_ALL & ~E_USER_DEPRECATED` in your config/app.php.',
' You can disable all deprecation warnings by setting `Error.errorLevel` to' .
' `E_ALL & ~E_USER_DEPRECATED`, or add `%s` to ' .
' `Error.ignoredDeprecationPaths` in your `config/app.php` to mute deprecations from only this file.',
$message,
$frame['file'],
$frame['line']
$frame['line'],
$relative
);
}

Expand Down
16 changes: 16 additions & 0 deletions tests/TestCase/Core/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
namespace Cake\Test\TestCase\Core;

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

Expand Down Expand Up @@ -101,6 +102,21 @@ public function testDeprecationWarningEnabledDefaultFrame()
});
}

/**
* Test no error when deprecation matches ignore paths.
*
* @return void
*/
public function testDeprecationWarningPathDisabled()
{
$this->expectNotToPerformAssertions();

Configure::write('Error.ignoredDeprecationPaths', ['src/TestSuite/*']);
$this->withErrorReporting(E_ALL, function () {
deprecationWarning('This is going away');
});
}

/**
* Test no error when deprecated level is off.
*
Expand Down

0 comments on commit e194b11

Please sign in to comment.