定制 edgcarmu/codeigniter-phpunit 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

edgcarmu/codeigniter-phpunit

最新稳定版本:v1.0.0

Composer 安装命令:

composer require edgcarmu/codeigniter-phpunit

包简介

Official adaptation of yidas/codeigniter-phpunit for CodeIgniter 3.1.11 and PHP 7.1+

README 文档

README

CodeIgniter PHPUnit Test


CodeIgniter 3 PHPUnit Test extension library

Latest Stable Version License

Official adaptation of the yidas/codeigniter-phpunit repository for compatibility with CodeIgniter 3.1.13 and PHP 7.1+.

FEATURES

  • PHPUnit Test in Codeigniter 3 Framework

  • Easy to install into your Codeigniter project by Composer

OUTLINE

REQUIREMENTS

This library requires the following:

  • PHP 7.1.0+
  • CodeIgniter 3.1.13+

INSTALLATION

Run Composer from the project root:

composer require edgcarmu/codeigniter-phpunit

DIRECTORY STRUCTURE

codeigniter/
├── application/
├── system/
├── tests/
│   ├── bootstrap.php        ← Initializes the test environment; create only if needed to customize, then delegate to vendor/edgcarmu/codeigniter-phpunit/bootstrap.php
│   └── MyTest.php           ← Your test cases go here
├── vendor/
└── phpunit.xml              ← PHPUnit configuration; can point directly to the library's bootstrap if no customization is needed

CONFIGURATION

According to Directory Structure, create and configure phpunit.xml in the project root:

<?xml version="1.0" encoding="UTF-8" ?>
<phpunit bootstrap="vendor/edgcarmu/codeigniter-phpunit/bootstrap.php">
  <testsuites>
    <testsuite name="TestSuite">
      <directory>tests</directory>
    </testsuite>
  </testsuites>
</phpunit>

For this phpunit.xml template, the test cases directory is tests/, located at the project root. Make sure to place all your test cases inside this directory.

USAGE

From the project root, run PHPUnit using the Composer-installed binary:

./vendor/bin/phpunit

Or using absolute path commands like:

$ /var/www/html/codeigniter3/vendor/bin/phpunit -c /var/www/html/codeigniter3/phpunit.xml
$ phpunit -c /var/www/html/codeigniter3/phpunit.xml

Then the result would like:

PHPUnit 5.7.27 by Sebastian Bergmann and contributors.



Time: 40 ms, Memory: 2.75MB

No tests executed!

TEST CASE

With this extension library, you can write test cases while loading the CodeIgniter framework.

For example, create a test case at tests/CodeigniterTest.php to test a CodeIgniter component like the config loader:

<?php

use PHPUnit\Framework\TestCase;

final class CodeigniterTest extends TestCase
{
    function __construct() 
    {
        parent::__construct();
        // Load CI application
        $this->CI = & get_instance();
    }
    
    public function testConfigItem()
    {
        $indexPage = $this->CI->config->item('index_page');
        
        $this->assertSame('index.php', $indexPage);
    }
}

Then you would get the result OK (1 test, 1 assertion) by running PHPUnit test.

统计信息

  • 总下载量: 475
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-08