Actually, the best way provides better readability and better error messages: use PHPUnit based on approval functions or the Hamcrest Library .
assertThat(count($users), greaterThan(2)); >> Expected: greater than 2 >> but: was 1
or
assertThat($users, arrayWithSize(greaterThan(2))); >> Expected: array with size greater than 2 >> but: was array with size 1
You can always provide a readable error message with any statement by adding a line as the first parameter to the statement methods or the Hamcrest assertThat function or the third parameter to the PHPUnit assertThat function:
self::assertTrue('At least one user found', !empty($users)); >> At least one user found >> Expected: true >> but: false
or
assertThat('At least one user found', !empty($users), is(true)); >> At least one user found >> Expected: true >> but: false
source share