public function testService_StoreObjects() { $app = new App(); $app->service('foo', $obj = new \stdClass()); $this->assertSame($obj, $app->foo()); }
/** * Constructor * * Create a new Klein instance with optionally injected dependencies * This DI allows for easy testing, object mocking, or class extension * * @param ServiceProvider $service Service provider object responsible for utilitarian behaviors * @param mixed $app An object passed to each route callback, defaults to an App instance * @param RouteCollection $routes Collection object responsible for containing all route instances * @param AbstractRouteFactory $route_factory A factory class responsible for creating Route instances * @access public */ public function __construct($app = null, RouteCollection $routes = null, AbstractRouteFactory $route_factory = null) { $this->app = $app ?: new App(); $this->app->service('router', $this); $this->routes = $routes ?: new RouteCollection(); $this->route_factory = $route_factory ?: new RouteFactory(); }