Skip to content

Commit 1eb810a

Browse files
committed
ConnectionManagerTest の reference closure を MutableClock に置換
probeReplicas の TTL リフレッシュテストで `use (&$now)` を使用しており、 SlevomatCodingStandard.PHP.DisallowReference (CLAUDE.md 「参照渡し禁止」) に 違反していた。既存の MutableClock helper に置き換えて解消する。 ed023d7 の push 後、CI Code Style ジョブで検出。原因はローカル phpcs 確認時に 出力を切り詰めて exit code を見落とし、エラーを誤って green と報告したこと。 今回は exit code を明示確認した。
1 parent ed023d7 commit 1eb810a

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

tests/Unit/Database/ConnectionManagerTest.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Sloop\Database\Exception\InvalidConfigException;
1414
use Sloop\Database\Factory\ConnectionFactory;
1515
use Sloop\Database\Replica\InMemoryDeadReplicaCache;
16+
use Sloop\Tests\Support\MutableClock;
1617
use Sloop\Tests\Unit\Database\Stub\AlwaysFailConnectionFactory;
1718
use Sloop\Tests\Unit\Database\Stub\FixedReplicaSelector;
1819
use Sloop\Tests\Unit\Database\Stub\ScriptedConnectionFactory;
@@ -954,17 +955,14 @@ public function testProbeReplicasRefreshesDeadMarkTtlOnRepeatedFailure(): void
954955
{
955956
// Use a controllable clock so the assertion proves the dead mark was
956957
// re-stamped by the probe rather than just lingering from the pre-mark.
957-
$now = 1000;
958-
$clock = function () use (&$now): int {
959-
return $now;
960-
};
961-
$deadCache = new InMemoryDeadReplicaCache($clock);
958+
$clock = new MutableClock(1000);
959+
$deadCache = new InMemoryDeadReplicaCache($clock(...));
962960

963961
// Pre-mark with a short TTL that would naturally expire at 1010.
964962
$deadCache->markServerDead('replica.internal', 0, 10);
965963

966964
// Advance past the original expiry; sanity-check the pre-mark is gone.
967-
$now = 1100;
965+
$clock->now = 1100;
968966
$this->assertFalse($deadCache->isDead('replica.internal', 0, 'master'));
969967

970968
$factory = new ScriptedConnectionFactory();
@@ -996,9 +994,9 @@ public function testProbeReplicasRefreshesDeadMarkTtlOnRepeatedFailure(): void
996994
// Still dead between the original 1010 expiry and the new 1160 expiry,
997995
// and gone again past 1160. This proves a fresh stamp, not a stale entry.
998996
$this->assertTrue($deadCache->isDead('replica.internal', 0, 'master'));
999-
$now = 1150;
997+
$clock->now = 1150;
1000998
$this->assertTrue($deadCache->isDead('replica.internal', 0, 'master'));
1001-
$now = 1170;
999+
$clock->now = 1170;
10021000
$this->assertFalse($deadCache->isDead('replica.internal', 0, 'master'));
10031001
}
10041002

0 commit comments

Comments
 (0)