function FileStorageTest::testCreateDirectoryFailWarning
Same name in other branches
- 9 core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php \Drupal\Tests\Component\PhpStorage\FileStorageTest::testCreateDirectoryFailWarning()
- 8.9.x core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php \Drupal\Tests\Component\PhpStorage\FileStorageTest::testCreateDirectoryFailWarning()
- 11.x core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php \Drupal\Tests\Component\PhpStorage\FileStorageTest::testCreateDirectoryFailWarning()
@covers ::createDirectory
File
-
core/
tests/ Drupal/ Tests/ Component/ PhpStorage/ FileStorageTest.php, line 102
Class
- FileStorageTest
- @coversDefaultClass \Drupal\Component\PhpStorage\FileStorage @group Drupal @group PhpStorage
Namespace
Drupal\Tests\Component\PhpStorageCode
public function testCreateDirectoryFailWarning() : void {
$directory = new vfsStreamDirectory('permissionDenied', 0200);
$storage = new FileStorage([
'directory' => $directory->url(),
'bin' => 'test',
]);
$code = "<?php\n echo 'here';";
// 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]);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.