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:
@@ -54,4 +54,46 @@ class ServiceCoverageNPlusOneTest extends ApiTestCase
|
||||
sort($returnedUuids);
|
||||
$this->assertSame($expectedUuids, $returnedUuids);
|
||||
}
|
||||
|
||||
/** @return array{0: \App\Auth\Entity\User, 1: TenantInsurance} */
|
||||
private function makeContract(int $coverageRows): array
|
||||
{
|
||||
$owner = $this->createUser(['ROLE_DOCTOR']);
|
||||
$doctor = new Doctor($owner, 'دکتر تست');
|
||||
$this->em->persist($doctor);
|
||||
$this->em->flush();
|
||||
|
||||
$tenant = new TenantInsurance(TenantInsurance::TYPE_DOCTOR, $doctor->getId(), 1);
|
||||
$section = new ServiceSection(TenantInsurance::TYPE_DOCTOR, $doctor->getId(), 'بخش');
|
||||
$this->em->persist($tenant);
|
||||
$this->em->persist($section);
|
||||
$this->em->flush();
|
||||
|
||||
for ($i = 0; $i < $coverageRows; $i++) {
|
||||
$item = new ServiceItem($section, "خدمت $i");
|
||||
$this->em->persist($item);
|
||||
$this->em->flush();
|
||||
$this->em->persist(new TenantServiceCoverage($tenant->getId(), $item->getId()));
|
||||
}
|
||||
$this->em->flush();
|
||||
|
||||
return [$owner, $tenant];
|
||||
}
|
||||
|
||||
public function testQueryCountDoesNotGrowWithCoverageRows(): void
|
||||
{
|
||||
$this->client->disableReboot();
|
||||
|
||||
[$ownerS, $small] = $this->makeContract(1);
|
||||
[$ownerL, $large] = $this->makeContract(6);
|
||||
$this->em->clear();
|
||||
|
||||
$url = fn (TenantInsurance $t) => '/api/v1/billing/tenant-insurances/' . $t->getUuid() . '/service-coverage';
|
||||
|
||||
$qSmall = $this->countQueries(fn () => $this->authJson('GET', $url($small), $ownerS));
|
||||
$qLarge = $this->countQueries(fn () => $this->authJson('GET', $url($large), $ownerL));
|
||||
|
||||
// batch fetch → constant query count; per-row find() would add ~1/row.
|
||||
$this->assertLessThanOrEqual($qSmall + 1, $qLarge, "N+1: query count grew from $qSmall to $qLarge");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user