Download the PHP package xp-forge/assert without Composer
On this page you can find all versions of the php package xp-forge/assert. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download xp-forge/assert
More information about xp-forge/assert
Files in xp-forge/assert
Package assert
Short Description Assertions for the XP Framework
License BSD-3-Clause
Homepage http://xp-framework.net/
Informations about the package assert
Assertions
Flexible assertions on top of the XP Framework's unittest package.
Example
Running this test will yield one succeeded and one failed test. The difference to regular unittest messages is the more readable format.
On top of that, this library's assertions are also more flexible: As seen in the above case, we wrapped the chain in an All::of()
call which will yield all failed assertions, not just the first one.
`
Assertions
Generic assertions:
is(unittest.assert.Condition $condition)
- Asserts a given condition matchesisNot(unittest.assert.Condition $condition)
- Asserts a given condition does not matchisEqualTo(var $compare)
- Asserts the value is equal to a given comparisonisNotEqualTo(var $compare)
- Asserts the value is not equal to a given comparisonisNull()
- Asserts the value is nullisTrue()
- Asserts the value is trueisFalse()
- Asserts the value is falseisIn(var $enumerable)
- Asserts the value is in a given enumerableisNotIn(var $enumerable)
- Asserts the value is not in a given enumerableisInstanceOf(string|lang.Type $type)
- Asserts the value is of a given type
With special meanings dependant on type:
isEmpty()
- Asserts a string, array or map is emptyhasSize(int $size)
- Asserts a string length, array or map sizestartsWith(var $element)
- Asserts a string or array contains the given element at its startendsWith(var $element)
- Asserts a string or array contains the given element at its endcontains(var $element)
- Asserts a string, array or map contains a given elementdoesNotContain(var $element)
- Asserts a string, array or map does not contain a given element
For numbers:
isGreaterThan(int|double $comparison)
- Asserts value > comparisonisLessThan(int|double $comparison)
- Asserts value < comparisonisBetween(int|double $start, int|double $end)
- Asserts value >= start && value <= endisCloseTo(int|double $comparison, int|double $tolerance)
- Asserts value is close (defined per tolerance)
Transformations
Values can be transformed prior to invoking assertions on them.
Extraction works directly on instances (using properties and get
-prefixed as well as plain getters):
You can also pass a closure to control more precisely what's extracted:
For maps, extraction accesses the elements by their string keys:
Passing an array to extracting()
will extract multiple elements and return them in an array in the order they're passed:
Passing maps to extracting()
will extract multiple elements and return them in a map.
For arrays, the extracting()
method applies the extraction on every element: