Passed
Push — master ( c14dbc...579f08 )
by Luís
12:22
created

ManyToManyPersisterTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B testDeleteManyToManyCollection() 0 29 1
1
<?php
2
3
namespace Doctrine\Tests\ORM\Persisters;
4
5
use Doctrine\ORM\Persisters\Collection\ManyToManyPersister;
6
use Doctrine\Tests\Mocks\ConnectionMock;
7
use Doctrine\Tests\Models\ManyToManyPersister\ChildClass;
8
use Doctrine\Tests\Models\ManyToManyPersister\OtherParentClass;
9
use Doctrine\Tests\Models\ManyToManyPersister\ParentClass;
10
use Doctrine\Tests\OrmTestCase;
11
12
/**
13
 * @covers \Doctrine\ORM\Persisters\Collection\ManyToManyPersister
14
 */
15
final class ManyToManyPersisterTest extends OrmTestCase
16
{
17
    /**
18
     * @group 6991
19
     * @group ManyToManyPersister
20
     *
21
     * @throws \Doctrine\ORM\ORMException
22
     */
23
    public function testDeleteManyToManyCollection(): void
24
    {
25
        $parent      = new ParentClass(1);
26
        $otherParent = new OtherParentClass(42);
27
        $child       = new ChildClass(1, $otherParent);
28
29
        $parent->children->add($child);
30
        $child->parents->add($parent);
31
32
        $em = $this->getTestEntityManager();
33
        $em->persist($parent);
34
        $em->flush();
35
36
        /** @var ChildClass|null $childReloaded */
37
        $childReloaded = $em->find(ChildClass::class, ['id1' => 1, 'otherParent' => $otherParent]);
38
39
        self::assertNotNull($childReloaded);
40
41
        $persister = new ManyToManyPersister($em);
42
        $persister->delete($childReloaded->parents);
43
44
        /** @var ConnectionMock $conn */
45
        $conn = $em->getConnection();
46
47
        $updates    = $conn->getExecuteUpdates();
48
        $lastUpdate = array_pop($updates);
49
50
        self::assertEquals('DELETE FROM "parent_child" WHERE "child_id1" = ? AND "child_id2" = ?', $lastUpdate['query']);
51
        self::assertEquals([1, 42], $lastUpdate['params']);
52
    }
53
}
54