codeception 和 phpunit
codecept run unit tests/unit/moTest.php --debug 在项目的根目录运行
第1步 - 安装 Codeception 框架。运行下面的代码。
使用 composer 命令
composer global require "codeception/codeception"
composer global require "codeception/specify"
composer global require "codeception/verify"
步骤2 - 运行如下
ccomposer global status
输出“Changed current directory to <directory>”如下图所示:
Changed current directory to C:/Users/luky/AppData/Roaming/Composer
No local changes
添加到环境变量:应该加上'C:/Users/luky/AppData/Roaming/Composer/vendor/bin ' 到 PATH 环境变量。在本示例中,运行下面的代码 -
export PATH = $PATH:~/.composer/vendor/bin
注:windows系统可右键"我的电脑"=>"高级系统设置"=>"环境变量"来添加。
linux下codecept安装
**codecept: command not found
on Ubuntu then you should follow these steps:**
sudo composer global require "codeception/codeception=2.1.*" "codeception/specify=*" "codeception/verify=*"
and then run this command:
sudo ln -s ~/.composer/vendor/bin/codecept /usr/local/bin/codecept
其他~
Socodecept build
andcodecept run
will work.
**If you are using Windows then run this command:**
composer global require "codeception/codeception=2.1.*" "codeception/specify=*" "codeception/verify=*"
Add this line into your path:
~\AppData\Roaming\Composer\vendor\bin
问题:如何将远程服务器的数据库导入到本地
步骤一:从远程服务器下载数据库
注:D:\Program Files\MySQL\MySQL Server 5.0\bin>为你安装的MYSQL安装目录,\bin为mysqldump管理工具所有在的目录;
mysqldump -h[hosname] -u[user_name] -p[password] --default-character-set=[char_set_name] [db_name] > [save_path]
eg:mysqldump -h119.12.12.11 -umysqluser -pmysqlpwd --default-character-set=utf8 dbname --skip-lock-tables> d:\sqlname.sql
步骤二:通过phpmyadmin或者其他数据库管理工具导入即可
或者命令行导入
http://jingyan.baidu.com/article/cbf0e500d15c762eab289362.html
==
指令:
codecept bootstrap
codecept build
codecept run
步骤3 - 开始测试:
1 用户测试模块
①:测试寻找用户id
过程:
a.已输入的id
b.判断id对应的用户名和用户名相同,并返回正确。
c.不相同,返回错误。
函数:
public function testFindUserById()
{
//$user = User::findIdentity(1);
//print_r($user);
expect_that($user = User::findIdentity(1));
expect($user->username)->equals('aa@cc.cc');
expect_not(User::findIdentity(0));
}
②:测试寻找用户token
过程:
a.已输入的token
b.判断token对应的用户名和用户名相同,并返回正确。
c.不相同,或不存在token,返回错误
函数:
public function testFindUserByAccessToken()
{
expect_that($user = User::findIdentityByAccessToken('asdflawejflwefadsfasdf'));
expect($user->username)->equals('aa@cc.cc');
expect_not(User::findIdentityByAccessToken('non-existing'));
}
③:测试寻找用户用户名
过程:
a.判断用户对应的用户名和用户名相同,并返回正确。
b.不存在,返回错误
函数:
public function testFindUserByUsername()
{
expect_that($user = User::findByUsername('aa@cc.cc'));
expect_not(User::findByUsername('not-admin'));
}
④:测试用户的key是否激活
过程:
a.输入用户名和用户的key,判断对应则激活。
b.判断key和username不对应,则激活失败。
c.判断用户的username和密码是否一样,一样返回正确
d.不一致,返回错误
函数:
/**
* @depends testFindUserByUsername
*/
public function testActivationKey($user)
{
$user = User::findByUsername('dd');
expect_that($user->findByActivationKey('awelvowaslfdf'));
expect_not($user->findByActivationKey('test102key'));
expect_that($user->validatePassword('abc123'));
expect_not($user->validatePassword('123456'));
}