summaryrefslogtreecommitdiff
path: root/tests/Unit/Http/Validation/ValidatorTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Unit/Http/Validation/ValidatorTest.php')
-rw-r--r--tests/Unit/Http/Validation/ValidatorTest.php42
1 files changed, 35 insertions, 7 deletions
diff --git a/tests/Unit/Http/Validation/ValidatorTest.php b/tests/Unit/Http/Validation/ValidatorTest.php
index 799265ec..0790b7a8 100644
--- a/tests/Unit/Http/Validation/ValidatorTest.php
+++ b/tests/Unit/Http/Validation/ValidatorTest.php
@@ -2,7 +2,6 @@
namespace Engelsystem\Test\Unit\Http\Validation;
-use Engelsystem\Http\Validation\Validates;
use Engelsystem\Http\Validation\Validator;
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
@@ -10,19 +9,18 @@ use PHPUnit\Framework\TestCase;
class ValidatorTest extends TestCase
{
/**
- * @covers \Engelsystem\Http\Validation\Validator::__construct
* @covers \Engelsystem\Http\Validation\Validator::validate
* @covers \Engelsystem\Http\Validation\Validator::getData
* @covers \Engelsystem\Http\Validation\Validator::getErrors
*/
public function testValidate()
{
- $val = new Validator(new Validates);
+ $val = new Validator();
$this->assertTrue($val->validate(
- ['foo' => 'bar', 'lorem' => 'on'],
- ['foo' => 'required|not_in:lorem,ipsum,dolor', 'lorem' => 'accepted']
+ ['foo' => 'bar', 'lorem' => 'on', 'dolor' => 'bla'],
+ ['lorem' => 'accepted']
));
- $this->assertEquals(['foo' => 'bar', 'lorem' => 'on'], $val->getData());
+ $this->assertEquals(['lorem' => 'on'], $val->getData());
$this->assertFalse($val->validate(
[],
@@ -39,7 +37,7 @@ class ValidatorTest extends TestCase
*/
public function testValidateNotImplemented()
{
- $val = new Validator(new Validates);
+ $val = new Validator();
$this->expectException(InvalidArgumentException::class);
$val->validate(
@@ -47,4 +45,34 @@ class ValidatorTest extends TestCase
['foo' => 'never_implemented']
);
}
+
+ /**
+ * @covers \Engelsystem\Http\Validation\Validator::map
+ * @covers \Engelsystem\Http\Validation\Validator::mapBack
+ */
+ public function testValidateMapping()
+ {
+ $val = new Validator();
+ $this->assertTrue($val->validate(
+ ['foo' => 'bar'],
+ ['foo' => 'required']
+ ));
+ $this->assertTrue($val->validate(
+ ['foo' => '0'],
+ ['foo' => 'int']
+ ));
+ $this->assertTrue($val->validate(
+ ['foo' => 'on'],
+ ['foo' => 'accepted']
+ ));
+
+ $this->assertFalse($val->validate(
+ [],
+ ['lorem' => 'required']
+ ));
+ $this->assertEquals(
+ ['lorem' => ['validation.lorem.required']],
+ $val->getErrors()
+ );
+ }
}