test(audit): strengthen H5/H7/H8 into true fail-without-fix regressions

Verification pass found three tests only guarded correctness, not the fix's
behavior:
- H7: add repository white-box test asserting likes/replies come back as
  initialised PersistentCollections (lazy without the fetch-join).
- H8: add a query-count test (constant vs coverage-row count) — without the
  batch fetch the count grows ~1 per row.
- H5: add an end-to-end test hitting DELETE /api/v1/doctor and asserting the
  insurance config is purged (the service unit test didn't cover the wiring).

All three now fail when their fix is reverted. Suite: 39 tests / 92 assertions.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
hamed
2026-06-28 20:01:12 +03:30
co-authored by Claude Opus 4.8
parent c9ae3882fe
commit 131a78343b
4 changed files with 105 additions and 0 deletions
@@ -2,6 +2,7 @@
namespace App\Tests\Insurance;
use App\Doctor\Entity\Doctor;
use App\Insurance\Entity\EntityInsurancePricing;
use App\Insurance\Entity\TenantInsurance;
use App\Insurance\Entity\TenantServiceCoverage;
@@ -40,4 +41,31 @@ class TenantInsuranceCleanupTest extends ApiTestCase
$this->assertNull($this->em->getRepository(TenantServiceCoverage::class)
->findOneBy(['tenantInsuranceId' => $tenant->getId()]));
}
/**
* End-to-end: the DELETE doctor endpoint must trigger the purge. Without the
* wiring the doctor is removed but its insurance rows are left orphaned.
*/
public function testDeleteDoctorEndpointPurgesInsuranceConfig(): void
{
$doctor = new Doctor($this->createUser(['ROLE_DOCTOR']), 'دکتر حذف');
$this->em->persist($doctor);
$this->em->flush();
$doctorId = $doctor->getId();
$tenant = new TenantInsurance(TenantInsurance::TYPE_DOCTOR, $doctorId, 1);
$this->em->persist($tenant);
$this->em->persist(new EntityInsurancePricing(TenantInsurance::TYPE_DOCTOR, $doctorId, 1));
$this->em->flush();
$admin = $this->createUser(['ROLE_ADMIN']);
$this->authJson('DELETE', '/api/v1/doctor/' . $doctor->getUuid(), $admin);
$this->assertSame(200, $this->responseCode());
$this->em->clear();
$this->assertCount(0, $this->em->getRepository(TenantInsurance::class)
->findBy(['entityType' => TenantInsurance::TYPE_DOCTOR, 'entityId' => $doctorId]));
$this->assertCount(0, $this->em->getRepository(EntityInsurancePricing::class)
->findBy(['entityType' => TenantInsurance::TYPE_DOCTOR, 'entityId' => $doctorId]));
}
}