:heavy_check_mark: PHP Test Framework for Freedom, Truth, and Justice
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.
chat.freenode.net (server)
#kahlan (channel)
See the full documentation here
<?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']]);
});
});
$ composer require --dev kahlan/kahlan
Note:
Kahlan uses the Semantic Versioning and maintains a CHANGELOG
to help you easily understand what’s happening.
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)