phputil / kahlan
Additional matchers for Kahlan
v0.3.0
2024-05-15 03:42 UTC
Requires
- ext-mbstring: *
- ext-pcre: *
Requires (Dev)
- kahlan/kahlan: ^5.2
README
Additional matchers for Kahlan
Install
Requires PHP 7+ and the extensions
pcreandmbstring
composer require phputil/kahlan --dev
See tips for help on how to install extensions.
Matchers
- Exception:
- toThrowAnExceptionThatMatches - compares an exception message with the given Regular Expression
- toThrowAnExceptionWithCode - compares an exception code with the given code
- toThrowAnExceptionWithClassName - compares an exception name with the given class name
- String:
- toHaveStringLength - compares a multi-byte string length with the given length
Examples:
// toThrowAnExceptionThatMatches expect( function() { throw new Exception( 'Something went wrong!' ); } )->toThrowAnExceptionThatMatches( '/wrong/' ); // Regular Expression // toThrowAnExceptionWithCode expect( function() { throw new Exception( 'Something went wrong!', 123 ); } )->toThrowAnExceptionWithCode( 123 ); // Exception code // toThrowAnExceptionWithClassName ⭐ expect( function() { throw new MyOwnException( 'Something went wrong!', 123 ); } )->toThrowAnExceptionWithClassName( MyOwnException::class ); // Exception class // toHaveStringLength expect( 'Pelé' )->toHaveStringLength( 4 ); // Compares using mb_strlen() instead of strlen()
Suggestions? Please open an Issue.