UnrecognizedExtraFieldTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of the nelexa/zip package.
  5. * (c) Ne-Lexa <https://github.com/Ne-Lexa/php-zip>
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. namespace PhpZip\Tests\Extra\Fields;
  10. use PHPUnit\Framework\TestCase;
  11. use PhpZip\Exception\RuntimeException;
  12. use PhpZip\Model\Extra\Fields\UnrecognizedExtraField;
  13. /**
  14. * Class UnrecognizedExtraFieldTest.
  15. *
  16. * @internal
  17. *
  18. * @small
  19. */
  20. final class UnrecognizedExtraFieldTest extends TestCase
  21. {
  22. public function testExtraField(): void
  23. {
  24. $headerId = 0xF00D;
  25. $binaryData = "\x01\x02\x03\x04\x05";
  26. $unrecognizedExtraField = new UnrecognizedExtraField($headerId, $binaryData);
  27. self::assertSame($unrecognizedExtraField->getHeaderId(), $headerId);
  28. self::assertSame($unrecognizedExtraField->getData(), $binaryData);
  29. $newHeaderId = 0xDADA;
  30. $newBinaryData = "\x05\x00";
  31. $unrecognizedExtraField->setHeaderId($newHeaderId);
  32. self::assertSame($unrecognizedExtraField->getHeaderId(), $newHeaderId);
  33. $unrecognizedExtraField->setData($newBinaryData);
  34. self::assertSame($unrecognizedExtraField->getData(), $newBinaryData);
  35. self::assertSame($unrecognizedExtraField->packLocalFileData(), $newBinaryData);
  36. self::assertSame($unrecognizedExtraField->packCentralDirData(), $newBinaryData);
  37. }
  38. public function testUnpackLocalData(): void
  39. {
  40. $this->expectException(RuntimeException::class);
  41. $this->expectExceptionMessage('Unsupport parse');
  42. UnrecognizedExtraField::unpackLocalFileData("\x01\x02");
  43. }
  44. public function testUnpackCentralDirData(): void
  45. {
  46. $this->expectException(RuntimeException::class);
  47. $this->expectExceptionMessage('Unsupport parse');
  48. UnrecognizedExtraField::unpackCentralDirData("\x01\x02");
  49. }
  50. }