|
| 1 | +# Running System Tests |
| 2 | + |
| 3 | +This is the quick-start to CodeIgniter testing. Its intent is to describe what |
| 4 | +it takes to get your system setup and ready to run the system tests. |
| 5 | +It is not intended to be a full description of the test features that you can |
| 6 | +use to test your application, since that can be found in the documentation. |
| 7 | + |
| 8 | +## Requirements |
| 9 | + |
| 10 | +It is recommended to use the latest version of PHPUnit. At the time of this |
| 11 | +writing we are running version 7.5.1. Support for this has been built into the |
| 12 | +**composer.json** file that ships with CodeIgniter, and can easily be installed |
| 13 | +via [Composer](https://getcomposer.org/) if you don't already have it installed globally. |
| 14 | + |
| 15 | + > composer install |
| 16 | + |
| 17 | +If running under OS X or Linux, you can create a symbolic link to make running tests a touch nicer. |
| 18 | + |
| 19 | + > ln -s ./vendor/bin/phpunit ./phpunit |
| 20 | + |
| 21 | +You also need to install [XDebug](https://xdebug.org/index.php) in order |
| 22 | +for the unit tests to successfully complete. |
| 23 | + |
| 24 | +## Setup |
| 25 | + |
| 26 | +A number of the tests that are ran during the test suite are ran against a running database. |
| 27 | +In order to setup the database used here, edit the details for the `tests` database |
| 28 | +group in **app/Config/Database.php**. Make sure that you provide a database engine |
| 29 | +that is currently running, and have already created a table that you can use only |
| 30 | +for these tests, as it will be wiped and refreshed often while running the test suite. |
| 31 | + |
| 32 | +A simplified PHPunit configuration file, **phpunit.dist.xml**, is provided. |
| 33 | +You can use it as is, or copy it to **phpunit.xml**, and tailor it to suit your |
| 34 | +application. |
| 35 | + |
| 36 | +## Running the tests |
| 37 | + |
| 38 | +The entire test suite can be ran by simply typing one command from the command line within the main directory. |
| 39 | + |
| 40 | + > ./phpunit |
| 41 | + |
| 42 | +You can limit tests to those within a single test directory by specifying the |
| 43 | +directory name after phpunit. |
| 44 | + |
| 45 | + > ./phpunit app/Models |
| 46 | + |
| 47 | +## Generating Code Coverage |
| 48 | + |
| 49 | +To generate coverage information, including HTML reports you can view in your browser, |
| 50 | +you can use the following command: |
| 51 | + |
| 52 | + > ./phpunit --colors --coverage-text=tests/coverage.txt --coverage-html=tests/coverage/ -d memory_limit=1024m |
| 53 | + |
| 54 | +This runs all of the tests again, collecting information about how many lines, |
| 55 | +functions, and files are tested, and the percent of the code that is covered by the tests. |
| 56 | +It is collected in two formats: a simple text file that provides an overview, |
| 57 | +as well as comprehensive collection of HTML files that show the status of every line of code in the project. |
| 58 | + |
| 59 | +Code coverage details will be left in the **tests/coverage** folder. |
0 commit comments