Skip to content

Commit

Permalink
Fix test.
Browse files Browse the repository at this point in the history
Cannot rely on the order that the directory is iterated. On
my development machine, in fact, these are returned in a different
order.
  • Loading branch information
mrubinsk committed Feb 11, 2019
1 parent b2be2ef commit 5377519
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 43 deletions.
28 changes: 19 additions & 9 deletions test/Horde/Compress/TarTest.php
Expand Up @@ -115,14 +115,24 @@ public function testTarDirectory()
return strcmp($a['name'], $b['name']);
});
$this->assertCount(3, $list);
$this->assertEquals('one.txt', $list[0]['name']);
$this->assertEquals(4, $list[0]['size']);
$this->assertEquals("One\n", $list[0]['data']);
$this->assertEquals('sub/three.txt', $list[1]['name']);
$this->assertEquals(6, $list[1]['size']);
$this->assertEquals("Three\n", $list[1]['data']);
$this->assertEquals('two.bin', $list[2]['name']);
$this->assertEquals(2, $list[2]['size']);
$this->assertEquals("\x02\x0a", $list[2]['data']);

$fixtures = array(
'one.txt' => array(4, "One\n"),
'sub/three.txt' => array(6, "Three\n"),
'two.bin' => array(2, "\x02\x0a")
);
foreach ($fixtures as $key => $testValues) {
$found = false;
foreach ($list as $file) {
if ($file['name'] == $key) {
$found = true;
$this->assertEquals($testValues[0], $file['size']);
$this->assertEquals($testValues[1], $file['data']);
}
}
if (!$found) {
$this->fail($key . ' not found.');
}
}
}
}
60 changes: 26 additions & 34 deletions test/Horde/Compress/ZipTest.php
Expand Up @@ -146,41 +146,33 @@ public function testZipDirectory()
return strcmp($a['name'], $b['name']);
});
$this->assertCount(3, $list);
$this->assertEquals('one.txt', $list[0]['name']);
$this->assertEquals(4, $list[0]['size']);
$this->assertEquals('sub/three.txt', $list[1]['name']);
$this->assertEquals(6, $list[1]['size']);
$this->assertEquals('two.bin', $list[2]['name']);
$this->assertEquals(2, $list[2]['size']);

$data = $compress->decompress(
$zip_data,
array(
'action' => Horde_Compress_Zip::ZIP_DATA,
'info' => $list,
'key' => 0
)
);
$this->assertEquals("One\n", $data);

$data = $compress->decompress(
$zip_data,
array(
'action' => Horde_Compress_Zip::ZIP_DATA,
'info' => $list,
'key' => 1
)
);
$this->assertEquals("Three\n", $data);

$data = $compress->decompress(
$zip_data,
array(
'action' => Horde_Compress_Zip::ZIP_DATA,
'info' => $list,
'key' => 2
)
$fixtures = array(
'one.txt' => array(4, "One\n"),
'sub/three.txt' => array(6, "Three\n"),
'two.bin' => array(2, "\x02\x0a")
);
$this->assertEquals("\x02\x0a", $data);
foreach ($fixtures as $key => $testValues) {
$found = false;
for ($i = 0; $i < 3; $i++) {
$file = $list[$i];
if ($file['name'] == $key) {
$found = true;
$this->assertEquals($testValues[0], $file['size']);
$data = $compress->decompress(
$zip_data,
array(
'action' => Horde_Compress_Zip::ZIP_DATA,
'info' => $list,
'key' => $i
)
);
$this->assertEquals($testValues[1], $data);
}
}
if (!$found) {
$this->fail($key . ' not found.');
}
}
}
}

0 comments on commit 5377519

Please sign in to comment.