Skip to content

Instantly share code, notes, and snippets.

@wilburpowery
Last active October 11, 2018 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wilburpowery/2d7a99689b834100538c4b6a152ee2ed to your computer and use it in GitHub Desktop.
Save wilburpowery/2d7a99689b834100538c4b6a152ee2ed to your computer and use it in GitHub Desktop.
<?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