60, 'unit_minor' => 100 ) ), new RuleDef( 2, 1, 'counter', array( 'step' => 1, 'per_minor' => 1000, 'carry_over' => true, 'label' => 'Pies' ) ), ) ), new FakeEventStore(), $state, fn(): int => $now ); $svc = new OverlayService( new class( $state ) implements OverlayDataSource { public function __construct( private FakeStateRepository $s ) {} public function activeGoal(): ?array { return array( 'id' => 1, 'title' => 'G', 'target_minor' => 5000, 'currency' => 'USD' ); } public function raisedMinor( array $goal ): int { return 0; } public function stateValue( int $goalId, string $key ): ?string { $v = $this->s->getInt( $goalId, $key, -1 ); return -1 === $v ? null : (string) $v; } public function counter( int $goalId ): array { return array( 'label' => 'Pies', 'value' => $this->s->getInt( $goalId, 'counter:2' ) ); } public function donations( ?int $sinceId, int $limit ): array { return array(); } } ); $d = new Donation( 7, 1, 2500, 0, 2500, 'USD' ); // $25 -> +25 min, counter +2 $engine->applyDonation( $d ); $this->assertSame( $now + 1500, $svc->payload( 'timer', $now )['ends_at'] ); $this->assertSame( 2, $svc->payload( 'counter', $now )['value'] ); $engine->applyDonation( $d ); // webhook replay must not double count $this->assertSame( $now + 1500, $svc->payload( 'timer', $now )['ends_at'] ); $engine->reverseDonation( $d ); $this->assertSame( 0, $svc->payload( 'counter', $now )['value'] ); } }