From 1f4e347cae51667e7cf5772aef55d274a39c8023 Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Thu, 20 Oct 2022 17:42:47 -0400 Subject: Add tests on i18n classes (#4756) --- cli/i18n/I18nCompletionValidator.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'cli/i18n/I18nCompletionValidator.php') diff --git a/cli/i18n/I18nCompletionValidator.php b/cli/i18n/I18nCompletionValidator.php index ee4ab9f78..000629f8d 100644 --- a/cli/i18n/I18nCompletionValidator.php +++ b/cli/i18n/I18nCompletionValidator.php @@ -16,6 +16,12 @@ class I18nCompletionValidator implements I18nValidatorInterface { } public function displayReport() { + if ($this->passEntries > $this->totalEntries) { + throw new \RuntimeException('The number of translated strings cannot be higher than the number of strings'); + } + if ($this->totalEntries === 0) { + return 'There is no data.' . PHP_EOL; + } return sprintf('Translation is %5.1f%% complete.', $this->passEntries / $this->totalEntries * 100) . PHP_EOL; } @@ -27,7 +33,7 @@ class I18nCompletionValidator implements I18nValidatorInterface { foreach ($this->reference as $file => $data) { foreach ($data as $refKey => $refValue) { $this->totalEntries++; - if (!array_key_exists($refKey, $this->language[$file])) { + if (!array_key_exists($file, $this->language) || !array_key_exists($refKey, $this->language[$file])) { $this->result .= "Missing key $refKey" . PHP_EOL; continue; } -- cgit v1.2.3