|  Download Webmozart Assert        
 Latest release: 1.1.0 PHP >= 5.3.9 This library contains efficient assertions to test the input and output of
your methods. With these assertions, you can greatly reduce the amount of coding
needed to write a safe implementation. All assertions in the [Assert] class throw an\InvalidArgumentExceptionif 
they fail. FAQWhat's the difference to [beberlei/assert]? This library is heavily inspired by Benjamin Eberlei's wonderful [assert package],
but fixes a usability issue with error messages that can't be fixed there without
breaking backwards compatibility. This package features usable error messages by default. However, you can also 
easily write custom error messages: Assert::string($path, 'The path is expected to be a string. Got: %s');
 In [beberlei/assert], the ordering of the %splaceholders is different for 
every assertion. This package, on the contrary, provides consistent placeholder 
ordering for all assertions: 
`%s`: The tested value as string, e.g. `"/foo/bar"`.
`%2$s`, `%3$s`, ...: Additional assertion-specific values, e.g. the
minimum/maximum length, allowed values, etc.
 Check the source code of the assertions to find out details about the additional
available placeholders. InstallationUse [Composer] to install the package: $ composer require webmozart/assert
 Exampleuse Webmozart\Assert\Assert;
class Employee
{
    public function __construct($id)
    {
        Assert::integer($id, 'The employee ID must be an integer. Got: %s');
        Assert::greaterThan($id, 0, 'The employee ID must be a positive integer. Got: %s');
    }
}
 If you create an employee with an invalid ID, an exception is thrown: new Employee('foobar');
// => InvalidArgumentException: 
//    The employee ID must be an integer. Got: string
new Employee(-10);
// => InvalidArgumentException: 
//    The employee ID must be a positive integer. Got: -10
 AssertionsThe [Assert] class provides the following assertions: Type AssertionsMethod                                          | Description
----------------------------------------------- | --------------------------------------------------
string($value, $message = '')| Check that a value is a stringstringNotEmpty($value, $message = '')| Check that a value is a non-empty stringinteger($value, $message = '')| Check that a value is an integerintegerish($value, $message = '')| Check that a value casts to an integerfloat($value, $message = '')| Check that a value is a floatnumeric($value, $message = '')| Check that a value is numericboolean($value, $message = '')| Check that a value is a booleanscalar($value, $message = '')| Check that a value is a scalarobject($value, $message = '')| Check that a value is an objectresource($value, $type = null, $message = '')| Check that a value is a resourceisCallable($value, $message = '')| Check that a value is a callableisArray($value, $message = '')| Check that a value is an arrayisTraversable($value, $message = '')| Check that a value is an array or a\TraversableisInstanceOf($value, $class, $message = '')| Check that a value is aninstanceofa classnotInstanceOf($value, $class, $message = '')| Check that a value is not aninstanceofa class Comparison AssertionsMethod                                          | Description
----------------------------------------------- | --------------------------------------------------
true($value, $message = '')| Check that a value istruefalse($value, $message = '')| Check that a value isfalsenull($value, $message = '')| Check that a value isnullnotNull($value, $message = '')| Check that a value is notnullisEmpty($value, $message = '')| Check that a value isempty()notEmpty($value, $message = '')| Check that a value is notempty()eq($value, $value2, $message = '')| Check that a value equals another (==)notEq($value, $value2, $message = '')| Check that a value does not equal another (!=)same($value, $value2, $message = '')| Check that a value is identical to another (===)notSame($value, $value2, $message = '')| Check that a value is not identical to another (!==)greaterThan($value, $value2, $message = '')| Check that a value is greater than anothergreaterThanEq($value, $value2, $message = '')| Check that a value is greater than or equal to anotherlessThan($value, $value2, $message = '')| Check that a value is less than anotherlessThanEq($value, $value2, $message = '')| Check that a value is less than or equal to anotherrange($value, $min, $max, $message = '')| Check that a value is within a rangeoneOf($value, array $values, $message = '')| Check that a value is one of a list of values String AssertionsYou should check that a value is a string with Assert::string()before making
any of the following assertions. Method                                              | Description
--------------------------------------------------- | --------------------------------------------------
contains($value, $subString, $message = '')| Check that a string contains a substringstartsWith($value, $prefix, $message = '')| Check that a string has a prefixstartsWithLetter($value, $message = '')| Check that a string starts with a letterendsWith($value, $suffix, $message = '')| Check that a string has a suffixregex($value, $pattern, $message = '')| Check that a string matches a regular expressionalpha($value, $message = '')| Check that a string contains letters onlydigits($value, $message = '')| Check that a string contains digits onlyalnum($value, $message = '')| Check that a string contains letters and digits onlylower($value, $message = '')| Check that a string contains lowercase characters onlyupper($value, $message = '')| Check that a string contains uppercase characters onlylength($value, $length, $message = '')| Check that a string has a certain number of charactersminLength($value, $min, $message = '')| Check that a string has at least a certain number of charactersmaxLength($value, $max, $message = '')| Check that a string has at most a certain number of characterslengthBetween($value, $min, $max, $message = '')| Check that a string has a length in the given rangeuuid($value, $message = '')| Check that a string is a valid UUID File AssertionsMethod                              | Description
----------------------------------- | --------------------------------------------------
fileExists($value, $message = '')| Check that a value is an existing pathfile($value, $message = '')| Check that a value is an existing filedirectory($value, $message = '')| Check that a value is an existing directoryreadable($value, $message = '')| Check that a value is a readable pathwritable($value, $message = '')| Check that a value is a writable path Object AssertionsMethod                                                | Description
----------------------------------------------------- | --------------------------------------------------
classExists($value, $message = '')| Check that a value is an existing class namesubclassOf($value, $class, $message = '')| Check that a class is a subclass of anotherimplementsInterface($value, $class, $message = '')| Check that a class implements an interfacepropertyExists($value, $property, $message = '')| Check that a property exists in a class/objectpropertyNotExists($value, $property, $message = '')| Check that a property does not exist in a class/objectmethodExists($value, $method, $message = '')| Check that a method exists in a class/objectmethodNotExists($value, $method, $message = '')| Check that a method does not exist in a class/object Array AssertionsMethod                                      | Description
------------------------------------------- | --------------------------------------------------
keyExists($array, $key, $message = '')| Check that a key exists in an arraykeyNotExists($array, $key, $message = '')| Check that a key does not exist in an array Collection AssertionsAll of the above assertions can be prefixed with all*()to test the contents
of an array or a\Traversable: Assert::allIsInstanceOf('Acme\Employee', $employees);
 Nullable AssertionsAll of the above assertions can be prefixed with nullOr*()to run the
assertion only if it the value is notnull: Assert::nullOrString($middleName, 'The middle name must be a string or null. Got: %s');
 Authors
[Bernhard Schussek] a.k.a. [@webmozart]
[The Community Contributors]
 ContributeContributions to the package are always welcome! 
Report any bugs or issues you find on the [issue tracker].
You can grab the source code at the package's [Git repository].
 SupportIf you are having problems, send a mail to [email protected] or shout out to
[@webmozart] on Twitter. LicenseAll contents of this package are licensed under the [MIT license]. [beberlei/assert]: https://github.com/beberlei/assert
[assert package]: https://github.com/beberlei/assert
[Composer]: https://getcomposer.org
[Bernhard Schussek]: http://webmozarts.com
[The Community Contributors]: https://github.com/webmozart/assert/graphs/contributors
[issue tracker]: https://github.com/webmozart/assert
[Git repository]: https://github.com/webmozart/assert
[@webmozart]: https://twitter.com/webmozart
[MIT license]: LICENSE
[Assert]: src/Assert.php |