function ZipTest::testCreateArchive

Same name in other branches
  1. 10 core/tests/Drupal/KernelTests/Core/Archiver/ZipTest.php \Drupal\KernelTests\Core\Archiver\ZipTest::testCreateArchive()

Tests that the Zip archive is created if it does not exist.

File

core/tests/Drupal/KernelTests/Core/Archiver/ZipTest.php, line 22

Class

ZipTest
@coversDefaultClass \Drupal\Core\Archiver\Zip @group zip

Namespace

Drupal\KernelTests\Core\Archiver

Code

public function testCreateArchive() : void {
    $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.