Files

26 lines
720 B
PHP
Raw Permalink Normal View History

<?php
declare( strict_types=1 );
namespace StreamGoals\Tests\Unit;
use StreamGoals\Rules\EventStore;
final class FakeEventStore implements EventStore {
public array $events = array(); // "rule:donation" => [delta, reversed]
public function record( int $ruleId, int $donationId, int $delta ): bool {
$k = "$ruleId:$donationId";
if ( isset( $this->events[ $k ] ) ) {
return false;
}
$this->events[ $k ] = array( $delta, false );
return true;
}
public function markReversed( int $ruleId, int $donationId ): ?int {
$k = "$ruleId:$donationId";
if ( ! isset( $this->events[ $k ] ) || $this->events[ $k ][1] ) {
return null;
}
$this->events[ $k ][1] = true;
return $this->events[ $k ][0];
}
}