Skip to content

Commit 5ad221d

Browse files
committed
Added tests for strict mode in models
1 parent 6e705d6 commit 5ad221d

10 files changed

+97
-2
lines changed

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
}
2121
],
2222
"require": {
23-
"illuminate/database": "^8.83|^9.0.1",
24-
"illuminate/support": "^8.83|^9.0.1"
23+
"illuminate/database": "^8.83|^9.35",
24+
"illuminate/support": "^8.83|^9.35"
2525
},
2626
"autoload": {
2727
"psr-4": {

tests/CountTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
class CountTest extends TestCase
99
{
10+
/**
11+
* @dataProvider strictModeContextProvider
12+
*/
1013
public function test_count()
1114
{
1215
$posts = factory(Post::class, 5)->create();
@@ -21,6 +24,9 @@ public function test_count()
2124
);
2225
}
2326

27+
/**
28+
* @dataProvider strictModeContextProvider
29+
*/
2430
public function test_count_with_columns()
2531
{
2632
$posts = factory(Post::class, 5)->create();

tests/FirstTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
class FirstTest extends TestCase
99
{
10+
/**
11+
* @dataProvider strictModeContextProvider
12+
*/
1013
public function test_first()
1114
{
1215
$post = factory(Post::class)->create();
@@ -21,6 +24,9 @@ public function test_first()
2124
);
2225
}
2326

27+
/**
28+
* @dataProvider strictModeContextProvider
29+
*/
2430
public function test_first_with_columns()
2531
{
2632
$post = factory(Post::class)->create();

tests/FlushCacheOnUpdatePivotTest.php

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
class FlushCacheOnUpdatePivotTest extends TestCase
99
{
10+
/**
11+
* @dataProvider strictModeContextProvider
12+
*/
1013
public function test_belongs_to_many()
1114
{
1215
$key = 'leqc:sqlitegetselect "roles".*, "role_user"."user_id" as "pivot_user_id", "role_user"."role_id" as "pivot_role_id" from "roles" inner join "role_user" on "roles"."id" = "role_user"."role_id" where "role_user"."user_id" = ? limit 1a:1:{i:0;i:1;}';

tests/FlushCacheOnUpdateTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
class FlushCacheOnUpdateTest extends TestCase
88
{
9+
/**
10+
* @dataProvider strictModeContextProvider
11+
*/
912
public function test_flush_cache_on_create()
1013
{
1114
$page = factory(Page::class)->create();
@@ -28,6 +31,9 @@ public function test_flush_cache_on_create()
2831
$this->assertNull($cache);
2932
}
3033

34+
/**
35+
* @dataProvider strictModeContextProvider
36+
*/
3137
public function test_flush_cache_on_update()
3238
{
3339
$page = factory(Page::class)->create();
@@ -50,6 +56,9 @@ public function test_flush_cache_on_update()
5056
$this->assertNull($cache);
5157
}
5258

59+
/**
60+
* @dataProvider strictModeContextProvider
61+
*/
5362
public function test_flush_cache_on_delete()
5463
{
5564
$page = factory(Page::class)->create();
@@ -70,6 +79,9 @@ public function test_flush_cache_on_delete()
7079
$this->assertNull($cache);
7180
}
7281

82+
/**
83+
* @dataProvider strictModeContextProvider
84+
*/
7385
public function test_flush_cache_on_force_deletion()
7486
{
7587
$page = factory(Page::class)->create();

tests/GetTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
class GetTest extends TestCase
99
{
10+
/**
11+
* @dataProvider strictModeContextProvider
12+
*/
1013
public function test_get()
1114
{
1215
$post = factory(Post::class)->create();
@@ -26,6 +29,9 @@ public function test_get()
2629
);
2730
}
2831

32+
/**
33+
* @dataProvider strictModeContextProvider
34+
*/
2935
public function test_get_with_columns()
3036
{
3137
$post = factory(Post::class)->create();
@@ -45,6 +51,9 @@ public function test_get_with_columns()
4551
);
4652
}
4753

54+
/**
55+
* @dataProvider strictModeContextProvider
56+
*/
4857
public function test_get_with_string_columns()
4958
{
5059
$post = factory(Post::class)->create();

tests/MethodsTest.php

+34
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Rennokki\QueryCache\Test;
44

5+
use Illuminate\Database\Eloquent\Model;
56
use Illuminate\Support\Facades\Cache;
67
use Rennokki\QueryCache\Test\Models\Book;
78
use Rennokki\QueryCache\Test\Models\Kid;
@@ -10,6 +11,9 @@
1011

1112
class MethodsTest extends TestCase
1213
{
14+
/**
15+
* @dataProvider strictModeContextProvider
16+
*/
1317
public function test_do_not_cache()
1418
{
1519
$post = factory(Post::class)->create();
@@ -23,6 +27,9 @@ public function test_do_not_cache()
2327
$this->assertNull($cache);
2428
}
2529

30+
/**
31+
* @dataProvider strictModeContextProvider
32+
*/
2633
public function test_cache_prefix()
2734
{
2835
$post = factory(Post::class)->create();
@@ -32,6 +39,9 @@ public function test_cache_prefix()
3239
$this->assertNotNull($cache);
3340
}
3441

42+
/**
43+
* @dataProvider strictModeContextProvider
44+
*/
3545
public function test_cache_tags()
3646
{
3747
$post = factory(Post::class)->create();
@@ -49,6 +59,9 @@ public function test_cache_tags()
4959
$this->assertNotNull($cache);
5060
}
5161

62+
/**
63+
* @dataProvider strictModeContextProvider
64+
*/
5265
public function test_cache_flush_with_the_right_tag()
5366
{
5467
$post = factory(Post::class)->create();
@@ -63,6 +76,9 @@ public function test_cache_flush_with_the_right_tag()
6376
$this->assertNull($cache);
6477
}
6578

79+
/**
80+
* @dataProvider strictModeContextProvider
81+
*/
6682
public function test_cache_flush_without_the_right_tag()
6783
{
6884
$post = factory(Post::class)->create();
@@ -83,6 +99,9 @@ public function test_cache_flush_without_the_right_tag()
8399
: $this->assertNull($cache);
84100
}
85101

102+
/**
103+
* @dataProvider strictModeContextProvider
104+
*/
86105
public function test_cache_flush_with_more_tags()
87106
{
88107
$post = factory(Post::class)->create();
@@ -101,6 +120,9 @@ public function test_cache_flush_with_more_tags()
101120
$this->assertNull($cache);
102121
}
103122

123+
/**
124+
* @dataProvider strictModeContextProvider
125+
*/
104126
public function test_cache_flush_with_default_tags_attached()
105127
{
106128
$book = factory(Book::class)->create();
@@ -116,6 +138,9 @@ public function test_cache_flush_with_default_tags_attached()
116138
$this->assertNull($cache);
117139
}
118140

141+
/**
142+
* @dataProvider strictModeContextProvider
143+
*/
119144
public function test_hashed_key()
120145
{
121146
$kid = factory(Kid::class)->create();
@@ -125,6 +150,9 @@ public function test_hashed_key()
125150
$this->assertNotNull($cache);
126151
}
127152

153+
/**
154+
* @dataProvider strictModeContextProvider
155+
*/
128156
public function test_append_cache_tags()
129157
{
130158
$post = factory(Post::class)->create();
@@ -142,6 +170,9 @@ public function test_append_cache_tags()
142170
$this->assertNotNull($cache);
143171
}
144172

173+
/**
174+
* @dataProvider strictModeContextProvider
175+
*/
145176
public function test_multiple_append_cache_tags()
146177
{
147178
$post = factory(Post::class)->create();
@@ -150,6 +181,9 @@ public function test_multiple_append_cache_tags()
150181
$this->assertEquals($storedPostQuery->getQuery()->getCacheTags(), ['test', 'test2']);
151182
}
152183

184+
/**
185+
* @dataProvider strictModeContextProvider
186+
*/
153187
public function test_append_cache_tags_with_sub_query()
154188
{
155189
$user = factory(User::class)->create();

tests/PaginateTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
class PaginateTest extends TestCase
99
{
10+
/**
11+
* @dataProvider strictModeContextProvider
12+
*/
1013
public function test_paginate()
1114
{
1215
$posts = factory(Post::class, 30)->create();
@@ -28,6 +31,9 @@ public function test_paginate()
2831
$this->assertEquals(1, $postsCache->first()->id);
2932
}
3033

34+
/**
35+
* @dataProvider strictModeContextProvider
36+
*/
3137
public function test_paginate_with_columns()
3238
{
3339
$posts = factory(Post::class, 30)->create();

tests/SimplePaginateTest.php

+7
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22

33
namespace Rennokki\QueryCache\Test;
44

5+
use Illuminate\Database\Eloquent\Model;
56
use Illuminate\Support\Facades\Cache;
67
use Rennokki\QueryCache\Test\Models\Post;
78

89
class SimplePaginateTest extends TestCase
910
{
11+
/**
12+
* @dataProvider strictModeContextProvider
13+
*/
1014
public function test_simple_paginate()
1115
{
1216
$posts = factory(Post::class, 30)->create();
@@ -26,6 +30,9 @@ public function test_simple_paginate()
2630
);
2731
}
2832

33+
/**
34+
* @dataProvider strictModeContextProvider
35+
*/
2936
public function test_simple_paginate_with_columns()
3037
{
3138
$posts = factory(Post::class, 30)->create();

tests/TestCase.php

+12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Rennokki\QueryCache\Test;
44

5+
use Illuminate\Database\Eloquent\Model;
56
use Illuminate\Support\Facades\Cache;
67
use Orchestra\Testbench\TestCase as Orchestra;
78

@@ -14,6 +15,11 @@ public function setUp(): void
1415
{
1516
parent::setUp();
1617

18+
if ($this->getProvidedData()) {
19+
[$strict] = $this->getProvidedData();
20+
Model::preventAccessingMissingAttributes($strict);
21+
}
22+
1723
$this->resetDatabase();
1824
$this->clearCache();
1925

@@ -91,6 +97,12 @@ protected function getCacheWithTags(string $key, $tags = null)
9197
: Cache::get($key);
9298
}
9399

100+
public function strictModeContextProvider(): iterable
101+
{
102+
yield [true];
103+
yield [false];
104+
}
105+
94106
/**
95107
* Check if the current driver supports tags.
96108
*

0 commit comments

Comments
 (0)