File tree Expand file tree Collapse file tree 6 files changed +96
-1
lines changed
src/Domain/Question/Validation
tests/unit/Domain/Question/Validation Expand file tree Collapse file tree 6 files changed +96
-1
lines changed Original file line number Diff line number Diff line change 11.idea
2-
2+ .phpunit.cache
33/vendor /
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <phpunit xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
3+ xsi : noNamespaceSchemaLocation =" https://schema.phpunit.de/13.0/phpunit.xsd"
4+ cacheDirectory =" .phpunit.cache"
5+ beStrictAboutOutputDuringTests =" true"
6+ beStrictAboutTestsThatDoNotTestAnything =" true"
7+ displayDetailsOnAllIssues =" true"
8+ failOnPhpunitDeprecation =" true"
9+ failOnRisky =" true"
10+ failOnWarning =" true"
11+ colors =" true" >
12+ <testsuites >
13+ <testsuite name =" unit" >
14+ <directory >tests/unit</directory >
15+ </testsuite >
16+ </testsuites >
17+ </phpunit >
Original file line number Diff line number Diff line change 1+ <?php
2+ declare (strict_types=1 );
3+
4+ namespace thofman \KnowledgeBase \Domain \Question \Validation ;
5+
6+ final readonly class NonEmptyStringValidator implements Validator
7+ {
8+ public function validate (string $ value ): ValidationResult
9+ {
10+ return ValidationResult::valid ();
11+ }
12+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ declare (strict_types=1 );
3+
4+ namespace thofman \KnowledgeBase \Domain \Question \Validation ;
5+
6+ final readonly class ValidationResult
7+ {
8+ public static function valid (): self
9+ {
10+ return new self (
11+ isValid: true ,
12+ );
13+ }
14+
15+ public static function invalid (string $ validationErrorMessage ): self
16+ {
17+ return new self (
18+ isValid: false ,
19+ validationErrorMessage: $ validationErrorMessage ,
20+ );
21+ }
22+
23+ private function __construct (
24+ public bool $ isValid ,
25+ public string $ validationErrorMessage = '' ,
26+ ) {
27+ }
28+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ declare (strict_types=1 );
3+
4+ namespace thofman \KnowledgeBase \Domain \Question \Validation ;
5+
6+ use Symfony \Component \Console \Question \Question ;
7+
8+ interface Validator
9+ {
10+ public function validate (string $ value ): ValidationResult ;
11+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ declare (strict_types=1 );
3+
4+ namespace thofman \KnowledgeBase \tests \unit \Domain \Question \Validation ;
5+
6+ use Generator ;
7+ use PHPUnit \Framework \Attributes \DataProvider ;
8+ use PHPUnit \Framework \Attributes \Test ;
9+ use PHPUnit \Framework \TestCase ;
10+ use thofman \KnowledgeBase \Domain \Question \Validation \NonEmptyStringValidator ;
11+ use thofman \KnowledgeBase \Domain \Question \Validation \ValidationResult ;
12+
13+ final class NonEmptyStringValidatorTest extends TestCase
14+ {
15+ #[Test]
16+ #[DataProvider('provideDataToTestTheNonEmptyStringValidator ' )]
17+ public function theNonEmptyStringValidator (string $ value , ValidationResult $ expectedResult ): void
18+ {
19+ $ validator = new NonEmptyStringValidator ();
20+ self ::assertEquals ($ expectedResult , $ validator ->validate ($ value ));
21+ }
22+
23+ public static function provideDataToTestTheNonEmptyStringValidator (): Generator
24+ {
25+ yield ['test ' , ValidationResult::valid ()];
26+ }
27+ }
You can’t perform that action at this time.
0 commit comments