expect / expect
Expectation library for unit testing
Installs: 8 621
Dependents: 3
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=5.6.0
- hassankhan/config: ~0.10
- yosymfony/toml: ~0.3
Requires (Dev)
- beberlei/assert: ~2.5
- cloak/peridot-cloak-plugin: ~2.0
- cloak/robo-coveralls-kit: ~2.1
- codegyre/robo: ~0.7
- holyshared/peridot-file-fixture-plugin: ~1.0
- holyshared/robo-peridot: ~2.0
- peridot-php/peridot: ~1.18
- peridot-php/peridot-dot-reporter: ~1.0
- phpspec/prophecy: ~1.6
README
Basic usage
use expect\Expect; use expect\configurator\FileConfigurator; $configurator = new FileConfigurator(__DIR__ . '/.expect.toml'); Expect::configure($configurator); Expect::that(true)->toEqual(true); //pass Expect::that(false)->toEqual(true); //failed
Configuration file
You can specify the matcher package and a reporter to be used in the configuration file.
Configuration file in toml format, examples are as follows.
packages = [ "\\expect\\fixture\\package\\CustomPackageRegistrar" ] reporter = "\\expect\\reporter\\ExceptionReporter"
Learn detailed document
- API Document - http://expectation-php.github.io/expect/
- Matcher packages
Other recommended library
If you did not like this library, please try the following library.
- Leo - Assertions and matcher library, in peridot and affinity is good.
- Assert - Simple assertion library, Assertion api is easy to use with simple.
All of matcher
toEqual
Expect::that(true)->toEqual(true); //pass Expect::that(false)->toEqual(true); //failed
toBeTrue
Expect::that(true)->toBeTrue(); //pass Expect::that(false)->toBeTrue(); //failed
toBeFalse
Expect::that(false)->toBeFalse(); //pass Expect::that(true)->toBeFalse(); //failed
toBeNull
Expect::that(null)->toBeNull(); //pass Expect::that(100)->toBeNull(); //failed
toBeAnInstanceOf
Expect::that(new ToEqual(true))->toBeAnInstanceOf('expect\Mathcer'); //pass Expect::that(new stdClass)->toBeAnInstanceOf('expect\Mathcer'); //failed
toBeAn / toBeA
Expect::that(1)->toBeAn('integer'); //pass Expect::that('foo')->toBeAn('integer'); //failed Expect::that('foo')->toBeInteger(); //failed
Expect::that('foo')->toBeAn('string'); //pass Expect::that(1)->toBeAn('string'); //failed Expect::that('foo')->toBeString(); //failed
Expect::that(1.1)->toBeAn('float'); //pass Expect::that('foo')->toBeAn('float'); //failed Expect::that('foo')->toBeFloat(); //failed
Expect::that(true)->toBeAn('boolean'); //pass Expect::that('foo')->toBeAn('boolean'); //failed Expect::that('foo')->toBeBoolean(); //failed
Expect::that(1)->toBeA('integer'); //pass Expect::that('foo')->toBeA('integer'); //failed
Expect::that([])->toBeA('array'); //pass Expect::that('foo')->toBeArray('array'); //failed
toMatch
Expect::that('foobar')->toMatch('/foo/'); //pass Expect::that('foobar')->toMatch('/cat/'); //failed
toStartWith
Expect::that('foobar')->toStartWith('foo'); //pass Expect::that('foobar')->toStartWith('cat'); //failed
toEndWith
Expect::that('foobar')->toEndWith('bar'); //pass Expect::that('foobar')->toEndWith('cat'); //failed
toHaveLength
Expect::that('foobar')->toHaveLength(6); //pass Expect::that('foobar')->toHaveLength(5); //failed
Expect::that([ 1 ])->toHaveLength(1); //pass Expect::that([ 1, 2 ])->toHaveLength(3); //failed
Expect::that(new ArrayIterator([ 1 ]))->toHaveLength(1); //pass Expect::that(new ArrayIterator([ 1, 2 ]))->toHaveLength(3); //failed
toBeEmpty
Expect::that([])->toBeEmpty(); //pass Expect::that([ 1 ])->toBeEmpty(); //failed
toPrint
Expect::that(function () { echo 'foo'; })->toPrint('foo'); //pass Expect::that(function () { echo 'bar'; })->toPrint('foo'); //failed
toBeGreaterThan / toBeAbove
Expect::that(11)->toBeGreaterThan(10); //pass Expect::that(10)->toBeGreaterThan(10); //pass Expect::that(9)->toBeGreaterThan(10); //failed
Expect::that(11)->toBeAbove(10); //pass Expect::that(10)->toBeAbove(10); //pass Expect::that(9)->toBeAbove(10); //failed
toBeLessThan / toBeBelow
Expect::that(9)->toBeLessThan(10); //pass Expect::that(10)->toBeLessThan(10); //failed
Expect::that(9)->toBeBelow(10); //pass Expect::that(10)->toBeBelow(10); //failed
toBeWithin
Expect::that(11)->toBeWithin(10, 20); //pass Expect::that(9)->toBeWithin(10, 20); //failed Expect::that(21)->toBeWithin(10, 20); //failed
toContain
Expect::that('foo')->toContain('foo'); //pass Expect::that('foo')->toContain('foo', 'bar'); //failed
Expect::that([ 'foo', 'bar' ])->toContain('foo'); //pass Expect::that([ 'foo', 'bar' ])->toContain('foo', 'bar'); //pass Expect::that([ 'foo', 'bar' ])->toContain('foo', 'bar', 'bar1'); //failed
toHaveKey
Expect::that([ 'foo' => 1 ])->toHaveKey('foo'); //pass Expect::that([ 'foo' => 1 ])->toHaveKey('bar'); //failed
ToBeTruthy
Expect::that(true)->ToBeTruthy(); //pass Expect::that('')->ToBeTruthy(); //pass Expect::that(0)->ToBeTruthy(); //pass Expect::that(false)->ToBeTruthy(); //failed
ToBeFalsey
Expect::that(false)->ToBeFalsey(); //pass Expect::that(null)->ToBeFalsey(); //pass Expect::that('')->ToBeFalsey(); //failed Expect::that(0)->ToBeFalsey(); //failed