path = sys_get_temp_dir() . '/monitor-hook-counter-' . uniqid() . '/hooks-count'; } protected function tearDown(): void { if (file_exists($this->path)) { unlink($this->path); } if (is_dir(dirname($this->path))) { rmdir(dirname($this->path)); } } public function testCountIsZeroWithoutAnyIncrement(): void { self::assertSame(0, (new HookCounter($this->path))->count()); } public function testIncrementReturnsTheNewCountAndPersistsIt(): void { $counter = new HookCounter($this->path); self::assertSame(1, $counter->increment()); self::assertSame(2, $counter->increment()); self::assertSame(3, $counter->increment()); self::assertSame(3, $counter->count()); } /** Ein zweites Objekt auf demselben Pfad muss den bereits geschriebenen Stand sehen. */ public function testCountIsSharedAcrossInstancesOnTheSamePath(): void { (new HookCounter($this->path))->increment(); (new HookCounter($this->path))->increment(); self::assertSame(2, (new HookCounter($this->path))->count()); } public function testIncrementCreatesMissingDirectory(): void { (new HookCounter($this->path))->increment(); self::assertFileExists($this->path); } public function testFingerprintReflectsTheCurrentCount(): void { $counter = new HookCounter($this->path); self::assertSame('0', $counter->fingerprint()); $counter->increment(); self::assertSame('1', $counter->fingerprint()); } }