Ejemplo n.º 1
0
 /**
  * ZIP files consist of a series of records with headers and optional bodies.
  * The main info is divided between Local File and Central File records. We
  * should be able to report an accurate list of all records in summmary form.
  *
  * @dataProvider  providerTestFixtures
  * @param  string  $filename  sample zip filename
  * @param  string  $records   expected list of valid records
  */
 public function testStoresListOfAllValidRecords($filename, $records)
 {
     $zip = new ZipInfo();
     $zip->open($filename, true);
     $this->assertEmpty($zip->error, $zip->error);
     $recordList = $zip->getRecords();
     $this->assertEquals(count($records), count($recordList));
     $this->assertEquals($records, $recordList);
 }
Ejemplo n.º 2
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";
    }
}