test: remove the two real sources of full-run flakiness, and the mock notices

createUser() drew a random mobile and recovered from a collision by catching
the unique-constraint violation and calling resetManager(). That hands back a
brand-new EntityManager, which detaches every entity the running test had
built so far; its next flush died with "Multiple non-persisted new entities
were found", always in a different test and never reproducible in isolation.
The number is now checked before the insert, so the collision never reaches
the database and the manager stays open.

testParentIdAddsNoQueryPerSpecialty counted queries on the first request of
each size, so one-shot per-process caches — site config, subscription plan,
Doctrine metadata — landed inside the count or not depending on which tests
had run before it. Both requests are now warmed first; the assertion measures
steady-state growth, which is what it was always about.

The 23 PHPUnit notices were all one complaint: doubles created with
createMock() that never had an expectation. The ones that only stub return
values became createStub(); in SmsServiceLookupOnlyTest the provider and the
bus got the expectations they were missing, since "dispatch does not touch
the provider" and "sendNow does not enqueue" are exactly what that suite is
there to prove.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
hamed
2026-08-18 09:57:29 +03:30
co-authored by Claude Opus 5
parent ed2d2ec74a
commit 8a43297e24
8 changed files with 59 additions and 48 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ class DoctorClaimTest extends ApiTestCase
private function mockApiIr(bool $shahkar = true, ?array $person = ['firstName' => 'تست', 'lastName' => 'ایمپورت', 'alive' => true]): void
{
$mock = $this->createMock(ApiIrService::class);
$mock = $this->createStub(ApiIrService::class);
$mock->method('isConfigured')->willReturn(true);
$mock->method('shahkarMatch')->willReturn($shahkar);
$mock->method('personInfo')->willReturn($person);
@@ -222,6 +222,13 @@ class DoctorSpecialtySearchTest extends ApiTestCase
$this->newDoctor('دکتر شمارش ' . uniqid(), [$t['root'], $t['childA'], $t['childB']]);
}
// اجرای گرم‌کننده پیش از شمارش: کوئری‌های یک‌بارهٔ هر پردازه — پیکربندی سایت،
// پلن اشتراک، متادیتای Doctrine — بسته به اینکه کدام تست‌ها زودتر اجرا شده‌اند
// پر یا خالی‌اند. بدون این گرم‌کردن، همان کوئری‌ها در اجرای کامل suite داخل
// شمارش می‌افتادند و تست به‌صورت تصادفی می‌شکست. اینجا رشدِ حالت پایدار مهم است.
$this->get('specialty_id=' . $t['root']->getId() . '&limit=2');
$this->get('specialty_id=' . $t['root']->getId() . '&limit=6');
$qSmall = $this->countQueries(fn() => $this->get('specialty_id=' . $t['root']->getId() . '&limit=2'));
$qLarge = $this->countQueries(fn() => $this->get('specialty_id=' . $t['root']->getId() . '&limit=6'));