Download the PHP package bound1ess/essence without Composer
On this page you can find all versions of the php package bound1ess/essence. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package essence
Essence 1.5.1
Essence is a very flexible BDD style assertion framework for PHP that fits into existing PHPUnit projects nicely.
Installation
The Idea
In most PHP testing frameworks, you are tied to concrete matcher names (e.g., assertEqual
, shouldHaveType
).
I don't like that.
That's why I created Essence.
Usage
In order to run a matcher you need to specify it in the query string. So what is a query string? Have a look:
Yes, Essence is smart enough to handle all these cases just as you would expect it to do. So, how do you build a query string (or assertion)?
- Decide if you need to configure a matcher you plan to use. As for now there are two only matchers that can be used in configuration mode -
ValuesMatcher
andKeysMatcher
. - Determine what matcher you will need to use to get the job done. Is it
ThrowMatcher
, or, say,RespondMatcher
? - Add some links to make the assertion readable.
- Choose an appropriate entry point (
expect
,this
,these
etc). - Pass a proper value and arguments.
- If you want to, add
->go()
to immediately perform validation. I'll tell you more about that later.
Configuration
First of all, Essence leverages the singleton pattern to persist all its important data during the runtime. It means that this expression will always be equal to true
:
You can configure Essence by using configure
method:
Available configuration options:
Name | Possible value |
---|---|
exception | fully qualified class name (as a string) |
implicit_validation | a boolean value (true or false ) |
links | an array (won't be merged automatically) |
matchers | an associative array name => aliases (won't be merged automatically) |
Explicit and implicit, validateAll and PHPUnit extension
If you don't want to write ->validate()
or ->go()
every time, you can enable implicit validation:
It will validate the last (previous) assertion when you create a new one. Or, even better, just use the PHPUnit extension as shown below:
It'll do the job for you, no need to configure anything or call go/validate
.
Verbose mode
This line of code will throw an Essence\Exceptions\AssertionException
by default:
However, if you pass true
to validate/go
, Essence will dump all important data and just exit
.
Cheatsheet
Entry points
- essence
- it
- that
- this
- these
- those
Links
- of
- have
- be
- at
- to
Matchers
Name | Aliases |
---|---|
TypeMatcher | an, a, type |
ContainMatcher | contain, include |
PositiveMatcher | ok, fine |
TrueMatcher | true |
FalseMatcher | false |
NullMatcher | null |
EmptyMatcher | empty |
EqualMatcher | equal |
LikeMatcher | like |
AboveMatcher | above |
BelowMatcher | below |
LeastMatcher | least |
MostMatcher | most |
WithinMatcher | within |
LengthMatcher | length |
MatchMatcher | match |
KeysMatcher | key, keys |
ValuesMatcher | value, values |
ThrowMatcher | throw, raise |
RespondMatcher | respond |
CloseMatcher | close |
License
The MIT License (MIT).
Development
The Makefile
contains all sorts of useful tasks.
Running tests
Creating code coverage report
Building documentation
All versions of essence with dependencies
php-packages/container Version ~1
php-packages/fluent Version ~1
php-packages/dumpy Version ~1