Server
in package
The Server class is used to control a scripted webserver using node.js that will respond to HTTP requests with queued responses.
Queued responses will be served to requests using a FIFO order. All requests received by the server are stored on the node.js server and can be retrieved by calling Server::getReceivedRequests().
Mock responses that don't require data to be transmitted over HTTP a great for testing. Mock response, however, cannot test the actual sending of an HTTP request using cURL. This test server allows the simulation of any number of HTTP request response transactions to test the actual sending of requests over the wire without having to leave an internal network.
Table of Contents
- DEFAULT_PORT = 8124
- REQUEST_DELIMITER = " ----[request] "
- $client : Client
- $port : int
- $running : bool
- __construct() : mixed
- Create a new scripted server
- enqueue() : mixed
- Queue an array of responses or a single response on the server.
- flush() : mixed
- Flush the received requests from the server
- getPort() : int
- Get the port that the server is listening on
- getReceivedRequests() : array<string|int, mixed>
- Get all of the received requests
- getUrl() : string
- Get the URL to the server
- isRunning() : bool
- Check if the server is running
- start() : mixed
- Start running the node.js server in the background
- stop() : mixed
- Stop running the node.js server
Constants
DEFAULT_PORT
public
mixed
DEFAULT_PORT
= 8124
REQUEST_DELIMITER
public
mixed
REQUEST_DELIMITER
= "
----[request]
"
Properties
$client
private
Client
$client
$port
private
int
$port
Port that the server will listen on
$running
private
bool
$running
= false
Is the server running
Methods
__construct()
Create a new scripted server
public
__construct([int $port = null ]) : mixed
Parameters
- $port : int = null
-
Port to listen on (defaults to 8124)
Return values
mixed —enqueue()
Queue an array of responses or a single response on the server.
public
enqueue(array<string|int, mixed>|Response $responses) : mixed
Any currently queued responses will be overwritten. Subsequent requests on the server will return queued responses in FIFO order.
Parameters
- $responses : array<string|int, mixed>|Response
-
A single or array of Responses to queue
Tags
Return values
mixed —flush()
Flush the received requests from the server
public
flush() : mixed
Tags
Return values
mixed —getPort()
Get the port that the server is listening on
public
getPort() : int
Return values
int —getReceivedRequests()
Get all of the received requests
public
getReceivedRequests([bool $hydrate = false ]) : array<string|int, mixed>
Parameters
- $hydrate : bool = false
-
Set to TRUE to turn the messages into actual RequestInterface objects. If $hydrate is FALSE, requests will be returned as strings.
Tags
Return values
array<string|int, mixed> —getUrl()
Get the URL to the server
public
getUrl() : string
Return values
string —isRunning()
Check if the server is running
public
isRunning() : bool
Return values
bool —start()
Start running the node.js server in the background
public
start() : mixed
Return values
mixed —stop()
Stop running the node.js server
public
stop() : mixed