Testing mainly revolves around
asserting that some behaviour, object or value, is working in an expected manner
or with an expected result. With Craft introducing some key concepts
the Craft module introduces its own set of
expect methods allowing
you to write more concise and effective tests.
This assert can be used to test that multiple elements exist in the database I.E as a result of code you have just executed. It accepts four arguments:
string $elementTypewhat element type must these elements be of.
array $searchParametersthe params that they must match (see below).
int $amount = 1the amount of elements that must be found.
bool $searchAll = falsewhether
trashed(null)should be used when searching for possible Elements. Do so if you, for example, need to search for a newly created User who will have
User::STATUS_DRAFTas applicable status.
Under the hood the Craft module will call
$elementType::find() creating a
Then it will apply the
$searchParameters with the
$key being the property of the
that property must be set to.
This assert is useful for if you are providing support resources for developers who work with your module/plugin.
I.E. if you provide an
assert method of your own for an element type your module/plugin introduces. It
accepts two arguments:
callable $callbacka callable in which a test should fail (I.E
string $message = ''the message the test should fail with.
Please see our separate page on events testing for everything you need to know about testing for events.