* @license MIT * * @link https://github.com/Ocramius/ProxyManager/issues/10 * * @group Functional * @group issue-10 * @coversNothing */ class MultipleProxyGenerationTest extends PHPUnit_Framework_TestCase { /** * Verifies that proxies generated from different factories will retain their specific implementation * and won't conflict * * @dataProvider getTestedClasses */ public function testCanGenerateMultipleDifferentProxiesForSameClass($className) { $skipScopeLocalizerTests = false; $ghostProxyFactory = new LazyLoadingGhostFactory(); $virtualProxyFactory = new LazyLoadingValueHolderFactory(); $accessInterceptorFactory = new AccessInterceptorValueHolderFactory(); $accessInterceptorScopeLocalizerFactory = new AccessInterceptorScopeLocalizerFactory(); $initializer = function () { }; $reflectionClass = new ReflectionClass($className); if ((! method_exists('Closure', 'bind')) && $reflectionClass->getProperties(ReflectionProperty::IS_PRIVATE)) { $skipScopeLocalizerTests = true; } $generated = array( $ghostProxyFactory->createProxy($className, $initializer), $virtualProxyFactory->createProxy($className, $initializer), $accessInterceptorFactory->createProxy(new $className()), ); if (! $skipScopeLocalizerTests) { $generated[] = $accessInterceptorScopeLocalizerFactory->createProxy(new $className()); } foreach ($generated as $key => $proxy) { $this->assertInstanceOf($className, $proxy); foreach ($generated as $comparedKey => $comparedProxy) { if ($comparedKey === $key) { continue; } $this->assertNotSame(get_class($comparedProxy), get_class($proxy)); } } $this->assertInstanceOf('ProxyManager\Proxy\GhostObjectInterface', $generated[0]); $this->assertInstanceOf('ProxyManager\Proxy\VirtualProxyInterface', $generated[1]); $this->assertInstanceOf('ProxyManager\Proxy\AccessInterceptorInterface', $generated[2]); $this->assertInstanceOf('ProxyManager\Proxy\ValueHolderInterface', $generated[2]); if (! $skipScopeLocalizerTests) { $this->assertInstanceOf('ProxyManager\Proxy\AccessInterceptorInterface', $generated[3]); } } /** * @return string[][] */ public function getTestedClasses() { $data = array( array('ProxyManagerTestAsset\\BaseClass'), array('ProxyManagerTestAsset\\ClassWithMagicMethods'), array('ProxyManagerTestAsset\\ClassWithFinalMethods'), array('ProxyManagerTestAsset\\ClassWithFinalMagicMethods'), array('ProxyManagerTestAsset\\ClassWithByRefMagicMethods'), array('ProxyManagerTestAsset\\ClassWithMixedProperties'), array('ProxyManagerTestAsset\\ClassWithPrivateProperties'), array('ProxyManagerTestAsset\\ClassWithProtectedProperties'), array('ProxyManagerTestAsset\\ClassWithPublicProperties'), array('ProxyManagerTestAsset\\EmptyClass'), array('ProxyManagerTestAsset\\HydratedObject'), ); if (PHP_VERSION_ID >= 50401) { // PHP < 5.4.1 misbehaves, throwing strict standards, see https://bugs.php.net/bug.php?id=60573 $data[] = array('ProxyManagerTestAsset\\ClassWithSelfHint'); } return $data; } }