Weave Code
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

Fork of webmozart/assert that lets every assertion throw your chosen exception (or a default AssertionFailedException) instead of always InvalidArgumentException. Adds a few custom assertions aimed at XML/SAML2 use cases.

View on GitHub
Deep Wiki
Context7

A wrapper around webmozart/assert to make it useful beyond checking method arguments

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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky