- 浏览: 380439 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (229)
- java编程 (4)
- java实用程序 (2)
- 算法设计 (34)
- 数据库 (8)
- ACM模板 (12)
- 技术术语 (1)
- java_web (3)
- php (22)
- eclipse (3)
- linux (25)
- linux命令使用心得 (3)
- web服务器 (8)
- IT知识 (2)
- 前端技术 (17)
- 开源软件 (5)
- vim (3)
- linux多线程 (9)
- web开发经验 (3)
- lua (5)
- linux编程 (3)
- smarty (1)
- mysql (4)
- Hive (2)
- 数据挖掘 (9)
- python (2)
- 生活 (1)
- C++ (2)
- 计算机 (1)
- objective-c (11)
- css (2)
- 游戏 (1)
- Mac (1)
最新评论
-
lr544463316:
我的怎么不行呀.....
Mysql Access denied for user ''@'localhost' to database 的一种解决方法 -
babaoqi:
使用时需要注意group_concat函数返回值的最大长度=g ...
mysql中的group_concat函数 -
代码能力弱成渣:
可以帮我看下我的代码么?我自己写的sam,也有ac过题的,但是 ...
求两个字符串的最长公共连续子序列(SAM实现) -
atgoingguoat:
有1000个?不过还是收藏下。
jquery常用的插件1000收集(转载)
转载自: http://d.hatena.ne.jp/Kenji_s/20120117/1326763908
How to use PHPUnit (CIUnit) with CodeIgniter 2.1.0
This article explains how to install and use PHPUnit/CIUnit with CodeIgniter 2.1.0.
What is CIUnit?
CIUnit is a bridge between your CodeIgniter application and PHPUnit.
- CIUnit Official Site http://www.foostack.com/foostack/
But the official release supports CodeIgniter 1.7.2. So I use the fork of CIUnit (my-ciunit).
Install PHPUnit
$ sudo pear channel-discover pear.phpunit.de $ sudo pear channel-discover components.ez.no $ sudo pear channel-discover pear.symfony-project.com $ sudo pear install phpunit/PHPUnit
Install CodeIgniter
$ wget http://downloads.codeigniter.com/reactor/CodeIgniter_2.1.0.zip $ unzip CodeIgniter_2.1.0.zip
Install CIUnit
Download my-ciunit
The default branch of my-ciunit is now for CodeIgniter 2.1.0.
$ wget https://bitbucket.org/kenjis/my-ciunit/get/default.zip $ unzip default.zip
If you use CodeIgniter 2.0.3, get "CI 2.0.3" branch.
$ wget https://bitbucket.org/kenjis/my-ciunit/get/CI%202.0.3.zip $ unzip "CI 2.0.3.zip"
Install my-ciunit by shell script
my-ciunit has a installer shell script.
How to use:
$ tools/install.sh /path/to/CodeIgniter/ [database_name [database_user [database_password [database_host]]]]
Note: The database name for testing must end with "_test".
For example:
$ cd kenjis-my-ciunit-* $ tools/install.sh ../CodeIgniter_2.1.0/ ciunit_test root password
This script creates database config file for testing, "application/config/testing/database.php".
Install my-ciunit manually
Copy application folder and tests folder in my-ciunit to CodeIgniter top diretory.
$ cd kenjis-my-ciunit-* $ cp -R application /path/to/CodeIgniter_2.1.0/ $ cp -R tests /path/to/CodeIgniter_2.1.0/
And create database config file for testing, "application/config/testing/database.php".
Note: The database name for testing must end with "_test".
If you use MY_Loader, MY_Output, MY_Session
Change the parent classes to MY_* in:
- application/third_party/CIUnit/core/CIU_*.php
- application/third_party/CIUnit/libraries/CIU_*.php
Directory structure of CIUnit
CodeIgniter/ application/ third_party/ CIUnit/ ... CIUnit itself tests/ controllers/ ... tests of controller fixtures/ ... fixtures helpers/ ... tests of helper libs/ ... tests of library models/ ... tests of model system/ ... tests of system (PHP)
Prepare Database for Testing
The database name for testing must end with "_test". This is the specification of CIUnit.
Create "ciunit_test" database, and create "phone_carrier" table for a sample model test code in CIUnit.
CREATE TABLE IF NOT EXISTS `phone_carrier` ( `name` varchar(255) NOT NULL, `txt_address` varchar(255) NOT NULL, `txt_message_length` int(11) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Prepare Model for sample test code
CIUnit has a sample test code for "Phone_carrier_model" model, but has no "Phone_carrier_model" model code.
Create the model.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Phone_carrier_model extends CI_Model { function __construct() { parent::__construct(); $this->load->database(); } function getCarriers(array $attributes) { foreach ($attributes as $field) { $this->db->select($field)->from('phone_carrier'); $query = $this->db->get(); foreach ($query->result_array() as $row) { $data[] = array($field, $row[$field]); } } return $data; } } /* End of file phone_carrier_model.php */ /* Location: ./application/models/phone_carrier_model.php */
Run tests
Before run phpunit, move to tests folder.
$ cd tests/
To run all tests,
$ phpunit
To run tests of model, specify a folder,
$ phpunit models
To run a specific test file,
$ phpunit models/PhoneCarrierModelTest.php
If all tests have passed, you'll see green OK below:
Next: Database Testing of CodeIgniter Application with PHPUnit (CIUnit) - A Day in Serenity @ Kenji
发表评论
-
php redis api
2014-10-25 10:13 2694参考:http://jianzhong5137.blog.1 ... -
php创建zookeeper临时变量
2014-10-17 18:37 1132临时变量会在连接断开之后被删除。 <?php ... -
设置session_id,现有的session数据会覆盖原有的
2014-08-30 11:27 928有两个session_id $sid1 = "d ... -
php的session不支持数字作为key的原因
2014-08-30 10:57 1739php_serialize is available fro ... -
PHP输入流php://input
2014-04-09 11:21 844转自: http://blog.csdn.net/lxzo1 ... -
php保留两位小数但不四舍五入
2013-12-23 18:10 705<?php $s = '1.339' ... -
PHP5的__clone实现深复制
2013-01-30 01:57 781<?php class cb{ va ... -
phpinfo() 中 Local Value Master Value 的区别
2012-12-19 00:09 903转自: http://hi.baidu.com/kkwtre/ ... -
PHP session回收机制
2012-12-18 23:49 1333转自: http://blog.csdn.net/21aspn ... -
php时区设置
2012-11-27 00:17 584转自: http://www.jb51.net/article ... -
关于php中trigger_error的日志输出到哪里的问题
2012-11-25 14:34 2954#display_errors display_errors ... -
打印调用栈的函数print_stack_trace
2012-10-10 22:07 6152打印调用栈的函数print_stack_trace ... -
时间戳转换为“年-月-日 时:分:秒”的格式
2012-09-18 11:38 1315<?php if($argc < 2){ ... -
启动php-cgi
2012-09-13 10:30 949命令为: php-cgi --fpm --fpm-confi ... -
php实用函数
2012-09-04 00:37 668常常会需要当经常会忘记,还是记下来吧 get_defin ... -
php session配置
2012-08-21 16:23 972转自: http://blog.csdn.net/jallin ... -
php+mysql的安装
2012-08-15 17:35 864设用户名为work。 假设mysql已经安装成功,安装目录为 ... -
php用redis存储session的配置项示例
2012-08-06 23:09 871session.save_handler = re ... -
php正则表达式例子
2012-07-03 20:56 855* 判断字符串是否包含 ... -
php抓取网页内容的方法
2011-10-25 16:52 2023转自: http://bbs.phplovers.com/re ...
相关推荐
Get started with PHPUnit and learn how to write and test code using advanced technologies Overview Learn how to install PHPUnit as well as how to write and execute tests Understand the advanced ...
ci-phpunit-test, 一种简单的使用 PHPUnit 3.x 语言的方法 ci-phpunit-test用于 CodeIgniter 3 。x 在 CodeIgniter 3. x. 中使用PHPUnit的简便方法你根本不需要修改CodeIgniter核心文件。你可以轻松编
Imadoki的CodeIgniter入门PHPUnit 的源代码。
适用于CodeIgniter 3.x的ci-phpunit-test 将PHPUnit与 3.x结合使用的更简单方法。 您根本不需要修改CodeIgniter核心文件。 您可以轻松编写控制器测试。 也许没有什么是不可测试的。 有据可查。要求PHP 7.3或更高版本...
如果你在用PHPUNIT会报 include(PHPUnit_Extensions_Story_TestCase.php): failed to open stream: No such file or directory include(PHPUnit_Extensions_Database_TestCase.php): failed to open stream: No such...
phpunit-extensions 是 Etsy 的 PHPUnit 扩展。 标签:phpunit
phpunit 3 67 最新版 PHPUnit是一个轻量级的PHP测试框架 它是在PHP5下面对JUnit3系列版本的完整移植 是xUnit测试框架家族的一员 它们都基于模式先锋Kent Beck的设计 单元测试是几个现代敏捷开发方法的基础 使得...
We’ll conclude the chapter with an introduction to PHPUnit, showing you how to create and execute your first automated Laravel test! Chapter2.ManagingYourProjectControllers,Layout,Views,and ...
本版次适用于3.2版的PHPUnit。当然,大多数示例应该也可用于2.0-3.1版的PHPUnit。本书后面的“用于PHP 4的PHPUnit”(附录B - 译注)部分涉及了适用于PHP 4的旧版PHPUnit,它们已不再积极开发。 读者需要很好的理解...
ci-phpunit-test的CodeIgniter测试应用程序此CodeIgniter应用程序用于。要求PHP 7.3或更高版本如何进行测试 $ git clone -b 3.x https://github.com/kenjis/ci-app-for-ci-phpunit-test.git$ cd ci-app-for-ci-...
phpunit配置及使用
phpunit_中文手册说明 根据目录进行的编排!
PHPUnit单元测试的配置及使用,PHPUnit单元测试的配置及使用,PHPUnit单元测试的配置及使用,PHPUnit单元测试的配置及使用,PHPUnit单元测试的配置及使用
PHPUnit 5.7 是之前旧的 稳定 版本。 它 稳定 于 2016年12月02日。 PHPUnit 5.7 支持于 PHP 5.6, PHP 7.0 和 PHP 7.1, PHPUnit 5 将于2018年02月02日结束维护支持。
NULL 博文链接:https://tangzhifei.iteye.com/blog/437196
phpunit.phar phpunit.cmd的打包文件
用法使用PHPUnit use Asynchronicity \ PHPUnit \ Asynchronicity ;use PHPUnit \ Framework \ Assert ;use PHPUnit \ Framework \ TestCase ;final class ProcessTest extends TestCase{ use Asynchronicity ; /** ...
PHPUnit袖珍指南.doc PHPUnit 单元测试 从环境配置到 段元详细介绍
PHPUnit手册Sebastian Bergmann 此版本对应于PHPUnit 5.7。最后更新于2017-05026。 版权 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015 Sebastian Bergmann
该文档为 phpunit自动换测试文档。如果大家有什么问题希望大家回复。