Update test config in admin repos

This commit is contained in:
Matt Gatner 2020-02-20 21:47:49 +00:00
parent 8fd17e0f8f
commit 9bb537661f
No known key found for this signature in database
GPG Key ID: 98F2DFA2FF210CCC
4 changed files with 147 additions and 58 deletions

View File

@ -1,22 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="tests/_support/_bootstrap.php"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false">
<testsuites>
<testsuite name="app">
<directory>./tests</directory>
</testsuite>
</testsuites>
<php>
<env name="app.baseURL" value="http://example.com"/>
</php>
<phpunit bootstrap="system/Test/bootstrap.php"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false">
<testsuites>
<testsuite name="app">
<directory>./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true" processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
<exclude>
<directory suffix=".php">./app/Views</directory>
<file>./app/Config/Routes.php</file>
</exclude>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="build/logs/html"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<log type="coverage-php" target="build/logs/coverage.serialized"/>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false"/>
<log type="testdox-html" target="build/logs/testdox.html"/>
<log type="testdox-text" target="build/logs/testdox.txt"/>
<log type="junit" target="build/logs/logfile.xml"/>
</logging>
<php>
<server name="app.baseURL" value="http://example.com"/>
<!-- Directory containing phpunit.xml -->
<const name="HOMEPATH" value="./"/>
<!-- Directory containing the Paths config file -->
<const name="CONFIGPATH" value="./app/Config/"/>
<!-- Directory containing the front controller (index.php) -->
<const name="PUBLICPATH" value="./public/"/>
<!-- Database configuration -->
<!-- <env name="database.tests.hostname" value="localhost"/> -->
<!-- <env name="database.tests.database" value="tests"/> -->
<!-- <env name="database.tests.username" value="tests_user"/> -->
<!-- <env name="database.tests.password" value=""/> -->
<!-- <env name="database.tests.DBDriver" value="MySQLi"/> -->
<!-- <env name="database.tests.DBPrefix" value="tests_"/> -->
<env name="database.tests.database" value=":memory:"/>
<env name="database.tests.DBDriver" value="SQLite3"/>
</php>
</phpunit>

View File

@ -1,22 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="tests/_support/_bootstrap.php"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false">
<testsuites>
<testsuite name="app">
<directory>./tests</directory>
</testsuite>
</testsuites>
<phpunit bootstrap="vendor/codeigniter4/framework/system/Test/bootstrap.php"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false">
<testsuites>
<testsuite name="app">
<directory>./tests</directory>
</testsuite>
</testsuites>
<php>
<env name="app.baseURL" value="http://example.com"/>
</php>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true" processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
<exclude>
<directory suffix=".php">./app/Views</directory>
<file>./app/Config/Routes.php</file>
</exclude>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="build/logs/html"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<log type="coverage-php" target="build/logs/coverage.serialized"/>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false"/>
<log type="testdox-html" target="build/logs/testdox.html"/>
<log type="testdox-text" target="build/logs/testdox.txt"/>
<log type="junit" target="build/logs/logfile.xml"/>
</logging>
<php>
<server name="app.baseURL" value="http://example.com"/>
<!-- Directory containing phpunit.xml -->
<const name="HOMEPATH" value="./"/>
<!-- Directory containing the Paths config file -->
<const name="CONFIGPATH" value="./app/Config/"/>
<!-- Directory containing the front controller (index.php) -->
<const name="PUBLICPATH" value="./public/"/>
<!-- Database configuration -->
<!-- <env name="database.tests.hostname" value="localhost"/> -->
<!-- <env name="database.tests.database" value="tests"/> -->
<!-- <env name="database.tests.username" value="tests_user"/> -->
<!-- <env name="database.tests.password" value=""/> -->
<!-- <env name="database.tests.DBDriver" value="MySQLi"/> -->
<!-- <env name="database.tests.DBPrefix" value="tests_"/> -->
<env name="database.tests.database" value=":memory:"/>
<env name="database.tests.DBDriver" value="SQLite3"/>
</php>
</phpunit>

View File

@ -1,15 +1,15 @@
# Running System Tests
This is the quick-start to CodeIgniter testing. Its intent is to describe what
it takes to get your system setup and ready to run the system tests.
it takes to set up your application and get it ready to run unit tests.
It is not intended to be a full description of the test features that you can
use to test your application, since that can be found in the documentation.
use to test your application. Those details can be found in the documentation.
## Requirements
It is recommended to use the latest version of PHPUnit. At the time of this
writing we are running version 7.5.1. Support for this has been built into the
**composer.json** file that ships with CodeIgniter, and can easily be installed
**composer.json** file that ships with CodeIgniter and can easily be installed
via [Composer](https://getcomposer.org/) if you don't already have it installed globally.
> composer install
@ -19,23 +19,24 @@ If running under OS X or Linux, you can create a symbolic link to make running t
> ln -s ./vendor/bin/phpunit ./phpunit
You also need to install [XDebug](https://xdebug.org/index.php) in order
for the unit tests to successfully complete.
for code coverage to be calculated successfully.
## Setup
## Setting Up
A number of the tests that are ran during the test suite are ran against a running database.
In order to setup the database used here, edit the details for the `tests` database
group in **app/Config/Database.php**. Make sure that you provide a database engine
that is currently running, and have already created a table that you can use only
for these tests, as it will be wiped and refreshed often while running the test suite.
A number of the tests use a running database.
In order to set up the database edit the details for the `tests` group in
**app/Config/Database.php** or **phpunit.xml**. Make sure that you provide a database engine
that is currently running on your machine. More details on a test database setup are in the
*Docs>>Testing>>Testing Your Database* section of the documentation.
A simplified PHPunit configuration file, **phpunit.dist.xml**, is provided.
You can use it as is, or copy it to **phpunit.xml**, and tailor it to suit your
application.
If you want to run the tests without using live database you can
exclude @DatabaseLive group. Or make a copy of **phpunit.dist.xml** -
call it **phpunit.xml** - and comment out the <testsuite> named "database". This will make
the tests run quite a bit faster.
## Running the tests
The entire test suite can be ran by simply typing one command from the command line within the main directory.
The entire test suite can be run by simply typing one command-line command from the main directory.
> ./phpunit
@ -51,9 +52,21 @@ you can use the following command:
> ./phpunit --colors --coverage-text=tests/coverage.txt --coverage-html=tests/coverage/ -d memory_limit=1024m
This runs all of the tests again, collecting information about how many lines,
functions, and files are tested, and the percent of the code that is covered by the tests.
It is collected in two formats: a simple text file that provides an overview,
as well as comprehensive collection of HTML files that show the status of every line of code in the project.
This runs all of the tests again collecting information about how many lines,
functions, and files are tested. It also reports the percentage of the code that is covered by tests.
It is collected in two formats: a simple text file that provides an overview as well
as a comprehensive collection of HTML files that show the status of every line of code in the project.
Code coverage details will be left in the **tests/coverage** folder.
The text file can be found at **tests/coverage.txt**.
The HTML files can be viewed by opening **tests/coverage/index.html** in your favorite browser.
## PHPUnit XML Configuration
The repository has a ``phpunit.xml.dist`` file in the project root that's used for
PHPUnit configuration. This is used to provide a default configuration if you
do not have your own configuration file in the project root.
The normal practice would be to copy ``phpunit.xml.dist`` to ``phpunit.xml``
(which is git ignored), and to tailor it as you see fit.
For instance, you might wish to exclude database tests, or automatically generate
HTML code coverage reports.

View File

@ -31,8 +31,8 @@ that is currently running on your machine. More details on a test database setup
If you want to run the tests without using live database you can
exclude @DatabaseLive group. Or make a copy of **phpunit.dist.xml** -
call it **phpunit.xml** - and uncomment the line within the <testsuite> that excludes
the **tests/system/Database/Live** directory. This will make the tests run quite a bit faster.
call it **phpunit.xml** - and comment out the <testsuite> named "database". This will make
the tests run quite a bit faster.
## Running the tests