From 40fc82e515cc752d01e06c44a9d64d4c24ce3712 Mon Sep 17 00:00:00 2001 From: Ferdinand Kuhl Date: Fri, 2 Jun 2017 21:58:33 +0200 Subject: [PATCH] TASK: Add basic functional tests --- Configuration/Testing/Validation.yaml | 18 +++++++++ Tests/Functional/Fixtures/TestObject.php | 47 ++++++++++++++++++++++ Tests/Functional/SettingsValidatorTest.php | 34 ++++++++++++++++ composer.json | 5 +++ 4 files changed, 104 insertions(+) create mode 100644 Configuration/Testing/Validation.yaml create mode 100644 Tests/Functional/Fixtures/TestObject.php create mode 100644 Tests/Functional/SettingsValidatorTest.php 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",