summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2019-07-16 01:39:54 +0200
committerIgor Scheller <igor.scheller@igorshp.de>2019-07-16 01:39:54 +0200
commitb25924e868cdf80944e56a76fa6eed4509d9af7b (patch)
tree598dbd84af3610aaf02cab44994eaa9a0c9b7c10 /tests
parent6743106d9a8c760580690aab704f908766731801 (diff)
Allow nested rules (not and optional)
Diffstat (limited to 'tests')
-rw-r--r--tests/Unit/Http/Validation/ValidatorTest.php64
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/Unit/Http/Validation/ValidatorTest.php b/tests/Unit/Http/Validation/ValidatorTest.php
index 0790b7a8..450e5d4e 100644
--- a/tests/Unit/Http/Validation/ValidatorTest.php
+++ b/tests/Unit/Http/Validation/ValidatorTest.php
@@ -16,6 +16,7 @@ class ValidatorTest extends TestCase
public function testValidate()
{
$val = new Validator();
+
$this->assertTrue($val->validate(
['foo' => 'bar', 'lorem' => 'on', 'dolor' => 'bla'],
['lorem' => 'accepted']
@@ -35,9 +36,36 @@ class ValidatorTest extends TestCase
/**
* @covers \Engelsystem\Http\Validation\Validator::validate
*/
+ public function testValidateChaining()
+ {
+ $val = new Validator();
+
+ $this->assertTrue($val->validate(
+ ['lorem' => 10],
+ ['lorem' => 'required|min:3|max:10']
+ ));
+ $this->assertTrue($val->validate(
+ ['lorem' => 3],
+ ['lorem' => 'required|min:3|max:10']
+ ));
+
+ $this->assertFalse($val->validate(
+ ['lorem' => 2],
+ ['lorem' => 'required|min:3|max:10']
+ ));
+ $this->assertFalse($val->validate(
+ ['lorem' => 42],
+ ['lorem' => 'required|min:3|max:10']
+ ));
+ }
+
+ /**
+ * @covers \Engelsystem\Http\Validation\Validator::validate
+ */
public function testValidateNotImplemented()
{
$val = new Validator();
+
$this->expectException(InvalidArgumentException::class);
$val->validate(
@@ -53,6 +81,7 @@ class ValidatorTest extends TestCase
public function testValidateMapping()
{
$val = new Validator();
+
$this->assertTrue($val->validate(
['foo' => 'bar'],
['foo' => 'required']
@@ -75,4 +104,39 @@ class ValidatorTest extends TestCase
$val->getErrors()
);
}
+
+ /**
+ * @covers \Engelsystem\Http\Validation\Validator::validate
+ */
+ public function testValidateNesting()
+ {
+ $val = new Validator();
+
+ $this->assertTrue($val->validate(
+ [],
+ ['foo' => 'not|required']
+ ));
+
+ $this->assertTrue($val->validate(
+ ['foo' => 'foo'],
+ ['foo' => 'not|int']
+ ));
+ $this->assertFalse($val->validate(
+ ['foo' => 1],
+ ['foo' => 'not|int']
+ ));
+
+ $this->assertTrue($val->validate(
+ [],
+ ['foo' => 'optional|int']
+ ));
+ $this->assertTrue($val->validate(
+ ['foo' => '33'],
+ ['foo' => 'optional|int']
+ ));
+ $this->assertFalse($val->validate(
+ ['foo' => 'T'],
+ ['foo' => 'optional|int']
+ ));
+ }
}