ProductTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 16
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testRelatedProductWithSelf() 0 5 1
A testRelatedProducts() 0 20 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ApplicationTest\Model;
6
7
use Application\Model\Product;
8
use PHPUnit\Framework\TestCase;
9
10
class ProductTest extends TestCase
11
{
12
    public function testRelatedProducts(): void
13
    {
14
        $product1 = new Product();
15
        $product2 = new Product();
16
17
        self::assertCount(0, $product1->getRelatedProducts());
18
        self::assertCount(0, $product2->getRelatedProducts());
19
20
        $product1->addRelatedProduct($product2);
21
22
        self::assertCount(1, $product1->getRelatedProducts());
23
        self::assertCount(0, $product2->getRelatedProducts());
24
25
        self::assertSame($product2, $product1->getRelatedProducts()->first());
26
        self::assertFalse($product2->getRelatedProducts()->first());
27
28
        $product1->removeRelatedProduct($product2);
29
30
        self::assertCount(0, $product1->getRelatedProducts());
31
        self::assertCount(0, $product2->getRelatedProducts());
32
    }
33
34
    public function testRelatedProductWithSelf(): void
35
    {
36
        $this->expectExceptionMessage('A product cannot be related to itself');
37
        $product = new Product();
38
        $product->addRelatedProduct($product);
39
    }
40
}
41