Skip to content

Commit

Permalink
Add support for ignoring deprecations by path
Browse files Browse the repository at this point in the history
Being able to have deprecations on globally but silence problematic
parts of your application or a noisy plugin that can't be upgraded just
yet allows developers more control when upgrading.

Instead of having to hope they don't add new deprecations they can fix
a part of their application and then remove it from the deprecation
ignore patterns.

I've used glob here instead of regex as I don't think the power of regex
is needed for this.

Refs #14915
  • Loading branch information
markstory committed Aug 23, 2020
1 parent 201ea18 commit ab26a03
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Core/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,16 @@ function deprecationWarning(string $message, int $stackFrame = 1): void
$frame = $trace[$stackFrame];
$frame += ['file' => '[internal]', 'line' => '??'];

$patterns = (array)Configure::read('Error.disableDeprecations');
$relative = substr($frame['file'], strlen(ROOT) + 1);
debug($relative);
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' .
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.disableDeprecations', ['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 ab26a03

Please sign in to comment.