cedriclange/ci-phpunit

使用 PHPUnit 与 CodeIgniter 3.x 的更简单方法

v0.17.5 2020-04-02 22:19 UTC

This package is auto-updated.

Last update: 2024-09-29 05:29:09 UTC


README

phpunit

此仓库已构建以解决问题 #34 和 #311

使用 CodeIgniter 3.x 更简单地使用 PHPUnit。

  • 您完全不需要修改 CodeIgniter 核心文件。
  • 您可以轻松编写控制器测试。
  • 可能没有什么是不可以测试的。
  • 良好的文档。

Screenshot: Running tests on NetBeans 8.1

要求

  • PHP 5.4.0 或更高版本(推荐使用 5.6 或更高版本)
  • CodeIgniter 3.x
  • PHPUnit 4.3 至 7.5(推荐使用 4.8 或更高版本)
    • 如果您想使用 PHPUnit 8 或更高版本,请使用 ci-phpunit-test 2.x
    • 如果您使用 PHPUnit 6.0,请使用 ci-phpunit-test v0.14.0 或更高版本。
    • 您可以从 https://phar.phpunit.de/ 下载旧的 phpunit.phar 版本。

可选

  • NetBeans
    • 转到 项目属性 > 测试 > PHPUnit,勾选 使用自定义测试套件 复选框,并选择 application/tests/_ci_phpunit_test/TestSuiteProvider.php

变更日志

查看 变更日志

目录结构

codeigniter/
├── application/
│   └── tests/
│        ├── _ci_phpunit_test/ ... don't touch! files ci-phpunit-test uses
│        ├── Bootstrap.php     ... bootstrap file for PHPUnit
│        ├── DbTestCase.php    ... DbTestCase class
│        ├── TestCase.php      ... TestCase class
│        ├── controllers/      ... put your controller tests
│        ├── libraries/        ... put your library tests
│        ├── mocks/
│        │   └── libraries/    ... mock libraries
│        ├── models/           ... put your model tests
│        └── phpunit.xml       ... config file for PHPUnit
└── vendor/

安装

通过 Composer 安装

如果您喜欢 Composer

$ cd /path/to/codeigniter/
$ composer require cedriclange/ci-phpunit --dev

然后运行 install.php

$ php vendor/cedric/ci-phpunit/install.php --from-composer
  • 上述命令始终覆盖现有文件。
  • 您必须在其根目录中运行它。
  • 请从 tests/phpunit.xml 中删除 <exclude>./_ci_phpunit_test/</exclude> 行。
  • 如果您使用自定义文件夹路径,可以使用选项参数指定您的 applicationpublic 文件夹。
$ php vendor/cedriclange/ci-phpunit/install.php -a <application_dir> -p <public_dir>
  • 但某些路径可能不正确,在这种情况下,请在 tests/Bootstrap.php 中修复它们。

通过 Composer 升级

如果您喜欢 Composer

$ cd /path/to/codeigniter/
$ composer update cedriclange/ci-phpunit

如果您是从创建 application/test/_ci_phpunit_test 目录的先前版本的 ci-phpunit-test 升级,并且现在想直接使用 Composer 中的 ci-phpunit-test,您需要执行以下额外步骤

  1. 删除旧测试库目录:rm -rf /path/to/codeigniter/application/tests/_ci_phpunit_test
  2. 编辑 application/tests/Bootstrap.php 文件。在“设置主路径常量”部分的底部