147 lines
4.5 KiB
PHP
147 lines
4.5 KiB
PHP
<?php
|
|
/**
|
|
* Smoke test: EmployeeServiceController::getEmployeeClaimStatusForDeletion
|
|
* Run: php tests/smoke_employee_claim_status_for_deletion.php [emp_id] [client_policy_id]
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
ob_start();
|
|
|
|
define('FCPATH', __DIR__ . '/../public/');
|
|
chdir(FCPATH);
|
|
|
|
require FCPATH . '../app/Config/Paths.php';
|
|
$paths = new Config\Paths();
|
|
require rtrim($paths->systemDirectory, '\\/ ') . DIRECTORY_SEPARATOR . 'bootstrap.php';
|
|
require_once SYSTEMPATH . 'Config/DotEnv.php';
|
|
(new CodeIgniter\Config\DotEnv(ROOTPATH))->load();
|
|
|
|
defined('ENVIRONMENT') || define('ENVIRONMENT', env('CI_ENVIRONMENT', 'development'));
|
|
|
|
$boot = APPPATH . 'Config/Boot/' . ENVIRONMENT . '.php';
|
|
if (is_file($boot)) {
|
|
require_once $boot;
|
|
}
|
|
|
|
use App\Controllers\EmployeeServiceController;
|
|
|
|
$pass = 0;
|
|
$fail = 0;
|
|
$results = [];
|
|
|
|
function ok(string $label, bool $cond, string $detail = ''): void
|
|
{
|
|
global $pass, $fail, $results;
|
|
if ($cond) {
|
|
$pass++;
|
|
$results[] = '[PASS] ' . $label . ($detail ? " — {$detail}" : '');
|
|
} else {
|
|
$fail++;
|
|
$results[] = '[FAIL] ' . $label . ($detail ? " — {$detail}" : '');
|
|
}
|
|
}
|
|
|
|
function invokeClaimStatus(EmployeeServiceController $controller, int $empId, int $clientPolicyId): int
|
|
{
|
|
$method = new ReflectionMethod($controller, 'getEmployeeClaimStatusForDeletion');
|
|
$method->setAccessible(true);
|
|
|
|
return (int) $method->invoke($controller, $empId, $clientPolicyId);
|
|
}
|
|
|
|
$db = db_connect('default');
|
|
$controller = new EmployeeServiceController();
|
|
|
|
$withClaim = $db->query(
|
|
'SELECT emp_id, client_policy_id
|
|
FROM ticket_master
|
|
WHERE is_active = 1 AND emp_id > 0 AND client_policy_id > 0
|
|
LIMIT 1'
|
|
)->getRowArray();
|
|
|
|
$withoutClaim = $db->query(
|
|
'SELECT e.id AS emp_id, ep.client_policy_id
|
|
FROM employees e
|
|
JOIN employee_polices ep ON ep.employee_id = e.id
|
|
WHERE e.is_active = 1
|
|
AND ep.is_active = 1
|
|
AND e.id > 0
|
|
AND ep.client_policy_id > 0
|
|
AND NOT EXISTS (
|
|
SELECT 1
|
|
FROM ticket_master tm
|
|
WHERE tm.emp_id = e.id
|
|
AND tm.client_policy_id = ep.client_policy_id
|
|
AND tm.is_active = 1
|
|
)
|
|
LIMIT 1'
|
|
)->getRowArray();
|
|
|
|
$wrongPolicy = $db->query(
|
|
'SELECT id FROM client_policy WHERE id > 0 ORDER BY id DESC LIMIT 1'
|
|
)->getRowArray();
|
|
|
|
ok('fixture with claim found', is_array($withClaim) && ! empty($withClaim));
|
|
ok('fixture without claim found', is_array($withoutClaim) && ! empty($withoutClaim));
|
|
|
|
if ($withClaim) {
|
|
$empId = (int) $withClaim['emp_id'];
|
|
$policyId = (int) $withClaim['client_policy_id'];
|
|
$result = invokeClaimStatus($controller, $empId, $policyId);
|
|
|
|
ok(
|
|
'returns 1 when active claim exists for emp_id + client_policy_id',
|
|
$result === 1,
|
|
"emp_id={$empId}, client_policy_id={$policyId}, got={$result}"
|
|
);
|
|
|
|
if (isset($argv[1], $argv[2])) {
|
|
$manualEmp = (int) $argv[1];
|
|
$manualPolicy = (int) $argv[2];
|
|
$manualResult = invokeClaimStatus($controller, $manualEmp, $manualPolicy);
|
|
$expected = $db->table('ticket_master')
|
|
->where('emp_id', $manualEmp)
|
|
->where('client_policy_id', $manualPolicy)
|
|
->where('is_active', 1)
|
|
->countAllResults() > 0 ? 1 : 0;
|
|
|
|
ok(
|
|
'manual args match ticket_master lookup',
|
|
$manualResult === $expected,
|
|
"emp_id={$manualEmp}, client_policy_id={$manualPolicy}, got={$manualResult}, expected={$expected}"
|
|
);
|
|
}
|
|
}
|
|
|
|
if ($withClaim && $wrongPolicy) {
|
|
$empId = (int) $withClaim['emp_id'];
|
|
$wrongPolicyId = (int) $wrongPolicy['id'];
|
|
|
|
if ($wrongPolicyId !== (int) $withClaim['client_policy_id']) {
|
|
$result = invokeClaimStatus($controller, $empId, $wrongPolicyId);
|
|
ok(
|
|
'returns 0 when emp has claim on a different client_policy_id',
|
|
$result === 0,
|
|
"emp_id={$empId}, client_policy_id={$wrongPolicyId}, got={$result}"
|
|
);
|
|
}
|
|
}
|
|
|
|
if ($withoutClaim) {
|
|
$empId = (int) $withoutClaim['emp_id'];
|
|
$policyId = (int) $withoutClaim['client_policy_id'];
|
|
$result = invokeClaimStatus($controller, $empId, $policyId);
|
|
|
|
ok(
|
|
'returns 0 when no active claim exists for emp_id + client_policy_id',
|
|
$result === 0,
|
|
"emp_id={$empId}, client_policy_id={$policyId}, got={$result}"
|
|
);
|
|
}
|
|
|
|
echo PHP_EOL . implode(PHP_EOL, $results) . PHP_EOL;
|
|
echo PHP_EOL . "Summary: {$pass} passed, {$fail} failed" . PHP_EOL;
|
|
|
|
exit($fail > 0 ? 1 : 0);
|