Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/DependencyInjection/ServiceContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function getContainerBuilder(): ContainerBuilder
$loader = new YamlFileLoader($containerBuilder, new FileLocator(__DIR__ . '/../../src/config'));
$loader->load('services.yaml');

$containerBuilder->setParameter('FILE_NAME', $_ENV['FILE_NAME']);
$containerBuilder->setParameter('STORED_HASH_FILE', $_ENV['STORED_HASH_FILE']);

return $containerBuilder;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Validator/FileValidatorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ public function validateFileName(string $filename, string|null $path = null): st
{
$container = (new ServiceContainer())->getContainerBuilder();

$stored_hash_file = $container->getParameter('FILE_NAME');
$stored_hash_file = $container->getParameter('STORED_HASH_FILE');

if ($filename != $stored_hash_file) {
self::sanitize($filename);
$this->sanitize($filename);
}


Expand Down
2 changes: 1 addition & 1 deletion tests/Base/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class BaseTest extends TestCase
*/
protected static array|null $files = [];

private static ContainerBuilder|null $containerBuilder;
protected static ContainerBuilder|null $containerBuilder;

public static function setUpBeforeClass(): void
{
Expand Down
26 changes: 22 additions & 4 deletions tests/unit/FileHashCheckerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

use Base\BaseTest;
use PHPUnit\Framework\Attributes\Test;
use Rcsofttech85\FileHandler\Exception\FileHandlerException;
use Rcsofttech85\FileHandler\Exception\HashException;
use Rcsofttech85\FileHandler\FileHashChecker;
use Symfony\Component\Dotenv\Dotenv;

class FileHashCheckerTest extends BaseTest
{
Expand All @@ -29,10 +30,11 @@ protected function tearDown(): void
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
$dotenv = new Dotenv();
$dotenv->load('.env');

self::$file = $_ENV['FILE_NAME'];
$file = self::$containerBuilder->getParameter('STORED_HASH_FILE');
if (is_string($file)) {
self::$file = $file;
}
static::$files = ['movie.csv', 'sample'];
}

Expand All @@ -41,6 +43,10 @@ public static function tearDownAfterClass(): void
parent::tearDownAfterClass();
}


/**
* @throws HashException
*/
#[Test]
public function shouldGenerateValidHashForDifferentAlgo(): void
{
Expand All @@ -58,6 +64,10 @@ public function shouldGenerateValidHashForDifferentAlgo(): void
$this->assertEquals($expectedHash, $actualHash);
}

/**
* @throws HashException
* @throws FileHandlerException
*/
#[Test]
public function checkFileIntegrityReturnsTrueIfHashMatch(): void
{
Expand All @@ -66,6 +76,10 @@ public function checkFileIntegrityReturnsTrueIfHashMatch(): void
$this->assertTrue($isVerified);
}

/**
* @throws HashException
* @throws FileHandlerException
*/
#[Test]
public function shouldReturnFalseIfFileIsModified(): void
{
Expand All @@ -79,6 +93,10 @@ public function shouldReturnFalseIfFileIsModified(): void
file_put_contents("movie.csv", $backup);
}

/**
* @throws HashException
* @throws FileHandlerException
*/
#[Test]
public function shouldReturnFalseIfDifferentAlgoIsUsedForVerifyHash(): void
{
Expand Down