Skip to content

Commit

Permalink
Merge 67dc641 into c062df8
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Aug 26, 2020
2 parents c062df8 + 67dc641 commit e7267f5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
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.disableDeprecations');
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.',
' `E_ALL & ~E_USER_DEPRECATED`, or add `%s` to ' .
' `Error.disableDeprecations` in your `config/app.php` to mute deprecations.',
$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.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 e7267f5

Please sign in to comment.