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

SearcherTest::testQueryFluentInterface()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Radowoj\Searcher;
4
5
6
use stdClass;
7
8
use PHPUnit\Framework\TestCase;
9
use Radowoj\Searcher\Searcher;
10
use Radowoj\Searcher\ISearcher;
11
use Radowoj\Searcher\SearchProvider\SearchProvider;
12
use Radowoj\Searcher\SearchResult\Collection;
13
use Radowoj\Searcher\SearchResult\ICollection;
14
use GuzzleHttp\Client as GuzzleClient;
15
16
class SearcherTest extends TestCase
17
{
18
19
    protected function getBasicSearcher()
20
    {
21
        $searchProvider = $this->getMockForAbstractClass(SearchProvider::class);
22
        $searcher = new Searcher($searchProvider);
23
        return $searcher;
24
    }
25
26
27
    public function testInstantiation()
28
    {
29
        $searcher = $this->getBasicSearcher();
30
        $this->assertInstanceOf(ISearcher::class, $searcher);
31
    }
32
33
34
    public function testQueryFluentInterface()
35
    {
36
        $searcher = $this->getBasicSearcher();
37
        $result = $searcher->query('some query');
38
        $this->assertInstanceOf(ISearcher::class, $result);
39
    }
40
41
42
    public function testLimitFluentInterface()
43
    {
44
        $searcher = $this->getBasicSearcher();
45
        $result = $searcher->limit(100);
46
        $this->assertInstanceOf(ISearcher::class, $result);
47
    }
48
49
50
    public function testOffsetFluentInterface()
51
    {
52
        $searcher = $this->getBasicSearcher();
53
        $result = $searcher->offset(100);
54
        $this->assertInstanceOf(ISearcher::class, $result);
55
    }
56
57
58
    public function providerTestFind()
59
    {
60
        return [
61
            ['nyan cat', 100, 0],
62
            ['some search query', 42, 51]
63
        ];
64
    }
65
66
67
    /**
68
     * @dataProvider providerTestFind
69
     */
70
    public function testFind($query, $limit, $offset)
71
    {
72
        $searchProvider = $this->getMockForAbstractClass(SearchProvider::class);
73
74
        $searchProvider->expects($this->once())
75
            ->method('searchRequest')
76
            ->with(
77
                $this->equalTo($query),
78
                $this->equalTo($limit),
79
                $this->equalTo($offset)
80
            )
81
            ->will($this->returnValue(new stdClass));
82
83
        $searchProvider->expects($this->once())
84
            ->method('getCollection')
85
            ->will($this->returnValue(new Collection));
86
87
        $searcher = new Searcher($searchProvider);
88
89
        $results = $searcher
90
            ->query($query)
91
            ->limit($limit)
92
            ->offset($offset)
93
            ->find();
94
95
        $this->assertInstanceOf(ICollection::class, $results);
96
    }
97
98
99
}
100