Tests
Sirius has a variety of suites to test different parts of the application.
PHP linting
PHP code is linted with PHP_CodeSniffer to ensure it meets PSR-12 standards.
You can lint the API and frontend code respectively with:
make api-lint
make frontend-lint
You should also configure your code editor to apply PSR-12 formatting when you save a file.
PHPStan
We use PHPStan to statically analyze our PHP code. This highlights errors with PHP types (such as passing an integer to a string parameter).
You can run PHPStan on the API and frontend code respectively with:
make api-phpstan
make frontend-phpstan
If PHPStan identifies errors in the API. that you can’t fix, then you can add them to the baseline file of ignored errors. However, this should only be done in extreme circumstances and generally we should fix any errors reported by PHPStan.
make api-phpstan-baseline
API unit tests
The API unit tests use PHPUnit to test individual PHP classes in isolation. They mock out any dependencies of the class so that they’re only testing its intrinsic code.
You can run the full unit test suite:
make api-unit
You can also filter the suite to only run a particular class or test:
API_UNIT_EXTRA=--filter=PhoneNumberTest make api-unit-local
API_UNIT_EXTRA=--filter=test_getPaymentAmountAndDate make api-unit-local
API functional tests
The API functional tests also use PHPUnit but they start a full copy of the database and API instead of mocking out dependencies. They are used for tests that require a full copy of the API, such as controller routing and tests that rely on database data.
The functional tests are split into several suites that can be run in parallel so that they can run faster.
make api-functional-correspondence # Tests related to sending correspondence
make api-functional-controller # Tests of controllers
make api-functional-ddc # Tests related to digital document capture (DDC/scanning)
make api-functional-finance # Tests related to Supervision's finance functionality
make api-functional-mi # Tests related to MI reports
make api-functional # Remaining functional tests not in the other suites
You can filter each suite to only run a particular class or test, for example:
API_FUNCTIONAL_EXTRA=--filter=UserControllerTest make api-functional-controller-local
NB: You must ensure that the class/test you filter to is in the suite you specify
Behat tests
We use Behat to test related API endpoints in small journeys (e.g. “If I create a new case, then request unassigned cases, my new case should be shown”). The tests are written in Cucumber syntax, making them more human readable, and are matched with regex to perform PHP code, mostly to make HTTP requests to the API.
Like functional tests, the behat tests are split into suites so they can performantly be run in parallel.
make behat-v0
make behat-functional
make behat-v1-ci
make behat-v1-ci-publicapi
make behat-v1-finance-1
make behat-v1-finance-2
make behat-v1-finance-reports-1
make behat-v1-ingestion
make behat-v1-ingestion-supervision
make behat-v1-supervision
make behat-v1-supervision-client
make behat-v1-supervision-correspondence
make behat-v1-supervision-documents
make behat-v1-supervision-scheduler
make behat-v1-supervision-search
You can run particular tests by giving them a custom tag (e.g. @abc
) and running the following command. Note that this must run build-api-test
so the new tag is recognised.
API_BEHAT_EXTRA="--tags=@abc" make api-behat