Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ignoring deprecations by path #14925

Merged
merged 8 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 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' .
garas marked this conversation as resolved.
Show resolved Hide resolved
' `E_ALL & ~E_USER_DEPRECATED` in your config/app.php.',
' `E_ALL & ~E_USER_DEPRECATED`, or add `%s` to ' .
' `Error.ignoredDeprecationPaths` in your `config/app.php` to mute deprecations.',
dereuromark marked this conversation as resolved.
Show resolved Hide resolved
$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