Skip to content

Commit 57a1b08

Browse files
authored
Merge pull request #440 from faytekin/laravel-10
Add support for Laravel 10
2 parents 3530b50 + d84e1d7 commit 57a1b08

File tree

11 files changed

+84
-48
lines changed

11 files changed

+84
-48
lines changed

Diff for: .github/workflows/laravel.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ jobs:
1414
strategy:
1515
fail-fast: true
1616
matrix:
17-
php: [8.0, 8.1]
17+
php: [8.2, 8.1]
1818

1919
name: PHP ${{ matrix.php }}
2020

2121
steps:
22-
- uses: actions/checkout@v2
22+
- name: Checkout code
23+
uses: actions/checkout@v3
2324

2425
- name: Cache dependencies
2526
uses: actions/cache@v1

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
composer.lock
44
.phpunit.result.cache
55
phpunit.xml
6+
.idea

Diff for: composer.json

+11-11
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@
1515
}
1616
],
1717
"require": {
18-
"php": "^8.0",
19-
"genealabs/laravel-pivot-events": "^9.0",
20-
"illuminate/cache": "^9.0",
21-
"illuminate/config": "^9.0",
22-
"illuminate/console": "^9.0",
23-
"illuminate/container": "^9.0",
24-
"illuminate/database": "^9.0",
25-
"illuminate/http": "^9.0",
26-
"illuminate/support": "^9.0"
18+
"php": "^8.1",
19+
"genealabs/laravel-pivot-events": "^10.0",
20+
"illuminate/cache": "^10.0",
21+
"illuminate/config": "^10.0",
22+
"illuminate/console": "^10.0",
23+
"illuminate/container": "^10.0",
24+
"illuminate/database": "^10.0",
25+
"illuminate/http": "^10.0",
26+
"illuminate/support": "^10.0"
2727
},
2828
"require-dev": {
2929
"doctrine/dbal": "^3.3",
3030
"fakerphp/faker": "^1.11",
3131
"laravel/nova": "^3.9",
32-
"orchestra/testbench-browser-kit": "^7.0",
33-
"orchestra/testbench": "^7.0",
32+
"orchestra/testbench-browser-kit": "^8.0",
33+
"orchestra/testbench": "^8.0",
3434
"php-coveralls/php-coveralls" : "^2.2",
3535
"phpmd/phpmd": "^2.11",
3636
"phpunit/phpunit": "^9.5",

Diff for: src/CacheKey.php

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

33
use Exception;
44
use GeneaLabs\LaravelModelCaching\Traits\CachePrefixing;
5+
use Illuminate\Database\Query\Expression;
56
use Illuminate\Support\Arr;
67
use Illuminate\Support\Collection;
78
use Illuminate\Support\Str;
@@ -170,14 +171,19 @@ protected function getOrderByClauses() : string
170171
}
171172

172173
$orders = collect($this->query->orders);
173-
174+
174175
return $orders
175176
->reduce(function ($carry, $order) {
176177
if (($order["type"] ?? "") === "Raw") {
177178
return $carry . "_orderByRaw_" . (new Str)->slug($order["sql"]);
178179
}
179180

180-
return $carry . "_orderBy_" . $order["column"] . "_" . $order["direction"];
181+
return sprintf(
182+
'%s_orderBy_%s_%s',
183+
$carry,
184+
$this->expressionToString($order["column"]),
185+
$order["direction"]
186+
);
181187
})
182188
?: "";
183189
}
@@ -211,7 +217,11 @@ protected function getQueryColumns(array $columns) : string
211217
if (property_exists($this->query, "columns")
212218
&& $this->query->columns
213219
) {
214-
return "_" . implode("_", $this->query->columns);
220+
$columns = array_map(function ($column) {
221+
return $this->expressionToString($column);
222+
}, $this->query->columns);
223+
224+
return "_" . implode("_", $columns);
215225
}
216226

217227
return "_" . implode("_", $columns);
@@ -393,12 +403,14 @@ protected function recursiveImplode(array $items, string $glue = ",") : string
393403
return $result;
394404
}
395405

396-
private function processEnum(\BackedEnum|\UnitEnum|string $value): string
406+
private function processEnum(\BackedEnum|\UnitEnum|Expression|string $value): string
397407
{
398408
if ($value instanceof \BackedEnum) {
399409
return $value->value;
400410
} elseif ($value instanceof \UnitEnum) {
401411
return $value->name;
412+
} elseif ($value instanceof Expression) {
413+
return $this->expressionToString($value);
402414
}
403415

404416
return $value;
@@ -408,4 +420,13 @@ private function processEnums(array $values): array
408420
{
409421
return array_map(fn($value) => $this->processEnum($value), $values);
410422
}
423+
424+
private function expressionToString(Expression|string $value): string
425+
{
426+
if (is_string($value)) {
427+
return $value;
428+
}
429+
430+
return $value->getValue($this->query->getConnection()->getQueryGrammar());
431+
}
411432
}

Diff for: tests/CreatesApplication.php

+15
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,19 @@ protected function getEnvironmentSetUp($app)
138138
'pagination' => 'simple',
139139
]);
140140
}
141+
142+
public function appVersionEightAndUp(): bool
143+
{
144+
return version_compare(app()->version(), '8.0.0', '>=');
145+
}
146+
147+
public function appVersionFiveBetweenSeven(): bool
148+
{
149+
return version_compare(app()->version(), '5.6.0', '>=') && version_compare(app()->version(), '8.0.0', '<');
150+
}
151+
152+
public function appVersionOld(): bool
153+
{
154+
return version_compare(app()->version(), '5.4.0', '>=') && version_compare(app()->version(), '5.6.0', '<');
155+
}
141156
}

Diff for: tests/Feature/PaginationTest.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ class PaginationTest extends FeatureTestCase
88
public function testPaginationProvidesDifferentLinksOnDifferentPages()
99
{
1010
// Checking the version start with 8.0.
11-
if (preg_match("/^([8|9]\.)/", app()->version())) {
11+
if ($this->appVersionEightAndUp()) {
1212
$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>';
1313
$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>';
1414
}
1515

16-
// Checking the version start with 5.6, 5.7, 5.8 or 6.
17-
if (preg_match("/^((5\.[6-8])|(6\.)|(7\.))/", app()->version())) {
16+
// Checking the version start with 5.6, 5.7, 5.8, 6 or 7.
17+
if ($this->appVersionFiveBetweenSeven()) {
1818
$page1ActiveLink = '<li class="page-item active" aria-current="page"><span class="page-link">1</span></li>';
1919
$page2ActiveLink = '<li class="page-item active" aria-current="page"><span class="page-link">2</span></li>';
2020
}
2121

2222
// Checking the version 5.4 and 5.5
23-
if (preg_match("/^5\.[4-5]/", app()->version())) {
23+
if ($this->appVersionOld()) {
2424
$page1ActiveLink = '<li class="active"><span>1</span></li>';
2525
$page2ActiveLink = '<li class="active"><span>2</span></li>';
2626
}
@@ -40,17 +40,17 @@ public function testPaginationProvidesDifferentLinksOnDifferentPages()
4040
public function testAdvancedPagination()
4141
{
4242
// Checking the version start with 8.0.
43-
if (preg_match("/^([8|9]\.)/", app()->version())) {
43+
if ($this->appVersionEightAndUp()) {
4444
$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>';
4545
$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>';
4646
}
4747

48-
if (preg_match("/^((5\.[6-8])|(6\.)|(7\.))/", app()->version())) {
48+
if ($this->appVersionFiveBetweenSeven()) {
4949
$page1ActiveLink = '<li class="page-item active" aria-current="page"><span class="page-link">1</span></li>';
5050
$page2ActiveLink = '<li class="page-item active" aria-current="page"><span class="page-link">2</span></li>';
5151
}
5252

53-
if (preg_match("/^5\.[4-5]/", app()->version())) {
53+
if ($this->appVersionOld()) {
5454
$page1ActiveLink = '<li class="active"><span>1</span></li>';
5555
$page2ActiveLink = '<li class="active"><span>2</span></li>';
5656
}
@@ -63,17 +63,17 @@ public function testAdvancedPagination()
6363
public function testCustomPagination()
6464
{
6565
// Checking the version start with 8.0.
66-
if (preg_match("/^([8|9]\.)/", app()->version())) {
66+
if ($this->appVersionEightAndUp()) {
6767
$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>';
6868
$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>';
6969
}
7070

71-
if (preg_match("/^((5\.[6-8])|(6\.)|(7\.))/", app()->version())) {
71+
if ($this->appVersionFiveBetweenSeven()) {
7272
$page1ActiveLink = '<li class="page-item active" aria-current="page"><span class="page-link">1</span></li>';
7373
$page2ActiveLink = '<li class="page-item active" aria-current="page"><span class="page-link">2</span></li>';
7474
}
7575

76-
if (preg_match("/^5\.[4-5]/", app()->version())) {
76+
if ($this->appVersionOld()) {
7777
$page1ActiveLink = '<li class="active"><span>1</span></li>';
7878
$page2ActiveLink = '<li class="active"><span>2</span></li>';
7979
}

Diff for: tests/Fixtures/Book.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ class Book extends Model
1414

1515
protected $casts = [
1616
'price' => 'float',
17+
'published_at' => 'datetime',
1718
];
18-
protected $dates = [
19-
'published_at',
20-
];
19+
2120
protected $fillable = [
2221
"author_id",
2322
'description',

Diff for: tests/Fixtures/BookWithUncachedStore.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ class BookWithUncachedStore extends Model
1414

1515
protected $casts = [
1616
'price' => 'float',
17+
'published_at' => 'datetime',
1718
];
18-
protected $dates = [
19-
'published_at',
20-
];
19+
2120
protected $fillable = [
2221
"author_id",
2322
'description',

Diff for: tests/Fixtures/UncachedBook.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ class UncachedBook extends Model
1010
{
1111
protected $casts = [
1212
'price' => 'float',
13+
'published_at' => 'datetime',
1314
];
14-
protected $dates = [
15-
'published_at',
16-
];
15+
1716
protected $fillable = [
1817
'description',
1918
'published_at',
2019
'title',
2120
];
21+
2222
protected $table = 'books';
2323

2424
public function author() : BelongsTo

Diff for: tests/Fixtures/UncachedBookWithStores.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ class UncachedBookWithStores extends Model
1010
{
1111
protected $casts = [
1212
'price' => 'float',
13+
'published_at' => 'datetime',
1314
];
14-
protected $dates = [
15-
'published_at',
16-
];
15+
1716
protected $fillable = [
1817
'description',
1918
'published_at',
2019
'title',
2120
];
21+
2222
protected $table = 'books';
2323

2424
public function author() : BelongsTo

Diff for: tests/Integration/CachedBuilder/PaginateTest.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@ public function testPaginationIsCached()
3636

3737
public function testPaginationReturnsCorrectLinks()
3838
{
39-
if (preg_match("/^([8|9]\.)/", app()->version())) {
39+
if ($this->appVersionEightAndUp()) {
4040
$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>';
4141
$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>';
4242
$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>';
4343
}
4444

45-
if (preg_match("/^((5\.[6-8])|(6\.)|(7\.))/", app()->version())) {
45+
if ($this->appVersionFiveBetweenSeven()) {
4646
$page1ActiveLink = '<li class="page-item active" aria-current="page"><span class="page-link">1</span></li>';
4747
$page2ActiveLink = '<li class="page-item active" aria-current="page"><span class="page-link">2</span></li>';
4848
$page24ActiveLink = '<li class="page-item active" aria-current="page"><span class="page-link">24</span></li>';
4949
}
5050

51-
if (preg_match("/^5\.[4-5]/", app()->version())) {
51+
if ($this->appVersionOld()) {
5252
$page1ActiveLink = '<li class="active"><span>1</span></li>';
5353
$page2ActiveLink = '<li class="active"><span>2</span></li>';
5454
$page24ActiveLink = '<li class="active"><span>24</span></li>';
@@ -71,19 +71,19 @@ public function testPaginationReturnsCorrectLinks()
7171

7272
public function testPaginationWithOptionsReturnsCorrectLinks()
7373
{
74-
if (preg_match("/^([8|9]\.)/", app()->version())) {
74+
if ($this->appVersionEightAndUp()) {
7575
$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>';
7676
$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>';
7777
$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>';
7878
}
7979

80-
if (preg_match("/^((5\.[6-8])|(6\.)|(7\.))/", app()->version())) {
80+
if ($this->appVersionFiveBetweenSeven()) {
8181
$page1ActiveLink = '<li class="page-item active" aria-current="page"><span class="page-link">1</span></li>';
8282
$page2ActiveLink = '<li class="page-item active" aria-current="page"><span class="page-link">2</span></li>';
8383
$page24ActiveLink = '<li class="page-item active" aria-current="page"><span class="page-link">24</span></li>';
8484
}
8585

86-
if (preg_match("/^5\.[4-5]/", app()->version())) {
86+
if ($this->appVersionOld()) {
8787
$page1ActiveLink = '<li class="active"><span>1</span></li>';
8888
$page2ActiveLink = '<li class="active"><span>2</span></li>';
8989
$page24ActiveLink = '<li class="active"><span>24</span></li>';
@@ -106,19 +106,19 @@ public function testPaginationWithOptionsReturnsCorrectLinks()
106106

107107
public function testPaginationWithCustomOptionsReturnsCorrectLinks()
108108
{
109-
if (preg_match("/^([8|9]\.)/", app()->version())) {
109+
if ($this->appVersionEightAndUp()) {
110110
$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>';
111111
$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>';
112112
$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>';
113113
}
114114

115-
if (preg_match("/^((5\.[6-8])|(6\.)|(7\.))/", app()->version())) {
115+
if ($this->appVersionFiveBetweenSeven()) {
116116
$page1ActiveLink = '<li class="page-item active" aria-current="page"><span class="page-link">1</span></li>';
117117
$page2ActiveLink = '<li class="page-item active" aria-current="page"><span class="page-link">2</span></li>';
118118
$page24ActiveLink = '<li class="page-item active" aria-current="page"><span class="page-link">24</span></li>';
119119
}
120120

121-
if (preg_match("/^5\.[4-5]/", app()->version())) {
121+
if ($this->appVersionOld()) {
122122
$page1ActiveLink = '<li class="active"><span>1</span></li>';
123123
$page2ActiveLink = '<li class="active"><span>2</span></li>';
124124
$page24ActiveLink = '<li class="active"><span>24</span></li>';

0 commit comments

Comments
 (0)