Description
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 embraces the KISS principle and makes Unit & BDD testing fun again!
Kahlan alternatives and similar libraries
Based on the "Testing" category.
Alternatively, view Kahlan alternatives based on common mentions on social networks and blogs.
-
Mockery
Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its core goal is to offer a test double framework with a succinct API capable of clearly defining all possible object operations and interactions using a human readable Domain Specific Language (DSL). -
VFS Stream
vfsStream is a stream wrapper for a virtual file system that may be helpful in unit tests to mock the real file system. It can be used with any unit test framework, like PHPUnit or SimpleTest. -
PHP-Mock: mocking built-in PHP functions
Mock built-in PHP functions (e.g. time(), exec() or rand())
InfluxDB - Purpose built for real-time analytics at any scale.
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of Kahlan or a related project?
Popular Comparisons
README
[Kahlan](docs/assets/logo.png "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
Requirements
Main Features
- RSpec/JSpec syntax
- Code 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/instances
- Built-in Reporters (Terminal or HTML reporting through istanbul or lcov)
- Built-in Exporters (Coveralls, Code Climate, Scrutinizer, Clover)
- Extensible, customizable workflow
Syntax
<?php
describe("Example", function() {
it("makes an expectation", function() {
expect(true)->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
$ 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.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)
*Note that all licence references and agreements mentioned in the Kahlan README section above
are relevant to that project's source code only.