Skip to content

Commit 152926e

Browse files
Copilotlisachenko
andcommitted
Make proxy class reflection more resilient when AOP framework is not initialized
Co-authored-by: lisachenko <640114+lisachenko@users.noreply.github.com>
1 parent 7d7ec98 commit 152926e

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

tests/Go/PhpUnit/ClassMemberNotWovenConstraint.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ public function matches($other): bool
3737
}
3838

3939
$reflectionClass = ProxyClassReflectionHelper::createReflectionClass($other->getClass(), $this->configuration);
40+
41+
// If proxy class reflection cannot be created, the class is not woven
42+
if ($reflectionClass === null) {
43+
return true; // For "NotWoven" constraint, null reflection means success
44+
}
4045
$wovenAdvisorIdentifiers = $reflectionClass->getStaticPropertyValue('__joinPoints', null);
4146
$target = $other->getTarget();
4247

tests/Go/PhpUnit/ClassMemberWovenConstraint.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ public function matches($other): bool
3636
}
3737

3838
$reflectionClass = ProxyClassReflectionHelper::createReflectionClass($other->getClass(), $this->configuration);
39+
40+
// If proxy class reflection cannot be created, the class is not woven
41+
if ($reflectionClass === null) {
42+
return false;
43+
}
3944
$wovenAdvisorIdentifiers = $reflectionClass->getStaticPropertyValue('__joinPoints', null);
4045
$target = $other->getTarget();
4146

tests/Go/PhpUnit/ProxyClassReflectionHelper.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ private function __construct()
3232
*
3333
* @param string $className Full qualified class name for which \Go\ParserReflection\ReflectionClass ought to be initialized
3434
* @param array $configuration Configuration used for Go! AOP project setup
35+
*
36+
* @throws \RuntimeException when proxy file cannot be read or parsed
3537
*/
36-
public static function createReflectionClass(string $className, array $configuration): ReflectionClass
38+
public static function createReflectionClass(string $className, array $configuration): ?ReflectionClass
3739
{
3840
$parsedReflectionClass = new ReflectionClass($className);
3941
$originalClassFile = $parsedReflectionClass->getFileName();
@@ -47,7 +49,8 @@ public static function createReflectionClass(string $className, array $configura
4749
$proxyFileContent = file_get_contents($proxyFileName);
4850

4951
if ($proxyFileContent === false) {
50-
throw new \RuntimeException("Could not read proxy file: {$proxyFileName}");
52+
// Return null to indicate that the class is not woven (proxy file doesn't exist)
53+
return null;
5154
}
5255

5356
// To prevent deep analysis of parents, we just cut everything after "extends"

0 commit comments

Comments
 (0)