Skip to content

Commit

Permalink
Merge pull request #5569 from doctrine/3.3.x
Browse files Browse the repository at this point in the history
Merge 3.3.x into 3.4.x
  • Loading branch information
morozov committed Aug 6, 2022
2 parents 1c5d39c + f873a82 commit 118a360
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 @@ -12,6 +12,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 @@ -48,6 +51,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 @@ -44,6 +45,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 118a360

Please sign in to comment.