Download the PHP package andreasindal/limerence without Composer
On this page you can find all versions of the php package andreasindal/limerence. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download andreasindal/limerence
More information about andreasindal/limerence
Files in andreasindal/limerence
Package limerence
Short Description A BDD-style testing framework for PHP.
License MIT
Informations about the package limerence
Limerence
Limerence is a BDD/TDD testing library for PHP heavily inspired by mocha and chai.
Installation
Installation through Composer is recommended. To add Limerence to your project, simply run:
$ composer require --dev andreasindal/limerence
And then, to run your tests, run:
$ vendor/bin/limerence
Alternatively, you can install Limerence globally:
$ composer global require andreasindal/limerence
With Limerence installed globally, you can easily run your tests from the root of your project by simply typing limerence
.
Content
-
Assertions
equal
be
have
contain
-
Negating
- HTTP Requests
request(method[, endpoint])
expect(status)
protocol(protocol)
at(hostname)
on(port)
get(endpoint)
,post(endpoint)
,put(endpoint)
,patch(endpoint)
, anddelete(endpoint)
send(data[, json])
with(header, value)
Usage
Limerence expect you to have all of your tests inside a directory called either test or tests in the root of your project, but you can use how many subdirectories you wish.
Testing
Limerence is very to use, and everything you type will feel natural. There are mainly four functions that are used in a test: test()
, describe()
, it()
and expect()
, and they are all used in conjunction to each other.
test()
The test()
function defines the boundaries of a test suite.
describe()
The describe()
function defines the boundaries of a test case.
it()
The it()
function describes the expectation of the test.
expect()
The expect()
function makes the assertion.
Example
Dog.php
dogTest.php
Here, we're expecting the Dog object to have a method called makeSound(), and that it returns a string that equals "Woof woof!". If we run the test, we'll get the following output:
Assertions
A wide variety of assertions is available with Limerence.
equal(value)
be(value)
Be can assert the following types: string, number, int, integer, long, bool, boolean, float, double, real, object, array, callable, null, empty, file, writable.
There's also an alias for a
to make it look good when the expectation starts with a vowel:
You can also call be($value)
directly if a/an doesn't make sense.
(Note that both expect($user->age)->to->be->a('integer')
and expect($user->age)->to->be('integer')
would still work.)
have(value)
The have method can be used to assert properties and methods of objects.
contain(value|values)
Contain can be used to check if an array contain certain values or keys.
which is the same as
You can also check keys by calling
Contain can be used to check multiple keys/values as well by passing it an array as argument:
Negating
All assertions can be negated by adding not
to the assertion chain, and will behave as expected. For example:
or
HTTP Requests
Limerence also includes functionality to test HTTP requests, which can be particularly useful when testing REST APIs. The protocol defaults to http, hostname defaults to localhost, port defaults to 80, request method defaults to GET. Example:
request(method[, endpoint])
expect(status)
The expect function makes an assertion of the response status code.
protocol(protocol)
Sets the protocol of the request. Can be either http or https. Defaults to http.
at(hostname)
Sets the target hostname of the request. Defaults to localhost.
on(port)
Sets the target port of the request. Defaults to 80.
Short hand helpers
There's also short hand functions for GET, POST, PUT, PATCH and DELETE requests, for example:
send(data[, json])
To send data, use the send function. It accepts an array of key/value pairs with the data, and optionally a flag that tells Limerence to send the data as JSON. If you set the json to true, it will automatically include a Content-type: application/json
header for you. Example:
with(header, value)
To attach a header to the request, simply use the with
function. It takes a key and a value, for example:
end(callback)
The request is dispatched when the end
method is called, which accepts a callback. Two variables will be passed to the callback, the first one contains any errors that occurs, and the second one is the Response object. Inside the callback, you should put all of your assertions.
License
MIT.