suin/php-expose
Expose helps PHPUnit tests access private/protected properties and methods in PHP objects. Use a simple fluent API to set non-public attributes and call hidden methods without changing production code. Requires PHP 5.3+ and installs via Composer.
bootstrap.php), preventing accidental exposure in CI/CD pipelines or production deployments.ReflectionClass to expose members, which may introduce minor performance overhead in tests (negligible for most cases but worth benchmarking in high-scale test suites).ReflectionProperty::setAccessible() is now public but behavior may differ).'_secret') lacks IDE autocompletion or static analysis support (e.g., PHPStan).Test Strategy Alignment:
@internal annotations, setAccessible(true), or mocking frameworks like Mockery) that could reduce dependency on this package?PHP Version Support:
CI/CD Impact:
Maintenance Burden:
bootstrap.php, handling version bumps)?Security Implications:
Pilot Phase:
setAccessible(true) or mocks).Gradual Adoption:
Tooling Integration:
phpunit.xml with bootstrap.php pointing to the autoloader.phpunit.xml snippet:
<php>
<autoload>
<file>vendor/autoload.php</file>
</autoload>
</php>
composer.json:
"require-dev": {
"suin/php-expose": "^1.0"
}
composer install --dev.e::expose($object) only where necessary.public function testPrivateMethod()
{
$obj = new MyClass();
$result = e::expose($obj)->call('_privateMethod', $arg);
$this->assertEquals(...);
}
ReflectionClass::setAccessible()).ReflectionClass::setAccessible() if the package fails.--parallel).| Scenario | Impact | Mitigation |
|---|---|---|
| Package abandoned | Tests break on PHP updates | Pin version in composer.json |
| Reflection deprecations (PHP 8+) | Warnings/errors in tests | Use polyfills or migrate to alternatives |
| Overuse in production code | Accidental exposure | Restrict to tests/ directory via CI linting |
| False test passes | Tests pass due to exposed state | Pair with mocking or behavioral tests |
CONTRIBUTING.md).How can I help you explore Laravel packages today?