false]); $this->mockConfigRepositoryDebugMode(true); $response = $this->postJson('/_boost/g7-debug/dump-state', ['test' => true]); $response->assertStatus(200); $response->assertJson(['status' => 'success']); } /** * 양쪽 모두 꺼져 있으면 403 이어야 한다 (500 이 아니라). */ public function test_dump_state_returns_403_when_debug_disabled(): void { config(['app.debug' => false]); $this->mockConfigRepositoryDebugMode(false); $response = $this->postJson('/_boost/g7-debug/dump-state', ['test' => true]); $response->assertStatus(403); $response->assertJson(['status' => 'error']); // 번역 키가 해석되지 않으면 Laravel 은 키 문자열을 그대로 돌려준다 — 오류 없이 // 사용자에게 `devtools.debug_disabled` 가 노출되므로 해석 여부를 단언한다. $this->assertNotSame( 'devtools.debug_disabled', $response->json('message'), '번역 키가 해석되지 않았습니다 (lang/{ko,en}/devtools.php 누락).' ); } /** * `browser-logs` 도 동일 게이트를 사용한다. */ public function test_browser_logs_returns_403_when_debug_disabled(): void { config(['app.debug' => false]); $this->mockConfigRepositoryDebugMode(false); $response = $this->postJson('/_boost/browser-logs', ['logs' => []]); $response->assertStatus(403); } /** * `.env` 의 `APP_DEBUG=true` 만으로도 통과한다 (환경설정 조회 불필요). */ public function test_gate_passes_on_app_debug_without_settings_lookup(): void { config(['app.debug' => true]); $repository = Mockery::mock(ConfigRepositoryInterface::class); $repository->shouldNotReceive('get'); $this->app->instance(ConfigRepositoryInterface::class, $repository); $this->assertTrue(DebugGate::isEnabled()); } /** * `ConfigRepositoryInterface` 를 `debug.mode` 고정값으로 대체한다. * * @param bool $enabled debug.mode 값 * @return void */ private function mockConfigRepositoryDebugMode(bool $enabled): void { $repository = Mockery::mock(ConfigRepositoryInterface::class); $repository->shouldReceive('get') ->with('debug.mode', false) ->andReturn($enabled); $repository->shouldReceive('get')->andReturnUsing( static fn (string $key, mixed $default = null): mixed => $default ); $this->app->instance(ConfigRepositoryInterface::class, $repository); } }