LinuxCommandLibrary

kahlan

Run and test applications written with Kahlan

TLDR

Run all specifications in the "spec" directory

$ kahlan
copy

Run specifications using a specific configuration file
$ kahlan --config=[path/to/configuration_file]
copy

Run specifications and output using a reporter
$ kahlan --reporter=[dot|bar|json|tap|verbose]
copy

Run specifications with code coverage (detail can be between 0 and 4)
$ kahlan --coverage=[detail_level]
copy

SYNOPSIS

kahlan [options] [paths…]

PARAMETERS

--help
    Display help information

--version
    Display Kahlan version

--spec
    Run specs instead of tests

--test
    Run tests (default)

--coverage[=<path>]
    Generate code coverage report

--reporter=<reporter>
    Specify output reporter (e.g., 'console', 'json', 'html')

--backtrace[=<N>]
    Show backtraces (N lines)

--colors[=<scheme>]
    Enable colored output

--no-colors
    Disable colored output

--configuration=<file>
    Path to configuration file

--src-paths=<paths>
    Source code paths (comma-separated)

--spec-paths=<paths>
    Spec/test paths (comma-separated)

--exclude-tags=<tags>
    Exclude specs by tags (comma-separated)

--concurrency=<N>
    Number of parallel processes

--ff
    Fail fast on first error

DESCRIPTION

Kahlan is a high-speed BDD (Behavior-Driven Development) framework and command-line tool for PHP applications. Designed for performance, it uses a custom JavaScript-like engine to execute tests up to 10x faster than traditional frameworks like PHPUnit. Kahlan emphasizes simplicity with zero-config setup, natural-language assertions, and features like parallel execution, code coverage, and customizable reporters.

It supports writing specs in a descriptive style, e.g., it("calculates sum", function() { expect(sum(2, 3))->toBe(5); });. Isolation is achieved via monkey-patching rather than slow class reloading, making it ideal for large suites. Kahlan integrates seamlessly with Composer-installed projects and supports exclusions by tags, paths, or namespaces.

Primarily used in modern PHP development for TDD/BDD workflows, it outputs results in console, HTML, or JSON formats. Coverage reports highlight untested code with LCOV or Clover support.

CAVEATS

Requires PHP 7.2+ and Composer installation (composer require --dev kahlan/kahlan). Not a standard system command; run via ./vendor/bin/kahlan. Monkey-patching may conflict with certain code patterns or extensions.

INSTALLATION

Run composer require --dev kahlan/kahlan in your project, then execute via ./vendor/bin/kahlan.

EXAMPLE USAGE

./vendor/bin/kahlan --spec --coverage=build/coverage
./vendor/bin/kahlan --reporter=html --exclude-tags=@slow

HISTORY

Released in 2014 by kahlan-dev team as a performant alternative to PHPUnit. Major versions up to 5.x focus on speed optimizations, PHP 8 support, and enhanced coverage. Widely adopted in PHP communities for CI/CD pipelines.

SEE ALSO

phpunit(1), composer(1), behat(1)

Copied to clipboard