Skip to content

Commit 5e89d16

Browse files
committed
Fixed tests
1 parent 57b76d0 commit 5e89d16

File tree

8 files changed

+96
-5
lines changed

8 files changed

+96
-5
lines changed

database/factories/BookFactory.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/*
3+
|--------------------------------------------------------------------------
4+
| Model Factories
5+
|--------------------------------------------------------------------------
6+
|
7+
| This directory should contain each of the model factory definitions for
8+
| your application. Factories provide a convenient way to generate new
9+
| model instances for testing / seeding your application's database.
10+
|
11+
*/
12+
13+
use Illuminate\Support\Str;
14+
15+
$factory->define(\Rennokki\QueryCache\Test\Models\Book::class, function () {
16+
return [
17+
'name' => 'Book'.Str::random(5),
18+
];
19+
});

tests/MethodsTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Rennokki\QueryCache\Test;
44

55
use Cache;
6+
use Rennokki\QueryCache\Test\Models\Book;
67
use Rennokki\QueryCache\Test\Models\Kid;
78
use Rennokki\QueryCache\Test\Models\Post;
89

@@ -91,15 +92,15 @@ public function test_cache_flush_with_more_tags()
9192

9293
public function test_cache_flush_with_default_tags_attached()
9394
{
94-
$post = factory(Post::class)->create();
95-
$storedPost = Post::cacheFor(now()->addHours(1))->cacheTags(['test'])->first();
95+
$book = factory(Book::class)->create();
96+
$storedBook = Book::cacheFor(now()->addHours(1))->cacheTags(['test'])->first();
9697

97-
$cache = Cache::tags(['test', Post::getCacheBaseTags()[0]])->get('leqc:sqlitegetselect * from "posts" limit 1a:0:{}');
98+
$cache = Cache::tags(['test', Book::getCacheBaseTags()[0]])->get('leqc:sqlitegetselect * from "books" limit 1a:0:{}');
9899
$this->assertNotNull($cache);
99100

100-
Post::flushAllQueryCache();
101+
Book::flushAllQueryCache();
101102

102-
$cache = Cache::tags(['test', Post::getCacheBaseTags()[0]])->get('leqc:sqlitegetselect * from "posts" limit 1a:0:{}');
103+
$cache = Cache::tags(['test', Book::getCacheBaseTags()[0]])->get('leqc:sqlitegetselect * from "books" limit 1a:0:{}');
103104

104105
$this->assertNull($cache);
105106
}

tests/Models/Book.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Rennokki\QueryCache\Test\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
use Rennokki\QueryCache\Traits\QueryCacheable;
7+
8+
class Book extends Model
9+
{
10+
use QueryCacheable;
11+
12+
protected $cacheUsePlainKey = true;
13+
14+
protected $fillable = [
15+
'name',
16+
];
17+
}

tests/Models/Kid.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,11 @@ class Kid extends Model
1212
protected $fillable = [
1313
'name',
1414
];
15+
16+
protected function getCacheBaseTags(): array
17+
{
18+
return [
19+
//
20+
];
21+
}
1522
}

tests/Models/Post.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,11 @@ class Post extends Model
1414
protected $fillable = [
1515
'name',
1616
];
17+
18+
protected function getCacheBaseTags(): array
19+
{
20+
return [
21+
//
22+
];
23+
}
1724
}

tests/Models/User.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,11 @@ class User extends Authenticatable
1313
protected $hidden = [
1414
'password', 'remember_token',
1515
];
16+
17+
protected function getCacheBaseTags(): array
18+
{
19+
return [
20+
//
21+
];
22+
}
1623
}

tests/TestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public function getEnvironmentSetUp($app)
5656
$app['config']->set('auth.providers.users.model', User::class);
5757
$app['config']->set('auth.providers.posts.model', Post::class);
5858
$app['config']->set('auth.providers.kids.model', Kid::class);
59+
$app['config']->set('auth.providers.books.model', Book::class);
5960
$app['config']->set('app.key', 'wslxrEFGWY6GfGhvN9L3wH3KSRJQQpBD');
6061
}
6162

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
class Books extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('books', function (Blueprint $table) {
17+
$table->increments('id');
18+
$table->string('name');
19+
$table->timestamps();
20+
});
21+
}
22+
23+
/**
24+
* Reverse the migrations.
25+
*
26+
* @return void
27+
*/
28+
public function down()
29+
{
30+
Schema::dropIfExists('books');
31+
}
32+
}

0 commit comments

Comments
 (0)