php peridot 使用教程,PHP测试框架Peridot-支持BDD

php peridot 使用教程,PHP测试框架Peridot-支持BDDPeridot 是什么 Peridot 是一个先进的 PHP 测试框架 支持 PHP5 4 以上的 PHP 版本 能够通过 BDD 的方式组织代码 使得测试代码非常易读 特点 官网给出的一下特点 1 灵活的 BDD 测试接口 2

大家好,我是讯享网,很高兴认识大家。

66557734b445d4af744a4e51c0f8fcf4.png
讯享网

Peridot是什么?

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

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

1,灵活的BDD测试接口;

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

3,便于命令行操作;

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

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

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

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

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

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

安装:

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

windows开发环境:

完成:打开命令行输入 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,查看是否安装正确。

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

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的方式来介绍其各种借口的使用方式。对下一小节感兴趣,请留言,更新后会通知各位。

小讯
上一篇 2025-01-11 17:17
下一篇 2025-03-08 21:53

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/59307.html