Skip to content

Commit 5d3f48b

Browse files
[5.x] Adds Laravel 11 support (#1420)
* Adds Laravel 11 support * Updates upgrade guide * Updates upgrade guide * Uses `publishesMigrations` * Publishes migrations on `telescope:install` command * Fixes test suite on Laravel versions prior to Laravel 11 * Don't create jobs table if not necessary * Keeps working on the test suite * Apply fixes from StyleCI * Fixes test suite * Apply fixes from StyleCI * Bumps testbench * Reverts non-needed changes * Reverts change on tests * Adds older upgrade guide notes --------- Co-authored-by: StyleCI Bot <[email protected]>
1 parent a978f6e commit 5d3f48b

17 files changed

+124
-105
lines changed

.github/workflows/tests.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ jobs:
2424
fail-fast: true
2525
matrix:
2626
php: [8.0, 8.1, 8.2, 8.3]
27-
laravel: [8, 9, 10]
27+
laravel: [8, 9, 10, 11]
2828
exclude:
2929
- php: '8.0'
3030
laravel: 10
31+
- php: '8.0'
32+
laravel: 11
33+
- php: 8.1
34+
laravel: 11
3135
- php: 8.2
3236
laravel: 8
3337
- php: 8.3

UPGRADE.md

+10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ With every upgrade, make sure to publish Telescope's assets and clear the view c
66

77
php artisan view:clear
88

9+
## Upgrading To 5.0 From 4.x
10+
11+
### Migration Changes
12+
13+
Telescope 5.0 no longer automatically loads migrations from its own migrations directory. Instead, you should run the following command to publish Telescope's migrations to your application:
14+
15+
```bash
16+
php artisan vendor:publish --tag=telescope-migrations
17+
```
18+
919
## Upgrading To 4.0 From 3.x
1020

1121
### Minimum PHP Version

composer.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616
"require": {
1717
"php": "^8.0",
1818
"ext-json": "*",
19-
"laravel/framework": "^8.37|^9.0|^10.0",
20-
"symfony/var-dumper": "^5.0|^6.0"
19+
"laravel/framework": "^8.37|^9.0|^10.0|^11.0",
20+
"symfony/var-dumper": "^5.0|^6.0|^7.0"
2121
},
2222
"require-dev": {
2323
"ext-gd": "*",
2424
"guzzlehttp/guzzle": "^6.0|^7.0",
25-
"laravel/octane": "^1.4",
26-
"orchestra/testbench": "^6.0|^7.0|^8.0",
25+
"laravel/octane": "^1.4|^2.0|dev-develop",
26+
"orchestra/testbench": "^6.40|^7.37|^8.17|^9.0",
2727
"phpstan/phpstan": "^1.10",
28-
"phpunit/phpunit": "^9.0"
28+
"phpunit/phpunit": "^9.0|^10.4"
2929
},
3030
"autoload": {
3131
"psr-4": {

src/Console/InstallCommand.php

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Laravel\Telescope\Console;
44

55
use Illuminate\Console\Command;
6+
use Illuminate\Support\ServiceProvider;
67
use Illuminate\Support\Str;
78

89
class InstallCommand extends Command
@@ -37,6 +38,9 @@ public function handle()
3738
$this->comment('Publishing Telescope Configuration...');
3839
$this->callSilent('vendor:publish', ['--tag' => 'telescope-config']);
3940

41+
$this->comment('Publishing Telescope Migrations...');
42+
$this->callSilent('vendor:publish', ['--tag' => 'telescope-migrations']);
43+
4044
$this->registerTelescopeServiceProvider();
4145

4246
$this->info('Telescope scaffolding installed successfully.');
@@ -49,6 +53,11 @@ public function handle()
4953
*/
5054
protected function registerTelescopeServiceProvider()
5155
{
56+
if (method_exists(ServiceProvider::class, 'addProviderToBootstrapFile') &&
57+
ServiceProvider::addProviderToBootstrapFile(\App\Providers\TelescopeServiceProvider::class)) { // @phpstan-ignore-line
58+
return;
59+
}
60+
5261
$namespace = Str::replaceLast('\\', '', $this->laravel->getNamespace());
5362

5463
$appConfig = file_get_contents(config_path('app.php'));

src/Telescope.php

-19
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,6 @@ class Telescope
120120
*/
121121
public static $shouldRecord = false;
122122

123-
/**
124-
* Indicates if Telescope migrations will be run.
125-
*
126-
* @var bool
127-
*/
128-
public static $runsMigrations = true;
129-
130123
/**
131124
* Register the Telescope watchers and start recording if necessary.
132125
*
@@ -819,16 +812,4 @@ public static function scriptVariables()
819812
'recording' => ! cache('telescope:pause-recording'),
820813
];
821814
}
822-
823-
/**
824-
* Configure Telescope to not register its migrations.
825-
*
826-
* @return static
827-
*/
828-
public static function ignoreMigrations()
829-
{
830-
static::$runsMigrations = false;
831-
832-
return new static;
833-
}
834815
}

src/TelescopeServiceProvider.php

+5-24
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class TelescopeServiceProvider extends ServiceProvider
1818
*/
1919
public function boot()
2020
{
21-
$this->registerMigrations();
2221
$this->registerCommands();
2322
$this->registerPublishing();
2423

@@ -62,18 +61,6 @@ protected function registerResources()
6261
$this->loadViewsFrom(__DIR__.'/../resources/views', 'telescope');
6362
}
6463

65-
/**
66-
* Register the package's migrations.
67-
*
68-
* @return void
69-
*/
70-
protected function registerMigrations()
71-
{
72-
if ($this->app->runningInConsole() && $this->shouldMigrate()) {
73-
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
74-
}
75-
}
76-
7764
/**
7865
* Register the package's publishable resources.
7966
*
@@ -82,7 +69,11 @@ protected function registerMigrations()
8269
protected function registerPublishing()
8370
{
8471
if ($this->app->runningInConsole()) {
85-
$this->publishes([
72+
$publishesMigrationsMethod = method_exists($this, 'publishesMigrations')
73+
? 'publishesMigrations'
74+
: 'publishes';
75+
76+
$this->{$publishesMigrationsMethod}([
8677
__DIR__.'/../database/migrations' => database_path('migrations'),
8778
], 'telescope-migrations');
8879

@@ -174,14 +165,4 @@ protected function registerDatabaseDriver()
174165
->needs('$chunkSize')
175166
->give(config('telescope.storage.database.chunk'));
176167
}
177-
178-
/**
179-
* Determine if we should register the migrations.
180-
*
181-
* @return bool
182-
*/
183-
protected function shouldMigrate()
184-
{
185-
return Telescope::$runsMigrations && config('telescope.driver') === 'database';
186-
}
187168
}

testbench.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ providers:
22
- Laravel\Telescope\TelescopeServiceProvider
33
- Workbench\App\Providers\TelescopeServiceProvider
44

5-
migrations: true
5+
migrations:
6+
- database/migrations
7+
68
seeders:
79
- Workbench\Database\Seeders\DatabaseSeeder
810

tests/FeatureTestCase.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
use Laravel\Telescope\Storage\EntryModel;
1111
use Laravel\Telescope\Telescope;
1212
use Laravel\Telescope\TelescopeServiceProvider;
13+
use Orchestra\Testbench\Concerns\WithLaravelMigrations;
14+
use Orchestra\Testbench\Concerns\WithWorkbench;
1315
use Orchestra\Testbench\TestCase;
1416

1517
class FeatureTestCase extends TestCase
1618
{
17-
use RefreshDatabase;
19+
use WithWorkbench, RefreshDatabase, WithLaravelMigrations;
1820

1921
protected function setUp(): void
2022
{

tests/Http/AuthorizationTest.php

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Laravel\Telescope\Tests\Http;
44

55
use Illuminate\Contracts\Auth\Authenticatable;
6+
use Illuminate\Foundation\Http\Middleware\ValidateCsrfToken;
67
use Illuminate\Http\Request;
78
use Illuminate\Support\Facades\Gate;
89
use Laravel\Telescope\Telescope;
@@ -25,6 +26,7 @@ protected function setUp(): void
2526
parent::setUp();
2627

2728
$this->withoutMiddleware([VerifyCsrfToken::class]);
29+
$this->withoutMiddleware([ValidateCsrfToken::class]);
2830
}
2931

3032
protected function tearDown(): void
@@ -132,6 +134,11 @@ public function getAuthPassword()
132134
return 'secret';
133135
}
134136

137+
public function getAuthPasswordName()
138+
{
139+
return 'passord name';
140+
}
141+
135142
public function getRememberToken()
136143
{
137144
return 'i-am-telescope';

tests/Http/AvatarTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ public function getAuthPassword()
9595
return $this->password;
9696
}
9797

98+
public function getAuthPasswordName()
99+
{
100+
return 'passord name';
101+
}
102+
98103
public function getRememberToken()
99104
{
100105
return 'i-am-telescope';

tests/Http/RouteTest.php

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

33
namespace Laravel\Telescope\Tests\Http;
44

5+
use Illuminate\Foundation\Http\Middleware\ValidateCsrfToken;
56
use Illuminate\Testing\TestResponse;
67
use Laravel\Telescope\Database\Factories\EntryModelFactory;
78
use Laravel\Telescope\EntryType;
@@ -16,12 +17,12 @@ protected function setUp(): void
1617
{
1718
parent::setUp();
1819

19-
$this->withoutMiddleware([Authorize::class, VerifyCsrfToken::class]);
20+
$this->withoutMiddleware([Authorize::class, VerifyCsrfToken::class, ValidateCsrfToken::class]);
2021

2122
$this->registerAssertJsonExactFragmentMacro();
2223
}
2324

24-
public function telescopeIndexRoutesProvider()
25+
public static function telescopeIndexRoutesProvider()
2526
{
2627
return [
2728
'Mail' => ['/telescope/telescope-api/mail', EntryType::MAIL],

tests/Watchers/BatchWatcherTest.php

+11-9
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,17 @@ public function test_job_dispatch_registers_entries()
7878

7979
private function createJobsTable(): void
8080
{
81-
Schema::create('jobs', function (Blueprint $table) {
82-
$table->bigIncrements('id');
83-
$table->string('queue')->index();
84-
$table->longText('payload');
85-
$table->unsignedTinyInteger('attempts');
86-
$table->unsignedInteger('reserved_at')->nullable();
87-
$table->unsignedInteger('available_at');
88-
$table->unsignedInteger('created_at');
89-
});
81+
if (! Schema::hasTable('jobs')) {
82+
Schema::create('jobs', function (Blueprint $table) {
83+
$table->bigIncrements('id');
84+
$table->string('queue')->index();
85+
$table->longText('payload');
86+
$table->unsignedTinyInteger('attempts');
87+
$table->unsignedInteger('reserved_at')->nullable();
88+
$table->unsignedInteger('available_at');
89+
$table->unsignedInteger('created_at');
90+
});
91+
}
9092

9193
Schema::create('job_batches', function ($table) {
9294
$table->string('id')->primary();

tests/Watchers/EventWatcherTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function test_format_listeners($listener, $formatted)
114114
$this->assertSame($formatted, $method->invoke(new EventWatcher, DummyEvent::class)[0]['name']);
115115
}
116116

117-
public function formatListenersProvider()
117+
public static function formatListenersProvider()
118118
{
119119
return [
120120
'class string' => [

0 commit comments

Comments
 (0)