Phew
Phew is Jasmine-like testing framework for PHP. For now it's in exploring stage., (*1)
The goal of this project is to write tests as easily as in Jasmine., (*2)
, (*3)
Code Sample
<?php
describe('Phew', function () {
it('should be easy to write PHP tests', function () {
expect('writing PHP tests')->not->toBe('difficult');
});
});
Installation
It is highly recommended to install Phew using Composer - http://getcomposer.org/., (*4)
Run following commands:, (*5)
$ composer global require janvoracek/phew:dev-master
Try to run phew
. If the command is not found, you have to add
$HOME/.composer/vendor/bin
(Mac) or %APPDATA%/Composer/bin
(Win) to your PATH., (*6)
Specs
Phew is designed to be as similar as possible to Jasmine.
The biggest differences are caused by differences between PHP and JS:, (*7)
- Different object operator. JS uses "dot" (
.
), PHP uses "arrow" (->
).
- The
use
statement for closures. It makes the tests looking not so good. Deal with it :)
Matchers
There is for now only basic set of matchers:, (*8)
Strict equality matchers
- toBe
- toBeNull
- toBeTrue
- toBeFalse
Loose equality matchers
- toEqual
- toBeEmpty
- toBeTruthy
- toBeFalsy
Type matchers
- toBeA
- toBeAn (alias of toBeA)
- toBeInstanceOf (alias of toBeA)
- toImplement (alias of toBeA)
String matchers
Custom matchers
It is quiet simple to add custom matcher. Your matcher have to implement
the Phew\Matchers\Matcher interface and you have to register it., (*9)
Sample matcher:, (*10)
class GreaterThanMatcher implements Matcher {
/** @var number */
private $minimum;
/** @var number */
private $actual;
public function __construct($minimum = null) {
$this->minimum = $minimum;
}
public function matches($actual) {
$this->actual = $actual;
return $actual > $this->minimum;
}
public function getFailureMessage() {
return "Expected {$this->actual} to be greater than {$this->minimum}";
}
public function getNegativeFailureMessage() {
return "Expected {$this->actual} not to be greater than {$this->minimum}";
}
}
Registering:, (*11)
\Phew\Expectations\Expectation::addMatcher('toBeGreaterThan', 'GreaterThanMatcher');
Copyright (c) 2013 Jan Voracek. This software is licensed under the MIT License., (*12)