`
xieye
  • 浏览: 799348 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

php测试框架概览

    博客分类:
  • PHP
阅读更多
今天 2017-07-11
总体来说,写php程序,有测试代码好于无测试代码,不管用什么方式。

composer知识:require-dev使用

composer.json内一般用
 "require": {
        "zf1/zend-db":"1.12.11",
        "zf1/zend-paginator":"1.12.11"
        ... ...
    }


但也会像下面这样使用
   "require": {
        "zf1/zend-db":"1.12.11",
        "zf1/zend-paginator":"1.12.11"
    },
    "require-dev": { //这个是开发需要安装的项目,相当于开发环境,可以通过-no-dev来取消安装这个项目里面的包
        "phpspec/prophecy": "~1.0"
    }


关于测试是在开发机还是生产服务器的情况,应该说都有,自己选吧。
假设我们是在开发机测试,不在生产服务器测试,则我们的composer安装和更新命令应该是:
开发机上只运行:
composer install
composer update


生产服务器只运行
composer install --no-dev
composer update  --no-dev



php测试框架概览
本文的目的是查看当前所有的php测试框架,并且挑选出比较好的,并在之后的文章中予以介绍。
挑选依据依然很简单,composer下载量(单位:万),以及好评量(单位:百)。

    Alice - An expressive fixture generation library. (271/13)
    AspectMock - A mocking framework for PHPUnit/Codeception.(52/5)
    Atoum - A simple testing library.(39/10)
    Behat - A behaviour driven development (BDD) testing framework.(873/22)
    Codeception - A full stack testing framework.(515/29)
    DBUnit - A database testing library for PHPUnit.(379/1)
    Faker - A fake data generator library.(2268/113)这是一个数据库数据填充工具,laravel内置有。
    HTTP Mock - A library for mocking HTTP requests in unit tests.(0)
    Kahlan - Full stack Unit/BDD testing framework with built-in stub, mock and code-coverage support.(2/7)
    Mink - Web acceptance testing.(861/8)
    Mockery - A mock object library for testing.(1980/23)
    ParaTest - A parallel testing library for PHPUnit.(126/5)
    Peridot - An event driven test framework.(5/2)
    Phake - Another mock object library for testing.(110/4)
    Pho - Another behaviour driven development testing framework.(1/2)
    PHP-Mock - A mock library for built-in PHP functions (e.g. time()).(28/1)
    PHPSpec - A design by specification unit testing library.(894/12)
    PHPT - A test tool used by PHP itself.(没找到)
    PHPUnit - A unit testing framework.(5063/65)
    Prophecy - A highly opinionated mocking framework.(3799/9)mock类库,因为phpunit内置,所以下载量超高。
    Samsui - Another fake data generator library.(没找到)
    VFS Stream - A virtual filesystem stream wrapper for testing.(0)
    VFS - Another virtual filesystem for testing.(9/2)
    simpletest - 其实是一款很好用的测试框架,作者现在不怎么更新了。使用很简单是其特点,好上手。(7/1)
    Selenium 一个java的web客户端模拟操作类库,有php接口类库与之对应,可以使用。

上面的测试类库中:
本人文档有:
Codeception:codeception数据库中文支持
phpunit系列文章:php单元测试进阶系列文章
faker:Faker:php随机数据产生类库

phpunit官方中文文档
phpunit 4.8中文文档,支持php5.3-5.5,当然实际上以后也支持。
https://phpunit.de/manual/4.8/zh_cn/installation.html
"require-dev": {
  "phpunit/phpunit":"^4.8.36"
}

phpunit 5.7中文文档,支持php5.6以后全部
https://phpunit.de/manual/5.7/zh_cn/installation.html
"require-dev": {
  "phpunit/phpunit":"^5.7.21"
}

phpunit 6.2中文文档,支持php7以后
https://phpunit.de/manual/6.2/zh_cn/installation.html
"require-dev": {
  "phpunit/phpunit":"^6.2.3"
}


mocking框架Prophecy使用
Prophecy 高度可定制化的mocking框架。
安装
"require-dev": {
        "phpspec/prophecy": "1.7.0"
    }

这个类库的特点就是类和函数的名字特别神棍,什么预言,先知,启示等等。

延伸阅读:
依赖注入学习:http://xieye.iteye.com/blog/2384631
0
1
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics