Skip to content

Commit

Permalink
Merge pull request #288 from Ocramius/test/#276-verify-friend-objects…
Browse files Browse the repository at this point in the history
…-with-skipped-properties

#276 - testing friend object access against skipped properties
  • Loading branch information
Jefersson Nathan committed Jan 29, 2016
2 parents 2bde14e + ed8d987 commit e10083f
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1244,4 +1244,48 @@ public function getMethodsThatAccessPropertiesOnOtherObjectsInTheSameScope() : a
],
];
}

/**
* @group 276
*/
public function testFriendObjectWillNotCauseLazyLoadingOnSkippedProperty()
{
$proxyName = $this->generateProxy(
OtherObjectAccessClass::class,
[
'skippedProperties' => [
"\0" . OtherObjectAccessClass::class . "\0privateProperty",
"\0*\0protectedProperty",
'publicProperty'
],
]
);

/* @var $proxy OtherObjectAccessClass|LazyLoadingInterface */
$proxy = $proxyName::staticProxyConstructor(function () {
throw new \BadMethodCallException('The proxy should never be initialized, as all properties are skipped');
});

$privatePropertyValue = uniqid('', true);
$protectedPropertyValue = uniqid('', true);
$publicPropertyValue = uniqid('', true);

$reflectionPrivateProperty = new \ReflectionProperty(OtherObjectAccessClass::class, 'privateProperty');

$reflectionPrivateProperty->setAccessible(true);
$reflectionPrivateProperty->setValue($proxy, $privatePropertyValue);

$reflectionProtectedProperty = new \ReflectionProperty(OtherObjectAccessClass::class, 'protectedProperty');

$reflectionProtectedProperty->setAccessible(true);
$reflectionProtectedProperty->setValue($proxy, $protectedPropertyValue);

$proxy->publicProperty = $publicPropertyValue;

$friendObject = new OtherObjectAccessClass();

self::assertSame($privatePropertyValue, $friendObject->getPrivateProperty($proxy));
self::assertSame($protectedPropertyValue, $friendObject->getProtectedProperty($proxy));
self::assertSame($publicPropertyValue, $friendObject->getPublicProperty($proxy));
}
}

0 comments on commit e10083f

Please sign in to comment.