- Add some test data with another status
- Run the command in a test
- Check if the data was changed
If there is any chance that it could ever be changed and break, then test it (I assume this is the case) :)
I have an artisan command like below
public function handle(): void
{
info('[AdvertisementCommand][handle][Start]');
Advertisement::expired()->update(['status' => Advertisement::STATUS_EXPIRED]);
info('[AdvertisementCommand][handle][Done]');
}
expired scope just select rows with ended_at < now() How can I write a test for this? Is it need to test or not?
@FarhadMohammadi Lets say you add 2 records to the database. 1 that is "expired" and 1 that isnt. Then you run the command. Then you check the adverticements. You can keep the id's in the test when you create them if you want
$this->assertEquals($expiredAdverticement->refresh()->status, Advertisement::STATUS_EXPIRED);
$this->assertEquals($dverticement->refresh()->status, Advertisement::STATUS_ACTIVE);
Please or to participate in this conversation.