Passed
Push — master ( 4a0efd...7f5941 )
by Radosław
02:22
created

ItemTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 51
rs 10
c 0
b 0
f 0

5 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
A testInvalidProperty() 0 4 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
    /**
41
     * @expectedException InvalidArgumentException
42
     * @expectedExceptionMessage Invalid URL given:
43
     */
44
    public function testInvalidUrl()
45
    {
46
        $url = 'some invalid url';
47
        new Item(['url' => $url]);
48
    }
49
50
51
    /**
52
     * @expectedException InvalidArgumentException
53
     * @expectedExceptionMessage Invalid search result item property
54
     */
55
    public function testInvalidProperty()
56
    {
57
        new Item(['someInvalidProperty' => 'some value']);
58
    }
59
}
60