Download the PHP package joebengalen/assert without Composer
On this page you can find all versions of the php package joebengalen/assert. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download joebengalen/assert
More information about joebengalen/assert
Files in joebengalen/assert
Package assert
Short Description Assertion library
License MIT
Homepage https://github.com/JoeBengalen/Assert
Informations about the package assert
Assert
As we all know when using an existing library we wish some things would be a little different. To make sure I can use assertions exactly how I feel is best, I created my own implementation.
The assert methods are meant to be used to check whether incoming arguments are what you expect them to be. If the variable does not meet the assertion an InvalidArgumentException
is thrown.
I needed all available assertions to be actual methods instead of virtual ones in the class PHPDoc, because virtual ones do not work properly with static methods in netbeans.
Installation
Via Composer
Usage
Custom exception messages
Sometimes you may want to throw the exception with a different message. This can be done by passing a second string argument into the assertion method.
The error messages are run trough sprintf()
, where the passed variable, transformed into a useful string, will be available.
Some assertion methods take additional arguments which are needed for the assertion. The custom message shall always be the latest argument. Additional arguments will also be passed into sprintf()
, in the order of the arguments. This means the value to assert will always be the first string passed into sprintf()
.
If you want to use the arguments in a different order in the message you can swap them by referring to their number.
For more information on swapping the arguments checkout the php documentation of sprintf().
Change log
Please see the CHANGELOG for more information what has changed recently.
Testing
This project uses PHPUnit for testing. PHPUnit is not included as requirement, so to run the tests phpunit has to be manually installed. The reason for this is that I prefer having phpunit installed globally.