Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Adds Laravel 11 support #1420

Merged
merged 16 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ jobs:
fail-fast: true
matrix:
php: [8.0, 8.1, 8.2, 8.3]
laravel: [8, 9, 10]
laravel: [8, 9, 10, 11]
exclude:
- php: '8.0'
laravel: 10
- php: '8.0'
laravel: 11
- php: 8.1
laravel: 11
- php: 8.2
laravel: 8
- php: 8.3
Expand Down
10 changes: 10 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ With every upgrade, make sure to publish Telescope's assets and clear the view c

php artisan view:clear

## Upgrading To 5.0 From 4.x

### Migration Changes

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:

```bash
php artisan vendor:publish --tag=telescope-migrations
```
nunomaduro marked this conversation as resolved.
Show resolved Hide resolved

## Upgrading To 4.0 From 3.x

### Minimum PHP Version
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
"require": {
"php": "^8.0",
"ext-json": "*",
"laravel/framework": "^8.37|^9.0|^10.0",
"symfony/var-dumper": "^5.0|^6.0"
"laravel/framework": "^8.37|^9.0|^10.0|^11.0",
"symfony/var-dumper": "^5.0|^6.0|^7.0"
},
"require-dev": {
"ext-gd": "*",
"guzzlehttp/guzzle": "^6.0|^7.0",
"laravel/octane": "^1.4",
"orchestra/testbench": "^6.0|^7.0|^8.0",
"laravel/octane": "^1.4|^2.0|dev-develop",
"orchestra/testbench": "^6.40|^7.37|^8.17|^9.0",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9.0"
"phpunit/phpunit": "^9.0|^10.4"
},
"autoload": {
"psr-4": {
Expand Down
9 changes: 9 additions & 0 deletions src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Laravel\Telescope\Console;

use Illuminate\Console\Command;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;

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

$this->comment('Publishing Telescope Migrations...');
$this->callSilent('vendor:publish', ['--tag' => 'telescope-migrations']);

$this->registerTelescopeServiceProvider();

$this->info('Telescope scaffolding installed successfully.');
Expand All @@ -49,6 +53,11 @@ public function handle()
*/
protected function registerTelescopeServiceProvider()
{
if (method_exists(ServiceProvider::class, 'addProviderToBootstrapFile') &&
ServiceProvider::addProviderToBootstrapFile(\App\Providers\TelescopeServiceProvider::class)) { // @phpstan-ignore-line
return;
}

$namespace = Str::replaceLast('\\', '', $this->laravel->getNamespace());

$appConfig = file_get_contents(config_path('app.php'));
Expand Down
19 changes: 0 additions & 19 deletions src/Telescope.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,6 @@ class Telescope
*/
public static $shouldRecord = false;

/**
* Indicates if Telescope migrations will be run.
*
* @var bool
*/
public static $runsMigrations = true;

/**
* Register the Telescope watchers and start recording if necessary.
*
Expand Down Expand Up @@ -819,16 +812,4 @@ public static function scriptVariables()
'recording' => ! cache('telescope:pause-recording'),
];
}

/**
* Configure Telescope to not register its migrations.
*
* @return static
*/
public static function ignoreMigrations()
{
static::$runsMigrations = false;

return new static;
}
}
29 changes: 5 additions & 24 deletions src/TelescopeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class TelescopeServiceProvider extends ServiceProvider
*/
public function boot()
{
$this->registerMigrations();
$this->registerCommands();
$this->registerPublishing();

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

/**
* Register the package's migrations.
*
* @return void
*/
protected function registerMigrations()
{
if ($this->app->runningInConsole() && $this->shouldMigrate()) {
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
}
}

/**
* Register the package's publishable resources.
*
Expand All @@ -82,7 +69,11 @@ protected function registerMigrations()
protected function registerPublishing()
{
if ($this->app->runningInConsole()) {
$this->publishes([
$publishesMigrationsMethod = method_exists($this, 'publishesMigrations')
? 'publishesMigrations'
: 'publishes';

$this->{$publishesMigrationsMethod}([
__DIR__.'/../database/migrations' => database_path('migrations'),
], 'telescope-migrations');

Expand Down Expand Up @@ -174,14 +165,4 @@ protected function registerDatabaseDriver()
->needs('$chunkSize')
->give(config('telescope.storage.database.chunk'));
}

/**
* Determine if we should register the migrations.
*
* @return bool
*/
protected function shouldMigrate()
{
return Telescope::$runsMigrations && config('telescope.driver') === 'database';
}
}
4 changes: 3 additions & 1 deletion testbench.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ providers:
- Laravel\Telescope\TelescopeServiceProvider
- Workbench\App\Providers\TelescopeServiceProvider

migrations: true
migrations:
- database/migrations

seeders:
- Workbench\Database\Seeders\DatabaseSeeder

Expand Down
4 changes: 3 additions & 1 deletion tests/FeatureTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
use Laravel\Telescope\Storage\EntryModel;
use Laravel\Telescope\Telescope;
use Laravel\Telescope\TelescopeServiceProvider;
use Orchestra\Testbench\Concerns\WithLaravelMigrations;
use Orchestra\Testbench\Concerns\WithWorkbench;
use Orchestra\Testbench\TestCase;

class FeatureTestCase extends TestCase
{
use RefreshDatabase;
use WithWorkbench, RefreshDatabase, WithLaravelMigrations;

protected function setUp(): void
{
Expand Down
7 changes: 7 additions & 0 deletions tests/Http/AuthorizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Laravel\Telescope\Tests\Http;

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

$this->withoutMiddleware([VerifyCsrfToken::class]);
$this->withoutMiddleware([ValidateCsrfToken::class]);
}

protected function tearDown(): void
Expand Down Expand Up @@ -132,6 +134,11 @@ public function getAuthPassword()
return 'secret';
}

public function getAuthPasswordName()
{
return 'passord name';
}

public function getRememberToken()
{
return 'i-am-telescope';
Expand Down
5 changes: 5 additions & 0 deletions tests/Http/AvatarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ public function getAuthPassword()
return $this->password;
}

public function getAuthPasswordName()
{
return 'passord name';
}

public function getRememberToken()
{
return 'i-am-telescope';
Expand Down
5 changes: 3 additions & 2 deletions tests/Http/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Laravel\Telescope\Tests\Http;

use Illuminate\Foundation\Http\Middleware\ValidateCsrfToken;
use Illuminate\Testing\TestResponse;
use Laravel\Telescope\Database\Factories\EntryModelFactory;
use Laravel\Telescope\EntryType;
Expand All @@ -16,12 +17,12 @@ protected function setUp(): void
{
parent::setUp();

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

$this->registerAssertJsonExactFragmentMacro();
}

public function telescopeIndexRoutesProvider()
public static function telescopeIndexRoutesProvider()
{
return [
'Mail' => ['/telescope/telescope-api/mail', EntryType::MAIL],
Expand Down
20 changes: 11 additions & 9 deletions tests/Watchers/BatchWatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,17 @@ public function test_job_dispatch_registers_entries()

private function createJobsTable(): void
{
Schema::create('jobs', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('queue')->index();
$table->longText('payload');
$table->unsignedTinyInteger('attempts');
$table->unsignedInteger('reserved_at')->nullable();
$table->unsignedInteger('available_at');
$table->unsignedInteger('created_at');
});
if (! Schema::hasTable('jobs')) {
Schema::create('jobs', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('queue')->index();
$table->longText('payload');
$table->unsignedTinyInteger('attempts');
$table->unsignedInteger('reserved_at')->nullable();
$table->unsignedInteger('available_at');
$table->unsignedInteger('created_at');
});
}

Schema::create('job_batches', function ($table) {
$table->string('id')->primary();
Expand Down
2 changes: 1 addition & 1 deletion tests/Watchers/EventWatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function test_format_listeners($listener, $formatted)
$this->assertSame($formatted, $method->invoke(new EventWatcher, DummyEvent::class)[0]['name']);
}

public function formatListenersProvider()
public static function formatListenersProvider()
{
return [
'class string' => [
Expand Down
Loading