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

Commit 57a1e1e

Browse files
authored
Merge pull request #8 from codeigniter4projects/develop
Update master for release
2 parents 18a930a + dc1853d commit 57a1e1e

File tree

6 files changed

+51
-13
lines changed

6 files changed

+51
-13
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 MGatner
3+
Copyright (c) 2019 CodeIgniter Foundation
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ PHPUnit testing scaffold for CodeIgniter 4 modules
55
## Overview
66

77
Not a module itself but a testing scaffold for CodeIgniter 4 modules,
8-
**module-tests** makes it easy to setup PHPUnit tests in your modules.
8+
**ModuleTests** makes it easy to setup PHPUnit tests in your modules.
99

1010
To read more on Unit Testing in CodeIgniter 4 visit the
1111
[User Guide](https://codeigniter4.github.io/userguide/testing/index.html).
@@ -53,6 +53,23 @@ composer.lock
5353
Examples of **composer.json** and **.gitignore** are located in the [examples/](examples/)
5454
folder if you need a starting point.
5555

56+
### Paths
57+
58+
A number of framework and testing path are defined as constants during the
59+
[bootstrap process](src/tests/_support/bootstrap.php). These default to the assumed locations
60+
if you have a standard directory structure. If you move directories around you will need to
61+
review these paths and set them appropriately.
62+
63+
* **APPPATH**: `$paths->appDirectory`
64+
* **ROOTPATH**: `APPPATH . '../'`
65+
* **FCPATH**: `ROOTPATH . 'public/'`
66+
* **WRITEPATH**: `$paths->writableDirectory`
67+
* **SYSTEMPATH**: `$paths->systemDirectory`
68+
* **CIPATH**: `SYSTEMPATH . '../`
69+
* **SUPPORTPATH**: `CIPATH . 'tests/_support/`
70+
* **PROJECTSUPPORTPATH**: *bootstrap.php directory*
71+
* **TESTPATH**: `PROJECTSUPPORTPATH . '../`
72+
5673
## Updating
5774

5875
As this repo is updated with bugfixes and improvements you will want to update your
@@ -74,3 +91,10 @@ in **build/logs/**.
7491
## Code Coverage
7592

7693
See the docs on [Code Coverage](docs/COVERAGE.md).
94+
95+
## Project Testing
96+
97+
**ModuleTests** is designed to be added to your modular library which will be included into
98+
other CodeIgniter 4 projects. If you are looking for a testing scaffold for applications
99+
built using CodeIgniter 4 as their core framework, check out
100+
[Codeigniter4Projects/ProjectTests](https://github.com/codeigniter4projects/project-tests).

docs/COVERAGE.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55
66
## Overview
77

8-
**ci4-module-tests** comes preconfigured to handle code coverage in addition to the unit tests.
8+
**ModuleTests** comes preconfigured to handle code coverage in addition to the unit tests.
99
You will need to have a code coverage driver installed to use this feature, such as
1010
[Xdebug](https://xdebug.org).
1111

1212
## Setup
1313

14-
**ci4-module-tests** assumes your source code is in **src/**; if your code is somewhere else
14+
**ModuleTests** assumes your source code is in **src/**; if your code is somewhere else
1515
then you will need to modify the following line in your PHPUnit XML file:
1616
```
1717
<directory suffix=".php">./src</directory>
1818
```
1919

2020
## PHPUnit.xml
2121

22-
**ci4-module-tests** includes a ready-to-use PHPUnit template in **phpunit.xml.dist**.
22+
**ModuleTests** includes a ready-to-use PHPUnit template in **phpunit.xml.dist**.
2323
Common practice is to create a local copy of this file as **phpunit.xml** and add any
2424
sensitive or environment info (like database connections). Prevent **phpunit.xml** from
2525
being tracked in your repo by adding it to **.gitignore**.
@@ -30,7 +30,7 @@ being tracked in your repo by adding it to **.gitignore**.
3030

3131
In addition to the code source mentioned above, PHPUnit can be configured to exclude files
3232
that are not relevant to testing or would otherwise cause the coverage calculations to fail.
33-
**ci4-module-tests** starts with a few files common to CodeIgniter 4 but you may need to add
33+
**ModuleTests** starts with a few files common to CodeIgniter 4 but you may need to add
3434
your own:
3535
```
3636
<exclude>

examples/composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@
2727
"php" : ">=7.2"
2828
},
2929
"require-dev": {
30-
"phpunit/phpunit" : "^7.0",
30+
"codeigniter4/codeigniter4": "dev-develop",
31+
"mikey179/vfsstream": "1.6.*",
3132
"mockery/mockery": "^1.0",
32-
"codeigniter4/codeigniter4": "dev-develop"
33+
"phpunit/phpunit" : "^7.0"
3334
},
3435
"autoload": {
3536
"psr-4": {

src/tests/_support/Database/Migrations/2019-09-02-092335_create_test_tables.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
class CreateTestTables extends Migration
66
{
7+
protected $DBGroup = 'tests';
8+
79
public function up()
810
{
911
$fields = [

src/tests/_support/bootstrap.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,25 @@
1717
define('APPPATH', realpath($paths->appDirectory) . DIRECTORY_SEPARATOR);
1818
define('ROOTPATH', realpath(APPPATH . '../') . DIRECTORY_SEPARATOR);
1919
define('FCPATH', realpath(ROOTPATH . 'public') . DIRECTORY_SEPARATOR);
20-
define('SYSTEMPATH', realpath($paths->systemDirectory) . DIRECTORY_SEPARATOR);
2120
define('WRITEPATH', realpath($paths->writableDirectory) . DIRECTORY_SEPARATOR);
21+
define('SYSTEMPATH', realpath($paths->systemDirectory) . DIRECTORY_SEPARATOR);
22+
define('CIPATH', realpath(SYSTEMPATH . '../') . DIRECTORY_SEPARATOR);
23+
define('SUPPORTPATH', realpath(CIPATH . 'tests/_support') . DIRECTORY_SEPARATOR);
2224

2325
// Define necessary module test path constants
24-
define('SUPPORTPATH', realpath(__DIR__) . DIRECTORY_SEPARATOR);
25-
define('TESTPATH', realpath(SUPPORTPATH . '../') . DIRECTORY_SEPARATOR);
26-
define('MODULEPATH', realpath(__DIR__ . '/../../') . DIRECTORY_SEPARATOR);
27-
define('COMPOSER_PATH', MODULEPATH . 'vendor/autoload.php');
26+
define('MODULESUPPORTPATH', realpath(__DIR__) . DIRECTORY_SEPARATOR);
27+
define('TESTPATH', realpath(MODULESUPPORTPATH . '../') . DIRECTORY_SEPARATOR);
28+
define('MODULEPATH', realpath(__DIR__ . '/../../') . DIRECTORY_SEPARATOR);
29+
define('COMPOSER_PATH', MODULEPATH . 'vendor/autoload.php');
30+
31+
// Let's see if an app/Common.php file exists
32+
if (file_exists(APPPATH . 'Common.php'))
33+
{
34+
require_once APPPATH . 'Common.php';
35+
}
36+
37+
// Require system/Common.php
38+
require_once SYSTEMPATH . 'Common.php';
2839

2940
// Set environment values that would otherwise stop the framework from functioning during tests.
3041
if (! isset($_SERVER['app.baseURL']))

0 commit comments

Comments
 (0)