EE Unit Tests is an Add-on for ExpressionEngine that allows developers to execute unit tests from the Command Line. EE Unit Tests uses PHPUnit 9 out of the box though, in theory, you should be able to use whatever version you want.
- ExpressionEngine >= 6.1
- PHP 7.3
To get EE Unit Tests working simply:
- Install this Git repo
- Run
composer installwithin theunit_testsdirectory (where thecomposer.jsonfile is located. - Write your tests
EE Unit Tests is middleware between ExpressionEngine and your unit tests that you execute through ExpressionEngine's Command Line tool (introduced in 6.1).
This will execute the Tests within the unit_tests add-on.
php ./system/eecli.php tests:run -a your_addon_name
The below will display the available tests on the system
php ./system/eecli.php tests:list
So, previously, to run unit tests on ExpressionEngine code was cumbersome (at best). We're talking bootstraps, code runners, database instantiation, raw CodeIgniter, the list goes on. And this was PER PROJECT.
But, with release of 6.1, we got Command Line tools! Which handles all the rigamarole of setting all the bootstrap and environment up. So, yeah, just a silly little pass through thing here is all that's needed.
PHPUnit unit tests will be automatically detected within any tests directories stored in your add-on's root directory. For example, unit_tests/tests would be automatically picked up.
You can also configure a specific directory, relative to your add-on directory, within your addon.setup.php file, using the tests key.
The biggest problem is that there isn't any Command Line Options Support for configuration. Too much. Not worth it. Instead, be sure to use a phpunit.xml configuration file stored within your Tests root directory.