{"id":13746097,"url":"https://github.com/kenjis/ci-phpunit-test","last_synced_at":"2025-05-15T01:05:17.008Z","repository":{"id":31791836,"uuid":"35358299","full_name":"kenjis/ci-phpunit-test","owner":"kenjis","description":"An easier way to use PHPUnit with CodeIgniter 3.x.","archived":false,"fork":false,"pushed_at":"2024-02-16T11:50:09.000Z","size":2198,"stargazers_count":588,"open_issues_count":20,"forks_count":194,"subscribers_count":42,"default_branch":"3.x","last_synced_at":"2025-05-10T13:05:56.293Z","etag":null,"topics":["codeigniter","codeigniter3","hacktoberfest","monkey-patching","phpunit","testing-tools"],"latest_commit_sha":null,"homepage":"http://kenjis.github.io/ci-phpunit-test/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kenjis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-05-10T05:22:43.000Z","updated_at":"2025-05-09T10:15:12.000Z","dependencies_parsed_at":"2024-09-19T20:30:51.048Z","dependency_job_id":"1cf5fa0b-e434-48bb-8277-a3847c980c29","html_url":"https://github.com/kenjis/ci-phpunit-test","commit_stats":{"total_commits":959,"total_committers":24,"mean_commits":"39.958333333333336","dds":0.05735140771637126,"last_synced_commit":"f81403bdd05d941f474ad857781503be2926a40e"},"previous_names":[],"tags_count":46,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenjis%2Fci-phpunit-test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenjis%2Fci-phpunit-test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenjis%2Fci-phpunit-test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kenjis%2Fci-phpunit-test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kenjis","download_url":"https://codeload.github.com/kenjis/ci-phpunit-test/tar.gz/refs/heads/3.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253576267,"owners_count":21930169,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codeigniter","codeigniter3","hacktoberfest","monkey-patching","phpunit","testing-tools"],"created_at":"2024-08-03T06:00:46.731Z","updated_at":"2025-05-15T01:05:16.989Z","avatar_url":"https://github.com/kenjis.png","language":"PHP","readme":"# ci-phpunit-test for CodeIgniter 3.x\n\n[![Latest Stable Version](https://poser.pugx.org/kenjis/ci-phpunit-test/v/stable)](https://packagist.org/packages/kenjis/ci-phpunit-test) [![Total Downloads](https://poser.pugx.org/kenjis/ci-phpunit-test/downloads)](https://packagist.org/packages/kenjis/ci-phpunit-test) [![Latest Unstable Version](https://poser.pugx.org/kenjis/ci-phpunit-test/v/unstable)](https://packagist.org/packages/kenjis/ci-phpunit-test) [![License](https://poser.pugx.org/kenjis/ci-phpunit-test/license)](https://packagist.org/packages/kenjis/ci-phpunit-test)\n\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/kenjis/ci-phpunit-test/badges/quality-score.png?b=3.x)](https://scrutinizer-ci.com/g/kenjis/ci-phpunit-test/?branch=3.x)\n[![Coverage Status](https://coveralls.io/repos/kenjis/ci-phpunit-test/badge.svg?branch=3.x)](https://coveralls.io/r/kenjis/ci-phpunit-test?branch=3.x)\n[![Build Status](https://travis-ci.com/kenjis/ci-phpunit-test.svg?branch=3.x)](https://travis-ci.com/kenjis/ci-phpunit-test)\n\n---\n\n\u003e [!WARNING]\n\u003e [Upgrading to CodeIgniter4 is strongly recommended](https://github.com/kenjis/ci-phpunit-test/issues/409).\n\n---\n\nAn easier way to use PHPUnit with [CodeIgniter](https://github.com/bcit-ci/CodeIgniter) 3.x.\n\n* You don't have to modify CodeIgniter core files at all.\n* You can write controller tests easily.\n* Nothing is untestable, maybe.\n* Well documented.\n\n![Screenshot: Running tests on NetBeans 8.1](docs/imgs/netbeans-8.1.png)\n\n## Requirements\n\n* PHP 7.3 or later\n  * If you use Monkey Patching, you must use PHP-Parser 4.2 or later as a Composer dependency.\n* CodeIgniter 3.x\n  * If you want to upgrade to CodeIgniter4, see [#361](https://github.com/kenjis/ci-phpunit-test/issues/361).\n* PHPUnit 9.3 or later\n  * If you want to use PHPUnit 9.2 or earlier, please use ci-phpunit-test [2.x](https://github.com/kenjis/ci-phpunit-test/tree/2.x).\n\n## Optional\n\n* NetBeans\n  * Go to *Project Properties \u003e Testing \u003e PHPUnit*, check *Use Custom Test Suite* checkbox, and select `application/tests/_ci_phpunit_test/TestSuiteProvider.php`.\n\n## Change Log\n\nSee [Change Log](https://github.com/kenjis/ci-phpunit-test/blob/3.x/application/tests/_ci_phpunit_test/ChangeLog.md).\n\n## Folder Structure\n\n~~~\ncodeigniter/\n├── application/\n│   └── tests/\n│        ├── _ci_phpunit_test/ ... don't touch! files ci-phpunit-test uses\n│        ├── Bootstrap.php     ... bootstrap file for PHPUnit\n│        ├── DbTestCase.php    ... DbTestCase class\n│        ├── TestCase.php      ... TestCase class\n│        ├── controllers/      ... put your controller tests\n│        ├── libraries/        ... put your library tests\n│        ├── mocks/\n│        │   └── libraries/    ... mock libraries\n│        ├── models/           ... put your model tests\n│        └── phpunit.xml       ... config file for PHPUnit\n└── vendor/\n~~~\n\n## Installation\n\n### Manual Installation\n\n1. Download latest `ci-phpunit-test` from \u003chttps://github.com/kenjis/ci-phpunit-test/releases\u003e.\n2. Unzip and copy `application/tests` folder into your `application` folder in CodeIgniter project.\n\nThat's it.\n\n### Composer Installation\n\n~~~sh-session\n$ cd /path/to/codeigniter/\n$ composer require kenjis/ci-phpunit-test:^3.0 --dev\n~~~\n\nAnd run `install.php`:\n\n~~~sh-session\n$ php vendor/kenjis/ci-phpunit-test/install.php --from-composer\n~~~\n\n* The above command always overwrites existing files.\n* You must run it at CodeIgniter project root folder.\n* You can specify your `application` and `public` folder with option arguments, if you use custom folder paths.\n\n~~~sh-session\n$ php vendor/kenjis/ci-phpunit-test/install.php -a \u003capplication_dir\u003e -p \u003cpublic_dir\u003e -t \u003cunittest_dir\u003e\n~~~\n\nSo the default would be:\n~~~sh-session\n$ php vendor/kenjis/ci-phpunit-test/install.php -a application -p public -t application/tests\n~~~\n\n* But some paths may be not correct, in that case, please fix them in [tests/Bootstrap.php](https://github.com/kenjis/ci-phpunit-test/blob/3.x/application/tests/Bootstrap.php#L98).\n\n## Upgrading\n\n### Manual Upgrading\n\n1. Download latest `ci-phpunit-test` from \u003chttps://github.com/kenjis/ci-phpunit-test/releases\u003e.\n2. Unzip and replace `application/tests/_ci_phpunit_test` folder.\n3. Read [Change Log](https://github.com/kenjis/ci-phpunit-test/blob/3.x/application/tests/_ci_phpunit_test/ChangeLog.md).\n\n### Composer Upgrading\n\n~~~sh-session\n$ cd /path/to/codeigniter/\n$ composer update kenjis/ci-phpunit-test\n~~~\n\nRead [Change Log](https://github.com/kenjis/ci-phpunit-test/blob/3.x/application/tests/_ci_phpunit_test/ChangeLog.md).\n\n#### If you want to remove application/test/_ci_phpunit_test/\n\nIf you're upgrading from a previous version of `ci-phpunit-test` that created\nan `application/test/_ci_phpunit_test` directory and now want to directly use\n`ci-phpunit-test` from Composer, you have a couple of additional steps:\n\n1. Delete the old test library directory: \n    ```sh-session\n    $ rm -rf /path/to/codeigniter/application/tests/_ci_phpunit_test\n    ```\n2. Edit the `application/tests/Bootstrap.php` file. At the bottom of the \"set the main path constants\"\n   section, add the following:\n    ```php\n    define('CI_PHPUNIT_TESTPATH', implode(\n        DIRECTORY_SEPARATOR,\n        [dirname(APPPATH), 'vendor', 'kenjis', 'ci-phpunit-test', 'application', 'tests', '_ci_phpunit_test']\n    ).DIRECTORY_SEPARATOR);\n    ```\n    And replace any references to `__DIR__ . '/_ci_phpunit_test/` or `TESTPATH . '_ci_phpunit_test` with\n    `CI_PHPUNIT_TESTPATH . '`.  (So, for example, `__DIR__ . '/_ci_phpunit_test/CIPHPUnitTest.php'`\n    would become `CI_PHPUNIT_TESTPATH . '/CIPHPUnitTest.php'`.)\n\n## How to Run Tests\n\nYou need to install PHPUnit before running tests.\n\nIf you use Composer:\n```sh-session\n$ composer require phpunit/phpunit --dev\n```\n\n### Run All Tests\n\n~~~sh-session\n$ cd /path/to/codeigniter/\n$ vendor/bin/phpunit -c application/tests/\nPHPUnit 9.5.4 by Sebastian Bergmann and contributors.\n\n...                                                                 3 / 3 (100%)\n\nTime: 00:00.102, Memory: 12.00 MB\n\nOK (3 tests, 3 assertions)\n\nGenerating code coverage report in Clover XML format ... done [00:00.002]\n\nGenerating code coverage report in HTML format ... done [00:00.012]\n~~~\n\nTo generate coverage report, Xdebug is needed.\n\n### Run a Single Test\n\nIf you want to run a single test case file:\n\n~~~sh-session\n$ vendor/bin/phpunit -c application/tests/ application/tests/models/Category_model_test.php\n~~~\n\n## How to Write Tests\n\nAs an example, a test case class for `Inventory_model` would be as follows:\n\n~~~php\n\u003c?php\n\nclass Inventory_model_test extends TestCase\n{\n    public function setUp(): void\n    {\n        $this-\u003eresetInstance();\n        $this-\u003eCI-\u003eload-\u003emodel('Inventory_model');\n        $this-\u003eobj = $this-\u003eCI-\u003eInventory_model;\n    }\n\n    public function test_get_category_list()\n    {\n        $expected = [\n            1 =\u003e 'Book',\n            2 =\u003e 'CD',\n            3 =\u003e 'DVD',\n        ];\n        $list = $this-\u003eobj-\u003eget_category_list();\n        foreach ($list as $category) {\n            $this-\u003eassertEquals($expected[$category-\u003eid], $category-\u003ename);\n        }\n    }\n\n    public function test_get_category_name()\n    {\n        $actual = $this-\u003eobj-\u003eget_category_name(1);\n        $expected = 'Book';\n        $this-\u003eassertEquals($expected, $actual);\n    }\n}\n~~~\n\nAs an example, a test case class for Welcome controller would be as follows:\n\n~~~php\n\u003c?php\n\nclass Welcome_test extends TestCase\n{\n    public function test_index()\n    {\n        $output = $this-\u003erequest('GET', 'welcome/index');\n        $this-\u003eassertStringContainsString(\n            '\u003ctitle\u003eWelcome to CodeIgniter\u003c/title\u003e', $output\n        );\n    }\n}\n~~~\n\nSee [How to Write Tests](https://github.com/kenjis/ci-phpunit-test/blob/3.x/docs/HowToWriteTests.md) for details.\n\n## Function/Class Reference\n\nSee [Function and Class Reference](https://github.com/kenjis/ci-phpunit-test/blob/3.x/docs/FunctionAndClassReference.md).\n\n## Tips\n\nSee [Tips](https://github.com/kenjis/ci-phpunit-test/blob/3.x/docs/Tips.md).\n\n## Stand-alone Packages\n\nSome features of *ci-phpunit-test* are available in the following standalone packages.\n\n* https://github.com/kenjis/phpunit-helper\n* https://github.com/kenjis/monkey-patch\n\n## Related Projects for CodeIgniter 3.x\n\n* [CodeIgniter Test Application for ci-phpunit-test](https://github.com/kenjis/ci-app-for-ci-phpunit-test)\n* [CodeIgniter Composer Installer](https://github.com/kenjis/codeigniter-composer-installer)\n* [Cli for CodeIgniter 3.0](https://github.com/kenjis/codeigniter-cli)\n* [CodeIgniter Simple and Secure Twig](https://github.com/kenjis/codeigniter-ss-twig)\n* [CodeIgniter Doctrine](https://github.com/kenjis/codeigniter-doctrine)\n* [CodeIgniter Deployer](https://github.com/kenjis/codeigniter-deployer)\n* [CodeIgniter3 Filename Checker](https://github.com/kenjis/codeigniter3-filename-checker)\n* [CodeIgniter Widget (View Partial) Sample](https://github.com/kenjis/codeigniter-widgets)\n* [CodeIgniter3 Namespaced Controller](https://github.com/kenjis/codeigniter3-namespaced-controller)\n","funding_links":[],"categories":["Testing"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkenjis%2Fci-phpunit-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkenjis%2Fci-phpunit-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkenjis%2Fci-phpunit-test/lists"}