Issue #3427173 by mondrake, longwave, alexpott, catch: Replace calls to :::expectWarning*() in Drupal\Tests\Component\PhpStorage\FileStorageTest
(cherry picked from commit c1b1ba78d6
)
merge-requests/7855/head
parent
c9248457c4
commit
6eb7fe2dcf
|
@ -2383,18 +2383,6 @@ $ignoreErrors[] = [
|
|||
'count' => 1,
|
||||
'path' => __DIR__ . '/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php',
|
||||
];
|
||||
$ignoreErrors[] = [
|
||||
'message' => '#^Call to deprecated method expectWarning\\(\\) of class PHPUnit\\\\Framework\\\\TestCase\\:
|
||||
https\\://github\\.com/sebastianbergmann/phpunit/issues/5062$#',
|
||||
'count' => 1,
|
||||
'path' => __DIR__ . '/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php',
|
||||
];
|
||||
$ignoreErrors[] = [
|
||||
'message' => '#^Call to deprecated method expectWarningMessage\\(\\) of class PHPUnit\\\\Framework\\\\TestCase\\:
|
||||
https\\://github\\.com/sebastianbergmann/phpunit/issues/5062$#',
|
||||
'count' => 1,
|
||||
'path' => __DIR__ . '/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php',
|
||||
];
|
||||
$ignoreErrors[] = [
|
||||
'message' => '#^Constructor of class Drupal\\\\Tests\\\\Component\\\\Plugin\\\\Factory\\\\ArgumentsAllNull has an unused parameter \\$charismatic\\.$#',
|
||||
'count' => 1,
|
||||
|
|
|
@ -106,9 +106,21 @@ class FileStorageTest extends PhpStorageTestBase {
|
|||
'bin' => 'test',
|
||||
]);
|
||||
$code = "<?php\n echo 'here';";
|
||||
$this->expectWarning();
|
||||
$this->expectWarningMessage('mkdir(): Permission Denied');
|
||||
|
||||
// PHPUnit 10 cannot expect warnings, so we have to catch them ourselves.
|
||||
$messages = [];
|
||||
set_error_handler(function (int $errno, string $errstr) use (&$messages): void {
|
||||
$messages[] = [$errno, $errstr];
|
||||
});
|
||||
|
||||
$storage->save('subdirectory/foo.php', $code);
|
||||
|
||||
restore_error_handler();
|
||||
$this->assertCount(2, $messages);
|
||||
$this->assertSame(E_USER_WARNING, $messages[0][0]);
|
||||
$this->assertSame('mkdir(): Permission Denied', $messages[0][1]);
|
||||
$this->assertSame(E_WARNING, $messages[1][0]);
|
||||
$this->assertStringStartsWith('file_put_contents(vfs://permissionDenied/test/subdirectory/foo.php)', $messages[1][1]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue