mirror of
https://github.com/yiisoft/yii.git
synced 2026-02-20 01:21:22 +01:00
Fixes #4573: Fix test to catch mb_strtolower(null, ...) deprecation in PHP 8.1+
This commit is contained in:
@@ -254,6 +254,19 @@ class CArrayDataProviderTest extends CTestCase
|
||||
return false;
|
||||
});
|
||||
|
||||
$previousErrorReporting = error_reporting(E_ALL);
|
||||
$previousHandler = set_error_handler(function ($errno, $errstr) {
|
||||
if (($errno & (E_DEPRECATED | E_USER_DEPRECATED)) !== 0
|
||||
&& strpos($errstr, 'mb_strtolower') !== false
|
||||
) {
|
||||
throw new ErrorException($errstr, 0, $errno);
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
$exception = null;
|
||||
|
||||
try {
|
||||
$data = array(
|
||||
array('id' => 1, 'name' => 'Alpha'),
|
||||
@@ -280,7 +293,7 @@ class CArrayDataProviderTest extends CTestCase
|
||||
|
||||
$dataProvider->caseSensitiveSort = false;
|
||||
|
||||
// Before the fix this call triggered a deprecation in PHP 8.1+ via mb_strtolower(null, ...)
|
||||
// Before the fix on PHP 8.1+ this triggered a deprecation via mb_strtolower(null, ...)
|
||||
$items = $dataProvider->getData();
|
||||
|
||||
$this->assertCount(3, $items);
|
||||
@@ -297,9 +310,17 @@ class CArrayDataProviderTest extends CTestCase
|
||||
$this->assertNull($item['name']);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
set_error_handler($previousHandler);
|
||||
error_reporting($previousErrorReporting);
|
||||
} catch (Exception $e) {
|
||||
$exception = $e;
|
||||
}
|
||||
|
||||
// emulate finally: always restore handler & error_reporting
|
||||
set_error_handler($previousHandler);
|
||||
error_reporting($previousErrorReporting);
|
||||
|
||||
if ($exception !== null) {
|
||||
// rethrow after cleanup so the test still fails correctly
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user