Assertions
The Xmf\Assert
class provides the following assertions:
Type Assertions
Method | Description |
| Check that a value is a string |
| Check that a value is a non-empty string |
| Check that a value is an integer |
| Check that a value casts to an integer |
| Check that a value is a float |
| Check that a value is numeric |
| Check that a value is a non-negative integer |
| Check that a value is a boolean |
| Check that a value is a scalar |
| Check that a value is an object |
| Check that a value is a resource |
| Check that a value is a callable |
| Check that a value is an array |
| Check that a value is an array or a |
| Check that a value is an array or a |
| Check that a value is an array or a |
| Check that a value is an |
| Check that a value is an |
| Check that a value is not an |
| Check that a value is of the class or has one of its parents |
| Check that a value is of at least one of the classes or has one of its parents |
| Check that a value is not of the class or has not one of its parents |
| Check that a value can be accessed as an array |
| Check that the given array contains unique values |
Comparison Assertions
Method | Description |
| Check that a value is |
| Check that a value is |
| Check that a value is not |
| Check that a value is |
| Check that a value is not |
| Check that a value is |
| Check that a value is not |
| Check that a value equals another ( |
| Check that a value does not equal another ( |
| Check that a value is identical to another ( |
| Check that a value is not identical to another ( |
| Check that a value is greater than another |
| Check that a value is greater than or equal to another |
| Check that a value is less than another |
| Check that a value is less than or equal to another |
| Check that a value is within a range |
| Check that a value is one of a list of values |
| Check that a value is one of a list of values (alias of |
String Assertions
You should check that a value is a string with Assert::string()
before making any of the following assertions.
Method | Description |
| Check that a string contains a substring |
| Check that a string does not contain a substring |
| Check that a string has a prefix |
| Check that a string does not have a prefix |
| Check that a string starts with a letter |
| Check that a string has a suffix |
| Check that a string does not have a suffix |
| Check that a string matches a regular expression |
| Check that a string does not match a regular expression |
| Check that a string contains Unicode letters only |
| Check that a string contains letters only |
| Check that a string contains digits only |
| Check that a string contains letters and digits only |
| Check that a string contains lowercase characters only |
| Check that a string contains uppercase characters only |
| Check that a string has a certain number of characters |
| Check that a string has at least a certain number of characters |
| Check that a string has at most a certain number of characters |
| Check that a string has a length in the given range |
| Check that a string is a valid UUID |
| Check that a string is a valid IP (either IPv4 or IPv6) |
| Check that a string is a valid IPv4 |
| Check that a string is a valid IPv6 |
| Check that a string is a valid e-mail address |
| Check that a string contains at least one non-whitespace character |
File Assertions
Method | Description |
| Check that a value is an existing path |
| Check that a value is an existing file |
| Check that a value is an existing directory |
| Check that a value is a readable path |
| Check that a value is a writable path |
Object Assertions
Method | Description |
| Check that a value is an existing class name |
| Check that a class is a subclass of another |
| Check that a value is an existing interface name |
| Check that a class implements an interface |
| Check that a property exists in a class/object |
| Check that a property does not exist in a class/object |
| Check that a method exists in a class/object |
| Check that a method does not exist in a class/object |
Array Assertions
Method | Description |
| Check that a key exists in an array |
| Check that a key does not exist in an array |
| Check that a value is a valid array key (int or string) |
| Check that an array contains a specific number of elements |
| Check that an array contains at least a certain number of elements |
| Check that an array contains at most a certain number of elements |
| Check that an array has a count in the given range |
| Check that an array is a non-associative list |
| Check that an array is a non-associative list, and not empty |
| Check that an array is associative and has strings as keys |
| Check that an array is associative and has strings as keys, and is not empty |
Function Assertions
Method | Description |
| Check that a function throws a certain exception. Subclasses of the exception class will be accepted. |
Collection Assertions
All of the above assertions can be prefixed with all*()
to test the contents of an array or a \Traversable
:
Nullable Assertions
All of the above assertions can be prefixed with nullOr*()
to run the assertion only if it the value is not null
:
Credits
Xmf\Assert depends on webmozart/assert
This documentation is derived from the webmozart/assert documentation which is licensed as follows:
The MIT License (MIT)
Copyright (c) 2014 Bernhard Schussek
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Last updated