Skip to content

Commit 78201e3

Browse files
authored
Merge remote-tracking branch 'origin/master' into pr/laravel-shift/459
2 parents c90c9c5 + eda274d commit 78201e3

File tree

6 files changed

+114
-16
lines changed

6 files changed

+114
-16
lines changed

.github/workflows/laravel.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
with:
4545
postgresql version: '15'
4646
postgresql db: 'testing'
47-
postgresql user: 'homestead'
47+
postgresql user: 'forge'
4848
postgresql password: 'secret'
4949

5050
- name: Remove Nova on a pull request
@@ -56,7 +56,7 @@ jobs:
5656

5757
- name: Install Dependencies
5858
run: |
59-
composer config "http-basic.nova.laravel.com" "${{ secrets.NOVA_USERNAME }}" "${{ secrets.NOVA_PASSWORD }}"
59+
composer config "http-basic.nova.laravel.com" "${{ secrets.NOVA_USERNAME }}" "${{ secrets.NOVA_LICENSE_KEY }}"
6060
composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist
6161
6262
- name: Execute Integration and Feature tests via PHPUnit

phpunit.xml.dist

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit
3+
backupGlobals="false"
4+
backupStaticProperties="false"
5+
bootstrap="vendor/autoload.php"
6+
cacheDirectory=".phpunit.cache"
7+
colors="true"
8+
processIsolation="false"
9+
stopOnFailure="true"
10+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
11+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
12+
>
13+
<testsuites>
14+
<testsuite name="Feature">
15+
<directory suffix="Test.php">./tests/Feature</directory>
16+
</testsuite>
17+
<testsuite name="Integration">
18+
<directory suffix="Test.php">./tests/Integration</directory>
19+
</testsuite>
20+
<testsuite name="Nova">
21+
<directory suffix="Test.php">./tests/Nova</directory>
22+
</testsuite>
23+
</testsuites>
24+
<php>
25+
<server name="APP_ENV" value="testing"/>
26+
<server name="APP_KEY" value="base64:Xgs1LQt1GdVHhD6qyYCXnyq61DE3UKqJ5k2SJc+Nw2g="/>
27+
<server name="APP_URL" value="http://localhost"/>
28+
<server name="CACHE_DRIVER" value="redis"/>
29+
<server name="DB_CONNECTION" value="sqlite"/>
30+
<server name="DB_DATABASE" value=":memory:"/>
31+
<server name="DB_PASSWORD" value="secret"/>
32+
<server name="DB_USERNAME" value="homestead"/>
33+
<server name="PGSQL_HOST" value="127.0.0.1"/>
34+
<server name="QUEUE_DRIVER" value="sync"/>
35+
<server name="REDIS_HOST" value="127.0.0.1"/>
36+
<server name="SESSION_DRIVER" value="array"/>
37+
</php>
38+
<source>
39+
<include>
40+
<directory suffix=".php">./src</directory>
41+
</include>
42+
</source>
43+
</phpunit>

src/Traits/Caching.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function applyScopes()
4141
if ($this->scopesAreApplied) {
4242
return $this;
4343
}
44-
44+
4545
return parent::applyScopes();
4646
}
4747

@@ -170,7 +170,7 @@ protected function makeCacheKey(
170170
?? Container::getInstance()
171171
->make("db")
172172
->query();
173-
173+
174174
if (
175175
$this->query
176176
&& method_exists($this->query, "getQuery")
@@ -263,6 +263,10 @@ protected function checkCooldownAndRemoveIfExpired(Model $instance)
263263

264264
protected function checkCooldownAndFlushAfterPersisting(Model $instance, string $relationship = "")
265265
{
266+
if (! $this->isCachable()) {
267+
return;
268+
}
269+
266270
[$cacheCooldown, $invalidatedAt] = $instance->getModelCacheCooldown($instance);
267271

268272
if (! $cacheCooldown) {
@@ -295,6 +299,11 @@ public function isCachable() : bool
295299
$isCacheDisabled = ! Container::getInstance()
296300
->make("config")
297301
->get("laravel-model-caching.enabled");
302+
303+
if ($isCacheDisabled) {
304+
return false;
305+
}
306+
298307
$allRelationshipsAreCachable = true;
299308

300309
if (
@@ -311,7 +320,7 @@ public function isCachable() : bool
311320
) {
312321
return $carry;
313322
}
314-
323+
315324
$relatedModel = $this->model->$related()->getRelated();
316325

317326
if (
@@ -327,7 +336,6 @@ public function isCachable() : bool
327336
}
328337

329338
return $this->isCachable
330-
&& ! $isCacheDisabled
331339
&& $allRelationshipsAreCachable;
332340
}
333341

tests/CreatesApplication.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,26 @@ protected function getEnvironmentSetUp($app)
139139
]);
140140
}
141141

142-
public function appVersionEightAndUp(): bool
142+
public function appVersionEightAndNine(): bool
143143
{
144-
return version_compare(app()->version(), '8.0.0', '>=');
144+
return version_compare(app()->version(), '8.0.0', '>=')
145+
&& version_compare(app()->version(), '10.0.0', '<');
145146
}
146147

147148
public function appVersionFiveBetweenSeven(): bool
148149
{
149-
return version_compare(app()->version(), '5.6.0', '>=') && version_compare(app()->version(), '8.0.0', '<');
150+
return version_compare(app()->version(), '5.6.0', '>=')
151+
&& version_compare(app()->version(), '8.0.0', '<');
150152
}
151153

152154
public function appVersionOld(): bool
153155
{
154-
return version_compare(app()->version(), '5.4.0', '>=') && version_compare(app()->version(), '5.6.0', '<');
156+
return version_compare(app()->version(), '5.4.0', '>=')
157+
&& version_compare(app()->version(), '5.6.0', '<');
158+
}
159+
160+
public function appVersionTen(): bool
161+
{
162+
return version_compare(app()->version(), '10.0.0', '>=');
155163
}
156164
}

tests/Feature/PaginationTest.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@ class PaginationTest extends FeatureTestCase
77
{
88
public function testPaginationProvidesDifferentLinksOnDifferentPages()
99
{
10+
// Checking the version start with 10.0.
11+
if ($this->appVersionTen()) {
12+
$page1ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5 dark:bg-gray-800 dark:border-gray-600">1</span>';
13+
$page2ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5 dark:bg-gray-800 dark:border-gray-600">2</span>';
14+
}
15+
1016
// Checking the version start with 8.0.
11-
if ($this->appVersionEightAndUp()) {
17+
if ($this->appVersionEightAndNine()) {
1218
$page1ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5">1</span>';
1319
$page2ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5">2</span>';
1420
}
@@ -39,8 +45,14 @@ public function testPaginationProvidesDifferentLinksOnDifferentPages()
3945

4046
public function testAdvancedPagination()
4147
{
48+
// Checking the version start with 10.0.
49+
if ($this->appVersionTen()) {
50+
$page1ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5 dark:bg-gray-800 dark:border-gray-600">1</span>';
51+
$page2ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5 dark:bg-gray-800 dark:border-gray-600">2</span>';
52+
}
53+
4254
// Checking the version start with 8.0.
43-
if ($this->appVersionEightAndUp()) {
55+
if ($this->appVersionEightAndNine()) {
4456
$page1ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5">1</span>';
4557
$page2ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5">2</span>';
4658
}
@@ -62,8 +74,14 @@ public function testAdvancedPagination()
6274

6375
public function testCustomPagination()
6476
{
77+
// Checking the version start with 10.0.
78+
if ($this->appVersionTen()) {
79+
$page1ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5 dark:bg-gray-800 dark:border-gray-600">1</span>';
80+
$page2ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5 dark:bg-gray-800 dark:border-gray-600">2</span>';
81+
}
82+
6583
// Checking the version start with 8.0.
66-
if ($this->appVersionEightAndUp()) {
84+
if ($this->appVersionEightAndNine()) {
6785
$page1ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5">1</span>';
6886
$page2ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5">2</span>';
6987
}

tests/Integration/CachedBuilder/PaginateTest.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ public function testPaginationIsCached()
3636

3737
public function testPaginationReturnsCorrectLinks()
3838
{
39-
if ($this->appVersionEightAndUp()) {
39+
// Checking the version start with 10.0.
40+
if ($this->appVersionTen()) {
41+
$page1ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5 dark:bg-gray-800 dark:border-gray-600">1</span>';
42+
$page2ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5 dark:bg-gray-800 dark:border-gray-600">2</span>';
43+
$page24ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5 dark:bg-gray-800 dark:border-gray-600">24</span>';
44+
}
45+
46+
if ($this->appVersionEightAndNine()) {
4047
$page1ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5">1</span>';
4148
$page2ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5">2</span>';
4249
$page24ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5">24</span>';
@@ -71,7 +78,14 @@ public function testPaginationReturnsCorrectLinks()
7178

7279
public function testPaginationWithOptionsReturnsCorrectLinks()
7380
{
74-
if ($this->appVersionEightAndUp()) {
81+
// Checking the version start with 10.0.
82+
if ($this->appVersionTen()) {
83+
$page1ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5 dark:bg-gray-800 dark:border-gray-600">1</span>';
84+
$page2ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5 dark:bg-gray-800 dark:border-gray-600">2</span>';
85+
$page24ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5 dark:bg-gray-800 dark:border-gray-600">24</span>';
86+
}
87+
88+
if ($this->appVersionEightAndNine()) {
7589
$page1ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5">1</span>';
7690
$page2ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5">2</span>';
7791
$page24ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5">24</span>';
@@ -106,7 +120,14 @@ public function testPaginationWithOptionsReturnsCorrectLinks()
106120

107121
public function testPaginationWithCustomOptionsReturnsCorrectLinks()
108122
{
109-
if ($this->appVersionEightAndUp()) {
123+
// Checking the version start with 10.0.
124+
if ($this->appVersionTen()) {
125+
$page1ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5 dark:bg-gray-800 dark:border-gray-600">1</span>';
126+
$page2ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5 dark:bg-gray-800 dark:border-gray-600">2</span>';
127+
$page24ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5 dark:bg-gray-800 dark:border-gray-600">24</span>';
128+
}
129+
130+
if ($this->appVersionEightAndNine()) {
110131
$page1ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5">1</span>';
111132
$page2ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5">2</span>';
112133
$page24ActiveLink = '<span class="relative inline-flex items-center px-4 py-2 -ml-px text-sm font-medium text-gray-500 bg-white border border-gray-300 cursor-default leading-5">24</span>';

0 commit comments

Comments
 (0)