getSystemInfo(); $this->assertNotSame([], $info, '시스템 정보 페이로드가 비어 있으면 안 된다.'); $encoded = json_encode($info, JSON_UNESCAPED_UNICODE); $this->assertNotFalse( $encoded, 'getSystemInfo() 페이로드 직렬화 실패: '.json_last_error_msg() .' — invalid UTF-8 필드: '.implode(', ', $this->invalidUtf8Paths($info)) ); } #[Test] public function every_string_in_system_info_is_valid_utf8(): void { $info = app(SettingsService::class)->getSystemInfo(); $this->assertSame( [], $this->invalidUtf8Paths($info), '시스템 정보에 유효하지 않은 UTF-8 문자열이 있으면 관리자 화면이 500 이 된다.' ); } /** * invalid UTF-8 문자열이 있는 키 경로를 점 표기로 수집합니다. * * @param mixed $value 검사할 값 * @param string $prefix 상위 경로 * @return array 점 구분 경로 목록 */ private function invalidUtf8Paths(mixed $value, string $prefix = ''): array { if (is_string($value)) { return mb_check_encoding($value, 'UTF-8') ? [] : [$prefix === '' ? '(root)' : $prefix]; } if (! is_array($value)) { return []; } $paths = []; foreach ($value as $key => $item) { $label = $prefix === '' ? (string) $key : $prefix.'.'.$key; $paths = array_merge($paths, $this->invalidUtf8Paths($item, $label)); } return $paths; } }