forked from renoki-co/laravel-eloquent-query-cache
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPaginateTest.php
55 lines (42 loc) · 1.66 KB
/
PaginateTest.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
51
52
53
54
55
<?php
namespace Rennokki\QueryCache\Test;
use Cache;
use Rennokki\QueryCache\Test\Models\Post;
class PaginateTest extends TestCase
{
public function test_paginate()
{
$posts = factory(Post::class, 30)->create();
$storedPosts = Post::cacheFor(now()->addHours(1))->paginate(15);
$postsCount = $posts->count();
$totalCountCache = Cache::get('leqc:sqlitegetselect count(*) as aggregate from "posts"a:0:{}');
$postsCache = Cache::get('leqc:sqlitegetselect * from "posts" limit 15 offset 0a:0:{}');
$this->assertNotNull($totalCountCache);
$this->assertNotNull($postsCache);
$this->assertEquals(
$totalCountCache->first()->aggregate,
$postsCount
);
$this->assertEquals(15, $postsCache->count());
$this->assertEquals(1, $postsCache->first()->id);
}
public function test_paginate_with_columns()
{
$posts = factory(Post::class, 30)->create();
$storedPosts = Post::cacheFor(now()->addHours(1))->paginate(15, ['name']);
$postsCount = $posts->count();
$totalCountCache = Cache::get('leqc:sqlitegetselect count(*) as aggregate from "posts"a:0:{}');
$postsCache = Cache::get('leqc:sqlitegetselect "name" from "posts" limit 15 offset 0a:0:{}');
$this->assertNotNull($totalCountCache);
$this->assertNotNull($postsCache);
$this->assertEquals(
$totalCountCache->first()->aggregate,
$postsCount
);
$this->assertEquals(15, $postsCache->count());
$this->assertEquals(
$posts->first()->name,
$postsCache->first()->name
);
}
}