Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
When you need to make a protected/private property public for testing/inspection.
# ignore
use \Way\Console\Guardfile;
use Mockery as m;
class GuardfileTest extends \PHPUnit_Framework_TestCase {
public function testCanOverrideDefaultPath()
$file = m::mock('Illuminate\Filesystem\Filesystem');
$guardFile = new Guardfile($file, 'foo/bar');
# When we need to inspect private properties,
# let's use a helper method.
$pathProperty = $this->makePublic($guardFile, 'path');
# Use getValue($instance) to fetch the value of the prop.
$this->assertEquals('foo/bar', $pathProperty->getValue($guardFile));
protected function makePublic($obj, $property)
$reflect = new \ReflectionObject($obj);
$property = $reflect->getProperty($property);
return $property;

This comment has been minimized.

Copy link

troccoli commented Dec 19, 2018

Great gist. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.