Skip to content

Commit

Permalink
Merge pull request #486 from Ocramius/fix/avoid-phpunit-8.3-due-to-ph…
Browse files Browse the repository at this point in the history
…pdbg-process-isolation-bugs

Remove process isolation from tests around file writer generators
  • Loading branch information
Ocramius committed Aug 10, 2019
2 parents 0360501 + 0e1ac25 commit 37c7201
Show file tree
Hide file tree
Showing 46 changed files with 210 additions and 154 deletions.
Expand Up @@ -21,7 +21,6 @@ abstract class UniqueIdentifierGenerator
* Generates a valid unique identifier from the given name
*
* @psalm-return class-string
*
* @psalm-suppress MoreSpecificReturnType
*/
public static function getIdentifier(string $name) : string
Expand Down
Expand Up @@ -45,10 +45,9 @@ public function __construct(FileLocatorInterface $fileLocator)
*/
public function generate(ClassGenerator $classGenerator) : string
{
$className = trim($classGenerator->getNamespaceName(), '\\')
. '\\' . trim($classGenerator->getName(), '\\');
/** @var string $generatedCode */
$generatedCode = $classGenerator->generate();
$className = $classGenerator->getNamespaceName() . '\\' . $classGenerator->getName();
$fileName = $this->fileLocator->getProxyFileName($className);

set_error_handler($this->emptyErrorHandler);
Expand Down
Expand Up @@ -17,7 +17,6 @@
*/
final class UnsetPropertiesGenerator
{
/** @var string */
private const CLOSURE_TEMPLATE = <<<'PHP'
\Closure::bind(function (\%s $instance) {
%s
Expand Down
Expand Up @@ -186,7 +186,7 @@ static function (ClassGenerator $targetClass) use ($proxyClassName) : bool {
self::fail('Not supposed to be called');
},
];
$proxy = $factory->createProxy($instance, $prefixInterceptors, $suffixInterceptors);
$proxy = $factory->createProxy($instance, $prefixInterceptors, $suffixInterceptors);

self::assertInstanceOf($proxyClassName, $proxy);
self::assertSame($instance, $proxy->instance);
Expand Down
Expand Up @@ -26,6 +26,7 @@
use ReflectionClass;
use stdClass;
use function array_values;
use function get_class;
use function random_int;
use function serialize;
use function uniqid;
Expand Down Expand Up @@ -268,8 +269,8 @@ public function testPropertyUnset(object $instance, AccessInterceptorInterface $
*/
public function testCanWriteToArrayKeysInPublicProperty() : void
{
$instance = new ClassWithPublicArrayPropertyAccessibleViaMethod();
$proxy = (new AccessInterceptorScopeLocalizerFactory())->createProxy($instance);
$instance = new ClassWithPublicArrayPropertyAccessibleViaMethod();
$proxy = (new AccessInterceptorScopeLocalizerFactory())->createProxy($instance);

$proxy->arrayProperty['foo'] = 'bar';

Expand All @@ -287,8 +288,8 @@ public function testCanWriteToArrayKeysInPublicProperty() : void
*/
public function testWillNotModifyRetrievedPublicProperties() : void
{
$instance = new ClassWithPublicProperties();
$proxy = (new AccessInterceptorScopeLocalizerFactory())->createProxy($instance);
$instance = new ClassWithPublicProperties();
$proxy = (new AccessInterceptorScopeLocalizerFactory())->createProxy($instance);

$variable = $proxy->property0;

Expand All @@ -308,8 +309,8 @@ public function testWillNotModifyRetrievedPublicProperties() : void
*/
public function testWillModifyByRefRetrievedPublicProperties() : void
{
$instance = new ClassWithPublicProperties();
$proxy = (new AccessInterceptorScopeLocalizerFactory())->createProxy($instance);
$instance = new ClassWithPublicProperties();
$proxy = (new AccessInterceptorScopeLocalizerFactory())->createProxy($instance);

$variable = &$proxy->property0;

Expand Down Expand Up @@ -403,7 +404,7 @@ public static function getProxyMethods() : array
*/
public function getPropertyAccessProxies() : array
{
$instance = new BaseClass();
$instance = new BaseClass();

return [
[
Expand Down
Expand Up @@ -273,8 +273,8 @@ public function testPropertyUnset(
*/
public function testCanWriteToArrayKeysInPublicProperty() : void
{
$instance = new ClassWithPublicArrayPropertyAccessibleViaMethod();
$proxy = (new AccessInterceptorValueHolderFactory())->createProxy($instance);
$instance = new ClassWithPublicArrayPropertyAccessibleViaMethod();
$proxy = (new AccessInterceptorValueHolderFactory())->createProxy($instance);

$proxy->arrayProperty['foo'] = 'bar';

Expand All @@ -290,7 +290,7 @@ public function testCanWriteToArrayKeysInPublicProperty() : void
*/
public function testWillNotModifyRetrievedPublicProperties() : void
{
$instance = new ClassWithPublicProperties();
$instance = new ClassWithPublicProperties();
$proxy = (new AccessInterceptorValueHolderFactory())->createProxy($instance);
$variable = $proxy->property0;

Expand All @@ -307,7 +307,7 @@ public function testWillNotModifyRetrievedPublicProperties() : void
*/
public function testWillModifyByRefRetrievedPublicProperties() : void
{
$instance = new ClassWithPublicProperties();
$instance = new ClassWithPublicProperties();
$proxy = (new AccessInterceptorValueHolderFactory())->createProxy($instance);
$variable = &$proxy->property0;

Expand Down Expand Up @@ -468,8 +468,8 @@ public function getProxyMethods() : array
*/
public function getPropertyAccessProxies() : array
{
$instance1 = new BaseClass();
$instance2 = new BaseClass();
$instance1 = new BaseClass();
$instance2 = new BaseClass();
/** @var AccessInterceptorValueHolderInterface $serialized */
$serialized = unserialize(serialize((new AccessInterceptorValueHolderFactory())->createProxy($instance2)));

Expand Down
Expand Up @@ -50,8 +50,8 @@ final class FatalPreventionFunctionalTest extends TestCase
*/
public function testCodeGeneration(string $generatorClass, string $className) : void
{
$generatedClass = new ClassGenerator(uniqid('generated', true));
$generatorStrategy = new EvaluatingGeneratorStrategy();
$generatedClass = new ClassGenerator(uniqid('generated', true));
$generatorStrategy = new EvaluatingGeneratorStrategy();
$classGenerator = new $generatorClass();
$classSignatureGenerator = new ClassSignatureGenerator(new SignatureGenerator());

Expand Down
Expand Up @@ -169,7 +169,7 @@ public function testMethodCallsAfterCloning(
array $params,
$expectedValue
) : void {
$proxy = (new LazyLoadingGhostFactory())->createProxy(
$proxy = (new LazyLoadingGhostFactory())->createProxy(
$className,
$this->createInitializer($className, $instance)
);
Expand Down Expand Up @@ -438,7 +438,7 @@ static function (
?Closure & $initializer,
array $properties
) : bool {
$initializer = null;
$initializer = null;
$properties["\0" . ClassWithCollidingPrivateInheritedProperties::class . "\0property0"] = 'foo';
$properties["\0" . get_parent_class(ClassWithCollidingPrivateInheritedProperties::class) . "\0property0"] = 'bar';

Expand Down Expand Up @@ -820,7 +820,6 @@ public function testInitializeProxyWillReturnTrueOnSuccessfulInitialization() :

/**
* @psalm-param (CallableInterface&Mock)|null $initializerMatcher
*
* @psalm-return Closure(
* GhostObjectInterface $proxy,
* string $method,
Expand Down Expand Up @@ -990,8 +989,8 @@ public function getProxyNonInitializingMethods() : array
*/
public function getPropertyAccessProxies() : array
{
$instance1 = new BaseClass();
$instance2 = new BaseClass();
$instance1 = new BaseClass();
$instance2 = new BaseClass();

$factory = new LazyLoadingGhostFactory();

Expand Down Expand Up @@ -1219,7 +1218,10 @@ static function (
array $params,
?Closure & $initializer,
array $properties
) use ($propertyIndex, $expectedValue) : bool {
) use (
$propertyIndex,
$expectedValue
) : bool {
$initializer = null;

$properties[$propertyIndex] = $expectedValue;
Expand Down Expand Up @@ -1251,20 +1253,24 @@ public function testWillAccessMembersOfOtherDeSerializedProxiesWithTheSamePrivat
$proxy = unserialize(serialize(
(new LazyLoadingGhostFactory())->createProxy(
OtherObjectAccessClass::class,
static function (
GhostObjectInterface$proxy,
string $method,
array $params,
?Closure & $initializer,
array $properties
) use ($propertyIndex, $expectedValue) : bool {
$initializer = null;
static function (
GhostObjectInterface $proxy,
string $method,
array $params,
?Closure & $initializer,
array $properties
) use (
$propertyIndex,
$expectedValue
) : bool {
$initializer = null;

$properties[$propertyIndex] = $expectedValue;

$properties[$propertyIndex] = $expectedValue;

return true;
}
)));
return true;
}
)
));

$accessor = [$callerObject, $method];

Expand Down Expand Up @@ -1292,7 +1298,10 @@ static function (
array $params,
?Closure & $initializer,
array $properties
) use ($propertyIndex, $expectedValue) : bool {
) use (
$propertyIndex,
$expectedValue
) : bool {
$initializer = null;

$properties[$propertyIndex] = $expectedValue;
Expand Down
Expand Up @@ -125,7 +125,7 @@ public function testMethodCallsAfterCloning(
array $params,
$expectedValue
) : void {
$proxy = (new LazyLoadingValueHolderFactory())->createProxy(
$proxy = (new LazyLoadingValueHolderFactory())->createProxy(
$className,
$this->createInitializer($className, $instance)
);
Expand Down Expand Up @@ -236,7 +236,7 @@ public function testCanWriteToArrayKeysInPublicProperty() : void
*/
public function testWillNotModifyRetrievedPublicProperties() : void
{
$proxy = (new LazyLoadingValueHolderFactory())->createProxy(
$proxy = (new LazyLoadingValueHolderFactory())->createProxy(
ClassWithPublicProperties::class,
$this->createInitializer(ClassWithPublicProperties::class, new ClassWithPublicProperties())
);
Expand All @@ -255,7 +255,7 @@ public function testWillNotModifyRetrievedPublicProperties() : void
*/
public function testWillModifyByRefRetrievedPublicProperties() : void
{
$proxy = (new LazyLoadingValueHolderFactory())->createProxy(
$proxy = (new LazyLoadingValueHolderFactory())->createProxy(
ClassWithPublicProperties::class,
$this->createInitializer(ClassWithPublicProperties::class, new ClassWithPublicProperties())
);
Expand All @@ -276,7 +276,7 @@ public function testWillModifyByRefRetrievedPublicProperties() : void
*/
public function testWillAllowMultipleProxyInitialization() : void
{
$counter = 0;
$counter = 0;

$proxy = (new LazyLoadingValueHolderFactory())->createProxy(
BaseClass::class,
Expand Down Expand Up @@ -375,15 +375,15 @@ static function (?object & $wrappedInstance) : bool {
}

/**
* @psalm-param (CallableInterface&Mock)|null $initializerMatcher
*
* @return Closure(
* object|null,
* VirtualProxyInterface,
* string,
* array,
* ?Closure
* ) : bool
*
* @psalm-param (CallableInterface&Mock)|null $initializerMatcher
*/
private function createInitializer(string $className, object $realInstance, ?Mock $initializerMatcher = null) : Closure
{
Expand Down Expand Up @@ -534,9 +534,9 @@ public function getProxyMethods() : array
*/
public function getPropertyAccessProxies() : array
{
$instance1 = new BaseClass();
$instance2 = new BaseClass();
$factory = new LazyLoadingValueHolderFactory();
$instance1 = new BaseClass();
$instance2 = new BaseClass();
$factory = new LazyLoadingValueHolderFactory();
/** @var VirtualProxyInterface $serialized */
$serialized = unserialize(serialize($factory->createProxy(
BaseClass::class,
Expand Down Expand Up @@ -598,7 +598,7 @@ public function testWillFetchMembersOfOtherDeSerializedProxiesWithTheSamePrivate
) : void {
$className = get_class($realInstance);
/** @var LazyLoadingInterface $proxy */
$proxy = unserialize(serialize((new LazyLoadingValueHolderFactory())->createProxy(
$proxy = unserialize(serialize((new LazyLoadingValueHolderFactory())->createProxy(
$className,
$this->createInitializer($className, $realInstance)
)));
Expand Down
Expand Up @@ -23,7 +23,7 @@ final class ClassGeneratorUtilsTest extends TestCase
{
public function testCantAddAFinalMethod() : void
{
$classGenerator = $this->createMock(ClassGenerator::class);
$classGenerator = $this->createMock(ClassGenerator::class);
$methodGenerator = $this->createMock(MethodGenerator::class);

$methodGenerator
Expand All @@ -42,7 +42,7 @@ public function testCantAddAFinalMethod() : void

public function testCanAddANotFinalMethod() : void
{
$classGenerator = $this->createMock(ClassGenerator::class);
$classGenerator = $this->createMock(ClassGenerator::class);
$methodGenerator = $this->createMock(MethodGenerator::class);

$methodGenerator
Expand Down

0 comments on commit 37c7201

Please sign in to comment.