Skip to content
Snippets Groups Projects
phpunit.md 3.85 KiB

PHP tests ensure that CiviCRM's PHP logic is working as expected — for example, ensuring that the 'Contact.create' API actually creates a contact.

These tests are written with PHPUnit. The PHP tests are grouped into suites (api_v3_AllTests, CRM_AllTests, and Civi\AllTests).

Setup

These tests required the latest supported version of PHPUnit. This is included with buildkit.

!!!warning It is possible that using the wrong configuration for tests will cause your main local database to be used for testing, and will leave it unusable afterwards.

To check that everything is configured correctly:

$ cd /path/to/civicrm
$ cv vars:show

Check that CIVI_DB_DSN and TEST_DB_DSN is configured. If you installed using buildkit this should all be configured for you.

If you want to run unit tests (and not WebTests or E2E tests) set the environment variable CIVICRM_UF to "UnitTests" (eg. in civicrm.settings.test.php above). This can also be set using the env command to change the environment just for a single command.

!!! warning Beware that if your tests change data in your CMS database (creating system users etc.) your local build will be affected when running tests.