Example #1
0
    });
    context('__call', function () use($child, $parent) {
        $parent->callable1 = function () {
            return 'Callable 1';
        };
        $child->callable2 = function () {
            return 'Callable 2';
        };
        $child->callableWithArgs = function ($arg1, $arg2) {
            return "{$arg1} {$arg2}";
        };
        it('invokes the stored callable', function () use($child) {
            expect($child->callable2())->toBe('Callable 2');
        });
        it('invokes the stored callable with arguments', function () use($child) {
            $invokeCallable = function () use($child) {
                return $child->callableWithArgs('test', 'callable');
            };
            expect($invokeCallable())->toBe('test callable');
        });
        it("if not set, invokes the parent's callable", function () use($child) {
            expect($child->callable1())->toBe('Callable 1');
        });
        it('throws an exception if not found in the parent', function () use($child) {
            $callInvalidKey = function () use($child) {
                $child->invalidKey();
            };
            expect($callInvalidKey)->toThrow('\\BadFunctionCallException');
        });
    });
});