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

Rename to ModuleTests #3

Merged
merged 5 commits into from
Sep 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# ci4-module-tests
# ModuleTests

PHPUnit testing scaffold for CodeIgniter 4 modules

## Overview

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

To read more on Unit Testing in CodeIgniter 4 visit the
[User Guide](https://codeigniter4.github.io/userguide/testing/index.html).
Expand All @@ -29,7 +29,7 @@ project root. Add the following lines to **composer.json**:
},
"autoload-dev": {
"psr-4": {
"CIModuleTests\\Support\\": "tests/_support"
"ModuleTests\\Support\\": "tests/_support"
}
},
"scripts": {
Expand Down
12 changes: 6 additions & 6 deletions docs/CREATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ provides a few that you may use directly:
* `CodeIgniter\Test\CIUnitTestCase` - for basic tests with no other service needs
* `CodeIgniter\Test\CIDatabaseTestCase` - for tests that need database access

**ci-module-tests** also provides some examples:
* `CIModuleTests\Support\DatabaseTestCase` - for database tests, pre-configured for migrations, seeds, and models from **tests/_support**
* `CIModuleTests\Support\SessionTestCase` - for session tests, pre-configured with a mock session driver
**ModuleTests** also provides some examples:
* `ModuleTests\Support\DatabaseTestCase` - for database tests, pre-configured for migrations, seeds, and models from **tests/_support**
* `ModuleTests\Support\SessionTestCase` - for session tests, pre-configured with a mock session driver

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

## Tests

All tests go in the **tests/** directory. **ci-module-tests** provides two generic
All tests go in the **tests/** directory. **ModuleTests** provides two generic
subfolders for you, **unit** and **database** - but feel free to make your own. Each test file
is a class that extends a **Test Case** (see above) and contains methods for the individual
tests. These method names must start with the word "test" and should have descriptive names
Expand All @@ -33,7 +33,7 @@ the links above and always pay attention to your [Code Coverage](docs/COVERAGE.m

### Database Tests

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

### Session Tests

Similar to database testing, **ci-module-tests** provides a test case pre-configured
Similar to database testing, **ModuleTests** provides a test case pre-configured
with the [mock session class](https://codeigniter4.github.io/userguide/testing/overview.html#mocking-services)
to make testing sessions easier:
* **tests/_support/SessionTestCase.php**
3 changes: 1 addition & 2 deletions examples/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"require-dev": {
"phpunit/phpunit" : "^7.0",
"mockery/mockery": "^1.0",
"mgatner/ci-module-tests": "^1.0",
"codeigniter4/codeigniter4": "dev-develop"
},
"autoload": {
Expand All @@ -39,7 +38,7 @@
},
"autoload-dev": {
"psr-4": {
"CIModuleTests\\Support\\": "tests/_support"
"ModuleTests\\Support\\": "tests/_support"
}
},
"scripts": {
Expand Down
64 changes: 32 additions & 32 deletions src/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
<?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="all">
<directory>./tests</directory>
</testsuite>
</testsuites>
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false">
<testsuites>
<testsuite name="all">
<directory>./tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist addUncoveredFilesFromWhitelist="true" processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
<exclude>
<directory suffix=".php">./src/Views</directory>
<file>./src/Config/Routes.php</file>
</exclude>
</whitelist>
</filter>
<logging>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true" processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
<exclude>
<directory suffix=".php">./src/Views</directory>
<file>./src/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>
</logging>

<php>
<php>
<env name="app.baseURL" value="http://example.com"/>
<env name="CI_ENVIRONMENT" value="testing"/>
<!-- <env name="database.tests.hostname" value="localhost"/> -->
<!-- <env name="database.tests.database" value="tests"/> -->
<!-- <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.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>
</php>
</phpunit>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php namespace CIModuleTests\Support\Database\Migrations;
<?php namespace ModuleTests\Support\Database\Migrations;

use CodeIgniter\Database\Migration;

Expand Down
2 changes: 1 addition & 1 deletion src/tests/_support/Database/Seeds/ExampleSeeder.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php namespace CIModuleTests\Support\Database\Seeds;
<?php namespace ModuleTests\Support\Database\Seeds;

class ExampleSeeder extends \CodeIgniter\Database\Seeder
{
Expand Down
6 changes: 3 additions & 3 deletions src/tests/_support/DatabaseTestCase.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php namespace CIModuleTests\Support;
<?php namespace ModuleTests\Support;

class DatabaseTestCase extends \CodeIgniter\Test\CIDatabaseTestCase
{
Expand All @@ -14,7 +14,7 @@ class DatabaseTestCase extends \CodeIgniter\Test\CIDatabaseTestCase
*
* @var string
*/
protected $seed = 'CIModuleTests\Support\Database\Seeds\ExampleSeeder';
protected $seed = 'ModuleTests\Support\Database\Seeds\ExampleSeeder';

/**
* The path to where we can find the test Seeds directory.
Expand All @@ -28,7 +28,7 @@ class DatabaseTestCase extends \CodeIgniter\Test\CIDatabaseTestCase
*
* @var string
*/
protected $namespace = 'CIModuleTests\Support';
protected $namespace = 'ModuleTests\Support';

public function setUp(): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/tests/_support/Models/ExampleModel.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php namespace CIModuleTests\Support\Models;
<?php namespace ModuleTests\Support\Models;

use CodeIgniter\Model;

Expand Down
2 changes: 1 addition & 1 deletion src/tests/_support/SessionTestCase.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php namespace CIModuleTests\Support;
<?php namespace ModuleTests\Support;

use CodeIgniter\Session\Handlers\ArrayHandler;
use Tests\Support\Session\MockSession;
Expand Down
4 changes: 2 additions & 2 deletions src/tests/database/ExampleDatabaseTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class ExampleDatabaseTest extends CIModuleTests\Support\DatabaseTestCase
class ExampleDatabaseTest extends ModuleTests\Support\DatabaseTestCase
{
public function setUp(): void
{
Expand All @@ -9,7 +9,7 @@ public function setUp(): void

public function testDatabaseSimple()
{
$model = new \CIModuleTests\Support\Models\ExampleModel();
$model = new \ModuleTests\Support\Models\ExampleModel();

$objects = $model->findAll();

Expand Down
2 changes: 1 addition & 1 deletion src/tests/session/ExampleSessionTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class ExampleSessionTest extends CIModuleTests\Support\SessionTestCase
class ExampleSessionTest extends ModuleTests\Support\SessionTestCase
{
public function setUp(): void
{
Expand Down