A PHP Testing Framework
<?php
describe('Huck Fin', function() {
it('should be Huck', function() {
expect('Huck')->toBe('Huck');
});
it('should not be Huck', function() {
expect('Tom')->not->toBe('Huck');
});
});
?>Huck is a BDD (Behavior Driven Development) framework based on Jasmine for JS. It is designed for with a simple syntax to give it a low learning curve.
Huck runs in the browser. Just upload it to your server, create the specs and load index.php. Huck will automatically find all files in specs/*_spec.php and run them.
Huck includes most of the matchers available in Jasmine.
expect($x)->toEqual($y);checks to see if$xand$yhave the same value
expect($x)->toBe($y);checks to see if$xand$yare identical. e.g.1 !== '1'
expect($x)->toMatch($pattern);compares$xto regular expression$pattern
expect($x)->toBeNull();checks to see if$x === null
expect($x)->toBeTruthy();checks if$x === true
expect($x)->toBeFalsy();checks if$x === false
expect($x)->toContain($y);checks to see if(array) $xcontains$y. Runs array_key_exists && in_array
expect($x)->toBeLessThan($y);checks to see if$x < $y
expect($x)->toBeGreaterThan($y);checks to see if$x > $y
expect($x)->toBeEmpty();runs empty
expect($x)->toBeString();runs is_string
expect($x)->toBeInteger();runs is_int
expect($x)->toBeArray();runs is_array
expect($x)->toBeInstanceOf();runs instanceof type operator
You can invert any of the matches by using
expect($x)->not->toEqual($y)
To create custom matchers run this in your spec file.
<?php
/**
* Checks to match length
*
* @param $actual the value passed into expect()
* @param $expected the value passed into ->toBeLength()
* @author Baylor Rae'
*/
Huck::addMatcher('toBeLength', function($actual, $expected) {
if( !is_array($actual) && !is_array($expected) )
return false;
return count($actual) === count($expected);
});
?>