When you create tests in Laravel, you sometimes need to be able to access private properties.

There is a way to get around this by using the following helper method:

public static function getProperty($object, $property)
{
    $reflectedClass = new \ReflectionClass($object);
    $reflection = $reflectedClass->getProperty($property);
    $reflection->setAccessible(true);
    return $reflection->getValue($object);
}

And then in the unit test, use that like this:

$value = ReflectionHelper::getProperty($class, 'someProperty');
$this->assertSame($expected, $value);

Originally found the code here.