-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from rennokki/increase-code-coverage
Increase the code coverage
- Loading branch information
Showing
9 changed files
with
162 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| Model Factories | ||
|-------------------------------------------------------------------------- | ||
| | ||
| This directory should contain each of the model factory definitions for | ||
| your application. Factories provide a convenient way to generate new | ||
| model instances for testing / seeding your application's database. | ||
| | ||
*/ | ||
|
||
use Illuminate\Support\Str; | ||
|
||
$factory->define(\Rennokki\QueryCache\Test\Models\Kid::class, function () { | ||
return [ | ||
'name' => 'Kid'.Str::random(5), | ||
]; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
namespace Rennokki\QueryCache\Test; | ||
|
||
use Cache; | ||
use Rennokki\QueryCache\Test\Models\Kid; | ||
use Rennokki\QueryCache\Test\Models\Post; | ||
|
||
class MethodsTest extends TestCase | ||
{ | ||
public function test_do_not_cache() | ||
{ | ||
$post = factory(Post::class)->create(); | ||
|
||
$storedPost = Post::cacheFor(now()->addHours(1))->doNotCache()->first(); | ||
$cache = Cache::get('leqc:sqlitegetselect * from "posts" limit 1a:0:{}'); | ||
$this->assertNull($cache); | ||
|
||
$storedPost = Post::cacheFor(now()->addHours(1))->dontCache()->first(); | ||
$cache = Cache::get('leqc:sqlitegetselect * from "posts" limit 1a:0:{}'); | ||
$this->assertNull($cache); | ||
} | ||
|
||
public function test_cache_prefix() | ||
{ | ||
$post = factory(Post::class)->create(); | ||
$storedPost = Post::cacheFor(now()->addHours(1))->cachePrefix('test')->first(); | ||
$cache = Cache::get('test:sqlitegetselect * from "posts" limit 1a:0:{}'); | ||
|
||
$this->assertNotNull($cache); | ||
} | ||
|
||
public function test_cache_tags() | ||
{ | ||
$post = factory(Post::class)->create(); | ||
$storedPost = Post::cacheFor(now()->addHours(1))->cacheTags(['test'])->first(); | ||
|
||
$cache = Cache::get('leqc:sqlitegetselect * from "posts" limit 1a:0:{}'); | ||
$this->assertNull($cache); | ||
|
||
$cache = Cache::tags(['test'])->get('leqc:sqlitegetselect * from "posts" limit 1a:0:{}'); | ||
$this->assertNotNull($cache); | ||
} | ||
|
||
public function test_cache_flush_with_the_right_tag() | ||
{ | ||
$post = factory(Post::class)->create(); | ||
$storedPost = Post::cacheFor(now()->addHours(1))->cacheTags(['test'])->first(); | ||
|
||
$cache = Cache::tags(['test'])->get('leqc:sqlitegetselect * from "posts" limit 1a:0:{}'); | ||
$this->assertNotNull($cache); | ||
|
||
Post::flushQueryCache(['test']); | ||
|
||
$cache = Cache::tags(['test'])->get('leqc:sqlitegetselect * from "posts" limit 1a:0:{}'); | ||
$this->assertNull($cache); | ||
} | ||
|
||
public function test_cache_flush_without_the_right_tag() | ||
{ | ||
$post = factory(Post::class)->create(); | ||
$storedPost = Post::cacheFor(now()->addHours(1))->cacheTags(['test'])->first(); | ||
|
||
$cache = Cache::tags(['test'])->get('leqc:sqlitegetselect * from "posts" limit 1a:0:{}'); | ||
$this->assertNotNull($cache); | ||
|
||
Post::flushQueryCache(['test2']); | ||
|
||
$cache = Cache::tags(['test'])->get('leqc:sqlitegetselect * from "posts" limit 1a:0:{}'); | ||
$this->assertNotNull($cache); | ||
} | ||
|
||
public function test_hashed_key() | ||
{ | ||
$kid = factory(Kid::class)->create(); | ||
$storedKid = Kid::cacheFor(now()->addHours(1))->first(); | ||
$cache = Cache::get('leqc:156667fa9bcb7fb8abb01018568648406f251ef65736e89e6fd27d08bc48b5bb'); | ||
|
||
$this->assertNotNull($cache); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Rennokki\QueryCache\Test\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Rennokki\QueryCache\Traits\QueryCacheable; | ||
|
||
class Kid extends Model | ||
{ | ||
use QueryCacheable; | ||
|
||
protected $fillable = [ | ||
'name', | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class Kids extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('kids', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->string('name'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('kids'); | ||
} | ||
} |