Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/baylorrae/php-huck
A PHP Testing Framework based on Jasmine
https://github.com/baylorrae/php-huck
bdd php unit-testing
Last synced: about 19 hours ago
JSON representation
A PHP Testing Framework based on Jasmine
- Host: GitHub
- URL: https://github.com/baylorrae/php-huck
- Owner: BaylorRae
- Created: 2011-12-21T19:56:44.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2014-04-18T03:55:28.000Z (almost 11 years ago)
- Last Synced: 2023-03-11T04:44:57.652Z (almost 2 years ago)
- Topics: bdd, php, unit-testing
- Language: PHP
- Homepage:
- Size: 161 KB
- Stars: 5
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Huck
**A PHP Testing Framework**```php
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][jasmine_url]. It is designed for with a simple syntax to give it a low
learning curve.---
**WARNING**: This project should be considered _very dangerous_ and not be
used on any real projects. It is an experimental testing suite for PHP and may
break everything.DO NOT DEPEND ON IT FOR ANYTHING IMPORTANT.
## Features
Huck includes the `let` syntax from RSpec. Because tests are defined in a
procedural style, it's not possible to share common variables without using `global`.
To get around this you can define a variable with `let()` and the value will be
passed into your test.```php
describe("let() syntax", function() {// define the variable "user"
let('user', User::create(array('name' => 'Huck')));it("gets the user object", function($spec) {
expect($spec->user->name)->toEqual('Huck');
});// it resolves closures
let('user_new_name', function($spec) {
$user = $spec->user;
$user->name = 'Tom';
return $user;
});it("gets the value from a closure", function($spec) {
expect($spec->user_new_name->name)->toEqual('Tom');
});
});
```## How to Use
Huck can be executed via `bin/huck` and it can run against a directory or a
file.```bash
$ bin/huck spec
$ bin/huck spec/huck_suite_spec.php
```## Available Matchers
Huck includes most of the [matchers available in Jasmine][jasmine_matchers].> `expect($x)->toEqual($y);` checks to see if `$x` and `$y` have the same value
>
> `expect($x)->toBe($y);` checks to see if `$x` and `$y` are identical. e.g. `1 !== '1'`
>
> `expect($x)->toMatch($pattern);` compares `$x` to 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) $x` contains `$y`. Runs [array_key_exists][array_key_exists] && [in_array][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][empty]
>
> `expect($x)->toBeString();` runs [is_string][is_string]
>
> `expect($x)->toBeInteger();` runs [is_int][is_int]
>
> `expect($x)->toBeArray();` runs [is_array][is_array]
>
> `expect($x)->toBeInstanceOf();` runs [instanceof type operator][instanceof]You can invert any of the matches by using
expect($x)->not->toEqual($y)
## Custom Matchers
To create custom matchers run this in your spec file.```php
toBeLength()
* @author Baylor Rae'
*/
Huck::addMatcher('toBeLength', function($actual, $expected) {
if( !is_array($actual) && !is_array($expected) )
return false;
return count($actual) === count($expected);
});?>
```[jasmine_url]: https://github.com/pivotal/jasmine
[jasmine_matchers]: https://github.com/pivotal/jasmine/wiki/Matchers
[array_key_exists]: http://php.net/array_key_exists
[in_array]: http://php.net/in_array
[empty]: http://php.net/empty
[is_string]: http://php.net/is_string
[is_int]: http://php.net/is_int
[is_array]: http://php.net/is_array
[instanceof]: http://php.net/manual/en/language.operators.type.php