-
-
Notifications
You must be signed in to change notification settings - Fork 502
/
GH936Test.php
74 lines (59 loc) · 1.79 KB
/
GH936Test.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
<?php
declare(strict_types=1);
namespace Doctrine\ODM\MongoDB\Tests\Functional\Ticket;
use Doctrine\ODM\MongoDB\Event\LifecycleEventArgs;
use Doctrine\ODM\MongoDB\Events;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use Doctrine\ODM\MongoDB\Tests\BaseTest;
use ProxyManager\Proxy\GhostObjectInterface;
class GH936Test extends BaseTest
{
public function testRemoveCascadesThroughProxyDocuments(): void
{
$listener = new GH936Listener();
$this->dm->getEventManager()->addEventListener(Events::postRemove, $listener);
$baz = new GH936Document();
$bar = new GH936Document($baz);
$foo = new GH936Document($bar);
$this->dm->persist($foo);
$this->dm->flush();
$this->dm->clear();
$foo = $this->dm->find(GH936Document::class, $foo->id);
$this->assertInstanceOf(GhostObjectInterface::class, $foo->ref);
$this->dm->remove($foo);
$this->dm->flush();
$this->assertCount(3, $listener->removed);
$this->assertNull($this->dm->find(GH936Document::class, $foo->id));
$this->assertNull($this->dm->find(GH936Document::class, $bar->id));
$this->assertNull($this->dm->find(GH936Document::class, $baz->id));
}
}
/** @ODM\Document */
class GH936Document
{
/**
* @ODM\Id
*
* @var string|null
*/
public $id;
/**
* @ODM\ReferenceOne(targetDocument=GH936Document::class, cascade={"persist","remove"})
*
* @var GH936Document|null
*/
public $ref;
public function __construct(?GH936Document $ref = null)
{
$this->ref = $ref;
}
}
class GH936Listener
{
/** @var object[] */
public $removed = [];
public function postRemove(LifecycleEventArgs $args): void
{
$this->removed[] = $args->getDocument();
}
}