wikimedia/testing-access-wrapper
Small PHP utility from Wikimedia that wraps objects to access otherwise non-public (protected/private) methods and properties in tests. Helps write focused unit tests without changing production visibility, acting as a thin “testing access wrapper.”
Purpose Alignment: The wikimedia/testing-access-wrapper package is a test utility designed to simplify access control testing in PHP applications (primarily MediaWiki). It abstracts authentication/authorization logic, allowing developers to mock or simulate user permissions without deep integration with the underlying auth system.
actingAs(), partialMock()) and packages like laravel-permission or spatie/laravel-permission already handle auth testing. This package’s value is niche—primarily useful if:
Title/User access controls.Illuminate\Auth), this package adds unnecessary abstraction without clear benefits.Key Features:
User/Title access checks (e.g., canRead(), canEdit()) for testing.PHP/Laravel Compatibility:
Title objects). Laravel typically uses User models or roles (e.g., spatie/laravel-permission).TestCase or HttpTests.Implementation Effort:
Title to Laravel’s Post/Page models).Guard/Provider system, which is not its intended use.User and Title classes. If your Laravel app uses different models (e.g., App\Models\User, App\Models/Article), you’ll need to rewrite or adapt the wrapper’s logic.Why Not Use Laravel’s Native Tools?
Integration Scope:
actingAs() or spatie/laravel-permission tests?Title/User to Laravel’s models?Long-Term Viability:
Alternatives:
laravel-permission or mockery achieve the same goals with less coupling?orchid/permissions) that fits better?Evaluation Phase:
Adaptation Phase:
Title/User to Laravel’s models (e.g., Article/User).
// Example adapter
class LaravelTitleAdapter {
public static function fromLaravelModel(Article $article): Title {
return new Title('...', $article->title);
}
}
TestCase to include the wrapper’s helpers.Full Integration:
require-dev dependency.Auth facade if misused in production.spatie/laravel-permission) if they define overlapping methods.| Scenario | Impact | Mitigation |
|---|---|---|
| MediaWiki auth system changes | Package breaks tests | Fork and maintain locally |
| Misused in production | Auth bypass vulnerabilities | Strictly scope to tests/ namespace |
| Overlaps with Laravel auth | Conflicting permission logic | Isolate wrapper in a test trait |
| Abandoned package | No updates for PHP/Laravel | Plan for migration to alternatives |
How can I help you explore Laravel packages today?