Passed
Push — master ( 048cfc...89074f )
by
unknown
12:32
created

CategoryTest::testTree()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 18
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ApplicationTest\Model;
6
7
use Application\Model\Category;
8
use Application\Model\Transaction;
9
use PHPUnit\Framework\TestCase;
10
11
class CategoryTest extends TestCase
12
{
13
    public function testTree(): void
14
    {
15
        $a = new Category();
16
        $b = new Category();
17
        $c = new Category();
18
        $d = new Category();
19
20
        $b->addParent($a);
21
        $c->addParent($a);
22
23
        self::assertCount(2, $a->getChildren());
24
25
        $d->addParent($b);
26
        $d->addParent($c);
27
28
        self::assertCount(2, $d->getParents());
29
        self::assertCount(1, $b->getChildren());
30
        self::assertCount(1, $c->getChildren());
31
    }
32
33
    public function testTransactionRelation(): void
34
    {
35
        $transaction = new Transaction();
36
        $category = new Category();
37
38
        $transaction->setCategory($category);
39
40
        self::assertCount(1, $category->getTransactions());
41
42
        self::assertSame($transaction->getCategory(), $category);
43
44
        $transaction2 = new Transaction();
45
        $category2 = new Category();
46
        $transaction->setCategory($category2);
47
        $transaction2->setCategory($category2);
48
        self::assertCount(0, $category->getTransactions());
49
        self::assertCount(2, $category2->getTransactions());
50
    }
51
}
52