diff --git a/src/DependencyInjection/ServiceContainer.php b/src/DependencyInjection/ServiceContainer.php index 9e4d61f..28b2d23 100644 --- a/src/DependencyInjection/ServiceContainer.php +++ b/src/DependencyInjection/ServiceContainer.php @@ -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; } diff --git a/src/Validator/FileValidatorTrait.php b/src/Validator/FileValidatorTrait.php index 33e3f61..7292dc7 100644 --- a/src/Validator/FileValidatorTrait.php +++ b/src/Validator/FileValidatorTrait.php @@ -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); } diff --git a/tests/Base/BaseTest.php b/tests/Base/BaseTest.php index a8e5cea..4d98fef 100644 --- a/tests/Base/BaseTest.php +++ b/tests/Base/BaseTest.php @@ -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 { diff --git a/tests/unit/FileHashCheckerTest.php b/tests/unit/FileHashCheckerTest.php index 64d3566..ee8c8c2 100644 --- a/tests/unit/FileHashCheckerTest.php +++ b/tests/unit/FileHashCheckerTest.php @@ -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 { @@ -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']; } @@ -41,6 +43,10 @@ public static function tearDownAfterClass(): void parent::tearDownAfterClass(); } + + /** + * @throws HashException + */ #[Test] public function shouldGenerateValidHashForDifferentAlgo(): void { @@ -58,6 +64,10 @@ public function shouldGenerateValidHashForDifferentAlgo(): void $this->assertEquals($expectedHash, $actualHash); } + /** + * @throws HashException + * @throws FileHandlerException + */ #[Test] public function checkFileIntegrityReturnsTrueIfHashMatch(): void { @@ -66,6 +76,10 @@ public function checkFileIntegrityReturnsTrueIfHashMatch(): void $this->assertTrue($isVerified); } + /** + * @throws HashException + * @throws FileHandlerException + */ #[Test] public function shouldReturnFalseIfFileIsModified(): void { @@ -79,6 +93,10 @@ public function shouldReturnFalseIfFileIsModified(): void file_put_contents("movie.csv", $backup); } + /** + * @throws HashException + * @throws FileHandlerException + */ #[Test] public function shouldReturnFalseIfDifferentAlgoIsUsedForVerifyHash(): void {