Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
public function test_jobs_older_than_90_days_are_deleted_automatically()
{
$listings = factory(Listing::class, 5)->create();
$listings[0]->update(['created_at' => now()->subDays(91)]);
$listings[1]->update(['created_at' => now()->subDays(91)]);
// We have 5 listings now
$this->assertCount(5, Listing::all());
// run the command to delete listings posted 90 or more days ago.
$this->artisan(DeleteOldListings::class);
// we have 3 listings now because the 2 old ones were deleted.
$this->assertCount(3, Listing::all());
// 2 listings should have been deleted.
$this->assertCount(2, Listing::onlyTrashed()->get());
// since were using soft deleted, we should still
// have 5 records if we include the trashed ones.
$this->assertCount(5, Listing::withTrashed()->get());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment