Skip to content

Commit

Permalink
ProxyGenerator: do not generate long file names
Browse files Browse the repository at this point in the history
  • Loading branch information
JanTvrdik committed Aug 8, 2023
1 parent 0a357f1 commit 414ccd0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/Proxy/ProxyGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -979,8 +979,8 @@ public function getProxyFileName($className, $baseDirectory = null)
{
$baseDirectory = $baseDirectory ?: $this->proxyDirectory;

return rtrim($baseDirectory, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . Proxy::MARKER
. str_replace('\\', '', $className) . '.php';
return rtrim($baseDirectory, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . Proxy::MARKER . DIRECTORY_SEPARATOR
. str_replace('\\', DIRECTORY_SEPARATOR, $className) . '.php';
}

/**
Expand Down
64 changes: 32 additions & 32 deletions tests/Common/Proxy/ProxyGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function testClassWithSleepProxyGeneration()
$this->generateAndRequire($proxyGenerator, $metadata);
}

$classCode = file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxySleepClass.php');
$classCode = file_get_contents(__DIR__ . '/generated/__CG__/Doctrine/Tests/Common/Proxy/SleepClass.php');
self::assertEquals(1, substr_count($classCode, 'function __sleep'));
self::assertEquals(1, substr_count($classCode, 'parent::__sleep()'));
}
Expand All @@ -119,7 +119,7 @@ public function testClassWithStaticPropertyProxyGeneration()
$this->generateAndRequire($proxyGenerator, $metadata);
}

$classCode = file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyStaticPropertyClass.php');
$classCode = file_get_contents(__DIR__ . '/generated/__CG__/Doctrine/Tests/Common/Proxy/StaticPropertyClass.php');
self::assertEquals(1, substr_count($classCode, 'function __sleep'));
self::assertStringNotContainsString('protectedStaticProperty', $classCode);
}
Expand All @@ -141,7 +141,7 @@ public function testClassWithCallableTypeHintOnProxiedMethod()
$this->generateAndRequire($proxyGenerator, $metadata);
}

$classCode = file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyCallableTypeHintClass.php');
$classCode = file_get_contents(__DIR__ . '/generated/__CG__/Doctrine/Tests/Common/Proxy/CallableTypeHintClass.php');

self::assertEquals(1, substr_count($classCode, 'call(callable $foo)'));
}
Expand All @@ -156,7 +156,7 @@ public function testClassWithVariadicArgumentOnProxiedMethod()
$this->generateAndRequire($proxyGenerator, $metadata);
}

$classCode = file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyVariadicTypeHintClass.php');
$classCode = file_get_contents(__DIR__ . '/generated/__CG__/Doctrine/Tests/Common/Proxy/VariadicTypeHintClass.php');

self::assertEquals(1, substr_count($classCode, 'function addType(...$types)'));
self::assertEquals(1, substr_count($classCode, '__invoke($this, \'addType\', [$types])'));
Expand All @@ -173,7 +173,7 @@ public function testClassWithScalarTypeHintsOnProxiedMethods()
$this->generateAndRequire($proxyGenerator, $metadata);
}

$classCode = file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyScalarTypeHintsClass.php');
$classCode = file_get_contents(__DIR__ . '/generated/__CG__/Doctrine/Tests/Common/Proxy/ScalarTypeHintsClass.php');

self::assertEquals(1, substr_count($classCode, 'function singleTypeHint(string $param)'));
self::assertEquals(1, substr_count($classCode, 'function multipleTypeHints(int $a, float $b, bool $c, string $d)'));
Expand All @@ -193,7 +193,7 @@ public function testClassWithReturnTypesOnProxiedMethods()
$this->generateAndRequire($proxyGenerator, $metadata);
}

$classCode = file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyReturnTypesClass.php');
$classCode = file_get_contents(__DIR__ . '/generated/__CG__/Doctrine/Tests/Common/Proxy/ReturnTypesClass.php');

self::assertEquals(1, substr_count($classCode, 'function returnsClass(): \stdClass'));
self::assertEquals(1, substr_count($classCode, 'function returnsScalar(): int'));
Expand All @@ -214,7 +214,7 @@ public function testClassWithNullableTypeHintsOnProxiedMethods()
$this->generateAndRequire($proxyGenerator, $metadata);
}

$classCode = file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyNullableTypeHintsClass.php');
$classCode = file_get_contents(__DIR__ . '/generated/__CG__/Doctrine/Tests/Common/Proxy/NullableTypeHintsClass.php');

self::assertEquals(1, substr_count($classCode, 'function nullableTypeHintInt(?int $param)'));
self::assertEquals(1, substr_count($classCode, 'function nullableTypeHintObject(?\stdClass $param)'));
Expand All @@ -234,7 +234,7 @@ public function testClassWithNullableReturnTypesOnProxiedMethods()
$this->generateAndRequire($proxyGenerator, $metadata);
}

$classCode = file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyNullableTypeHintsClass.php');
$classCode = file_get_contents(__DIR__ . '/generated/__CG__/Doctrine/Tests/Common/Proxy/NullableTypeHintsClass.php');

self::assertEquals(1, substr_count($classCode, 'function returnsNullableInt(): ?int'));
self::assertEquals(1, substr_count($classCode, 'function returnsNullableObject(): ?\stdClass'));
Expand All @@ -260,12 +260,12 @@ public function testClassWithNullableOptionalNonLastParameterOnProxiedMethods()

self::assertStringContainsString(
'public function midSignatureNullableParameter(\stdClass $param = NULL, $secondParam)',
file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyNullableNonOptionalHintClass.php')
file_get_contents(__DIR__ . '/generated/__CG__/Doctrine/Tests/Common/Proxy/NullableNonOptionalHintClass.php')
);

self::assertStringContainsString(
'public function midSignatureNotNullableHintedParameter(string $param = \'foo\', $secondParam)',
file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyNullableNonOptionalHintClass.php')
file_get_contents(__DIR__ . '/generated/__CG__/Doctrine/Tests/Common/Proxy/NullableNonOptionalHintClass.php')
);
}

Expand All @@ -288,13 +288,13 @@ public function testClassWithPhp71NullableOptionalNonLastParameterOnProxiedMetho

self::assertStringContainsString(
'public function midSignatureNullableParameter(string $param = NULL, $secondParam)',
file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyPhp71NullableDefaultedNonOptionalHintClass.php'),
file_get_contents(__DIR__ . '/generated/__CG__/Doctrine/Tests/Common/Proxy/Php71NullableDefaultedNonOptionalHintClass.php'),
'Signature allows nullable type, although explicit "?" marker isn\'t used in the proxy'
);

self::assertStringContainsString(
'public function midSignatureNotNullableHintedParameter(?string $param = \'foo\', $secondParam)',
file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyPhp71NullableDefaultedNonOptionalHintClass.php')
file_get_contents(__DIR__ . '/generated/__CG__/Doctrine/Tests/Common/Proxy/Php71NullableDefaultedNonOptionalHintClass.php')
);
}

Expand All @@ -308,7 +308,7 @@ public function testClassWithVoidReturnType()
$this->generateAndRequire($proxyGenerator, $metadata);
}

$classCode = file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyVoidReturnTypeClass.php');
$classCode = file_get_contents(__DIR__ . '/generated/__CG__/Doctrine/Tests/Common/Proxy/VoidReturnTypeClass.php');

self::assertEquals(1, substr_count($classCode, 'function returnsVoid(): void'));
}
Expand All @@ -323,7 +323,7 @@ public function testClassWithIterableTypeHint()
$this->generateAndRequire($proxyGenerator, $metadata);
}

$classCode = file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyIterableTypeHintClass.php');
$classCode = file_get_contents(__DIR__ . '/generated/__CG__/Doctrine/Tests/Common/Proxy/IterableTypeHintClass.php');

self::assertEquals(1, substr_count($classCode, 'function parameterType(iterable $param)'));
self::assertEquals(1, substr_count($classCode, 'function returnType(): iterable'));
Expand Down Expand Up @@ -433,7 +433,7 @@ public function testPhp8CloneWithVoidReturnType()

self::assertStringContainsString(
'public function __clone(): void',
file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyPhp8MagicCloneClass.php')
file_get_contents(__DIR__ . '/generated/__CG__/Doctrine/Tests/Common/Proxy/Php8MagicCloneClass.php')
);
}

Expand All @@ -453,12 +453,12 @@ public function testPhp8UnionTypes()

self::assertStringContainsString(
'setValue(\stdClass|array $value): float|bool',
file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyPhp8UnionTypes.php')
file_get_contents(__DIR__ . '/generated/__CG__/Doctrine/Tests/Common/Proxy/Php8UnionTypes.php')
);

self::assertStringContainsString(
'setNullableValue(\stdClass|array|null $value): float|bool|null',
file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyPhp8UnionTypes.php')
file_get_contents(__DIR__ . '/generated/__CG__/Doctrine/Tests/Common/Proxy/Php8UnionTypes.php')
);
}

Expand All @@ -478,7 +478,7 @@ public function testPhp8MixedType()

self::assertStringContainsString(
'foo(mixed $bar): mixed',
file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyPhp8MixedType.php')
file_get_contents(__DIR__ . '/generated/__CG__/Doctrine/Tests/Common/Proxy/Php8MixedType.php')
);
}

Expand All @@ -498,12 +498,12 @@ public function testPhp8StaticType()

self::assertStringContainsString(
'foo(mixed $bar): static',
file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyPhp8StaticType.php')
file_get_contents(__DIR__ . '/generated/__CG__/Doctrine/Tests/Common/Proxy/Php8StaticType.php')
);

self::assertStringContainsString(
'fooNull(mixed $bar): ?static',
file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyPhp8StaticType.php')
file_get_contents(__DIR__ . '/generated/__CG__/Doctrine/Tests/Common/Proxy/Php8StaticType.php')
);
}

Expand All @@ -523,7 +523,7 @@ public function testPhp81IntersectionType()

self::assertStringContainsString(
'setFoo(\Traversable&\Countable $foo): \Traversable&\Countable',
file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyPHP81IntersectionTypes.php')
file_get_contents(__DIR__ . '/generated/__CG__/Doctrine/Tests/Common/Proxy/PHP81IntersectionTypes.php')
);
}

Expand All @@ -543,17 +543,17 @@ public function testPhp81NeverType()

self::assertStringContainsString(
'__get($name): never',
file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyPHP81NeverType.php')
file_get_contents(__DIR__ . '/generated/__CG__/Doctrine/Tests/Common/Proxy/PHP81NeverType.php')
);

self::assertStringContainsString(
'__set($name, $value): never',
file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyPHP81NeverType.php')
file_get_contents(__DIR__ . '/generated/__CG__/Doctrine/Tests/Common/Proxy/PHP81NeverType.php')
);

self::assertStringContainsString(
'finishHim(): never',
file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyPHP81NeverType.php')
file_get_contents(__DIR__ . '/generated/__CG__/Doctrine/Tests/Common/Proxy/PHP81NeverType.php')
);
}

Expand All @@ -575,7 +575,7 @@ public function testEnumDefaultInPublicProperty() : void

$this->assertStringContainsString(
'use Doctrine;',
file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyPhp81EnumPublicPropertyType.php')
file_get_contents(__DIR__ . '/generated/__CG__/Doctrine/Tests/Common/Proxy/Php81EnumPublicPropertyType.php')
);

$object = new \Doctrine\Tests\Common\ProxyProxy\__CG__\Doctrine\Tests\Common\Proxy\Php81EnumPublicPropertyType();
Expand All @@ -600,37 +600,37 @@ public function testPhp81NewInInitializers()

self::assertStringContainsString(
'onlyInitializer($foo = new \stdClass()): void',
file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyPHP81NewInInitializers.php')
file_get_contents(__DIR__ . '/generated/__CG__/Doctrine/Tests/Common/Proxy/PHP81NewInInitializers.php')
);

self::assertStringContainsString(
'typed(\DateTimeInterface $foo = new \DateTimeImmutable(\'now\')): void',
file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyPHP81NewInInitializers.php')
file_get_contents(__DIR__ . '/generated/__CG__/Doctrine/Tests/Common/Proxy/PHP81NewInInitializers.php')
);

self::assertStringContainsString(
'arrayInDefault(array $foo = [new \DateTimeImmutable(\'2022-08-22 16:20\', new \DateTimeZone(\'Europe/Warsaw\'))]): void',
file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyPHP81NewInInitializers.php')
file_get_contents(__DIR__ . '/generated/__CG__/Doctrine/Tests/Common/Proxy/PHP81NewInInitializers.php')
);

self::assertStringContainsString(
'scalarConstInDefault(string $foo = \'foo\'): void',
file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyPHP81NewInInitializers.php')
file_get_contents(__DIR__ . '/generated/__CG__/Doctrine/Tests/Common/Proxy/PHP81NewInInitializers.php')
);

self::assertStringContainsString(
'constInDefault(array $foo = \Doctrine\Tests\Common\Util\TestAsset\ConstProvider::FOO): void',
file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyPHP81NewInInitializers.php')
file_get_contents(__DIR__ . '/generated/__CG__/Doctrine/Tests/Common/Proxy/PHP81NewInInitializers.php')
);

self::assertStringContainsString(
"globalEolInDefault(string \$foo = '\n'): void",
file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyPHP81NewInInitializers.php')
file_get_contents(__DIR__ . '/generated/__CG__/Doctrine/Tests/Common/Proxy/PHP81NewInInitializers.php')
);

self::assertStringContainsString(
"specialCharacterInDefault(string \$foo = '\n'): void",
file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyPHP81NewInInitializers.php')
file_get_contents(__DIR__ . '/generated/__CG__/Doctrine/Tests/Common/Proxy/PHP81NewInInitializers.php')
);
}

Expand Down

0 comments on commit 414ccd0

Please sign in to comment.