public function testMethod() { $app = new \OnePHP\App(); $func = function () { return true; }; //default HTTP Requests in OneFramework $app->get('/get', $func); $app->post('/post', $func); $app->put('/put', $func); $app->delete('/delete', $func); $routes = $app->getRoutes(); //check if routes are found $this->assertEquals('/get', $routes['GET'][0]->route); $this->assertEquals('/post', $routes['POST'][0]->route); $this->assertEquals('/put', $routes['PUT'][0]->route); $this->assertEquals('/delete', $routes['DELETE'][0]->route); }
} catch (Exception $e) { // imprime a resposta em JSON $app->JsonResponse('[' . $e->getMessage() . ']', 500); } }); $app->put('/api/:action/:id', function ($action, $id) use($app) { // verifica o Token $auth = checkAuth($app->getRequest()->header("Authorization")); if (!$auth["success"]) { $app->JsonResponse($auth); return; } $data = (array) json_decode($app->getRequest()->getBody()); // define o nome da model, se não existir usa a base model $entity = ucfirst(load($action)); // instancia a model, passando o nome da action (tabela) como parametro $model = new $entity($action); // chama o metodo try { $response = $model->save($data, $id); // imprime a resposta em JSON $app->JsonResponse($response); } catch (Exception $e) { // imprime a resposta em JSON $app->JsonResponse('[' . $e->getMessage() . ']', 500); } }); $app->delete('/api/:action/:id', function ($action, $id) use($app) { // verifica o Token $auth = checkAuth($app->getRequest()->header("Authorization")); if (!$auth["success"]) { $app->JsonResponse($auth);