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

Commit 17f28d2

Browse files
committed
Update references for Projects
1 parent 091a67a commit 17f28d2

File tree

11 files changed

+47
-38
lines changed

11 files changed

+47
-38
lines changed

README.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# ModuleTests
1+
# ProjectTests
22

3-
PHPUnit testing scaffold for CodeIgniter 4 modules
3+
PHPUnit testing scaffold for CodeIgniter 4 projects
44

55
## Overview
66

7-
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.
7+
Not a module itself but a testing scaffold for CodeIgniter 4 projects,
8+
**ProjectTests** makes it easy to setup PHPUnit tests in your projects.
99

1010
To read more on Unit Testing in CodeIgniter 4 visit the
1111
[User Guide](https://codeigniter4.github.io/userguide/testing/index.html).
@@ -29,7 +29,7 @@ project root. Add the following lines to **composer.json**:
2929
},
3030
"autoload-dev": {
3131
"psr-4": {
32-
"ModuleTests\\Support\\": "tests/_support"
32+
"ProjectTests\\Support\\": "tests/_support"
3333
}
3434
},
3535
"scripts": {
@@ -56,7 +56,7 @@ folder if you need a starting point.
5656
## Updating
5757

5858
As this repo is updated with bugfixes and improvements you will want to update your
59-
modules that use it. Because files need to be copied in place manually you will have to
59+
projects that use it. Because files need to be copied in place manually you will have to
6060
handle updates manually by cloning or downloading this repo and merging changed files
6161
into your project. "Watch" this repo to be notified of new releases and changes.
6262

@@ -74,3 +74,10 @@ in **build/logs/**.
7474
## Code Coverage
7575

7676
See the docs on [Code Coverage](docs/COVERAGE.md).
77+
78+
## Module Testing
79+
80+
**ProjectTests** is designed to be added to applications using CodeIgniter 4 as their core
81+
framework. If you are looking for a testing scaffold for your modular library intended to
82+
be included into other project, check out
83+
[Codeigniter4Projects/ModuleTests](https://github.com/codeigniter4projects/module-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+
**ProjectTests** 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+
**ProjectTests** 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+
**ProjectTests** 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+
**ProjectTests** starts with a few files common to CodeIgniter 4 but you may need to add
3434
your own:
3535
```
3636
<exclude>

docs/CREATING.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,28 @@ provides a few that you may use directly:
1212
* `CodeIgniter\Test\CIUnitTestCase` - for basic tests with no other service needs
1313
* `CodeIgniter\Test\CIDatabaseTestCase` - for tests that need database access
1414

15-
**ModuleTests** also provides some examples:
16-
* `ModuleTests\Support\DatabaseTestCase` - for database tests, pre-configured for migrations, seeds, and models from **tests/_support**
17-
* `ModuleTests\Support\SessionTestCase` - for session tests, pre-configured with a mock session driver
15+
**ProjectTests** also provides some examples:
16+
* `ProjectTests\Support\DatabaseTestCase` - for database tests, pre-configured for migrations, seeds, and models from **tests/_support**
17+
* `ProjectTests\Support\SessionTestCase` - for session tests, pre-configured with a mock session driver
1818

1919
Most of the time you will want to write your own test cases to hold functions and services
2020
common to your test suites.
2121

2222
## Tests
2323

24-
All tests go in the **tests/** directory. **ModuleTests** provides two generic
25-
subfolders for you, **unit** and **database** - but feel free to make your own. Each test file
26-
is a class that extends a **Test Case** (see above) and contains methods for the individual
27-
tests. These method names must start with the word "test" and should have descriptive names
28-
for precisely what they are testing: `testUserCanModifyFile()` `testOutputColorMatchesInput()`
29-
`testIsLoggedInFailsWithInvalidUser()`
24+
All tests go in the **tests/** directory. **ProjectTests** provides some generic
25+
subfolders for you (**unit**, **session**, and **database**) - but feel free to make your
26+
own. Each test file is a class that extends a **Test Case** (see above) and contains methods
27+
for the individual tests. These method names must start with the word "test" and should
28+
have descriptive names for precisely what they are testing:
29+
`testUserCanModifyFile()` `testOutputColorMatchesInput()` `testIsLoggedInFailsWithInvalidUser()`
3030

3131
Writing tests is an art, and there are many resources available to help learn how. Review
3232
the links above and always pay attention to your [Code Coverage](docs/COVERAGE.md).
3333

3434
### Database Tests
3535

36-
**ModuleTests** provides examples for migrating, seeding, and testing against a mock
36+
**ProjectTests** provides examples for migrating, seeding, and testing against a mock
3737
or live<sup>1</sup> database. The example files can be modified or replaced with your own:
3838
* **tests/_support/Database/Migrations/create_test_tables.php**
3939
* **tests/_support/Database/Seeds/ExampleSeeder.php**
@@ -50,7 +50,7 @@ repo by adding it to **.gitignore**.
5050

5151
### Session Tests
5252

53-
Similar to database testing, **ModuleTests** provides a test case pre-configured
53+
Similar to database testing, **ProjectTests** provides a test case pre-configured
5454
with the [mock session class](https://codeigniter4.github.io/userguide/testing/overview.html#mocking-services)
5555
to make testing sessions easier:
5656
* **tests/_support/SessionTestCase.php**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php namespace ModuleTests\Support\Database\Migrations;
1+
<?php namespace ProjectTests\Support\Database\Migrations;
22

33
use CodeIgniter\Database\Migration;
44

src/tests/_support/Database/Seeds/ExampleSeeder.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
<?php namespace ModuleTests\Support\Database\Seeds;
1+
<?php namespace ProjectTests\Support\Database\Seeds;
22

3-
class ExampleSeeder extends \CodeIgniter\Database\Seeder
3+
use CodeIgniter\Database\Seeder;
4+
5+
class ExampleSeeder extends Seeder
46
{
57
public function run()
68
{

src/tests/_support/DatabaseTestCase.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php namespace ModuleTests\Support;
1+
<?php namespace ProjectTests\Support;
22

33
class DatabaseTestCase extends \CodeIgniter\Test\CIDatabaseTestCase
44
{
@@ -14,7 +14,7 @@ class DatabaseTestCase extends \CodeIgniter\Test\CIDatabaseTestCase
1414
*
1515
* @var string
1616
*/
17-
protected $seed = 'ModuleTests\Support\Database\Seeds\ExampleSeeder';
17+
protected $seed = 'ProjectTests\Support\Database\Seeds\ExampleSeeder';
1818

1919
/**
2020
* The path to where we can find the test Seeds directory.
@@ -28,7 +28,7 @@ class DatabaseTestCase extends \CodeIgniter\Test\CIDatabaseTestCase
2828
*
2929
* @var string
3030
*/
31-
protected $namespace = 'ModuleTests\Support';
31+
protected $namespace = 'ProjectTests\Support';
3232

3333
public function setUp(): void
3434
{

src/tests/_support/Models/ExampleModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php namespace ModuleTests\Support\Models;
1+
<?php namespace ProjectTests\Support\Models;
22

33
use CodeIgniter\Model;
44

src/tests/_support/SessionTestCase.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
<?php namespace ModuleTests\Support;
1+
<?php namespace ProjectTests\Support;
22

3+
use CodeIgniter\Test\CIUnitTestCase;
34
use CodeIgniter\Session\Handlers\ArrayHandler;
45
use Tests\Support\Session\MockSession;
56

6-
class SessionTestCase extends \CodeIgniter\Test\CIUnitTestCase
7+
class SessionTestCase extends CIUnitTestCase
78
{
89
/**
910
* @var SessionHandler
@@ -24,7 +25,7 @@ public function setUp(): void
2425
*/
2526
protected function mockSession()
2627
{
27-
require_once ROOTPATH . 'tests/_support/Session/MockSession.php';
28+
require_once CIPATH . 'tests/_support/Session/MockSession.php';
2829
$config = config('App');
2930
$this->session = new MockSession(new ArrayHandler($config, '0.0.0.0'), $config);
3031
\Config\Services::injectMock('session', $this->session);

src/tests/_support/bootstrap.php

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

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

1616
// Define necessary framework path constants
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);
2223

2324
// Define necessary module test path constants
2425
define('SUPPORTPATH', realpath(__DIR__) . DIRECTORY_SEPARATOR);
2526
define('TESTPATH', realpath(SUPPORTPATH . '../') . DIRECTORY_SEPARATOR);
26-
define('MODULEPATH', realpath(__DIR__ . '/../../') . DIRECTORY_SEPARATOR);
27-
define('COMPOSER_PATH', MODULEPATH . 'vendor/autoload.php');
2827

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

src/tests/database/ExampleDatabaseTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
class ExampleDatabaseTest extends ModuleTests\Support\DatabaseTestCase
3+
class ExampleDatabaseTest extends ProjectTests\Support\DatabaseTestCase
44
{
55
public function setUp(): void
66
{
@@ -9,7 +9,7 @@ public function setUp(): void
99

1010
public function testDatabaseSimple()
1111
{
12-
$model = new \ModuleTests\Support\Models\ExampleModel();
12+
$model = new \ProjectTests\Support\Models\ExampleModel();
1313

1414
$objects = $model->findAll();
1515

src/tests/session/ExampleSessionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
class ExampleSessionTest extends ModuleTests\Support\SessionTestCase
3+
class ExampleSessionTest extends ProjectTests\Support\SessionTestCase
44
{
55
public function setUp(): void
66
{

0 commit comments

Comments
 (0)