\Guzzle\Tests\HttpServer

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 \Guzzle\Tests\Http\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.

Summary

Methods
Properties
Constants
__construct()
flush()
enqueue()
isRunning()
getUrl()
getPort()
getReceivedRequests()
start()
stop()
No public properties found
DEFAULT_PORT
REQUEST_DELIMITER
No protected methods found
No protected properties found
N/A
No private methods found
$port
$running
$client
N/A

Constants

DEFAULT_PORT

DEFAULT_PORT = 8124

REQUEST_DELIMITER

REQUEST_DELIMITER = "\n----[request]\n"

Properties

$port

$port : integer

Type

integer — Port that the server will listen on

$running

$running : boolean

Type

boolean — Is the server running

Methods

__construct()

__construct(integer  $port = null) 

Create a new scripted server

Parameters

integer $port

Port to listen on (defaults to 8124)

flush()

flush() 

Flush the received requests from the server

Throws

\Guzzle\Common\Exception\RuntimeException

enqueue()

enqueue(array|\Guzzle\Http\Message\Response  $responses) 

Queue an array of responses or a single response on the server.

Any currently queued responses will be overwritten. Subsequent requests on the server will return queued responses in FIFO order.

Parameters

array|\Guzzle\Http\Message\Response $responses

A single or array of Responses to queue

Throws

\Guzzle\Http\Exception\BadResponseException

isRunning()

isRunning() : boolean

Check if the server is running

Returns

boolean

getUrl()

getUrl() : string

Get the URL to the server

Returns

string

getPort()

getPort() : integer

Get the port that the server is listening on

Returns

integer

getReceivedRequests()

getReceivedRequests(boolean  $hydrate = false) : array

Get all of the received requests

Parameters

boolean $hydrate

Set to TRUE to turn the messages into actual {@see RequestInterface} objects. If $hydrate is FALSE, requests will be returned as strings.

Throws

\Guzzle\Common\Exception\RuntimeException

Returns

array

start()

start() 

Start running the node.js server in the background

stop()

stop() 

Stop running the node.js server