Skip to content

Commit

Permalink
test: Add more Hash test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
tienvx committed Apr 25, 2024
1 parent 07a644b commit ed7c4e7
Showing 1 changed file with 17 additions and 3 deletions.
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

0 comments on commit ed7c4e7

Please sign in to comment.