Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kahlan/kahlan
:heavy_check_mark: PHP Test Framework for Freedom, Truth, and Justice
https://github.com/kahlan/kahlan
bdd coverage monkey-patching php spec tdd test
Last synced: 2 days ago
JSON representation
:heavy_check_mark: PHP Test Framework for Freedom, Truth, and Justice
- Host: GitHub
- URL: https://github.com/kahlan/kahlan
- Owner: kahlan
- License: mit
- Created: 2013-08-18T18:12:58.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2024-10-18T19:02:43.000Z (about 2 months ago)
- Last Synced: 2024-11-13T13:03:16.648Z (29 days ago)
- Topics: bdd, coverage, monkey-patching, php, spec, tdd, test
- Language: PHP
- Homepage: https://kahlan.github.io/docs/
- Size: 3.56 MB
- Stars: 1,145
- Watchers: 30
- Forks: 69
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-php - Kahlan - Full stack Unit/BDD testing framework with built-in stub, mock and code-coverage support. (Table of Contents / Testing)
- awesome-bdd - Kahlan - PHP Test Framework for Freedom, Truth, and Justice. (Tools / PHP)
- awesome-projects - Kahlan - Full stack Unit/BDD testing framework with built-in stub, mock and code-coverage support. (PHP / Testing)
- awesome-php - Kahlan - Full stack Unit/BDD testing framework with built-in stub, mock and code-coverage support. (Table of Contents / Testing)
- awesome-php-cn - Kahlan - 完整的堆栈单元/ BDD测试框架内置存根,模拟和代码覆盖的支持. (目录 / 测试 Testing)
README
![Kahlan](docs/assets/logo.png "Kahlan")
![Build Status](https://github.com/kahlan/kahlan/workflows/Build/badge.svg) [![License](https://poser.pugx.org/kahlan/kahlan/license.svg)](https://packagist.org/packages/kahlan/kahlan)
[![Latest Stable Version](https://img.shields.io/packagist/v/kahlan/kahlan.svg)](https://packagist.org/packages/kahlan/kahlan)
[![Total Downloads](https://img.shields.io/packagist/dt/kahlan/kahlan.svg)](https://packagist.org/packages/kahlan/kahlan)
[![Code Coverage](https://codecov.io/gh/kahlan/kahlan/branch/dev/graph/badge.svg)](https://app.codecov.io/gh/kahlan/kahlan/)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.net** (server)
**#kahlan** (channel)## Documentation
See the [full documentation here](https://kahlan.github.io/docs)
## Requirements
* PHP 7.2+
* Composer
* [phpdbg](http://php.net/manual/en/debugger-about.php) or [Xdebug](http://xdebug.org/) (only required for code coverage analysis)## Main Features
* RSpec/JSpec syntax
* Code Coverage metrics ([xdebug](http://xdebug.org) or [phpdbg](http://phpdbg.com/docs) required)
* Handy stubbing system ([mockery](https://github.com/padraic/mockery) or [prophecy](https://github.com/phpspec/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/instances
* Built-in Reporters (Terminal or HTML reporting through [istanbul](https://gotwarlost.github.io/istanbul/) or [lcov](http://ltp.sourceforge.net/coverage/lcov.php))
* Built-in Exporters (Coveralls, Code Climate, Scrutinizer, Clover)
* Extensible, customizable workflow## Syntax
```php
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:
![dot_reporter](docs/assets/dot_reporter.png)### Example of verbose reporting:
![verbose_reporter](docs/assets/verbose_reporter.png)### Example of code coverage on a specific scope:
![code_coverage](docs/assets/code_coverage.png)## Installation
### via Composer
```bash
$ composer require --dev kahlan/kahlan
```Note:
Kahlan uses the [Semantic Versioning](http://semver.org/) and maintains a `CHANGELOG` to help you easily understand what's happening.### via Git clone
```
git clone git://github.com/kahlan/kahlan.git
cd kahlan
composer install
bin/kahlan # to run specs or,
bin/kahlan --coverage=4 # to run specs with coverage info for namespaces, classes & methods (require xdebug)
```