Download the PHP package danielstjules/pho without Composer
On this page you can find all versions of the php package danielstjules/pho. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download danielstjules/pho
More information about danielstjules/pho
Files in danielstjules/pho
Package pho
Short Description A BDD testing framework
License MIT
Homepage https://github.com/danielstjules/pho
Informations about the package pho
BDD test framework for PHP, inspired by Jasmine and RSpec. Features a familiar syntax, and a watch command to automatically re-run specs during development. It can also be extended with custom matchers and reporters.
- Installation
- Usage
- Writing Specs
- Running Specs
- Expectations/Matchers
- Custom Matchers
- Reporters
- Mocking
- Namespace
Installation
The following instructions outline installation using Composer. If you don't have Composer, you can download it from http://getcomposer.org/ If you're new to composer, make sure to add the vendor bin to your PATH:
To install pho, run:
Usage
Writing Specs
Pho exposes a DSL for organizing and writing your tests, which includes the
following functions: describe
, context
, it
, before
, after
, beforeEach
,
afterEach
and expect
. Equivalent functions for disabling specs and suites
also exist via xdescribe
, xcontext
and xit
.
To create a suite, describe
and context
can be used by passing them a
string and function. Both are interchangeable, though context is more often
nested in a describe to group some set of behaviour. it
is then used to create
a spec, or test.
A spec may contain multiple expectations or assertions, and will pass so long
as all assertions pass and no exception is uncaught. For asserting values in pho,
expect
can be used. The function accepts the value to be tested, and may be
chained with a handful of matchers.
Objects may be passed between suites and specs with php's use
keyword. Here's
an example:
Things can get a bit verbose when dealing with multiple objects that need to be
passed into closures with use
. To avoid such long lists of arguments, $this
can be used to set and retrieve values between suites and specs.
Hooks are available for running functions as setups and teardowns. before
is
ran prior to any specs in a suite, and after
, once all in the suite have been
ran. beforeEach
and afterEach
both run their closures once per spec. Note
that beforeEach
and afterEach
are both stackable, and will apply to specs
within nested suites. Furthermore, Global hooks may be defined in your bootstrap
file. For example, an afterEach hook in a bootstrap file will run after every
test in your suite.
Running Specs
By default, pho looks for specs in either a test
or spec
folder under the
working directory. It will recurse through all subfolders and run any files
ending with Spec.php
, ie: userSpec.php. Furthermore, continuous testing is as
easy as using the --watch
option, which will monitor all files in the path for
changes, and rerun specs on save.
Expectations/Matchers
Type Matching
Instance Matching
Strict Equality Matching
Loose Equality Matching
Length Matching
Inclusion Matching
Pattern Matching
Numeric Matching
Print Matching
Exception Matching
Custom Matchers
Custom matchers can be added by creating a class that implements
pho\Expectation\Matcher\MatcherInterface
and registering the matcher with
pho\Expectation\Expectation::addMatcher()
. Below is an example of a basic
matcher:
Registering it:
And that's it! You would now have access to the following:
Reporters
dot (default)
spec
list
Mocking
Pho doesn't currently provide mocks/stubs out of the box. Instead, it's suggested that a mocking framework such as prophecy or mockery be used.
Note: Tests can be failed from a test hook. If you need to check mock object expectations after running a spec, you can do so from an afterEach hook.
Namespace
If you'd rather not have pho use the global namespace for its functions, you
can set the --namespace
flag to force it to only use the pho namespace. This
will be a nicer alternative in PHP 5.6 with
https://wiki.php.net/rfc/use_function