Skip to content

Commit 4703372

Browse files
jbrooksukclaude
andauthored
Support Laravel 12 (#245)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent a744c70 commit 4703372

10 files changed

Lines changed: 57 additions & 42 deletions

File tree

.github/workflows/run-tests.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
fail-fast: false
5757
matrix:
5858
php: [8.4, 8.3, 8.2]
59-
laravel: [11.x]
59+
laravel: [12.x, 11.x]
6060
stability: [prefer-lowest, prefer-stable]
6161

6262
name: Static Analysis - P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }}
@@ -112,7 +112,7 @@ jobs:
112112
fail-fast: false
113113
matrix:
114114
php: [8.4, 8.3, 8.2]
115-
laravel: [11.x]
115+
laravel: [12.x, 11.x]
116116
stability: [prefer-lowest, prefer-stable]
117117

118118
name: Tests - P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - MySQL 8.0
@@ -182,7 +182,7 @@ jobs:
182182
fail-fast: false
183183
matrix:
184184
php: [8.4, 8.3, 8.2]
185-
laravel: [11.x]
185+
laravel: [12.x, 11.x]
186186
stability: [prefer-lowest, prefer-stable]
187187

188188
name: Tests - P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - PostgreSQL 13
@@ -251,8 +251,8 @@ jobs:
251251
strategy:
252252
fail-fast: false
253253
matrix:
254-
php: [ 8.3, 8.2 ]
255-
laravel: [ 11.x ]
254+
php: [8.4, 8.3, 8.2]
255+
laravel: [12.x, 11.x]
256256
stability: [ prefer-lowest, prefer-stable ]
257257

258258
name: Tests - P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - PostgreSQL 14
@@ -321,8 +321,8 @@ jobs:
321321
strategy:
322322
fail-fast: false
323323
matrix:
324-
php: [ 8.3, 8.2 ]
325-
laravel: [ 11.x ]
324+
php: [8.4, 8.3, 8.2]
325+
laravel: [12.x, 11.x]
326326
stability: [ prefer-lowest, prefer-stable ]
327327

328328
name: Tests - P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - PostgreSQL 15
@@ -379,8 +379,8 @@ jobs:
379379
strategy:
380380
fail-fast: false
381381
matrix:
382-
php: [ 8.3, 8.2 ]
383-
laravel: [ 11.x ]
382+
php: [8.4, 8.3, 8.2]
383+
laravel: [12.x, 11.x]
384384
stability: [ prefer-lowest, prefer-stable ]
385385

386386
name: Tests - P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - SQLite
1.24 KB
Binary file not shown.

.phpintel/index

149 Bytes
Binary file not shown.

composer.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@
2525
"filament/filament": "^4.0",
2626
"filament/spatie-laravel-settings-plugin": "^4.0",
2727
"guzzlehttp/guzzle": "^7.8",
28-
"illuminate/cache": "^11.35.0",
29-
"illuminate/console": "^11.35.0",
30-
"illuminate/database": "^11.35.0",
31-
"illuminate/events": "^11.35.0",
32-
"illuminate/queue": "^11.35.0",
33-
"illuminate/support": "^11.35.0",
28+
"illuminate/cache": "^11.35.0|^12.0",
29+
"illuminate/console": "^11.35.0|^12.0",
30+
"illuminate/database": "^11.35.0|^12.0",
31+
"illuminate/events": "^11.35.0|^12.0",
32+
"illuminate/queue": "^11.35.0|^12.0",
33+
"illuminate/support": "^11.35.0|^12.0",
3434
"laravel/sanctum": "^4.0",
35-
"nesbot/carbon": "^2.70",
35+
"nesbot/carbon": "^2.70|^3.0",
3636
"spatie/laravel-data": "^4.11",
37-
"spatie/laravel-query-builder": "^5.5",
37+
"spatie/laravel-query-builder": "^6.3",
3838
"spatie/laravel-settings": "^3.2",
3939
"spatie/laravel-webhook-server": "^3.8",
40-
"timacdonald/json-api": "^1.0.0-beta.4",
40+
"timacdonald/json-api": "^1.0.0-beta.10",
4141
"twig/twig": "^3.0"
4242
},
4343
"require-dev": {
@@ -47,11 +47,11 @@
4747
"laravel/mcp": "^0.5",
4848
"laravel/pail": "^1.1",
4949
"laravel/pint": "^1.24",
50-
"orchestra/testbench": "^9.15.1",
50+
"orchestra/testbench": "^9.15.1|^10.0",
5151
"pestphp/pest": "^3.8",
52-
"pestphp/pest-plugin-laravel": "^3.0",
53-
"pestphp/pest-plugin-livewire": "*",
54-
"pestphp/pest-plugin-type-coverage": "^3.3",
52+
"pestphp/pest-plugin-laravel": "^3.7",
53+
"pestphp/pest-plugin-livewire": "^3.0",
54+
"pestphp/pest-plugin-type-coverage": "^3.5",
5555
"psalm/plugin-laravel": "^3.14"
5656
},
5757
"minimum-stability": "dev",

src/Http/Controllers/Api/IncidentController.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Cachet\Models\Incident;
1313
use Dedoc\Scramble\Attributes\Group;
1414
use Dedoc\Scramble\Attributes\QueryParameter;
15-
use Illuminate\Database\Eloquent\Builder;
15+
use Illuminate\Http\Request;
1616
use Illuminate\Http\Response;
1717
use Illuminate\Routing\Controller;
1818
use Spatie\QueryBuilder\AllowedFilter;
@@ -38,22 +38,20 @@ class IncidentController extends Controller
3838
*/
3939
#[QueryParameter('per_page', 'How many items to show per page.', type: 'int', default: 15, example: 20)]
4040
#[QueryParameter('page', 'Which page to show.', type: 'int', example: 2)]
41-
public function index()
41+
public function index(Request $request)
4242
{
43-
$query = Incident::query()
44-
->when(! request('sort'), function (Builder $builder) {
45-
$builder->orderByDesc('created_at');
46-
});
47-
48-
$incidents = QueryBuilder::for($query)
43+
$incidents = QueryBuilder::for(Incident::query())
4944
->allowedIncludes(self::ALLOWED_INCLUDES)
5045
->allowedFilters([
5146
'name',
5247
AllowedFilter::exact('status'),
53-
'occurred_at',
48+
AllowedFilter::scope('occurs_after'),
49+
AllowedFilter::scope('occurs_before'),
50+
AllowedFilter::scope('occurs_on'),
5451
])
55-
->allowedSorts(['name', 'status', 'id'])
56-
->simplePaginate(request('per_page', 15));
52+
->allowedSorts(['name', 'status', 'id', 'created_at'])
53+
->defaultSort('-created_at')
54+
->simplePaginate($request->input('per_page', 15));
5755

5856
return IncidentResource::collection($incidents);
5957
}

src/Models/Incident.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,21 @@ public function scopeStickied(Builder $query): void
171171
$query->where('stickied', true);
172172
}
173173

174+
public function scopeOccursAfter(Builder $query, $date): void
175+
{
176+
$query->where('occurred_at', '>=', $date);
177+
}
178+
179+
public function scopeOccursBefore(Builder $query, $date): void
180+
{
181+
$query->where('occurred_at', '<=', $date);
182+
}
183+
184+
public function scopeOccursOn(Builder $query, $date): void
185+
{
186+
$query->whereDate('occurred_at', $date);
187+
}
188+
174189
/**
175190
* @return Attribute<Carbon, never>
176191
*/

src/Models/MetricPoint.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class MetricPoint extends Model
4545
protected $fillable = [
4646
'value',
4747
'counter',
48+
'created_at',
4849
];
4950

5051
public function calculatedValue(): Attribute
@@ -96,7 +97,7 @@ public function withinThreshold(int $threshold, string|int|DateTime|null $timest
9697

9798
$now ??= Carbon::parse($timestamp);
9899

99-
return $this->created_at->startOfMinute()->diffInMinutes($now->startOfMinute()) < $threshold;
100+
return $this->created_at->startOfMinute()->diffInMinutes($now->startOfMinute(), true) < $threshold;
100101
}
101102

102103
/**

tests/Feature/Api/IncidentTest.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,19 +147,18 @@
147147

148148
it('can filter incidents by occurred at date', function () {
149149
Incident::factory(20)->create([
150-
'occurred_at' => '2019-01-01',
150+
'occurred_at' => '2019-01-01 00:00:00',
151151
]);
152152
$incident = Incident::factory()->create([
153-
'occurred_at' => '2023-01-01',
153+
'occurred_at' => '2025-01-01 00:00:00',
154154
]);
155155

156-
$query = http_build_query([
156+
$response = getJson(route('cachet.api.incidents.index', [
157157
'filter' => [
158-
'occurred_at' => '2023-01-01',
158+
'occurs_after' => '2024-12-31',
159159
],
160-
]);
161-
162-
$response = getJson('/status/api/incidents?'.$query);
160+
]))
161+
->assertOk();
163162

164163
$response->assertJsonCount(1, 'data');
165164
$response->assertJsonPath('data.0.attributes.id', $incident->id);

tests/TestCase.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Livewire\LivewireServiceProvider;
1717
use Orchestra\Testbench\Concerns\WithWorkbench;
1818
use Orchestra\Testbench\TestCase as Orchestra;
19+
use Spatie\QueryBuilder\QueryBuilderServiceProvider;
1920

2021
abstract class TestCase extends Orchestra
2122
{
@@ -42,6 +43,7 @@ protected function getPackageProviders($app)
4243
BladeHeroiconsServiceProvider::class,
4344
WidgetsServiceProvider::class,
4445
ScrambleServiceProvider::class,
46+
QueryBuilderServiceProvider::class,
4547
]);
4648

4749
// Laravel apps register providers in alphabetical order, so we do the same here for consistency.

tests/Unit/Actions/Metric/CreateMetricPointTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106

107107
expect($point)
108108
->toBeInstanceOf(MetricPoint::class)
109-
->created_at->isSameAs(Carbon::parse($timestamp));
109+
->created_at->toDateTimeString()->toBe(Carbon::parse($timestamp)->toDateTimeString());
110110
})->with([
111111
now()->addWeek()->startOfMinute()->unix(),
112112
now()->subHour()->startOfMinute()->toAtomString(),

0 commit comments

Comments
 (0)