From 31538a0cb4a669ef748f6411bf1bbffa3e49f026 Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Thu, 8 Oct 2026 20:55:10 +0530 Subject: [PATCH] test: add spark test command for ABDM PDF generation --- app/Commands/TestAbdmPdf.php | 66 ++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 app/Commands/TestAbdmPdf.php diff --git a/app/Commands/TestAbdmPdf.php b/app/Commands/TestAbdmPdf.php new file mode 100644 index 0000000..452a7d0 --- /dev/null +++ b/app/Commands/TestAbdmPdf.php @@ -0,0 +1,66 @@ + 'Patient ID to test (default 15350)', + 'consent_request_id' => 'Optional consent request ID filter', + ]; + + public function run(array $params) + { + $patientId = (int) ($params[0] ?? 15350); + $consentReqId = (string) ($params[1] ?? ''); + + CLI::write("Testing ABDM PDF generation for patient: {$patientId}", 'yellow'); + + $_SERVER['REQUEST_METHOD'] = 'GET'; + $get = []; + if ($consentReqId !== '') { + $get['consent_request_id'] = $consentReqId; + } + $_GET = $get; + + $request = \Config\Services::request(null, false); + $request->setGlobal('get', $get); + \Config\Services::injectMock('request', $request); + + $controller = new \App\Controllers\Patient(); + $response = \Config\Services::response(); + $logger = service('logger'); + $controller->initController($request, $response, $logger); + + $startTime = microtime(true); + $res = $controller->abdm_records_pdf($patientId); + $duration = round((microtime(true) - $startTime) * 1000, 2); + + $status = $res->getStatusCode(); + $contentType = $res->getHeaderLine('Content-Type'); + $disposition = $res->getHeaderLine('Content-Disposition'); + $body = $res->getBody(); + $len = strlen($body); + + CLI::write("Status: {$status}", $status === 200 ? 'green' : 'red'); + CLI::write("Content-Type: {$contentType}"); + CLI::write("Disposition: {$disposition}"); + CLI::write("PDF Size: {$len} bytes (generated in {$duration} ms)"); + + if (str_starts_with($body, '%PDF-')) { + CLI::write("VALID PDF HEADER: " . substr($body, 0, 8), 'green'); + $outPath = WRITEPATH . 'cache/test_abdm_records.pdf'; + file_put_contents($outPath, $body); + CLI::write("Saved test PDF to: {$outPath}", 'green'); + } else { + CLI::write("ERROR: Output is not a valid PDF: " . substr($body, 0, 200), 'red'); + } + } +}