for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types = 1);
namespace Common;
use ReflectionProperty;
/**
* Reusable component to allow changing private/protected attributes
*
* @author Luís Otávio Cobucci Oblonczyk <[email protected]>
*/
trait ChangeProtectedAttribute
{
* Configures the attribute with the given value
* @param object $object
* @param string $name
* @param mixed $value
public function modifyAttribute($object, $name, $value)
$attribute = new ReflectionProperty($object, $name);
$attribute->setAccessible(true);
$attribute->setValue($object, $value);
}