TASK: Add basic functional tests
This commit is contained in:
parent
93fa97e817
commit
40fc82e515
4 changed files with 104 additions and 0 deletions
18
Configuration/Testing/Validation.yaml
Normal file
18
Configuration/Testing/Validation.yaml
Normal 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
|
47
Tests/Functional/Fixtures/TestObject.php
Normal file
47
Tests/Functional/Fixtures/TestObject.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
34
Tests/Functional/SettingsValidatorTest.php
Normal file
34
Tests/Functional/SettingsValidatorTest.php
Normal 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());
|
||||||
|
}
|
||||||
|
}
|
|
@ -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",
|
||||||
|
|
Loading…
Reference in a new issue