Skip to content

Commit

Permalink
Merge pull request #5566 from wouterj/serialization-deprecation
Browse files Browse the repository at this point in the history
Do not treat deprecation level as errors
  • Loading branch information
morozov committed Aug 5, 2022
2 parents de42378 + c66b982 commit f873a82
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Types/ArrayType.php
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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);
});

Expand Down
9 changes: 9 additions & 0 deletions tests/Types/ArrayTest.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
15 changes: 15 additions & 0 deletions tests/Types/Fixtures/UnserializeWithDeprecationObject.php
@@ -0,0 +1,15 @@
<?php

namespace Doctrine\DBAL\Tests\Types\Fixtures;

use function trigger_error;

use const E_USER_DEPRECATED;

class UnserializeWithDeprecationObject
{
public function __wakeup(): void
{
trigger_error('Deprecation triggered', E_USER_DEPRECATED);
}
}

0 comments on commit f873a82

Please sign in to comment.