Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge 3.3.x into 3.4.x #5569

Merged
merged 2 commits into from Aug 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
}
}