Ejemplo n.º 1
0
 /**
  * test complex mvc handling
  */
 public function testMVCComplex()
 {
     $controller = new ControllerExtended();
     $view = new View();
     $model = new Model();
     $controllerSetView = $controller->setView($view);
     $this->assertInstanceOf('PicoRest\\Components\\Controller', $controllerSetView);
     $viewSetModel = $view->setModel($model);
     $this->assertInstanceOf('PicoRest\\Components\\View', $viewSetModel);
     $view->set('test', true);
     $displayedResult = substr($controller->display(false, true), 0, 47);
     $this->assertEquals($displayedResult, '{"error":false,"data":{"test":true},"duration":');
     $route = new RouteGet('actionName', '/path', 'description');
     $this->assertEquals($route->getPath(), 'path');
     $this->assertEquals($route->getActionName(), 'actionName');
     $this->assertEquals($route->getDescription(), 'description');
     $this->assertEquals($route->getRouteType(), Route::TYPE_GET);
     $endpoint = new Endpoint($controller, '/controller', 'name', 'description');
     $this->assertEquals($endpoint->getController(), $controller);
     $this->assertEquals($endpoint->getName(), 'name');
     $this->assertEquals($endpoint->getPath(), '/controller/');
     $this->assertEquals($endpoint->getDescription(), 'description');
     $this->assertInstanceOf('PicoRest\\Components\\Endpoint', $endpoint->assignRoute($route));
 }
Ejemplo n.º 2
0
use PicoRest\Components\RouteGet;
use PicoRest\Components\RoutePost;
use PicoRest\Components\RouteDelete;
use PicoRest\Components\RoutePut;
use Sample\User\UserController;
use Sample\User\UserView;
use Sample\User\UserModel;
use PicoRest\Configuration\AppConfiguration;
$appConfiguration = AppConfiguration::getInstance();
$appConfiguration->set('key', 'value');
$userController = new UserController();
$userView = new UserView();
$userModel = new UserModel();
$userPDO = new PDO('mysql:host=localhost;dbname=picorest;charset=utf8', 'picorest', 'picorest');
$userController->setView($userView);
$userView->setModel($userModel);
$userModel->setPDO($userPDO);
$userEndpoint = new Endpoint($userController, 'user', 'user', 'create, edit, delete user from users database');
$listUsersRoute = new RouteGet('listUsers', '/list\\/users', 'show list of users');
$editUserRoute = new RoutePut('editUser', '/edit\\/(\\d*)', 'edit user via id');
$createUserRoute = new RoutePost('createUser', '/create', 'create new user');
$deleteUserRoute = new RouteDelete('deleteUser', '/delete\\/(\\d*)', 'delete user by id');
$userEndpoint->assignRoute($listUsersRoute);
$userEndpoint->assignRoute($editUserRoute);
$userEndpoint->assignRoute($createUserRoute);
$userEndpoint->assignRoute($deleteUserRoute);
$apiV1 = App::createAndRegisterRestApi('/api/v1/');
$apiV1->assignEndpoint($userEndpoint);
$apiV2 = App::createAndRegisterRestApi('/api/v2/');
$apiV2->assignEndpoint($userEndpoint);
App::run();