Completed
Pull Request — master (#6185)
by Ilya
09:34
created

ManyToManyWithUniqueTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 5
dl 0
loc 45
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
B testMoveProductFromOneCategoryToAnother() 0 36 1
1
<?php
2
3
namespace Doctrine\Tests\ORM\Functional;
4
5
use Doctrine\Tests\Models\AivusTest\Category;
6
use Doctrine\Tests\Models\AivusTest\Product;
7
8
/**
9
 * Tests many-to-many association mapping with unique=true.
10
 */
11
class ManyToManyWithUniqueTest extends AbstractManyToManyAssociationTestCase
12
{
13
    protected function setUp()
14
    {
15
        $this->useModelSet('AivusTest');
16
        parent::setUp();
17
    }
18
19
    public function testMoveProductFromOneCategoryToAnother()
20
    {
21
        $product = new Product();
22
        $this->_em->persist($product);
23
24
        $category1 = new Category();
25
        $category1->addProduct($product);
26
        $this->_em->persist($category1);
27
28
        $category2 = new Category();
29
        $this->_em->persist($category2);
30
31
        $this->_em->flush();
32
33
        $category1Id = $category1->getId();
34
        $category2Id = $category2->getId();
35
36
        $this->_em->clear();
37
38
        $categoryRepository = $this->_em->getRepository(Category::class);
39
        $productRepository = $this->_em->getRepository(Product::class);
40
41
        /** @var Product $product */
42
        $product = $productRepository->findOneBy([]);
43
44
        /** @var Category $category2 */
45
        $category2 = $categoryRepository->find($category2Id);
46
47
        /** @var Category $category1 */
48
        $category1 = $categoryRepository->find($category1Id);
49
50
        $category1->removeProduct($product);
51
        $category2->addProduct($product);
52
53
        $this->_em->flush();
54
    }
55
}
56