diff --git a/Configuration/Testing/Validation.yaml b/Configuration/Testing/Validation.yaml new file mode 100644 index 0000000..f9575d2 --- /dev/null +++ b/Configuration/Testing/Validation.yaml @@ -0,0 +1,18 @@ +DigiComp\SettingValidator\Tests\Functional\Fixtures\TestObject: + - + property: shouldBeTrue + validator: BooleanValue + options: + expectedValue: true + - + property: shouldBeFalse + validator: BooleanValue + options: + expectedValue: false + + +TrueValidator: + - + validator: BooleanValue + options: + expectedValue: true \ No newline at end of file diff --git a/Tests/Functional/Fixtures/TestObject.php b/Tests/Functional/Fixtures/TestObject.php new file mode 100644 index 0000000..ddd62c5 --- /dev/null +++ b/Tests/Functional/Fixtures/TestObject.php @@ -0,0 +1,47 @@ +shouldBeTrue; + } + + /** + * @return bool + */ + public function isShouldBeFalse(): bool + { + return $this->shouldBeFalse; + } + + /** + * @return bool + */ + public function isShouldBeTrueAndValidatedByAnnotation(): bool + { + return $this->shouldBeTrueAndValidatedByAnnotation; + } +} diff --git a/Tests/Functional/SettingsValidatorTest.php b/Tests/Functional/SettingsValidatorTest.php new file mode 100644 index 0000000..8feae6d --- /dev/null +++ b/Tests/Functional/SettingsValidatorTest.php @@ -0,0 +1,34 @@ +objectManager->get(SettingsValidator::class); + $result = $validator->validate(new TestObject()); + $this->assertTrue($result->hasErrors()); + $this->assertCount(1, $result->getFlattenedErrors()); + $this->assertCount(1, $result->forProperty('shouldBeFalse')->getErrors()); + } + + /** + * @test + */ + public function conjunctionValidationWorksAsExpected() + { + $validatorResolver = $this->objectManager->get(ValidatorResolver::class); + $validator = $validatorResolver->getBaseValidatorConjunction(TestObject::class); + $result = $validator->validate(new TestObject()); + $this->assertTrue($result->hasErrors()); + $this->assertCount(1, $result->getFlattenedErrors()); + } +} diff --git a/composer.json b/composer.json index 20f8488..a3cd64d 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,11 @@ "DigiComp\\SettingValidator\\": "Classes" } }, + "autoload-dev": { + "psr-4": { + "DigiComp\\SettingValidator\\Tests\\": "Tests" + } + }, "extra": { "branch-alias": { "dev-master": "1.0.x-dev",