Skip to content

Commit 9bb5376

Browse files
committed
Update test config in admin repos
1 parent 8fd17e0 commit 9bb5376

4 files changed

Lines changed: 147 additions & 58 deletions

File tree

admin/framework/phpunit.xml.dist

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,60 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="tests/_support/_bootstrap.php"
3-
backupGlobals="false"
4-
colors="true"
5-
convertErrorsToExceptions="true"
6-
convertNoticesToExceptions="true"
7-
convertWarningsToExceptions="true"
8-
stopOnError="false"
9-
stopOnFailure="false"
10-
stopOnIncomplete="false"
11-
stopOnSkipped="false">
12-
<testsuites>
13-
<testsuite name="app">
14-
<directory>./tests</directory>
15-
</testsuite>
16-
</testsuites>
17-
18-
<php>
19-
<env name="app.baseURL" value="http://example.com"/>
20-
</php>
2+
<phpunit bootstrap="system/Test/bootstrap.php"
3+
backupGlobals="false"
4+
colors="true"
5+
convertErrorsToExceptions="true"
6+
convertNoticesToExceptions="true"
7+
convertWarningsToExceptions="true"
8+
stopOnError="false"
9+
stopOnFailure="false"
10+
stopOnIncomplete="false"
11+
stopOnSkipped="false">
12+
<testsuites>
13+
<testsuite name="app">
14+
<directory>./tests</directory>
15+
</testsuite>
16+
</testsuites>
2117

18+
<filter>
19+
<whitelist addUncoveredFilesFromWhitelist="true" processUncoveredFilesFromWhitelist="true">
20+
<directory suffix=".php">./app</directory>
21+
<exclude>
22+
<directory suffix=".php">./app/Views</directory>
23+
<file>./app/Config/Routes.php</file>
24+
</exclude>
25+
</whitelist>
26+
</filter>
27+
28+
<logging>
29+
<log type="coverage-html" target="build/logs/html"/>
30+
<log type="coverage-clover" target="build/logs/clover.xml"/>
31+
<log type="coverage-php" target="build/logs/coverage.serialized"/>
32+
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false"/>
33+
<log type="testdox-html" target="build/logs/testdox.html"/>
34+
<log type="testdox-text" target="build/logs/testdox.txt"/>
35+
<log type="junit" target="build/logs/logfile.xml"/>
36+
</logging>
37+
38+
<php>
39+
<server name="app.baseURL" value="http://example.com"/>
40+
41+
<!-- Directory containing phpunit.xml -->
42+
<const name="HOMEPATH" value="./"/>
43+
44+
<!-- Directory containing the Paths config file -->
45+
<const name="CONFIGPATH" value="./app/Config/"/>
46+
47+
<!-- Directory containing the front controller (index.php) -->
48+
<const name="PUBLICPATH" value="./public/"/>
49+
50+
<!-- Database configuration -->
51+
<!-- <env name="database.tests.hostname" value="localhost"/> -->
52+
<!-- <env name="database.tests.database" value="tests"/> -->
53+
<!-- <env name="database.tests.username" value="tests_user"/> -->
54+
<!-- <env name="database.tests.password" value=""/> -->
55+
<!-- <env name="database.tests.DBDriver" value="MySQLi"/> -->
56+
<!-- <env name="database.tests.DBPrefix" value="tests_"/> -->
57+
<env name="database.tests.database" value=":memory:"/>
58+
<env name="database.tests.DBDriver" value="SQLite3"/>
59+
</php>
2260
</phpunit>

admin/starter/phpunit.xml.dist

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,60 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="tests/_support/_bootstrap.php"
3-
backupGlobals="false"
4-
colors="true"
5-
convertErrorsToExceptions="true"
6-
convertNoticesToExceptions="true"
7-
convertWarningsToExceptions="true"
8-
stopOnError="false"
9-
stopOnFailure="false"
10-
stopOnIncomplete="false"
11-
stopOnSkipped="false">
12-
<testsuites>
13-
<testsuite name="app">
14-
<directory>./tests</directory>
15-
</testsuite>
16-
</testsuites>
2+
<phpunit bootstrap="vendor/codeigniter4/framework/system/Test/bootstrap.php"
3+
backupGlobals="false"
4+
colors="true"
5+
convertErrorsToExceptions="true"
6+
convertNoticesToExceptions="true"
7+
convertWarningsToExceptions="true"
8+
stopOnError="false"
9+
stopOnFailure="false"
10+
stopOnIncomplete="false"
11+
stopOnSkipped="false">
12+
<testsuites>
13+
<testsuite name="app">
14+
<directory>./tests</directory>
15+
</testsuite>
16+
</testsuites>
1717

18-
<php>
19-
<env name="app.baseURL" value="http://example.com"/>
20-
</php>
18+
<filter>
19+
<whitelist addUncoveredFilesFromWhitelist="true" processUncoveredFilesFromWhitelist="true">
20+
<directory suffix=".php">./app</directory>
21+
<exclude>
22+
<directory suffix=".php">./app/Views</directory>
23+
<file>./app/Config/Routes.php</file>
24+
</exclude>
25+
</whitelist>
26+
</filter>
2127

28+
<logging>
29+
<log type="coverage-html" target="build/logs/html"/>
30+
<log type="coverage-clover" target="build/logs/clover.xml"/>
31+
<log type="coverage-php" target="build/logs/coverage.serialized"/>
32+
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false"/>
33+
<log type="testdox-html" target="build/logs/testdox.html"/>
34+
<log type="testdox-text" target="build/logs/testdox.txt"/>
35+
<log type="junit" target="build/logs/logfile.xml"/>
36+
</logging>
37+
38+
<php>
39+
<server name="app.baseURL" value="http://example.com"/>
40+
41+
<!-- Directory containing phpunit.xml -->
42+
<const name="HOMEPATH" value="./"/>
43+
44+
<!-- Directory containing the Paths config file -->
45+
<const name="CONFIGPATH" value="./app/Config/"/>
46+
47+
<!-- Directory containing the front controller (index.php) -->
48+
<const name="PUBLICPATH" value="./public/"/>
49+
50+
<!-- Database configuration -->
51+
<!-- <env name="database.tests.hostname" value="localhost"/> -->
52+
<!-- <env name="database.tests.database" value="tests"/> -->
53+
<!-- <env name="database.tests.username" value="tests_user"/> -->
54+
<!-- <env name="database.tests.password" value=""/> -->
55+
<!-- <env name="database.tests.DBDriver" value="MySQLi"/> -->
56+
<!-- <env name="database.tests.DBPrefix" value="tests_"/> -->
57+
<env name="database.tests.database" value=":memory:"/>
58+
<env name="database.tests.DBDriver" value="SQLite3"/>
59+
</php>
2260
</phpunit>

admin/starter/tests/README.md

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# Running System Tests
22

33
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.
4+
it takes to set up your application and get it ready to run unit tests.
55
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.
6+
use to test your application. Those details can be found in the documentation.
77

88
## Requirements
99

1010
It is recommended to use the latest version of PHPUnit. At the time of this
1111
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
12+
**composer.json** file that ships with CodeIgniter and can easily be installed
1313
via [Composer](https://getcomposer.org/) if you don't already have it installed globally.
1414

1515
> composer install
@@ -19,23 +19,24 @@ If running under OS X or Linux, you can create a symbolic link to make running t
1919
> ln -s ./vendor/bin/phpunit ./phpunit
2020

2121
You also need to install [XDebug](https://xdebug.org/index.php) in order
22-
for the unit tests to successfully complete.
22+
for code coverage to be calculated successfully.
2323

24-
## Setup
24+
## Setting Up
2525

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.
26+
A number of the tests use a running database.
27+
In order to set up the database edit the details for the `tests` group in
28+
**app/Config/Database.php** or **phpunit.xml**. Make sure that you provide a database engine
29+
that is currently running on your machine. More details on a test database setup are in the
30+
*Docs>>Testing>>Testing Your Database* section of the documentation.
3131

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.
32+
If you want to run the tests without using live database you can
33+
exclude @DatabaseLive group. Or make a copy of **phpunit.dist.xml** -
34+
call it **phpunit.xml** - and comment out the <testsuite> named "database". This will make
35+
the tests run quite a bit faster.
3536

3637
## Running the tests
3738

38-
The entire test suite can be ran by simply typing one command from the command line within the main directory.
39+
The entire test suite can be run by simply typing one command-line command from the main directory.
3940

4041
> ./phpunit
4142

@@ -51,9 +52,21 @@ you can use the following command:
5152

5253
> ./phpunit --colors --coverage-text=tests/coverage.txt --coverage-html=tests/coverage/ -d memory_limit=1024m
5354

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.
55+
This runs all of the tests again collecting information about how many lines,
56+
functions, and files are tested. It also reports the percentage of the code that is covered by tests.
57+
It is collected in two formats: a simple text file that provides an overview as well
58+
as a comprehensive collection of HTML files that show the status of every line of code in the project.
5859

59-
Code coverage details will be left in the **tests/coverage** folder.
60+
The text file can be found at **tests/coverage.txt**.
61+
The HTML files can be viewed by opening **tests/coverage/index.html** in your favorite browser.
62+
63+
## PHPUnit XML Configuration
64+
65+
The repository has a ``phpunit.xml.dist`` file in the project root that's used for
66+
PHPUnit configuration. This is used to provide a default configuration if you
67+
do not have your own configuration file in the project root.
68+
69+
The normal practice would be to copy ``phpunit.xml.dist`` to ``phpunit.xml``
70+
(which is git ignored), and to tailor it as you see fit.
71+
For instance, you might wish to exclude database tests, or automatically generate
72+
HTML code coverage reports.

tests/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ that is currently running on your machine. More details on a test database setup
3131

3232
If you want to run the tests without using live database you can
3333
exclude @DatabaseLive group. Or make a copy of **phpunit.dist.xml** -
34-
call it **phpunit.xml** - and uncomment the line within the <testsuite> that excludes
35-
the **tests/system/Database/Live** directory. This will make the tests run quite a bit faster.
34+
call it **phpunit.xml** - and comment out the <testsuite> named "database". This will make
35+
the tests run quite a bit faster.
3636

3737
## Running the tests
3838

0 commit comments

Comments
 (0)