Download the PHP package jolicode/asynit without Composer
On this page you can find all versions of the php package jolicode/asynit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jolicode/asynit
More information about jolicode/asynit
Files in jolicode/asynit
Package asynit
Short Description Asynchronous HTTP Request Testing Library for API or more...
License MIT
Informations about the package asynit
asynit
Asynchronous (if library use fiber) testing library runner for HTTP / API and more...
Install
Usage
Writing a test
Asynit will read PHP's classes to find available Test using the Asynit\Attribute\TestCase
attribute. You need to
create a test class in some directory, which will have the TestCase
attribute of
Asynit:
Then you can add some tests that will use the API of the TestCase class:
Note: All test methods should be prefixed by the test
keyword or use the Asynit\Attribute\Test
anotation. All others
methods will not be executed automatically.
A test fail when an exception occurs during the test
Using assertion
Asynit provide trait to ease the writing of test. You can use the Asynit\AssertCaseTrait
trait to use the assertion.
All assertions supported by PHPUnit are also supported by Asynit thanks to the bovigo-assert library. But you can use your own as long as it's throw an exception on failure.
Running the test
For running this test you will only need to use the PHP file provided by this project:
If you have many test files, you can run Asynit with a directory
Using HTTP Client
Asynit provide an optional Asynit\HttpClient\HttpClientWebCaseTrait
trait that you can use to make HTTP request. You will need to install amphp/http-client
and
nyholm/psr7
to use it.
You can also use a more oriented API trait Asynit\HttpClient\HttpClientApiCaseTrait
that will allow you to write test like this:
Dependency between tests
Sometime a test may need a value from the result of another test, like an authentication token that need to be available for some requests (or a cookie defining the session).
Asynit provides a Depend
attribute which allows you to specify that a test is
dependent from another one.
So if you have 3 tests, A
, B
and C
and you say that C
depend on A
;
Test A
and B
will be run in parallel and once A
is completed and
successful, C
will be run with the result from A
.
Let's see an example:
Here testAuthenticatedRequest
will only be run after testLogin
has been
completed. You can also use dependency between different test case. The previous
test case is under the Application\ApiTest
namespace and thus we can write
another test case like this:
Test Organization
It's really common to reuse this token in a lot of test, and maybe you don't need test when fetching the token. Asynit allow you to depend on any method of any class.
So you could write a TokenFetcherClass
that will fetch the token and then use it in your test.
Then in your test class you will be able to call this method:
As you may notice, the fetchUserToken
method does not start with test
. Thus
by default this method will not be included in the test suite. But as it is a
dependency of a test, it will be included as a regular test in the global test
suite and will leverage the cache system.
All versions of asynit with dependencies
amphp/amp Version ^3.0
amphp/http-client Version ^v5.0.1
amphp/sync Version ^2.0
bovigo/assert Version ^7.0
symfony/console Version ^4.4 || ^5.0 || ^6.0 || ^7.0
symfony/finder Version ^4.4 || ^5.0 || ^6.0 || ^7.0