From 051c1572bc01eacad6ff4eccae7bca9f1ebd58d3 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 23 Feb 2024 09:09:08 +0100 Subject: [PATCH] new table layout and fixes --- CHANGELOG.md | 13 ++ src/Commands/ValidateAllCommand.php | 2 +- src/Commands/ValidateStructureCommand.php | 2 +- .../Reporter/Model/ReportResult.php | 8 +- ...ationSetResult.php => ReportSetResult.php} | 10 +- .../{TestResult.php => ReportTestResult.php} | 2 +- .../Service/ReportTestResultConverter.php | 27 +++++ .../Validator/CaseStyleValidator.php | 106 ++++++++--------- .../Validator/EmptyContentValidator.php | 52 ++++---- .../Validator/MissingStructureValidator.php | 56 ++++----- .../Validator/Model/ValidationError.php | 111 ------------------ .../Validator/Model/ValidationResult.php | 24 ++-- .../Validator/Model/ValidationTest.php | 21 ++-- .../Validator/Rules/DisallowedTextsRule.php | 31 ++--- .../Validator/Rules/DuplicateContentRule.php | 44 ++----- .../Validator/Rules/EmptyContentRule.php | 3 +- .../Validator/Rules/MaxKeyLengthRule.php | 34 ++---- .../Validator/Rules/NestingDepthRule.php | 41 ++----- src/Components/Validator/RulesValidator.php | 10 +- src/Facades/CLI/MessValidatorCliFacade.php | 74 ++++++++---- src/Facades/CLI/ValidatorCliFacade.php | 60 ++++------ src/Models/Command/ErrorTableRow.php | 99 ++++++++++++++++ src/Models/Translation/TranslationSet.php | 15 ++- src/Traits/CommandOutputTrait.php | 80 +++++++++++++ .../Repoter/JSON/JsonReporterTest.php | 4 +- .../Repoter/JUnit/JUnitReporterTest.php | 4 +- .../Repoter/Model/ReportResultTest.php | 14 +-- ...ResultTest.php => ReportSetResultTest.php} | 14 +-- ...esultTest.php => ReportTestResultTest.php} | 8 +- .../Validator/CaseStyleValidatorTest.php | 2 +- .../Validator/Model/ValidationErrorTest.php | 78 ------------ .../Validator/Model/ValidationResultTest.php | 14 +-- .../Utils/Traits/TestReportBuilderTrait.php | 8 +- 33 files changed, 505 insertions(+), 566 deletions(-) rename src/Components/Reporter/Model/{TranslationSetResult.php => ReportSetResult.php} (83%) rename src/Components/Reporter/Model/{TestResult.php => ReportTestResult.php} (98%) create mode 100644 src/Components/Reporter/Service/ReportTestResultConverter.php delete mode 100644 src/Components/Validator/Model/ValidationError.php create mode 100644 src/Models/Command/ErrorTableRow.php create mode 100644 src/Traits/CommandOutputTrait.php rename tests/phpunit/Components/Repoter/Model/{SuiteResultTest.php => ReportSetResultTest.php} (80%) rename tests/phpunit/Components/Repoter/Model/{TestResultTest.php => ReportTestResultTest.php} (88%) delete mode 100644 tests/phpunit/Components/Validator/Model/ValidationErrorTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index c8a81003..95cf1b19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,21 @@ using the [Keep a CHANGELOG](https://keepachangelog.com/) principles. ## [Unreleased] +### Added + - Add new option to **ignore** some keys from case style validation. Sometimes you are bound to the platform you are using for some keys. +- Add new **table layout** for all errors on CLI. This makes it easier to read and understand the errors. + +### Changed + +- Validators will now show a new **table layout** for all errors. This makes it easier to read and understand the + errors. + +### Fixed + +- Positive test results from mess validations where missing in reports. +- Case Style validation always showed up in reports even though not configured. ## [1.17.0] diff --git a/src/Commands/ValidateAllCommand.php b/src/Commands/ValidateAllCommand.php index a6b3e553..7873a627 100644 --- a/src/Commands/ValidateAllCommand.php +++ b/src/Commands/ValidateAllCommand.php @@ -69,7 +69,7 @@ public function execute(InputInterface $input, OutputInterface $output): int $translationSetCLI = new TranslationSetCliFacade($io); $coverageCLI = new CoverageCliFacade($io); - $validatorsCLI = new ValidatorCliFacade($io); + $validatorsCLI = new ValidatorCliFacade($io, $output); $reporterCLI = new ReporterCliFacade($io); # ----------------------------------------------------------------- diff --git a/src/Commands/ValidateStructureCommand.php b/src/Commands/ValidateStructureCommand.php index 0780ce09..9461eff8 100644 --- a/src/Commands/ValidateStructureCommand.php +++ b/src/Commands/ValidateStructureCommand.php @@ -62,7 +62,7 @@ public function execute(InputInterface $input, OutputInterface $output): int $validators[] = new MissingStructureValidator(); $translationSetCLI = new TranslationSetCliFacade($io); - $validatorsCLI = new ValidatorCliFacade($io); + $validatorsCLI = new ValidatorCliFacade($io, $output); $reporterCLI = new ReporterCliFacade($io); # ----------------------------------------------------------------- diff --git a/src/Components/Reporter/Model/ReportResult.php b/src/Components/Reporter/Model/ReportResult.php index 913018ef..7fad44bf 100644 --- a/src/Components/Reporter/Model/ReportResult.php +++ b/src/Components/Reporter/Model/ReportResult.php @@ -6,22 +6,22 @@ class ReportResult { /** - * @var TranslationSetResult[] + * @var ReportSetResult[] */ private $suites = []; /** - * @param TranslationSetResult $result + * @param ReportSetResult $result * @return void */ - public function addTranslationSet(TranslationSetResult $result): void + public function addTranslationSet(ReportSetResult $result): void { $this->suites[] = $result; } /** - * @return TranslationSetResult[] + * @return ReportSetResult[] */ public function getSuites(): array { diff --git a/src/Components/Reporter/Model/TranslationSetResult.php b/src/Components/Reporter/Model/ReportSetResult.php similarity index 83% rename from src/Components/Reporter/Model/TranslationSetResult.php rename to src/Components/Reporter/Model/ReportSetResult.php index 7d1e1b45..8ec3e45c 100644 --- a/src/Components/Reporter/Model/TranslationSetResult.php +++ b/src/Components/Reporter/Model/ReportSetResult.php @@ -2,7 +2,7 @@ namespace PHPUnuhi\Components\Reporter\Model; -class TranslationSetResult +class ReportSetResult { /** @@ -11,7 +11,7 @@ class TranslationSetResult private $name; /** - * @var TestResult[] + * @var ReportTestResult[] */ private $tests = []; @@ -32,16 +32,16 @@ public function getName(): string } /** - * @param TestResult $result + * @param ReportTestResult $result * @return void */ - public function addTestResult(TestResult $result): void + public function addTestResult(ReportTestResult $result): void { $this->tests[] = $result; } /** - * @return TestResult[] + * @return ReportTestResult[] */ public function getTests(): array { diff --git a/src/Components/Reporter/Model/TestResult.php b/src/Components/Reporter/Model/ReportTestResult.php similarity index 98% rename from src/Components/Reporter/Model/TestResult.php rename to src/Components/Reporter/Model/ReportTestResult.php index cf8ca3df..35769a56 100644 --- a/src/Components/Reporter/Model/TestResult.php +++ b/src/Components/Reporter/Model/ReportTestResult.php @@ -2,7 +2,7 @@ namespace PHPUnuhi\Components\Reporter\Model; -class TestResult +class ReportTestResult { /** diff --git a/src/Components/Reporter/Service/ReportTestResultConverter.php b/src/Components/Reporter/Service/ReportTestResultConverter.php new file mode 100644 index 00000000..cbb2ad2c --- /dev/null +++ b/src/Components/Reporter/Service/ReportTestResultConverter.php @@ -0,0 +1,27 @@ +getTitle(), + $test->getTranslationKey(), + basename($test->getFilename()), + $test->getLineNumber(), + $test->getClassification(), + $test->getFailureMessage(), + $test->isSuccess() + ); + } +} diff --git a/src/Components/Validator/CaseStyleValidator.php b/src/Components/Validator/CaseStyleValidator.php index 78e68ad8..5beab7a4 100644 --- a/src/Components/Validator/CaseStyleValidator.php +++ b/src/Components/Validator/CaseStyleValidator.php @@ -6,7 +6,6 @@ use PHPUnuhi\Bundles\Storage\StorageInterface; use PHPUnuhi\Components\Validator\CaseStyle\CaseStyleValidatorFactory; use PHPUnuhi\Components\Validator\CaseStyle\Exception\CaseStyleNotFoundException; -use PHPUnuhi\Components\Validator\Model\ValidationError; use PHPUnuhi\Components\Validator\Model\ValidationResult; use PHPUnuhi\Components\Validator\Model\ValidationTest; use PHPUnuhi\Models\Configuration\CaseStyle\CaseStyle; @@ -37,88 +36,81 @@ public function validate(TranslationSet $set, StorageInterface $storage): Valida $hierarchy = $storage->getHierarchy(); $tests = []; - $errors = []; $caseStyles = $set->getCasingStyleSettings()->getCaseStyles(); $ignoreKeys = $set->getCasingStyleSettings()->getIgnoreKeys(); - foreach ($set->getLocales() as $locale) { - foreach ($locale->getTranslations() as $translation) { - $isKeyCaseValid = true; - $invalidKeyPart = ''; - $isCurrentKeyValid = true; + $allowedCaseStylesText = implode(', ', array_map(function (CaseStyle $caseStyle): string { + return $caseStyle->getName(); + }, $caseStyles)); - # we have a full key like root.sub.lblTitle - # and we want to split it into parts and separately check the cases of the hierarchy levels - # sample: root.sub.lblTitle => [root, sub, lblTitle] - $keyParts = $this->getKeyParts($translation->getKey(), $hierarchy); + if ($caseStyles !== []) { + foreach ($set->getLocales() as $locale) { + foreach ($locale->getTranslations() as $translation) { + $isKeyCaseValid = true; + $invalidKeyPart = ''; + $isCurrentKeyValid = true; - $partLevel = 0; + # we have a full key like root.sub.lblTitle + # and we want to split it into parts and separately check the cases of the hierarchy levels + # sample: root.sub.lblTitle => [root, sub, lblTitle] + $keyParts = $this->getKeyParts($translation->getKey(), $hierarchy); - foreach ($keyParts as $part) { - $isPartValid = $this->verifyLevel($part, $partLevel, $caseStyles); + $partLevel = 0; - if (!$isPartValid) { - $invalidKeyPart = $part; - $isCurrentKeyValid = false; - break; - } + foreach ($keyParts as $part) { + $isPartValid = $this->verifyLevel($part, $partLevel, $caseStyles); - $partLevel++; - } + if (!$isPartValid) { + $invalidKeyPart = $part; + $isCurrentKeyValid = false; + break; + } + + $partLevel++; + } - # if it's somehow not valid - # then make sure to also check ouf ignore list - # then it might be valid :) - if (!$isCurrentKeyValid) { - # sample: $part => root.sub.IGNORE_THIS (fully qualified) - # also check ignore list - foreach ($ignoreKeys as $ignoreKey) { - if ($ignoreKey->isFullyQualifiedPath()) { - if ($translation->getKey() === $ignoreKey->getKey()) { + # if it's somehow not valid + # then make sure to also check ouf ignore list + # then it might be valid :) + if (!$isCurrentKeyValid) { + # sample: $part => root.sub.IGNORE_THIS (fully qualified) + # also check ignore list + foreach ($ignoreKeys as $ignoreKey) { + if ($ignoreKey->isFullyQualifiedPath()) { + if ($translation->getKey() === $ignoreKey->getKey()) { + $isCurrentKeyValid = true; + break; + } + } elseif ($this->stringDoesContain($translation->getKey(), $ignoreKey->getKey())) { $isCurrentKeyValid = true; break; } - } elseif ($this->stringDoesContain($translation->getKey(), $ignoreKey->getKey())) { - $isCurrentKeyValid = true; - break; } } - } - if (!$isCurrentKeyValid) { - $isKeyCaseValid = false; - } - - - $testPassed = $isKeyCaseValid; + if (!$isCurrentKeyValid) { + $isKeyCaseValid = false; + } - $tests[] = new ValidationTest( - $translation->getKey(), - $locale->getName(), - 'Test case-style of key: ' . $translation->getKey(), - $locale->getFilename(), - $locale->findLineNumber($translation->getKey()), - $this->getTypeIdentifier(), - 'Translation key ' . $translation->getKey() . ' has part with invalid case-style: ' . $invalidKeyPart . ' at level: ' . $partLevel, - $testPassed - ); + $testPassed = $isKeyCaseValid; - if (!$testPassed) { - $errors[] = new ValidationError( - $this->getTypeIdentifier(), - 'Invalid case-style for key: ' . $invalidKeyPart . ' at level: ' . $partLevel, + $tests[] = new ValidationTest( + $translation->getKey(), $locale->getName(), + "Test case-style of key '" . $translation->getKey() . "' to be one of: " . $allowedCaseStylesText, $locale->getFilename(), - $translation->getKey(), - $locale->findLineNumber($translation->getKey()) + $locale->findLineNumber($translation->getKey()), + $this->getTypeIdentifier(), + "Invalid case-style for part '" . $invalidKeyPart . "' in key '" . $translation->getKey() . "' at level: " . $partLevel, + $testPassed ); } } } - return new ValidationResult($tests, $errors); + return new ValidationResult($tests); } /** diff --git a/src/Components/Validator/EmptyContentValidator.php b/src/Components/Validator/EmptyContentValidator.php index 3fd08f79..f9ef2d01 100644 --- a/src/Components/Validator/EmptyContentValidator.php +++ b/src/Components/Validator/EmptyContentValidator.php @@ -4,9 +4,10 @@ use PHPUnuhi\Bundles\Storage\StorageInterface; use PHPUnuhi\Components\Validator\EmptyContent\AllowEmptyContent; -use PHPUnuhi\Components\Validator\Model\ValidationError; use PHPUnuhi\Components\Validator\Model\ValidationResult; use PHPUnuhi\Components\Validator\Model\ValidationTest; +use PHPUnuhi\Models\Translation\Locale; +use PHPUnuhi\Models\Translation\Translation; use PHPUnuhi\Models\Translation\TranslationSet; class EmptyContentValidator implements ValidatorInterface @@ -44,7 +45,6 @@ public function getTypeIdentifier(): string public function validate(TranslationSet $set, StorageInterface $storage): ValidationResult { $tests = []; - $errors = []; foreach ($set->getLocales() as $locale) { foreach ($locale->getTranslations() as $translation) { @@ -61,39 +61,37 @@ public function validate(TranslationSet $set, StorageInterface $storage): Valida } } - $tests[] = new ValidationTest( - $translation->getKey(), - $locale->getName(), - 'Test existing translation of key: ' . $translation->getKey(), - $locale->getFilename(), - $locale->findLineNumber($translation->getKey()), - $this->getTypeIdentifier(), - 'Translation for key ' . $translation->getKey() . ' does not have a value', - $testPassed - ); - - - if ($testPassed) { - continue; - } - if ($translation->getGroup() !== '') { $identifier = $translation->getGroup() . ' (group) => ' . $translation->getKey(); } else { $identifier = $translation->getID(); } - $errors[] = new ValidationError( - $this->getTypeIdentifier(), - 'Found empty translation', - $locale->getName(), - $locale->getFilename(), - $identifier, - $locale->findLineNumber($identifier) - ); + $tests[] = $this->buildValidationTest($identifier, $locale, $translation, $testPassed); } } - return new ValidationResult($tests, $errors); + return new ValidationResult($tests); + } + + /** + * @param string $identifier + * @param Locale $locale + * @param Translation $translation + * @param bool $testPassed + * @return ValidationTest + */ + private function buildValidationTest(string $identifier, Locale $locale, Translation $translation, bool $testPassed): ValidationTest + { + return new ValidationTest( + $identifier, + $locale->getName(), + 'Test existing translation for key: ' . $translation->getKey(), + $locale->getFilename(), + $locale->findLineNumber($translation->getKey()), + $this->getTypeIdentifier(), + 'Translation for key ' . $translation->getKey() . ' does not have a value', + $testPassed + ); } } diff --git a/src/Components/Validator/MissingStructureValidator.php b/src/Components/Validator/MissingStructureValidator.php index 9e34d05e..d4b21a63 100644 --- a/src/Components/Validator/MissingStructureValidator.php +++ b/src/Components/Validator/MissingStructureValidator.php @@ -3,9 +3,9 @@ namespace PHPUnuhi\Components\Validator; use PHPUnuhi\Bundles\Storage\StorageInterface; -use PHPUnuhi\Components\Validator\Model\ValidationError; use PHPUnuhi\Components\Validator\Model\ValidationResult; use PHPUnuhi\Components\Validator\Model\ValidationTest; +use PHPUnuhi\Models\Translation\Locale; use PHPUnuhi\Models\Translation\TranslationSet; class MissingStructureValidator implements ValidatorInterface @@ -30,7 +30,6 @@ public function validate(TranslationSet $set, StorageInterface $storage): Valida $allKeys = $set->getAllTranslationIDs(); $tests = []; - $errors = []; foreach ($set->getLocales() as $locale) { $localeKeys = $locale->getTranslationIDs(); @@ -46,43 +45,16 @@ public function validate(TranslationSet $set, StorageInterface $storage): Valida $filtered = $this->getDiff($localeKeys, $allKeys); foreach ($filtered as $key) { - $errors[] = new ValidationError( - $this->getTypeIdentifier(), - 'Found missing structure in locale', - $locale->getName(), - $locale->getFilename(), - $key, - $locale->findLineNumber($key) - ); - - $tests[] = new ValidationTest( - $key, - $locale->getName(), - 'Text structure of key: ' . $key, - $locale->getFilename(), - $locale->findLineNumber($key), - $this->getTypeIdentifier(), - 'Translation key ' . $key . ' is not found in locale ' . $locale->getName(), - false - ); + $tests[] = $this->buildValidationTest($key, $locale, false); } } foreach ($same as $key) { - $tests[] = new ValidationTest( - $key, - $locale->getName(), - 'Text structure of key: ' . $key, - $locale->getFilename(), - $locale->findLineNumber($key), - $this->getTypeIdentifier(), - '', - true - ); + $tests[] = $this->buildValidationTest($key, $locale, true); } } - return new ValidationResult($tests, $errors); + return new ValidationResult($tests); } @@ -126,4 +98,24 @@ private function getSame(array $a, array $b): array return array_merge($diffA, $diffB); } + + /** + * @param string $key + * @param Locale $locale + * @param bool $success + * @return ValidationTest + */ + private function buildValidationTest(string $key, Locale $locale, bool $success): ValidationTest + { + return new ValidationTest( + $key, + $locale->getName(), + 'Test structure of key: ' . $key, + $locale->getFilename(), + $locale->findLineNumber($key), + $this->getTypeIdentifier(), + 'Found missing structure in locale. Key is missing: ' . $key, + $success + ); + } } diff --git a/src/Components/Validator/Model/ValidationError.php b/src/Components/Validator/Model/ValidationError.php deleted file mode 100644 index 7734e465..00000000 --- a/src/Components/Validator/Model/ValidationError.php +++ /dev/null @@ -1,111 +0,0 @@ -classification = $classification; - $this->message = $message; - $this->locale = $locale; - $this->filename = $filename; - $this->identifier = $identifier; - $this->lineNumber = $lineNumber; - } - - - /** - * @return string - */ - public function getClassification(): string - { - return $this->classification; - } - - /** - * @return string - */ - public function getMessage(): string - { - return $this->message; - } - - /** - * @return string - */ - public function getLocale(): string - { - return $this->locale; - } - - /** - * @return string - */ - public function getFilename(): string - { - return $this->filename; - } - - /** - * @return string - */ - public function getIdentifier(): string - { - return $this->identifier; - } - - /** - * @return int - */ - public function getLineNumber(): int - { - return $this->lineNumber; - } -} diff --git a/src/Components/Validator/Model/ValidationResult.php b/src/Components/Validator/Model/ValidationResult.php index 06380828..41ceaaec 100644 --- a/src/Components/Validator/Model/ValidationResult.php +++ b/src/Components/Validator/Model/ValidationResult.php @@ -11,20 +11,12 @@ class ValidationResult private $tests; - /** - * @var ValidationError[] - */ - private $errors; - - /** * @param ValidationTest[] $tests - * @param ValidationError[] $errors */ - public function __construct(array $tests, array $errors) + public function __construct(array $tests) { $this->tests = $tests; - $this->errors = $errors; } /** @@ -32,7 +24,7 @@ public function __construct(array $tests, array $errors) */ public function isValid(): bool { - return count($this->errors) === 0; + return $this->getErrors() === []; } /** @@ -44,10 +36,18 @@ public function getTests(): array } /** - * @return ValidationError[] + * @return ValidationTest[] */ public function getErrors(): array { - return $this->errors; + $errors = []; + + foreach ($this->tests as $test) { + if (!$test->isSuccess()) { + $errors[] = $test; + } + } + + return $errors; } } diff --git a/src/Components/Validator/Model/ValidationTest.php b/src/Components/Validator/Model/ValidationTest.php index 759da305..7c5af822 100644 --- a/src/Components/Validator/Model/ValidationTest.php +++ b/src/Components/Validator/Model/ValidationTest.php @@ -51,20 +51,13 @@ class ValidationTest * @param string $locale * @param string $title * @param string $filename + * @param int $lineNumber * @param string $classification * @param string $failureMessage * @param bool $success */ - public function __construct( - string $translationKey, - string $locale, - string $title, - string $filename, - int $lineNumber, - string $classification, - string $failureMessage, - bool $success - ) { + public function __construct(string $translationKey, string $locale, string $title, string $filename, int $lineNumber, string $classification, string $failureMessage, bool $success) + { $this->translationKey = $translationKey; $this->locale = $locale; $this->title = $title; @@ -127,4 +120,12 @@ public function isSuccess(): bool { return $this->success; } + + /** + * @return string + */ + public function getLocale(): string + { + return $this->locale; + } } diff --git a/src/Components/Validator/Rules/DisallowedTextsRule.php b/src/Components/Validator/Rules/DisallowedTextsRule.php index adde072e..212cb180 100644 --- a/src/Components/Validator/Rules/DisallowedTextsRule.php +++ b/src/Components/Validator/Rules/DisallowedTextsRule.php @@ -3,7 +3,6 @@ namespace PHPUnuhi\Components\Validator\Rules; use PHPUnuhi\Bundles\Storage\StorageInterface; -use PHPUnuhi\Components\Validator\Model\ValidationError; use PHPUnuhi\Components\Validator\Model\ValidationResult; use PHPUnuhi\Components\Validator\Model\ValidationTest; use PHPUnuhi\Models\Translation\TranslationSet; @@ -44,7 +43,6 @@ public function getRuleIdentifier(): string public function validate(TranslationSet $set, StorageInterface $storage): ValidationResult { $tests = []; - $errors = []; foreach ($set->getLocales() as $locale) { foreach ($locale->getTranslations() as $translation) { @@ -58,38 +56,25 @@ public function validate(TranslationSet $set, StorageInterface $storage): Valida $testPassed = ($foundWord === null); - $tests[] = new ValidationTest( - $translation->getKey(), - $locale->getName(), - 'Test against disallowed text for key: ' . $translation->getKey(), - $locale->getFilename(), - $locale->findLineNumber($translation->getKey()), - $this->getRuleIdentifier(), - 'Translation for key ' . $translation->getKey() . ' has disallowed text: ' . $foundWord, - $testPassed - ); - - if ($testPassed) { - continue; - } - if ($translation->getGroup() !== '') { $identifier = $translation->getGroup() . ' (group) => ' . $translation->getKey(); } else { $identifier = $translation->getID(); } - $errors[] = new ValidationError( - $this->getRuleIdentifier(), - 'Found disallowed text in key ' . $translation->getKey() . '. Value must not contain: ' . $foundWord, + $tests[] = new ValidationTest( + $identifier, $locale->getName(), + "Test against disallowed texts for key: '" . $translation->getKey(), $locale->getFilename(), - $identifier, - $locale->findLineNumber($identifier) + $locale->findLineNumber($translation->getKey()), + $this->getRuleIdentifier(), + "Found disallowed text in key '" . $translation->getKey() . "'. Value must not contain: '" . $foundWord . "'", + $testPassed ); } } - return new ValidationResult($tests, $errors); + return new ValidationResult($tests); } } diff --git a/src/Components/Validator/Rules/DuplicateContentRule.php b/src/Components/Validator/Rules/DuplicateContentRule.php index f325a655..3cff335d 100644 --- a/src/Components/Validator/Rules/DuplicateContentRule.php +++ b/src/Components/Validator/Rules/DuplicateContentRule.php @@ -4,7 +4,6 @@ use PHPUnuhi\Bundles\Storage\StorageInterface; use PHPUnuhi\Components\Validator\DuplicateContent\DuplicateContent; -use PHPUnuhi\Components\Validator\Model\ValidationError; use PHPUnuhi\Components\Validator\Model\ValidationResult; use PHPUnuhi\Components\Validator\Model\ValidationTest; use PHPUnuhi\Models\Translation\Locale; @@ -45,14 +44,12 @@ public function getRuleIdentifier(): string public function validate(TranslationSet $set, StorageInterface $storage): ValidationResult { if (count($this->localeSettings) === 0) { - return new ValidationResult([], []); + return new ValidationResult([]); } $storage->getHierarchy(); $tests = []; - $errors = []; - foreach ($set->getLocales() as $locale) { if (!$this->requiresDuplicateContent($locale->getName())) { @@ -74,27 +71,21 @@ public function validate(TranslationSet $set, StorageInterface $storage): Valida $testPassed = true; } - $tests[] = $this->buildTestEntry( - $locale, - $translation->getKey(), - $testPassed - ); - - if ($testPassed) { - continue; - } - if ($translation->getGroup() !== '') { $identifier = $translation->getGroup() . ' (group) => ' . $translation->getKey(); } else { $identifier = $translation->getID(); } - $errors[] = $this->buildError($locale, $identifier); + $tests[] = $this->buildTestEntry( + $locale, + $identifier, + $testPassed + ); } } - return new ValidationResult($tests, $errors); + return new ValidationResult($tests); } /** @@ -131,29 +122,12 @@ private function buildTestEntry(Locale $locale, string $translationKey, bool $pa return new ValidationTest( $translationKey, $locale->getName(), - 'Testing for duplicate content of key: ' . $translationKey, + "Testing for duplicate content in key: '" . $translationKey . "'", $locale->getFilename(), $locale->findLineNumber($translationKey), $this->getRuleIdentifier(), - 'Content of key ' . $translationKey . ' has been found multiple times within locale: ' . $locale->getName(), + "Content of key '" . $translationKey . "' has been found multiple times within locale '" . $locale->getName() . "'", $passed ); } - - /** - * @param Locale $locale - * @param string $identifier - * @return ValidationError - */ - private function buildError(Locale $locale, string $identifier): ValidationError - { - return new ValidationError( - $this->getRuleIdentifier(), - 'Content of key ' . $identifier . ' has been found multiple times within locale: ' . $locale->getName(), - $locale->getName(), - $locale->getFilename(), - $identifier, - $locale->findLineNumber($identifier) - ); - } } diff --git a/src/Components/Validator/Rules/EmptyContentRule.php b/src/Components/Validator/Rules/EmptyContentRule.php index 80b97ced..e1f33930 100644 --- a/src/Components/Validator/Rules/EmptyContentRule.php +++ b/src/Components/Validator/Rules/EmptyContentRule.php @@ -28,7 +28,6 @@ public function getRuleIdentifier(): string public function validate(TranslationSet $set, StorageInterface $storage): ValidationResult { $tests = []; - $errors = []; foreach ($set->getLocales() as $locale) { foreach ($locale->getTranslations() as $translation) { @@ -40,7 +39,7 @@ public function validate(TranslationSet $set, StorageInterface $storage): Valida } } - return new ValidationResult($tests, $errors); + return new ValidationResult($tests); } /** diff --git a/src/Components/Validator/Rules/MaxKeyLengthRule.php b/src/Components/Validator/Rules/MaxKeyLengthRule.php index c347042b..f1b6c05c 100644 --- a/src/Components/Validator/Rules/MaxKeyLengthRule.php +++ b/src/Components/Validator/Rules/MaxKeyLengthRule.php @@ -3,7 +3,6 @@ namespace PHPUnuhi\Components\Validator\Rules; use PHPUnuhi\Bundles\Storage\StorageInterface; -use PHPUnuhi\Components\Validator\Model\ValidationError; use PHPUnuhi\Components\Validator\Model\ValidationResult; use PHPUnuhi\Components\Validator\Model\ValidationTest; use PHPUnuhi\Models\Translation\TranslationSet; @@ -47,12 +46,10 @@ public function validate(TranslationSet $set, StorageInterface $storage): Valida # this is always valid if ($this->maxKeyLength <= 0) { - return new ValidationResult([], []); + return new ValidationResult([]); } $tests = []; - $errors = []; - foreach ($set->getLocales() as $locale) { foreach ($locale->getTranslations() as $translation) { @@ -73,38 +70,25 @@ public function validate(TranslationSet $set, StorageInterface $storage): Valida $testPassed = ($invalidKey === null); $invalidKey = (string)$invalidKey; # for output below - $tests[] = new ValidationTest( - $translation->getKey(), - $locale->getName(), - 'Test length of key: ' . $translation->getKey(), - $locale->getFilename(), - $locale->findLineNumber($translation->getKey()), - $this->getRuleIdentifier(), - 'Maximum length of key ' . $invalidKey . ' has been reached. Length is ' . strlen($invalidKey) . ' of max allowed ' . $this->maxKeyLength . '.', - $testPassed - ); - - if ($testPassed) { - continue; - } - if ($translation->getGroup() !== '') { $identifier = $translation->getGroup() . ' (group) => ' . $translation->getKey(); } else { $identifier = $translation->getID(); } - $errors[] = new ValidationError( - $this->getRuleIdentifier(), - 'Maximum length of key ' . $invalidKey . ' has been reached. Length is ' . strlen($invalidKey) . ' of max allowed ' . $this->maxKeyLength . '.', + $tests[] = new ValidationTest( + $identifier, $locale->getName(), + "Test length of key '" . $translation->getKey(), $locale->getFilename(), - $identifier, - $locale->findLineNumber($identifier) + $locale->findLineNumber($translation->getKey()), + $this->getRuleIdentifier(), + "Maximum length of " . $this->maxKeyLength . " for key '" . $invalidKey . "' has been reached. Length is " . strlen($invalidKey), + $testPassed ); } } - return new ValidationResult($tests, $errors); + return new ValidationResult($tests); } } diff --git a/src/Components/Validator/Rules/NestingDepthRule.php b/src/Components/Validator/Rules/NestingDepthRule.php index e7101523..4266d13c 100644 --- a/src/Components/Validator/Rules/NestingDepthRule.php +++ b/src/Components/Validator/Rules/NestingDepthRule.php @@ -3,7 +3,6 @@ namespace PHPUnuhi\Components\Validator\Rules; use PHPUnuhi\Bundles\Storage\StorageInterface; -use PHPUnuhi\Components\Validator\Model\ValidationError; use PHPUnuhi\Components\Validator\Model\ValidationResult; use PHPUnuhi\Components\Validator\Model\ValidationTest; use PHPUnuhi\Models\Translation\Locale; @@ -46,22 +45,20 @@ public function validate(TranslationSet $set, StorageInterface $storage): Valida $hierarchy = $storage->getHierarchy(); if (!$hierarchy->isNestedStorage()) { - return new ValidationResult([], []); + return new ValidationResult([]); } if ($hierarchy->getDelimiter() === '') { - return new ValidationResult([], []); + return new ValidationResult([]); } # this is always valid if ($this->maxNestingLevel <= 0) { - return new ValidationResult([], []); + return new ValidationResult([]); } $tests = []; - $errors = []; - foreach ($set->getLocales() as $locale) { foreach ($locale->getTranslations() as $translation) { @@ -71,23 +68,17 @@ public function validate(TranslationSet $set, StorageInterface $storage): Valida $testPassed = $currentLevels <= $this->maxNestingLevel; - $tests[] = $this->buildTestEntry($locale, $translation->getKey(), $currentLevels, $testPassed); - - if ($testPassed) { - continue; - } - if ($translation->getGroup() !== '') { $identifier = $translation->getGroup() . ' (group) => ' . $translation->getKey(); } else { $identifier = $translation->getID(); } - $errors[] = $this->buildError($locale, $identifier, $currentLevels); + $tests[] = $this->buildTestEntry($locale, $identifier, $currentLevels, $testPassed); } } - return new ValidationResult($tests, $errors); + return new ValidationResult($tests); } /** @@ -102,30 +93,12 @@ private function buildTestEntry(Locale $locale, string $translationKey, int $dep return new ValidationTest( $translationKey, $locale->getName(), - 'Test nesting level of key: ' . $translationKey, + "Test nesting-depth of key '" . $translationKey, $locale->getFilename(), $locale->findLineNumber($translationKey), $this->getRuleIdentifier(), - 'Translation for key ' . $translationKey . ' has ' . $depthOfKey . ' levels. Maximum nesting level is: ' . $this->maxNestingLevel, + 'Maximum nesting depth of ' . $this->maxNestingLevel . ' has been reached. Key has ' . $depthOfKey . ' levels', $passed ); } - - /** - * @param Locale $locale - * @param string $identifier - * @param int $depthOfKey - * @return ValidationError - */ - private function buildError(Locale $locale, string $identifier, int $depthOfKey): ValidationError - { - return new ValidationError( - $this->getRuleIdentifier(), - 'Maximum nesting level of ' . $this->maxNestingLevel . ' has been reached. Translation has ' . $depthOfKey . ' levels.', - $locale->getName(), - $locale->getFilename(), - $identifier, - $locale->findLineNumber($identifier) - ); - } } diff --git a/src/Components/Validator/RulesValidator.php b/src/Components/Validator/RulesValidator.php index b728a10a..dd9a1c28 100644 --- a/src/Components/Validator/RulesValidator.php +++ b/src/Components/Validator/RulesValidator.php @@ -32,7 +32,7 @@ public function getTypeIdentifier(): string public function validate(TranslationSet $set, StorageInterface $storage): ValidationResult { if ($set->getAllTranslationIDs() === []) { - return new ValidationResult([], []); + return new ValidationResult([]); } $ruleValidators = []; @@ -64,21 +64,15 @@ public function validate(TranslationSet $set, StorageInterface $storage): Valida } } - $allTests = []; - $allErrors = []; /** @var RuleValidatorInterface $validator */ foreach ($ruleValidators as $validator) { $result = $validator->validate($set, $storage); $allTests = array_merge($allTests, $result->getTests()); - $allErrors = array_merge($allErrors, $result->getErrors()); } - return new ValidationResult( - $allTests, - $allErrors - ); + return new ValidationResult($allTests); } } diff --git a/src/Facades/CLI/MessValidatorCliFacade.php b/src/Facades/CLI/MessValidatorCliFacade.php index 5037a84a..41ac3245 100644 --- a/src/Facades/CLI/MessValidatorCliFacade.php +++ b/src/Facades/CLI/MessValidatorCliFacade.php @@ -3,13 +3,17 @@ namespace PHPUnuhi\Facades\CLI; use PHPUnuhi\Components\Reporter\Model\ReportResult; -use PHPUnuhi\Components\Reporter\Model\TestResult; -use PHPUnuhi\Components\Reporter\Model\TranslationSetResult; +use PHPUnuhi\Components\Reporter\Model\ReportSetResult; +use PHPUnuhi\Components\Reporter\Service\ReportTestResultConverter; +use PHPUnuhi\Components\Validator\Model\ValidationTest; +use PHPUnuhi\Exceptions\TranslationNotFoundException; use PHPUnuhi\Models\Translation\TranslationSet; +use PHPUnuhi\Traits\CommandOutputTrait; use Symfony\Component\Console\Style\SymfonyStyle; class MessValidatorCliFacade { + use CommandOutputTrait; /** * @var SymfonyStyle @@ -26,38 +30,68 @@ public function __construct(SymfonyStyle $io) /** * @param TranslationSet[] $translationSets + * @throws TranslationNotFoundException * @return ReportResult */ public function execute(array $translationSets): ReportResult { $reportResult = new ReportResult(); + $allTests = []; + + $reportConverter = new ReportTestResultConverter(); + foreach ($translationSets as $set) { $this->io->section('Translation-Set: ' . $set->getName()); - $setResult = new TranslationSetResult($set->getName()); - - foreach ($set->getInvalidTranslationsIDs() as $translationID) { - $setResult->addTestResult( - new TestResult( - $translationID, - $translationID, - '', - 0, - 'MESS', - 'Not a single translation exists for this key. You might not need this translation.', - false - ) - ); - - $this->io->writeln(' - Key: ' . $translationID); - $this->io->writeln(' [x]: Not a single translation exists. You might not need this translation?!'); - $this->io->writeln(''); + $setResult = new ReportSetResult($set->getName()); + + $invalidIDs = $set->getInvalidTranslationsIDs(); + + foreach ($invalidIDs as $translationID) { + $valTest = $this->buildTestValidation($translationID, false); + $reportResultTest = $reportConverter->toTestResult($valTest); + + $allTests[] = $valTest; + $setResult->addTestResult($reportResultTest); + } + + foreach ($set->getAllTranslationIDs() as $translationID) { + if (in_array($translationID, $invalidIDs)) { + continue; + } + + $valTest = $this->buildTestValidation($translationID, true); + $reportResultTest = $reportConverter->toTestResult($valTest); + + $allTests[] = $valTest; + $setResult->addTestResult($reportResultTest); } $reportResult->addTranslationSet($setResult); } + $this->showErrorTable($allTests, $this->io); + return $reportResult; } + + /** + * @param string $translationID + * @param bool $success + * @return ValidationTest + */ + private function buildTestValidation(string $translationID, bool $success): ValidationTest + { + return new ValidationTest( + $translationID, + '-', + 'Test if translation for key ' . $translationID . ' exists in any locale', + '', + 0, + 'MESS', + 'Not a single translation exists for this key. You might not need this translation.', + $success + ); + } } diff --git a/src/Facades/CLI/ValidatorCliFacade.php b/src/Facades/CLI/ValidatorCliFacade.php index 585d4e00..fb3ea383 100644 --- a/src/Facades/CLI/ValidatorCliFacade.php +++ b/src/Facades/CLI/ValidatorCliFacade.php @@ -3,85 +3,73 @@ namespace PHPUnuhi\Facades\CLI; use PHPUnuhi\Bundles\Storage\StorageFactory; -use PHPUnuhi\Components\Reporter\Model\TestResult; -use PHPUnuhi\Components\Reporter\Model\TranslationSetResult; +use PHPUnuhi\Components\Reporter\Model\ReportSetResult; +use PHPUnuhi\Components\Reporter\Service\ReportTestResultConverter; use PHPUnuhi\Components\Validator\ValidatorInterface; use PHPUnuhi\Exceptions\ConfigurationException; use PHPUnuhi\Models\Translation\TranslationSet; +use PHPUnuhi\Traits\CommandOutputTrait; +use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; class ValidatorCliFacade { + use CommandOutputTrait; + /** * @var SymfonyStyle */ private $io; + /** + * @var OutputInterface + */ + private $output; + /** * @param SymfonyStyle $io + * @param OutputInterface $output */ - public function __construct(SymfonyStyle $io) + public function __construct(SymfonyStyle $io, OutputInterface $output) { $this->io = $io; + $this->output = $output; } /** * @param TranslationSet $set * @param ValidatorInterface[] $validators * @throws ConfigurationException - * @return TranslationSetResult + * @return ReportSetResult */ - public function execute(TranslationSet $set, array $validators): TranslationSetResult + public function execute(TranslationSet $set, array $validators): ReportSetResult { - $errorCount = 0; - - $this->io->section('Translation-Set: ' . $set->getName()); $storage = StorageFactory::getInstance()->getStorage($set); - $translationSetResult = new TranslationSetResult($set->getName()); + $translationSetResult = new ReportSetResult($set->getName()); + + $allTableErrors = []; + $reporterConverter = new ReportTestResultConverter(); foreach ($validators as $validator) { $validatorResult = $validator->validate($set, $storage); if (!$validatorResult->isValid()) { - foreach ($validatorResult->getErrors() as $error) { - $errorCount++; - - $this->io->writeln('#' . $errorCount . ' [' . $error->getClassification() . "] " . $error->getMessage()); - $this->io->writeln(' - Locale: ' . $error->getLocale()); - - if (!empty($error->getFilename())) { - $this->io->writeln(" - File: " . $error->getFilename()); - } - - if (!empty($error->getLineNumber())) { - $this->io->writeln(" - Line: " . $error->getLineNumber()); - } - - $this->io->writeln(' [x]: ' . $error->getIdentifier()); - $this->io->writeln(''); - } + $allTableErrors = array_merge($allTableErrors, $validatorResult->getErrors()); } foreach ($validatorResult->getTests() as $test) { - $testResult = new TestResult( - $test->getTitle(), - $test->getTranslationKey(), - basename($test->getFilename()), - $test->getLineNumber(), - $test->getClassification(), - $test->getFailureMessage(), - $test->isSuccess() - ); - + $testResult = $reporterConverter->toTestResult($test); $translationSetResult->addTestResult($testResult); } } + $this->showErrorTable($allTableErrors, $this->output); + return $translationSetResult; } } diff --git a/src/Models/Command/ErrorTableRow.php b/src/Models/Command/ErrorTableRow.php new file mode 100644 index 00000000..89c3a3a3 --- /dev/null +++ b/src/Models/Command/ErrorTableRow.php @@ -0,0 +1,99 @@ +id = $id; + $this->classType = $classType; + $this->locale = $locale; + $this->error = $error; + $this->key = $key; + $this->file = $file; + $this->line = $line; + } + + public function getId(): string + { + return $this->id; + } + + public function getClassType(): string + { + return $this->classType; + } + + + + public function getError(): string + { + return $this->error; + } + + public function getKey(): string + { + return $this->key; + } + + public function getFile(): string + { + return $this->file; + } + + public function getLine(): string + { + return $this->line; + } + + public function getLocale(): string + { + return $this->locale; + } +} diff --git a/src/Models/Translation/TranslationSet.php b/src/Models/Translation/TranslationSet.php index c1ed664b..ee592c77 100644 --- a/src/Models/Translation/TranslationSet.php +++ b/src/Models/Translation/TranslationSet.php @@ -315,11 +315,16 @@ public function getInvalidTranslationsIDs(): array $hasValueInAnyLocale = false; foreach ($this->locales as $locale) { - $translation = $locale->findTranslation($id); - - if (!$translation->isEmpty()) { - $hasValueInAnyLocale = true; - break; + try { + $translation = $locale->findTranslation($id); + + if (!$translation->isEmpty()) { + $hasValueInAnyLocale = true; + break; + } + } catch (TranslationNotFoundException $ex) { + # this is fine, it can happen that + # it just does not exist } } diff --git a/src/Traits/CommandOutputTrait.php b/src/Traits/CommandOutputTrait.php new file mode 100644 index 00000000..1ff75a82 --- /dev/null +++ b/src/Traits/CommandOutputTrait.php @@ -0,0 +1,80 @@ +setStyle('default'); + + $headers = [ + '#', + 'Type', + 'Locale', + 'Key', + 'Error', + ]; + $table->setHeaders($headers); + + $rowData = []; + + $intRowIndex = 1; + + foreach ($rows as $row) { + $rowData[] = [ + $intRowIndex, + ' ' . $row->getClassification() . ' ', + ' ' . $row->getLocale() . ' ', + ' ' . $row->getTranslationKey() . ' ', + $row->getFailureMessage() + ]; + + + if (!empty($row->getLineNumber())) { + $lineError = '// Line ' . $row->getLineNumber() . ' in file: ' . $row->getFilename(); + + $rowData[] = [ + new TableCell(''), + new TableCell(''), + new TableCell(''), + new TableCell(''), + new TableCell( + $lineError, + [ + 'colspan' => count($headers) - 4 + ] + )]; + } + + # don't add as last line + if ($row !== end($rows)) { + $rowData[] = new TableSeparator(); + } + + $intRowIndex++; + } + $table->setRows($rowData); + + $table->render(); + + $output->writeln(''); + } +} diff --git a/tests/phpunit/Components/Repoter/JSON/JsonReporterTest.php b/tests/phpunit/Components/Repoter/JSON/JsonReporterTest.php index 78e54573..64bec7f8 100644 --- a/tests/phpunit/Components/Repoter/JSON/JsonReporterTest.php +++ b/tests/phpunit/Components/Repoter/JSON/JsonReporterTest.php @@ -9,7 +9,7 @@ use phpunit\Utils\Traits\TestReportBuilderTrait; use PHPUnuhi\Components\Reporter\JSON\JsonReporter; use PHPUnuhi\Components\Reporter\Model\ReportResult; -use PHPUnuhi\Components\Reporter\Model\TranslationSetResult; +use PHPUnuhi\Components\Reporter\Model\ReportSetResult; class JsonReporterTest extends TestCase { @@ -88,7 +88,7 @@ public function testSubfoldersAreGeneratedForResultFile(): void */ public function testReportGeneration(): void { - $suite = new TranslationSetResult('Storefront'); + $suite = new ReportSetResult('Storefront'); $suite->addTestResult($this->buildTestResult(true)); $suite->addTestResult($this->buildTestResult(false)); diff --git a/tests/phpunit/Components/Repoter/JUnit/JUnitReporterTest.php b/tests/phpunit/Components/Repoter/JUnit/JUnitReporterTest.php index 5e3b2c18..92e6c9d4 100644 --- a/tests/phpunit/Components/Repoter/JUnit/JUnitReporterTest.php +++ b/tests/phpunit/Components/Repoter/JUnit/JUnitReporterTest.php @@ -9,7 +9,7 @@ use phpunit\Utils\Traits\TestReportBuilderTrait; use PHPUnuhi\Components\Reporter\JUnit\JUnitReporter; use PHPUnuhi\Components\Reporter\Model\ReportResult; -use PHPUnuhi\Components\Reporter\Model\TranslationSetResult; +use PHPUnuhi\Components\Reporter\Model\ReportSetResult; class JUnitReporterTest extends TestCase { @@ -93,7 +93,7 @@ public function testSubfoldersAreGeneratedForResultFile(): void */ public function testReportGeneration(): void { - $suite = new TranslationSetResult('Storefront'); + $suite = new ReportSetResult('Storefront'); $suite->addTestResult($this->buildTestResult(true)); $suite->addTestResult($this->buildTestResult(false)); diff --git a/tests/phpunit/Components/Repoter/Model/ReportResultTest.php b/tests/phpunit/Components/Repoter/Model/ReportResultTest.php index 9c44e8f7..fa19e6ff 100644 --- a/tests/phpunit/Components/Repoter/Model/ReportResultTest.php +++ b/tests/phpunit/Components/Repoter/Model/ReportResultTest.php @@ -4,8 +4,8 @@ use PHPUnit\Framework\TestCase; use PHPUnuhi\Components\Reporter\Model\ReportResult; -use PHPUnuhi\Components\Reporter\Model\TestResult; -use PHPUnuhi\Components\Reporter\Model\TranslationSetResult; +use PHPUnuhi\Components\Reporter\Model\ReportSetResult; +use PHPUnuhi\Components\Reporter\Model\ReportTestResult; class ReportResultTest extends TestCase { @@ -22,9 +22,9 @@ class ReportResultTest extends TestCase */ public function setUp(): void { - $suite1 = new TranslationSetResult('test'); + $suite1 = new ReportSetResult('test'); $suite1->addTestResult( - new TestResult( + new ReportTestResult( '', '', '', @@ -35,10 +35,10 @@ public function setUp(): void ) ); - $suite2 = new TranslationSetResult('test2'); + $suite2 = new ReportSetResult('test2'); $suite2->addTestResult( - new TestResult( + new ReportTestResult( '', '', '', @@ -50,7 +50,7 @@ public function setUp(): void ); $suite2->addTestResult( - new TestResult( + new ReportTestResult( '', '', '', diff --git a/tests/phpunit/Components/Repoter/Model/SuiteResultTest.php b/tests/phpunit/Components/Repoter/Model/ReportSetResultTest.php similarity index 80% rename from tests/phpunit/Components/Repoter/Model/SuiteResultTest.php rename to tests/phpunit/Components/Repoter/Model/ReportSetResultTest.php index 127a45e7..e3da924e 100644 --- a/tests/phpunit/Components/Repoter/Model/SuiteResultTest.php +++ b/tests/phpunit/Components/Repoter/Model/ReportSetResultTest.php @@ -3,15 +3,15 @@ namespace phpunit\Components\Repoter\Model; use PHPUnit\Framework\TestCase; -use PHPUnuhi\Components\Reporter\Model\TestResult; -use PHPUnuhi\Components\Reporter\Model\TranslationSetResult; +use PHPUnuhi\Components\Reporter\Model\ReportSetResult; +use PHPUnuhi\Components\Reporter\Model\ReportTestResult; -class SuiteResultTest extends TestCase +class ReportSetResultTest extends TestCase { /** - * @var TranslationSetResult + * @var ReportSetResult */ private $result; @@ -21,10 +21,10 @@ class SuiteResultTest extends TestCase */ public function setUp(): void { - $this->result = new TranslationSetResult('storefront'); + $this->result = new ReportSetResult('storefront'); $this->result->addTestResult( - new TestResult( + new ReportTestResult( 'storefront', 'btnCancel', 'ErrorClass', @@ -36,7 +36,7 @@ public function setUp(): void ); $this->result->addTestResult( - new TestResult( + new ReportTestResult( 'storefront', 'btnOk', 'ErrorClass', diff --git a/tests/phpunit/Components/Repoter/Model/TestResultTest.php b/tests/phpunit/Components/Repoter/Model/ReportTestResultTest.php similarity index 88% rename from tests/phpunit/Components/Repoter/Model/TestResultTest.php rename to tests/phpunit/Components/Repoter/Model/ReportTestResultTest.php index 3ced3ca4..107a3d25 100644 --- a/tests/phpunit/Components/Repoter/Model/TestResultTest.php +++ b/tests/phpunit/Components/Repoter/Model/ReportTestResultTest.php @@ -3,13 +3,13 @@ namespace phpunit\Components\Repoter\Model; use PHPUnit\Framework\TestCase; -use PHPUnuhi\Components\Reporter\Model\TestResult; +use PHPUnuhi\Components\Reporter\Model\ReportTestResult; -class TestResultTest extends TestCase +class ReportTestResultTest extends TestCase { /** - * @var TestResult + * @var ReportTestResult */ private $resultFailed; @@ -18,7 +18,7 @@ class TestResultTest extends TestCase */ public function setUp(): void { - $this->resultFailed = new TestResult( + $this->resultFailed = new ReportTestResult( 'storefront 1', 'btnCancel', 'ErrorClass', diff --git a/tests/phpunit/Components/Validator/CaseStyleValidatorTest.php b/tests/phpunit/Components/Validator/CaseStyleValidatorTest.php index 318a5bd3..5c4bf47e 100644 --- a/tests/phpunit/Components/Validator/CaseStyleValidatorTest.php +++ b/tests/phpunit/Components/Validator/CaseStyleValidatorTest.php @@ -220,7 +220,7 @@ public function testOnlyLevel1IsSetAndFails(): void # make sure the correct error is found # we only have an error at level 1, not at 0 - $this->assertEquals('Invalid case-style for key: lblTitle at level: 1', $firstError->getMessage()); + $this->assertEquals("Invalid case-style for part 'lblTitle' in key 'card-section.lblTitle' at level: 1", $firstError->getFailureMessage()); } /** diff --git a/tests/phpunit/Components/Validator/Model/ValidationErrorTest.php b/tests/phpunit/Components/Validator/Model/ValidationErrorTest.php deleted file mode 100644 index 04cacdcf..00000000 --- a/tests/phpunit/Components/Validator/Model/ValidationErrorTest.php +++ /dev/null @@ -1,78 +0,0 @@ -error = new ValidationError( - 'NOT_FOUND', - 'Translation not found', - 'en_US', - 'en.json', - 'ID-123', - 14 - ); - } - - /** - * @return void - */ - public function testClassification(): void - { - $this->assertEquals('NOT_FOUND', $this->error->getClassification()); - } - - /** - * @return void - */ - public function testLocale(): void - { - $this->assertEquals('en_US', $this->error->getLocale()); - } - - /** - * @return void - */ - public function testFilename(): void - { - $this->assertEquals('en.json', $this->error->getFilename()); - } - - /** - * @return void - */ - public function testMessage(): void - { - $this->assertEquals('Translation not found', $this->error->getMessage()); - } - - /** - * @return void - */ - public function testIdentifier(): void - { - $this->assertEquals('ID-123', $this->error->getIdentifier()); - } - - /** - * @return void - */ - public function testLineNumber(): void - { - $this->assertEquals('14', $this->error->getLineNumber()); - } -} diff --git a/tests/phpunit/Components/Validator/Model/ValidationResultTest.php b/tests/phpunit/Components/Validator/Model/ValidationResultTest.php index 4e3ca89e..90aebf35 100644 --- a/tests/phpunit/Components/Validator/Model/ValidationResultTest.php +++ b/tests/phpunit/Components/Validator/Model/ValidationResultTest.php @@ -3,7 +3,6 @@ namespace phpunit\Components\Validator\Model; use PHPUnit\Framework\TestCase; -use PHPUnuhi\Components\Validator\Model\ValidationError; use PHPUnuhi\Components\Validator\Model\ValidationResult; use PHPUnuhi\Components\Validator\Model\ValidationTest; @@ -30,19 +29,10 @@ public function setUp(): void 5, '', '', - true + false ); - $error = new ValidationError( - '', - '', - '', - '', - '', - 4 - ); - - $this->result = new ValidationResult([$test], [$error]); + $this->result = new ValidationResult([$test]); } /** diff --git a/tests/phpunit/Utils/Traits/TestReportBuilderTrait.php b/tests/phpunit/Utils/Traits/TestReportBuilderTrait.php index d3f501ba..c07af323 100644 --- a/tests/phpunit/Utils/Traits/TestReportBuilderTrait.php +++ b/tests/phpunit/Utils/Traits/TestReportBuilderTrait.php @@ -2,18 +2,18 @@ namespace phpunit\Utils\Traits; -use PHPUnuhi\Components\Reporter\Model\TestResult; +use PHPUnuhi\Components\Reporter\Model\ReportTestResult; trait TestReportBuilderTrait { /** * @param bool $success - * @return TestResult + * @return ReportTestResult */ - protected function buildTestResult(bool $success): TestResult + protected function buildTestResult(bool $success): ReportTestResult { - return new TestResult( + return new ReportTestResult( 'Fake Test', 'btnTitle', 'CONTENT_VALIDATOR',