Download the PHP package lark/resttest without Composer
On this page you can find all versions of the php package lark/resttest. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lark/resttest
More information about lark/resttest
Files in lark/resttest
Package resttest
Short Description Lark RestTest
License MIT
Homepage https://github.com/shayanderson/lark-resttest
Informations about the package resttest
Lark RestTest
RestTest is a REST API test library for testing REST API endpoints.
Install
Setup a Test Directory
Create a test directory, for example ./tests/Rest
and add a run tests file like ./tests/Rest/run.php
:
Create a Test Class
A test class can be created the ./tests/Rest
directory and must end in Test.php
. Create a first test class like ./tests/Rest/UserTest.php
:
Each test class method that is a test must have @test
in the docblock, otherwise it will be ignored when running tests.
If a method depends on another method, or multiple methods, the @depends [METHODNAME]
annotation in the method docblock should be used, like @depends create
.
If a class depends on another class the @depends [CLASSNAME]
annotation in the class docblock should be used, like @depends \Tests\Rest\UserTest
.
All classes ending in
Test.php
will be considered tests. To exclude a class file ending inTest.php
from tests use@ignore
in the class docblock.
Cleanup Callable
A test method can return a callable
that is used as a cleanup function and will be called after the test method has been called, example:
Comparing Response Body
Sometimes a response body array of objects can be randomly ordered, which can cause a test to fail when using RestTest::expectBodySame
. For example:
To get around this problem the RestTest::expectBodySameSorted
method can be used to auto sort the expected array of objects and the response body array of objects by a specific field (id
by default).
Run Tests
To run the tests go to the tests directory where the run tests file is located like ./tests/Rest
and execute the run file: