Phew is Jasmine-like testing framework for PHP. For now it's in exploring stage.
The goal of this project is to write tests as easily as in Jasmine.
<?php
describe('Phew', function () {
it('should be easy to write PHP tests', function () {
expect('writing PHP tests')->not->toBe('difficult');
});
});
It is highly recommended to install Phew using Composer - http://getcomposer.org/.
Run following commands:
$ 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.
Phew is designed to be as similar as possible to Jasmine. The biggest differences are caused by differences between PHP and JS:
- 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 :)
There is for now only basic set of matchers:
- toBe
- toBeNull
- toBeTrue
- toBeFalse
- toEqual
- toBeEmpty
- toBeTruthy
- toBeFalsy
- toBeA
- toBeAn (alias of toBeA)
- toBeInstanceOf (alias of toBeA)
- toImplement (alias of toBeA)
- toStartsWith
- toMatch
It is quiet simple to add custom matcher. Your matcher have to implement the Phew\Matchers\Matcher interface and you have to register it.
Sample matcher:
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:
\Phew\Expectations\Expectation::addMatcher('toBeGreaterThan', 'GreaterThanMatcher');
Copyright (c) 2013 Jan Voracek. This software is licensed under the MIT License.