Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 6m55s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 7m6s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 6m26s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 6m13s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 9m12s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 8m41s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m19s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 6m29s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m33s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
72 lines
2.3 KiB
PHP
72 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Http\Middleware\RunPseudoCron;
|
|
use App\Support\BackgroundTasks;
|
|
use Illuminate\Console\Scheduling\CallbackEvent;
|
|
use Illuminate\Console\Scheduling\Schedule;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Http\Request;
|
|
use Tests\TestCase;
|
|
|
|
class BackgroundTasksTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
@unlink(storage_path('.background-heartbeat'));
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
@unlink(storage_path('.background-heartbeat'));
|
|
|
|
parent::tearDown();
|
|
}
|
|
|
|
public function test_web_cron_requires_the_secret_token(): void
|
|
{
|
|
$token = app(BackgroundTasks::class)->webCronToken();
|
|
|
|
$this->assertSame(40, strlen($token));
|
|
$this->get('/cron/falsch')->assertNotFound();
|
|
$this->get("/cron/{$token}")->assertNoContent();
|
|
|
|
$this->assertArrayHasKey('webcron', app(BackgroundTasks::class)->heartbeats());
|
|
}
|
|
|
|
public function test_pseudo_cron_only_steps_in_without_external_cron(): void
|
|
{
|
|
$tasks = app(BackgroundTasks::class);
|
|
|
|
$this->assertTrue($tasks->pseudoCronDue());
|
|
|
|
$tasks->heartbeat('cron');
|
|
$this->assertFalse($tasks->pseudoCronDue());
|
|
|
|
$this->travel(BackgroundTasks::PSEUDO_CRON_AFTER_SECONDS + 5)->seconds();
|
|
$this->assertTrue($tasks->pseudoCronDue());
|
|
|
|
$tasks->heartbeat('pseudo');
|
|
$this->assertFalse($tasks->pseudoCronDue(), 'Höchstens einmal pro Minute.');
|
|
}
|
|
|
|
public function test_pseudo_cron_never_runs_during_saving_or_background_requests(): void
|
|
{
|
|
$this->assertTrue(RunPseudoCron::suitable(Request::create('/')));
|
|
$this->assertFalse(RunPseudoCron::suitable(Request::create('/livewire/update', 'POST')));
|
|
$this->assertFalse(RunPseudoCron::suitable(Request::create('/admin/menue', 'GET', server: ['HTTP_X_LIVEWIRE' => '1'])));
|
|
$this->assertFalse(RunPseudoCron::suitable(Request::create('/neuigkeiten', 'GET', server: ['HTTP_X_INERTIA' => 'true'])));
|
|
}
|
|
|
|
public function test_queue_is_worked_in_process_not_via_an_external_php_binary(): void
|
|
{
|
|
$event = collect(app(Schedule::class)->events())->first(fn ($e) => $e->description === 'queue');
|
|
|
|
$this->assertInstanceOf(CallbackEvent::class, $event);
|
|
}
|
|
}
|