Download the PHP package k2gl/phpunit-fluent-assertions without Composer
On this page you can find all versions of the php package k2gl/phpunit-fluent-assertions. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download k2gl/phpunit-fluent-assertions
More information about k2gl/phpunit-fluent-assertions
Files in k2gl/phpunit-fluent-assertions
Package phpunit-fluent-assertions
Short Description Improves test code readability.
License MIT
Homepage https://github.com/k2gl/phpunit-fluent-assertions
Informations about the package phpunit-fluent-assertions
Fluent assertions for PHPUnit
This library is inspired by Vladimir Khorikov, the author of Unit Testing: Principles, Patterns and Practices and makes checks in tests more readable.
Installation
You can add this library as a local, per-project dependency to your project using Composer:
Usage
Write tests as usual, just use fluent assertions short aliases , or instead of .
Array assertions
Boolean assertions
Comparison and equality assertions
Null assertions
Numeric assertions
String assertions
Type Checking assertions
PHPStan support
The package ships a PHPStan extension that narrows the asserted value, so the analyser keeps following your types after a fluent assertion:
More examples — every supported assertion narrows the subject in place:
The chain can be opened with any of check(), expect(), fact() or
FluentAssertions::for(), and the subject may be a variable or a property
(e.g. fact($user->getContext())->notNull()).
If you use phpstan/extension-installer
it is picked up automatically. Otherwise include it manually in your phpstan.neon:
Narrowing is applied for notNull(), null(), true(), notTrue(), false(),
notFalse(), instanceOf(), notInstanceOf(), is(), and the type checks isString(),
isInt(), isFloat(), isBool(), isArray(), isCallable() and isResource(). Loose or
negated assertions such as equals() (loose ==) and not() would not narrow soundly, so they
are intentionally left out and leave the type unchanged.