summaryrefslogtreecommitdiff
path: root/tests/Unit/Http/Validation/ValidatorTest.php
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2019-07-09 21:43:18 +0200
committerIgor Scheller <igor.scheller@igorshp.de>2019-07-09 21:43:18 +0200
commit7414f9b23dbcc66e5f0efda3d0cbfd79372ec780 (patch)
tree891a11b71d8b25922fc4b343dbc77a01a0646ba1 /tests/Unit/Http/Validation/ValidatorTest.php
parent508695efb253d7bc0caea1fa017ed5608d774596 (diff)
Implemented Validation for controllers
Diffstat (limited to 'tests/Unit/Http/Validation/ValidatorTest.php')
-rw-r--r--tests/Unit/Http/Validation/ValidatorTest.php50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/Unit/Http/Validation/ValidatorTest.php b/tests/Unit/Http/Validation/ValidatorTest.php
new file mode 100644
index 00000000..799265ec
--- /dev/null
+++ b/tests/Unit/Http/Validation/ValidatorTest.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace Engelsystem\Test\Unit\Http\Validation;
+
+use Engelsystem\Http\Validation\Validates;
+use Engelsystem\Http\Validation\Validator;
+use InvalidArgumentException;
+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);
+ $this->assertTrue($val->validate(
+ ['foo' => 'bar', 'lorem' => 'on'],
+ ['foo' => 'required|not_in:lorem,ipsum,dolor', 'lorem' => 'accepted']
+ ));
+ $this->assertEquals(['foo' => 'bar', 'lorem' => 'on'], $val->getData());
+
+ $this->assertFalse($val->validate(
+ [],
+ ['lorem' => 'required|min:3']
+ ));
+ $this->assertEquals(
+ ['lorem' => ['validation.lorem.required', 'validation.lorem.min']],
+ $val->getErrors()
+ );
+ }
+
+ /**
+ * @covers \Engelsystem\Http\Validation\Validator::validate
+ */
+ public function testValidateNotImplemented()
+ {
+ $val = new Validator(new Validates);
+ $this->expectException(InvalidArgumentException::class);
+
+ $val->validate(
+ ['lorem' => 'bar'],
+ ['foo' => 'never_implemented']
+ );
+ }
+}