Skip to content

Commit 1ec48ed

Browse files
author
Tim Helfensdörfer
committed
Fixed tests and linting errors
1 parent d90137a commit 1ec48ed

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"license": "MIT",
55
"require": {
66
"php": ">=7",
7+
"ext-json": "*",
78
"voku/httpful": "0.4.*"
89
},
910
"require-dev": {

src/Matomo.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php namespace VisualAppeal;
22

3+
use Httpful\Exception\ConnectionErrorException;
34
use Httpful\Request;
45

56
/**
@@ -373,7 +374,7 @@ public function reset()
373374
* @param string $method
374375
* @param array $params
375376
* @param array $optional
376-
* @return bool|object
377+
* @return bool|object|array
377378
*/
378379
private function _request($method, $params = [], $optional = [])
379380
{
@@ -387,7 +388,12 @@ private function _request($method, $params = [], $optional = [])
387388
$req->max_redirects = $this->maxRedirects;
388389
$req->setConnectionTimeout(5);
389390

390-
$buffer = $req->send();
391+
try {
392+
$buffer = $req->send();
393+
} catch (ConnectionErrorException $e) {
394+
$this->_addError(sprintf('Could not send buffer: %s', $e->getMessage()));
395+
return false;
396+
}
391397

392398
if (!empty($buffer)) {
393399
$request = $this->_parseRequest($buffer);
@@ -1545,7 +1551,7 @@ public function getAvailableExtractionDimensions()
15451551
*
15461552
* @param string $segment
15471553
* @param array $optional
1548-
* @return bool|object
1554+
* @return array
15491555
*/
15501556
public function getCustomVariables($segment = '', $optional = [])
15511557
{
@@ -2567,7 +2573,7 @@ public function getUsersById( $segment = '', $optional = []){
25672573
'segment' => $segment,
25682574
], $optional);
25692575
}
2570-
2576+
25712577
/**
25722578
* MODULE: MOBILEMESSAGING
25732579
* The MobileMessaging API lets you manage and access all the MobileMessaging plugin features
@@ -4297,7 +4303,7 @@ public function getCountry($segment = '', $optional = [])
42974303
*
42984304
* @return object
42994305
*/
4300-
public function getCountryCodeMapping($segment = '', $optional = [])
4306+
public function getCountryCodeMapping()
43014307
{
43024308
return $this->_request('UserCountry.getCountryCodeMapping');
43034309
}

tests/MatomoTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class MatomoTest extends \PHPUnit\Framework\TestCase
88
{
99
const TEST_SITE_URL = 'https://demo.matomo.org/';
1010

11-
const TEST_SITE_ID = 7;
11+
const TEST_SITE_ID = 62;
1212

1313
const TEST_TOKEN = 'anonymous';
1414

@@ -191,26 +191,26 @@ public function testMultipleErrors()
191191
*/
192192
public function testOptionalParameters()
193193
{
194-
$this->_matomo->setDate('2011-01-11');
194+
$this->_matomo->setDate('2018-10-01');
195195
$this->_matomo->setPeriod(Matomo::PERIOD_WEEK);
196196
$result = $this->_matomo->getWebsites('', [
197197
'flat' => 1,
198198
]);
199199

200200
$this->assertInternalType('array', $result);
201201
$this->assertEquals('', implode(',', $this->_matomo->getErrors()));
202-
$this->assertEquals(388, $result[0]->nb_visits);
202+
$this->assertEquals(934, $result[0]->nb_visits);
203203
}
204204

205205
/**
206206
* Test if the response contains custom variables
207207
*/
208208
public function testCustomVariables()
209209
{
210-
$this->_matomo->setDate('2011-11-08');
210+
$this->_matomo->setDate('2018-10-01');
211211
$this->_matomo->setPeriod(Matomo::PERIOD_WEEK);
212212
$result = $this->_matomo->getCustomVariables();
213213

214-
$this->assertEquals(1, count($result));
214+
$this->assertEquals(15, count($result));
215215
}
216216
}

0 commit comments

Comments
 (0)