Passed
Branch master (168fd2)
by Dariusz
06:34
created

CartItemCollectionTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A testCollection() 0 15 1
1
<?php
2
3
namespace Plane\Shop\Tests;
4
5
use Plane\Shop\CartItem;
6
use Plane\Shop\CartItemCollection;
7
8
class CartItemCollectionTest extends \PHPUnit\Framework\TestCase
9
{
10
    public function testCollection()
11
    {
12
        $firstCartItem  = $this->createMock(CartItem::class);
13
        $secondCartItem = $this->createMock(CartItem::class);
14
15
        $cartItemCollection = new CartItemCollection;
16
        $cartItemCollection->addItem($firstCartItem);
0 ignored issues
show
Documentation introduced by
$firstCartItem is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Plane\Shop\CartItemInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
17
        $cartItemCollection->addItem($secondCartItem);
0 ignored issues
show
Documentation introduced by
$secondCartItem is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Plane\Shop\CartItemInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
18
19
        $this->assertTrue($cartItemCollection->length() == 2);
20
        $this->assertSame([
21
            0 => $firstCartItem,
22
            1 => $secondCartItem
23
        ], $cartItemCollection->getItems());
24
    }
25
}
26