public function register(Container $app) { $app['restapi.storage'] = function () use($app) { return new HashedStorage($app['restapi']['storage_path']); }; $app['restapi.service'] = function () use($app) { $api = new RestApi($app['db'], $app['restapi']['schema_cache']); $api->setStorage($app['restapi.storage']); $api->setDebug($app['debug']); return $api; }; if (isset($app['restapi']['auth'])) { $app['restapi.auth'] = function () use($app) { $auth = new AuthService($app['restapi']['auth']['users']); $auth->setTokenOptions($app['restapi']['auth']['token']); $auth->setCookieOptions($app['restapi']['auth']['cookie']); return $auth; }; $app['restapi.listener.auth_checker'] = $app->protect(function (Request $request) use($app) { if (!($user = $app['restapi.auth']->getAuthenticatedUserFromRequest($request))) { return new Response(null, 401, ['Content-Type' => 'application/json']); } $app['restapi.service']->setUser($user); }); } if (isset($app['restapi']['cors'])) { $app['restapi.middleware.cors'] = function () use($app) { return new CorsMiddleware($app['restapi']['cors']); }; } }
public function testUpdateResourceNonExisting() { $api = new RestApi($this->database); $todo = $api->updateResource('todos', 1, ['done' => 1]); $this->assertEquals(400, $todo['code']); $this->assertEquals('Resource todos does not exist', $todo['body']['message']); }