diff --git a/src/Stores/MemoryStore.php b/src/Stores/MemoryStore.php index 4299bd0..80cc1b7 100644 --- a/src/Stores/MemoryStore.php +++ b/src/Stores/MemoryStore.php @@ -13,14 +13,14 @@ class MemoryStore implements RateLimitStore * * @var array */ - protected array $store = []; + protected static array $store = []; /** * Get a rate limit from the store */ public function get(string $key): ?string { - return $this->store[$key] ?? null; + return self::$store[$key] ?? null; } /** @@ -28,7 +28,7 @@ public function get(string $key): ?string */ public function set(string $key, string $value, int $ttl): bool { - $this->store[$key] = $value; + self::$store[$key] = $value; return true; } @@ -40,6 +40,14 @@ public function set(string $key, string $value, int $ttl): bool */ public function getStore(): array { - return $this->store; + return self::$store; + } + + /** + * Clear the store + */ + public static function clear(): void + { + self::$store = []; } } diff --git a/tests/Pest.php b/tests/Pest.php index 0bc9ce1..78c84f2 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -13,9 +13,17 @@ | */ +use Saloon\RateLimitPlugin\Stores\MemoryStore; use Orchestra\Testbench\TestCase as LaravelTestCase; -uses(LaravelTestCase::class)->in('./Laravel'); +uses(LaravelTestCase::class) + ->beforeEach(fn () => MemoryStore::clear()) + ->in('./Laravel'); + +uses() + ->beforeEach(fn () => MemoryStore::clear()) + ->afterEach(fn () => MemoryStore::clear()) + ->in('./'); /* |--------------------------------------------------------------------------