Reduce bcrypt cost in Auth and Hasher tests for faster test execution#436
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughTests now construct Hasher instances with bcrypt cost explicitly set to 4 via setCost(4) across auth and hasher test files; related expectations in HasherTest were adjusted to reflect the lower-cost hashing behavior. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #436 +/- ##
=========================================
Coverage 82.64% 82.64%
Complexity 2721 2721
=========================================
Files 241 241
Lines 7305 7305
=========================================
Hits 6037 6037
Misses 1268 1268 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/Unit/Auth/AuthTest.php (1)
35-35: Consider centralizing the fast test hasher to remove duplication.
(new Hasher())->setCost(4)is repeated multiple times here (and similarly in sibling tests). A small helper improves maintainability if test hashing config changes again.♻️ Possible refactor
class AuthTest extends AuthTestCase { private JwtToken $jwt; + + private function fastHasher(): Hasher + { + return (new Hasher())->setCost(4); + } public function testAuthGetAdapter(): void { - $auth = new Auth(new SessionAuthAdapter($this->authService, $this->mailer, (new Hasher())->setCost(4))); + $auth = new Auth(new SessionAuthAdapter($this->authService, $this->mailer, $this->fastHasher())); $this->assertInstanceOf(AuthenticatableInterface::class, $auth->getAdapter()); - $auth = new Auth(new JwtAuthAdapter($this->authService, $this->mailer, (new Hasher())->setCost(4), $this->jwt)); + $auth = new Auth(new JwtAuthAdapter($this->authService, $this->mailer, $this->fastHasher(), $this->jwt)); } public function testAuthCallingValidMethod(): void { - $auth = new Auth(new JwtAuthAdapter($this->authService, $this->mailer, (new Hasher())->setCost(4), $this->jwt)); + $auth = new Auth(new JwtAuthAdapter($this->authService, $this->mailer, $this->fastHasher(), $this->jwt)); } public function testAuthCallingInvalidMethod(): void { - $auth = new Auth(new JwtAuthAdapter($this->authService, $this->mailer, (new Hasher())->setCost(4), $this->jwt)); + $auth = new Auth(new JwtAuthAdapter($this->authService, $this->mailer, $this->fastHasher(), $this->jwt)); } }Also applies to: 39-39, 46-46, 61-61
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/Unit/Auth/AuthTest.php` at line 35, Replace repeated inline Hasher creation in tests with a centralized helper to produce a low-cost test hasher: add a private helper (e.g., createFastHasher or setUp-initialized $fastHasher) and use that in places constructing SessionAuthAdapter and Auth (referencing Auth and SessionAuthAdapter and Hasher in tests/Unit/Auth/AuthTest.php) so all occurrences of (new Hasher())->setCost(4) are replaced by the helper call; this keeps test setup consistent and makes future cost changes one-place updates.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@tests/Unit/Auth/AuthTest.php`:
- Line 35: Replace repeated inline Hasher creation in tests with a centralized
helper to produce a low-cost test hasher: add a private helper (e.g.,
createFastHasher or setUp-initialized $fastHasher) and use that in places
constructing SessionAuthAdapter and Auth (referencing Auth and
SessionAuthAdapter and Hasher in tests/Unit/Auth/AuthTest.php) so all
occurrences of (new Hasher())->setCost(4) are replaced by the helper call; this
keeps test setup consistent and makes future cost changes one-place updates.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: bacf7745-a4a7-4cef-9c4b-1f930e239295
📒 Files selected for processing (4)
tests/Unit/Auth/Adapters/JwtAuthAdapterTest.phptests/Unit/Auth/Adapters/SessionAuthAdapterTest.phptests/Unit/Auth/AuthTest.phptests/Unit/Hasher/HasherTest.php
helper to produce a low-cost test hasher
Fixes #435
Summary by CodeRabbit