Skip to content
This repository was archived by the owner on May 18, 2024. It is now read-only.

Commit 3b06f99

Browse files
committed
Move bootstrap to support folder for easy updates
1 parent 100dc52 commit 3b06f99

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ All tests go in the **tests/** directory. There are two generic subfolders for y
3333
test case:
3434
* For basic tests extend `CodeIgniter\Test\CIUnitTestCase`
3535
* For database tests extend `CIModuleTests\Support\DatabaseTestCase`
36+
* For session tests extend `CIModuleTests\Support\SessionTestCase`
3637

3738
Tests are individual methods within each file. Method names must start with the word "test":
3839
`testUserSync()` `testOutputColor()` `testFooBar()`
@@ -50,3 +51,31 @@ steps in `setUp()`.
5051

5152
Similarly there is a pre-configured test case available with a mock session configured to
5253
make testing sessions easy: **tests/_support/SessionTestCase.php**.
54+
55+
## Code Coverage
56+
57+
**CIModuleTests** comes preconfigured to run code coverage as part of the testing. You will
58+
need to have a code coverage driver installed to use this feature, such as
59+
[Xdebug](https://xdebug.org). **CIModuleTests** assumes your source code is in **src/**;
60+
if your code is somewhere else then modify the following line in **phpunit.xml.dist** :
61+
```
62+
<directory suffix=".php">./src</directory>
63+
```
64+
Other common modifications would be removing the attributes from the whitelist element:
65+
```
66+
<whitelist addUncoveredFilesFromWhitelist="true" processUncoveredFilesFromWhitelist="true">
67+
```
68+
... and adjusting the output location and format of the coverage reports:
69+
```
70+
<logging>
71+
<log type="coverage-clover" target="build/logs/clover.xml"/>
72+
<log type="coverage-html" target="build/logs/html"/>
73+
<log type="coverage-text" target="php://stdout" showUncoveredFiles="true"/>
74+
</logging>
75+
```
76+
77+
## Updating
78+
79+
As this repo is updated with bugfixes and improvements you will want to update the code
80+
merged into your modules. Because tests need to be top-level and should not include their
81+
own repository info you will need to handle updates manually.

src/phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="tests/bootstrap.php"
2+
<phpunit bootstrap="tests/_support/bootstrap.php"
33
backupGlobals="false"
44
colors="true"
55
convertErrorsToExceptions="true"

src/tests/bootstrap.php renamed to src/tests/_support/bootstrap.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
define('ENVIRONMENT', 'testing');
1111

1212
// Load our paths config file
13-
require __DIR__ . '/../vendor/codeigniter4/codeigniter4/app/Config/Paths.php';
13+
require __DIR__ . '/../../vendor/codeigniter4/codeigniter4/app/Config/Paths.php';
1414
$paths = new Config\Paths();
1515

1616
// Define necessary framework path constants
@@ -21,9 +21,9 @@
2121
define('WRITEPATH', realpath($paths->writableDirectory) . DIRECTORY_SEPARATOR);
2222

2323
// Define necessary module test path constants
24-
define('MODULEPATH', realpath(__DIR__ . '/../') . DIRECTORY_SEPARATOR);
25-
define('TESTPATH', realpath(__DIR__) . DIRECTORY_SEPARATOR);
26-
define('SUPPORTPATH', realpath(TESTPATH . '_support/') . DIRECTORY_SEPARATOR);
24+
define('SUPPORTPATH', realpath(__DIR__) . DIRECTORY_SEPARATOR);
25+
define('TESTPATH', realpath(SUPPORTPATH . '../') . DIRECTORY_SEPARATOR);
26+
define('MODULEPATH', realpath(__DIR__ . '/../../') . DIRECTORY_SEPARATOR);
2727
define('COMPOSER_PATH', MODULEPATH . 'vendor/autoload.php');
2828

2929
// Set environment values that would otherwise stop the framework from functioning during tests.

0 commit comments

Comments
 (0)