From f77392ade4417b1576b6f6d771780561033d7fd6 Mon Sep 17 00:00:00 2001 From: Rostislav Wolny Date: Thu, 17 Jun 2021 12:53:22 +0200 Subject: [PATCH] Workaround doctrine serialisation issue in integration tests Doctrine uses a default ProxyClassNameResolver but it is implemented as an anonymous class and can not be serialised. This commit adds a custom ProxyClassNameResolver that copies the anonymous one so that we avoid using the anonymous fallback. [MAILPOET-3658] --- lib/Doctrine/ProxyClassNameResolver.php | 27 +++++++++++++++++++++ lib/Doctrine/TablePrefixMetadataFactory.php | 1 + 2 files changed, 28 insertions(+) create mode 100644 lib/Doctrine/ProxyClassNameResolver.php diff --git a/lib/Doctrine/ProxyClassNameResolver.php b/lib/Doctrine/ProxyClassNameResolver.php new file mode 100644 index 0000000000..94ead19cdf --- /dev/null +++ b/lib/Doctrine/ProxyClassNameResolver.php @@ -0,0 +1,27 @@ + + */ + public function resolveClassName(string $className) : string { + $pos = \strrpos($className, '\\' . \MailPoetVendor\Doctrine\Persistence\Proxy::MARKER . '\\'); + if ($pos === \false) { + /** @var class-string */ + return $className; + } + /** @var class-string */ + return \substr($className, $pos + \MailPoetVendor\Doctrine\Persistence\Proxy::MARKER_LENGTH + 2); + } +} diff --git a/lib/Doctrine/TablePrefixMetadataFactory.php b/lib/Doctrine/TablePrefixMetadataFactory.php index f36bdf3f92..15540ab123 100644 --- a/lib/Doctrine/TablePrefixMetadataFactory.php +++ b/lib/Doctrine/TablePrefixMetadataFactory.php @@ -22,6 +22,7 @@ class TablePrefixMetadataFactory extends ClassMetadataFactory { throw new \RuntimeException('DB table prefix not initialized'); } $this->prefix = Env::$dbPrefix; + $this->setProxyClassNameResolver(new ProxyClassNameResolver()); } public function getMetadataFor($className) {