GNUTarOutputParserTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace Alchemy\Zippy\Tests\Parser;
  3. use Alchemy\Zippy\Parser\GNUTarOutputParser;
  4. use Alchemy\Zippy\Tests\TestCase;
  5. class GNUTarOutputParserTest extends TestCase
  6. {
  7. public function testNewParser()
  8. {
  9. return new GNUTarOutputParser();
  10. }
  11. /**
  12. * @depends testNewParser
  13. */
  14. public function testParseFileListing($parser)
  15. {
  16. $current_timezone = ini_get('date.timezone');
  17. ini_set('date.timezone', 'UTC');
  18. $output = "drwxrwxrwx myself/user 0 2006-06-09 12:06 practice/
  19. -rw-rw-rw- myself/user 62373 2006-06-09 12:06 practice/blues
  20. -rw-rw-rw- myself/user 11481 2006-06-09 12:06 practice/folk
  21. -rw-rw-rw- myself/user 23152 2006-06-09 12:06 practice/jazz
  22. -rw-rw-rw- myself/user 10240 2006-06-09 12:06 practice/records";
  23. $members = $parser->parseFileListing($output);
  24. $this->assertEquals(5, count($members));
  25. foreach ($members as $member) {
  26. $this->assertTrue(is_array($member));
  27. }
  28. $memberDirectory = array_shift($members);
  29. $this->assertTrue($memberDirectory['is_dir']);
  30. $this->assertEquals('practice/', $memberDirectory['location']);
  31. $this->assertEquals(0, $memberDirectory['size']);
  32. $date = $memberDirectory['mtime'];
  33. $this->assertTrue($date instanceof \DateTime);
  34. $this->assertEquals('1149854760', $date->format("U"));
  35. $memberFile = array_pop($members);
  36. $this->assertFalse($memberFile['is_dir']);
  37. $this->assertEquals('practice/records', $memberFile['location']);
  38. $this->assertEquals(10240, $memberFile['size']);
  39. $date = $memberFile['mtime'];
  40. $this->assertTrue($date instanceof \DateTime);
  41. $this->assertEquals('1149854760', $date->format("U"));
  42. ini_set('date.timezone', $current_timezone);
  43. }
  44. /**
  45. * @depends testNewParser
  46. */
  47. public function testParseVersion($parser)
  48. {
  49. $this->assertEquals('2.8.3', $parser->parseInflatorVersion("bsdtar 2.8.3 - libarchive 2.8.3"));
  50. }
  51. }