forked from puncoz-bookmarks/laravel-mailcoach-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeleteOldUnconfirmedSubscribersCommandTest.php
50 lines (39 loc) · 1.74 KB
/
DeleteOldUnconfirmedSubscribersCommandTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace Spatie\Mailcoach\Tests\Commands;
use Spatie\Mailcoach\Commands\DeleteOldUnconfirmedSubscribersCommand;
use Spatie\Mailcoach\Enums\SubscriptionStatus;
use Spatie\Mailcoach\Models\EmailList;
use Spatie\Mailcoach\Models\Subscriber;
use Spatie\Mailcoach\Tests\TestCase;
use Spatie\TestTime\TestTime;
class DeleteOldUnconfirmedSubscribersCommandTest extends TestCase
{
private EmailList $emailList;
public function setUp(): void
{
parent::setUp();
TestTime::freeze('Y-m-d H:i:s', '2019-01-01 00:00:00');
$this->emailList = factory(EmailList::class)->create(['requires_confirmation' => true]);
}
/** @test */
public function it_will_delete_all_unconfirmed_subscribers_that_are_older_than_a_month()
{
$subscriber = Subscriber::createWithEmail('[email protected]')->subscribeTo($this->emailList);
$this->assertEquals(SubscriptionStatus::UNCONFIRMED, $subscriber->status);
TestTime::addMonth();
$this->artisan(DeleteOldUnconfirmedSubscribersCommand::class)->assertExitCode(0);
$this->assertCount(1, Subscriber::all());
TestTime::addSecond();
$this->artisan(DeleteOldUnconfirmedSubscribersCommand::class)->assertExitCode(0);
$this->assertCount(0, Subscriber::all());
}
/** @test */
public function it_will_not_delete_confirmed_subscribers()
{
$subscriber = Subscriber::createWithEmail('[email protected]')->skipConfirmation()->subscribeTo($this->emailList);
$this->assertEquals(SubscriptionStatus::SUBSCRIBED, $subscriber->status);
TestTime::addMonth()->addSecond();
$this->artisan(DeleteOldUnconfirmedSubscribersCommand::class)->assertExitCode(0);
$this->assertCount(1, Subscriber::all());
}
}