-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHasCachedSoftDeleteCountTest.php
More file actions
69 lines (48 loc) · 1.56 KB
/
HasCachedSoftDeleteCountTest.php
File metadata and controls
69 lines (48 loc) · 1.56 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace Javaabu\Helpers\Tests\Unit;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Javaabu\Helpers\Tests\TestCase;
use Javaabu\Helpers\Tests\TestSupport\Models\Post;
use PHPUnit\Framework\Attributes\Test;
class HasCachedSoftDeleteCountTest extends TestCase
{
use RefreshDatabase;
#[Test]
public function it_can_check_whether_a_model_has_soft_deletes()
{
$post = new Post([
'title' => 'test'
]);
$post->save();
$this->assertFalse(Post::hasRecordsInTrash());
$post->delete();
$this->assertTrue(Post::hasRecordsInTrash());
$post->forceDelete();
$this->assertFalse(Post::hasRecordsInTrash());
}
#[Test]
public function it_clears_the_cached_soft_deletes_when_a_model_is_deleted()
{
$post = new Post([
'title' => 'test'
]);
$post->save();
$this->assertFalse(Post::hasRecordsInTrash());
$this->assertTrue(cache()->has(Post::getSoftDeleteCacheKey()));
$post->delete();
$this->assertFalse(cache()->has(Post::getSoftDeleteCacheKey()));
}
#[Test]
public function it_clears_the_cached_soft_deletes_when_a_model_is_restored()
{
$post = new Post([
'title' => 'test'
]);
$post->save();
$post->delete();
$this->assertTrue(Post::hasRecordsInTrash());
$this->assertTrue(cache()->has(Post::getSoftDeleteCacheKey()));
$post->restore();
$this->assertFalse(cache()->has(Post::getSoftDeleteCacheKey()));
}
}