/kahlan

Kahlan - Unit/BDD PHP Test Framework for Freedom, Truth, and Justice

Primary LanguagePHPMIT LicenseMIT

Kahlan

Build Status Build Status HHVM 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 embraces the KISS principle and makes Unit & BDD testing fun again!

Killer feature: Kahlan allows to stub or monkey patch your code directly like in Ruby or JavaScript without any required PECL-extentions.

Video

Documentation

See the whole documentation here.

Requirements

  • PHP 5.4+
  • Composer
  • Xdebug (if you want to perform code coverage analysis)

Main Features

  • Simple API
  • Small code base (~10 times smaller than PHPUnit)
  • Fast Code Coverage metrics (xdebug 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 class/instances
  • Built-in Reporters/Exporters (Terminal, Coveralls, Code Climate, Scrutinizer, Clover)
  • Extensible, customizable workflow

Syntax

describe("Example", function() {

    it("passes if true === true", function() {

        expect(true)->toBe(true);

    });

    it("passes if false !== true", function() {

        expect(false)->not->toBe(true);

    });

});

Screenshots

Example of error reporting: Kahlan

Example of detailed code coverage on a specific scope: code_coverage_example

Installation

via Composer

Here is a sample composer.json to install Kahlan:

{
    "name": "example/kahlan",
    "description": "Demonstration of installing Kahlan through Composer",
    "require": {
    },
    "require-dev": {
        "crysalead/kahlan": "~1.0"
    },
    "license": "MIT",
    "minimum-stability": "dev"
}

Then install via:

composer install --dev

Note: Kahlan uses the ferver versioning so a "~x.y" version constraint shouldn't ever BC-break.

via Git clone

git clone git@github.com:crysalead/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)