- 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.