Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add more Hash test cases #46

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions tests/Unit/Model/HashTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ class HashTest extends TestCase
{
private ?VirtualFileSystem $fs = null;
private string $tmpFile = '/path/to/vendor/composer/tmp-random';
private string $content = 'hello world';

protected function setUp(): void
{
$this->fs = new VirtualFileSystem();
$this->fs->createDirectory(\dirname($this->tmpFile), true);
$this->fs->createFile($this->tmpFile, $this->content);
}

protected function tearDown(): void
Expand All @@ -27,12 +30,23 @@ protected function tearDown(): void
*/
public function testVerifyFile(bool $isValid): void
{
$this->fs->createDirectory(\dirname($this->tmpFile), true);
$this->fs->createFile($this->tmpFile, $content = 'hello world');
$hash = new Hash('md5', $isValid ? md5($content) : 'not valid');
$hash = new Hash('md5', $isValid ? md5($this->content) : 'not valid');
$this->assertSame($isValid, $hash->verifyFile($this->getTmpFilePath()));
}

public function testVerifyNotExistFile(): void
{
$hash = new Hash('any', 'any');
$this->assertFalse($hash->verifyFile('/path/to/invalid/file.ext'));
}

public function testInvalidAlgo(): void
{
$this->expectException(\ValueError::class);
$hash = new Hash('invalid', 'any');
$hash->verifyFile($this->getTmpFilePath());
}

protected function getTmpFilePath(): string
{
return $this->fs->path($this->tmpFile);
Expand Down
Loading