TASK: Add basic functional tests

This commit is contained in:
Ferdinand Kuhl 2017-06-02 21:58:33 +02:00
parent 93fa97e817
commit 40fc82e515
4 changed files with 104 additions and 0 deletions

View file

@ -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

View file

@ -0,0 +1,47 @@
<?php
namespace DigiComp\SettingValidator\Tests\Functional\Fixtures;
use Neos\Flow\Annotations as Flow;
class TestObject
{
/**
* @var bool
*/
protected $shouldBeTrue = true;
/**
* @var bool
*/
protected $shouldBeFalse = true;
/**
* @Flow\Validate(type="DigiComp.SettingValidator:Settings", options={"name": "TrueValidator"})
* @var bool
*/
protected $shouldBeTrueAndValidatedByAnnotation = false;
/**
* @return bool
*/
public function isShouldBeTrue(): bool
{
return $this->shouldBeTrue;
}
/**
* @return bool
*/
public function isShouldBeFalse(): bool
{
return $this->shouldBeFalse;
}
/**
* @return bool
*/
public function isShouldBeTrueAndValidatedByAnnotation(): bool
{
return $this->shouldBeTrueAndValidatedByAnnotation;
}
}

View file

@ -0,0 +1,34 @@
<?php
namespace DigiComp\SettingValidator\Tests\Functional;
use DigiComp\SettingValidator\Tests\Functional\Fixtures\TestObject;
use DigiComp\SettingValidator\Validation\Validator\SettingsValidator;
use Neos\Flow\Tests\FunctionalTestCase;
use Neos\Flow\Validation\ValidatorResolver;
class SettingsValidatorTest extends FunctionalTestCase
{
/**
* @test
*/
public function ifNoNameIsGivenClassNameIsUsed()
{
$validator = $this->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());
}
}

View file

@ -25,6 +25,11 @@
"DigiComp\\SettingValidator\\": "Classes" "DigiComp\\SettingValidator\\": "Classes"
} }
}, },
"autoload-dev": {
"psr-4": {
"DigiComp\\SettingValidator\\Tests\\": "Tests"
}
},
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "1.0.x-dev", "dev-master": "1.0.x-dev",