Exemple #1
0
 /**
  * PAR2 files consist of self-contained packets with their own checksums, of
  * various types. Redundancy means that details of the recovery set are repeated
  * across multiple files, and within files. Packets should only be added to the
  * list if they pass the internal checksum test.
  *
  * @dataProvider  providerTestFixtures
  * @param  string  $filename  sample par2 filename
  * @param  string  $packets   expected list of valid packets
  */
 public function testStoresListOfAllValidPackets($filename, $packets)
 {
     $par2 = new Par2Info();
     $par2->open($filename);
     $this->assertEmpty($par2->error, $par2->error);
     $packetList = $par2->getPackets(true);
     $this->assertEquals(count($packets), count($packetList));
     $this->assertEquals($packets, $packetList);
 }
Exemple #2
0
/**
 * Generates test fixtures from PAR2 sample files.
 *
 * @param   boolean  $pretend  debug output only?
 * @param   boolean  $refresh  regenerate existing files?
 * @return  void
 */
function makePar2Fixtures($pretend = false, $refresh = true)
{
    $par2 = new Par2Info();
    foreach (glob(dirname(__FILE__) . '/par2/*.par2') as $par2file) {
        $fname = pathinfo($par2file, PATHINFO_BASENAME) . '.packets';
        $file = dirname(__FILE__) . "/par2/{$fname}";
        if (!$refresh && file_exists($file)) {
            continue;
        }
        echo "Generating for {$par2file}:\n";
        $par2->open($par2file);
        if ($par2->error) {
            echo "Error: {$par2->error}\n";
            continue;
        }
        $data = $par2->getPackets(true);
        if (!$pretend) {
            $data = "<?php\nreturn " . var_export($data, true) . ";\n";
            file_put_contents($file, $data);
        }
        echo "-- {$fname}\n";
    }
}