/
GH467Test.php
84 lines (71 loc) · 2 KB
/
GH467Test.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
declare(strict_types=1);
namespace Doctrine\ODM\MongoDB\Tests\Functional\Ticket;
use Doctrine\Common\Collections\Collection;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use Doctrine\ODM\MongoDB\PersistentCollection;
use Doctrine\ODM\MongoDB\Tests\BaseTest;
class GH467Test extends BaseTest
{
public function testMergeDocumentWithUnsetCollectionFields(): void
{
$doc = new GH467Document();
$this->dm->persist($doc);
$this->dm->flush();
$this->dm->clear();
$doc = $this->dm->merge($doc);
$this->assertNull($doc->col, 'Unset basic collections are not initialized');
$this->assertInstanceOf(PersistentCollection::class, $doc->embedMany, 'Unset EmbedMany collections are initialized as empty PersistentCollections');
$this->assertCount(0, $doc->embedMany, 'Unset EmbedMany collections are initialized as empty PersistentCollections');
$this->assertInstanceOf(PersistentCollection::class, $doc->refMany, 'Unset ReferenceMany collections are initialized as empty PersistentCollections');
$this->assertCount(0, $doc->refMany, 'Unset ReferenceMany collections are initialized as empty PersistentCollections');
}
}
/** @ODM\Document */
class GH467Document
{
/**
* @ODM\Id
*
* @var string|null
*/
public $id;
/**
* @ODM\Field(type="collection")
*
* @var mixed[]
*/
public $col;
/**
* @ODM\EmbedMany(targetDocument=GH467EmbeddedDocument::class)
*
* @var Collection<int, GH467EmbeddedDocument>
*/
public $embedMany;
/**
* @ODM\ReferenceMany(targetDocument=GH467EmbeddedDocument::class)
*
* @var Collection<int, GH467EmbeddedDocument>
*/
public $refMany;
}
/** @ODM\EmbeddedDocument */
class GH467EmbeddedDocument
{
/**
* @ODM\Id
*
* @var string|null
*/
public $id;
}
/** @ODM\Document */
class GH467ReferencedDocument
{
/**
* @ODM\Id
*
* @var string|null
*/
public $id;
}