Skip to content

Commit 62c4baf

Browse files
committed
Merge branch 'release/0.2.45'
2 parents 3e6be63 + 89af400 commit 62c4baf

File tree

10 files changed

+117
-12
lines changed

10 files changed

+117
-12
lines changed

CHANGELOG.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,38 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [0.2.45] - 3 Mar 2018
8+
### Fixed
9+
- pagination cache key generation; fixes #85.
10+
11+
## [0.2.44] - 3 Mar 2018
12+
### Fixed
13+
- disabling of caching using the query scope.
14+
15+
## [0.2.43] - 2 Mar 2018
16+
### Fixed
17+
- actions on belongsToMany relationships not flushing cache when needed.
18+
19+
## [0.2.42] - 28 Feb 2018
20+
### Added
21+
- additional integration tests for additional use cases.
22+
23+
### Fixed
24+
- flushing a specific model from the command line that extended a base class and did not use the trait directly.
25+
26+
## [0.2.41] - 26 Feb 2018
27+
### Fixes
28+
- cache invalidation when using ->insert() method.
29+
- cache invalidation when using ->update() method.
30+
31+
## [0.2.40] - 24 Feb 2018
32+
### Updated
33+
- code with some home-cleaning and refactoring.
34+
35+
## [0.2.39] - 24 Feb 2018
36+
### Updated
37+
- CachedBuilder class with some refactoring and cleanup.
38+
739
## [0.2.38] - 24 Feb 2018
840
### Added
941
- cache-invalidation-cool-down functionality.

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"mockery/mockery": "0.9.*",
2424
"orchestra/database": "3.6.x-dev@dev",
2525
"orchestra/testbench": "^3.6",
26+
"orchestra/testbench-browser-kit": "^3.6",
2627
"php-coveralls/php-coveralls" : "*",
2728
"phpmd/phpmd": "*",
2829
"phpunit/phpunit": "*",

phpunit.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
syntaxCheck="false"
1414
>
1515
<testsuites>
16+
<testsuite name="Feature">
17+
<directory suffix="Test.php">./tests/Feature</directory>
18+
</testsuite>
1619
<testsuite name="Integration">
1720
<directory suffix="Test.php">./tests/Integration</directory>
1821
</testsuite>

src/CachedBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function paginate(
115115
return parent::paginate($perPage, $columns, $pageName, $page);
116116
}
117117

118-
$page = $page ?: 1;
118+
$page = request("page", $page ?: 1);
119119
$cacheKey = $this->makeCacheKey($columns, null, "-paginate_by_{$perPage}_{$pageName}_{$page}");
120120

121121
return $this->cachedValue(func_get_args(), $cacheKey);

tests/CreatesApplication.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,26 @@ trait CreatesApplication
1212
{
1313
protected $cache;
1414

15+
protected function cache()
16+
{
17+
$cache = cache();
18+
19+
if (config('laravel-model-caching.store')) {
20+
$cache = $cache->store(config('laravel-model-caching.store'));
21+
}
22+
23+
return $cache;
24+
}
25+
1526
public function setUp()
1627
{
1728
parent::setUp();
1829

30+
require(__DIR__ . '/routes/web.php');
31+
1932
$this->withFactories(__DIR__ . '/database/factories');
2033
$this->loadMigrationsFrom(__DIR__ . '/database/migrations');
34+
view()->addLocation(__DIR__ . '/resources/views', 'laravel-model-caching');
2135

2236
$this->cache = cache()
2337
->store(config('laravel-model-caching.store'));

tests/Feature/PaginationTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php namespace GeneaLabs\LaravelModelCaching\Tests\Browser;
2+
3+
use GeneaLabs\LaravelModelCaching\Tests\FeatureTestCase;
4+
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Book;
5+
6+
class PaginationTest extends FeatureTestCase
7+
{
8+
public function testPaginationProvidesDifferentLinksOnDifferentPages()
9+
{
10+
$book = (new Book)
11+
->take(11)
12+
->get()
13+
->last();
14+
$page1 = $this->visit("pagination-test");
15+
16+
$this->assertTrue(str_contains($page1->response->getContent(), '<li class="page-item active"><span class="page-link">1</span></li>'));
17+
18+
$page2 = $page1->click("2");
19+
20+
$this->assertTrue(str_contains($page2->response->getContent(), '<li class="page-item active"><span class="page-link">2</span></li>'));
21+
$page2->see($book->title);
22+
}
23+
}

tests/FeatureTestCase.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php namespace GeneaLabs\LaravelModelCaching\Tests;
2+
3+
use Orchestra\Testbench\BrowserKit\TestCase as BaseTestCase;
4+
5+
abstract class FeatureTestCase extends BaseTestCase
6+
{
7+
use CreatesApplication;
8+
}

tests/IntegrationTestCase.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,4 @@
55
abstract class IntegrationTestCase extends BaseTestCase
66
{
77
use CreatesApplication;
8-
9-
protected function cache()
10-
{
11-
$cache = cache();
12-
13-
if (config('laravel-model-caching.store')) {
14-
$cache = $cache->store(config('laravel-model-caching.store'));
15-
}
16-
17-
return $cache;
18-
}
198
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body>
4+
<table>
5+
6+
@foreach ($books as $book)
7+
<tr>
8+
<td>
9+
{{ $book->id }}
10+
</td>
11+
<td>
12+
{{ $book->title }}
13+
</td>
14+
</tr>
15+
@endforeach
16+
17+
</table>
18+
19+
{{ $books->links() }}
20+
21+
</body>
22+
</html>

tests/routes/web.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
use GeneaLabs\LaravelModelCaching\Tests\Fixtures\Book;
4+
5+
Route::get('pagination-test', function () {
6+
$books = (new Book)
7+
->paginate(10);
8+
9+
return view("model-caching-tests.pagination")
10+
->with(compact(
11+
'books'
12+
));
13+
});

0 commit comments

Comments
 (0)