Ejemplo n.º 1
0
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';
            };
            expect($validator->error($handler))->toBe($handler);
            expect($validator->error())->toBe($handler);
        });
    });
    describe("->get()", function () {
        it("throws an exceptions for unexisting validation handler", function () {