terah / fluent-assert
A light weight assertion package based on beberlei/assert
Installs: 2 374
Dependents: 7
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Requires
- php: >=8.0
- dev-master
- 8.0.1.0
- 8.0.0.0
- 6.0.1.0
- 6.0.0.9
- 6.0.0.8
- 6.0.0.7
- 6.0.0.5
- 6.0.0.1
- 6.0.0.0
- 4.0.7.6
- 4.0.7.5
- 4.0.7.4
- 4.0.7.3
- 4.0.6.7
- 4.0.6.6
- 4.0.6.5
- 4.0.6.4
- 4.0.6.3
- 4.0.6.2
- 4.0.5.55
- 4.0.5.54
- 4.0.5.53
- 4.0.5.52
- 4.0.5.51
- 4.0.5.40
- 4.0.5.39
- 4.0.5.38
- 4.0.5.37
- 4.0.5.36
- 4.0.5.35
- 4.0.5.33
- 4.0.5.32
- 4.0.5.31
- 4.0.5.30
- 4.0.5.29
- 4.0.5.28
- 4.0.5.27
- 4.0.5.26
- 4.0.5.23
- 4.0.5.22
- 4.0.5.18
- 4.0.5.17
- 4.0.5.16
- 4.0.5.15
- 4.0.5.14
- 4.0.5.13
- 4.0.5.12
- 4.0.5.11
- 4.0.5.10
- 4.0.5.9
- 4.0.5.8
- 4.0.5.7
- 4.0.5.6
- 4.0.5.5
- 4.0.5.4
- 4.0.5.3
- 4.0.5.2
- 4.0.5.1
- 4.0.5.0
- 4.0.4.9
- 4.0.4.7
- 4.0.4.5
- 4.0.4.4
- 4.0.4.3
- 4.0.4.2
- 4.0.4.1
- 4.0.4.0
- 4.0.3.9
- 4.0.3.8
- 4.0.3.7
- 4.0.3.6
- 4.0.3.5
- 4.0.3.4
- 4.0.3.3
- 4.0.3.2
- 4.0.3.1
- 4.0.2.7
- 4.0.2.6
- 4.0.2.4
- 4.0.2.3
- 4.0.2.2
- 4.0.2.1
- 4.0.2.0
- 4.0.1.9
- 4.0.1.8
- 4.0.1.7
- 4.0.1.6
- 4.0.1.5
- 4.0.1.4
- 4.0.1.3
- 4.0.1.2
- 4.0.1.0
- 4.0.0.6
- 4.0.0.5
- 3.0.0.9
- 3.0.0.8
- 3.0.0.7
- 3.0.0.6
- 3.0.0.5
- 3.0.0.4
- 3.0.0.3
- 3.0.0.2
- 3.0.0.1
- 3.0.0.0
- 2.0.0.4
- 2.0.0.3
- 2.0.0.2
- 2.0.0.1
- 2.0.0
- 1.0.7.4
- 1.0.7.3
- 1.0.7.2
- 1.0.7.1
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0
- 0.1
This package is auto-updated.
Last update: 2025-08-21 00:31:23 UTC
README
This is a fork/subset of the awesome package Assert (https://github.com/beberlei/assert). I only use the fluent (chained) interface and the assert library is very heavily used chunk of code. By breaking it into it's own library the library is about 3 times faster (using my very unscienctific benchark).
Install
Via Composer
$ composer require terah/fluent-assert
Usage
use Terah\Assert\Assert; (new Assert($value))->eq($value2, string $message='', string $fieldName=''); (new Assert($value))->same($value2, string $message='', string $fieldName=''); (new Assert($value))->notEq($value2, string $message='', string $fieldName=''); (new Assert($value))->notSame($value2, string $message='', string $fieldName=''); (new Assert($value))->integer(string $message='', string $fieldName=''); (new Assert($value))->float(string $message='', string $fieldName=''); (new Assert($value))->digit(string $message='', string $fieldName=''); (new Assert($value))->date($message=null, $fieldName=null); (new Assert($value))->integerish(string $message='', string $fieldName=''); (new Assert($value))->boolean(string $message='', string $fieldName=''); (new Assert($value))->scalar(string $message='', string $fieldName=''); (new Assert($value))->notEmpty(string $message='', string $fieldName=''); (new Assert($value))->noContent(string $message='', string $fieldName=''); (new Assert($value))->notNull(string $message='', string $fieldName=''); (new Assert($value))->string(string $message='', string $fieldName=''); (new Assert($value))->regex($pattern, string $message='', string $fieldName=''); (new Assert($value))->length($length, string $message='', string $fieldName='', $encoding = 'utf8'); (new Assert($value))->minLength($minLength, string $message='', string $fieldName='', $encoding = 'utf8'); (new Assert($value))->maxLength($maxLength, string $message='', string $fieldName='', $encoding = 'utf8'); (new Assert($value))->betweenLength($minLength, $maxLength, string $message='', string $fieldName='', $encoding = 'utf8'); (new Assert($value))->startsWith($needle, string $message='', string $fieldName='', $encoding = 'utf8'); (new Assert($value))->endsWith($needle, string $message='', string $fieldName='', $encoding = 'utf8'); (new Assert($value))->contains($needle, string $message='', string $fieldName='', $encoding = 'utf8'); (new Assert($value))->choice(array $choices, string $message='', string $fieldName=''); (new Assert($value))->inArray(array $choices, string $message='', string $fieldName=''); (new Assert($value))->numeric(string $message='', string $fieldName=''); (new Assert($value))->isArray(string $message='', string $fieldName=''); (new Assert($value))->isTraversable(string $message='', string $fieldName=''); (new Assert($value))->isArrayAccessible(string $message='', string $fieldName=''); (new Assert($value))->keyExists($key, string $message='', string $fieldName=''); (new Assert($value))->keysExist($keys, string $message='', string $fieldName=''); (new Assert($value))->propertyExists($key, string $message='', string $fieldName=''); (new Assert($value))->propertiesExist(array $keys, string $message='', string $fieldName=''); (new Assert($value))->utf8(string $message='', string $fieldName=''); (new Assert($value))->keyIsset($key, string $message='', string $fieldName=''); (new Assert($value))->notEmptyKey($key, string $message='', string $fieldName=''); (new Assert($value))->notBlank(string $message='', string $fieldName=''); (new Assert($value))->isInstanceOf($className, string $message='', string $fieldName=''); (new Assert($value))->notIsInstanceOf($className, string $message='', string $fieldName=''); (new Assert($value))->subclassOf($className, string $message='', string $fieldName=''); (new Assert($value))->range($minValue, $maxValue, string $message='', string $fieldName=''); (new Assert($value))->min($minValue, string $message='', string $fieldName=''); (new Assert($value))->max($maxValue, string $message='', string $fieldName=''); (new Assert($value))->file(string $message='', string $fieldName=''); (new Assert($value))->directory(string $message='', string $fieldName=''); (new Assert($value))->readable(string $message='', string $fieldName=''); (new Assert($value))->writeable(string $message='', string $fieldName=''); (new Assert($value))->email(string $message='', string $fieldName=''); (new Assert($value))->url(string $message='', string $fieldName=''); (new Assert($value))->alnum(string $message='', string $fieldName=''); (new Assert($value))->true(string $message='', string $fieldName=''); (new Assert($value))->false(string $message='', string $fieldName=''); (new Assert($value))->classExists(string $message='', string $fieldName=''); (new Assert($value))->implementsInterface($interfaceName, string $message='', string $fieldName=''); (new Assert($value))->isJsonString(string $message='', string $fieldName=''); (new Assert($value))->uuid(string $message='', string $fieldName=''); (new Assert($value))->samAccountName(string $message='', string $fieldName=''); (new Assert($value))->unc(string $message='', string $fieldName=''); (new Assert($value))->driveLetter(string $message='', string $fieldName=''); (new Assert($value))->userPrincipalName(string $message='', string $fieldName=''); (new Assert($value))->count($count, string $message='', string $fieldName=''); (new Assert($value))->choicesNotEmpty(array $choices, string $message='', string $fieldName=''); (new Assert($value))->methodExists($object, string $message='', string $fieldName=''); (new Assert($value))->isObject(string $message='', string $fieldName=''); // Chaining (new Assert($myValue))->integer()->notEmpty()->eq(1); // Checking members of arrays and objects) (new Assert($myArray))->all()->integer()->notEmpty()->eq(1); // Null or valid (new Assert($myNullValue)->nullOr()->integer()->notEmpty()->eq(1); // Reset the all and nullOr flags and set value (new Assert($value))->reset($value) // Set a new value (new Assert($value))->value($value) // Set the null or flag (new Assert($value))->nullOr($nullOr=true) // Set the all flag (new Assert($value))->all($all=true) // Set the exception class (new Assert($value))->setExceptionClass('\\My\\Exception\\Class');
Testing
$ bin/tester tests/
Please see tests/AssertSuite.php for example of writing tests
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email terry@terah.com.au instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.