Add unit tests for mutex classes#20786
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #20786 +/- ##
============================================
+ Coverage 80.15% 80.17% +0.01%
Complexity 11536 11536
============================================
Files 374 374
Lines 30213 30213
============================================
+ Hits 24218 24222 +4
+ Misses 5995 5991 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR adds PHPUnit coverage for Yii2’s mutex layer to validate core behaviors in Mutex, DB-backed mutex initialization in DbMutex, and driver validation / configuration defaults in OracleMutex.
Changes:
- Add unit tests for base
Mutexacquire/release behavior andautoReleasehandling using a lightweight mock mutex. - Add unit tests for
DbMutexto verify$dbresolution via app component, config arrays, and invalid configuration handling. - Add unit tests for
OracleMutexto verify supported drivers, default/custom properties, and invalid driver exceptions.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/framework/mutex/MutexTest.php | Covers core Mutex acquire/release semantics and ensures acquire short-circuits when already held. |
| tests/framework/mutex/DbMutexTest.php | Verifies DbMutex::$db initialization via Instance::ensure() across supported input forms and error cases. |
| tests/framework/mutex/OracleMutexTest.php | Validates OracleMutex::init() driver checks plus default/custom property configuration and exception behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
📝 WalkthroughSummary by CodeRabbit
WalkthroughThree new test suites were added to validate mutex implementations: Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/framework/mutex/OracleMutexTest.php (1)
23-97: Optional: extract repeated DB mock setup into a helper.The
Connectionmock +driverNamemapping pattern is repeated in several tests; a private helper would make this file easier to maintain.♻️ Suggested refactor
class OracleMutexTest extends TestCase { + private function createDbMock(string $driverName): Connection + { + $db = $this->createMock(Connection::class); + $db->method('__get')->willReturnMap([ + ['driverName', $driverName], + ]); + return $db; + } + public function testInitSucceedsWithOciDriver(): void { - $db = $this->createMock(Connection::class); - $db->method('__get')->willReturnMap([ - ['driverName', 'oci'], - ]); + $db = $this->createDbMock('oci'); ... }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/framework/mutex/OracleMutexTest.php` around lines 23 - 97, Multiple tests in OracleMutexTest repeat creating a Connection mock with a driverName mapping; extract that into a private helper (e.g., private function createConnectionMock(string $driverName): Connection) and use it from tests like testInitSucceedsWithOciDriver, testInitSucceedsWithOdbcDriver, testDefaultProperties, testCustomProperties, and testThrowsExceptionForInvalidDrivers to reduce duplication; the helper should configure the __get()->willReturnMap([...]) for 'driverName' and return the mock so tests can pass it into mockApplication() and OracleMutex instantiation.
🤖 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/framework/mutex/OracleMutexTest.php`:
- Around line 23-97: Multiple tests in OracleMutexTest repeat creating a
Connection mock with a driverName mapping; extract that into a private helper
(e.g., private function createConnectionMock(string $driverName): Connection)
and use it from tests like testInitSucceedsWithOciDriver,
testInitSucceedsWithOdbcDriver, testDefaultProperties, testCustomProperties, and
testThrowsExceptionForInvalidDrivers to reduce duplication; the helper should
configure the __get()->willReturnMap([...]) for 'driverName' and return the mock
so tests can pass it into mockApplication() and OracleMutex instantiation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: f016babe-ad09-4a88-bcc5-2a7217663ff3
📒 Files selected for processing (3)
tests/framework/mutex/DbMutexTest.phptests/framework/mutex/MutexTest.phptests/framework/mutex/OracleMutexTest.php
What does this PR do?
Adds unit tests for
Mutex,DbMutex, andOracleMutex.Coverage
framework/mutex/Mutex.phpframework/mutex/DbMutex.phpframework/mutex/OracleMutex.phpChangelog not required, because no source files changed.