Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Assert Laravel Package

simplesamlphp/assert

A fork of webmozart/assert that lets every assertion throw a custom exception via an extra parameter, falling back to AssertionFailedException. It also adds XML/SAML2-specific assertions for SimpleSAMLphp projects.

View on GitHub
Deep Wiki
Context7

A fork of webmozart/assert that extends assertions beyond method argument checks. It wraps the original assertion methods via __callStatic, allowing an optional exception parameter so you can throw custom Throwable classes instead of the generic InvalidArgumentException. When no exception is supplied, failures raise the library's own AssertionFailedException, which extends UnexpectedValueException—a more semantically correct choice for value verification.

  • Custom exceptions — throw your own Throwable on assertion failure
  • AssertionFailedException fallback for generic failures
  • Drop-in compatibility with all webmozart assertion methods
  • Extra XML/SAML2 assertions for domain-specific checks
  • PHPStan-enabled with high code quality and coverage
Frequently asked questions about Assert
How does this package differ from webmozart/assert for Laravel apps?
This package is a fork that lets you throw custom exceptions (e.g., `AuthException`) instead of `InvalidArgumentException`, which is more semantic for Laravel validation. It also adds SAML/XML-specific assertions like `validSAMLResponse()` and stricter regex handling for security-sensitive inputs like tokens or metadata.
Can I use this package with Laravel’s built-in Validator?
Yes, but it’s best used as a pre-check. For example, validate SAML responses with `Assert::validSAMLResponse()` before passing data to Laravel’s `Validator`. It’s not a replacement but complements Laravel’s validation for domain-specific rules.
Does this package support Laravel’s enums (PHP 8.1+)?
Yes, it introduces enum validation (v1.5.0+) for fixed sets of values, like SAML `AuthnContext` classes or OAuth scopes. Use `Assert::enum($value, [AuthContext::PASSWORD, AuthContext::SAML])` in your service layer or form requests.
Will this break existing code if I upgrade from webmozart/assert?
No, this is a drop-in replacement. All original `webmozart/assert` methods are preserved, but you can now add an optional `exception` parameter to customize thrown exceptions. No breaking changes exist.
How does the stricter regex handling affect my Laravel app?
The stricter regex (e.g., disallowing newlines) hardens security for inputs like SAML metadata or JWT payloads but may reject legitimate multi-line data. Pair it with Laravel’s `trim()` or `sanitize()` methods if your app relies on newlines in inputs.
Is this package compatible with Laravel 10/11 and PHP 8.1+?
Yes, it requires PHP 8.1+ and works seamlessly with Laravel 10/11. The package’s latest features (enum support, stricter regex) are fully compatible with these versions.
Can I use this for testing Laravel API endpoints with SAML assertions?
Absolutely. Use it in PHPUnit/Pest tests to validate SAML responses or enums before hitting Laravel’s `Validator`. For example, test `Assert::validSAMLResponse($samlData)` in your `SAMLAuthTest` class.
What exceptions does this package throw by default?
By default, it throws `AssertionFailedException` (extending `UnexpectedValueException`), which is more semantic than `InvalidArgumentException`. You can override this with any `Throwable` by passing the `exception` parameter to any assertion method.
Are there alternatives for custom exception assertions in Laravel?
For Laravel-specific needs, consider `spatie/laravel-validation-extensions` for custom rules or `laravel-pipeline` for exception handling. However, this package is unique for SAML/XML use cases and custom exception control.
How do I handle dynamic enums that aren’t fixed sets?
This package is optimized for fixed enums (e.g., SAML standards). For dynamic enums, create a wrapper method in your service layer that validates against a database or config array, then use `Assert::contains()` or `Assert::inArray()` from the original library.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
socialdept/atp-orm
cboxdk/laravel-assistant-client
socialdept/atp-resolver
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings
coleus/apps
seampact/laravel
emmyconceptng/laravel-ng-postcode
jjsquady/round-robin