CollectionTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 28
c 1
b 0
f 0
dl 0
loc 46
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testChildCollectionsRelation() 0 21 1
A testCannotCreateCyclicHierarchy() 0 12 1
A testCannotCreateCyclicHierarchyAsMyOwnParent() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ApplicationTest\Model;
6
7
use Application\Model\Collection;
8
use InvalidArgumentException;
9
10
class CollectionTest extends \PHPUnit\Framework\TestCase
11
{
12
    public function testChildCollectionsRelation(): void
13
    {
14
        $parent = new Collection();
15
        $child = new Collection();
16
        self::assertCount(0, $parent->getChildren());
17
18
        $child->setParent($parent);
19
        self::assertCount(1, $parent->getChildren());
20
        self::assertSame($child, $parent->getChildren()[0]);
21
22
        $otherParent = new Collection();
23
        self::assertCount(0, $otherParent->getChildren());
24
25
        $child->setParent($otherParent);
26
        self::assertCount(0, $parent->getChildren());
27
        self::assertCount(1, $otherParent->getChildren());
28
        self::assertSame($child, $otherParent->getChildren()[0]);
29
30
        $child->setParent(null);
31
        self::assertCount(0, $parent->getChildren());
32
        self::assertCount(0, $otherParent->getChildren());
33
    }
34
35
    public function testCannotCreateCyclicHierarchy(): void
36
    {
37
        $parent = new Collection();
38
        $child = new Collection();
39
        $grandChild = new Collection();
40
41
        $child->setParent($parent);
42
        $grandChild->setParent($child);
43
44
        self::expectException(InvalidArgumentException::class);
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCase::expectException() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

44
        self::/** @scrutinizer ignore-call */ 
45
              expectException(InvalidArgumentException::class);
Loading history...
45
        self::expectExceptionMessage('Parent object is invalid because it would create a cyclic hierarchy');
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCa...xpectExceptionMessage() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
        self::/** @scrutinizer ignore-call */ 
46
              expectExceptionMessage('Parent object is invalid because it would create a cyclic hierarchy');
Loading history...
46
        $parent->setParent($grandChild);
47
    }
48
49
    public function testCannotCreateCyclicHierarchyAsMyOwnParent(): void
50
    {
51
        $collection = new Collection();
52
53
        self::expectException(InvalidArgumentException::class);
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCase::expectException() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
        self::/** @scrutinizer ignore-call */ 
54
              expectException(InvalidArgumentException::class);
Loading history...
54
        self::expectExceptionMessage('An object cannot be his own parent');
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCa...xpectExceptionMessage() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

54
        self::/** @scrutinizer ignore-call */ 
55
              expectExceptionMessage('An object cannot be his own parent');
Loading history...
55
        $collection->setParent($collection);
56
    }
57
}
58