-
Notifications
You must be signed in to change notification settings - Fork 0
Debugging
Mango has an option which allows you to simulate requests from the command line. This allows you to use a debugger like hhvm to debug your program directly in the command line without the need of a web server.
The parameters of the request are loaded from a JSON file and are used by mango to simulate a request sent to your application. It's important to note that you should not use $_GET, $_POST, $_SERVER variables directly within your code, in order for this to work you should use MHTTPRequest()->get(), MHTTPRequest()->post() & MHTTPRequest()->server(). They will contain the variables loaded from the simulated JSON request file.
Below is an example of a JSON request file called request.json
{
"request" {
"post" : {
},
"server" : {
"REQUEST_METHOD" : "POST",
"REQUEST_URI" : "/"
},
"contents-file" : "file/path"
}
}
By specifying a contents-file parameter you can even simulate the upload of a file.
In order to start the debugging run the following command from within your mango application's root folder:
hhvm -m d index.php --simulate-request request.json request
The format for the command is:
hhvm -m d index.php --simulate-request [json_request_file] [request_name]
You can place multiple requests inside one JSON file and call them using the [request_name] parameter.
This will fire the debugger allowing you to set breakpoints, step through your code, etc.
If you wish to simply run the request without a debugger simply use:
hhvm index.php --simulate-request request.json
As you can see this offers endless possibilities not just in terms of debugging but also automation & testing.