Kahlan - 全栈 Unit/BDD测试框架

网友投稿 1056 2022-10-20

Kahlan - 全栈 Unit/BDD测试框架

Kahlan - 全栈 Unit/BDD测试框架

Kahlan is a full-featured Unit & BDD test framework a la RSpec/JSpec which uses a describe-it syntax and moves testing in PHP one step forward.

Kahlan lets you stub or monkey patch your code directly like in Ruby or JavaScript without any required PECL-extensions.

Videos

Warren Seymour presentation at Unified Diff (2015)Grafikart presentation in French (2016, Kahlan 2.X)

IRC

chat.freenode- (server) #kahlan (channel)

Documentation

See the full documentation here

Requirements

PHP 5.5+Composerphpdbg or Xdebug (only required for code coverage analysis)

Main Features

RSpec/JSpec syntaxCode Coverage metrics (xdebug or phpdbg required)Handy stubbing system (mockery or prophecy are no longer needed)Set stubs on your class methods directly (i.e allows dynamic mocking)Ability to Monkey Patch your code (i.e. allows replacement of core functions/classes on the fly)Check called methods on your classes/instancesBuilt-in Reporters (Terminal or HTML reporting through istanbul or lcov)Built-in Exporters (Coveralls, Code Climate, Scrutinizer, Clover)Extensible, customizable workflow

Syntax

toBe(true); }); it("expects methods to be called", function() { $user = new User(); expect($user)->toReceive('save')->with(['validates' => false]); $user->save(['validates' => false]); }); it("stubs a function", function() { allow('time')->toBeCalled()->andReturn(123); $user = new User(); expect($user->save())->toBe(true) expect($user->created)->toBe(123); }); it("stubs a class", function() { allow('PDO')->toReceive('prepare', 'fetchAll')->andReturn([['name' => 'bob']]); $user = new User(); expect($user->all())->toBe([['name' => 'bob']]); });});

Screenshots

Example of default reporting:

Example of verbose reporting:

Example of code coverage on a specific scope:

Installation

via Composer

$ composer require --dev kahlan/kahlan

Note: Kahlan uses the Semantic Versioning and maintains a CHANGELOG to help you easily understand what's happening.

via Git clone

git clone git://github.com/kahlan/kahlan.gitcd kahlancomposer installbin/kahlan # to run specs or,bin/kahlan --coverage=4 # to run specs with coverage info for namespaces, classes & methods (require xdebug)

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:SpringBoot+Minio搭建不再爆肝秃头的分布式文件服务器
下一篇:FlieBeat & Kafka & Clickhouse 替代ELK 系列一
相关文章

 发表评论

暂时没有评论,来抢沙发吧~