Should I be doing "Higher Order Assertions"? #1238
-
I was writing some tests today and I noticed that the expectation has the same methods as those on the subject. For example, instead of doing this: expect($timer->isRunning())->toBeTrue();
expect($timer->isStopped())->toBeFalse(); I can do this: expect($timer)->isRunning();
expect($timer)->isStopped()->toBeFalse(); However, I don't see this documented anywhere. @nunomaduro is this an intended design pattern or is it just a happy coincidence that it works? Aside, I was sad to see that expect($timer)->isStopped()->toBeFalse(); Couldn't be replaced by expect($timer)->not->isStopped(); If this pattern is intentional/desired then I might open a PR |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
So I started digging into the code and I learned some things. This feature is called "Higher Order Assertions". It seems like it's pretty well supported (or at least there's tests and things) I went to try and write this test: expect($timer)->isRunning(); And it said it wasn't running any assertions. That's weird, cause I swear I've seen this fail if My questions are resolved here |
Beta Was this translation helpful? Give feedback.
So I started digging into the code and I learned some things.
This feature is called "Higher Order Assertions". It seems like it's pretty well supported (or at least there's tests and things)
I went to try and write this test:
And it said it wasn't running any assertions.
That's weird, cause I swear I've seen this fail if
isRunning
returned false multiple times. Oh well.My questions are resolved here