[ProxyManager] fix tests

This commit is contained in:
Nicolas Grekas 2021-01-04 12:30:20 +01:00
parent 04671ee726
commit 5ec2a252ee
4 changed files with 90 additions and 24 deletions

View File

@ -18,7 +18,7 @@
"require": { "require": {
"php": ">=7.1.3", "php": ">=7.1.3",
"ext-xml": "*", "ext-xml": "*",
"friendsofphp/proxy-manager-lts": "^1.0", "friendsofphp/proxy-manager-lts": "^1.0.2",
"doctrine/event-manager": "~1.0", "doctrine/event-manager": "~1.0",
"doctrine/persistence": "^1.3|^2", "doctrine/persistence": "^1.3|^2",
"twig/twig": "^1.41|^2.10|^3.0", "twig/twig": "^1.41|^2.10|^3.0",

View File

@ -11,7 +11,7 @@
namespace Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper; namespace Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper;
use ProxyManager\Generator\ClassGenerator; use Laminas\Code\Generator\ClassGenerator;
use ProxyManager\GeneratorStrategy\BaseGeneratorStrategy; use ProxyManager\GeneratorStrategy\BaseGeneratorStrategy;
use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface; use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface;

View File

@ -48,7 +48,7 @@ class SunnyInterface_%s implements \ProxyManager\Proxy\VirtualProxyInterface, \S
static $reflection; static $reflection;
$reflection = $reflection ?? new \ReflectionClass(__CLASS__); $reflection = $reflection ?? new \ReflectionClass(__CLASS__);
$instance%w= $reflection->newInstanceWithoutConstructor(); $instance = $reflection->newInstanceWithoutConstructor();
$instance->initializer%s = $initializer; $instance->initializer%s = $initializer;
@ -73,48 +73,114 @@ class SunnyInterface_%s implements \ProxyManager\Proxy\VirtualProxyInterface, \S
return $this->valueHolder%s->$name; return $this->valueHolder%s->$name;
} }
$targetObject = $this->valueHolder%s; $realInstanceReflection = new \ReflectionClass(__CLASS__);
$backtrace = debug_backtrace(false%S); if (! $realInstanceReflection->hasProperty($name)) {
trigger_error( $targetObject = $this->valueHolder%s;
sprintf(
'Undefined property: %s::$%s in %s on line %s', $backtrace = debug_backtrace(false, 1);
__CLASS__, trigger_error(
$name, sprintf(
$backtrace[0]['file'], 'Undefined property: %%s::$%%s in %%s on line %%s',
$backtrace[0]['line'] $realInstanceReflection->getName(),
), $name,
\E_USER_NOTICE $backtrace[0]['file'],
); $backtrace[0]['line']
return $targetObject->$name; ),
\E_USER_NOTICE
);
return $targetObject->$name;
}
$targetObject = $this->valueHolder%s;
$accessor = function & () use ($targetObject, $name) {
return $targetObject->$name;
};
$backtrace = debug_backtrace(true, 2);
$scopeObject = isset($backtrace[1]['object']) ? $backtrace[1]['object'] : new \ProxyManager\Stub\EmptyClassStub();
$accessor = $accessor->bindTo($scopeObject, get_class($scopeObject));
$returnValue = & $accessor();
return $returnValue;
} }
public function __set($name, $value) public function __set($name, $value)
{ {
$this->initializer%s && ($this->initializer%s->__invoke($valueHolder%s, $this, '__set', array('name' => $name, 'value' => $value), $this->initializer%s) || 1) && $this->valueHolder%s = $valueHolder%s; $this->initializer%s && ($this->initializer%s->__invoke($valueHolder%s, $this, '__set', array('name' => $name, 'value' => $value), $this->initializer%s) || 1) && $this->valueHolder%s = $valueHolder%s;
$targetObject = $this->valueHolder%s; $realInstanceReflection = new \ReflectionClass(__CLASS__);
$targetObject->$name = $value;%wreturn $targetObject->$name; if (! $realInstanceReflection->hasProperty($name)) {
$targetObject = $this->valueHolder%s;
$targetObject->$name = $value;
return $targetObject->$name;
}
$targetObject = $this->valueHolder%s;
$accessor = function & () use ($targetObject, $name, $value) {
$targetObject->$name = $value;
return $targetObject->$name;
};
$backtrace = debug_backtrace(true, 2);
$scopeObject = isset($backtrace[1]['object']) ? $backtrace[1]['object'] : new \ProxyManager\Stub\EmptyClassStub();
$accessor = $accessor->bindTo($scopeObject, get_class($scopeObject));
$returnValue = & $accessor();
return $returnValue;
} }
public function __isset($name) public function __isset($name)
{ {
$this->initializer%s && ($this->initializer%s->__invoke($valueHolder%s, $this, '__isset', array('name' => $name), $this->initializer%s) || 1) && $this->valueHolder%s = $valueHolder%s; $this->initializer%s && ($this->initializer%s->__invoke($valueHolder%s, $this, '__isset', array('name' => $name), $this->initializer%s) || 1) && $this->valueHolder%s = $valueHolder%s;
$targetObject = $this->valueHolder%s; $realInstanceReflection = new \ReflectionClass(__CLASS__);
return isset($targetObject->$name); if (! $realInstanceReflection->hasProperty($name)) {
$targetObject = $this->valueHolder%s;
return isset($targetObject->$name);
}
$targetObject = $this->valueHolder%s;
$accessor = function () use ($targetObject, $name) {
return isset($targetObject->$name);
};
$backtrace = debug_backtrace(true, 2);
$scopeObject = isset($backtrace[1]['object']) ? $backtrace[1]['object'] : new \ProxyManager\Stub\EmptyClassStub();
$accessor = $accessor->bindTo($scopeObject, get_class($scopeObject));
$returnValue = $accessor();
return $returnValue;
} }
public function __unset($name) public function __unset($name)
{ {
$this->initializer%s && ($this->initializer%s->__invoke($valueHolder%s, $this, '__unset', array('name' => $name), $this->initializer%s) || 1) && $this->valueHolder%s = $valueHolder%s; $this->initializer%s && ($this->initializer%s->__invoke($valueHolder%s, $this, '__unset', array('name' => $name), $this->initializer%s) || 1) && $this->valueHolder%s = $valueHolder%s;
$targetObject = $this->valueHolder%s; $realInstanceReflection = new \ReflectionClass(__CLASS__);
unset($targetObject->$name); if (! $realInstanceReflection->hasProperty($name)) {
%a } $targetObject = $this->valueHolder%s;
unset($targetObject->$name);
return;
}
$targetObject = $this->valueHolder%s;
$accessor = function () use ($targetObject, $name) {
unset($targetObject->$name);
return;
};
$backtrace = debug_backtrace(true, 2);
$scopeObject = isset($backtrace[1]['object']) ? $backtrace[1]['object'] : new \ProxyManager\Stub\EmptyClassStub();
$accessor = $accessor->bindTo($scopeObject, get_class($scopeObject));
$accessor();
}
public function __clone() public function __clone()
{ {

View File

@ -18,7 +18,7 @@
"require": { "require": {
"php": ">=7.1.3", "php": ">=7.1.3",
"composer/package-versions-deprecated": "^1.8", "composer/package-versions-deprecated": "^1.8",
"friendsofphp/proxy-manager-lts": "^1.0", "friendsofphp/proxy-manager-lts": "^1.0.2",
"symfony/dependency-injection": "^4.0|^5.0" "symfony/dependency-injection": "^4.0|^5.0"
}, },
"require-dev": { "require-dev": {