When we are writing tests, we often need to check that values meet certain conditions. And for that, at the time of this writing, we are using PHPUnit syntax using the global helpers: assertEquals, assertTrue, assertFalse, etc.
The problem with this is the number of global helpers that are injected in the global namespace: One function per assertion.
This RFC introduces the global helper expect, that would offer the same number of assertions of PHPUnit, but using a single global function and a fluent syntax like so:
// old
assertTrue($variable);
// new
expect($variable)->toBe(true);
// --
// old
assertGreaterThan(0, $variable);
// new
expect($variable)->toBeGreaterThan(0);
// --
// old
assertContains('nuno', $array);
// new
expect($array)->toContain('nuno');
Of course, the RFC is inspired in Jest: jestjs.io/docs/en/expect.
@nunomaduro for easier migration and reduce cognitive load, can the default expectations be consistent with the asserts then add aliases to better sounding or user friendly names
Just plug this in and you are ready! 馃幆
https://github.com/Codeception/Verify
In progress...
Will they be chainable? For example:
expect($array)->toContain('nuno')->toHaveMinElements(5)->toIncludeElementsFrom($array2);
Like Laravel's Validation system. And maybe have clauses like toContainWhen('nuno', count($array) > 0).
I've just bootstrapped this work of adding the full-featured expect API.
Check out the pull request: https://github.com/pestphp/pest/pull/123. Fell free to help me with this. 馃憤馃徎
@tpaksu Yes: https://github.com/pestphp/pest/pull/123/files#diff-a644964bd3325a15734d76efdaabd137R52.
Most helpful comment
Just plug this in and you are ready! 馃幆
https://github.com/Codeception/Verify