From c66b982813108b1298c506fc4ebfb057e6c3e16b Mon Sep 17 00:00:00 2001 From: Wouter de Jong Date: Fri, 5 Aug 2022 12:27:48 +0200 Subject: [PATCH] Do not treat deprecation level as errors --- src/Types/ArrayType.php | 7 +++++++ tests/Types/ArrayTest.php | 9 +++++++++ .../Fixtures/UnserializeWithDeprecationObject.php | 15 +++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 tests/Types/Fixtures/UnserializeWithDeprecationObject.php diff --git a/src/Types/ArrayType.php b/src/Types/ArrayType.php index 3137e03f37a..b3d9d3c56ae 100644 --- a/src/Types/ArrayType.php +++ b/src/Types/ArrayType.php @@ -11,6 +11,9 @@ use function stream_get_contents; use function unserialize; +use const E_DEPRECATED; +use const E_USER_DEPRECATED; + /** * Type that maps a PHP array to a clob SQL type. */ @@ -45,6 +48,10 @@ public function convertToPHPValue($value, AbstractPlatform $platform) $value = is_resource($value) ? stream_get_contents($value) : $value; set_error_handler(function (int $code, string $message): bool { + if ($code === E_DEPRECATED || $code === E_USER_DEPRECATED) { + return false; + } + throw ConversionException::conversionFailedUnserialization($this->getName(), $message); }); diff --git a/tests/Types/ArrayTest.php b/tests/Types/ArrayTest.php index f7f823cfcac..172a5bdd042 100644 --- a/tests/Types/ArrayTest.php +++ b/tests/Types/ArrayTest.php @@ -3,6 +3,7 @@ namespace Doctrine\DBAL\Tests\Types; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Tests\Types\Fixtures\UnserializeWithDeprecationObject; use Doctrine\DBAL\Types\ArrayType; use Doctrine\DBAL\Types\ConversionException; use PHPUnit\Framework\MockObject\MockObject; @@ -45,6 +46,14 @@ public function testConversionFailure(): void $this->type->convertToPHPValue('abcdefg', $this->platform); } + public function testDeprecationDuringConversion(): void + { + @self::assertInstanceOf(UnserializeWithDeprecationObject::class, $this->type->convertToPHPValue( + serialize(new UnserializeWithDeprecationObject()), + $this->platform + )); + } + public function testNullConversion(): void { self::assertNull($this->type->convertToPHPValue(null, $this->platform)); diff --git a/tests/Types/Fixtures/UnserializeWithDeprecationObject.php b/tests/Types/Fixtures/UnserializeWithDeprecationObject.php new file mode 100644 index 00000000000..c668450c2e1 --- /dev/null +++ b/tests/Types/Fixtures/UnserializeWithDeprecationObject.php @@ -0,0 +1,15 @@ +