function ZipTest::testCreateArchive
Tests that the Zip archive is created if it does not exist.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Archiver/ ZipTest.php, line 29
Class
- ZipTest
- Tests Drupal\Core\Archiver\Zip.
Namespace
Drupal\KernelTests\Core\ArchiverCode
public function testCreateArchive() : void {
$this->expectDeprecation('\\Drupal\\Core\\Archiver\\Zip is deprecated in drupal:11.3.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3556927');
$textFile = current($this->getTestFiles('text'));
$archiveFilename = $this->fileSystem
->realpath('public://' . $this->randomMachineName() . '.zip');
$zip = new Zip($archiveFilename, [
'flags' => \ZipArchive::CREATE,
]);
$zip->add($this->fileSystem
->realPath($textFile->uri));
// Close the archive and make sure it is written to disk.
$this->assertTrue($zip->getArchive()
->close(), 'Successfully closed archive.');
$this->assertFileExists($archiveFilename, 'Archive is automatically created if the file does not exist.');
$this->assertArchiveContainsFile($archiveFilename, $this->fileSystem
->realPath($textFile->uri));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.