/
ArrayTest.php
66 lines (53 loc) · 1.93 KB
/
ArrayTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
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;
use PHPUnit\Framework\TestCase;
use function serialize;
class ArrayTest extends TestCase
{
/** @var AbstractPlatform&MockObject */
private $platform;
/** @var ArrayType */
private $type;
protected function setUp(): void
{
$this->platform = $this->createMock(AbstractPlatform::class);
$this->type = new ArrayType();
}
public function testArrayConvertsToDatabaseValue(): void
{
self::assertIsString($this->type->convertToDatabaseValue([], $this->platform));
}
public function testArrayConvertsToPHPValue(): void
{
self::assertIsArray($this->type->convertToPHPValue(serialize([]), $this->platform));
}
public function testConversionFailure(): void
{
$this->expectException(ConversionException::class);
$this->expectExceptionMessage(
"Could not convert database value to 'array' as an error was triggered by the unserialization:"
. " 'unserialize(): Error at offset 0 of 7 bytes'"
);
$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));
}
public function testFalseConversion(): void
{
self::assertFalse($this->type->convertToPHPValue(serialize(false), $this->platform));
}
}