Passed
Push — master ( bbe808...4a0efd )
by Radosław
02:19
created

ItemTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 40
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testInstantiation() 0 5 1
A testArrayRepresentation() 0 12 1
A testToString() 0 6 1
A testInvalidUrl() 0 5 1
1
<?php
2
3
namespace Radowoj\Searcher\SearchResult;
4
5
use PHPUnit\Framework\TestCase;
6
use Radowoj\Searcher\SearchResult\Item;
7
use Radowoj\Searcher\SearchResult\IItem;
8
9
class ItemTest extends TestCase
10
{
11
    public function testInstantiation()
12
    {
13
        $item = new Item([]);
14
        $this->assertInstanceOf(IItem::class, $item);
15
    }
16
17
18
    public function testArrayRepresentation()
19
    {
20
        $array = [
21
            'url' => 'http://example.com',
22
            'title' => 'some title',
23
            'description' => 'some description',
24
        ];
25
26
        $item = new Item($array);
27
28
        $this->assertSame($array, $item->toArray());
29
    }
30
31
32
    public function testToString()
33
    {
34
        $url = 'http://example.com';
35
        $item = new Item(['url' => $url]);
36
        $this->assertSame($url, (string)$item);
37
    }
38
39
    /**
40
     * @expectedException InvalidArgumentException
41
     * @expectedExceptionMessage Invalid URL given:
42
     */
43
    public function testInvalidUrl()
44
    {
45
        $url = 'some invalid url';
46
        $item = new Item(['url' => $url]);
0 ignored issues
show
Unused Code introduced by
$item is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
47
    }
48
}
49