Download the PHP package litvinab/rest-api-test without Composer
On this page you can find all versions of the php package litvinab/rest-api-test. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download litvinab/rest-api-test
More information about litvinab/rest-api-test
Files in litvinab/rest-api-test
Package rest-api-test
Short Description This symfony bundle is made to simplify testing of your rest API. It can be useful in running of functional data fixtures based tests and acceptance (Behat) tests. It simplifies automatic tests development by provided test cases classes and commands
License
Homepage https://github.com/litvinab/rest-api-test
Informations about the package rest-api-test
RestAPITest
This symfony bundle is made to simplify testing of your rest API.
It can be useful for functional tests based on data fixtures and for acceptance tests.
Also current bundle provides some aliases of doctrine commands. It was made to prevent copy-paste of the same commands in your CI (for example, in Makefile, in setup of your tests, etc.)
Contents
Installation
Install via Composer:
Enable Bundle
In your app/AppKernel.php
file, add the following to your list of dev bundles:
Commands
-
bin/console db:create
- alias ofdoctrine:database:create
command; -
bin/console db:update-schema
- alias ofdoctrine:schema:update --force
command; -
bin/console db:load-fixtures
- alias ofdoctrine:fixtures:load --no-interaction
command; bin/console db:clear-cache
- clean database metadata, query, result cache at the same time;
Functional Data Fixtures Based Tests
Configuration
1. Setup parameters_test.yml
with test database name and connection details;
2. Create data fixtures and configure them right;
How To Use
Extend test cases mentioned below and call method to reload test data fixtures before each test or before specified test.
Call db:create
, db:create-schema
before using to create test database and create database schema;
FixturesWebTestCase
It can be useful in repositories tests to have the same database state at the beggining of each test.
Methods:
RestFixturesWebTestCase
Methods:
Asserts:
Examples
FixturesWebTestCase
RestFixturesWebTestCase
Acceptance (Behat) Tests
Configuration
1. Add route to routing.yml
:
2. Add parameters to parameters.yml
(rest_api_test.access_token
value should be secured enough):
rest_api_test.controller_on
(false by default) - parameter to turn ON/OFF endpoint to reload database in symfony prod
environment.
Be careful! It should be turned ON for acceptance tests (external tests of rest API) only.
Do not turn ON it at production server!
It would be good to setup additional security rules for this endpoint, for example, white list of IPs.
rest_api_test.access_token
(empty string by default) - random strong password, for example, 5j%]4fX.)z[HTR{M
;
This token required to access to reload db endpoint; It will be applied only ifrest_api_test.controller_on
is set to true
;
How To Use
Your application side:
1. Setup data fixtures if they weren't setup yet;
2. Setup separated application instance with not production database;
Bundle provides possibility to reload data fixtures in prod
symfony environment to make possible an end-user testing;
3. check configuration setup in parameters.yml
;
Behat tests runner side:
Make GET
request to reload database state of your application. It should be made before each acceptance test.
Endpoint: http://YOUR_DOMAIN/api/test/db/reload
Custom header: Rest-API-Test-Access-Token: 5j%]4fX.)z[HTR{M
(value is value of rest_api_test.access_token
parameter);
As result database mentioned in parameters.yml
should be reloaded with your test data fixtures;