Beispiel #1
0
            });
            $wrapper = new Wrapper(['box' => $this->box, 'name' => 'spec.stdClass']);
            $dependency = $wrapper->get();
            expect($dependency)->toBeAnInstanceOf("stdClass");
            expect($wrapper->get())->toBe($dependency);
        });
        it("throws an exception if the dependency doesn't exists", function () {
            $wrapper = new Wrapper(['box' => $this->box, 'name' => 'spec.stdUnexistingClass']);
            expect(function () use($wrapper) {
                $wrapper->get();
            })->toThrow(new BoxException());
        });
        it("passes parameters to the Closure", function () {
            $this->box->factory('spec.arguments', function () {
                return func_get_args();
            });
            $params = ['param1', 'param2'];
            $wrapper = new Wrapper(['box' => $this->box, 'name' => 'spec.arguments', 'params' => $params]);
            expect($wrapper->get())->toBe($params);
        });
        it("override passed parameters to the Closure", function () {
            $this->box->factory('spec.arguments', function () {
                return func_get_args();
            });
            $params = ['param1', 'param2'];
            $wrapper = new Wrapper(['box' => $this->box, 'name' => 'spec.arguments', 'params' => $params]);
            $overrided = ['param3', 'param4'];
            expect($wrapper->get('param3', 'param4'))->toBe($overrided);
        });
    });
});