diff --git a/README.md b/README.md index c435f2d..59c31b6 100644 --- a/README.md +++ b/README.md @@ -150,7 +150,7 @@ if ($sevenZip->checkSupport(['zip', 'tar', '7z'])) { - [x] Auto untar on extraction - [x] Filter files by patterns - [x] Encrypt and decrypt -- [ ] Test files using 7z test command +- [x] Test files using 7z test command - [x] Detect supported formats by the OS - [x] Add built-in binaries for mac and linux - [x] ~~Use docker for PHPUnit tests~~ not needed with built-in binaries @@ -883,6 +883,22 @@ Configures maximum compression settings based on the specified format. **Returns**: The current instance for method chaining. +### `verify(): string` + +Tests the integrity of an archive. + +**Returns**: The output of the 7-Zip command. + +**Throws** + +- `InvalidArgumentException`: If the archive path (source) is not set. + +**Example** + +```php +$sevenZip->source('/path/to/archive.7z')->verify(); +``` + ## License This package is open-sourced software licensed under the [MIT license](./LICENSE.md). diff --git a/src/SevenZip.php b/src/SevenZip.php index 0a734f0..44b0bd2 100644 --- a/src/SevenZip.php +++ b/src/SevenZip.php @@ -1157,41 +1157,13 @@ public function rename(array $renames): string public function test(): bool { try { - $this->testWithDetails(); + $this->verify(); return true; } catch (\RuntimeException $e) { return false; } } - /** - * Test the integrity of an archive with detailed output. - * - * @return string The output of the test command. - * @throws \InvalidArgumentException If the source path is not set. - * @throws \RuntimeException If the archive is corrupted or invalid. - */ - public function testWithDetails(): string - { - if (!$this->getSourcePath()) { - throw new \InvalidArgumentException('Archive path (source) must be set'); - } - - if ($this->getPassword()) { - $this->addFlag('p', $this->getPassword(), glued: true); - } - - $command = [ - $this->getSevenZipPath(), - 't', - ...$this->flagrize($this->getAlwaysFlags()), - ...$this->flagrize($this->getCustomFlags()), - $this->getSourcePath(), - ]; - - return $this->runCommand($command); - } - /** * Format flags and values into an array of strings suitable for passing to 7-Zip commands. *