function IconFinderTest::testExtractIconIdFromFilenameWarning
Test the IconFinder::extractIconIdFromFilename method with failing pattern.
File
-
core/
tests/ Drupal/ Tests/ Core/ Theme/ Icon/ IconFinderTest.php, line 776
Class
- IconFinderTest
- @coversDefaultClass \Drupal\Core\Theme\Icon\IconFinder
Namespace
Drupal\Tests\Core\Theme\IconCode
public function testExtractIconIdFromFilenameWarning() : void {
$method = new \ReflectionMethod(IconFinder::class, 'extractIconIdFromFilename');
$method->setAccessible(TRUE);
// PHPUnit 10 cannot expect warnings, so we have to catch them ourselves.
// Thanks to: Drupal\Tests\Component\PhpStorage\FileStorageTest.
$messages = [];
set_error_handler(function (int $errno, string $errstr) use (&$messages) : void {
$messages[] = [
$errno,
$errstr,
];
});
$method->invoke($this->iconFinder, 'foo*bar*baz', 'foo*{icon_id}*baz');
restore_error_handler();
$this->assertCount(1, $messages);
$this->assertSame(E_WARNING, $messages[0][0]);
$this->assertSame('preg_match(): Compilation failed: quantifier does not follow a repeatable item at offset 19', $messages[0][1]);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.