roccococco/ciunit

允许使用PHPUnit测试CodeIgniter 2.1

1.0.0 2015-06-25 02:46 UTC

This package is auto-updated.

Last update: 2024-09-06 08:45:34 UTC


README

注意:此软件与CodeIgniter 3不兼容。我-ciunit的原始创建者为CodeIgniter 3创建了新的项目,链接如下:https://github.com/kenjis/ci-phpunit-test

示例

控制器

class LoginActionTest extends CIUnit_TestCase
{
    public function setUp()
    {
        $this->CI = set_controller('login');
    }

    public function testLogin()
    {
        $_POST['useremail'] = 'kitsunde@example.org';
        $_POST['password'] = '123';
        $this->CI->login_action();
        $out = output();
        $this->assertRedirects($GLOBALS['OUT'], 'employee/index');
    }

    public function testTemplateRendered()
    {
        $this->CI->login_action();
        $views = output_views();
        $this->assertContains('login', $views);
    }
}

通过composer安装

composer require Celc/ciunit dev-master

将示例测试目录复制到项目的根目录(与applicationsystem目录在同一文件夹中)

cp -R vendor/celc/ciunit/tests ./

为数据库测试创建application/config/testing/database.php。数据库名称必须以_test结尾。

编写测试

tests目录是一个示例。您应该用您自己的测试替换它。

运行测试

tests目录运行

../vendor/phpunit