Strings.replace().errors.callback.phpt 580 B

12345678910111213141516171819202122232425
  1. <?php
  2. /**
  3. * Test: Nette\Utils\Strings and error in callback.
  4. */
  5. declare(strict_types=1);
  6. use Nette\Utils\Strings;
  7. use Tester\Assert;
  8. require __DIR__ . '/../bootstrap.php';
  9. Assert::error(fn() => Strings::replace('hello', '#.+#', function ($m) {
  10. $a++; // E_NOTICE
  11. return strtoupper($m[0]);
  12. }), ...(PHP_VERSION_ID < 80000 ? [E_NOTICE, 'Undefined variable: a'] : [E_WARNING, 'Undefined variable $a']));
  13. Assert::same('HELLO', Strings::replace('hello', '#.+#', function ($m) {
  14. preg_match('#\d#u', "0123456789\xFF"); // Malformed UTF-8 data
  15. return strtoupper($m[0]);
  16. }));