kahlan

:heavy_check_mark: PHP Test Framework for Freedom, Truth, and Justice

Github星跟踪图

Kahlan

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.

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

  • 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

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();
        $user = new User();
        expect($user->all())->toBe();

    });

});

Screenshots

Example of default reporting:

dot_reporter

Example of verbose reporting:

verbose_reporter

Example of code coverage on a specific scope:

code_coverage

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)

主要指标

概览
名称与所有者kahlan/kahlan
主编程语言PHP
编程语言PHP (语言数: 3)
平台
许可证MIT License
所有者活动
创建于2013-08-18 18:12:58
推送于2025-02-22 16:05:43
最后一次提交2025-01-27 05:33:25
发布数133
最新版本名称6.0.2 (发布于 2025-02-22 23:05:27)
第一版名称1.0.0 (发布于 )
用户参与
星数1.1k
关注者数28
派生数70
提交数1.1k
已启用问题?
问题数254
打开的问题数6
拉请求数136
打开的拉请求数0
关闭的拉请求数47
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?