nyholm/nsa
See everything and do whatever you want. No privacy rule will stop us. Used in tests, debugging and fixtures to access properties and methods.
Maintainers
Fund package maintenance!
Requires
- php: >=7.1
- webmozart/assert: ^1.1.0 || ^2.0
Requires (Dev)
- symfony/phpunit-bridge: ^4.4 || ^5.1 || ^6.0 || ^7.0 || ^8.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
MIT 1998db84b74a2f5f5a4a651132000672346af24d
- Tobias Nyholm <tobias.nyholm.woop@gmail.com>
This package is auto-updated.
Last update: 2026-05-20 15:35:35 UTC
README
👁 Latest Version
👁 Software License
👁 Tests
👁 Code Coverage
👁 Quality Score
👁 Total Downloads
This small class helps you to test your private and protected properties and methods. One could argue that you never should test private methods but sometimes it just makes the test code a lot cleaner and easier to write and understand. This library is all about DX.
Usage
$object = new Dog(); NSA::setProperty($object, 'name', 'Foobar'); $name = NSA::getProperty($object, 'name'); $result = NSA::invokeMethod($object, 'doAction', 'jump', '1 meter'); echo $name; // "Foobar" echo $result; // "Dog just did 'jump' for 1 meter" // Access static properties and methods $age = NSA::getProperty('\Dog', 'age'); echo $age; // 12
class Dog { private $name = 'unnamed'; private static $age = 12; private function doAction($action, $parameter) { return sprintf("Dog just did '%s' for %s", $action, $parameter); } }
Install
$ composer require nyholm/nsa
License
The MIT License (MIT). Please see License File for more information.
