Download the PHP package michaelhall/webunit without Composer
On this page you can find all versions of the php package michaelhall/webunit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download michaelhall/webunit
More information about michaelhall/webunit
Files in michaelhall/webunit
Informations about the package webunit
Webunit
Webunit is a command line client for automated web application tests.
Requirements
- PHP >= 8.0
Install with Composer
Basic usage
The client requires a file in text format, containing the tests to run. Pass the name of this file as a command line parameter:
The tests in the test file consists of one or more test cases. Every test case starts with a command. The most basic test case is just a command, e.g.
This test will be successful if the Url is functional and does not return an error or redirect status code. Otherwise, the test will fail.
The Url can also be fetched with one of the other supported HTTP methods:
A test case can also contain specific assertions:
Comments and whitespaces can be used to format the test file:
Some assertions can be modified with modifier characters:
The request can be modified with request modifiers:
The test file can set variables to be reused for the tests.
Variables are evaluated at parse-time in a manner similar to the preprocessor directives in languages like C and C#.
It is also possible to set variables from the command line:
A default value can be used to set the variable if not already set.
Example 1:
Example 2:
The command line option can be used to disable colors in output.
The following escape sequences can be used in the test file:
Escape sequence | Character |
---|---|
\n | Line feed |
\r | Carriage return |
\s | Space |
\t | Horizontal tab |
\\ | Backslash |
Commands
delete url
Fetches a Url via a request.
get url
Fetches a Url via a request.
patch url
Fetches a Url via a request.
post url
Fetches a Url via a request.
put url
Fetches a Url via a request.
Assertions
assert-contains content
Asserts that the content of the result contains the specified content. Allowed modifiers are , ,
assert-empty
Asserts that the content of the result is empty. Allowed modifier is
assert-equals content
Asserts that the content of the result is the same as the specified content. Allowed modifiers are , ,
assert-header header-name[: header-value]
Asserts that the result contains a header with the specified name and an optional value. Allowed modifiers are , ,
Note: The header name is always case-insensitive.
assert-status-code status-code
Asserts that the status code of the result is the same as the specified status code. Allowed modifier is
Note: This assert must be present for a test to pass if the result has a status code other than 200-299.
Request modifiers
with-header header-name: header-value
Sets an HTTP-header with the specified name to the specified value.
with-post-file parameter-name = file-path
Sets a POST-parameter with the specified name to a file to be uploaded. The file path can be either absolute or relative to the webunit test script. This request modifier can not be used for GET requests and can not be combined with the with-raw-content request modifier.
with-post-parameter parameter-name = parameter-value
Sets a POST-parameter with the specified name to the specified value. This request modifier can not be used for GET requests and can not be combined with the with-raw-content request modifier.
with-raw-content content
Sets the request body content to the specified content. This request modifier can not be used for GET requests and can not be combined with the with-post-file and with-post-parameter request modifiers.
License
MIT
All versions of webunit with dependencies
ext-mbstring Version *
michaelhall/http-client Version ^2.0
datatypes/datatypes Version ^3.0