nyholm/nsa
Testing helper to access and manipulate private/protected properties and methods in PHP. Set/get instance or static properties and invoke hidden methods to simplify tests and improve DX. Install via Composer: nyholm/nsa.
protected for testing).NSA::getConstant() and static property access for abstract classes address Laravel-specific testing gaps (e.g., testing Illuminate\Support\Facades or base model behaviors).require-dev in composer.json to prevent accidental inclusion in production. Laravel’s composer.json supports this natively.tinker or debugbar).Illuminate\Database\Eloquent\Model static properties) due to reflection limitations.NSA::getClosure()) or restricting usage to critical test paths.webmozart/assert is lightweight but could introduce breaking changes (e.g., version 2.0+ in 1.4.0). Lock to ^1.0 in composer.json to avoid surprises.phpstan or psalm).autoload (not autoload-dev) could expose internal methods. Add CI checks:
grep -r "Nsa\\\\" src/ && exit 1
"Use NSA only for testing behavior that cannot be refactored to use public APIs or interfaces."
webmozart/assert or PHP 8+ behavior?allowMockingPrivateMethods be sufficient for our needs?Illuminate\Support\Facades or base classes.composer.json under require-dev:
"require-dev": {
"nyholm/nsa": "^1.3"
}
App/Services/) to test integration.composer.json and run tests to ensure no conflicts.Illuminate/Testing or Laravel/Pest.// @psalm-suppress UndefinedClass, UndefinedMethod
NSA::invokeMethod($object, 'privateMethod');
composer.json and run composer update.composer install --dev).autoload-dev in composer.json:
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
}
hashPassword()).webmozart/assert to ^1.0 to avoid breaking changes (e.g., version 2.0+ in 1.4.0).# Example GitHub Actions check
- name: Prevent
How can I help you explore Laravel packages today?