PHP测试框架Peridot 4年前

代码工具
441
PHP测试框架Peridot

PHP测试框架Peridot

Peridot是什么?

Peridot是一个先进的PHP测试框架,支持PHP5.4+以上的PHP版本,能够通过BDD的方式组织代码,使得测试代码非常易读。

官网:http://peridot-php.github.io/

特点:(官网给出的一下特点)

1,灵活的BDD测试接口;

2,基于事件驱动插件的架构;

3,便于命令行操作;

4,创建自定义的测试记录;

5,基于异常的通过或者失败的判定;

6,通过子域来最小化功能测试;

7,创建自己的领域特定语言DSL的测试。

通俗的将就是,通过BDD的形式组织代码,能够进行命令行操作,细化测试块,并将这些小的测试快整合到一个group中,表示某个大功能的测试。测试可以用于DSL开发。

正式其BDD组织代码方式,我才对其产生了好奇,其语法结构类似于Jasmine(一个专门做前段测试的测试框架)

安装:

1,首先安装composer(Composer是PHP用来做以来管理的);

windows开发环境:

进入:http://docs.phpcomposer.com/00-intro.md#Installation-*nix

下载:Composer-Setup.exe

完成:打开命令行输入 composer 后,查看是否安装成功。

2,安装Peridot

安装官方网站的介绍直接:

composer global require peridot-php/peridot:~1.0

                       下面是安装过程的打印信息

Changed current directory to C:/Users/tengyp/AppData/Roaming/Composer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing phpunit/php-timer (1.0.5)
    Downloading: 100%
  - Installing symfony/console (v2.5.6)
    Downloading: 100%
  - Installing evenement/evenement (v2.0.0)
    Downloading: 100%
  - Installing peridot-php/peridot (1.1.0)
    Downloading: 100%
symfony/console suggests installing symfony/event-dispatcher ()
symfony/console suggests installing psr/log (For using the console logger)
Writing lock file
Generating autoload files

完成之后,可以看到打印信息中第一行给出了composer的安装目录

C:/Users/tengyp/AppData/Roaming/Composer,

将composer目录下的vendor/peridot-php/peridot/bin将bin目录添加到环境变量path中。

3,打开新的命令行窗口,输入peridot,查看是否安装正确。

第一个小测试(这里直接使用官网的例子);

<?php //arrayobject.spec.php 
describe('ArrayObject', function() {   
  beforeEach(function() {         
      $this->arrayObject = new ArrayObject(['one', 'two', 'three']);     
  });     
  describe('->count()', function() {         
      it("should return the number of items", function() {             
          $count = $this->arrayObject->count();             
          assert($count === 3, "expected 3");         
      });     
  }); 
});

然后在命令行进入该文件存放的位置后,执行:peridot arrayobject.spec.php

会看到如下结果:

ArrayObject         ->count()           ✓ should return the number of items           1 passing (19 ms)

下一小节,通过结合一个具体的业务实例,使用TDD的方式来介绍其各种借口的使用方式。对下一小节感兴趣,请留言,更新后会通知各位。

image
暴力熊吉
不要在晚上做出任何决定。
8
发布数
3
关注者
11721
累计阅读

热门教程文档

Flutter
105小节
Dart
35小节
Objective-C
29小节
Spring Boot
24小节
Rust
84小节
广告