PHPUnit Testing for API
Step 1 - Starting Docker Container
From the ~/Documents/elentra-developer
directory enter:
This will start all relevant containers.
Step 2 - Seeding the database
From the ~/Documents/elentra-developer
directory, shell into the docker container:
This will open a Command Line Interface (CLI) inside the virtual server To seed the database, run the Elentra seed script (WARNING: you will lose data in existing databases and the contents of your config.inc.php
file):
this will drop all the databases, recreate them, and seed the database tables with data from the Seeder classes.
Step 3 - Creating a PHP Unit Test
Inside the elentra-1x-api/tests
directory, go into either the Functional
or Unit
directory (please ensure what type of test you are creating or it will be rejected during code review if it's in the wrong directory), create a new file. eg:
The setUp()
method will instantiate any objects required for running tests. These are created by specifying the complete namespace path to the file itself.
the test methods must have the annotation for a test in the comment block:
Without this, the method will be ignored when the tests are run.
Step 4 - Running php unit
from the /var/www/vhosts/elentra-1x-api
directory, type in:
This will run all Functional and Integration tests.
To test a single file, type:
Troubleshooting
Make sure your elentra-1x-api/phpunit.xml
has test suites for both Functional AND Integration specified:
Last updated