NewUnixExtraFieldTest.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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\ZipException;
  12. use PhpZip\Model\Extra\Fields\NewUnixExtraField;
  13. /**
  14. * Class NewUnixExtraFieldTest.
  15. *
  16. * @internal
  17. *
  18. * @small
  19. */
  20. final class NewUnixExtraFieldTest extends TestCase
  21. {
  22. /**
  23. * @dataProvider provideExtraField
  24. *
  25. * @throws ZipException
  26. */
  27. public function testExtraField(int $version, int $uid, int $gid, string $binaryData): void
  28. {
  29. $extraField = new NewUnixExtraField($version, $uid, $gid);
  30. self::assertSame($extraField->getHeaderId(), NewUnixExtraField::HEADER_ID);
  31. self::assertSame($extraField->getVersion(), $version);
  32. self::assertSame($extraField->getGid(), $gid);
  33. self::assertSame($extraField->getUid(), $uid);
  34. self::assertEquals(NewUnixExtraField::unpackLocalFileData($binaryData), $extraField);
  35. self::assertEquals(NewUnixExtraField::unpackCentralDirData($binaryData), $extraField);
  36. self::assertSame($extraField->packLocalFileData(), $binaryData);
  37. self::assertSame($extraField->packCentralDirData(), $binaryData);
  38. }
  39. public function provideExtraField(): array
  40. {
  41. return [
  42. [
  43. 1,
  44. NewUnixExtraField::USER_GID_PID,
  45. NewUnixExtraField::USER_GID_PID,
  46. "\x01\x04\xE8\x03\x00\x00\x04\xE8\x03\x00\x00",
  47. ],
  48. [
  49. 1,
  50. 501,
  51. 20,
  52. "\x01\x04\xF5\x01\x00\x00\x04\x14\x00\x00\x00",
  53. ],
  54. [
  55. 1,
  56. 500,
  57. 495,
  58. "\x01\x04\xF4\x01\x00\x00\x04\xEF\x01\x00\x00",
  59. ],
  60. [
  61. 1,
  62. 11252,
  63. 10545,
  64. "\x01\x04\xF4+\x00\x00\x041)\x00\x00",
  65. ],
  66. [
  67. 1,
  68. 1721,
  69. 1721,
  70. "\x01\x04\xB9\x06\x00\x00\x04\xB9\x06\x00\x00",
  71. ],
  72. ];
  73. }
  74. public function testSetter(): void
  75. {
  76. $extraField = new NewUnixExtraField(1, 1000, 1000);
  77. self::assertSame(1, $extraField->getVersion());
  78. self::assertSame(1000, $extraField->getUid());
  79. self::assertSame(1000, $extraField->getGid());
  80. $extraField->setUid(0);
  81. self::assertSame(0, $extraField->getUid());
  82. self::assertSame(1000, $extraField->getGid());
  83. $extraField->setGid(0);
  84. self::assertSame(0, $extraField->getUid());
  85. self::assertSame(0, $extraField->getGid());
  86. }
  87. }