Пример #1
0
/**
 * Generates test fixtures from ZIP sample files.
 *
 * @param   boolean  $pretend  debug output only?
 * @param   boolean  $refresh  regenerate existing files?
 * @return  void
 */
function makeZipFixtures($pretend = false, $refresh = true)
{
    $zip = new ZipInfo();
    foreach (glob(dirname(__FILE__) . '/zip/*.zip') as $zipfile) {
        $fname = pathinfo($zipfile, PATHINFO_BASENAME) . '.records';
        $file = dirname(__FILE__) . "/zip/{$fname}";
        if (!$refresh && file_exists($file)) {
            continue;
        }
        echo "Generating for {$zipfile}:\n";
        $zip->open($zipfile);
        if ($zip->error) {
            echo "Error: {$zip->error}\n";
            continue;
        }
        $data = $zip->getRecords();
        if (!$pretend) {
            $data = "<?php\nreturn " . var_export($data, true) . ";\n";
            file_put_contents($file, $data);
        }
        echo "-- {$fname}\n";
    }
}
Пример #2
0
 /**
  * Decompression of archive contents should be possible by using an external
  * client to read the current file, or temporary files for data sources. The
  * test should be skipped if no external client is available.
  *
  * @group  external
  */
 public function testDecompressesWithExternalClient()
 {
     if (!($unzip = $this->getUnzipPath())) {
         $this->markTestSkipped();
     }
     $zip = new ZipInfo();
     // From a file source
     $zipfile = $this->fixturesDir . '/pecl_test.zip';
     $zip->open($zipfile);
     $this->assertEmpty($zip->error);
     $files = $zip->getFileList();
     $file = $files[3];
     $this->assertSame('entry1.txt', $file['name']);
     $this->assertSame(1, $file['compressed']);
     $data = $zip->extractFile($file['name']);
     $this->assertNotEmpty($zip->error);
     $this->assertContains('external client', $zip->error);
     $this->assertFalse($data);
     $zip->setExternalClient($unzip);
     $data = $zip->extractFile($file['name']);
     $this->assertEmpty($zip->error, $zip->error);
     $this->assertSame($file['size'], strlen($data));
     $this->assertSame($file['crc32'], dechex(crc32($data)));
     $this->assertSame("entry #1", $data);
     // From a data source (via temp file)
     $zip->setData(file_get_contents($zipfile));
     $this->assertEmpty($zip->error);
     $summary = $zip->getSummary(true);
     $this->assertSame(filesize($zipfile), $summary['data_size']);
     $data = $zip->extractFile($file['name']);
     $this->assertEmpty($zip->error);
     $this->assertSame($file['size'], strlen($data));
 }