Skip to content

Commit 6ccf1db

Browse files
authored
minor changes (#45)
Signed-off-by: rahul <rcsofttech85@gmail.com>
1 parent 5730f0e commit 6ccf1db

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

src/DependencyInjection/ServiceContainer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function getContainerBuilder(): ContainerBuilder
1919
$loader = new YamlFileLoader($containerBuilder, new FileLocator(__DIR__ . '/../../src/config'));
2020
$loader->load('services.yaml');
2121

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

2424
return $containerBuilder;
2525
}

src/Validator/FileValidatorTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ public function validateFileName(string $filename, string|null $path = null): st
1717
{
1818
$container = (new ServiceContainer())->getContainerBuilder();
1919

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

2222
if ($filename != $stored_hash_file) {
23-
self::sanitize($filename);
23+
$this->sanitize($filename);
2424
}
2525

2626

tests/Base/BaseTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class BaseTest extends TestCase
1313
*/
1414
protected static array|null $files = [];
1515

16-
private static ContainerBuilder|null $containerBuilder;
16+
protected static ContainerBuilder|null $containerBuilder;
1717

1818
public static function setUpBeforeClass(): void
1919
{

tests/unit/FileHashCheckerTest.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
use Base\BaseTest;
66
use PHPUnit\Framework\Attributes\Test;
7+
use Rcsofttech85\FileHandler\Exception\FileHandlerException;
8+
use Rcsofttech85\FileHandler\Exception\HashException;
79
use Rcsofttech85\FileHandler\FileHashChecker;
8-
use Symfony\Component\Dotenv\Dotenv;
910

1011
class FileHashCheckerTest extends BaseTest
1112
{
@@ -29,10 +30,11 @@ protected function tearDown(): void
2930
public static function setUpBeforeClass(): void
3031
{
3132
parent::setUpBeforeClass();
32-
$dotenv = new Dotenv();
33-
$dotenv->load('.env');
3433

35-
self::$file = $_ENV['FILE_NAME'];
34+
$file = self::$containerBuilder->getParameter('STORED_HASH_FILE');
35+
if (is_string($file)) {
36+
self::$file = $file;
37+
}
3638
static::$files = ['movie.csv', 'sample'];
3739
}
3840

@@ -41,6 +43,10 @@ public static function tearDownAfterClass(): void
4143
parent::tearDownAfterClass();
4244
}
4345

46+
47+
/**
48+
* @throws HashException
49+
*/
4450
#[Test]
4551
public function shouldGenerateValidHashForDifferentAlgo(): void
4652
{
@@ -58,6 +64,10 @@ public function shouldGenerateValidHashForDifferentAlgo(): void
5864
$this->assertEquals($expectedHash, $actualHash);
5965
}
6066

67+
/**
68+
* @throws HashException
69+
* @throws FileHandlerException
70+
*/
6171
#[Test]
6272
public function checkFileIntegrityReturnsTrueIfHashMatch(): void
6373
{
@@ -66,6 +76,10 @@ public function checkFileIntegrityReturnsTrueIfHashMatch(): void
6676
$this->assertTrue($isVerified);
6777
}
6878

79+
/**
80+
* @throws HashException
81+
* @throws FileHandlerException
82+
*/
6983
#[Test]
7084
public function shouldReturnFalseIfFileIsModified(): void
7185
{
@@ -79,6 +93,10 @@ public function shouldReturnFalseIfFileIsModified(): void
7993
file_put_contents("movie.csv", $backup);
8094
}
8195

96+
/**
97+
* @throws HashException
98+
* @throws FileHandlerException
99+
*/
82100
#[Test]
83101
public function shouldReturnFalseIfDifferentAlgoIsUsedForVerifyHash(): void
84102
{

0 commit comments

Comments
 (0)