assertInstanceOf(ShouldQueue::class, $job);
}
/**
* tries=3, timeout=300 속성을 확인합니다.
*/
public function test_job_has_correct_tries_and_timeout(): void
{
$job = new GenerateSitemapJob();
$this->assertSame(3, $job->tries);
$this->assertSame(300, $job->timeout);
}
/**
* handle() 호출 시 Sitemap을 생성하고 캐시에 저장하는지 확인합니다.
*/
public function test_handle_generates_and_caches_sitemap(): void
{
Config::set('g7_settings.core.seo.sitemap_enabled', true);
Config::set('g7_settings.core.seo.sitemap_cache_ttl', 86400);
$xml = '';
$generator = Mockery::mock(SitemapGenerator::class);
$generator->shouldReceive('generate')
->once()
->andReturn($xml);
$cache = Mockery::mock(CacheInterface::class);
$cache->shouldReceive('put')
->once()
->with('seo.sitemap', $xml, 86400);
Log::shouldReceive('info')
->once()
->with('[SEO] Sitemap generated and cached', Mockery::on(function ($context) use ($xml) {
return $context['size'] === strlen($xml) && $context['ttl'] === 86400;
}));
$job = new GenerateSitemapJob();
$job->handle($generator, $cache);
$this->addToAssertionCount(Mockery::getContainer()->mockery_getExpectationCount());
}
/**
* sitemap_enabled=false일 때 생성을 건너뛰는지 확인합니다.
*/
public function test_handle_skips_when_sitemap_disabled(): void
{
Config::set('g7_settings.core.seo.sitemap_enabled', false);
$generator = Mockery::mock(SitemapGenerator::class);
$generator->shouldNotReceive('generate');
$cache = Mockery::mock(CacheInterface::class);
Log::shouldReceive('info')
->once()
->with('[SEO] Sitemap generation skipped (disabled)');
$job = new GenerateSitemapJob();
$job->handle($generator, $cache);
$this->addToAssertionCount(Mockery::getContainer()->mockery_getExpectationCount());
}
/**
* 설정된 커스텀 TTL이 cache->put에 전달되는지 확인합니다.
*/
public function test_handle_uses_configured_cache_ttl(): void
{
Config::set('g7_settings.core.seo.sitemap_enabled', true);
Config::set('g7_settings.core.cache.seo_sitemap_ttl', 3600);
Config::set('g7_settings.core.seo.sitemap_cache_ttl', 3600);
$xml = '';
$generator = Mockery::mock(SitemapGenerator::class);
$generator->shouldReceive('generate')
->once()
->andReturn($xml);
$cache = Mockery::mock(CacheInterface::class);
$cache->shouldReceive('put')
->once()
->with('seo.sitemap', $xml, 3600);
Log::shouldReceive('info')
->once()
->with('[SEO] Sitemap generated and cached', Mockery::on(function ($context) {
return $context['ttl'] === 3600;
}));
$job = new GenerateSitemapJob();
$job->handle($generator, $cache);
$this->addToAssertionCount(Mockery::getContainer()->mockery_getExpectationCount());
}
/**
* failed() 호출 시 에러 로그를 기록하는지 확인합니다.
*/
public function test_failed_logs_error(): void
{
$exception = new \RuntimeException('Sitemap generation timeout');
Log::shouldReceive('error')
->once()
->with('[SEO] Sitemap generation failed', Mockery::on(function ($context) {
return $context['error'] === 'Sitemap generation timeout';
}));
$job = new GenerateSitemapJob();
$job->failed($exception);
$this->addToAssertionCount(Mockery::getContainer()->mockery_getExpectationCount());
}
}