|
2 | 2 |
|
3 | 3 | namespace Aternos\IO\Test\Unit\System;
|
4 | 4 |
|
| 5 | +use Aternos\IO\Exception\ChmodException; |
5 | 6 | use Aternos\IO\Exception\IOException;
|
6 | 7 | use Aternos\IO\Exception\MoveException;
|
7 | 8 | use Aternos\IO\Exception\PathOutsideElementException;
|
|
12 | 13 | use Aternos\IO\System\Directory\Directory;
|
13 | 14 | use Aternos\IO\System\FilesystemElement;
|
14 | 15 | use Aternos\IO\System\FilesystemInterface;
|
| 16 | +use Aternos\IO\System\Util\Permissions; |
15 | 17 |
|
16 | 18 | abstract class FilesystemTestCase extends TmpDirTestCase
|
17 | 19 | {
|
@@ -426,6 +428,65 @@ public function testSetModificationTimestampThrowsExceptionOnImpossibleSet(): vo
|
426 | 428 | $element->setModificationTimestamp(1234567890);
|
427 | 429 | }
|
428 | 430 |
|
| 431 | + /** |
| 432 | + * @return void |
| 433 | + * @throws IOException |
| 434 | + * @throws StatException |
| 435 | + */ |
| 436 | + public function testGetPermissions(): void |
| 437 | + { |
| 438 | + $path = $this->getTmpPath() . "/test"; |
| 439 | + $element = $this->createElement($path); |
| 440 | + $this->create($element); |
| 441 | + chmod($path, 0o755); |
| 442 | + $this->assertEquals(0o755, $element->getPermissions()->toNumeric()); |
| 443 | + } |
| 444 | + |
| 445 | + /** |
| 446 | + * @return void |
| 447 | + * @throws IOException |
| 448 | + * @throws StatException |
| 449 | + */ |
| 450 | + public function testThrowsExceptionOnGetPermissions(): void |
| 451 | + { |
| 452 | + $path = $this->getTmpPath() . "/test"; |
| 453 | + $element = $this->createElement($path); |
| 454 | + $this->expectException(StatException::class); |
| 455 | + /** @noinspection SpellCheckingInspection */ |
| 456 | + $this->expectExceptionMessage("Could not get permissions (" . $path . ")"); |
| 457 | + $element->getPermissions(); |
| 458 | + } |
| 459 | + |
| 460 | + /** |
| 461 | + * @return void |
| 462 | + * @throws IOException |
| 463 | + * @throws ChmodException |
| 464 | + */ |
| 465 | + public function testSetPermissions(): void |
| 466 | + { |
| 467 | + $path = $this->getTmpPath() . "/test"; |
| 468 | + $element = $this->createElement($path); |
| 469 | + $this->create($element); |
| 470 | + chmod($path, 0o777); |
| 471 | + $element->setPermissions(Permissions::fromNumeric(0o755)); |
| 472 | + $this->assertEquals(0o755, fileperms($path) & 0o777); |
| 473 | + } |
| 474 | + |
| 475 | + /** |
| 476 | + * @return void |
| 477 | + * @throws IOException |
| 478 | + * @throws ChmodException |
| 479 | + */ |
| 480 | + public function testThrowsExceptionOnSetPermissions(): void |
| 481 | + { |
| 482 | + $path = $this->getTmpPath() . "/test"; |
| 483 | + $element = $this->createElement($path); |
| 484 | + $this->expectException(ChmodException::class); |
| 485 | + /** @noinspection SpellCheckingInspection */ |
| 486 | + $this->expectExceptionMessage("Could not set permissions (" . $path . ")"); |
| 487 | + $element->setPermissions(Permissions::fromNumeric(0o755)); |
| 488 | + } |
| 489 | + |
429 | 490 | /**
|
430 | 491 | * @return void
|
431 | 492 | */
|
|
0 commit comments