webmozart/assert
Assertions to validate method input/output with nice error messages.
2.4.1
954M downloads/mo
#87 most downloaded on composer
webmozarts/assert
What this package is like to depend on
Last release 2 months ago
15 Jun 2026
Ships unpredictably
gaps range from 9 days to 3.4 years
Nearly every release is documented
notes for 28 of 29 stable releases
Nothing withdrawn
no release was ever pulled
11 years old
31 releases · first in 2015
15 releases in the last 12 months
see the full history below
Release timeline
31 releases · Mar 2015 to Jun 2026Releases
latest 31-
2.4.115 Jun 2026Release notes
Open source →Fixed
- Corrected
uuidassertion to prevent braces and prefixes being inside the value.
- Corrected
-
2.4.020 May 2026Release notes
Open source →Changed
- Updated docblocks for many methods, improving psalm support and type hints.
-
2.3.011 Apr 2026Release notes
Open source →Changed
- Clarified documentation and testing of
uniqueValues.
Added
- All assertions now support
string|callablefor the message.
- Clarified documentation and testing of
-
2.2.009 Apr 2026 -
2.1.627 Feb 2026 -
2.1.518 Feb 2026 -
2.1.417 Feb 2026 -
2.1.313 Feb 2026Release notes
Open source →Fixed
- Corrected
isListtype documentation. - Corrected
isAOf,isInstanceOf, etc type documentation.
- Corrected
-
2.1.213 Jan 2026 -
2.1.108 Jan 2026 -
2.1.007 Jan 2026Release notes
Open source →Fixed
- Corrected
@paramdeclaration forisMap. - Pass custom message to internal assertion calls.
- Corrected
-
2.0.016 Dec 2025Release notes
Open source →Changed
- BREAKING Minimum PHP version is now 8.2 (was 7.2).
- BREAKING Remove deprecated
isTraversable, useisIterableorisInstanceOfinstead. - BREAKING Added
declare(strict_types=1)to all classes. - Updated CI/CD test matrix to test PHP 8.2, 8.3, 8.4, and 8.5.
- Updated development tools (PHPUnit, Psalm, PHP-CS-Fixer) to supported versions.
- Added explicit return types and parameter types to all methods in both source code and tests.
Added
- All assertion methods now return the checked value.
- Added
notInArrayandnotOneOf. - Added
isInitialized, to check if a class property is initialized. - Added
negativeIntegerandnotNegativeInteger - Added
isStaticandnotStatic
Fixed
- Corrected validation of emails with unicode characters.
-
2.0.0-beta03 Dec 2025 pre-releaseNothing published for this version
-
1.12.129 Oct 2025 -
1.12.020 Oct 2025Release notes
Open source →Fixed
- Corrected messages and typos in various assertions.
- Document
voidreturn type. - Prevent UUIDs with trailing newlines from validating.
- Assert values are strings before ctype checks.
-
1.11.003 Jun 2022Release notes
Open source →Added
- Added explicit (non-magic)
allNullOr*methods, with@psalm-assertannotations, for better Psalm support.
Changed
- Trait methods will now check the assertion themselves, instead of using
__callStatic isListwill now deal correctly with (modified) lists that containNaNreportInvalidArgumentnow has a return type ofnever.
Removed
- Removed
symfony/polyfill-ctypeas a dependency, and requireext-ctypeinstead.- You can still require the
symfony/polyfill-ctypein your project if you need it, as it providesext-ctype
- You can still require the
- Added explicit (non-magic)
-
1.10.009 Mar 2021Release notes
Open source →Added
- On invalid assertion, we throw a
Webmozart\Assert\InvalidArgumentException - Added
Assert::positiveInteger()
Changed
- Using a trait with real implementations of
all*()andnullOr*()methods to improve psalm compatibility.
Removed
- Support for PHP <7.2
- On invalid assertion, we throw a
-
1.9.108 Jul 2020Nothing published for this version
-
1.9.016 Jun 2020Release notes
Open source →- added better Psalm support for
all*&nullOr*methods - These methods are now understood by Psalm through a mixin. You may need a newer version of Psalm in order to use this
- added
@psalm-pureannotation toAssert::notFalse() - added more
@psalm-assertannotations where appropriate
- added better Psalm support for
-
1.8.018 Apr 2020Release notes
Open source →Added
- added
Assert::notStartsWith() - added
Assert::notEndsWith() - added
Assert::inArray() - added
@psalm-pureannotations to pure assertions
Fixed
- Exception messages of comparisons between
DateTime(Immutable)objects now display their date & time. - Custom Exception messages for
Assert::count()now use the values to render the exception message.
- added
-
1.7.014 Feb 2020Release notes
Open source →Added
- added
Assert::notFalse() - added
Assert::isAOf() - added
Assert::isAnyOf() - added
Assert::isNotA()
- added
-
1.6.024 Nov 2019Release notes
Open source →Added
- added
Assert::validArrayKey() - added
Assert::isNonEmptyList() - added
Assert::isNonEmptyMap() - added
@throws InvalidArgumentExceptionannotations to all methods that throw. - added
@psalm-assertfor the list type to theisListassertion.
Fixed
ResourceBundle&SimpleXMLElementnow pass theisCountableassertions. They are countable, without implementing theCountableinterface.- The doc block of
rangenow has the proper variables. - An empty array will now pass
isListandisMap. As it is a valid form of both. If a non-empty variant is needed, useisNonEmptyListorisNonEmptyMap.
Changed
- added
-
1.5.024 Aug 2019Release notes
Open source →Added
- added
Assert::uniqueValues() - added
Assert::unicodeLetters() - added:
Assert::email() - added support for Psalm, by adding
@psalm-assertannotations where appropriate.
Fixed
Assert::endsWith()would not give the correct result when dealing with a multibyte suffix.Assert::length(), minLength, maxLength, lengthBetweenwould not give the correct result when dealing with multibyte characters.
NOTE: These 2 changes may break your assertions if you relied on the fact that multibyte characters didn't behave correctly.
Changed
- The names of some variables have been updated to better reflect what they are.
- All function calls are now in their FQN form, slightly increasing performance.
- Tests are now properly ran against HHVM-3.30 and PHP nightly.
Deprecation
- deprecated
Assert::isTraversable()in favor ofAssert::isIterable()- This was already done in 1.3.0, but it was only done through a silenced
trigger_error. It is now annotated as well.
- This was already done in 1.3.0, but it was only done through a silenced
- added
-
1.4.025 Dec 2018Release notes
Open source →Added
- added
Assert::ip() - added
Assert::ipv4() - added
Assert::ipv6() - added
Assert::notRegex() - added
Assert::interfaceExists() - added
Assert::isList() - added
Assert::isMap() - added polyfill for ctype
Fixed
- Special case when comparing objects implementing
__toString()
- added
-
1.3.029 Jan 2018Release notes
Open source →Added
- added
Assert::minCount() - added
Assert::maxCount() - added
Assert::countBetween() - added
Assert::isCountable() - added
Assert::notWhitespaceOnly() - added
Assert::natural() - added
Assert::notContains() - added
Assert::isArrayAccessible() - added
Assert::isInstanceOfAny() - added
Assert::isIterable()
Fixed
stringNotEmptywill no longer report "0" is an empty string
Deprecation
- deprecated
Assert::isTraversable()in favor ofAssert::isIterable()
- added
-
1.2.023 Nov 2016Release notes
Open source →- added
Assert::throws() - added
Assert::count() - added extension point
Assert::reportInvalidArgument()for custom subclasses
- added
-
1.1.009 Aug 2016Release notes
Open source →- added
Assert::object() - added
Assert::propertyExists() - added
Assert::propertyNotExists() - added
Assert::methodExists() - added
Assert::methodNotExists() - added
Assert::uuid()
- added
-
1.0.224 Aug 2015Release notes
Open source →- integrated Style CI
- add tests for minimum package dependencies on Travis CI
-
1.0.112 May 2015 -
1.0.012 May 2015 -
1.0.0-beta19 Mar 2015 pre-release