Skip to content

Commit 8229c34

Browse files
committed
Merge branch 'master' into develop
2 parents 60ae6ac + 31c0b12 commit 8229c34

File tree

2 files changed

+70
-20
lines changed

2 files changed

+70
-20
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Integration;
2+
3+
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Author;
4+
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Book;
5+
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Profile;
6+
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Publisher;
7+
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Store;
8+
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedAuthor;
9+
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedBook;
10+
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedProfile;
11+
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedPublisher;
12+
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\UncachedStore;
13+
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Http\Resources\Author as AuthorResource;
14+
use GeneaLabs\LaravelModelCaching\Tests\IntegrationTestCase;
15+
use Illuminate\Foundation\Testing\RefreshDatabase;
16+
17+
/**
18+
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
19+
* @SuppressWarnings(PHPMD.TooManyMethods)
20+
*/
21+
class CachedBuilderPaginationTest extends IntegrationTestCase
22+
{
23+
use RefreshDatabase;
24+
25+
public function testPaginationIsCached()
26+
{
27+
$authors = (new Author)
28+
->paginate(3);
29+
30+
$key = sha1('genealabs:laravel-model-caching:genealabslaravelmodelcachingtestsfixturesauthor-paginate_by_3_page_1');
31+
$tags = [
32+
'genealabs:laravel-model-caching:genealabslaravelmodelcachingtestsfixturesauthor',
33+
];
34+
35+
$cachedResults = $this->cache()
36+
->tags($tags)
37+
->get($key)['value'];
38+
$liveResults = (new UncachedAuthor)
39+
->paginate(3);
40+
41+
$this->assertEquals($cachedResults->toArray(), $authors->toArray());
42+
$this->assertEquals($liveResults->toArray(), $authors->toArray());
43+
}
44+
45+
public function testPaginationReturnsCorrectLinks()
46+
{
47+
$booksPage1 = (new Book)
48+
->paginate(2);
49+
$booksPage2 = (new Book)
50+
->paginate(2, ['*'], null, 2);
51+
$booksPage24 = (new Book)
52+
->paginate(2, ['*'], null, 24);
53+
54+
$this->assertCount(2, $booksPage1);
55+
$this->assertCount(2, $booksPage2);
56+
$this->assertCount(2, $booksPage24);
57+
$this->assertContains(
58+
'<li class="page-item active"><span class="page-link">1</span></li>',
59+
(string) $booksPage1->links()
60+
);
61+
$this->assertContains(
62+
'<li class="page-item active"><span class="page-link">2</span></li>',
63+
(string) $booksPage2->links()
64+
);
65+
$this->assertContains(
66+
'<li class="page-item active"><span class="page-link">24</span></li>',
67+
(string) $booksPage24->links()
68+
);
69+
}
70+
}

tests/Integration/CachedBuilderTest.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -870,26 +870,6 @@ public function testFindOrFailCachesModels()
870870
$this->assertEquals($liveResults->toArray(), $author->toArray());
871871
}
872872

873-
public function testPaginationIsCached()
874-
{
875-
$authors = (new Author)
876-
->paginate(3);
877-
878-
$key = sha1('genealabs:laravel-model-caching:genealabslaravelmodelcachingtestsfixturesauthor-paginate_by_3_page_1');
879-
$tags = [
880-
'genealabs:laravel-model-caching:genealabslaravelmodelcachingtestsfixturesauthor',
881-
];
882-
883-
$cachedResults = $this->cache()
884-
->tags($tags)
885-
->get($key)['value'];
886-
$liveResults = (new UncachedAuthor)
887-
->paginate(3);
888-
889-
$this->assertEquals($cachedResults->toArray(), $authors->toArray());
890-
$this->assertEquals($liveResults->toArray(), $authors->toArray());
891-
}
892-
893873
public function testInsertInvalidatesCache()
894874
{
895875
$authors = (new Author)

0 commit comments

Comments
 (0)