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:
@@ -25,16 +25,16 @@ class ActivateTrialTest extends TestCase
|
||||
?SubscriptionPlan $basicPlan,
|
||||
mixed $trialPeriod,
|
||||
): SubscriptionService {
|
||||
$subscriptionRepo = $this->createMock(ClinicSubscriptionRepository::class);
|
||||
$subscriptionRepo = $this->createStub(ClinicSubscriptionRepository::class);
|
||||
$subscriptionRepo->method('hasUsedTrial')->willReturn($usedTrial);
|
||||
|
||||
$planRepo = $this->createMock(SubscriptionPlanRepository::class);
|
||||
$planRepo = $this->createStub(SubscriptionPlanRepository::class);
|
||||
$planRepo->method('findByName')->willReturn($basicPlan);
|
||||
|
||||
$periodRepo = $this->createMock(SubscriptionPeriodRepository::class);
|
||||
$periodRepo = $this->createStub(SubscriptionPeriodRepository::class);
|
||||
$periodRepo->method('findTrialPeriodForPlan')->willReturn($trialPeriod);
|
||||
|
||||
$configRepo = $this->createMock(SiteConfigRepository::class);
|
||||
$configRepo = $this->createStub(SiteConfigRepository::class);
|
||||
$configRepo->method('get')->willReturn($trialEnabled);
|
||||
|
||||
return new SubscriptionService($subscriptionRepo, $planRepo, $periodRepo, $configRepo);
|
||||
@@ -45,7 +45,7 @@ class ActivateTrialTest extends TestCase
|
||||
$service = $this->service(
|
||||
usedTrial: false,
|
||||
trialEnabled: '1',
|
||||
basicPlan: $this->createMock(SubscriptionPlan::class),
|
||||
basicPlan: $this->createStub(SubscriptionPlan::class),
|
||||
trialPeriod: null,
|
||||
);
|
||||
|
||||
|
||||
@@ -26,27 +26,27 @@ class GrantSubscriptionTest extends TestCase
|
||||
|
||||
private function service(?SubscriptionPeriod $period, ?ClinicSubscription $active): SubscriptionService
|
||||
{
|
||||
$subscriptionRepo = $this->createMock(ClinicSubscriptionRepository::class);
|
||||
$subscriptionRepo = $this->createStub(ClinicSubscriptionRepository::class);
|
||||
$subscriptionRepo->method('findActive')->willReturn($active);
|
||||
$subscriptionRepo->method('save')->willReturnCallback(function (ClinicSubscription $s): void {
|
||||
$this->saved = $s;
|
||||
});
|
||||
|
||||
$periodRepo = $this->createMock(SubscriptionPeriodRepository::class);
|
||||
$periodRepo = $this->createStub(SubscriptionPeriodRepository::class);
|
||||
$periodRepo->method('findByUuid')->willReturn($period);
|
||||
|
||||
return new SubscriptionService(
|
||||
$subscriptionRepo,
|
||||
$this->createMock(SubscriptionPlanRepository::class),
|
||||
$this->createStub(SubscriptionPlanRepository::class),
|
||||
$periodRepo,
|
||||
$this->createMock(SiteConfigRepository::class),
|
||||
$this->createStub(SiteConfigRepository::class),
|
||||
);
|
||||
}
|
||||
|
||||
private function period(int $durationMonths): SubscriptionPeriod
|
||||
{
|
||||
$period = $this->createMock(SubscriptionPeriod::class);
|
||||
$period->method('getPlan')->willReturn($this->createMock(SubscriptionPlan::class));
|
||||
$period = $this->createStub(SubscriptionPeriod::class);
|
||||
$period->method('getPlan')->willReturn($this->createStub(SubscriptionPlan::class));
|
||||
$period->method('getDurationMonths')->willReturn($durationMonths);
|
||||
|
||||
return $period;
|
||||
@@ -54,7 +54,7 @@ class GrantSubscriptionTest extends TestCase
|
||||
|
||||
public function testGrantCreatesSubscriptionWithoutPaymentAndRecordsTheAdmin(): void
|
||||
{
|
||||
$admin = $this->createMock(User::class);
|
||||
$admin = $this->createStub(User::class);
|
||||
$service = $this->service($this->period(1), null);
|
||||
|
||||
$subscription = $service->grant('doctor', 7, 'period-uuid', $admin);
|
||||
@@ -73,7 +73,7 @@ class GrantSubscriptionTest extends TestCase
|
||||
{
|
||||
$service = $this->service($this->period(1), null);
|
||||
|
||||
$subscription = $service->grant('clinic', 3, 'period-uuid', $this->createMock(User::class));
|
||||
$subscription = $service->grant('clinic', 3, 'period-uuid', $this->createStub(User::class));
|
||||
|
||||
$this->assertFalse($subscription->isTrial());
|
||||
$this->assertTrue($subscription->toArray()['is_granted']);
|
||||
@@ -84,7 +84,7 @@ class GrantSubscriptionTest extends TestCase
|
||||
$service = $this->service(null, null);
|
||||
|
||||
try {
|
||||
$service->grant('doctor', 1, 'missing-uuid', $this->createMock(User::class));
|
||||
$service->grant('doctor', 1, 'missing-uuid', $this->createStub(User::class));
|
||||
$this->fail('expected AppException');
|
||||
} catch (AppException $e) {
|
||||
$this->assertSame(ErrorCodes::ERR_NOT_FOUND_001, $e->getErrorCode());
|
||||
@@ -97,12 +97,12 @@ class GrantSubscriptionTest extends TestCase
|
||||
{
|
||||
$currentExpiry = time() + 20 * 86400;
|
||||
|
||||
$active = $this->createMock(ClinicSubscription::class);
|
||||
$active = $this->createStub(ClinicSubscription::class);
|
||||
$active->method('getExpiresAt')->willReturn($currentExpiry);
|
||||
|
||||
$service = $this->service($this->period(1), $active);
|
||||
|
||||
$subscription = $service->grant('doctor', 7, 'period-uuid', $this->createMock(User::class));
|
||||
$subscription = $service->grant('doctor', 7, 'period-uuid', $this->createStub(User::class));
|
||||
|
||||
$this->assertEqualsWithDelta($currentExpiry + 30 * 86400, $subscription->getExpiresAt(), 5);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user