Download the PHP package star/structure-assertion without Composer
On this page you can find all versions of the php package star/structure-assertion. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download star/structure-assertion
More information about star/structure-assertion
Files in star/structure-assertion
Package structure-assertion
Short Description PHP Tool to assert array structure using the fluent interface
License MIT
Informations about the package structure-assertion
Structure assertion
PHP Tool for asserting array structures using the fluent interface.
Installation
Using Composer, run composer require --dev star/structure-assertion
.
Usage
This library is usefull when you have PHPUnit tests, and you want to assert some nodes of an array.
Construction methods
StructureAssertion::fromArray($array);
: Using the given array.StructureAssertion::fromJsonResponse($response);
: Build with a Response object that is assumed to have a JSON content.
Assertions methods
By convention, all assertion methods are named assert*
.
Under the hood, StructureAssertion uses PHPUnit assertions.
Many of the assertions are named after the PHPUnit's constraint.
You can use your own assertion if a specific one is not defined by using the StructureAssertion::assertCallback()
method.
ie.
Navigation methods
To navigate the nodes, you can use the methods that starts with enter*
. We assume that the current node is at the correct position.
StructureAssertion::exitNode()
: Move the internal pointer to the parent node.StructureAssertion::nextArrayElement()
: Shortcut forexitNode()->enterArrayElement($current + 1)
. Enters the next element at index + 1. Works only on integer indexed element.
Debugging methods
The lib also provide debugging method, in order to know the current position of the cursor.
StructureAssertion::dump($maxDepth = 2, $dumpStrategy)
: Will dump the current node using the$strategy
and up to$maxDepth
.StructureAssertion::dumpPath($dumpStrategy)
: Will dump the current node path using the$strategy
.StructureAssertion::dumpKeys($dumpStrategy)
: Will dump the current node keys using the$strategy
.
Contributing
Any contribution is welcome, just propose a Pull request, and we'll look into it.