Download the PHP package we-bridge/functionnal-test-helpers without Composer
On this page you can find all versions of the php package we-bridge/functionnal-test-helpers. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package functionnal-test-helpers
Symfony2 functionnal test helpers
This library offer you a set of Traits to ease the creation of functionnal tests for both REST api and normal HTML controllers of your symfony2 application. It also take care as much as possible to close the database connections after the tests are done (which by default phpunit seems not to do)
Installation
add in your composer.json
:
Then the classes are accessible from the namespace WeBridge\TestHelpers
Documentation:
A more complete documentation is to come, waiting for that one can directly check the code, which has been made to be as clear as possible, if you got any specific question, you can open a ticket, we're quite fast to answer.
For ApiHelpersTrait
For the moment the Api go with the assumption that except for binary data (images etc.), you want to send and receive JSON encoded data
Perform requests
all these methods perform the request using $this->client
and it's your responsability
(for the moment) to create it to fit your needs
Once the Request is performed, the raw response is assigned in $this->response
if the content
is json, the decoded content will in $this->responseJson
performGET(string $uri)
GET request to $uriperformDELETE($string $uri)
DELETE request to $uriperformPOSt(string $uri, array $data)
json_encode the $data and POST it to the URIperformPUT(string $uri, array $data)
json_encode the $data and PUT it to the URIperformPATCH(string $uri, array $data)
json_encode the $data and PATCH it to the URI
Methods to play with data fixtures
given(string $fixtureName)
, load the entity referenced by $fixtureName and set it in $this->entityrefreshEntiy()
, resync/refresh the entity in$this->entity
with the database
Assert HTTP status code
`
assertBadRequestError()
=> 400assertPermissionError()
=> 401assertPermissionDenied()
=> 403assertNotFoundError()
=> 404-
assertResponseUnprocessableEntity()
=> 422 assertOkSuccess()
=> 200assertCreatedSuccess()
=> 201assertNoContentResponse()
=> 203
Assert JSON returned
all these assets use the property $this->responseJson
, which is populated by
assertEmptyList
, check the json returned by aperform*
is a json Array with 0 elementassertNotEmptyList
, check the json returned by aperform*
is a json Array with 1+ elementassertResponseHasFields(array $fields)
check that the json returned is a json object made of at least the fields given in parametersassertListElementsHaveFields(array $fields)
check the json is an array for which every single element contains at least the given fields
Usage For REST Api
Example
Usage For normal Controllers
Note
The method getFirstElementByTestName('example')
takes the first HTML tag with the attribute
data-for-test-name="example"
the goal being to put all identifier and selectors based on data-for-test-*
attributes, the rationnal being
that this way you can modify without fear your id
and class
or tag
types without breaking your tests
(and there's nothing more raging than to break tests because you refactorize the CSS)
License
MIT
Contributing
Contributions are warmly welcomed, be it
- Feature requests
- Bug reports
- PR correcting one little typo
- PR adding some functionnalities
if you would like to contribute but have no clue on how to do it feel free to open an issue explaining what you want to do, and we will try to guide you step by step.