Completed
Push — master ( efcd9d...99efad )
by PHPLicengine
08:21 queued 02:36
created

BitlinkTest   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 152
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 98
c 1
b 0
f 0
dl 0
loc 152
rs 10
wmc 11
1
<?php
2
3
// BitlinkTest.php
4
#################################################
5
##
6
## PHPLicengine
7
##
8
#################################################
9
## Copyright 2009-{current_year} PHPLicengine
10
## 
11
## Licensed under the Apache License, Version 2.0 (the "License");
12
## you may not use this file except in compliance with the License.
13
## You may obtain a copy of the License at
14
##
15
##    http://www.apache.org/licenses/LICENSE-2.0
16
##
17
## Unless required by applicable law or agreed to in writing, software
18
## distributed under the License is distributed on an "AS IS" BASIS,
19
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
## See the License for the specific language governing permissions and
21
## limitations under the License.
22
#################################################
23
24
use PHPLicengine\Api\ApiInterface;
25
use PHPLicengine\Service\Bitlink;
26
use PHPUnit\Framework\TestCase;
27
28
class BitlinkTest extends TestCase
29
{
30
31
    public function testGetMetricsForBitlinkByReferrersByDomains()
32
    {
33
        $mock = $this->createMock(ApiInterface::class);
34
        $mock
35
            ->expects($this->once())
36
            ->method('get')
37
            ->with(
38
                    $this->equalTo('https://api-ssl.bitly.com/v4/bitlinks/test/referrers_by_domains'),                    
39
                    $this->identicalTo(['key' => 'value'])
40
                    );
41
        $bitlink = new Bitlink($mock);
42
        $bitlink->getMetricsForBitlinkByReferrersByDomains('test', ['key' => 'value']);
43
    }    
44
    
45
    public function testGetMetricsForBitlinkByCountries()
46
    {
47
        $mock = $this->createMock(ApiInterface::class);
48
        $mock
49
            ->expects($this->once())
50
            ->method('get')
51
            ->with(
52
                    $this->equalTo('https://api-ssl.bitly.com/v4/bitlinks/test/countries'),                    
53
                    $this->identicalTo(['key' => 'value'])
54
                    );
55
        $bitlink = new Bitlink($mock);
56
        $bitlink->getMetricsForBitlinkByCountries('test', ['key' => 'value']);
57
    }        
58
59
    public function testGetClicksForBitlink()
60
    {
61
        $mock = $this->createMock(ApiInterface::class);
62
        $mock
63
            ->expects($this->once())
64
            ->method('get')
65
            ->with(
66
                    $this->equalTo('https://api-ssl.bitly.com/v4/bitlinks/test/clicks'),                    
67
                    $this->identicalTo(['key' => 'value'])
68
                    );
69
        $bitlink = new Bitlink($mock);
70
        $bitlink->getClicksForBitlink('test', ['key' => 'value']);
71
    }        
72
73
    public function testExpandBitlink()
74
    {
75
        $mock = $this->createMock(ApiInterface::class);
76
        $mock
77
            ->expects($this->once())
78
            ->method('post')
79
            ->with(
80
                    $this->equalTo('https://api-ssl.bitly.com/v4/expand'),      
81
                    $this->identicalTo(['key' => 'value'])
82
                    );
83
        $bitlink = new Bitlink($mock);
84
        $bitlink->expandBitlink(['key' => 'value']);
85
    }        
86
87
    public function testGetMetricsForBitlinkByReferrers()
88
    {
89
        $mock = $this->createMock(ApiInterface::class);
90
        $mock
91
            ->expects($this->once())
92
            ->method('get')
93
            ->with(
94
                    $this->equalTo('https://api-ssl.bitly.com/v4/bitlinks/test/referrers'),      
95
                    $this->identicalTo(['key' => 'value'])
96
                    );
97
        $bitlink = new Bitlink($mock);
98
        $bitlink->getMetricsForBitlinkByReferrers('test', ['key' => 'value']);
99
    }        
100
101
    public function testCreateFullBitlink()
102
    {
103
        $mock = $this->createMock(ApiInterface::class);
104
        $mock
105
            ->expects($this->once())
106
            ->method('post')
107
            ->with(
108
                    $this->equalTo('https://api-ssl.bitly.com/v4/bitlinks'),
109
                    $this->identicalTo(['key' => 'value'])
110
                    );
111
        $bitlink = new Bitlink($mock);
112
        $bitlink->createFullBitlink(['key' => 'value']);
113
    }        
114
115
    public function testUpdateBitlink()
116
    {
117
        $mock = $this->createMock(ApiInterface::class);
118
        $mock
119
            ->expects($this->once())
120
            ->method('patch')
121
            ->with(
122
                    $this->equalTo('https://api-ssl.bitly.com/v4/bitlinks/test'),
123
                    $this->identicalTo(['key' => 'value'])
124
                    );
125
        $bitlink = new Bitlink($mock);
126
        $bitlink->updateBitlink('test', ['key' => 'value']);
127
    }        
128
129
    public function testGetBitlink()
130
    {
131
        $mock = $this->createMock(ApiInterface::class);
132
        $mock
133
            ->expects($this->once())
134
            ->method('get')
135
            ->with($this->equalTo('https://api-ssl.bitly.com/v4/bitlinks/test'));
136
        $bitlink = new Bitlink($mock);
137
        $bitlink->getBitlink('test');
138
    }
139
140
    public function testGetClicksSummaryForBitlink()
141
    {
142
        $mock = $this->createMock(ApiInterface::class);
143
        $mock
144
            ->expects($this->once())
145
            ->method('get')
146
            ->with(
147
                $this->equalTo('https://api-ssl.bitly.com/v4/bitlinks/test/clicks/summary'),
148
                $this->identicalTo(['key' => 'value'])
149
            );
150
        $bitlink = new Bitlink($mock);
151
        $bitlink->getClicksSummaryForBitlink('test', ['key' => 'value']);
152
    }    
153
    
154
    public function testCreateBitlink()
155
    {
156
        $mock = $this->createMock(ApiInterface::class);
157
        $mock
158
            ->expects($this->once())
159
            ->method('post')
160
            ->with(
161
                    $this->equalTo('https://api-ssl.bitly.com/v4/shorten'),
162
                    $this->identicalTo(['key' => 'value'])
163
                    );
164
        $bitlink = new Bitlink($mock);
165
        $bitlink->createBitlink(['key' => 'value']);
166
    }            
167
168
    public function testGetMetricsForBitlinkByReferringDomains()
169
    {
170
        $mock = $this->createMock(ApiInterface::class);
171
        $mock
172
            ->expects($this->once())
173
            ->method('get')
174
            ->with(
175
                $this->equalTo('https://api-ssl.bitly.com/v4/bitlinks/test/referring_domains'),
176
                $this->identicalTo(['key' => 'value'])
177
            );
178
        $bitlink = new Bitlink($mock);
179
        $bitlink->getMetricsForBitlinkByReferringDomains('test', ['key' => 'value']);
180
    }    
181
182
}
183