Пример #1
0
namespace validator\spec\suite;

use InvalidArgumentException;
use DateTime;
use validator\Validator;
use validator\Checker;
use kahlan\plugin\Stub;
describe("Validator", function () {
    afterEach(function () {
        Checker::reset();
    });
    describe("->__construct()", function () {
        it("correctly sets local validation handlers", function () {
            $validator = new Validator(['handlers' => ['zeroToNine' => '/^[0-9]$/', 'tenToNineteen' => '/^1[0-9]$/']]);
            expect($validator->handlers())->toContainKeys('zeroToNine', 'tenToNineteen');
        });
    });
    describe("->meta()", function () {
        it("gets/sets meta data", function () {
            $validator = new Validator();
            $meta = ['model' => 'Post'];
            expect($validator->meta($meta))->toBe($meta);
            expect($validator->meta())->toBe($meta);
        });
    });
    describe("->error()", function () {
        it("gets/sets the error handler", function () {
            $validator = new Validator();
            $handler = function () {
                return 'hello world';