Download the PHP package karriere/phpspec-matchers without Composer
On this page you can find all versions of the php package karriere/phpspec-matchers. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package phpspec-matchers
Collection of phpspec Matchers
This package contains a collection of additional phpspec matchers.
Installation
You can install the package via composer
To be able to use the matchers you need to add the following definition to your phpspec.yml
Matcher Usage
All custom matchers in this package implement the positive and the negative case. For example you can use:
and also
Matchers
General Matchers
- beAnyOf
- beSomeOf
- rangeBetween
- beEmpty
- beNull
- beLessThan
- beGreaterThan
Json Matchers
- beJson
- haveJsonKey
- haveJsonKeyWithValue
General Matchers
beAnyOf
This matcher allows to check the return value against a set of values.
Assume you have some sort of random mechanism to get an integer between 2 and 4. The you can use the shouldBeAnyOf
matcher:
beSomeOf
This matcher allows to check if the returned array values are contained in a set of values.
rangeBetween
This matcher allows to check if the given return value is inside a numeric range.
beEmpty
This matcher allows to check if the given return value is empty. The implementation uses the empty implementation.
beNull
This matcher allows to check if the given return value is null. The implementation uses the is_null implementation.
beLessThan
This matcher allows to check if the given return value is less than a specified value.
beGreaterThan
This matcher allows to check if the given return value is greater than a specified value.
Json Matchers
beJson
This matcher checks if the return value is a valid json string
haveJsonKey
This matcher checks if the returned json string contains a json key.
To match against subkey you can use the dot notation. For example let's assume the following json structure
The key for this check is 'key.subkey'
haveJsonKeyWithValue
This matcher checks if the returned json string contains the json key and the desired value. The dot syntax for subkeys can also be applied.
License
Apache License 2.0 Please see LICENSE for more information.