Download the PHP package drewlabs/htr without Composer
On this page you can find all versions of the php package drewlabs/htr. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package htr
Short Description HTTP Web Service Test runner implementation using PHP Programming language and configuration files written in YAML or JSON format
License MIT
Informations about the package htr
HTr (HTTP Service Test Runner)
HTr
is a PHP based utility library that allow application (espacially HTTP REST services) developper to easily test their RESTful service using a a single configuration file writtern in YAML
or JSON
.
- Why
YAML
orJSON
In modern web standard,JSON
andYAML
entity definition languages have become the defacto standard for modeling configuration that are easily portable between programming tools and languages. Therefore instead of creating a new language, we leverage existing ones that are known amoung developper community.
Installation
The library is a PHP based library therefore a PHP
binary is required along side the powerful PHP
libraries package manager composer
.
To install the library simply run the command below:
Usage
Configuration
HTr
client application works with configuration files written in either JSON (Javascript Object Notation)
format or YAML
format. Below is a sample configuration file:
Note Based on the configuration above requests can be customized using environment variables. Environment variables must be enclosed in [variable]
.
Testing
Test assertion use a natural language to make it easy to write test. Below is the syntax to write test:
left op right
-> For simple assertionsleft op righ and condition_2_left and condition_2_right
-> For composed assertions
Suported operator for testing are:
- Logical operators
and
: For joining 2 or more conditions and returntrue
only if all conditions returntrue
or
: For joining 2 o more condition and returntrue
if one of the condittions istrue
- Comparison operations
lt
or>
: Stand for valueless than
lte
or<=
: Forless than or equals to comparison
gt
or>
: Forgreater than comparison
gte
or>=
: Forgreater than or equals to comparison
eq
orne
: Respectivelyequals
ornot equals
has
: Check if an array has a given key or attributein
: Checks if a value exists in a list of value. Ex:mango in banana,orange,pinneaple
We use []
to denote properties of the response object:
[status]
denote response status code[body]
denote response body[headers]
denote response headers.
To Access properties of response body, we use [body] concatenated with the property name using .
symbol as follow;
[body].title
-> To access the title property of the response body[body].address.email
-> Can be used for instance to access inner property of responser body object
Command Line
The library provides a command line interface for testing your HTTP REST Service based on a configuration file. Below is the command to run a basic test command using a configuration file located in the root of your project:
The command above assune you have a file named htr.yml
in the root of your project that contains a valid HTr
test configuration.
-
Debug By default the
cli
script will run tests in silent mode and write output to a uniquely generated file at the root of your project. To run theHTr cli
in debug mode, execute the command below:Running the client application in debug mode allow developper ro see live running request with each request parameters output to the terminal.
-
Command output To override the output file name path were command logs are written simple use the
--output
flag as below: -
Request filtering
Sometimes developper might want to execute specific requests or specific request directory components. For such cases,
HTr
provides developpers with--request
or--req
for filtering by request name or id.Similary, to execute specific request directories, you can use
-d
or-directory
flag. TheHTr
client will only execute tests for requests in specified directory -
Overriding environment variables
When running tests using HTr client,
--input
argument usually contains anenv
field that is that are applied when running tests. To override the environment variable with command line variables, simple use--env
switch as follow:./vendor/bin/htr test --env=MyVar:MyVarValue --input=$(pwd)/htr.yml
- Json
By default the
HTr
client supportYAML
based configuration files. In order to useJSON
configuration file instead, simply use the--json
flag as follow:
All versions of htr with dependencies
drewlabs/curl-rest-client Version ^0.2.6|^0.3.0|^0.4.0
fakerphp/faker Version ^1.0