BSDTarOutputParserTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace Alchemy\Zippy\Tests\Parser;
  3. use Alchemy\Zippy\Parser\BSDTarOutputParser;
  4. use Alchemy\Zippy\Tests\TestCase;
  5. class BSDTarOutputParserTest extends TestCase
  6. {
  7. public function testNewParser()
  8. {
  9. return new BSDTarOutputParser();
  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 = "drw-rw-r-- 0 toto titi 0 Jan 3 1980 practice/
  19. -rw-rw-r-- 0 toto titi 0 Jan 3 1980 practice/newfile
  20. -rw-rw-r-- 0 toto titi 0 Aug 23 1999 practice/hello
  21. -rw-rw-r-- 0 toto titi 10240 Jan 22 13:31 practice/records";
  22. $members = $parser->parseFileListing($output);
  23. $this->assertEquals(4, count($members));
  24. foreach ($members as $member) {
  25. $this->assertTrue(is_array($member));
  26. }
  27. $memberDirectory = array_shift($members);
  28. $this->assertTrue($memberDirectory['is_dir']);
  29. $this->assertEquals('practice/', $memberDirectory['location']);
  30. $this->assertEquals(0, $memberDirectory['size']);
  31. $date = $memberDirectory['mtime'];
  32. $this->assertTrue($date instanceof \DateTime);
  33. $this->assertEquals('1980-01-03', $date->format("Y-m-d"));
  34. $memberFile = array_pop($members);
  35. $this->assertFalse($memberFile['is_dir']);
  36. $this->assertEquals('practice/records', $memberFile['location']);
  37. $this->assertEquals(10240, $memberFile['size']);
  38. $date = $memberFile['mtime'];
  39. $this->assertTrue($date instanceof \DateTime);
  40. $this->assertEquals('1358861460', $date->format("U"));
  41. ini_set('date.timezone', $current_timezone);
  42. }
  43. /**
  44. * @depends testNewParser
  45. */
  46. public function testParseVersion($parser)
  47. {
  48. $this->assertEquals('2.8.3', $parser->parseInflatorVersion("bsdtar 2.8.3 - libarchive 2.8.3"));
  49. }
  50. }