Skip to content

Commit 9986cf8

Browse files
author
Konrad Michalik
authored
Merge pull request #50 from move-elevator/fix-key-naming-enum
fix: improve error handling in EncodingValidator and update expected_convention in tests
2 parents 93c6e74 + 7033aee commit 9986cf8

4 files changed

Lines changed: 12 additions & 4 deletions

File tree

src/Validator/EncodingValidator.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ public function processFile(ParserInterface $file): array
4141
$filePath = $file->getFilePath();
4242
$issues = [];
4343

44+
if (!file_exists($filePath)) {
45+
$this->logger?->error(
46+
'File does not exist: '.$file->getFileName(),
47+
);
48+
49+
return [];
50+
}
51+
4452
// Read raw file content
4553
$content = file_get_contents($filePath);
4654
if (false === $content) {

src/Validator/KeyNamingConventionValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function processFile(ParserInterface $file): array
7070
$issueData[] = [
7171
'key' => $key,
7272
'file' => $file->getFileName(),
73-
'expected_convention' => $this->convention,
73+
'expected_convention' => $this->convention->value ?? 'custom pattern',
7474
'pattern' => $this->getActivePattern(),
7575
'suggestion' => $this->suggestCorrection($key),
7676
];

tests/src/Validator/EncodingValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ public function testFileReadErrorHandling(): void
329329
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
330330
$logger->expects($this->once())
331331
->method('error')
332-
->with('Could not read file content: temp-file.yaml');
332+
->with('File does not exist: temp-file.yaml');
333333

334334
$validator = new EncodingValidator($logger);
335335
$issues = $validator->processFile($mockParser);

tests/src/Validator/KeyNamingConventionValidatorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,8 @@ public function testDotNotationValidation(): void
588588
// Should detect invalid_key as violation
589589
$this->assertCount(1, $result);
590590
$this->assertEquals('invalid_key', $result[0]['key']);
591-
// expected_convention is now an enum, not a string
592-
$this->assertInstanceOf(\MoveElevator\ComposerTranslationValidator\Enum\KeyNamingConvention::class, $result[0]['expected_convention']);
591+
// expected_convention is now a string value from enum
592+
$this->assertEquals('dot.notation', $result[0]['expected_convention']);
593593
}
594594

595595
public function testDotNotationConversion(): void

0 commit comments

Comments
 (0)