Skip to content
✔️ PHP Test Framework for Freedom, Truth, and Justice
Branch: master
Clone or download
Latest commit b0341a5 Apr 18, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin Fix reading of vendor name from config.json at line 14 (#283) Nov 2, 2017
docs/assets Move documentation inside its own repository. Oct 3, 2016
spec Fix Nullable types for non built-in types. Apr 18, 2019
src Create the 4.6.3 release. Apr 18, 2019
.gitignore Fix typo. Oct 14, 2017
.travis.yml Create the 4.6.2 release. Apr 17, 2019 Create the 4.6.3 release. Apr 18, 2019
LICENSE.txt Add MIT license. Sep 29, 2014 Update (#293) Mar 5, 2018
autoload.php Refactor class autoloading. Oct 14, 2017
composer.json add php 7.3 to travis Oct 16, 2018
kahlan-config.travis.php Simplify filtering API. Aug 12, 2017
phpcs.xml Lazily load Kahlan's global functions. Apr 11, 2017


Build Status Build Status License

Latest Stable Version Total Downloads Code Climate Coverage Status Coveralls Coverage Status Scrutinizer Coverage Status

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.


IRC (server) #kahlan (channel)


See the full documentation here


  • PHP 5.5+
  • Composer
  • phpdbg or Xdebug (only required for code coverage analysis)

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



describe("Example", function() {

    it("makes an expectation", function() {



    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() {

        $user = new User();


    it("stubs a class", function() {

        allow('PDO')->toReceive('prepare', 'fetchAll')->andReturn([['name' => 'bob']]);
        $user = new User();
        expect($user->all())->toBe([['name' => 'bob']]);




Example of default reporting:


Example of verbose reporting:


Example of code coverage on a specific scope:



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://
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)
You can’t perform that action at this time.