PHP code example of phputil / kahlan
1. Go to this page and download the library: Download phputil/kahlan library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
phputil / kahlan example snippets
// 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()