Skip to content

Commit

Permalink
Fixes test suite on Laravel versions prior to Laravel 11
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro committed Dec 12, 2023
1 parent 5cb26f4 commit a16c500
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 27 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"require-dev": {
"ext-gd": "*",
"guzzlehttp/guzzle": "^6.0|^7.0",
"laravel/octane": "^1.4",
"orchestra/testbench": "^6.0|^7.0|^8.0|9.0",
"laravel/octane": "^1.4|^2.0|dev-develop",
"orchestra/testbench": "^6.0|^7.0|^8.0|^9.0",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9.0|^10.4"
},
Expand Down
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
5 changes: 5 additions & 0 deletions tests/Http/AuthorizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,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
2 changes: 1 addition & 1 deletion tests/Http/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected function setUp(): void
$this->registerAssertJsonExactFragmentMacro();
}

public function telescopeIndexRoutesProvider()
public static function telescopeIndexRoutesProvider()
{
return [
'Mail' => ['/telescope/telescope-api/mail', EntryType::MAIL],
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
41 changes: 31 additions & 10 deletions tests/Watchers/GateWatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ protected function getEnvironmentSetUp($app)
GateWatcher::class => true,
]);

$app->setBasePath(dirname(__FILE__, 3));

Gate::define('potato', function (User $user) {
return $user->email === 'allow';
});
Expand All @@ -37,6 +35,8 @@ protected function getEnvironmentSetUp($app)

public function test_gate_watcher_registers_allowed_entries()
{
$this->app->setBasePath(dirname(__FILE__, 3));

$check = Gate::forUser(new User('allow'))->check('potato');

$entry = $this->loadTelescopeEntries()->first();
Expand All @@ -52,51 +52,59 @@ public function test_gate_watcher_registers_allowed_entries()

public function test_gate_watcher_registers_denied_entries()
{
$this->app->setBasePath(dirname(__FILE__, 3));

$check = Gate::forUser(new User('deny'))->check('potato', ['banana']);

$entry = $this->loadTelescopeEntries()->first();

$this->assertFalse($check);
$this->assertSame(EntryType::GATE, $entry->type);
$this->assertSame(__FILE__, $entry->content['file']);
$this->assertSame(55, $entry->content['line']);
$this->assertSame(57, $entry->content['line']);
$this->assertSame('potato', $entry->content['ability']);
$this->assertSame('denied', $entry->content['result']);
$this->assertSame(['banana'], $entry->content['arguments']);
}

public function test_gate_watcher_registers_allowed_guest_entries()
{
$this->app->setBasePath(dirname(__FILE__, 3));

$check = Gate::check('guest potato');

$entry = $this->loadTelescopeEntries()->first();

$this->assertTrue($check);
$this->assertSame(EntryType::GATE, $entry->type);
$this->assertSame(__FILE__, $entry->content['file']);
$this->assertSame(70, $entry->content['line']);
$this->assertSame(74, $entry->content['line']);
$this->assertSame('guest potato', $entry->content['ability']);
$this->assertSame('allowed', $entry->content['result']);
$this->assertEmpty($entry->content['arguments']);
}

public function test_gate_watcher_registers_denied_guest_entries()
{
$this->app->setBasePath(dirname(__FILE__, 3));

$check = Gate::check('deny potato', ['gelato']);

$entry = $this->loadTelescopeEntries()->first();

$this->assertFalse($check);
$this->assertSame(EntryType::GATE, $entry->type);
$this->assertSame(__FILE__, $entry->content['file']);
$this->assertSame(85, $entry->content['line']);
$this->assertSame(91, $entry->content['line']);
$this->assertSame('deny potato', $entry->content['ability']);
$this->assertSame('denied', $entry->content['result']);
$this->assertSame(['gelato'], $entry->content['arguments']);
}

public function test_gate_watcher_registers_allowed_policy_entries()
{
$this->app->setBasePath(dirname(__FILE__, 3));

Gate::policy(TestResource::class, TestPolicy::class);

(new TestController())->create(new TestResource());
Expand All @@ -105,14 +113,16 @@ public function test_gate_watcher_registers_allowed_policy_entries()

$this->assertSame(EntryType::GATE, $entry->type);
$this->assertSame(__FILE__, $entry->content['file']);
$this->assertSame(250, $entry->content['line']);
$this->assertSame(271, $entry->content['line']);
$this->assertSame('create', $entry->content['ability']);
$this->assertSame('allowed', $entry->content['result']);
$this->assertSame([[]], $entry->content['arguments']);
}

public function test_gate_watcher_registers_after_checks()
{
$this->app->setBasePath(dirname(__FILE__, 3));

Gate::after(function (?User $user) {
return true;
});
Expand All @@ -124,14 +134,16 @@ public function test_gate_watcher_registers_after_checks()
$this->assertTrue($check);
$this->assertSame(EntryType::GATE, $entry->type);
$this->assertSame(__FILE__, $entry->content['file']);
$this->assertSame(120, $entry->content['line']);
$this->assertSame(130, $entry->content['line']);
$this->assertSame('foo-bar', $entry->content['ability']);
$this->assertSame('allowed', $entry->content['result']);
$this->assertEmpty($entry->content['arguments']);
}

public function test_gate_watcher_registers_denied_policy_entries()
{
$this->app->setBasePath(dirname(__FILE__, 3));

Gate::policy(TestResource::class, TestPolicy::class);

try {
Expand All @@ -144,14 +156,16 @@ public function test_gate_watcher_registers_denied_policy_entries()

$this->assertSame(EntryType::GATE, $entry->type);
$this->assertSame(__FILE__, $entry->content['file']);
$this->assertSame(255, $entry->content['line']);
$this->assertSame(276, $entry->content['line']);
$this->assertSame('update', $entry->content['ability']);
$this->assertSame('denied', $entry->content['result']);
$this->assertSame([[]], $entry->content['arguments']);
}

public function test_gate_watcher_registers_allowed_response_policy_entries()
{
$this->app->setBasePath(dirname(__FILE__, 3));

Gate::policy(TestResource::class, TestPolicy::class);

try {
Expand All @@ -164,14 +178,16 @@ public function test_gate_watcher_registers_allowed_response_policy_entries()

$this->assertSame(EntryType::GATE, $entry->type);
$this->assertSame(__FILE__, $entry->content['file']);
$this->assertSame(245, $entry->content['line']);
$this->assertSame(266, $entry->content['line']);
$this->assertSame('view', $entry->content['ability']);
$this->assertSame('allowed', $entry->content['result']);
$this->assertSame([[]], $entry->content['arguments']);
}

public function test_gate_watcher_registers_denied_response_policy_entries()
{
$this->app->setBasePath(dirname(__FILE__, 3));

Gate::policy(TestResource::class, TestPolicy::class);

try {
Expand All @@ -184,7 +200,7 @@ public function test_gate_watcher_registers_denied_response_policy_entries()

$this->assertSame(EntryType::GATE, $entry->type);
$this->assertSame(__FILE__, $entry->content['file']);
$this->assertSame(260, $entry->content['line']);
$this->assertSame(281, $entry->content['line']);
$this->assertSame('delete', $entry->content['ability']);
$this->assertSame('denied', $entry->content['result']);
$this->assertSame([[]], $entry->content['arguments']);
Expand Down Expand Up @@ -215,6 +231,11 @@ public function getAuthPassword()
return 'secret';
}

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

public function getRememberToken()
{
return 'i-am-telescope';
Expand Down
20 changes: 11 additions & 9 deletions tests/Watchers/JobWatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,17 @@ private function createJobsTable(): void
$table->unsignedInteger('created_at');
});

Schema::create('failed_jobs', function (Blueprint $table) {
$table->uuid('uuid');
$table->bigIncrements('id');
$table->text('connection');
$table->text('queue');
$table->longText('payload');
$table->longText('exception');
$table->timestamp('failed_at')->useCurrent();
});
if (! Schema::hasTable('failed_jobs')) {
Schema::create('failed_jobs', function (Blueprint $table) {
$table->uuid('uuid');
$table->bigIncrements('id');
$table->text('connection');
$table->text('queue');
$table->longText('payload');
$table->longText('exception');
$table->timestamp('failed_at')->useCurrent();
});
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Watchers/LogWatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected function getEnvironmentSetUp($app)

$app->get('config')->set('logging.default', 'syslog');

$config = match ($this->getName(false)) {
$config = match (method_exists($this, 'name') ? $this->name() : $this->getName(false)) {
'test_log_watcher_registers_entry_for_any_level_by_default' => true,
'test_log_watcher_only_registers_entries_for_the_specified_error_level_priority' => [
'enabled' => true,
Expand All @@ -38,7 +38,7 @@ protected function getEnvironmentSetUp($app)
]);
}

public function logLevelProvider()
public static function logLevelProvider()
{
return [
[LogLevel::EMERGENCY],
Expand Down

0 comments on commit a16c500

Please sign in to comment.