Skip to content

Commit b5f8ae6

Browse files
committed
[#190] Stabilize rate-limit test storage setup
1 parent e5e6200 commit b5f8ae6

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

tests/Feature/AppTestCase.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public function setUp(): void
2525
parent::setUp();
2626
ob_start();
2727

28+
$this->ensureRateLimitStorageExists();
2829
self::$app = createApp(AppType::WEB, PROJECT_ROOT);
2930
$this->clearRateLimitStorage();
3031
}
@@ -78,4 +79,19 @@ private function clearRateLimitStorage(): void
7879
}
7980
}
8081
}
82+
83+
private function ensureRateLimitStorageExists(): void
84+
{
85+
$rateLimitDir = PROJECT_ROOT . DS . 'cache' . DS . 'data';
86+
87+
if (is_dir($rateLimitDir)) {
88+
return;
89+
}
90+
91+
$created = mkdir($rateLimitDir, 0777, true);
92+
93+
if (!$created && !is_dir($rateLimitDir)) {
94+
throw new RuntimeException('Failed to create rate limit storage directory: ' . $rateLimitDir);
95+
}
96+
}
8197
}

tests/Feature/modules/Api/RateLimitTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class RateLimitTest extends AppTestCase
1010
public function setUp(): void
1111
{
1212
parent::setUp();
13-
$this->ensureRateLimitStorageExists();
1413
$this->clearRateLimitStorage();
1514
}
1615

@@ -75,13 +74,4 @@ private function clearRateLimitStorage(): void
7574
}
7675
}
7776

78-
private function ensureRateLimitStorageExists(): void
79-
{
80-
$rateLimitDir = PROJECT_ROOT . DS . 'cache' . DS . 'data';
81-
82-
if (!is_dir($rateLimitDir)) {
83-
$created = mkdir($rateLimitDir, 0777, true);
84-
$this->assertTrue($created || is_dir($rateLimitDir), 'Failed to create rate limit storage directory: ' . $rateLimitDir);
85-
}
86-
}
8777
}

0 commit comments

Comments
 (0)