ldc-sitemap-generator/tests/Unit/Jobs/GenerateSitemapJobTest.php
Jérémy Munsch 05840b58ff
feat(command): add queue option for sitemap generation
- Introduced a new `--queue` option to the `uwil:sitemap:refresh` command.
- Added `GenerateSitemapJob` for handling sitemap generation in the background.
- Updated service provider to schedule the job with the configured cron expression.
- Enhanced tests to cover new job dispatching functionality.
2026-10-15 16:34:00 +02:00

54 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace Uwil\SitemapGenerator\Tests\Unit\Jobs;
use Illuminate\Support\Facades\Queue;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Storage;
use Uwil\SitemapGenerator\Config\SitemapConfig;
use Uwil\SitemapGenerator\Jobs\GenerateSitemapJob;
covers(GenerateSitemapJob::class);
describe('GenerateSitemapJob', function () {
beforeEach(function () {
/** @var \Uwil\SitemapGenerator\Tests\TestCase $this */
Storage::disk($this->outputDisk)->delete($this->outputPath);
});
afterEach(function () {
/** @var \Uwil\SitemapGenerator\Tests\TestCase $this */
Storage::disk($this->outputDisk)->delete($this->outputPath);
});
it('generates and writes the sitemap to storage when handled', function () {
/** @var \Uwil\SitemapGenerator\Tests\TestCase $this */
// GIVEN
Route::name('contact')->get('/{locale}/contact', fn () => 'contact');
config()->set(SitemapConfig::CONFIG_KEY . '.single_pages', ['contact']);
// WHEN
GenerateSitemapJob::dispatchSync();
// THEN
expect(Storage::disk($this->outputDisk)->exists($this->outputPath))->toBeTrue();
$content = Storage::disk($this->outputDisk)->get($this->outputPath);
expect($content)
->toContain('<urlset')
->toContain('/fr/contact')
->toContain('/en/contact');
});
it('can be dispatched to queue', function () {
// GIVEN
Queue::fake();
// WHEN
GenerateSitemapJob::dispatch();
// THEN
Queue::assertPushed(GenerateSitemapJob::class);
});
});